@reekon-tools/react-native-pdf-canvas 0.1.1 → 0.2.0

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.
Files changed (121) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +57 -0
  3. package/PdfCanvas.podspec +68 -39
  4. package/README.md +213 -1316
  5. package/android/build.gradle +67 -54
  6. package/android/consumer-rules.pro +7 -0
  7. package/android/src/androidTest/java/tools/reekon/pdfcanvas/PdfCanvasNativeTest.java +254 -0
  8. package/android/src/androidTest/java/tools/reekon/pdfcanvas/TestPdfs.java +60 -468
  9. package/android/src/main/cpp/CMakeLists.txt +54 -0
  10. package/android/src/main/cpp/pdfcanvas-jni.cpp +262 -0
  11. package/android/src/main/java/tools/reekon/pdfcanvas/PdfCanvasNative.java +167 -0
  12. package/android/src/main/java/tools/reekon/pdfcanvas/PdfErrorCode.java +14 -4
  13. package/android/src/main/java/tools/reekon/pdfcanvas/PdfRasterException.java +10 -4
  14. package/android/src/reactnative/java/tools/reekon/pdfcanvas/rn/PdfCanvasModule.java +160 -376
  15. package/android/tools/compile-gate.sh +81 -101
  16. package/dist/controller.d.ts +14 -0
  17. package/dist/controller.js +4 -3
  18. package/dist/rasterizer/index.native.d.ts +8 -12
  19. package/dist/rasterizer/index.native.js +15 -21
  20. package/dist/rasterizer/native-bridge.d.ts +51 -75
  21. package/dist/rasterizer/native-bridge.js +49 -33
  22. package/dist/rasterizer/native.d.ts +45 -0
  23. package/dist/rasterizer/native.js +123 -0
  24. package/dist/react/usePdfDocument.d.ts +5 -5
  25. package/dist/react/usePdfLayer.d.ts +10 -1
  26. package/dist/react/usePdfLayer.js +10 -2
  27. package/dist/testing/scenes.d.ts +3 -3
  28. package/dist/testing/scenes.js +4 -4
  29. package/dist/types.d.ts +36 -42
  30. package/ios/Sources/PdfCanvasBridge/PdfCanvasModule.mm +234 -536
  31. package/native/.clangd +5 -0
  32. package/native/CMakeLists.txt +89 -0
  33. package/native/core/include/pdfcanvas/document.h +90 -0
  34. package/native/core/include/pdfcanvas/error.h +47 -0
  35. package/native/core/include/pdfcanvas/jsi.h +18 -0
  36. package/native/core/include/pdfcanvas/jsi_config.h +30 -0
  37. package/native/core/include/pdfcanvas/library.h +28 -0
  38. package/native/core/include/pdfcanvas/pixels.h +92 -0
  39. package/native/core/include/pdfcanvas/service.h +87 -0
  40. package/native/core/include/pdfcanvas/slots.h +113 -0
  41. package/native/core/include/pdfcanvas/types.h +110 -0
  42. package/native/core/pdfcanvas-core.cmake +22 -0
  43. package/native/core/src/document.cpp +516 -0
  44. package/native/core/src/error.cpp +29 -0
  45. package/native/core/src/jsi.cpp +66 -0
  46. package/native/core/src/library.cpp +52 -0
  47. package/native/core/src/pixels.cpp +45 -0
  48. package/native/core/src/service.cpp +156 -0
  49. package/native/core/src/slots.cpp +139 -0
  50. package/native/tests/fixtures.cpp +451 -0
  51. package/native/tests/fixtures.h +96 -0
  52. package/native/tests/harness.h +122 -0
  53. package/native/tests/main.cpp +64 -0
  54. package/native/tests/pixels_util.h +126 -0
  55. package/native/tests/test_document.cpp +485 -0
  56. package/native/tests/test_service.cpp +130 -0
  57. package/native/tests/test_slots.cpp +250 -0
  58. package/package.json +27 -7
  59. package/react-native.config.js +5 -2
  60. package/scripts/fetch-pdfium.mjs +487 -0
  61. package/scripts/pdfium-manifest.json +46 -0
  62. package/android/src/androidTest/java/tools/reekon/pdfcanvas/PdfCanvasCancellationTest.java +0 -226
  63. package/android/src/androidTest/java/tools/reekon/pdfcanvas/PdfCanvasConcurrencyTest.java +0 -239
  64. package/android/src/androidTest/java/tools/reekon/pdfcanvas/PdfCanvasDeviceTimingTest.java +0 -251
  65. package/android/src/androidTest/java/tools/reekon/pdfcanvas/PdfCanvasFailureTest.java +0 -221
  66. package/android/src/androidTest/java/tools/reekon/pdfcanvas/PdfCanvasJsiTransportTest.java +0 -783
  67. package/android/src/androidTest/java/tools/reekon/pdfcanvas/PdfCanvasPhaseTimingTest.java +0 -1388
  68. package/android/src/androidTest/java/tools/reekon/pdfcanvas/PdfCanvasPoisonGuardTest.java +0 -98
  69. package/android/src/androidTest/java/tools/reekon/pdfcanvas/PdfCanvasQuirksTest.java +0 -324
  70. package/android/src/androidTest/java/tools/reekon/pdfcanvas/PdfCanvasRasterizerTest.java +0 -775
  71. package/android/src/androidTest/java/tools/reekon/pdfcanvas/PoisonsTheProcess.java +0 -20
  72. package/android/src/jsi/cpp/CMakeLists.txt +0 -33
  73. package/android/src/jsi/cpp/pdfcanvas-jsi.cpp +0 -469
  74. package/android/src/jsi/java/tools/reekon/pdfcanvas/jsi/PdfCanvasPixelBridge.java +0 -140
  75. package/android/src/main/java/tools/reekon/pdfcanvas/PageGeometry.java +0 -45
  76. package/android/src/main/java/tools/reekon/pdfcanvas/PdfCanvasRasterizer.java +0 -564
  77. package/android/src/main/java/tools/reekon/pdfcanvas/PdfPlatformQuirks.java +0 -277
  78. package/android/src/main/java/tools/reekon/pdfcanvas/PdfPreflight.java +0 -214
  79. package/android/src/main/java/tools/reekon/pdfcanvas/PdfRendererPool.java +0 -234
  80. package/android/src/main/java/tools/reekon/pdfcanvas/RasterCancellation.java +0 -47
  81. package/android/src/main/java/tools/reekon/pdfcanvas/RasterPixels.java +0 -143
  82. package/android/src/main/java/tools/reekon/pdfcanvas/RasterRequest.java +0 -95
  83. package/dist/rasterizer/android.d.ts +0 -121
  84. package/dist/rasterizer/android.js +0 -126
  85. package/dist/rasterizer/ios.d.ts +0 -84
  86. package/dist/rasterizer/ios.js +0 -155
  87. package/ios/Package.swift +0 -58
  88. package/ios/Sources/PdfCanvasCore/PdfCanvasCancellation.m +0 -38
  89. package/ios/Sources/PdfCanvasCore/PdfCanvasDocumentPool.m +0 -389
  90. package/ios/Sources/PdfCanvasCore/PdfCanvasErrorCode.m +0 -57
  91. package/ios/Sources/PdfCanvasCore/PdfCanvasPageGeometry.m +0 -44
  92. package/ios/Sources/PdfCanvasCore/PdfCanvasPageTransform.m +0 -82
  93. package/ios/Sources/PdfCanvasCore/PdfCanvasPixelSink.m +0 -37
  94. package/ios/Sources/PdfCanvasCore/PdfCanvasPreflight.m +0 -158
  95. package/ios/Sources/PdfCanvasCore/PdfCanvasRasterPixels.m +0 -80
  96. package/ios/Sources/PdfCanvasCore/PdfCanvasRasterRequest.m +0 -65
  97. package/ios/Sources/PdfCanvasCore/PdfCanvasRasterizer.m +0 -548
  98. package/ios/Sources/PdfCanvasCore/include/PdfCanvasCancellation.h +0 -48
  99. package/ios/Sources/PdfCanvasCore/include/PdfCanvasCore.h +0 -26
  100. package/ios/Sources/PdfCanvasCore/include/PdfCanvasDocumentPool.h +0 -122
  101. package/ios/Sources/PdfCanvasCore/include/PdfCanvasErrorCode.h +0 -80
  102. package/ios/Sources/PdfCanvasCore/include/PdfCanvasPageGeometry.h +0 -79
  103. package/ios/Sources/PdfCanvasCore/include/PdfCanvasPageTransform.h +0 -129
  104. package/ios/Sources/PdfCanvasCore/include/PdfCanvasPixelSink.h +0 -100
  105. package/ios/Sources/PdfCanvasCore/include/PdfCanvasPreflight.h +0 -65
  106. package/ios/Sources/PdfCanvasCore/include/PdfCanvasRasterPixels.h +0 -111
  107. package/ios/Sources/PdfCanvasCore/include/PdfCanvasRasterRequest.h +0 -85
  108. package/ios/Sources/PdfCanvasCore/include/PdfCanvasRasterizer.h +0 -163
  109. package/ios/Sources/PdfCanvasSlots/PdfCanvasSlots.mm +0 -297
  110. package/ios/Sources/PdfCanvasSlots/include/PdfCanvasSlots.h +0 -140
  111. package/ios/Tests/PdfCanvasCoreTests/ConcurrencyTests.swift +0 -358
  112. package/ios/Tests/PdfCanvasCoreTests/FailureTests.swift +0 -262
  113. package/ios/Tests/PdfCanvasCoreTests/GeometryTests.swift +0 -173
  114. package/ios/Tests/PdfCanvasCoreTests/PreviewTests.swift +0 -114
  115. package/ios/Tests/PdfCanvasCoreTests/RasterAssertions.swift +0 -158
  116. package/ios/Tests/PdfCanvasCoreTests/RasterizerTests.swift +0 -544
  117. package/ios/Tests/PdfCanvasCoreTests/SinkTests.swift +0 -287
  118. package/ios/Tests/PdfCanvasCoreTests/SlotsTests.swift +0 -396
  119. package/ios/Tests/PdfCanvasCoreTests/TestPdfs.swift +0 -639
  120. package/ios/Tests/PdfCanvasCoreTests/TimingTests.swift +0 -179
  121. package/ios/Tests/PdfCanvasCoreTests/TransformTests.swift +0 -283
