@tobyt/expo-pdf-markup 1.1.2 → 1.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @tobyt/expo-pdf-markup
2
2
 
3
+ ## 1.1.3
4
+
5
+ ### Patch Changes
6
+
7
+ - 5bb3360: Work around an iOS 27 beta PDFKit regression where `PDFAnnotation.add(_:)`/`.paths` silently drops ink annotation stroke geometry. Ink annotations now store and render their own stroke data instead of relying on PDFKit's built-in ink storage, so drawing, persisting, erasing and moving ink markup continues to behave correctly on iOS 27.
8
+
3
9
  ## 1.1.2
4
10
 
5
11
  ### Patch Changes
@@ -97,9 +97,9 @@ enum AnnotationSerializer {
97
97
  switch model.type {
98
98
  case "ink":
99
99
  model.lineWidth = annotation.border?.lineWidth ?? 2.0
100
- if let bezierPaths = annotation.paths {
101
- model.paths = bezierPaths.map { path in
102
- pointsFromBezierPath(path).map { ["x": $0.x, "y": $0.y] }
100
+ if let inkAnnotation = annotation as? InkPDFAnnotation {
101
+ model.paths = inkAnnotation.strokes.map { stroke in
102
+ stroke.map { ["x": $0.x, "y": $0.y] }
103
103
  }
104
104
  }
105
105
  case "highlight", "underline":
@@ -209,23 +209,15 @@ enum AnnotationSerializer {
209
209
  annotationBounds = combinedRect.insetBy(dx: -padding, dy: -padding)
210
210
  }
211
211
 
212
- let annotation = PDFAnnotation(bounds: annotationBounds, forType: .ink, withProperties: nil)
212
+ let annotation = InkPDFAnnotation(bounds: annotationBounds, forType: .ink, withProperties: nil)
213
213
  annotation.color = color
214
214
 
215
215
  let border = PDFBorder()
216
216
  border.lineWidth = lineWidth
217
217
  annotation.border = border
218
218
 
219
- for path in paths {
220
- let bezierPath = UIBezierPath()
221
- for (index, point) in path.enumerated() {
222
- if index == 0 {
223
- bezierPath.move(to: CGPoint(x: point.x, y: point.y))
224
- } else {
225
- bezierPath.addLine(to: CGPoint(x: point.x, y: point.y))
226
- }
227
- }
228
- annotation.add(bezierPath)
219
+ annotation.strokes = paths.map { path in
220
+ path.map { CGPoint(x: $0.x, y: $0.y) }
229
221
  }
230
222
 
231
223
  let createdAt = model.createdAt ?? Date().timeIntervalSince1970
@@ -294,24 +286,4 @@ enum AnnotationSerializer {
294
286
  height: height
295
287
  )
296
288
  }
297
-
298
- private static func pointsFromBezierPath(_ path: UIBezierPath) -> [CGPoint] {
299
- var points: [CGPoint] = []
300
- let cgPath = path.cgPath
301
- cgPath.applyWithBlock { element in
302
- switch element.pointee.type {
303
- case .moveToPoint, .addLineToPoint:
304
- points.append(element.pointee.points[0])
305
- case .addQuadCurveToPoint:
306
- points.append(element.pointee.points[1])
307
- case .addCurveToPoint:
308
- points.append(element.pointee.points[2])
309
- case .closeSubpath:
310
- break
311
- @unknown default:
312
- break
313
- }
314
- }
315
- return points
316
- }
317
289
  }
@@ -94,22 +94,14 @@ extension ExpoPdfMarkupView {
94
94
  // and tight bounds calculations are fragile with coordinate transforms.
95
95
  let annotationBounds = page.bounds(for: pdfView.displayBox)
96
96
 
97
- let annotation = PDFAnnotation(bounds: annotationBounds, forType: .ink, withProperties: nil)
97
+ let annotation = InkPDFAnnotation(bounds: annotationBounds, forType: .ink, withProperties: nil)
98
98
  annotation.color = AnnotationSerializer.colorFromHex(annotationColor) ?? .red
99
99
 
100
100
  let border = PDFBorder()
101
101
  border.lineWidth = annotationLineWidth
102
102
  annotation.border = border
103
103
 
104
- let bezierPath = UIBezierPath()
105
- for (index, point) in pdfPoints.enumerated() {
106
- if index == 0 {
107
- bezierPath.move(to: point)
108
- } else {
109
- bezierPath.addLine(to: point)
110
- }
111
- }
112
- annotation.add(bezierPath)
104
+ annotation.strokes = [pdfPoints]
113
105
 
114
106
  let id = UUID().uuidString
115
107
  AnnotationSerializer.tagAsModuleManaged(annotation, id: id, createdAt: Date().timeIntervalSince1970)
@@ -166,10 +166,11 @@ extension ExpoPdfMarkupView {
166
166
  in documentView: UIView
167
167
  ) -> CGRect? {
168
168
  let pdfRect: CGRect
169
- if let paths = annotation.paths, !paths.isEmpty {
169
+ if let inkAnnotation = annotation as? InkPDFAnnotation, !inkAnnotation.strokes.isEmpty {
170
170
  var combinedBounds = CGRect.null
171
- for path in paths {
172
- combinedBounds = combinedBounds.union(path.cgPath.boundingBoxOfPath)
171
+ for stroke in inkAnnotation.strokes {
172
+ guard let cgPath = InkPDFAnnotation.cgPath(for: stroke) else { continue }
173
+ combinedBounds = combinedBounds.union(cgPath.boundingBoxOfPath)
173
174
  }
174
175
  guard !combinedBounds.isNull else { return nil }
175
176
  let padding = max(annotation.border?.lineWidth ?? 2.0, 10.0)
@@ -272,10 +272,11 @@ class ExpoPdfMarkupView: ExpoView, UIGestureRecognizerDelegate {
272
272
  for annotation in page.annotations.reversed() {
273
273
  guard AnnotationSerializer.isModuleManaged(annotation) else { continue }
274
274
 
275
- if let paths = annotation.paths {
275
+ if let inkAnnotation = annotation as? InkPDFAnnotation {
276
276
  let tolerance = max(annotation.border?.lineWidth ?? 2.0, 10.0)
277
- for path in paths {
278
- let hitPath = path.cgPath.copy(
277
+ for stroke in inkAnnotation.strokes {
278
+ guard let cgPath = InkPDFAnnotation.cgPath(for: stroke) else { continue }
279
+ let hitPath = cgPath.copy(
279
280
  strokingWithWidth: tolerance,
280
281
  lineCap: .round,
281
282
  lineJoin: .round,
@@ -0,0 +1,45 @@
1
+ import PDFKit
2
+ import UIKit
3
+
4
+ /// Renders freehand ink strokes as a PDFKit annotation, storing and drawing the stroke
5
+ /// geometry itself rather than going through `PDFAnnotation.add(_:)` / `.paths`. iOS 27 beta
6
+ /// has a PDFKit regression where those APIs silently drop ink stroke geometry (see report/),
7
+ /// so this class sidesteps them entirely — matching the pattern `StampPDFAnnotation` already
8
+ /// uses for its own custom-drawn content.
9
+ final class InkPDFAnnotation: PDFAnnotation {
10
+ var strokes: [[CGPoint]] = []
11
+
12
+ required init?(coder: NSCoder) {
13
+ super.init(coder: coder)
14
+ }
15
+
16
+ override init(bounds: CGRect, forType type: PDFAnnotationSubtype, withProperties properties: [AnyHashable: Any]?) {
17
+ super.init(bounds: bounds, forType: type, withProperties: properties)
18
+ }
19
+
20
+ override func draw(with _: PDFDisplayBox, in context: CGContext) {
21
+ guard !strokes.isEmpty else { return }
22
+
23
+ context.saveGState()
24
+ context.setStrokeColor((color ?? .red).cgColor)
25
+ context.setLineWidth(border?.lineWidth ?? 2.0)
26
+ context.setLineCap(.round)
27
+ context.setLineJoin(.round)
28
+ for stroke in strokes {
29
+ guard let path = Self.cgPath(for: stroke) else { continue }
30
+ context.addPath(path)
31
+ }
32
+ context.strokePath()
33
+ context.restoreGState()
34
+ }
35
+
36
+ static func cgPath(for points: [CGPoint]) -> CGPath? {
37
+ guard let first = points.first else { return nil }
38
+ let path = CGMutablePath()
39
+ path.move(to: first)
40
+ for point in points.dropFirst() {
41
+ path.addLine(to: point)
42
+ }
43
+ return path
44
+ }
45
+ }
@@ -168,6 +168,32 @@ final class AnnotationSerializerTests: XCTestCase {
168
168
  XCTAssertEqual(result.type, "ink")
169
169
  XCTAssertEqual(result.page, 0)
170
170
  XCTAssertEqual(result.color, "#FF0000")
171
+ XCTAssertEqual(
172
+ result.decodedPaths,
173
+ [[AnnotationPoint(x: 10, y: 20), AnnotationPoint(x: 30, y: 40)]]
174
+ )
175
+ }
176
+
177
+ func testInkAnnotationStoresStrokesOnCustomSubclass() throws {
178
+ let model = AnnotationModel(
179
+ id: "ink-strokes-1",
180
+ type: "ink",
181
+ page: 0,
182
+ color: "#00FF00",
183
+ lineWidth: 4.0,
184
+ paths: [[["x": 1, "y": 2], ["x": 3, "y": 4]], [["x": 5, "y": 6]]],
185
+ createdAt: 1_741_340_000
186
+ )
187
+
188
+ let annotation = try XCTUnwrap(AnnotationSerializer.toPDFAnnotation(model))
189
+ let inkAnnotation = try XCTUnwrap(annotation as? InkPDFAnnotation)
190
+
191
+ // Regression coverage: on iOS 27 beta, PDFAnnotation.paths silently drops stroke
192
+ // geometry added via .add(_:), so ink annotations must not depend on it (report/).
193
+ XCTAssertEqual(
194
+ inkAnnotation.strokes,
195
+ [[CGPoint(x: 1, y: 2), CGPoint(x: 3, y: 4)], [CGPoint(x: 5, y: 6)]]
196
+ )
171
197
  }
172
198
 
173
199
  func testFreeTextColorRoundTrip() throws {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tobyt/expo-pdf-markup",
3
- "version": "1.1.2",
3
+ "version": "1.1.3",
4
4
  "description": "An Expo module for displaying and annotating PDFs",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",