From 600ce8b060134a80f926a00047e19be27957cf48 Mon Sep 17 00:00:00 2001 From: Dean Moore Date: Thu, 7 Jan 2021 09:44:45 -0500 Subject: [PATCH 1/3] Removed print statements --- Source/Internal/Graphics/PDFContext.swift | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/Source/Internal/Graphics/PDFContext.swift b/Source/Internal/Graphics/PDFContext.swift index 2f3fdfc0..e060248a 100644 --- a/Source/Internal/Graphics/PDFContext.swift +++ b/Source/Internal/Graphics/PDFContext.swift @@ -32,21 +32,18 @@ public class PDFContext { internal func beginPDFPage(_ pageInfo: CFDictionary?) { // Do not create page immediately, instead invoke it as soon as necessary - print("beginPDFPage") delayedCommands.append(.beginPDFPage(pageConfig: pageInfo)) currentPageContainsDrawnContent = false hasActivePage = true } internal func endPDFPage() { - print("endPDFPage") applyDelayedCommands() cgContext.endPDFPage() hasActivePage = false } internal func closePDF() { - print("closePDFPage") applyDelayedCommands() cgContext.closePDF() hasActivePage = false @@ -61,33 +58,28 @@ public class PDFContext { // MARK: - Translation internal func translateBy(x: CGFloat, y: CGFloat) { - print("translateBy") delayedCommands.append(.translateBy(x: x, y: y)) } internal func scaleBy(x: CGFloat, y: CGFloat) { - print("scaleBy") delayedCommands.append(.scaleBy(x: x, y: y)) } // MARK: - Drawing internal func drawPath(using mode: CGPathDrawingMode) { - print("drawPath") applyDelayedCommands() cgContext.drawPath(using: mode) currentPageContainsDrawnContent = true } internal func drawPDFPage(_ page: CGPDFPage) { - print("drawPDFPage") applyDelayedCommands() cgContext.drawPDFPage(page) currentPageContainsDrawnContent = true } internal func draw(image: CGImage, in frame: CGRect, flipped: Bool) { - print("draw(image:)") applyDelayedCommands() cgContext.draw(image: image, in: frame, flipped: flipped) currentPageContainsDrawnContent = true @@ -96,7 +88,6 @@ public class PDFContext { // MARK: - Colors internal func setFillColor(_ color: CGColor) { - print("setFillColor") applyDelayedCommands() cgContext.setFillColor(color) currentPageContainsDrawnContent = true @@ -105,42 +96,36 @@ public class PDFContext { // MARK: - Paths internal func beginPath() { - print("beginPath") applyDelayedCommands() cgContext.beginPath() currentPageContainsDrawnContent = true } internal func addPath(_ path: CGPath) { - print("addPath") applyDelayedCommands() cgContext.addPath(path) currentPageContainsDrawnContent = true } internal func setLineDash(phase: CGFloat, lengths: [CGFloat]) { - print("setLineDash") applyDelayedCommands() cgContext.setLineDash(phase: phase, lengths: lengths) currentPageContainsDrawnContent = true } internal func setLineCap(_ cap: CGLineCap) { - print("setLineCap") applyDelayedCommands() cgContext.setLineCap(cap) currentPageContainsDrawnContent = true } internal func setLineWidth(_ width: CGFloat) { - print("setLineWidth") applyDelayedCommands() cgContext.setLineWidth(width) currentPageContainsDrawnContent = true } internal func setStrokeColor(_ color: CGColor) { - print("setStrokeColor") applyDelayedCommands() cgContext.setStrokeColor(color) currentPageContainsDrawnContent = true @@ -149,13 +134,11 @@ public class PDFContext { // MARK: - State internal func saveGState() { - print("saveGState") applyDelayedCommands() cgContext.saveGState() } internal func restoreGState() { - print("restoreGState") applyDelayedCommands() cgContext.restoreGState() } @@ -172,7 +155,6 @@ public class PDFContext { } internal func draw(ctFrame frameRef: CTFrame) { - print("draw(ctFrame:)") applyDelayedCommands() CTFrameDraw(frameRef, cgContext) currentPageContainsDrawnContent = true @@ -181,7 +163,6 @@ public class PDFContext { // MARK: - Masking internal func clip() { - print("clip") applyDelayedCommands() cgContext.clip() currentPageContainsDrawnContent = true @@ -190,7 +171,6 @@ public class PDFContext { // MARK: - Metadata internal func setURL(_ url: CFURL, for rect: CGRect) { - print("setURL") applyDelayedCommands() cgContext.setURL(url, for: rect) currentPageContainsDrawnContent = true From 838c74f439ed2ae05e5b5a8a5abeaed4ce5795fe Mon Sep 17 00:00:00 2001 From: Dean Moore Date: Thu, 7 Jan 2021 09:47:30 -0500 Subject: [PATCH 2/3] Fix for missing space.header on pages > 1 --- Source/Internal/Utils/PDFCalculations.swift | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Source/Internal/Utils/PDFCalculations.swift b/Source/Internal/Utils/PDFCalculations.swift index aaff5eed..ca37e9c6 100644 --- a/Source/Internal/Utils/PDFCalculations.swift +++ b/Source/Internal/Utils/PDFCalculations.swift @@ -144,6 +144,7 @@ internal enum PDFCalculations { return pageLayout.height - layout.margin.top - layout.heights.maxHeaderHeight() + - pageLayout.space.header - layout.heights.content - generator.currentPadding.bottom - layout.heights.maxFooterHeight() @@ -153,8 +154,10 @@ internal enum PDFCalculations { 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 From b32ee079bda52eb93a839e2c2fb7450ffc464cd9 Mon Sep 17 00:00:00 2001 From: Dean Moore Date: Thu, 7 Jan 2021 10:10:17 -0500 Subject: [PATCH 3/3] Fix to shift rows below header on pages > 1 --- Source/Internal/Table/PDFTableObject.swift | 33 ++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/Source/Internal/Table/PDFTableObject.swift b/Source/Internal/Table/PDFTableObject.swift index 7a631307..7e12fe92 100644 --- a/Source/Internal/Table/PDFTableObject.swift +++ b/Source/Internal/Table/PDFTableObject.swift @@ -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 repeat { var pageStart = CGPoint.null @@ -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) @@ -329,6 +332,13 @@ 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 + } + } let filterResult = filterCellsOnPage(for: generator, items: nextPageCells, @@ -448,9 +458,32 @@ internal class PDFTableObject: PDFRenderObject { result.remainder.append(nextPageCell) } } + // reposition the cells with the top of the page )minOffset) + if let cellFrame = result.remainder.first { + if cellFrame.frames.cell.origin.y < minOffset { + // if cells are higher up on the page than minOffset, shift them down + let shiftValue = minOffset - cellFrame.frames.cell.origin.y + result.remainder = shiftCellsBy(cells: result.remainder, shiftValue: shiftValue) + } + } return result } + internal typealias ShiftedCells = ([PDFTableCalculatedCell]) + + 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 {