@embedpdf/engines 2.6.2 → 2.8.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/dist/{direct-engine-CmsmBgWP.js → direct-engine-BOkKwXM0.js} +290 -6
- package/dist/direct-engine-BOkKwXM0.js.map +1 -0
- package/dist/direct-engine-DQgFpJUz.cjs +2 -0
- package/dist/direct-engine-DQgFpJUz.cjs.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +8 -2
- package/dist/index.js.map +1 -1
- package/dist/lib/orchestrator/pdf-engine.d.ts +10 -2
- package/dist/lib/orchestrator/remote-executor.d.ts +5 -2
- package/dist/lib/pdfium/engine.d.ts +39 -2
- package/dist/lib/pdfium/index.cjs +1 -1
- package/dist/lib/pdfium/index.js +3 -3
- package/dist/lib/pdfium/web/direct-engine.cjs +1 -1
- package/dist/lib/pdfium/web/direct-engine.js +2 -2
- package/dist/lib/pdfium/web/worker-engine.cjs +1 -1
- package/dist/lib/pdfium/web/worker-engine.cjs.map +1 -1
- package/dist/lib/pdfium/web/worker-engine.js +7 -4
- package/dist/lib/pdfium/web/worker-engine.js.map +1 -1
- package/dist/lib/webworker/engine.cjs +1 -1
- package/dist/lib/webworker/engine.cjs.map +1 -1
- package/dist/lib/webworker/engine.d.ts +6 -2
- package/dist/lib/webworker/engine.js +27 -2
- package/dist/lib/webworker/engine.js.map +1 -1
- package/dist/pdf-engine-DeyImjZt.cjs +2 -0
- package/dist/pdf-engine-DeyImjZt.cjs.map +1 -0
- package/dist/{pdf-engine-C07l7iNd.js → pdf-engine-ZvReuoDb.js} +84 -3
- package/dist/pdf-engine-ZvReuoDb.js.map +1 -0
- package/dist/preact/index.cjs +1 -1
- package/dist/preact/index.js +1 -1
- package/dist/react/index.cjs +1 -1
- package/dist/react/index.js +1 -1
- package/dist/svelte/index.cjs +1 -1
- package/dist/svelte/index.js +1 -1
- package/dist/vue/index.cjs +1 -1
- package/dist/vue/index.js +1 -1
- package/package.json +6 -6
- package/dist/direct-engine-CCVjfywm.cjs +0 -2
- package/dist/direct-engine-CCVjfywm.cjs.map +0 -1
- package/dist/direct-engine-CmsmBgWP.js.map +0 -1
- package/dist/pdf-engine-C07l7iNd.js.map +0 -1
- package/dist/pdf-engine-DUjCt3HC.cjs +0 -2
- package/dist/pdf-engine-DUjCt3HC.cjs.map +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { init } from "@embedpdf/pdfium";
|
|
2
|
-
import { Rotation, NoopLogger, PdfTaskHelper, PdfErrorCode, pdfDateToDate, isUuidV4, uuidV4, PdfAnnotationSubtype, PdfPageFlattenFlag, stripPdfUnwantedMarkers, PdfAnnotationIcon,
|
|
3
|
-
import { P as PdfEngine } from "./pdf-engine-
|
|
2
|
+
import { Rotation, NoopLogger, PdfTaskHelper, PdfErrorCode, pdfDateToDate, isUuidV4, uuidV4, PdfAnnotationSubtype, PdfPageFlattenFlag, stripPdfUnwantedMarkers, PdfAnnotationIcon, PdfAnnotationColorType, PdfAnnotationBorderStyle, PdfAnnotationLineEnding, PdfStandardFont, PdfStampFit, PdfTrappedStatus, pdfColorToWebColor, webColorToPdfColor, pdfAlphaToWebOpacity, webOpacityToPdfAlpha, PdfAnnotationReplyType, dateToPdfDate, quadToRect, rectToQuad, PdfPageObjectType, flagsToNames, namesToFlags, PDF_FORM_FIELD_TYPE, AppearanceMode, Task, toIntRect, transformRect, buildUserToDeviceMatrix, AP_MODE_NORMAL, AP_MODE_ROLLOVER, AP_MODE_DOWN, PdfZoomMode, PdfActionType } from "@embedpdf/models";
|
|
3
|
+
import { P as PdfEngine } from "./pdf-engine-ZvReuoDb.js";
|
|
4
4
|
import { b as browserImageDataToBlobConverter } from "./browser-BISJ9naB.js";
|
|
5
5
|
function readString(wasmModule, readChars, parseChars, defaultLength = 100) {
|
|
6
6
|
let buffer = wasmModule.wasmExports.malloc(defaultLength);
|
|
@@ -1653,6 +1653,15 @@ class PdfiumNative {
|
|
|
1653
1653
|
saveAnnotation
|
|
1654
1654
|
);
|
|
1655
1655
|
break;
|
|
1656
|
+
case PdfAnnotationSubtype.CARET:
|
|
1657
|
+
isSucceed = this.addCaretContent(
|
|
1658
|
+
doc,
|
|
1659
|
+
page,
|
|
1660
|
+
pageCtx.pagePtr,
|
|
1661
|
+
annotationPtr,
|
|
1662
|
+
saveAnnotation
|
|
1663
|
+
);
|
|
1664
|
+
break;
|
|
1656
1665
|
case PdfAnnotationSubtype.REDACT:
|
|
1657
1666
|
isSucceed = this.addRedactContent(
|
|
1658
1667
|
doc,
|
|
@@ -1704,7 +1713,7 @@ class PdfiumNative {
|
|
|
1704
1713
|
*
|
|
1705
1714
|
* @returns PdfTask<boolean> – true on success
|
|
1706
1715
|
*/
|
|
1707
|
-
updatePageAnnotation(doc, page, annotation) {
|
|
1716
|
+
updatePageAnnotation(doc, page, annotation, options) {
|
|
1708
1717
|
this.logger.debug(LOG_SOURCE, LOG_CATEGORY, "updatePageAnnotation", doc, page, annotation);
|
|
1709
1718
|
this.logger.perf(
|
|
1710
1719
|
LOG_SOURCE,
|
|
@@ -1858,6 +1867,17 @@ class PdfiumNative {
|
|
|
1858
1867
|
);
|
|
1859
1868
|
break;
|
|
1860
1869
|
}
|
|
1870
|
+
/* ── Caret ────────────────────────────────────────────────────────────── */
|
|
1871
|
+
case PdfAnnotationSubtype.CARET: {
|
|
1872
|
+
ok = this.addCaretContent(
|
|
1873
|
+
doc,
|
|
1874
|
+
page,
|
|
1875
|
+
pageCtx.pagePtr,
|
|
1876
|
+
annotPtr,
|
|
1877
|
+
saveAnnotation
|
|
1878
|
+
);
|
|
1879
|
+
break;
|
|
1880
|
+
}
|
|
1861
1881
|
/* ── Redact ───────────────────────────────────────────────────────────── */
|
|
1862
1882
|
case PdfAnnotationSubtype.REDACT: {
|
|
1863
1883
|
ok = this.addRedactContent(
|
|
@@ -1873,7 +1893,7 @@ class PdfiumNative {
|
|
|
1873
1893
|
default:
|
|
1874
1894
|
ok = false;
|
|
1875
1895
|
}
|
|
1876
|
-
if (ok) {
|
|
1896
|
+
if (ok && (options == null ? void 0 : options.regenerateAppearance) !== false) {
|
|
1877
1897
|
if (annotation.blendMode !== void 0) {
|
|
1878
1898
|
this.pdfiumModule.EPDFAnnot_GenerateAppearanceWithBlend(annotPtr, annotation.blendMode);
|
|
1879
1899
|
} else {
|
|
@@ -2860,6 +2880,13 @@ class PdfiumNative {
|
|
|
2860
2880
|
if (annotation.stateModel && !this.setAnnotString(annotationPtr, "StateModel", annotation.stateModel)) {
|
|
2861
2881
|
return false;
|
|
2862
2882
|
}
|
|
2883
|
+
if (!this.setAnnotationOpacity(annotationPtr, annotation.opacity ?? 1)) {
|
|
2884
|
+
return false;
|
|
2885
|
+
}
|
|
2886
|
+
const strokeColor = annotation.strokeColor ?? annotation.color ?? "#FFFF00";
|
|
2887
|
+
if (!this.setAnnotationColor(annotationPtr, strokeColor, PdfAnnotationColorType.Color)) {
|
|
2888
|
+
return false;
|
|
2889
|
+
}
|
|
2863
2890
|
if (!annotation.flags) {
|
|
2864
2891
|
if (!this.setAnnotationFlags(annotationPtr, ["print", "noZoom", "noRotate"])) {
|
|
2865
2892
|
return false;
|
|
@@ -2867,6 +2894,30 @@ class PdfiumNative {
|
|
|
2867
2894
|
}
|
|
2868
2895
|
return this.applyBaseAnnotationProperties(doc, page, pagePtr, annotationPtr, annotation);
|
|
2869
2896
|
}
|
|
2897
|
+
/**
|
|
2898
|
+
* Add caret content to annotation
|
|
2899
|
+
* @param doc - document object
|
|
2900
|
+
* @param page - page info
|
|
2901
|
+
* @param pagePtr - pointer to page object
|
|
2902
|
+
* @param annotationPtr - pointer to caret annotation
|
|
2903
|
+
* @param annotation - caret annotation
|
|
2904
|
+
* @returns whether caret content is added to annotation
|
|
2905
|
+
*
|
|
2906
|
+
* @private
|
|
2907
|
+
*/
|
|
2908
|
+
addCaretContent(doc, page, pagePtr, annotationPtr, annotation) {
|
|
2909
|
+
if (annotation.strokeColor) {
|
|
2910
|
+
this.setAnnotationColor(annotationPtr, annotation.strokeColor, PdfAnnotationColorType.Color);
|
|
2911
|
+
}
|
|
2912
|
+
if (annotation.opacity !== void 0) {
|
|
2913
|
+
this.setAnnotationOpacity(annotationPtr, annotation.opacity);
|
|
2914
|
+
}
|
|
2915
|
+
if (annotation.intent) {
|
|
2916
|
+
this.setAnnotIntent(annotationPtr, annotation.intent);
|
|
2917
|
+
}
|
|
2918
|
+
this.setRectangleDifferences(annotationPtr, annotation.rectangleDifferences);
|
|
2919
|
+
return this.applyBaseAnnotationProperties(doc, page, pagePtr, annotationPtr, annotation);
|
|
2920
|
+
}
|
|
2870
2921
|
/**
|
|
2871
2922
|
* Add free text content to annotation
|
|
2872
2923
|
* @param page - page info
|
|
@@ -2909,6 +2960,7 @@ class PdfiumNative {
|
|
|
2909
2960
|
} else if (!this.setAnnotationColor(annotationPtr, bgColor ?? "#FFFFFF", PdfAnnotationColorType.Color)) {
|
|
2910
2961
|
return false;
|
|
2911
2962
|
}
|
|
2963
|
+
this.setRectangleDifferences(annotationPtr, annotation.rectangleDifferences);
|
|
2912
2964
|
return this.applyBaseAnnotationProperties(doc, page, pagePtr, annotationPtr, annotation);
|
|
2913
2965
|
}
|
|
2914
2966
|
/**
|
|
@@ -3049,6 +3101,12 @@ class PdfiumNative {
|
|
|
3049
3101
|
)) {
|
|
3050
3102
|
return false;
|
|
3051
3103
|
}
|
|
3104
|
+
if (annotation.type === PdfAnnotationSubtype.POLYGON) {
|
|
3105
|
+
this.setRectangleDifferences(
|
|
3106
|
+
annotationPtr,
|
|
3107
|
+
annotation.rectangleDifferences
|
|
3108
|
+
);
|
|
3109
|
+
}
|
|
3052
3110
|
return this.applyBaseAnnotationProperties(doc, page, pagePtr, annotationPtr, annotation);
|
|
3053
3111
|
}
|
|
3054
3112
|
/**
|
|
@@ -3124,6 +3182,7 @@ class PdfiumNative {
|
|
|
3124
3182
|
)) {
|
|
3125
3183
|
return false;
|
|
3126
3184
|
}
|
|
3185
|
+
this.setRectangleDifferences(annotationPtr, annotation.rectangleDifferences);
|
|
3127
3186
|
return this.applyBaseAnnotationProperties(doc, page, pagePtr, annotationPtr, annotation);
|
|
3128
3187
|
}
|
|
3129
3188
|
/**
|
|
@@ -4392,6 +4451,10 @@ class PdfiumNative {
|
|
|
4392
4451
|
}
|
|
4393
4452
|
if (annotation) {
|
|
4394
4453
|
annotation = this.reverseRotateAnnotationOnLoad(annotation);
|
|
4454
|
+
const apModes = this.pdfiumModule.EPDFAnnot_GetAvailableAppearanceModes(annotationPtr);
|
|
4455
|
+
if (apModes) {
|
|
4456
|
+
annotation.appearanceModes = apModes;
|
|
4457
|
+
}
|
|
4395
4458
|
}
|
|
4396
4459
|
return annotation;
|
|
4397
4460
|
}
|
|
@@ -4935,6 +4998,25 @@ class PdfiumNative {
|
|
|
4935
4998
|
this.memoryManager.free(bPtr);
|
|
4936
4999
|
return { ok, left, top, right, bottom };
|
|
4937
5000
|
}
|
|
5001
|
+
/**
|
|
5002
|
+
* Sets the /RD array on an annotation.
|
|
5003
|
+
*
|
|
5004
|
+
* @param annotationPtr pointer to an `FPDF_ANNOTATION`
|
|
5005
|
+
* @param rd the four inset values, or `undefined` to clear
|
|
5006
|
+
* @returns `true` on success
|
|
5007
|
+
*/
|
|
5008
|
+
setRectangleDifferences(annotationPtr, rd) {
|
|
5009
|
+
if (!rd) {
|
|
5010
|
+
return this.pdfiumModule.EPDFAnnot_ClearRectangleDifferences(annotationPtr);
|
|
5011
|
+
}
|
|
5012
|
+
return this.pdfiumModule.EPDFAnnot_SetRectangleDifferences(
|
|
5013
|
+
annotationPtr,
|
|
5014
|
+
rd.left,
|
|
5015
|
+
rd.top,
|
|
5016
|
+
rd.right,
|
|
5017
|
+
rd.bottom
|
|
5018
|
+
);
|
|
5019
|
+
}
|
|
4938
5020
|
/**
|
|
4939
5021
|
* Get the date of the annotation
|
|
4940
5022
|
*
|
|
@@ -5512,6 +5594,7 @@ class PdfiumNative {
|
|
|
5512
5594
|
id: index,
|
|
5513
5595
|
type: PdfAnnotationSubtype.TEXT,
|
|
5514
5596
|
rect,
|
|
5597
|
+
strokeColor: color ?? "#FFFF00",
|
|
5515
5598
|
color: color ?? "#FFFF00",
|
|
5516
5599
|
opacity,
|
|
5517
5600
|
state,
|
|
@@ -5539,6 +5622,7 @@ class PdfiumNative {
|
|
|
5539
5622
|
const verticalAlign = this.getAnnotationVerticalAlignment(annotationPtr);
|
|
5540
5623
|
const opacity = this.getAnnotationOpacity(annotationPtr);
|
|
5541
5624
|
const richContent = this.getAnnotRichContent(annotationPtr);
|
|
5625
|
+
const rd = this.getRectangleDifferences(annotationPtr);
|
|
5542
5626
|
return {
|
|
5543
5627
|
pageIndex: page.index,
|
|
5544
5628
|
id: index,
|
|
@@ -5556,6 +5640,14 @@ class PdfiumNative {
|
|
|
5556
5640
|
textAlign,
|
|
5557
5641
|
defaultStyle,
|
|
5558
5642
|
richContent,
|
|
5643
|
+
...rd.ok && {
|
|
5644
|
+
rectangleDifferences: {
|
|
5645
|
+
left: rd.left,
|
|
5646
|
+
top: rd.top,
|
|
5647
|
+
right: rd.right,
|
|
5648
|
+
bottom: rd.bottom
|
|
5649
|
+
}
|
|
5650
|
+
},
|
|
5559
5651
|
...this.readBaseAnnotationProperties(doc, page, annotationPtr)
|
|
5560
5652
|
};
|
|
5561
5653
|
}
|
|
@@ -5718,6 +5810,7 @@ class PdfiumNative {
|
|
|
5718
5810
|
vertices.pop();
|
|
5719
5811
|
}
|
|
5720
5812
|
}
|
|
5813
|
+
const rd = this.getRectangleDifferences(annotationPtr);
|
|
5721
5814
|
return {
|
|
5722
5815
|
pageIndex: page.index,
|
|
5723
5816
|
id: index,
|
|
@@ -5730,6 +5823,14 @@ class PdfiumNative {
|
|
|
5730
5823
|
strokeStyle,
|
|
5731
5824
|
strokeDashArray,
|
|
5732
5825
|
vertices,
|
|
5826
|
+
...rd.ok && {
|
|
5827
|
+
rectangleDifferences: {
|
|
5828
|
+
left: rd.left,
|
|
5829
|
+
top: rd.top,
|
|
5830
|
+
right: rd.right,
|
|
5831
|
+
bottom: rd.bottom
|
|
5832
|
+
}
|
|
5833
|
+
},
|
|
5733
5834
|
...this.readBaseAnnotationProperties(doc, page, annotationPtr)
|
|
5734
5835
|
};
|
|
5735
5836
|
}
|
|
@@ -5956,11 +6057,26 @@ class PdfiumNative {
|
|
|
5956
6057
|
readPdfCaretAnno(doc, page, annotationPtr, index) {
|
|
5957
6058
|
const pageRect = this.readPageAnnoRect(annotationPtr);
|
|
5958
6059
|
const rect = this.convertPageRectToDeviceRect(doc, page, pageRect);
|
|
6060
|
+
const strokeColor = this.getAnnotationColor(annotationPtr);
|
|
6061
|
+
const opacity = this.getAnnotationOpacity(annotationPtr);
|
|
6062
|
+
const intent = this.getAnnotIntent(annotationPtr);
|
|
6063
|
+
const rd = this.getRectangleDifferences(annotationPtr);
|
|
5959
6064
|
return {
|
|
5960
6065
|
pageIndex: page.index,
|
|
5961
6066
|
id: index,
|
|
5962
6067
|
type: PdfAnnotationSubtype.CARET,
|
|
5963
6068
|
rect,
|
|
6069
|
+
strokeColor,
|
|
6070
|
+
opacity,
|
|
6071
|
+
intent,
|
|
6072
|
+
...rd.ok && {
|
|
6073
|
+
rectangleDifferences: {
|
|
6074
|
+
left: rd.left,
|
|
6075
|
+
top: rd.top,
|
|
6076
|
+
right: rd.right,
|
|
6077
|
+
bottom: rd.bottom
|
|
6078
|
+
}
|
|
6079
|
+
},
|
|
5964
6080
|
...this.readBaseAnnotationProperties(doc, page, annotationPtr)
|
|
5965
6081
|
};
|
|
5966
6082
|
}
|
|
@@ -6276,6 +6392,7 @@ class PdfiumNative {
|
|
|
6276
6392
|
strokeDashArray = pattern;
|
|
6277
6393
|
}
|
|
6278
6394
|
}
|
|
6395
|
+
const rd = this.getRectangleDifferences(annotationPtr);
|
|
6279
6396
|
return {
|
|
6280
6397
|
pageIndex: page.index,
|
|
6281
6398
|
id: index,
|
|
@@ -6287,6 +6404,14 @@ class PdfiumNative {
|
|
|
6287
6404
|
strokeColor: strokeColor ?? "#FF0000",
|
|
6288
6405
|
strokeStyle,
|
|
6289
6406
|
...strokeDashArray !== void 0 && { strokeDashArray },
|
|
6407
|
+
...rd.ok && {
|
|
6408
|
+
rectangleDifferences: {
|
|
6409
|
+
left: rd.left,
|
|
6410
|
+
top: rd.top,
|
|
6411
|
+
right: rd.right,
|
|
6412
|
+
bottom: rd.bottom
|
|
6413
|
+
}
|
|
6414
|
+
},
|
|
6290
6415
|
...this.readBaseAnnotationProperties(doc, page, annotationPtr)
|
|
6291
6416
|
};
|
|
6292
6417
|
}
|
|
@@ -6316,6 +6441,7 @@ class PdfiumNative {
|
|
|
6316
6441
|
strokeDashArray = pattern;
|
|
6317
6442
|
}
|
|
6318
6443
|
}
|
|
6444
|
+
const rd = this.getRectangleDifferences(annotationPtr);
|
|
6319
6445
|
return {
|
|
6320
6446
|
pageIndex: page.index,
|
|
6321
6447
|
id: index,
|
|
@@ -6327,6 +6453,14 @@ class PdfiumNative {
|
|
|
6327
6453
|
strokeWidth,
|
|
6328
6454
|
strokeStyle,
|
|
6329
6455
|
...strokeDashArray !== void 0 && { strokeDashArray },
|
|
6456
|
+
...rd.ok && {
|
|
6457
|
+
rectangleDifferences: {
|
|
6458
|
+
left: rd.left,
|
|
6459
|
+
top: rd.top,
|
|
6460
|
+
right: rd.right,
|
|
6461
|
+
bottom: rd.bottom
|
|
6462
|
+
}
|
|
6463
|
+
},
|
|
6330
6464
|
...this.readBaseAnnotationProperties(doc, page, annotationPtr)
|
|
6331
6465
|
};
|
|
6332
6466
|
}
|
|
@@ -6363,7 +6497,13 @@ class PdfiumNative {
|
|
|
6363
6497
|
getInReplyToId(annotationPtr) {
|
|
6364
6498
|
const parentPtr = this.pdfiumModule.FPDFAnnot_GetLinkedAnnot(annotationPtr, "IRT");
|
|
6365
6499
|
if (!parentPtr) return;
|
|
6366
|
-
|
|
6500
|
+
let nm = this.getAnnotString(parentPtr, "NM");
|
|
6501
|
+
if (!nm || !isUuidV4(nm)) {
|
|
6502
|
+
nm = uuidV4();
|
|
6503
|
+
this.setAnnotString(parentPtr, "NM", nm);
|
|
6504
|
+
}
|
|
6505
|
+
this.pdfiumModule.FPDFPage_CloseAnnot(parentPtr);
|
|
6506
|
+
return nm;
|
|
6367
6507
|
}
|
|
6368
6508
|
/**
|
|
6369
6509
|
* Set the in reply to id of the annotation
|
|
@@ -7053,6 +7193,150 @@ class PdfiumNative {
|
|
|
7053
7193
|
this.memoryManager.free(heapPtr);
|
|
7054
7194
|
return task;
|
|
7055
7195
|
}
|
|
7196
|
+
/**
|
|
7197
|
+
* Batch-render all annotation appearance streams for a page in one call.
|
|
7198
|
+
* Returns a map of annotation ID -> rendered appearances (Normal/Rollover/Down).
|
|
7199
|
+
* Skips annotations that have rotation + unrotatedRect (EmbedPDF-rotated)
|
|
7200
|
+
* and annotations without any appearance stream.
|
|
7201
|
+
*
|
|
7202
|
+
* @public
|
|
7203
|
+
*/
|
|
7204
|
+
renderPageAnnotationsRaw(doc, page, options) {
|
|
7205
|
+
const { scaleFactor = 1, rotation = Rotation.Degree0, dpr = 1 } = options ?? {};
|
|
7206
|
+
this.logger.debug(LOG_SOURCE, LOG_CATEGORY, "renderPageAnnotationsRaw", doc, page, options);
|
|
7207
|
+
this.logger.perf(
|
|
7208
|
+
LOG_SOURCE,
|
|
7209
|
+
LOG_CATEGORY,
|
|
7210
|
+
"RenderPageAnnotationsRaw",
|
|
7211
|
+
"Begin",
|
|
7212
|
+
`${doc.id}-${page.index}`
|
|
7213
|
+
);
|
|
7214
|
+
const ctx = this.cache.getContext(doc.id);
|
|
7215
|
+
if (!ctx) {
|
|
7216
|
+
this.logger.perf(
|
|
7217
|
+
LOG_SOURCE,
|
|
7218
|
+
LOG_CATEGORY,
|
|
7219
|
+
"RenderPageAnnotationsRaw",
|
|
7220
|
+
"End",
|
|
7221
|
+
`${doc.id}-${page.index}`
|
|
7222
|
+
);
|
|
7223
|
+
return PdfTaskHelper.reject({
|
|
7224
|
+
code: PdfErrorCode.DocNotOpen,
|
|
7225
|
+
message: "document does not open"
|
|
7226
|
+
});
|
|
7227
|
+
}
|
|
7228
|
+
const pageCtx = ctx.acquirePage(page.index);
|
|
7229
|
+
const result = {};
|
|
7230
|
+
const finalScale = Math.max(0.01, scaleFactor * dpr);
|
|
7231
|
+
const annotCount = this.pdfiumModule.FPDFPage_GetAnnotCount(pageCtx.pagePtr);
|
|
7232
|
+
for (let i = 0; i < annotCount; i++) {
|
|
7233
|
+
const annotPtr = this.pdfiumModule.FPDFPage_GetAnnot(pageCtx.pagePtr, i);
|
|
7234
|
+
if (!annotPtr) continue;
|
|
7235
|
+
try {
|
|
7236
|
+
const nm = this.getAnnotString(annotPtr, "NM");
|
|
7237
|
+
if (!nm) continue;
|
|
7238
|
+
const extRotation = this.getAnnotExtendedRotation(annotPtr);
|
|
7239
|
+
if (extRotation !== 0) {
|
|
7240
|
+
const unrotatedRaw = this.readAnnotUnrotatedRect(annotPtr);
|
|
7241
|
+
if (unrotatedRaw) continue;
|
|
7242
|
+
}
|
|
7243
|
+
const apModes = this.pdfiumModule.EPDFAnnot_GetAvailableAppearanceModes(annotPtr);
|
|
7244
|
+
if (!apModes) continue;
|
|
7245
|
+
const appearances = {};
|
|
7246
|
+
const modesToRender = [
|
|
7247
|
+
{ bit: AP_MODE_NORMAL, mode: AppearanceMode.Normal, key: "normal" },
|
|
7248
|
+
{ bit: AP_MODE_ROLLOVER, mode: AppearanceMode.Rollover, key: "rollover" },
|
|
7249
|
+
{ bit: AP_MODE_DOWN, mode: AppearanceMode.Down, key: "down" }
|
|
7250
|
+
];
|
|
7251
|
+
for (const { bit, mode, key } of modesToRender) {
|
|
7252
|
+
if (!(apModes & bit)) continue;
|
|
7253
|
+
const rendered = this.renderSingleAnnotAppearance(
|
|
7254
|
+
doc,
|
|
7255
|
+
page,
|
|
7256
|
+
pageCtx,
|
|
7257
|
+
annotPtr,
|
|
7258
|
+
mode,
|
|
7259
|
+
rotation,
|
|
7260
|
+
finalScale
|
|
7261
|
+
);
|
|
7262
|
+
if (rendered) {
|
|
7263
|
+
appearances[key] = rendered;
|
|
7264
|
+
}
|
|
7265
|
+
}
|
|
7266
|
+
if (appearances.normal || appearances.rollover || appearances.down) {
|
|
7267
|
+
result[nm] = appearances;
|
|
7268
|
+
}
|
|
7269
|
+
} finally {
|
|
7270
|
+
this.pdfiumModule.FPDFPage_CloseAnnot(annotPtr);
|
|
7271
|
+
}
|
|
7272
|
+
}
|
|
7273
|
+
pageCtx.release();
|
|
7274
|
+
this.logger.perf(
|
|
7275
|
+
LOG_SOURCE,
|
|
7276
|
+
LOG_CATEGORY,
|
|
7277
|
+
"RenderPageAnnotationsRaw",
|
|
7278
|
+
"End",
|
|
7279
|
+
`${doc.id}-${page.index}`
|
|
7280
|
+
);
|
|
7281
|
+
const task = new Task();
|
|
7282
|
+
task.resolve(result);
|
|
7283
|
+
return task;
|
|
7284
|
+
}
|
|
7285
|
+
/**
|
|
7286
|
+
* Render a single annotation's appearance for a given mode.
|
|
7287
|
+
* Returns the image data and rect, or null on failure.
|
|
7288
|
+
* @private
|
|
7289
|
+
*/
|
|
7290
|
+
renderSingleAnnotAppearance(doc, page, pageCtx, annotPtr, mode, rotation, finalScale) {
|
|
7291
|
+
const pageRect = this.readPageAnnoRect(annotPtr);
|
|
7292
|
+
const annotRect = this.convertPageRectToDeviceRect(doc, page, pageRect);
|
|
7293
|
+
const rect = toIntRect(annotRect);
|
|
7294
|
+
const devRect = toIntRect(transformRect(page.size, rect, rotation, finalScale));
|
|
7295
|
+
const wDev = Math.max(1, devRect.size.width);
|
|
7296
|
+
const hDev = Math.max(1, devRect.size.height);
|
|
7297
|
+
const stride = wDev * 4;
|
|
7298
|
+
const bytes = stride * hDev;
|
|
7299
|
+
const heapPtr = this.memoryManager.malloc(bytes);
|
|
7300
|
+
const bitmapPtr = this.pdfiumModule.FPDFBitmap_CreateEx(
|
|
7301
|
+
wDev,
|
|
7302
|
+
hDev,
|
|
7303
|
+
4,
|
|
7304
|
+
heapPtr,
|
|
7305
|
+
stride
|
|
7306
|
+
);
|
|
7307
|
+
this.pdfiumModule.FPDFBitmap_FillRect(bitmapPtr, 0, 0, wDev, hDev, 0);
|
|
7308
|
+
const M = buildUserToDeviceMatrix(rect, rotation, wDev, hDev);
|
|
7309
|
+
const mPtr = this.memoryManager.malloc(6 * 4);
|
|
7310
|
+
const mView = new Float32Array(this.pdfiumModule.pdfium.HEAPF32.buffer, mPtr, 6);
|
|
7311
|
+
mView.set([M.a, M.b, M.c, M.d, M.e, M.f]);
|
|
7312
|
+
const FLAGS = 16;
|
|
7313
|
+
let ok = false;
|
|
7314
|
+
try {
|
|
7315
|
+
ok = !!this.pdfiumModule.EPDF_RenderAnnotBitmap(
|
|
7316
|
+
bitmapPtr,
|
|
7317
|
+
pageCtx.pagePtr,
|
|
7318
|
+
annotPtr,
|
|
7319
|
+
mode,
|
|
7320
|
+
mPtr,
|
|
7321
|
+
FLAGS
|
|
7322
|
+
);
|
|
7323
|
+
} finally {
|
|
7324
|
+
this.memoryManager.free(mPtr);
|
|
7325
|
+
this.pdfiumModule.FPDFBitmap_Destroy(bitmapPtr);
|
|
7326
|
+
}
|
|
7327
|
+
if (!ok) {
|
|
7328
|
+
this.memoryManager.free(heapPtr);
|
|
7329
|
+
return null;
|
|
7330
|
+
}
|
|
7331
|
+
const data = this.pdfiumModule.pdfium.HEAPU8.subarray(heapPtr, heapPtr + bytes);
|
|
7332
|
+
const imageData = {
|
|
7333
|
+
data: new Uint8ClampedArray(data),
|
|
7334
|
+
width: wDev,
|
|
7335
|
+
height: hDev
|
|
7336
|
+
};
|
|
7337
|
+
this.memoryManager.free(heapPtr);
|
|
7338
|
+
return { data: imageData, rect: annotRect };
|
|
7339
|
+
}
|
|
7056
7340
|
renderRectEncoded(doc, page, rect, options) {
|
|
7057
7341
|
const task = new Task();
|
|
7058
7342
|
const rotation = (options == null ? void 0 : options.rotation) ?? Rotation.Degree0;
|
|
@@ -8264,4 +8548,4 @@ export {
|
|
|
8264
8548
|
isValidCustomKey as i,
|
|
8265
8549
|
readArrayBuffer as r
|
|
8266
8550
|
};
|
|
8267
|
-
//# sourceMappingURL=direct-engine-
|
|
8551
|
+
//# sourceMappingURL=direct-engine-BOkKwXM0.js.map
|