package/dist/types.d.ts CHANGED
@@ -66,10 +66,10 @@ export declare class PdfError extends Error {
66
66
  });
67
67
  }
68
68
  /**
69
- * Byte order of a raster. The three backends produce different orderings and
70
- * the descriptor travels with the bytes rather than being assumed:
71
- * PDFium emits BGRA natively (or RGBA with FPDF_REVERSE_BYTE_ORDER), Android
72
- * Bitmap ARGB_8888 is RGBA in memory, CGBitmapContext is configured explicitly.
69
+ * Byte order of a raster. The descriptor travels with the bytes rather than
70
+ * being assumed: PDFium emits BGRA natively and RGBA with
71
+ * `FPDF_REVERSE_BYTE_ORDER`, and every backend this package ships asks for the
72
+ * latter — but a backend that did not would still be describable.
73
73
  */
74
74
  export type PixelFormat = 'rgba8888' | 'bgra8888';
75
75
  /**
@@ -82,22 +82,22 @@ export type PixelFormat = 'rgba8888' | 'bgra8888';
82
82
  * therefore worse.
83
83
  *
84
84
  * `'premultiplied'` — each channel is already scaled by alpha, so a 62%-covered
85
- * white edge is stored `[158, 158, 158, 158]`. Android's `Bitmap` ARGB_8888 is
86
- * this by default (`isPremultiplied()` is true unless a caller opts out) and so
87
- * is a `CGBitmapContext` created `kCGImageAlphaPremultipliedFirst`.
85
+ * white edge is stored `[158, 158, 158, 158]`. Android's `Bitmap` ARGB_8888 and
86
+ * a `CGBitmapContext` are both this, which is what the two retired native cores
87
+ * produced.
88
88
  *
89
89
  * `'straight'` — the channels carry the colour and alpha carries the coverage
90
90
  * independently, so the same edge is stored `[255, 255, 255, 158]`. MEASURED:
91
91
  * PDFium reads `[255, 255, 255, 157]` and pdf.js `[255, 255, 255, 160]` for an
92
92
  * antialiased opaque-white edge over a transparent page; premultiplied would
93
- * have been `~[157, 157, 157, 157]`. A canvas `getImageData` buffer is likewise
94
- * straight (a 50% grey patch reads `[128, 128, 128, 128]`).
93
+ * have been `~[157, 157, 157, 157]`. Every backend this package ships is PDFium
94
+ * and declares `'straight'`; the fake declares what it writes.
95
95
  *
96
- * NOT DEFAULTABLE, on purpose. Two of the three engines this package knows about
97
- * emit `'straight'` and one emits `'premultiplied'`, so there is no default that
98
- * is right more often than it is wrong — and a default is exactly how a global
99
- * `AlphaType.Premul` constant survived in `ingest.ts` until the first backend
100
- * that renders `background: 'transparent'` would have been silently wrong.
96
+ * NOT DEFAULTABLE, on purpose, even now that the shipped answers agree. A
97
+ * default is exactly how a global `AlphaType.Premul` constant survived in
98
+ * `ingest.ts` until the first backend that rendered `background: 'transparent'`
99
+ * would have been silently wrong, and a host-injected backend can still be
100
+ * either.
101
101
  *
102
102
  * INVISIBLE UNDER `background: 'white'`. A fully opaque pixel is byte-identical
103
103
  * in both encodings, which is why this can be stated wrongly for a long time
@@ -209,12 +209,14 @@ export interface RasterRequest {
209
209
  /** Device pixels per PDF point. */
