Skip to content
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
67 changes: 67 additions & 0 deletions Source/API/Pagination/PDFPagination.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
//
// PDFPagination.swift
// TPPDF
//
// Created by Philip Niedertscheider on 11/08/2017.
//

#if os(iOS)
import UIKit
#elseif os(macOS)
import AppKit
#endif

/**
* Structure used to configure the pagination
*/
public struct PDFPagination {
/// Container where the pagination will be placed
public var container: PDFContainer

/// Style of the pagination
public var style: PDFPaginationStyle

/**
* Range of pages which will be paginated
*
* This range starts at zero
*/
public var range: (start: Int, end: Int)

/**
* Add a page number to this list to exclude it from the pagination
*
* This will not skip the page but instead not render the pagination object
*/
public var hiddenPages: [Int]

/**
* Text attribtues are used to create the attributed pagination string
*
* See ``NSAttributedString`` for reference
*/
public var textAttributes: [NSAttributedString.Key: Any]

/**
* Creates a new pagination configuration
*
* - Parameters;
* - container: Container where pagination is placed, defaults to `PDFContainer.none`, meaning it won't be rendered
* - style: Style of pagination
* - range: Start and end of pages which will be included
* - hiddenPages: List of numbers which are excluded from rendering
*/
public init(
container: PDFContainer = .none,
style: PDFPaginationStyle = .default,
range: (start: Int, end: Int) = (0, Int.max),
hiddenPages: [Int] = [],
textAttributes: [NSAttributedString.Key: Any] = [:]
) {
self.container = container
self.style = style
self.range = range
self.hiddenPages = hiddenPages
self.textAttributes = textAttributes
}
}
16 changes: 16 additions & 0 deletions Source/API/Pagination/PDFPaginationClosure.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// PDFPaginationClosure.swift
// TPPDF
//
// Created by Philip Niedertscheider on 04/11/2017.
//

/**
* Closure for custom pagination formatting.
*
* - Parameter page: `Int` - Current page number
* - Parameter total: `Int` - Total amount of pages
*
* - Returns: Formatted pagination string
*/
public typealias PDFPaginationClosure = (_ page: Int, _ total: Int) -> String
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ extension PDFPaginationStyle: Equatable {
}

