Skip to content

Commit af2648e

Browse files
author
Philip Niedertscheider
authored
Merge pull request #215 from techprimate/release/2.1.2
Release/2.1.2
2 parents 241a69f + 1bd1a7d commit af2648e

File tree

4 files changed

+93
-62
lines changed

4 files changed

+93
-62
lines changed

CHANGELOG.md

Lines changed: 70 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Change Log
22

33
## [Unreleased](https://github.com/techprimate/TPPDF/tree/HEAD) (2020-??-??)
4-
[Full Changelog](https://github.com/techprimate/TPPDF/compare/2.1.1...HEAD)
4+
[Full Changelog](https://github.com/techprimate/TPPDF/compare/2.1.2...HEAD)
55

66
**Implemented enhancements:**
77

@@ -11,6 +11,22 @@
1111

1212
**Merged pull requests:**
1313

14+
## [2.1.2](https://github.com/techprimate/TPPDF/tree/2.1.2) (2020-06-23)
15+
[Full Changelog](https://github.com/techprimate/TPPDF/compare/2.1.1...2.1.2)
16+
17+
**Fixed bugs:**
18+
19+
- Height of image captions are now calcuated correctly (Issue #208)
20+
21+
**Closed issues:**
22+
23+
- Issue #208
24+
25+
**Merged pull requests:**
26+
27+
- PR #214 [by chrisgonzgonz]
28+
29+
1430
## [2.1.1](https://github.com/techprimate/TPPDF/tree/2.1.1) (2020-06-16)
1531
[Full Changelog](https://github.com/techprimate/TPPDF/compare/2.1.0...2.1.1)
1632

@@ -40,18 +56,18 @@
4056

4157
**Closed issues:**
4258

43-
- #73
44-
- #122
45-
- #204
46-
- #197
47-
- #189
48-
- #186
49-
- #184
50-
- #183
59+
- Issue #73
60+
- Issue #122
61+
- Issue #204
62+
- Issue #197
63+
- Issue #189
64+
- Issue #186
65+
- Issue #184
66+
- Issue #183
5167

5268
**Merged pull requests:**
5369

54-
- #211
70+
- Issue #211
5571

5672
## [2.0.1](https://github.com/techprimate/TPPDF/tree/2.0.1) (2020-05-31)
5773
[Full Changelog](https://github.com/techprimate/TPPDF/compare/2.0.0...2.0.1)
@@ -67,7 +83,7 @@
6783

6884
**Closed issues:**
6985

70-
- #204
86+
- Issue #204
7187

7288
## [2.0.0](https://github.com/techprimate/TPPDF/tree/2.0.0) (2020-05-19)
7389
[Full Changelog](https://github.com/techprimate/TPPDF/compare/1.6.0...2.0.0)
@@ -84,22 +100,22 @@
84100

85101
**Closed issues:**
86102

87-
- #41
88-
- #86
89-
- #148
90-
- #178
91-
- #179
92-
- #182
93-
- #183
94-
- #184
95-
- #185
96-
- #186
97-
- #196
98-
- #197
103+
- Issue #41
104+
- Issue #86
105+
- Issue #148
106+
- Issue #178
107+
- Issue #179
108+
- Issue #182
109+
- Issue #183
110+
- Issue #184
111+
- Issue #185
112+
- Issue #186
113+
- Issue #196
114+
- Issue #197
99115

100116
**Merged pull requests:**
101117

102-
- #181
118+
- Issue #181
103119

104120
## [1.6.0](https://github.com/techprimate/TPPDF/tree/1.6.0) (2020-03-23)
105121
[Full Changelog](https://github.com/techprimate/TPPDF/compare/1.5.4...1.6.0)
@@ -119,17 +135,17 @@
119135

120136
**Closed issues:**
121137

122-
- #155
123-
- #31
124-
- #170
125-
- #71
138+
- Issue #155
139+
- Issue #31
140+
- Issue #170
141+
- Issue #71
126142

127143
**Merged pull requests:**
128144

129-
- #171
130-
- #172
131-
- #174
132-
- #177
145+
- Issue #171
146+
- Issue #172
147+
- Issue #174
148+
- Issue #177
133149

134150
## [1.5.4](https://github.com/techprimate/TPPDF/tree/1.5.4) (2019-06-06)
135151
[Full Changelog](https://github.com/techprimate/TPPDF/compare/1.5.3...1.5.4)
@@ -161,7 +177,7 @@
161177

162178
**Closed issues:**
163179

164-
- #67
180+
- Issue #67
165181

166182
## [1.5.0](https://github.com/techprimate/TPPDF/tree/1.5.0) (2019-06-05)
167183
[Full Changelog](https://github.com/techprimate/TPPDF/compare/1.4.1...1.5.0)
@@ -182,17 +198,17 @@
182198

183199
**Closed issues:**
184200

185-
- #9
186-
- #57
187-
- #58
188-
- #88
189-
- #113
190-
- #118
191-
- #127
192-
- #132
193-
- #136
194-
- #137
195-
- #138
201+
- Issue #9
202+
- Issue #57
203+
- Issue #58
204+
- Issue #88
205+
- Issue #113
206+
- Issue #118
207+
- Issue #127
208+
- Issue #132
209+
- Issue #136
210+
- Issue #137
211+
- Issue #138
196212

197213
## [1.4.1](https://github.com/techprimate/TPPDF/tree/1.4.1) (2019-05-19)
198214
[Full Changelog](https://github.com/techprimate/TPPDF/compare/1.4.0...1.4.1)
@@ -219,9 +235,9 @@
219235

220236
**Closed issues:**
221237

222-
- #123
223-
- #125
224-
- #128
238+
- Issue #123
239+
- Issue #125
240+
- Issue #128
225241

226242
## [1.3.3](https://github.com/techprimate/TPPDF/tree/1.3.3) (2019-03-13)
227243
[Full Changelog](https://github.com/techprimate/TPPDF/compare/1.3.2...1.3.3)
@@ -232,14 +248,13 @@
232248

233249
**Closed issues:**
234250

235-
- #101
236-
- #103
237-
- #108
238-
- #109
239-
- #111
240-
- #113
241-
- #114
242-
251+
- Issue #101
252+
- Issue #103
253+
- Issue #108
254+
- Issue #109
255+
- Issue #111
256+
- Issue #113
257+
- Issue #114
243258

244259
**Merged pull requests:**
245260

Shared/Examples/ImageExampleFactory.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,19 @@ class ImageExampleFactory: ExampleFactory {
8181
document.add(imagesInRow: images[1], spacing: 10)
8282
document.add(imagesInRow: images[1], spacing: 10)
8383

84+
// Image and caption should be on same page
85+
let tallImage = PDFImage(image: UIImage(named: "Image-4.jpg")!,
86+
size: CGSize(width: 150, height: 800))
87+
tallImage.caption = PDFSimpleText(text: "Awesome Caption\nLine 2 of awesome Caption")
88+
89+
// Height should fit
90+
tallImage.sizeFit = .height
91+
92+
document.add(.contentCenter, image: tallImage)
93+
94+
// Just add some text to see page break
95+
document.add(text: LoremIpsum.get(words: 50))
96+
8497
return [document]
8598
}
8699
}

Source/Internal/Utils/PDFCalculations.swift

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -436,9 +436,15 @@ internal enum PDFCalculations {
436436
sizeFit: PDFImageSizeFit) -> (CGSize, CGSize) {
437437
/* calculate the aspect size of image */
438438
let size = (size == CGSize.zero) ? image.size : size
439+
440+
/* calculate caption height if a caption exists */
441+
let captionHeight: CGFloat =
442+
(image.caption as? PDFAttributedText).map({ $0.text.size().height })
443+
?? (image.caption as? PDFSimpleText).map({ $0.text.size().height })
444+
?? 0
439445

440446
let maxWidth = min(size.width, calculateAvailableFrameWidth(for: generator, in: container))
441-
let maxHeight = min(size.height, calculateAvailableFrameHeight(for: generator, in: container))
447+
let maxHeight = min(size.height, calculateAvailableFrameHeight(for: generator, in: container) - captionHeight)
442448

443449
let wFactor = image.size.width / maxWidth
444450
let hFactor = image.size.height / maxHeight
@@ -454,11 +460,8 @@ internal enum PDFCalculations {
454460
}
455461
}()
456462

457-
let imageSize = CGSize(width: image.size.width / factor, height: image.size.height / factor)
458-
let captionHeight: CGFloat = 0
459-
// if let _ = image.caption {
460-
// TODO: Fix caption height calculations
461-
// }
463+
let imageSize = CGSize(width: image.size.width / factor, height: (image.size.height / factor) - captionHeight)
464+
462465
return (imageSize, CGSize(width: imageSize.width, height: captionHeight))
463466
}
464467

TPPDF.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = 'TPPDF'
3-
s.version = '2.1.1'
3+
s.version = '2.1.2'
44
s.summary = 'TPPDF is a simple-to-use PDF builder for iOS'
55
s.description = <<-DESC
66
TPPDF is an object-based PDF builder, completely built in Swift.

0 commit comments

Comments
 (0)