@reekon-tools/react-native-pdf-canvas 0.1.0 → 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.
- package/LICENSE +202 -0
- package/NOTICE +57 -0
- package/PdfCanvas.podspec +68 -39
- package/README.md +213 -1316
- package/android/build.gradle +67 -54
- package/android/consumer-rules.pro +7 -0
- package/android/src/androidTest/java/tools/reekon/pdfcanvas/PdfCanvasNativeTest.java +254 -0
- package/android/src/androidTest/java/tools/reekon/pdfcanvas/TestPdfs.java +60 -468
- package/android/src/main/cpp/CMakeLists.txt +54 -0
- package/android/src/main/cpp/pdfcanvas-jni.cpp +262 -0
- package/android/src/main/java/tools/reekon/pdfcanvas/PdfCanvasNative.java +167 -0
- package/android/src/main/java/tools/reekon/pdfcanvas/PdfErrorCode.java +14 -4
- package/android/src/main/java/tools/reekon/pdfcanvas/PdfRasterException.java +10 -4
- package/android/src/reactnative/java/tools/reekon/pdfcanvas/rn/PdfCanvasModule.java +160 -376
- package/android/tools/compile-gate.sh +81 -101
- package/dist/controller.d.ts +14 -0
- package/dist/controller.js +4 -3
- package/dist/index.native.d.ts +5 -0
- package/dist/index.native.js +5 -0
- package/dist/index.web.d.ts +10 -0
- package/dist/index.web.js +10 -0
- package/dist/rasterizer/index.native.d.ts +8 -12
- package/dist/rasterizer/index.native.js +15 -21
- package/dist/rasterizer/native-bridge.d.ts +51 -75
- package/dist/rasterizer/native-bridge.js +49 -33
- package/dist/rasterizer/native.d.ts +45 -0
- package/dist/rasterizer/native.js +123 -0
- package/dist/react/usePdfDocument.d.ts +5 -5
- package/dist/react/usePdfLayer.d.ts +10 -1
- package/dist/react/usePdfLayer.js +10 -2
- package/dist/skia/index.native.d.ts +7 -3
- package/dist/skia/index.native.js +7 -3
- package/dist/skia/index.web.d.ts +4 -2
- package/dist/skia/index.web.js +4 -2
- package/dist/testing/scenes.d.ts +3 -3
- package/dist/testing/scenes.js +4 -4
- package/dist/types.d.ts +36 -42
- package/ios/Sources/PdfCanvasBridge/PdfCanvasModule.mm +234 -536
- package/native/.clangd +5 -0
- package/native/CMakeLists.txt +89 -0
- package/native/core/include/pdfcanvas/document.h +90 -0
- package/native/core/include/pdfcanvas/error.h +47 -0
- package/native/core/include/pdfcanvas/jsi.h +18 -0
- package/native/core/include/pdfcanvas/jsi_config.h +30 -0
- package/native/core/include/pdfcanvas/library.h +28 -0
- package/native/core/include/pdfcanvas/pixels.h +92 -0
- package/native/core/include/pdfcanvas/service.h +87 -0
- package/native/core/include/pdfcanvas/slots.h +113 -0
- package/native/core/include/pdfcanvas/types.h +110 -0
- package/native/core/pdfcanvas-core.cmake +22 -0
- package/native/core/src/document.cpp +516 -0
- package/native/core/src/error.cpp +29 -0
- package/native/core/src/jsi.cpp +66 -0
- package/native/core/src/library.cpp +52 -0
- package/native/core/src/pixels.cpp +45 -0
- package/native/core/src/service.cpp +156 -0
- package/native/core/src/slots.cpp +139 -0
- package/native/tests/fixtures.cpp +451 -0
- package/native/tests/fixtures.h +96 -0
- package/native/tests/harness.h +122 -0
- package/native/tests/main.cpp +64 -0
- package/native/tests/pixels_util.h +126 -0
- package/native/tests/test_document.cpp +485 -0
- package/native/tests/test_service.cpp +130 -0
- package/native/tests/test_slots.cpp +250 -0
- package/package.json +38 -8
- package/react-native.config.js +5 -2
- package/scripts/fetch-pdfium.mjs +487 -0
- package/scripts/pdfium-manifest.json +46 -0
- package/android/src/androidTest/java/tools/reekon/pdfcanvas/PdfCanvasCancellationTest.java +0 -226
- package/android/src/androidTest/java/tools/reekon/pdfcanvas/PdfCanvasConcurrencyTest.java +0 -239
- package/android/src/androidTest/java/tools/reekon/pdfcanvas/PdfCanvasDeviceTimingTest.java +0 -251
- package/android/src/androidTest/java/tools/reekon/pdfcanvas/PdfCanvasFailureTest.java +0 -221
- package/android/src/androidTest/java/tools/reekon/pdfcanvas/PdfCanvasJsiTransportTest.java +0 -783
- package/android/src/androidTest/java/tools/reekon/pdfcanvas/PdfCanvasPhaseTimingTest.java +0 -1388
- package/android/src/androidTest/java/tools/reekon/pdfcanvas/PdfCanvasPoisonGuardTest.java +0 -98
- package/android/src/androidTest/java/tools/reekon/pdfcanvas/PdfCanvasQuirksTest.java +0 -324
- package/android/src/androidTest/java/tools/reekon/pdfcanvas/PdfCanvasRasterizerTest.java +0 -775
- package/android/src/androidTest/java/tools/reekon/pdfcanvas/PoisonsTheProcess.java +0 -20
- package/android/src/jsi/cpp/CMakeLists.txt +0 -33
- package/android/src/jsi/cpp/pdfcanvas-jsi.cpp +0 -469
- package/android/src/jsi/java/tools/reekon/pdfcanvas/jsi/PdfCanvasPixelBridge.java +0 -140
- package/android/src/main/java/tools/reekon/pdfcanvas/PageGeometry.java +0 -45
- package/android/src/main/java/tools/reekon/pdfcanvas/PdfCanvasRasterizer.java +0 -564
- package/android/src/main/java/tools/reekon/pdfcanvas/PdfPlatformQuirks.java +0 -277
- package/android/src/main/java/tools/reekon/pdfcanvas/PdfPreflight.java +0 -214
- package/android/src/main/java/tools/reekon/pdfcanvas/PdfRendererPool.java +0 -234
- package/android/src/main/java/tools/reekon/pdfcanvas/RasterCancellation.java +0 -47
- package/android/src/main/java/tools/reekon/pdfcanvas/RasterPixels.java +0 -143
- package/android/src/main/java/tools/reekon/pdfcanvas/RasterRequest.java +0 -95
- package/dist/rasterizer/android.d.ts +0 -121
- package/dist/rasterizer/android.js +0 -126
- package/dist/rasterizer/ios.d.ts +0 -84
- package/dist/rasterizer/ios.js +0 -155
- package/ios/Package.swift +0 -58
- package/ios/Sources/PdfCanvasCore/PdfCanvasCancellation.m +0 -38
- package/ios/Sources/PdfCanvasCore/PdfCanvasDocumentPool.m +0 -389
- package/ios/Sources/PdfCanvasCore/PdfCanvasErrorCode.m +0 -57
- package/ios/Sources/PdfCanvasCore/PdfCanvasPageGeometry.m +0 -44
- package/ios/Sources/PdfCanvasCore/PdfCanvasPageTransform.m +0 -82
- package/ios/Sources/PdfCanvasCore/PdfCanvasPixelSink.m +0 -37
- package/ios/Sources/PdfCanvasCore/PdfCanvasPreflight.m +0 -158
- package/ios/Sources/PdfCanvasCore/PdfCanvasRasterPixels.m +0 -80
- package/ios/Sources/PdfCanvasCore/PdfCanvasRasterRequest.m +0 -65
- package/ios/Sources/PdfCanvasCore/PdfCanvasRasterizer.m +0 -548
- package/ios/Sources/PdfCanvasCore/include/PdfCanvasCancellation.h +0 -48
- package/ios/Sources/PdfCanvasCore/include/PdfCanvasCore.h +0 -26
- package/ios/Sources/PdfCanvasCore/include/PdfCanvasDocumentPool.h +0 -122
- package/ios/Sources/PdfCanvasCore/include/PdfCanvasErrorCode.h +0 -80
- package/ios/Sources/PdfCanvasCore/include/PdfCanvasPageGeometry.h +0 -79
- package/ios/Sources/PdfCanvasCore/include/PdfCanvasPageTransform.h +0 -129
- package/ios/Sources/PdfCanvasCore/include/PdfCanvasPixelSink.h +0 -100
- package/ios/Sources/PdfCanvasCore/include/PdfCanvasPreflight.h +0 -65
- package/ios/Sources/PdfCanvasCore/include/PdfCanvasRasterPixels.h +0 -111
- package/ios/Sources/PdfCanvasCore/include/PdfCanvasRasterRequest.h +0 -85
- package/ios/Sources/PdfCanvasCore/include/PdfCanvasRasterizer.h +0 -163
- package/ios/Sources/PdfCanvasSlots/PdfCanvasSlots.mm +0 -297
- package/ios/Sources/PdfCanvasSlots/include/PdfCanvasSlots.h +0 -140
- package/ios/Tests/PdfCanvasCoreTests/ConcurrencyTests.swift +0 -358
- package/ios/Tests/PdfCanvasCoreTests/FailureTests.swift +0 -262
- package/ios/Tests/PdfCanvasCoreTests/GeometryTests.swift +0 -173
- package/ios/Tests/PdfCanvasCoreTests/PreviewTests.swift +0 -114
- package/ios/Tests/PdfCanvasCoreTests/RasterAssertions.swift +0 -158
- package/ios/Tests/PdfCanvasCoreTests/RasterizerTests.swift +0 -544
- package/ios/Tests/PdfCanvasCoreTests/SinkTests.swift +0 -287
- package/ios/Tests/PdfCanvasCoreTests/SlotsTests.swift +0 -396
- package/ios/Tests/PdfCanvasCoreTests/TestPdfs.swift +0 -639
- package/ios/Tests/PdfCanvasCoreTests/TimingTests.swift +0 -179
- package/ios/Tests/PdfCanvasCoreTests/TransformTests.swift +0 -283
package/dist/skia/index.web.js
CHANGED
|
@@ -6,8 +6,10 @@
|
|
|
6
6
|
* install itself decides nothing: it stores a closure, and
|
|
7
7
|
* `globalThis.CanvasKit` is not read until the first raster.
|
|
8
8
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
9
|
+
* This file is named in `package.json#sideEffects`, and must stay there: it
|
|
10
|
+
* declares no binding of its own, so without the listing Rollup never marks it
|
|
11
|
+
* executed and the install below is dropped. See `index.native.ts` and
|
|
12
|
+
* `__tests__/tree-shaking.test.ts`.
|
|
11
13
|
*/
|
|
12
14
|
import { installWebSkiaResolver } from './resolve.web.js';
|
|
13
15
|
export * from './index.js';
|
package/dist/testing/scenes.d.ts
CHANGED
|
@@ -90,9 +90,9 @@ export interface ReferenceScene {
|
|
|
90
90
|
/**
|
|
91
91
|
* Plan item -> backend request.
|
|
92
92
|
*
|
|
93
|
-
* `annotations:
|
|
94
|
-
* for in production (
|
|
95
|
-
* buffer composites as black — see `ingest.ts`).
|
|
93
|
+
* `annotations: true` and `background: 'white'` match what the tile path asks
|
|
94
|
+
* for in production (a page looks as it does in any other viewer, and an
|
|
95
|
+
* unfilled buffer composites as black — see `ingest.ts`).
|
|
96
96
|
*/
|
|
97
97
|
export declare function sceneRasterRequest(item: RasterPlanItem, over?: Partial<RasterRequest>): RasterRequest;
|
|
98
98
|
export declare function sceneRasterMeta(item: RasterPlanItem, epoch?: number): RasterIngestMeta;
|
package/dist/testing/scenes.js
CHANGED
|
@@ -46,16 +46,16 @@ export function docRectToCanvas(transform, rect) {
|
|
|
46
46
|
/**
|
|
47
47
|
* Plan item -> backend request.
|
|
48
48
|
*
|
|
49
|
-
* `annotations:
|
|
50
|
-
* for in production (
|
|
51
|
-
* buffer composites as black — see `ingest.ts`).
|
|
49
|
+
* `annotations: true` and `background: 'white'` match what the tile path asks
|
|
50
|
+
* for in production (a page looks as it does in any other viewer, and an
|
|
51
|
+
* unfilled buffer composites as black — see `ingest.ts`).
|
|
52
52
|
*/
|
|
53
53
|
export function sceneRasterRequest(item, over = {}) {
|
|
54
54
|
return {
|
|
55
55
|
page: item.page,
|
|
56
56
|
docRect: item.docRect,
|
|
57
57
|
scale: item.scale,
|
|
58
|
-
annotations:
|
|
58
|
+
annotations: true,
|
|
59
59
|
background: 'white',
|
|
60
60
|
...over,
|
|
61
61
|
};
|
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
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
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
|
|
86
|
-
*
|
|
87
|
-
*
|
|
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]`.
|
|
94
|
-
*
|
|
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
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
*
|
|
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
|
|
212
|
+
* Whether PDF-embedded annotations — and form fields, which are widget
|
|
213
|
+
* annotations — are drawn into the raster.
|
|
213
214
|
*
|
|
214
|
-
* TRUE
|
|
215
|
-
*
|
|
216
|
-
*
|
|
217
|
-
*
|
|
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.
|
|
234
|
-
*
|
|
235
|
-
*
|
|
236
|
-
*
|
|
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
|
-
*
|
|
240
|
-
*
|
|
241
|
-
*
|
|
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
|
-
*
|
|
244
|
-
*
|
|
245
|
-
*
|
|
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
|
/**
|