if case PDFPaginationStyle.customClosure = lhs, case PDFPaginationStyle.customClosure = rhs {
// Always return false if a custom closure is used
// https://stackoverflow.com/questions/24111984/how-do-you-test-functions-and-closures-for-equality
// Always return false if a custom closure is used, because closures can not be equated
// Reference: https://stackoverflow.com/questions/24111984/how-do-you-test-functions-and-closures-for-equality
return false
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,52 +5,46 @@
// Created by Philip Niedertscheider on 13/06/2017.
//

#if os(iOS)
import UIKit
#elseif os(macOS)
import AppKit
#endif
import Foundation

/**
Use predefined pagination styles or create a custom one, using `.CustomNumberFormat` or `.CustomClosure`.

Enums using a template String as parameter will replace the first instance of `%@` with the index and the second one with the total amount of pages.
* Use predefined pagination styles or create a custom one, using `.CustomNumberFormat` or `.CustomClosure`.
*
* Enums using a template String as parameter will replace the first instance of `%@` with the index and the second one with the total amount of pages.
*/
public enum PDFPaginationStyle {
/**
Default format, concats current page and total pages with a dash.

e.g. Converts page 1 of 3 to **"1 - 3"**
* Default format, concats current page and total pages with a dash.
*
* e.g. Converts page 1 of 3 to **"1 - 3"**
*/
case `default`

/**
Returns pagination in roman numerals.

- Parameter template: Template `String`, instances of `%@` will be replaced.
* Returns pagination in roman numerals.
*
* - Parameter template: Template `String`, instances of `%@` will be replaced.
*/
case roman(template: String)

/**
Formats pagination numbers using the `formatter` and formatting the string using the given `template`.

- Parameter template: Template string where `$@` is replaced
- Parameter formatter: Number formatter
* Formats pagination numbers using the `formatter` and formatting the string using the given `template`.
*
* - Parameter template: Template string where `$@` is replaced
* - Parameter formatter: Number formatter
*/
case customNumberFormat(template: String, formatter: NumberFormatter)

/**
Formats the pagination using the provided closure
*/
/// Formats the pagination using the provided closure
case customClosure(PDFPaginationClosure)

/**
Creates formatted pagination string.

- Parameter page: `Int` - Current page
- Parameter total: `Int` - Total amount of pages.

- Returns: Formatted `String`
* Creates formatted pagination string.
*
* - Parameter page: Current page
* - Parameter total: Total amount of pages.
*
* - Returns: Formatted `String`
*/
public func format(page: Int, total: Int) -> String {
switch self {
Expand Down
63 changes: 0 additions & 63 deletions Source/Internal/Pagination/PDFPagination.swift

This file was deleted.

16 changes: 0 additions & 16 deletions Source/Internal/Pagination/PDFPaginationClosure.swift

This file was deleted.

18 changes: 5 additions & 13 deletions TPPDF.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
D4B30533293CA38600EA24C5 /* PDFPageFormat+NameConstants.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4B30532293CA38600EA24C5 /* PDFPageFormat+NameConstants.swift */; };
D4E1FB2C294DE37800D654C7 /* PDFGeneratorImageDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4E1FB2A294DE37800D654C7 /* PDFGeneratorImageDelegate.swift */; };
D4E1FB2D294DE37800D654C7 /* PDFGeneratorDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4E1FB2B294DE37800D654C7 /* PDFGeneratorDelegate.swift */; };
D4E49EED2BF11C0300BC7B0A /* Int+RomanNumerals.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4E49EEC2BF11C0200BC7B0A /* Int+RomanNumerals.swift */; };
OBJ_415 /* CwlCatchException.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_356 /* CwlCatchException.swift */; };
OBJ_417 /* CwlCatchExceptionSupport.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = "CwlCatchException::CwlCatchExceptionSupport::Product" /* CwlCatchExceptionSupport.framework */; };
OBJ_425 /* Package.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_362 /* Package.swift */; };
Expand Down Expand Up @@ -215,8 +216,6 @@
OBJ_673 /* PDFLineSeparatorObject.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_106 /* PDFLineSeparatorObject.swift */; };
OBJ_674 /* PDFRectangleObject.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_107 /* PDFRectangleObject.swift */; };
OBJ_675 /* UIColor+CloseToEqual.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_108 /* UIColor+CloseToEqual.swift */; };
OBJ_676 /* UIColor+Hex.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_109 /* UIColor+Hex.swift */; };
OBJ_677 /* UIImage+Pixel.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_110 /* UIImage+Pixel.swift */; };
OBJ_678 /* PDFGroupObject.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_112 /* PDFGroupObject.swift */; };
OBJ_679 /* PDFImageObject.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_114 /* PDFImageObject.swift */; };
OBJ_680 /* PDFImageRowObject.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_115 /* PDFImageRowObject.swift */; };
Expand All @@ -242,7 +241,6 @@
OBJ_700 /* CGPoint+Null.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_138 /* CGPoint+Null.swift */; };
OBJ_701 /* PDFGenerator+Debug.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_139 /* PDFGenerator+Debug.swift */; };
OBJ_702 /* PDFGenerator+Layout.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_140 /* PDFGenerator+Layout.swift */; };
OBJ_703 /* Int+RomanNumerals.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_142 /* Int+RomanNumerals.swift */; };
OBJ_704 /* PDFPagination+Equatable.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_143 /* PDFPagination+Equatable.swift */; };
OBJ_705 /* PDFPagination.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_144 /* PDFPagination.swift */; };
OBJ_706 /* PDFPaginationClosure.swift in Sources */ = {isa = PBXBuildFile; fileRef = OBJ_145 /* PDFPaginationClosure.swift */; };
Expand Down Expand Up @@ -639,6 +637,7 @@
D4B30532293CA38600EA24C5 /* PDFPageFormat+NameConstants.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "PDFPageFormat+NameConstants.swift"; sourceTree = "<group>"; };
D4E1FB2A294DE37800D654C7 /* PDFGeneratorImageDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PDFGeneratorImageDelegate.swift; sourceTree = "<group>"; };
D4E1FB2B294DE37800D654C7 /* PDFGeneratorDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PDFGeneratorDelegate.swift; sourceTree = "<group>"; };
D4E49EEC2BF11C0200BC7B0A /* Int+RomanNumerals.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Int+RomanNumerals.swift"; sourceTree = "<group>"; };
"Nimble::Nimble::Product" /* Nimble.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Nimble.framework; sourceTree = BUILT_PRODUCTS_DIR; };
OBJ_10 /* PDFExternalDocument.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PDFExternalDocument.swift; sourceTree = "<group>"; };
OBJ_101 /* PDFContext.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PDFContext.swift; sourceTree = "<group>"; };
Expand All @@ -649,8 +648,6 @@
OBJ_106 /* PDFLineSeparatorObject.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PDFLineSeparatorObject.swift; sourceTree = "<group>"; };
OBJ_107 /* PDFRectangleObject.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PDFRectangleObject.swift; sourceTree = "<group>"; };
OBJ_108 /* UIColor+CloseToEqual.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIColor+CloseToEqual.swift"; sourceTree = "<group>"; };
OBJ_109 /* UIColor+Hex.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIColor+Hex.swift"; sourceTree = "<group>"; };
OBJ_110 /* UIImage+Pixel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIImage+Pixel.swift"; sourceTree = "<group>"; };
OBJ_112 /* PDFGroupObject.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PDFGroupObject.swift; sourceTree = "<group>"; };
OBJ_114 /* PDFImageObject.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PDFImageObject.swift; sourceTree = "<group>"; };
OBJ_115 /* PDFImageRowObject.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PDFImageRowObject.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -679,7 +676,6 @@
OBJ_139 /* PDFGenerator+Debug.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "PDFGenerator+Debug.swift"; sourceTree = "<group>"; };
OBJ_14 /* PDFBezierPathVertex.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PDFBezierPathVertex.swift; sourceTree = "<group>"; };
OBJ_140 /* PDFGenerator+Layout.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "PDFGenerator+Layout.swift"; sourceTree = "<group>"; };
OBJ_142 /* Int+RomanNumerals.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Int+RomanNumerals.swift"; sourceTree = "<group>"; };
OBJ_143 /* PDFPagination+Equatable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "PDFPagination+Equatable.swift"; sourceTree = "<group>"; };
OBJ_144 /* PDFPagination.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PDFPagination.swift; sourceTree = "<group>"; };
OBJ_145 /* PDFPaginationClosure.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PDFPaginationClosure.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1135,8 +1131,6 @@
OBJ_106 /* PDFLineSeparatorObject.swift */,
OBJ_107 /* PDFRectangleObject.swift */,
OBJ_108 /* UIColor+CloseToEqual.swift */,
OBJ_109 /* UIColor+Hex.swift */,
OBJ_110 /* UIImage+Pixel.swift */,
);
path = Graphics;
sourceTree = "<group>";
Expand Down Expand Up @@ -1215,7 +1209,6 @@
OBJ_141 /* Pagination */ = {
isa = PBXGroup;
children = (
OBJ_142 /* Int+RomanNumerals.swift */,
OBJ_143 /* PDFPagination+Equatable.swift */,
OBJ_144 /* PDFPagination.swift */,
OBJ_145 /* PDFPaginationClosure.swift */,
Expand Down Expand Up @@ -1268,6 +1261,7 @@
OBJ_164 /* Utils */ = {
isa = PBXGroup;
children = (
D4E49EEC2BF11C0200BC7B0A /* Int+RomanNumerals.swift */,
OBJ_165 /* Attributes */,
OBJ_168 /* CustomStringConvertible+AutoDescribing.swift */,
OBJ_169 /* FileManager+TemporaryFiles.swift */,
Expand Down Expand Up @@ -2014,6 +2008,7 @@
OBJ_51 /* Table */,
OBJ_49 /* Table Of Content */,
OBJ_82 /* Text */,
OBJ_141 /* Pagination */,
OBJ_88 /* Utils */,
);
path = API;
Expand Down Expand Up @@ -2065,7 +2060,6 @@
OBJ_136 /* Math */,
OBJ_139 /* PDFGenerator+Debug.swift */,
OBJ_140 /* PDFGenerator+Layout.swift */,
OBJ_141 /* Pagination */,
OBJ_148 /* Section */,
OBJ_152 /* Table Of Content */,
OBJ_154 /* Table */,
Expand Down Expand Up @@ -2628,6 +2622,7 @@
D49B05E92658E76C0084A0B7 /* PDFDocumentBackground.swift in Sources */,
OBJ_624 /* PDFSection.swift in Sources */,
OBJ_625 /* PDFSectionColumn.swift in Sources */,
D4E49EED2BF11C0300BC7B0A /* Int+RomanNumerals.swift in Sources */,
OBJ_626 /* PDFTableOfContent.swift in Sources */,
OBJ_627 /* NSAttributedString+PDFTableContent.swift in Sources */,
OBJ_628 /* Number+PDFTableContentable.swift in Sources */,
Expand Down Expand Up @@ -2680,8 +2675,6 @@
OBJ_673 /* PDFLineSeparatorObject.swift in Sources */,
OBJ_674 /* PDFRectangleObject.swift in Sources */,
OBJ_675 /* UIColor+CloseToEqual.swift in Sources */,
OBJ_676 /* UIColor+Hex.swift in Sources */,
OBJ_677 /* UIImage+Pixel.swift in Sources */,
OBJ_678 /* PDFGroupObject.swift in Sources */,
OBJ_679 /* PDFImageObject.swift in Sources */,
OBJ_680 /* PDFImageRowObject.swift in Sources */,
Expand All @@ -2708,7 +2701,6 @@
OBJ_700 /* CGPoint+Null.swift in Sources */,
OBJ_701 /* PDFGenerator+Debug.swift in Sources */,
OBJ_702 /* PDFGenerator+Layout.swift in Sources */,
OBJ_703 /* Int+RomanNumerals.swift in Sources */,
D49B05E82658E76C0084A0B7 /* PDFDocument.swift in Sources */,
OBJ_704 /* PDFPagination+Equatable.swift in Sources */,
OBJ_705 /* PDFPagination.swift in Sources */,
Expand Down