Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

another fix for showHeaderOnEveryPage #264

Merged
merged 79 commits into from
Mar 15, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
79 commits
Select commit Hold shift + click to select a range
f756e5a
Updated docs for
Jun 24, 2020
bfee891
Updated docs for
Jun 24, 2020
d17548a
Updated docs for
Jun 24, 2020
bf9b18a
Updated docs for
Jun 25, 2020
17dc161
Updated docs for
Jun 26, 2020
ecba679
Updated docs for
Jun 28, 2020
ba6a78f
Added landing page with redirection
Jul 1, 2020
e2013e4
Updated docs for
Jul 1, 2020
34a39cb
Updated docs for
Jul 2, 2020
8ac72eb
Updated docs for
Jul 9, 2020
739fbc2
Updated docs for
Jul 16, 2020
2fc8b88
Updated docs for
Jul 16, 2020
f0c9a6b
Updated docs for
Jul 16, 2020
91e64b4
Updated docs for
Jul 23, 2020
99d5598
Updated docs for
Jul 30, 2020
c84be40
Updated docs for
Aug 6, 2020
ed1213b
Updated docs for
Aug 13, 2020
e2dd206
Updated docs for
Aug 20, 2020
c3244c1
Updated docs for
Aug 27, 2020
69551cc
Updated docs for
Sep 3, 2020
b629679
Updated docs for
Sep 10, 2020
537b656
Updated docs for
Sep 17, 2020
b0e7404
Merge branch 'master' into gh-pages
Sep 23, 2020
7fed85c
Updated docs for
Sep 23, 2020
930481f
Updated docs for
Sep 26, 2020
8f97c81
Merge branch 'master' into gh-pages
Sep 26, 2020
2b34637
Updated docs for
Sep 26, 2020
ce5a417
Updated docs for
Oct 1, 2020
28c9f01
Updated docs for
Oct 8, 2020
1069ff3
Merge branch 'master' into gh-pages
Oct 12, 2020
f98bb2e
Updated docs for
Oct 12, 2020
28701d5
Updated docs for
Oct 15, 2020
fc70bf9
Updated docs for
Oct 22, 2020
a6fc3a1
Updated docs for
Oct 29, 2020
dfd307a
Updated docs for
Nov 5, 2020
be59409
Updated docs for
Nov 12, 2020
c0ce4b9
Updated docs for
Nov 19, 2020
f9e3c28
Merge branch 'master' into gh-pages
Nov 21, 2020
f96b001
Updated docs for
Nov 21, 2020
74a4fee
Merge branch 'master' into gh-pages
Nov 21, 2020
910f475
Updated docs for
Nov 21, 2020
437b823
Merge branch 'master' into gh-pages
Nov 21, 2020
13011a4
Updated docs for
Nov 21, 2020
3122574
Updated docs for
Nov 21, 2020
b26dba4
Updated docs for
Nov 26, 2020
adb6e74
Updated docs for
Dec 3, 2020
533810a
Merge branch 'master' into gh-pages
Dec 5, 2020
ac6bc3b
Updated docs for
Dec 5, 2020
8ab0b1f
Updated docs for
Dec 10, 2020
84c14bc
Updated docs for
Dec 17, 2020
6fd3f53
Updated docs for
Dec 24, 2020
9ad0e78
Updated docs for
Dec 31, 2020
e733307
Merge branch 'master' into gh-pages
Jan 6, 2021
0bb8ecd
Updated docs for
Jan 6, 2021
a788b3d
Merge branch 'master' into gh-pages
Jan 7, 2021
55fac1c
Updated docs for
Jan 7, 2021
2c6d6aa
Updated docs for
Jan 7, 2021
53453df
Update PDFCalculations.swift
Sgkhour Aug 23, 2020
50d8d47
Update PDFTableObject.swift
Sgkhour Aug 23, 2020
736f9ba
Updated docs for
Jan 14, 2021
c1afb59
Updated docs for
Jan 21, 2021
c3e12ed
Update PDFTableObject.swift
Sgkhour Jan 23, 2021
85245e8
Updated docs for
Jan 28, 2021
c90a89e
Updated docs for
Feb 4, 2021
8f10b3f
Updated docs for
Feb 11, 2021
fa144dd
Updated docs for
Feb 18, 2021
652ba1e
Update PDFTableObjectSpec.swift
Sgkhour Feb 20, 2021
ae52122
Update PDFTableObjectSpec.swift
Sgkhour Feb 20, 2021
f888982
Update PDFTableObjectSpec.swift
Sgkhour Feb 20, 2021
283259b
Update PDFTableObject.swift
Sgkhour Feb 21, 2021
3bde7f8
Update PDFTableObjectSpec.swift
Sgkhour Feb 22, 2021
342bc97
Updated docs for
Feb 25, 2021
c0bc151
Fixed test cases
Feb 27, 2021
b0daf0a
Added page layout spacer explaination to README
Feb 27, 2021
554ccf5
Fixed copy-paste error in docs
Feb 27, 2021
917c4ed
Merge branch 'gh-pages'
Sgkhour Feb 28, 2021
b35163a
Merge branch '222-show-header-height-fixes'
Sgkhour Feb 28, 2021
e2d145b
Update PDFListItemObject_Spec.swift
Sgkhour Mar 1, 2021
dbaa0e1
remove the docs directory
Sgkhour Mar 2, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 additions & 2 deletions Source/Internal/Table/PDFTableObject.swift
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ internal class PDFTableObject: PDFRenderObject {
let startPosition: CGPoint = cells.first?.frames.cell.origin ?? .zero
var nextPageCells: [PDFTableCalculatedCell] = cells
var pageEnd = CGPoint.null
var headerShift = true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be a hardcoded value or should it be connected to showHeaderOnEveryPage or shouldSplitCellsOnPageBreak?


repeat {
var pageStart = CGPoint.null
Expand All @@ -296,7 +297,9 @@ internal class PDFTableObject: PDFRenderObject {
var cellFrame = item.frames.cell
var contentFrame = item.frames.content
cellFrame.origin.y -= startPosition.y - minOffset
cellFrame.origin.y += table.margin
contentFrame.origin.y -= startPosition.y - minOffset
contentFrame.origin.y += table.margin

pageStart = pageStart == .null ? cellFrame.origin : pageStart
pageEnd = CGPoint(x: cellFrame.maxX, y: cellFrame.maxY) + CGPoint(x: table.margin, y: table.margin)
Expand Down Expand Up @@ -329,6 +332,15 @@ internal class PDFTableObject: PDFRenderObject {
}
minOffset += headerHeight
}
if !firstPage {
// shift the rest of the cells down by headerHeight
if headerShift {
nextPageCells = shiftCellsBy(cells: nextPageCells, shiftValue: headerHeight)
headerShift = false
}
//add table padding around cells
nextPageCells = shiftCellsBy(cells: nextPageCells, shiftValue: table.padding)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line 342 adds additional spacing for me between the header and the first row on pages > 1. If I comment it out it works fine.

}

let filterResult = filterCellsOnPage(for: generator,
items: nextPageCells,
Expand Down Expand Up @@ -432,7 +444,6 @@ internal class PDFTableObject: PDFRenderObject {
if shouldSplitCellsOnPageBreak && cellFrame.minY < maxOffset {
result.cells.append(item)
}
// In any case, if the cell does not fit on the active page entirely, it must be repositioned for further pages
var nextPageCell = item
if shouldSplitCellsOnPageBreak {
nextPageCell.frames.cell.origin.y -= contentHeight
Expand All @@ -450,7 +461,22 @@ internal class PDFTableObject: PDFRenderObject {
}
return result
}


internal typealias ShiftedCells = ([PDFTableCalculatedCell])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
internal typealias ShiftedCells = ([PDFTableCalculatedCell])
internal typealias ShiftedCells = [PDFTableCalculatedCell]

It is not necessary to wrap the array in parantheses and that might lead to side effects (it would be a single value tuple)


internal func shiftCellsBy(cells: [PDFTableCalculatedCell], shiftValue: CGFloat) -> ShiftedCells {
var shiftedCells: [PDFTableCalculatedCell] = []

for cell in cells {
var shiftedCell = cell

shiftedCell.frames.cell.origin.y += shiftValue
shiftedCell.frames.content.origin.y += shiftValue
shiftedCells.append(shiftedCell)
}
return shiftedCells
}

internal func createSliceObject(frame: CGRect, elements: [PDFRenderObject], minOffset: CGFloat, maxOffset: CGFloat) -> PDFSlicedObject {
let sliceObject = PDFSlicedObject(children: elements, frame: frame)
if frame.maxY > maxOffset {
Expand Down
4 changes: 4 additions & 0 deletions Source/Internal/Utils/PDFCalculations.swift
Original file line number Diff line number Diff line change
Expand Up @@ -144,17 +144,21 @@ internal enum PDFCalculations {
return pageLayout.height
- layout.margin.top
- layout.heights.maxHeaderHeight()
- pageLayout.space.header
- layout.heights.content
- generator.currentPadding.bottom
- pageLayout.space.footer
- layout.heights.maxFooterHeight()
- layout.margin.bottom
}
}

internal static func calculateTopMinimum(for generator: PDFGenerator) -> CGFloat {
let layout = generator.layout
let pageLayout = generator.document.layout
return layout.margin.top
+ layout.heights.maxHeaderHeight()
+ pageLayout.space.header
}

/// Calculates the maximum offset from the top edge when the main content should break to the next page
Expand Down