210
210
  scale: number;
211
211
  /**
212
- * Whether PDF-embedded annotations are drawn into the raster.
212
+ * Whether PDF-embedded annotations — and form fields, which are widget
213
+ * annotations — are drawn into the raster.
213
214
  *
214
- * TRUE for file rasters (thumbnails, print) — that is what the outgoing
215
- * react-native-pdf-thumbnail did via PDFKit, and the app depends on it.
216
- * FALSE for tiles, because the Skia layer draws the app's own annotations and
217
- * they would double-draw.
215
+ * TRUE by default everywhere: file rasters (thumbnails, print) and the
216
+ * layer's tiles alike, so a page looks as it does in any other viewer. FALSE
217
+ * is for a host that imports the PDF's annotations into its own layer and
218
+ * would otherwise draw each one twice (`UsePdfLayerOptions.annotations`).
219
+ * Every shipped backend is PDFium and honours both values identically.
218
220
  */
219
221
  annotations: boolean;
220
222
  background: 'white' | 'transparent';
@@ -230,31 +232,23 @@ export interface RasterizerCapabilities {
230
232
  /**
231
233
  * How many `render` calls this backend can usefully have in flight at once.
232
234
  *
233
- * A PROPERTY OF THE BACKEND, never a constant in the controller. Android's
234
- * ceiling is the `PdfRendererPool` size — each slot is one more `PdfRenderer`
235
- * on its own dup'd file descriptor, and a request beyond that blocks on the
236
- * pool's queue rather than doing anything. A backend with one document handle
237
- * and no pool declares 1 and is scheduled exactly as it is today.
235
+ * A PROPERTY OF THE BACKEND, never a constant in the controller. OPTIONAL,
236
+ * DEFAULTING TO 1, and that default is the safe one: an unaware backend keeps
237
+ * the strictly-sequential behaviour it was written against. The controller
238
+ * reads it as `min(bound, plan.items.length)`.
238
239
  *
239
- * OPTIONAL, DEFAULTING TO 1, and that default is the safe one: an unaware
240
- * backend keeps the strictly-sequential behaviour it was written against. The
241
- * controller reads it as `min(bound, plan.items.length)`.
240
+ * EVERY SHIPPED BACKEND DECLARES 1, because PDFium is not thread-safe — not
241
+ * across documents, not across threads — and each backend serialises every
242
+ * call behind one lock. It was measured before it was a rule: on an LG V60
243
+ * (Snapdragon 865) the platform `PdfRenderer` — PDFium behind AOSP's own
244
+ * lock — ran every lane count above one SLOWER on real drawings, because the
245
+ * lock convoyed. What buys responsiveness instead is cancellation: the native
246
+ * core stops a superseded tile mid-render, so a stale render never holds the
247
+ * lock for longer than one progressive batch.
242
248
  *
243
- * IT IS NOT A PROMISE OF SPEEDUP, AND ON ANDROID IT IS A PROMISE OF THE
244
- * OPPOSITE. Measured on an LG V60 (Snapdragon 865, API 33): AOSP serialises
245
- * `PdfRenderer` behind a process-wide PDFium lock, so `openPage` throughput is
246
- * FLAT at 0.084 / 0.073 / 0.074 ops/ms across 1 / 2 / 4 threads while an
247
- * identical pure-Java workload scales 2.8x — and the lock CONVOYS, so
248
- * contending for it makes each call slower rather than merely unparallel. The
249
- * Android backend therefore declares 1. It used to declare 2 to PIPELINE its
250
- * base64 decode against the next tile's native work; the JSI transport deleted
251
- * that decode, and re-measuring on the JSI path put every lane count above 1
252
- * behind it on real documents. See `AndroidRasterizerOptions.poolSize` for the
253
- * numbers.
254
- *
255
- * A backend whose rasterizing genuinely parallelises should still declare it.
256
- * The lane machinery is not Android-specific and the controller has no opinion;
257
- * this field is where a backend states what it can actually do.
249
+ * A host-injected backend whose rasterizing genuinely parallelises should
250
+ * still declare it. The lane machinery is engine-agnostic and the controller
251
+ * has no opinion; this field is where a backend states what it can do.
258
252
  */
259
253
  maxConcurrentRenders?: number;
260
254
  /**