-
-
Notifications
You must be signed in to change notification settings - Fork 122
/
PDFSlicedObject.swift
44 lines (39 loc) · 1.08 KB
/
PDFSlicedObject.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
//
// PDFSlicedObject.swift
// TPPDF
//
// Created by Philip Niedertscheider on 06.01.20.
//
#if os(iOS)
import UIKit
#elseif os(macOS)
import AppKit
#endif
import CoreGraphics
class PDFSlicedObject: PDFRenderObject {
var children: [PDFRenderObject]
init(children: [PDFRenderObject] = [], frame: CGRect = .null) {
self.children = children
super.init()
self.frame = frame
}
override func calculate(generator _: PDFGenerator, container: PDFContainer) throws -> [PDFLocatedRenderObject] {
[
(container, self)
]
}
override func draw(generator: PDFGenerator, container: PDFContainer, in context: PDFContext) throws {
if frame != .null {
context.saveGState()
context.beginPath()
context.addPath(BezierPath(rect: frame).cgPath)
context.clip()
}
for child in children {
try child.draw(generator: generator, container: container, in: context)
}
if frame != .null {
context.restoreGState()
}
}
}