Skip to content
Closed
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
13 changes: 13 additions & 0 deletions Source/API/Image/PDFImage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,16 @@ public class PDFImage: PDFDocumentObject {
cornerRadius: self.cornerRadius)
}
}


extension PDFImage: Hashable {
public func hash(into hasher: inout Hasher) {
hasher.combine(image)
hasher.combine(caption)
hasher.combine(NSCoder.string(for: size))
hasher.combine(sizeFit)
hasher.combine(quality)
hasher.combine(options.rawValue)
hasher.combine(cornerRadius)
}
}
3 changes: 3 additions & 0 deletions Source/API/PDFGenerator+Generation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,9 @@ extension PDFGenerator {
*/
internal func render(object: PDFRenderObject, in container: PDFContainer, in context: CGContext) throws {
try object.draw(generator: self, container: container, in: context)
if let imageObject = object as? PDFImageObject {
imageDelegate?.generator(willBeginDrawingImage: imageObject.image, with: context, in: object.frame)
}
}

// MARK: - INTERNAL STATIC FUNCS
Expand Down
5 changes: 5 additions & 0 deletions Source/API/PDFGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ public class PDFGenerator: PDFGeneratorProtocol, CustomStringConvertible {
Relative value tracking progress
*/
public let progress = Progress.discreteProgress(totalUnitCount: 3)

/**
Delegate for image processing. Called after resizing and scaling and before drawing.
*/
public var imageDelegate: PDFGeneratorImageDelegate?

/**
Font of each container.
Expand Down
14 changes: 14 additions & 0 deletions Source/API/PDFGeneratorImageDelegate.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// PDFGeneratorImageDelegate.swift
// TPPDF
//
// Created by Chris Gonzales on 10/10/20.
//

import Foundation

public protocol PDFGeneratorImageDelegate: class {
func generator(willBeginDrawingImage image: PDFImage, with context: CGContext, in frame: CGRect)
}

typealias PDFGeneratorDelegate = PDFGeneratorImageDelegate // for extensibility
22 changes: 0 additions & 22 deletions Source/API/Text/PDFAttributedText+Equatable.swift

This file was deleted.

14 changes: 14 additions & 0 deletions Source/API/Text/PDFAttributedText.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,18 @@ public class PDFAttributedText: PDFText {
override internal var copy: PDFText {
PDFAttributedText(text: text)
}

public override func hash(into hasher: inout Hasher) {
hasher.combine(text)
}

/**
TODO: Documentation
*/
public static func == (lhs: PDFAttributedText, rhs: PDFAttributedText) -> Bool {
guard lhs.text == rhs.text else {
return false
}
return true
}
}
25 changes: 0 additions & 25 deletions Source/API/Text/PDFSimpleText+Equatable.swift

This file was deleted.

15 changes: 15 additions & 0 deletions Source/API/Text/PDFSimpleText.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,19 @@ public class PDFSimpleText: PDFText {
override internal var copy: PDFText {
PDFSimpleText(text: self.text, spacing: self.spacing, style: self.style)
}

override public func hash(into hasher: inout Hasher) {
hasher.combine(text)
hasher.combine(spacing)
}

public static func == (lhs: PDFSimpleText, rhs: PDFSimpleText) -> Bool {
guard lhs.text == rhs.text else {
return false
}
guard lhs.spacing == rhs.spacing else {
return false
}
return true
}
}
7 changes: 6 additions & 1 deletion Source/API/Text/PDFText.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
/**
Protocol all text objects should implement
*/
public class PDFText: PDFDocumentObject, CustomStringConvertible {
public class PDFText: PDFDocumentObject, CustomStringConvertible, Hashable {

/**
TODO: Documentation
Expand All @@ -35,4 +35,9 @@ public class PDFText: PDFDocumentObject, CustomStringConvertible {
}
return false
}

public func hash(into hasher: inout Hasher) {
fatalError()
}
}