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

Fix formatting issues #339

Merged
merged 2 commits into from
May 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion Source/API/Delegation/PDFGeneratorImageDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ public protocol PDFGeneratorImageDelegate: AnyObject {

public extension PDFGeneratorImageDelegate {

func generator(willBeginDrawingImage image: PDFImage, with context: PDFContext, in frame: CGRect){}
func generator(willBeginDrawingImage image: PDFImage, with context: PDFContext, in frame: CGRect) {}

}
2 changes: 1 addition & 1 deletion Source/API/PDFGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public class PDFGenerator: PDFGeneratorProtocol, CustomStringConvertible {
Relative value tracking progress
*/
public let progress = Progress.discreteProgress(totalUnitCount: 3)

/// Object acts as a delegate during the generation process
public var delegate: PDFGeneratorDelegate?

Expand Down
10 changes: 5 additions & 5 deletions Source/API/Page Format/PDFPageFormat+NameConstants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import AppKit
Source for names: https://www.papersizes.org
*/
public extension PDFPageFormat {

/**
Returns the defined US names if this format is a US format.
If it is not a US format, it will check other constants for correct name
Expand All @@ -30,7 +30,7 @@ public extension PDFPageFormat {
return name
}
}

/**
Returns the defined ANSI name if this format is a ANSI format.
If it is not a ANSI format, it will check other constants for correct name
Expand All @@ -51,7 +51,7 @@ public extension PDFPageFormat {
return name
}
}

/**
Returns the defined A-Series name if this format is a A-Series format.
If it is not a A-Series format, it will check other constants for correct name
Expand Down Expand Up @@ -84,7 +84,7 @@ public extension PDFPageFormat {
return name
}
}

/**
Returns the defined B-Series name if this format is a B-Series format.
If it is not a B-Series format, it will check other constants for correct name
Expand Down Expand Up @@ -117,7 +117,7 @@ public extension PDFPageFormat {
return name
}
}

/**
Returns the defined C-Series name if this format is a C-Series format.
If it is not a C-Series format, it will check other constants for correct name
Expand Down
2 changes: 1 addition & 1 deletion Source/API/Page Format/PDFPageFormat.swift
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public enum PDFPageFormat: String, CaseIterable {
public var landscapeSize: CGSize {
CGSize(width: size.height, height: size.width)
}

/**
Name defined in constants
*/
Expand Down
4 changes: 2 additions & 2 deletions Source/API/Text/PDFAttributedText.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ public class PDFAttributedText: PDFText {
}

// MARK: - Hashable
public override func hash(into hasher: inout Hasher) {

override public func hash(into hasher: inout Hasher) {
hasher.combine(text)
}
}
2 changes: 1 addition & 1 deletion Source/API/Text/PDFSimpleText.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public class PDFSimpleText: PDFText {
}

// MARK: - Hashable

override public func hash(into hasher: inout Hasher) {
hasher.combine(text)
hasher.combine(spacing)
Expand Down
1 change: 0 additions & 1 deletion Source/API/Text/PDFText.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,3 @@ public class PDFText: PDFDocumentObject, CustomStringConvertible {
fatalError()
}
}

15 changes: 7 additions & 8 deletions Source/Internal/Table/PDFTableObject.swift
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ internal class PDFTableObject: PDFRenderObject {
headerCells += cells[rowIdx]
rowIdx += 1
}

// Safety check to make sure we don't reference rows we don't have.
// This handles the case where we have a header row, but no data rows.
if rowIdx >= table.size.rows {
Expand Down Expand Up @@ -291,7 +291,6 @@ internal class PDFTableObject: PDFRenderObject {
var nextPageCells: [PDFTableCalculatedCell] = cells
var pageEnd = CGPoint.null
var headerShift = table.showHeadersOnEveryPage


repeat {
var pageStart = CGPoint.null
Expand Down Expand Up @@ -347,7 +346,7 @@ internal class PDFTableObject: PDFRenderObject {
nextPageCells = shiftCellsBy(cells: nextPageCells, shiftValue: headerHeight)
headerShift = false
}
//add table padding around cells
// add table padding around cells
nextPageCells = shiftCellsBy(cells: nextPageCells, shiftValue: table.margin)
}

Expand Down Expand Up @@ -468,22 +467,22 @@ internal class PDFTableObject: PDFRenderObject {
}
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 {
Expand Down
4 changes: 2 additions & 2 deletions Source/Internal/Text/PDFAttributedTextObject.swift
Original file line number Diff line number Diff line change
Expand Up @@ -205,14 +205,14 @@ internal class PDFAttributedTextObject: PDFRenderObject {
}
let startOffset = CTLineGetOffsetForStringIndex(metric.line, intersection.location, nil)
let endOffset = CTLineGetOffsetForStringIndex(metric.line, intersection.location + intersection.length, nil)

let linkFrame = CGRect(
x: self.frame.origin.x + startOffset,
y: metric.bounds.origin.y,
width: endOffset - startOffset,
height: metric.bounds.height)
attributes.append((attribute: .link(url: url), frame: linkFrame))

if debug {
PDFGraphics.drawRect(in: context,
rect: linkFrame,
Expand Down
9 changes: 4 additions & 5 deletions Source/Internal/Utils/PDFCalculations.swift
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ internal enum PDFCalculations {
- generator.currentPadding.right
}


/// Calculates the available height in a given `container` on the current page.
/// If the container is a header or a footer container, it has no limits and therefore returns the full page layout height
///
Expand Down Expand Up @@ -384,7 +383,7 @@ internal enum PDFCalculations {
position: (origin: CGPoint, width: CGFloat),
text: NSAttributedString,
alignment: PDFTableCellAlignment) -> CGRect {
let textMaxHeight = CGFloat.greatestFiniteMagnitude //PDFCalculations.calculateAvailableFrameHeight(for: generator, in: container)
let textMaxHeight = CGFloat.greatestFiniteMagnitude // PDFCalculations.calculateAvailableFrameHeight(for: generator, in: container)
let frame: CGRect = CGRect(x: position.origin.x, y: position.origin.y, width: position.width, height: textMaxHeight)

let currentRange = CFRange(location: 0, length: 0)
Expand All @@ -409,17 +408,17 @@ internal enum PDFCalculations {
let imageSize = image.size
var imageHeight = 0.0
var imageWidth = 0.0

// scale down only if the image's width is larger than the cell's width

if imageSize.width > width {
imageHeight = imageSize.height / imageSize.width * width
imageWidth = width
} else {
imageHeight = imageSize.height
imageWidth = imageSize.width
}

return CGRect(x: origin.x, y: origin.y, width: imageWidth, height: imageHeight)
}

Expand Down