@embedpdf/engines 2.4.0 → 2.5.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/{browser-C6QEa8uk.cjs → browser-13mzox-R.cjs} +2 -2
- package/dist/{browser-C6QEa8uk.cjs.map → browser-13mzox-R.cjs.map} +1 -1
- package/dist/{browser-awZxztMA.js → browser-qfUHZxQ6.js} +7 -3
- package/dist/{browser-awZxztMA.js.map → browser-qfUHZxQ6.js.map} +1 -1
- package/dist/direct-engine-BtiOvMLP.cjs +2 -0
- package/dist/direct-engine-BtiOvMLP.cjs.map +1 -0
- package/dist/{direct-engine-6BoAmGsC.js → direct-engine-D8HGqcIt.js} +198 -162
- package/dist/direct-engine-D8HGqcIt.js.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +3 -3
- package/dist/lib/converters/browser.d.ts +2 -2
- package/dist/lib/converters/index.cjs +1 -1
- package/dist/lib/converters/index.js +1 -1
- package/dist/lib/converters/types.d.ts +12 -2
- package/dist/lib/pdfium/cache.d.ts +9 -1
- package/dist/lib/pdfium/engine.d.ts +21 -3
- package/dist/lib/pdfium/index.cjs +1 -1
- package/dist/lib/pdfium/index.js +4 -4
- package/dist/lib/pdfium/web/direct-engine.cjs +1 -1
- package/dist/lib/pdfium/web/direct-engine.js +3 -3
- package/dist/lib/pdfium/web/worker-engine.cjs +1 -1
- package/dist/lib/pdfium/web/worker-engine.js +3 -3
- package/dist/pdf-engine-BmrecQLq.cjs +2 -0
- package/dist/pdf-engine-BmrecQLq.cjs.map +1 -0
- package/dist/{pdf-engine-D_Dua_6w.js → pdf-engine-aJNoNMbt.js} +5 -2
- package/dist/pdf-engine-aJNoNMbt.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-6BoAmGsC.js.map +0 -1
- package/dist/direct-engine-Byh1BweU.cjs +0 -2
- package/dist/direct-engine-Byh1BweU.cjs.map +0 -1
- package/dist/pdf-engine-BXctylEz.cjs +0 -2
- package/dist/pdf-engine-BXctylEz.cjs.map +0 -1
- package/dist/pdf-engine-D_Dua_6w.js.map +0 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { init } from "@embedpdf/pdfium";
|
|
2
2
|
import { Rotation, NoopLogger, PdfTaskHelper, PdfErrorCode, pdfDateToDate, isUuidV4, uuidV4, PdfAnnotationSubtype, PdfPageFlattenFlag, stripPdfUnwantedMarkers, PdfAnnotationIcon, PdfAnnotationBorderStyle, PdfAnnotationColorType, PdfAnnotationLineEnding, PdfStandardFont, PdfStampFit, PdfTrappedStatus, pdfColorToWebColor, webColorToPdfColor, pdfAlphaToWebOpacity, webOpacityToPdfAlpha, PdfAnnotationReplyType, dateToPdfDate, quadToRect, rectToQuad, PdfPageObjectType, flagsToNames, namesToFlags, PDF_FORM_FIELD_TYPE, AppearanceMode, Task, toIntRect, transformRect, buildUserToDeviceMatrix, PdfZoomMode, PdfActionType } from "@embedpdf/models";
|
|
3
|
-
import { P as PdfEngine } from "./pdf-engine-
|
|
4
|
-
import { b as browserImageDataToBlobConverter } from "./browser-
|
|
3
|
+
import { P as PdfEngine } from "./pdf-engine-aJNoNMbt.js";
|
|
4
|
+
import { b as browserImageDataToBlobConverter } from "./browser-qfUHZxQ6.js";
|
|
5
5
|
function readString(wasmModule, readChars, parseChars, defaultLength = 100) {
|
|
6
6
|
let buffer = wasmModule.wasmExports.malloc(defaultLength);
|
|
7
7
|
for (let i = 0; i < defaultLength; i++) {
|
|
@@ -98,7 +98,8 @@ const WasmPointer = (ptr) => ptr;
|
|
|
98
98
|
const DEFAULT_CONFIG = {
|
|
99
99
|
pageTtl: 5e3,
|
|
100
100
|
// 5 seconds
|
|
101
|
-
maxPagesPerDocument: 10
|
|
101
|
+
maxPagesPerDocument: 10,
|
|
102
|
+
normalizeRotation: false
|
|
102
103
|
};
|
|
103
104
|
class PdfCache {
|
|
104
105
|
constructor(pdfium, memoryManager, config = {}) {
|
|
@@ -108,10 +109,11 @@ class PdfCache {
|
|
|
108
109
|
this.config = { ...DEFAULT_CONFIG, ...config };
|
|
109
110
|
}
|
|
110
111
|
/** Open (or re-use) a document */
|
|
111
|
-
setDocument(id, filePtr, docPtr) {
|
|
112
|
+
setDocument(id, filePtr, docPtr, normalizeRotation = false) {
|
|
112
113
|
let ctx = this.docs.get(id);
|
|
113
114
|
if (!ctx) {
|
|
114
|
-
|
|
115
|
+
const docConfig = { ...this.config, normalizeRotation };
|
|
116
|
+
ctx = new DocumentContext(filePtr, docPtr, this.pdfium, this.memoryManager, docConfig);
|
|
115
117
|
this.docs.set(id, ctx);
|
|
116
118
|
}
|
|
117
119
|
}
|
|
@@ -162,6 +164,7 @@ class DocumentContext {
|
|
|
162
164
|
this.filePtr = filePtr;
|
|
163
165
|
this.docPtr = docPtr;
|
|
164
166
|
this.memoryManager = memoryManager;
|
|
167
|
+
this.normalizeRotation = config.normalizeRotation;
|
|
165
168
|
this.pageCache = new PageCache(pdfium, docPtr, config);
|
|
166
169
|
}
|
|
167
170
|
/** Main accessor for pages */
|
|
@@ -199,7 +202,12 @@ class PageCache {
|
|
|
199
202
|
let ctx = this.cache.get(pageIdx);
|
|
200
203
|
if (!ctx) {
|
|
201
204
|
this.evictIfNeeded();
|
|
202
|
-
|
|
205
|
+
let pagePtr;
|
|
206
|
+
if (this.config.normalizeRotation) {
|
|
207
|
+
pagePtr = this.pdf.EPDF_LoadPageNormalized(this.docPtr, pageIdx, 0);
|
|
208
|
+
} else {
|
|
209
|
+
pagePtr = this.pdf.FPDF_LoadPage(this.docPtr, pageIdx);
|
|
210
|
+
}
|
|
203
211
|
ctx = new PageContext(this.pdf, this.docPtr, pageIdx, pagePtr, this.config.pageTtl, () => {
|
|
204
212
|
this.cache.delete(pageIdx);
|
|
205
213
|
this.removeFromAccessOrder(pageIdx);
|
|
@@ -1054,6 +1062,7 @@ class PdfiumNative {
|
|
|
1054
1062
|
openDocumentBuffer(file, options) {
|
|
1055
1063
|
this.logger.debug(LOG_SOURCE, LOG_CATEGORY, "openDocumentBuffer", file, options);
|
|
1056
1064
|
this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `OpenDocumentBuffer`, "Begin", file.id);
|
|
1065
|
+
const normalizeRotation = (options == null ? void 0 : options.normalizeRotation) ?? false;
|
|
1057
1066
|
const array = new Uint8Array(file.content);
|
|
1058
1067
|
const length = array.length;
|
|
1059
1068
|
const filePtr = this.memoryManager.malloc(length);
|
|
@@ -1073,13 +1082,13 @@ class PdfiumNative {
|
|
|
1073
1082
|
const pages = [];
|
|
1074
1083
|
const sizePtr = this.memoryManager.malloc(8);
|
|
1075
1084
|
for (let index = 0; index < pageCount; index++) {
|
|
1076
|
-
const result = this.pdfiumModule.FPDF_GetPageSizeByIndexF(docPtr, index, sizePtr);
|
|
1085
|
+
const result = normalizeRotation ? this.pdfiumModule.EPDF_GetPageSizeByIndexNormalized(docPtr, index, sizePtr) : this.pdfiumModule.FPDF_GetPageSizeByIndexF(docPtr, index, sizePtr);
|
|
1077
1086
|
if (!result) {
|
|
1078
1087
|
const lastError = this.pdfiumModule.FPDF_GetLastError();
|
|
1079
1088
|
this.logger.error(
|
|
1080
1089
|
LOG_SOURCE,
|
|
1081
1090
|
LOG_CATEGORY,
|
|
1082
|
-
|
|
1091
|
+
`${normalizeRotation ? "EPDF_GetPageSizeByIndexNormalized" : "FPDF_GetPageSizeByIndexF"} failed with ${lastError}`
|
|
1083
1092
|
);
|
|
1084
1093
|
this.memoryManager.free(sizePtr);
|
|
1085
1094
|
this.pdfiumModule.FPDF_CloseDocument(docPtr);
|
|
@@ -1087,7 +1096,7 @@ class PdfiumNative {
|
|
|
1087
1096
|
this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `OpenDocumentBuffer`, "End", file.id);
|
|
1088
1097
|
return PdfTaskHelper.reject({
|
|
1089
1098
|
code: lastError,
|
|
1090
|
-
message:
|
|
1099
|
+
message: `${normalizeRotation ? "EPDF_GetPageSizeByIndexNormalized" : "FPDF_GetPageSizeByIndexF"} failed`
|
|
1091
1100
|
});
|
|
1092
1101
|
}
|
|
1093
1102
|
const rotation = this.pdfiumModule.EPDF_GetPageRotationByIndex(docPtr, index);
|
|
@@ -1111,9 +1120,10 @@ class PdfiumNative {
|
|
|
1111
1120
|
pages,
|
|
1112
1121
|
isEncrypted,
|
|
1113
1122
|
isOwnerUnlocked,
|
|
1114
|
-
permissions
|
|
1123
|
+
permissions,
|
|
1124
|
+
normalizedRotation: normalizeRotation
|
|
1115
1125
|
};
|
|
1116
|
-
this.cache.setDocument(file.id, filePtr, docPtr);
|
|
1126
|
+
this.cache.setDocument(file.id, filePtr, docPtr, normalizeRotation);
|
|
1117
1127
|
this.logger.perf(LOG_SOURCE, LOG_CATEGORY, `OpenDocumentBuffer`, "End", file.id);
|
|
1118
1128
|
return PdfTaskHelper.resolve(pdfDoc);
|
|
1119
1129
|
}
|
|
@@ -1470,7 +1480,7 @@ class PdfiumNative {
|
|
|
1470
1480
|
message: "document does not open"
|
|
1471
1481
|
});
|
|
1472
1482
|
}
|
|
1473
|
-
const annotations = this.readPageAnnotations(ctx, page);
|
|
1483
|
+
const annotations = this.readPageAnnotations(doc, ctx, page);
|
|
1474
1484
|
this.logger.perf(
|
|
1475
1485
|
LOG_SOURCE,
|
|
1476
1486
|
LOG_CATEGORY,
|
|
@@ -1542,7 +1552,7 @@ class PdfiumNative {
|
|
|
1542
1552
|
message: "can not set the name of the annotation"
|
|
1543
1553
|
});
|
|
1544
1554
|
}
|
|
1545
|
-
if (!this.setPageAnnoRect(page, annotationPtr, annotation.rect)) {
|
|
1555
|
+
if (!this.setPageAnnoRect(doc, page, annotationPtr, annotation.rect)) {
|
|
1546
1556
|
this.pdfiumModule.FPDFPage_CloseAnnot(annotationPtr);
|
|
1547
1557
|
pageCtx.release();
|
|
1548
1558
|
this.logger.perf(
|
|
@@ -1560,10 +1570,11 @@ class PdfiumNative {
|
|
|
1560
1570
|
let isSucceed = false;
|
|
1561
1571
|
switch (annotation.type) {
|
|
1562
1572
|
case PdfAnnotationSubtype.INK:
|
|
1563
|
-
isSucceed = this.addInkStroke(page, pageCtx.pagePtr, annotationPtr, annotation);
|
|
1573
|
+
isSucceed = this.addInkStroke(doc, page, pageCtx.pagePtr, annotationPtr, annotation);
|
|
1564
1574
|
break;
|
|
1565
1575
|
case PdfAnnotationSubtype.STAMP:
|
|
1566
1576
|
isSucceed = this.addStampContent(
|
|
1577
|
+
doc,
|
|
1567
1578
|
ctx.docPtr,
|
|
1568
1579
|
page,
|
|
1569
1580
|
pageCtx.pagePtr,
|
|
@@ -1579,11 +1590,11 @@ class PdfiumNative {
|
|
|
1579
1590
|
isSucceed = this.addFreeTextContent(page, pageCtx.pagePtr, annotationPtr, annotation);
|
|
1580
1591
|
break;
|
|
1581
1592
|
case PdfAnnotationSubtype.LINE:
|
|
1582
|
-
isSucceed = this.addLineContent(page, pageCtx.pagePtr, annotationPtr, annotation);
|
|
1593
|
+
isSucceed = this.addLineContent(doc, page, pageCtx.pagePtr, annotationPtr, annotation);
|
|
1583
1594
|
break;
|
|
1584
1595
|
case PdfAnnotationSubtype.POLYLINE:
|
|
1585
1596
|
case PdfAnnotationSubtype.POLYGON:
|
|
1586
|
-
isSucceed = this.addPolyContent(page, pageCtx.pagePtr, annotationPtr, annotation);
|
|
1597
|
+
isSucceed = this.addPolyContent(doc, page, pageCtx.pagePtr, annotationPtr, annotation);
|
|
1587
1598
|
break;
|
|
1588
1599
|
case PdfAnnotationSubtype.CIRCLE:
|
|
1589
1600
|
case PdfAnnotationSubtype.SQUARE:
|
|
@@ -1593,13 +1604,19 @@ class PdfiumNative {
|
|
|
1593
1604
|
case PdfAnnotationSubtype.STRIKEOUT:
|
|
1594
1605
|
case PdfAnnotationSubtype.SQUIGGLY:
|
|
1595
1606
|
case PdfAnnotationSubtype.HIGHLIGHT:
|
|
1596
|
-
isSucceed = this.addTextMarkupContent(
|
|
1607
|
+
isSucceed = this.addTextMarkupContent(
|
|
1608
|
+
doc,
|
|
1609
|
+
page,
|
|
1610
|
+
pageCtx.pagePtr,
|
|
1611
|
+
annotationPtr,
|
|
1612
|
+
annotation
|
|
1613
|
+
);
|
|
1597
1614
|
break;
|
|
1598
1615
|
case PdfAnnotationSubtype.LINK:
|
|
1599
1616
|
isSucceed = this.addLinkContent(ctx.docPtr, pageCtx.pagePtr, annotationPtr, annotation);
|
|
1600
1617
|
break;
|
|
1601
1618
|
case PdfAnnotationSubtype.REDACT:
|
|
1602
|
-
isSucceed = this.addRedactContent(page, pageCtx.pagePtr, annotationPtr, annotation);
|
|
1619
|
+
isSucceed = this.addRedactContent(doc, page, pageCtx.pagePtr, annotationPtr, annotation);
|
|
1603
1620
|
break;
|
|
1604
1621
|
}
|
|
1605
1622
|
if (!isSucceed) {
|
|
@@ -1679,7 +1696,7 @@ class PdfiumNative {
|
|
|
1679
1696
|
);
|
|
1680
1697
|
return PdfTaskHelper.reject({ code: PdfErrorCode.NotFound, message: "annotation not found" });
|
|
1681
1698
|
}
|
|
1682
|
-
if (!this.setPageAnnoRect(page, annotPtr, annotation.rect)) {
|
|
1699
|
+
if (!this.setPageAnnoRect(doc, page, annotPtr, annotation.rect)) {
|
|
1683
1700
|
this.pdfiumModule.FPDFPage_CloseAnnot(annotPtr);
|
|
1684
1701
|
pageCtx.release();
|
|
1685
1702
|
this.logger.perf(
|
|
@@ -1699,12 +1716,12 @@ class PdfiumNative {
|
|
|
1699
1716
|
/* ── Ink ─────────────────────────────────────────────────────────────── */
|
|
1700
1717
|
case PdfAnnotationSubtype.INK: {
|
|
1701
1718
|
if (!this.pdfiumModule.FPDFAnnot_RemoveInkList(annotPtr)) break;
|
|
1702
|
-
ok = this.addInkStroke(page, pageCtx.pagePtr, annotPtr, annotation);
|
|
1719
|
+
ok = this.addInkStroke(doc, page, pageCtx.pagePtr, annotPtr, annotation);
|
|
1703
1720
|
break;
|
|
1704
1721
|
}
|
|
1705
1722
|
/* ── Stamp ───────────────────────────────────────────────────────────── */
|
|
1706
1723
|
case PdfAnnotationSubtype.STAMP: {
|
|
1707
|
-
ok = this.addStampContent(ctx.docPtr, page, pageCtx.pagePtr, annotPtr, annotation);
|
|
1724
|
+
ok = this.addStampContent(doc, ctx.docPtr, page, pageCtx.pagePtr, annotPtr, annotation);
|
|
1708
1725
|
break;
|
|
1709
1726
|
}
|
|
1710
1727
|
case PdfAnnotationSubtype.TEXT: {
|
|
@@ -1724,13 +1741,13 @@ class PdfiumNative {
|
|
|
1724
1741
|
}
|
|
1725
1742
|
/* ── Line ─────────────────────────────────────────────────────────────── */
|
|
1726
1743
|
case PdfAnnotationSubtype.LINE: {
|
|
1727
|
-
ok = this.addLineContent(page, pageCtx.pagePtr, annotPtr, annotation);
|
|
1744
|
+
ok = this.addLineContent(doc, page, pageCtx.pagePtr, annotPtr, annotation);
|
|
1728
1745
|
break;
|
|
1729
1746
|
}
|
|
1730
1747
|
/* ── Polygon / Polyline ───────────────────────────────────────────────── */
|
|
1731
1748
|
case PdfAnnotationSubtype.POLYGON:
|
|
1732
1749
|
case PdfAnnotationSubtype.POLYLINE: {
|
|
1733
|
-
ok = this.addPolyContent(page, pageCtx.pagePtr, annotPtr, annotation);
|
|
1750
|
+
ok = this.addPolyContent(doc, page, pageCtx.pagePtr, annotPtr, annotation);
|
|
1734
1751
|
break;
|
|
1735
1752
|
}
|
|
1736
1753
|
/* ── Text-markup family ──────────────────────────────────────────────── */
|
|
@@ -1738,7 +1755,7 @@ class PdfiumNative {
|
|
|
1738
1755
|
case PdfAnnotationSubtype.UNDERLINE:
|
|
1739
1756
|
case PdfAnnotationSubtype.STRIKEOUT:
|
|
1740
1757
|
case PdfAnnotationSubtype.SQUIGGLY: {
|
|
1741
|
-
ok = this.addTextMarkupContent(page, pageCtx.pagePtr, annotPtr, annotation);
|
|
1758
|
+
ok = this.addTextMarkupContent(doc, page, pageCtx.pagePtr, annotPtr, annotation);
|
|
1742
1759
|
break;
|
|
1743
1760
|
}
|
|
1744
1761
|
/* ── Link ─────────────────────────────────────────────────────────────── */
|
|
@@ -1748,7 +1765,7 @@ class PdfiumNative {
|
|
|
1748
1765
|
}
|
|
1749
1766
|
/* ── Redact ───────────────────────────────────────────────────────────── */
|
|
1750
1767
|
case PdfAnnotationSubtype.REDACT: {
|
|
1751
|
-
ok = this.addRedactContent(page, pageCtx.pagePtr, annotPtr, annotation);
|
|
1768
|
+
ok = this.addRedactContent(doc, page, pageCtx.pagePtr, annotPtr, annotation);
|
|
1752
1769
|
break;
|
|
1753
1770
|
}
|
|
1754
1771
|
/* ── Unsupported edits – fall through to error ───────────────────────── */
|
|
@@ -2803,11 +2820,11 @@ class PdfiumNative {
|
|
|
2803
2820
|
*
|
|
2804
2821
|
* @private
|
|
2805
2822
|
*/
|
|
2806
|
-
addInkStroke(page, pagePtr, annotationPtr, annotation) {
|
|
2823
|
+
addInkStroke(doc, page, pagePtr, annotationPtr, annotation) {
|
|
2807
2824
|
if (!this.setBorderStyle(annotationPtr, PdfAnnotationBorderStyle.SOLID, annotation.strokeWidth)) {
|
|
2808
2825
|
return false;
|
|
2809
2826
|
}
|
|
2810
|
-
if (!this.setInkList(page, annotationPtr, annotation.inkList)) {
|
|
2827
|
+
if (!this.setInkList(doc, page, annotationPtr, annotation.inkList)) {
|
|
2811
2828
|
return false;
|
|
2812
2829
|
}
|
|
2813
2830
|
if (!this.setAnnotationOpacity(annotationPtr, annotation.opacity ?? 1)) {
|
|
@@ -2829,9 +2846,10 @@ class PdfiumNative {
|
|
|
2829
2846
|
*
|
|
2830
2847
|
* @private
|
|
2831
2848
|
*/
|
|
2832
|
-
addLineContent(page, pagePtr, annotationPtr, annotation) {
|
|
2849
|
+
addLineContent(doc, page, pagePtr, annotationPtr, annotation) {
|
|
2833
2850
|
var _a, _b;
|
|
2834
2851
|
if (!this.setLinePoints(
|
|
2852
|
+
doc,
|
|
2835
2853
|
page,
|
|
2836
2854
|
annotationPtr,
|
|
2837
2855
|
annotation.linePoints.start,
|
|
@@ -2888,7 +2906,7 @@ class PdfiumNative {
|
|
|
2888
2906
|
*
|
|
2889
2907
|
* @private
|
|
2890
2908
|
*/
|
|
2891
|
-
addPolyContent(page, pagePtr, annotationPtr, annotation) {
|
|
2909
|
+
addPolyContent(doc, page, pagePtr, annotationPtr, annotation) {
|
|
2892
2910
|
var _a, _b;
|
|
2893
2911
|
if (annotation.type === PdfAnnotationSubtype.POLYLINE && !this.setLineEndings(
|
|
2894
2912
|
annotationPtr,
|
|
@@ -2897,7 +2915,7 @@ class PdfiumNative {
|
|
|
2897
2915
|
)) {
|
|
2898
2916
|
return false;
|
|
2899
2917
|
}
|
|
2900
|
-
if (!this.setPdfAnnoVertices(page, annotationPtr, annotation.vertices)) {
|
|
2918
|
+
if (!this.setPdfAnnoVertices(doc, page, annotationPtr, annotation.vertices)) {
|
|
2901
2919
|
return false;
|
|
2902
2920
|
}
|
|
2903
2921
|
if (!this.setBorderStyle(annotationPtr, annotation.strokeStyle, annotation.strokeWidth)) {
|
|
@@ -3016,8 +3034,8 @@ class PdfiumNative {
|
|
|
3016
3034
|
*
|
|
3017
3035
|
* @private
|
|
3018
3036
|
*/
|
|
3019
|
-
addTextMarkupContent(page, pagePtr, annotationPtr, annotation) {
|
|
3020
|
-
if (!this.syncQuadPointsAnno(page, annotationPtr, annotation.segmentRects)) {
|
|
3037
|
+
addTextMarkupContent(doc, page, pagePtr, annotationPtr, annotation) {
|
|
3038
|
+
if (!this.syncQuadPointsAnno(doc, page, annotationPtr, annotation.segmentRects)) {
|
|
3021
3039
|
return false;
|
|
3022
3040
|
}
|
|
3023
3041
|
if (!this.setAnnotationOpacity(annotationPtr, annotation.opacity ?? 1)) {
|
|
@@ -3039,8 +3057,8 @@ class PdfiumNative {
|
|
|
3039
3057
|
*
|
|
3040
3058
|
* @private
|
|
3041
3059
|
*/
|
|
3042
|
-
addRedactContent(page, pagePtr, annotationPtr, annotation) {
|
|
3043
|
-
if (!this.syncQuadPointsAnno(page, annotationPtr, annotation.segmentRects)) {
|
|
3060
|
+
addRedactContent(doc, page, pagePtr, annotationPtr, annotation) {
|
|
3061
|
+
if (!this.syncQuadPointsAnno(doc, page, annotationPtr, annotation.segmentRects)) {
|
|
3044
3062
|
return false;
|
|
3045
3063
|
}
|
|
3046
3064
|
if (!this.setAnnotationOpacity(annotationPtr, annotation.opacity ?? 1)) {
|
|
@@ -3098,6 +3116,7 @@ class PdfiumNative {
|
|
|
3098
3116
|
}
|
|
3099
3117
|
/**
|
|
3100
3118
|
* Add contents to stamp annotation
|
|
3119
|
+
* @param doc - pdf document object
|
|
3101
3120
|
* @param docPtr - pointer to pdf document object
|
|
3102
3121
|
* @param page - page info
|
|
3103
3122
|
* @param pagePtr - pointer to page object
|
|
@@ -3108,7 +3127,7 @@ class PdfiumNative {
|
|
|
3108
3127
|
*
|
|
3109
3128
|
* @private
|
|
3110
3129
|
*/
|
|
3111
|
-
addStampContent(docPtr, page, pagePtr, annotationPtr, annotation, imageData) {
|
|
3130
|
+
addStampContent(doc, docPtr, page, pagePtr, annotationPtr, annotation, imageData) {
|
|
3112
3131
|
if (annotation.icon && !this.setAnnotationIcon(annotationPtr, annotation.icon)) {
|
|
3113
3132
|
return false;
|
|
3114
3133
|
}
|
|
@@ -3119,7 +3138,7 @@ class PdfiumNative {
|
|
|
3119
3138
|
for (let i = this.pdfiumModule.FPDFAnnot_GetObjectCount(annotationPtr) - 1; i >= 0; i--) {
|
|
3120
3139
|
this.pdfiumModule.FPDFAnnot_RemoveObject(annotationPtr, i);
|
|
3121
3140
|
}
|
|
3122
|
-
if (!this.addImageObject(docPtr, page, pagePtr, annotationPtr, annotation.rect, imageData)) {
|
|
3141
|
+
if (!this.addImageObject(doc, docPtr, page, pagePtr, annotationPtr, annotation.rect, imageData)) {
|
|
3123
3142
|
return false;
|
|
3124
3143
|
}
|
|
3125
3144
|
}
|
|
@@ -3130,6 +3149,7 @@ class PdfiumNative {
|
|
|
3130
3149
|
}
|
|
3131
3150
|
/**
|
|
3132
3151
|
* Add image object to annotation
|
|
3152
|
+
* @param doc - pdf document object
|
|
3133
3153
|
* @param docPtr - pointer to pdf document object
|
|
3134
3154
|
* @param page - page info
|
|
3135
3155
|
* @param pagePtr - pointer to page object
|
|
@@ -3140,7 +3160,7 @@ class PdfiumNative {
|
|
|
3140
3160
|
*
|
|
3141
3161
|
* @private
|
|
3142
3162
|
*/
|
|
3143
|
-
addImageObject(docPtr, page, pagePtr, annotationPtr, rect, imageData) {
|
|
3163
|
+
addImageObject(doc, docPtr, page, pagePtr, annotationPtr, rect, imageData) {
|
|
3144
3164
|
const bytesPerPixel = 4;
|
|
3145
3165
|
const pixelCount = imageData.width * imageData.height;
|
|
3146
3166
|
const bitmapBufferPtr = this.memoryManager.malloc(bytesPerPixel * pixelCount);
|
|
@@ -3196,7 +3216,7 @@ class PdfiumNative {
|
|
|
3196
3216
|
return false;
|
|
3197
3217
|
}
|
|
3198
3218
|
this.memoryManager.free(matrixPtr);
|
|
3199
|
-
const pagePos = this.convertDevicePointToPagePoint(page, {
|
|
3219
|
+
const pagePos = this.convertDevicePointToPagePoint(doc, page, {
|
|
3200
3220
|
x: rect.origin.x,
|
|
3201
3221
|
y: rect.origin.y + imageData.height
|
|
3202
3222
|
// shift down by the image height
|
|
@@ -3821,19 +3841,20 @@ class PdfiumNative {
|
|
|
3821
3841
|
/**
|
|
3822
3842
|
* Read page annotations
|
|
3823
3843
|
*
|
|
3844
|
+
* @param doc - pdf document object
|
|
3824
3845
|
* @param ctx - document context
|
|
3825
3846
|
* @param page - page info
|
|
3826
3847
|
* @returns annotations on the pdf page
|
|
3827
3848
|
*
|
|
3828
3849
|
* @private
|
|
3829
3850
|
*/
|
|
3830
|
-
readPageAnnotations(ctx, page) {
|
|
3851
|
+
readPageAnnotations(doc, ctx, page) {
|
|
3831
3852
|
return ctx.borrowPage(page.index, (pageCtx) => {
|
|
3832
3853
|
const annotationCount = this.pdfiumModule.FPDFPage_GetAnnotCount(pageCtx.pagePtr);
|
|
3833
3854
|
const annotations = [];
|
|
3834
3855
|
for (let i = 0; i < annotationCount; i++) {
|
|
3835
3856
|
pageCtx.withAnnotation(i, (annotPtr) => {
|
|
3836
|
-
const anno = this.readPageAnnotation(ctx.docPtr, page, annotPtr, pageCtx);
|
|
3857
|
+
const anno = this.readPageAnnotation(doc, ctx.docPtr, page, annotPtr, pageCtx);
|
|
3837
3858
|
if (anno) annotations.push(anno);
|
|
3838
3859
|
});
|
|
3839
3860
|
}
|
|
@@ -3843,13 +3864,14 @@ class PdfiumNative {
|
|
|
3843
3864
|
/**
|
|
3844
3865
|
* Read page annotations without loading the page (raw approach)
|
|
3845
3866
|
*
|
|
3867
|
+
* @param doc - pdf document object
|
|
3846
3868
|
* @param ctx - document context
|
|
3847
3869
|
* @param page - page info
|
|
3848
3870
|
* @returns annotations on the pdf page
|
|
3849
3871
|
*
|
|
3850
3872
|
* @private
|
|
3851
3873
|
*/
|
|
3852
|
-
readPageAnnotationsRaw(ctx, page) {
|
|
3874
|
+
readPageAnnotationsRaw(doc, ctx, page) {
|
|
3853
3875
|
const count = this.pdfiumModule.EPDFPage_GetAnnotCountRaw(ctx.docPtr, page.index);
|
|
3854
3876
|
if (count <= 0) return [];
|
|
3855
3877
|
const out = [];
|
|
@@ -3857,7 +3879,7 @@ class PdfiumNative {
|
|
|
3857
3879
|
const annotPtr = this.pdfiumModule.EPDFPage_GetAnnotRaw(ctx.docPtr, page.index, i);
|
|
3858
3880
|
if (!annotPtr) continue;
|
|
3859
3881
|
try {
|
|
3860
|
-
const anno = this.readPageAnnotation(ctx.docPtr, page, annotPtr);
|
|
3882
|
+
const anno = this.readPageAnnotation(doc, ctx.docPtr, page, annotPtr);
|
|
3861
3883
|
if (anno) out.push(anno);
|
|
3862
3884
|
} finally {
|
|
3863
3885
|
this.pdfiumModule.FPDFPage_CloseAnnot(annotPtr);
|
|
@@ -3890,7 +3912,7 @@ class PdfiumNative {
|
|
|
3890
3912
|
message: "document does not open"
|
|
3891
3913
|
});
|
|
3892
3914
|
}
|
|
3893
|
-
const out = this.readPageAnnotationsRaw(ctx, page);
|
|
3915
|
+
const out = this.readPageAnnotationsRaw(doc, ctx, page);
|
|
3894
3916
|
this.logger.perf(
|
|
3895
3917
|
LOG_SOURCE,
|
|
3896
3918
|
LOG_CATEGORY,
|
|
@@ -3910,6 +3932,7 @@ class PdfiumNative {
|
|
|
3910
3932
|
/**
|
|
3911
3933
|
* Read pdf annotation from pdf document
|
|
3912
3934
|
*
|
|
3935
|
+
* @param doc - pdf document object
|
|
3913
3936
|
* @param docPtr - pointer to pdf document
|
|
3914
3937
|
* @param page - page info
|
|
3915
3938
|
* @param annotationPtr - pointer to pdf annotation
|
|
@@ -3918,7 +3941,7 @@ class PdfiumNative {
|
|
|
3918
3941
|
*
|
|
3919
3942
|
* @private
|
|
3920
3943
|
*/
|
|
3921
|
-
readPageAnnotation(docPtr, page, annotationPtr, pageCtx) {
|
|
3944
|
+
readPageAnnotation(doc, docPtr, page, annotationPtr, pageCtx) {
|
|
3922
3945
|
let index = this.getAnnotString(annotationPtr, "NM");
|
|
3923
3946
|
if (!index || !isUuidV4(index)) {
|
|
3924
3947
|
index = uuidV4();
|
|
@@ -3931,94 +3954,94 @@ class PdfiumNative {
|
|
|
3931
3954
|
switch (subType) {
|
|
3932
3955
|
case PdfAnnotationSubtype.TEXT:
|
|
3933
3956
|
{
|
|
3934
|
-
annotation = this.readPdfTextAnno(page, annotationPtr, index);
|
|
3957
|
+
annotation = this.readPdfTextAnno(doc, page, annotationPtr, index);
|
|
3935
3958
|
}
|
|
3936
3959
|
break;
|
|
3937
3960
|
case PdfAnnotationSubtype.FREETEXT:
|
|
3938
3961
|
{
|
|
3939
|
-
annotation = this.readPdfFreeTextAnno(page, annotationPtr, index);
|
|
3962
|
+
annotation = this.readPdfFreeTextAnno(doc, page, annotationPtr, index);
|
|
3940
3963
|
}
|
|
3941
3964
|
break;
|
|
3942
3965
|
case PdfAnnotationSubtype.LINK:
|
|
3943
3966
|
{
|
|
3944
|
-
annotation = this.readPdfLinkAnno(page, docPtr, annotationPtr, index);
|
|
3967
|
+
annotation = this.readPdfLinkAnno(doc, page, docPtr, annotationPtr, index);
|
|
3945
3968
|
}
|
|
3946
3969
|
break;
|
|
3947
3970
|
case PdfAnnotationSubtype.WIDGET:
|
|
3948
3971
|
if (pageCtx) {
|
|
3949
|
-
return this.readPdfWidgetAnno(page, annotationPtr, pageCtx.getFormHandle(), index);
|
|
3972
|
+
return this.readPdfWidgetAnno(doc, page, annotationPtr, pageCtx.getFormHandle(), index);
|
|
3950
3973
|
}
|
|
3951
3974
|
case PdfAnnotationSubtype.FILEATTACHMENT:
|
|
3952
3975
|
{
|
|
3953
|
-
annotation = this.readPdfFileAttachmentAnno(page, annotationPtr, index);
|
|
3976
|
+
annotation = this.readPdfFileAttachmentAnno(doc, page, annotationPtr, index);
|
|
3954
3977
|
}
|
|
3955
3978
|
break;
|
|
3956
3979
|
case PdfAnnotationSubtype.INK:
|
|
3957
3980
|
{
|
|
3958
|
-
annotation = this.readPdfInkAnno(page, annotationPtr, index);
|
|
3981
|
+
annotation = this.readPdfInkAnno(doc, page, annotationPtr, index);
|
|
3959
3982
|
}
|
|
3960
3983
|
break;
|
|
3961
3984
|
case PdfAnnotationSubtype.POLYGON:
|
|
3962
3985
|
{
|
|
3963
|
-
annotation = this.readPdfPolygonAnno(page, annotationPtr, index);
|
|
3986
|
+
annotation = this.readPdfPolygonAnno(doc, page, annotationPtr, index);
|
|
3964
3987
|
}
|
|
3965
3988
|
break;
|
|
3966
3989
|
case PdfAnnotationSubtype.POLYLINE:
|
|
3967
3990
|
{
|
|
3968
|
-
annotation = this.readPdfPolylineAnno(page, annotationPtr, index);
|
|
3991
|
+
annotation = this.readPdfPolylineAnno(doc, page, annotationPtr, index);
|
|
3969
3992
|
}
|
|
3970
3993
|
break;
|
|
3971
3994
|
case PdfAnnotationSubtype.LINE:
|
|
3972
3995
|
{
|
|
3973
|
-
annotation = this.readPdfLineAnno(page, annotationPtr, index);
|
|
3996
|
+
annotation = this.readPdfLineAnno(doc, page, annotationPtr, index);
|
|
3974
3997
|
}
|
|
3975
3998
|
break;
|
|
3976
3999
|
case PdfAnnotationSubtype.HIGHLIGHT:
|
|
3977
|
-
annotation = this.readPdfHighlightAnno(page, annotationPtr, index);
|
|
4000
|
+
annotation = this.readPdfHighlightAnno(doc, page, annotationPtr, index);
|
|
3978
4001
|
break;
|
|
3979
4002
|
case PdfAnnotationSubtype.STAMP:
|
|
3980
4003
|
{
|
|
3981
|
-
annotation = this.readPdfStampAnno(page, annotationPtr, index);
|
|
4004
|
+
annotation = this.readPdfStampAnno(doc, page, annotationPtr, index);
|
|
3982
4005
|
}
|
|
3983
4006
|
break;
|
|
3984
4007
|
case PdfAnnotationSubtype.SQUARE:
|
|
3985
4008
|
{
|
|
3986
|
-
annotation = this.readPdfSquareAnno(page, annotationPtr, index);
|
|
4009
|
+
annotation = this.readPdfSquareAnno(doc, page, annotationPtr, index);
|
|
3987
4010
|
}
|
|
3988
4011
|
break;
|
|
3989
4012
|
case PdfAnnotationSubtype.CIRCLE:
|
|
3990
4013
|
{
|
|
3991
|
-
annotation = this.readPdfCircleAnno(page, annotationPtr, index);
|
|
4014
|
+
annotation = this.readPdfCircleAnno(doc, page, annotationPtr, index);
|
|
3992
4015
|
}
|
|
3993
4016
|
break;
|
|
3994
4017
|
case PdfAnnotationSubtype.UNDERLINE:
|
|
3995
4018
|
{
|
|
3996
|
-
annotation = this.readPdfUnderlineAnno(page, annotationPtr, index);
|
|
4019
|
+
annotation = this.readPdfUnderlineAnno(doc, page, annotationPtr, index);
|
|
3997
4020
|
}
|
|
3998
4021
|
break;
|
|
3999
4022
|
case PdfAnnotationSubtype.SQUIGGLY:
|
|
4000
4023
|
{
|
|
4001
|
-
annotation = this.readPdfSquigglyAnno(page, annotationPtr, index);
|
|
4024
|
+
annotation = this.readPdfSquigglyAnno(doc, page, annotationPtr, index);
|
|
4002
4025
|
}
|
|
4003
4026
|
break;
|
|
4004
4027
|
case PdfAnnotationSubtype.STRIKEOUT:
|
|
4005
4028
|
{
|
|
4006
|
-
annotation = this.readPdfStrikeOutAnno(page, annotationPtr, index);
|
|
4029
|
+
annotation = this.readPdfStrikeOutAnno(doc, page, annotationPtr, index);
|
|
4007
4030
|
}
|
|
4008
4031
|
break;
|
|
4009
4032
|
case PdfAnnotationSubtype.CARET:
|
|
4010
4033
|
{
|
|
4011
|
-
annotation = this.readPdfCaretAnno(page, annotationPtr, index);
|
|
4034
|
+
annotation = this.readPdfCaretAnno(doc, page, annotationPtr, index);
|
|
4012
4035
|
}
|
|
4013
4036
|
break;
|
|
4014
4037
|
case PdfAnnotationSubtype.REDACT:
|
|
4015
4038
|
{
|
|
4016
|
-
annotation = this.readPdfRedactAnno(page, annotationPtr, index);
|
|
4039
|
+
annotation = this.readPdfRedactAnno(doc, page, annotationPtr, index);
|
|
4017
4040
|
}
|
|
4018
4041
|
break;
|
|
4019
4042
|
default:
|
|
4020
4043
|
{
|
|
4021
|
-
annotation = this.readPdfAnno(page, subType, annotationPtr, index);
|
|
4044
|
+
annotation = this.readPdfAnno(doc, page, subType, annotationPtr, index);
|
|
4022
4045
|
}
|
|
4023
4046
|
break;
|
|
4024
4047
|
}
|
|
@@ -4539,11 +4562,12 @@ class PdfiumNative {
|
|
|
4539
4562
|
}
|
|
4540
4563
|
/**
|
|
4541
4564
|
* Get the start and end points of a LINE / POLYLINE annot.
|
|
4565
|
+
* @param doc - pdf document object
|
|
4542
4566
|
* @param annotationPtr - pointer to an `FPDF_ANNOTATION`
|
|
4543
4567
|
* @param page - logical page info object (`PdfPageObject`)
|
|
4544
4568
|
* @returns `{ start, end }` or `undefined` when PDFium can't read them
|
|
4545
4569
|
*/
|
|
4546
|
-
getLinePoints(page, annotationPtr) {
|
|
4570
|
+
getLinePoints(doc, page, annotationPtr) {
|
|
4547
4571
|
const startPtr = this.memoryManager.malloc(8);
|
|
4548
4572
|
const endPtr = this.memoryManager.malloc(8);
|
|
4549
4573
|
const ok = this.pdfiumModule.FPDFAnnot_GetLine(annotationPtr, startPtr, endPtr);
|
|
@@ -4559,22 +4583,23 @@ class PdfiumNative {
|
|
|
4559
4583
|
const ey = pdf.getValue(endPtr + 4, "float");
|
|
4560
4584
|
this.memoryManager.free(startPtr);
|
|
4561
4585
|
this.memoryManager.free(endPtr);
|
|
4562
|
-
const start = this.convertPagePointToDevicePoint(page, { x: sx, y: sy });
|
|
4563
|
-
const end = this.convertPagePointToDevicePoint(page, { x: ex, y: ey });
|
|
4586
|
+
const start = this.convertPagePointToDevicePoint(doc, page, { x: sx, y: sy });
|
|
4587
|
+
const end = this.convertPagePointToDevicePoint(doc, page, { x: ex, y: ey });
|
|
4564
4588
|
return { start, end };
|
|
4565
4589
|
}
|
|
4566
4590
|
/**
|
|
4567
4591
|
* Set the two end‑points of a **Line** annotation
|
|
4568
4592
|
* by writing a new /L array `[ x1 y1 x2 y2 ]`.
|
|
4593
|
+
* @param doc - pdf document object
|
|
4569
4594
|
* @param page - logical page info object (`PdfPageObject`)
|
|
4570
4595
|
* @param annotPtr - pointer to the annotation whose line points are needed
|
|
4571
4596
|
* @param start - start point
|
|
4572
4597
|
* @param end - end point
|
|
4573
4598
|
* @returns true on success
|
|
4574
4599
|
*/
|
|
4575
|
-
setLinePoints(page, annotPtr, start, end) {
|
|
4576
|
-
const p1 = this.convertDevicePointToPagePoint(page, start);
|
|
4577
|
-
const p2 = this.convertDevicePointToPagePoint(page, end);
|
|
4600
|
+
setLinePoints(doc, page, annotPtr, start, end) {
|
|
4601
|
+
const p1 = this.convertDevicePointToPagePoint(doc, page, start);
|
|
4602
|
+
const p2 = this.convertDevicePointToPagePoint(doc, page, end);
|
|
4578
4603
|
if (!p1 || !p2) return false;
|
|
4579
4604
|
const buf = this.memoryManager.malloc(16);
|
|
4580
4605
|
const pdf = this.pdfiumModule.pdfium;
|
|
@@ -4595,13 +4620,14 @@ class PdfiumNative {
|
|
|
4595
4620
|
* This preserves the true shape for rotated / skewed text, whereas callers
|
|
4596
4621
|
* that only need axis-aligned boxes can collapse each quad themselves.
|
|
4597
4622
|
*
|
|
4623
|
+
* @param doc - pdf document object
|
|
4598
4624
|
* @param page - logical page info object (`PdfPageObject`)
|
|
4599
4625
|
* @param annotationPtr - pointer to the annotation whose quads are needed
|
|
4600
4626
|
* @returns Array of `Rect` objects (`[]` if the annotation has no quads)
|
|
4601
4627
|
*
|
|
4602
4628
|
* @private
|
|
4603
4629
|
*/
|
|
4604
|
-
getQuadPointsAnno(page, annotationPtr) {
|
|
4630
|
+
getQuadPointsAnno(doc, page, annotationPtr) {
|
|
4605
4631
|
const quadCount = this.pdfiumModule.FPDFAnnot_CountAttachmentPoints(annotationPtr);
|
|
4606
4632
|
if (quadCount === 0) return [];
|
|
4607
4633
|
const FS_QUADPOINTSF_SIZE = 8 * 4;
|
|
@@ -4617,10 +4643,10 @@ class PdfiumNative {
|
|
|
4617
4643
|
xs.push(this.pdfiumModule.pdfium.getValue(base, "float"));
|
|
4618
4644
|
ys.push(this.pdfiumModule.pdfium.getValue(base + 4, "float"));
|
|
4619
4645
|
}
|
|
4620
|
-
const p1 = this.convertPagePointToDevicePoint(page, { x: xs[0], y: ys[0] });
|
|
4621
|
-
const p2 = this.convertPagePointToDevicePoint(page, { x: xs[1], y: ys[1] });
|
|
4622
|
-
const p3 = this.convertPagePointToDevicePoint(page, { x: xs[2], y: ys[2] });
|
|
4623
|
-
const p4 = this.convertPagePointToDevicePoint(page, { x: xs[3], y: ys[3] });
|
|
4646
|
+
const p1 = this.convertPagePointToDevicePoint(doc, page, { x: xs[0], y: ys[0] });
|
|
4647
|
+
const p2 = this.convertPagePointToDevicePoint(doc, page, { x: xs[1], y: ys[1] });
|
|
4648
|
+
const p3 = this.convertPagePointToDevicePoint(doc, page, { x: xs[2], y: ys[2] });
|
|
4649
|
+
const p4 = this.convertPagePointToDevicePoint(doc, page, { x: xs[3], y: ys[3] });
|
|
4624
4650
|
quads.push({ p1, p2, p3, p4 });
|
|
4625
4651
|
}
|
|
4626
4652
|
this.memoryManager.free(quadPtr);
|
|
@@ -4630,6 +4656,7 @@ class PdfiumNative {
|
|
|
4630
4656
|
/**
|
|
4631
4657
|
* Set the quadrilaterals for a **Highlight / Underline / StrikeOut / Squiggly** markup annotation.
|
|
4632
4658
|
*
|
|
4659
|
+
* @param doc - pdf document object
|
|
4633
4660
|
* @param page - logical page info object (`PdfPageObject`)
|
|
4634
4661
|
* @param annotationPtr - pointer to the annotation whose quads are needed
|
|
4635
4662
|
* @param rects - array of `Rect` objects (`[]` if the annotation has no quads)
|
|
@@ -4637,17 +4664,17 @@ class PdfiumNative {
|
|
|
4637
4664
|
*
|
|
4638
4665
|
* @private
|
|
4639
4666
|
*/
|
|
4640
|
-
syncQuadPointsAnno(page, annotPtr, rects) {
|
|
4667
|
+
syncQuadPointsAnno(doc, page, annotPtr, rects) {
|
|
4641
4668
|
const FS_QUADPOINTSF_SIZE = 8 * 4;
|
|
4642
4669
|
const pdf = this.pdfiumModule.pdfium;
|
|
4643
4670
|
const count = this.pdfiumModule.FPDFAnnot_CountAttachmentPoints(annotPtr);
|
|
4644
4671
|
const buf = this.memoryManager.malloc(FS_QUADPOINTSF_SIZE);
|
|
4645
4672
|
const writeQuad = (r) => {
|
|
4646
4673
|
const q = rectToQuad(r);
|
|
4647
|
-
const p1 = this.convertDevicePointToPagePoint(page, q.p1);
|
|
4648
|
-
const p2 = this.convertDevicePointToPagePoint(page, q.p2);
|
|
4649
|
-
const p3 = this.convertDevicePointToPagePoint(page, q.p3);
|
|
4650
|
-
const p4 = this.convertDevicePointToPagePoint(page, q.p4);
|
|
4674
|
+
const p1 = this.convertDevicePointToPagePoint(doc, page, q.p1);
|
|
4675
|
+
const p2 = this.convertDevicePointToPagePoint(doc, page, q.p2);
|
|
4676
|
+
const p3 = this.convertDevicePointToPagePoint(doc, page, q.p3);
|
|
4677
|
+
const p4 = this.convertDevicePointToPagePoint(doc, page, q.p4);
|
|
4651
4678
|
pdf.setValue(buf + 0, p1.x, "float");
|
|
4652
4679
|
pdf.setValue(buf + 4, p1.y, "float");
|
|
4653
4680
|
pdf.setValue(buf + 8, p2.x, "float");
|
|
@@ -4710,7 +4737,7 @@ class PdfiumNative {
|
|
|
4710
4737
|
return PdfTaskHelper.resolve(false);
|
|
4711
4738
|
}
|
|
4712
4739
|
const pageCtx = ctx.acquirePage(page.index);
|
|
4713
|
-
const { ptr, count } = this.allocFSQuadsBufferFromRects(page, clean);
|
|
4740
|
+
const { ptr, count } = this.allocFSQuadsBufferFromRects(doc, page, clean);
|
|
4714
4741
|
let ok = false;
|
|
4715
4742
|
try {
|
|
4716
4743
|
ok = !!this.pdfiumModule.EPDFText_RedactInQuads(
|
|
@@ -4857,7 +4884,7 @@ class PdfiumNative {
|
|
|
4857
4884
|
return PdfTaskHelper.resolve(!!ok);
|
|
4858
4885
|
}
|
|
4859
4886
|
/** Pack device-space Rects into an FS_QUADPOINTSF[] buffer (page space). */
|
|
4860
|
-
allocFSQuadsBufferFromRects(page, rects) {
|
|
4887
|
+
allocFSQuadsBufferFromRects(doc, page, rects) {
|
|
4861
4888
|
const STRIDE = 32;
|
|
4862
4889
|
const count = rects.length;
|
|
4863
4890
|
const ptr = this.memoryManager.malloc(STRIDE * count);
|
|
@@ -4865,10 +4892,10 @@ class PdfiumNative {
|
|
|
4865
4892
|
for (let i = 0; i < count; i++) {
|
|
4866
4893
|
const r = rects[i];
|
|
4867
4894
|
const q = rectToQuad(r);
|
|
4868
|
-
const p1 = this.convertDevicePointToPagePoint(page, q.p1);
|
|
4869
|
-
const p2 = this.convertDevicePointToPagePoint(page, q.p2);
|
|
4870
|
-
const p3 = this.convertDevicePointToPagePoint(page, q.p3);
|
|
4871
|
-
const p4 = this.convertDevicePointToPagePoint(page, q.p4);
|
|
4895
|
+
const p1 = this.convertDevicePointToPagePoint(doc, page, q.p1);
|
|
4896
|
+
const p2 = this.convertDevicePointToPagePoint(doc, page, q.p2);
|
|
4897
|
+
const p3 = this.convertDevicePointToPagePoint(doc, page, q.p3);
|
|
4898
|
+
const p4 = this.convertDevicePointToPagePoint(doc, page, q.p4);
|
|
4872
4899
|
const base = ptr + i * STRIDE;
|
|
4873
4900
|
pdf.setValue(base + 0, p1.x, "float");
|
|
4874
4901
|
pdf.setValue(base + 4, p1.y, "float");
|
|
@@ -4883,12 +4910,13 @@ class PdfiumNative {
|
|
|
4883
4910
|
}
|
|
4884
4911
|
/**
|
|
4885
4912
|
* Read ink list from annotation
|
|
4913
|
+
* @param doc - pdf document object
|
|
4886
4914
|
* @param page - logical page info object (`PdfPageObject`)
|
|
4887
4915
|
* @param pagePtr - pointer to the page
|
|
4888
4916
|
* @param annotationPtr - pointer to the annotation whose ink list is needed
|
|
4889
4917
|
* @returns ink list
|
|
4890
4918
|
*/
|
|
4891
|
-
getInkList(page, annotationPtr) {
|
|
4919
|
+
getInkList(doc, page, annotationPtr) {
|
|
4892
4920
|
const inkList = [];
|
|
4893
4921
|
const pathCount = this.pdfiumModule.FPDFAnnot_GetInkListCount(annotationPtr);
|
|
4894
4922
|
if (pathCount <= 0) return inkList;
|
|
@@ -4904,7 +4932,7 @@ class PdfiumNative {
|
|
|
4904
4932
|
const base = buf + j * POINT_STRIDE;
|
|
4905
4933
|
const px = pdf.getValue(base + 0, "float");
|
|
4906
4934
|
const py = pdf.getValue(base + 4, "float");
|
|
4907
|
-
const d = this.convertPagePointToDevicePoint(page, { x: px, y: py });
|
|
4935
|
+
const d = this.convertPagePointToDevicePoint(doc, page, { x: px, y: py });
|
|
4908
4936
|
points.push({ x: d.x, y: d.y });
|
|
4909
4937
|
}
|
|
4910
4938
|
this.memoryManager.free(buf);
|
|
@@ -4915,13 +4943,14 @@ class PdfiumNative {
|
|
|
4915
4943
|
}
|
|
4916
4944
|
/**
|
|
4917
4945
|
* Add ink list to annotation
|
|
4946
|
+
* @param doc - pdf document object
|
|
4918
4947
|
* @param page - logical page info object (`PdfPageObject`)
|
|
4919
4948
|
* @param pagePtr - pointer to the page
|
|
4920
4949
|
* @param annotationPtr - pointer to the annotation whose ink list is needed
|
|
4921
4950
|
* @param inkList - ink list array of `PdfInkListObject`
|
|
4922
4951
|
* @returns `true` if the operation was successful
|
|
4923
4952
|
*/
|
|
4924
|
-
setInkList(page, annotationPtr, inkList) {
|
|
4953
|
+
setInkList(doc, page, annotationPtr, inkList) {
|
|
4925
4954
|
const pdf = this.pdfiumModule.pdfium;
|
|
4926
4955
|
const POINT_STRIDE = 8;
|
|
4927
4956
|
for (const stroke of inkList) {
|
|
@@ -4930,7 +4959,7 @@ class PdfiumNative {
|
|
|
4930
4959
|
const buf = this.memoryManager.malloc(n * POINT_STRIDE);
|
|
4931
4960
|
for (let i = 0; i < n; i++) {
|
|
4932
4961
|
const pDev = stroke.points[i];
|
|
4933
|
-
const pPage = this.convertDevicePointToPagePoint(page, pDev);
|
|
4962
|
+
const pPage = this.convertDevicePointToPagePoint(doc, page, pDev);
|
|
4934
4963
|
pdf.setValue(buf + i * POINT_STRIDE + 0, pPage.x, "float");
|
|
4935
4964
|
pdf.setValue(buf + i * POINT_STRIDE + 4, pPage.y, "float");
|
|
4936
4965
|
}
|
|
@@ -4951,9 +4980,9 @@ class PdfiumNative {
|
|
|
4951
4980
|
*
|
|
4952
4981
|
* @private
|
|
4953
4982
|
*/
|
|
4954
|
-
readPdfTextAnno(page, annotationPtr, index) {
|
|
4983
|
+
readPdfTextAnno(doc, page, annotationPtr, index) {
|
|
4955
4984
|
const annoRect = this.readPageAnnoRect(annotationPtr);
|
|
4956
|
-
const rect = this.convertPageRectToDeviceRect(page, annoRect);
|
|
4985
|
+
const rect = this.convertPageRectToDeviceRect(doc, page, annoRect);
|
|
4957
4986
|
const state = this.getAnnotString(annotationPtr, "State");
|
|
4958
4987
|
const stateModel = this.getAnnotString(annotationPtr, "StateModel");
|
|
4959
4988
|
const color = this.getAnnotationColor(annotationPtr);
|
|
@@ -4981,9 +5010,9 @@ class PdfiumNative {
|
|
|
4981
5010
|
*
|
|
4982
5011
|
* @private
|
|
4983
5012
|
*/
|
|
4984
|
-
readPdfFreeTextAnno(page, annotationPtr, index) {
|
|
5013
|
+
readPdfFreeTextAnno(doc, page, annotationPtr, index) {
|
|
4985
5014
|
const annoRect = this.readPageAnnoRect(annotationPtr);
|
|
4986
|
-
const rect = this.convertPageRectToDeviceRect(page, annoRect);
|
|
5015
|
+
const rect = this.convertPageRectToDeviceRect(doc, page, annoRect);
|
|
4987
5016
|
const defaultStyle = this.getAnnotString(annotationPtr, "DS");
|
|
4988
5017
|
const da = this.getAnnotationDefaultAppearance(annotationPtr);
|
|
4989
5018
|
const bgColor = this.getAnnotationColor(annotationPtr);
|
|
@@ -5021,13 +5050,13 @@ class PdfiumNative {
|
|
|
5021
5050
|
*
|
|
5022
5051
|
* @private
|
|
5023
5052
|
*/
|
|
5024
|
-
readPdfLinkAnno(page, docPtr, annotationPtr, index) {
|
|
5053
|
+
readPdfLinkAnno(doc, page, docPtr, annotationPtr, index) {
|
|
5025
5054
|
const linkPtr = this.pdfiumModule.FPDFAnnot_GetLink(annotationPtr);
|
|
5026
5055
|
if (!linkPtr) {
|
|
5027
5056
|
return;
|
|
5028
5057
|
}
|
|
5029
5058
|
const annoRect = this.readPageAnnoRect(annotationPtr);
|
|
5030
|
-
const rect = this.convertPageRectToDeviceRect(page, annoRect);
|
|
5059
|
+
const rect = this.convertPageRectToDeviceRect(doc, page, annoRect);
|
|
5031
5060
|
const { style: strokeStyle, width: strokeWidth } = this.getBorderStyle(annotationPtr);
|
|
5032
5061
|
const strokeColor = this.getAnnotationColor(annotationPtr, PdfAnnotationColorType.Color);
|
|
5033
5062
|
let strokeDashArray;
|
|
@@ -5069,9 +5098,9 @@ class PdfiumNative {
|
|
|
5069
5098
|
*
|
|
5070
5099
|
* @private
|
|
5071
5100
|
*/
|
|
5072
|
-
readPdfWidgetAnno(page, annotationPtr, formHandle, index) {
|
|
5101
|
+
readPdfWidgetAnno(doc, page, annotationPtr, formHandle, index) {
|
|
5073
5102
|
const pageRect = this.readPageAnnoRect(annotationPtr);
|
|
5074
|
-
const rect = this.convertPageRectToDeviceRect(page, pageRect);
|
|
5103
|
+
const rect = this.convertPageRectToDeviceRect(doc, page, pageRect);
|
|
5075
5104
|
const field = this.readPdfWidgetAnnoField(formHandle, annotationPtr);
|
|
5076
5105
|
return {
|
|
5077
5106
|
pageIndex: page.index,
|
|
@@ -5091,9 +5120,9 @@ class PdfiumNative {
|
|
|
5091
5120
|
*
|
|
5092
5121
|
* @private
|
|
5093
5122
|
*/
|
|
5094
|
-
readPdfFileAttachmentAnno(page, annotationPtr, index) {
|
|
5123
|
+
readPdfFileAttachmentAnno(doc, page, annotationPtr, index) {
|
|
5095
5124
|
const pageRect = this.readPageAnnoRect(annotationPtr);
|
|
5096
|
-
const rect = this.convertPageRectToDeviceRect(page, pageRect);
|
|
5125
|
+
const rect = this.convertPageRectToDeviceRect(doc, page, pageRect);
|
|
5097
5126
|
return {
|
|
5098
5127
|
pageIndex: page.index,
|
|
5099
5128
|
id: index,
|
|
@@ -5111,13 +5140,13 @@ class PdfiumNative {
|
|
|
5111
5140
|
*
|
|
5112
5141
|
* @private
|
|
5113
5142
|
*/
|
|
5114
|
-
readPdfInkAnno(page, annotationPtr, index) {
|
|
5143
|
+
readPdfInkAnno(doc, page, annotationPtr, index) {
|
|
5115
5144
|
const pageRect = this.readPageAnnoRect(annotationPtr);
|
|
5116
|
-
const rect = this.convertPageRectToDeviceRect(page, pageRect);
|
|
5145
|
+
const rect = this.convertPageRectToDeviceRect(doc, page, pageRect);
|
|
5117
5146
|
const strokeColor = this.getAnnotationColor(annotationPtr) ?? "#FF0000";
|
|
5118
5147
|
const opacity = this.getAnnotationOpacity(annotationPtr);
|
|
5119
5148
|
const { width: strokeWidth } = this.getBorderStyle(annotationPtr);
|
|
5120
|
-
const inkList = this.getInkList(page, annotationPtr);
|
|
5149
|
+
const inkList = this.getInkList(doc, page, annotationPtr);
|
|
5121
5150
|
const blendMode = this.pdfiumModule.EPDFAnnot_GetBlendMode(annotationPtr);
|
|
5122
5151
|
const intent = this.getAnnotIntent(annotationPtr);
|
|
5123
5152
|
return {
|
|
@@ -5145,10 +5174,10 @@ class PdfiumNative {
|
|
|
5145
5174
|
*
|
|
5146
5175
|
* @private
|
|
5147
5176
|
*/
|
|
5148
|
-
readPdfPolygonAnno(page, annotationPtr, index) {
|
|
5177
|
+
readPdfPolygonAnno(doc, page, annotationPtr, index) {
|
|
5149
5178
|
const pageRect = this.readPageAnnoRect(annotationPtr);
|
|
5150
|
-
const rect = this.convertPageRectToDeviceRect(page, pageRect);
|
|
5151
|
-
const vertices = this.readPdfAnnoVertices(page, annotationPtr);
|
|
5179
|
+
const rect = this.convertPageRectToDeviceRect(doc, page, pageRect);
|
|
5180
|
+
const vertices = this.readPdfAnnoVertices(doc, page, annotationPtr);
|
|
5152
5181
|
const strokeColor = this.getAnnotationColor(annotationPtr);
|
|
5153
5182
|
const interiorColor = this.getAnnotationColor(
|
|
5154
5183
|
annotationPtr,
|
|
@@ -5194,10 +5223,10 @@ class PdfiumNative {
|
|
|
5194
5223
|
*
|
|
5195
5224
|
* @private
|
|
5196
5225
|
*/
|
|
5197
|
-
readPdfPolylineAnno(page, annotationPtr, index) {
|
|
5226
|
+
readPdfPolylineAnno(doc, page, annotationPtr, index) {
|
|
5198
5227
|
const pageRect = this.readPageAnnoRect(annotationPtr);
|
|
5199
|
-
const rect = this.convertPageRectToDeviceRect(page, pageRect);
|
|
5200
|
-
const vertices = this.readPdfAnnoVertices(page, annotationPtr);
|
|
5228
|
+
const rect = this.convertPageRectToDeviceRect(doc, page, pageRect);
|
|
5229
|
+
const vertices = this.readPdfAnnoVertices(doc, page, annotationPtr);
|
|
5201
5230
|
const strokeColor = this.getAnnotationColor(annotationPtr);
|
|
5202
5231
|
const interiorColor = this.getAnnotationColor(
|
|
5203
5232
|
annotationPtr,
|
|
@@ -5238,10 +5267,10 @@ class PdfiumNative {
|
|
|
5238
5267
|
*
|
|
5239
5268
|
* @private
|
|
5240
5269
|
*/
|
|
5241
|
-
readPdfLineAnno(page, annotationPtr, index) {
|
|
5270
|
+
readPdfLineAnno(doc, page, annotationPtr, index) {
|
|
5242
5271
|
const pageRect = this.readPageAnnoRect(annotationPtr);
|
|
5243
|
-
const rect = this.convertPageRectToDeviceRect(page, pageRect);
|
|
5244
|
-
const linePoints = this.getLinePoints(page, annotationPtr);
|
|
5272
|
+
const rect = this.convertPageRectToDeviceRect(doc, page, pageRect);
|
|
5273
|
+
const linePoints = this.getLinePoints(doc, page, annotationPtr);
|
|
5245
5274
|
const lineEndings = this.getLineEndings(annotationPtr);
|
|
5246
5275
|
const strokeColor = this.getAnnotationColor(annotationPtr);
|
|
5247
5276
|
const interiorColor = this.getAnnotationColor(
|
|
@@ -5285,10 +5314,10 @@ class PdfiumNative {
|
|
|
5285
5314
|
*
|
|
5286
5315
|
* @private
|
|
5287
5316
|
*/
|
|
5288
|
-
readPdfHighlightAnno(page, annotationPtr, index) {
|
|
5317
|
+
readPdfHighlightAnno(doc, page, annotationPtr, index) {
|
|
5289
5318
|
const pageRect = this.readPageAnnoRect(annotationPtr);
|
|
5290
|
-
const rect = this.convertPageRectToDeviceRect(page, pageRect);
|
|
5291
|
-
const segmentRects = this.getQuadPointsAnno(page, annotationPtr);
|
|
5319
|
+
const rect = this.convertPageRectToDeviceRect(doc, page, pageRect);
|
|
5320
|
+
const segmentRects = this.getQuadPointsAnno(doc, page, annotationPtr);
|
|
5292
5321
|
const strokeColor = this.getAnnotationColor(annotationPtr) ?? "#FFFF00";
|
|
5293
5322
|
const opacity = this.getAnnotationOpacity(annotationPtr);
|
|
5294
5323
|
const blendMode = this.pdfiumModule.EPDFAnnot_GetBlendMode(annotationPtr);
|
|
@@ -5315,10 +5344,10 @@ class PdfiumNative {
|
|
|
5315
5344
|
*
|
|
5316
5345
|
* @private
|
|
5317
5346
|
*/
|
|
5318
|
-
readPdfUnderlineAnno(page, annotationPtr, index) {
|
|
5347
|
+
readPdfUnderlineAnno(doc, page, annotationPtr, index) {
|
|
5319
5348
|
const pageRect = this.readPageAnnoRect(annotationPtr);
|
|
5320
|
-
const rect = this.convertPageRectToDeviceRect(page, pageRect);
|
|
5321
|
-
const segmentRects = this.getQuadPointsAnno(page, annotationPtr);
|
|
5349
|
+
const rect = this.convertPageRectToDeviceRect(doc, page, pageRect);
|
|
5350
|
+
const segmentRects = this.getQuadPointsAnno(doc, page, annotationPtr);
|
|
5322
5351
|
const strokeColor = this.getAnnotationColor(annotationPtr) ?? "#FF0000";
|
|
5323
5352
|
const opacity = this.getAnnotationOpacity(annotationPtr);
|
|
5324
5353
|
const blendMode = this.pdfiumModule.EPDFAnnot_GetBlendMode(annotationPtr);
|
|
@@ -5345,10 +5374,10 @@ class PdfiumNative {
|
|
|
5345
5374
|
*
|
|
5346
5375
|
* @private
|
|
5347
5376
|
*/
|
|
5348
|
-
readPdfStrikeOutAnno(page, annotationPtr, index) {
|
|
5377
|
+
readPdfStrikeOutAnno(doc, page, annotationPtr, index) {
|
|
5349
5378
|
const pageRect = this.readPageAnnoRect(annotationPtr);
|
|
5350
|
-
const rect = this.convertPageRectToDeviceRect(page, pageRect);
|
|
5351
|
-
const segmentRects = this.getQuadPointsAnno(page, annotationPtr);
|
|
5379
|
+
const rect = this.convertPageRectToDeviceRect(doc, page, pageRect);
|
|
5380
|
+
const segmentRects = this.getQuadPointsAnno(doc, page, annotationPtr);
|
|
5352
5381
|
const strokeColor = this.getAnnotationColor(annotationPtr) ?? "#FF0000";
|
|
5353
5382
|
const opacity = this.getAnnotationOpacity(annotationPtr);
|
|
5354
5383
|
const blendMode = this.pdfiumModule.EPDFAnnot_GetBlendMode(annotationPtr);
|
|
@@ -5375,10 +5404,10 @@ class PdfiumNative {
|
|
|
5375
5404
|
*
|
|
5376
5405
|
* @private
|
|
5377
5406
|
*/
|
|
5378
|
-
readPdfSquigglyAnno(page, annotationPtr, index) {
|
|
5407
|
+
readPdfSquigglyAnno(doc, page, annotationPtr, index) {
|
|
5379
5408
|
const pageRect = this.readPageAnnoRect(annotationPtr);
|
|
5380
|
-
const rect = this.convertPageRectToDeviceRect(page, pageRect);
|
|
5381
|
-
const segmentRects = this.getQuadPointsAnno(page, annotationPtr);
|
|
5409
|
+
const rect = this.convertPageRectToDeviceRect(doc, page, pageRect);
|
|
5410
|
+
const segmentRects = this.getQuadPointsAnno(doc, page, annotationPtr);
|
|
5382
5411
|
const strokeColor = this.getAnnotationColor(annotationPtr) ?? "#FF0000";
|
|
5383
5412
|
const opacity = this.getAnnotationOpacity(annotationPtr);
|
|
5384
5413
|
const blendMode = this.pdfiumModule.EPDFAnnot_GetBlendMode(annotationPtr);
|
|
@@ -5405,9 +5434,9 @@ class PdfiumNative {
|
|
|
5405
5434
|
*
|
|
5406
5435
|
* @private
|
|
5407
5436
|
*/
|
|
5408
|
-
readPdfCaretAnno(page, annotationPtr, index) {
|
|
5437
|
+
readPdfCaretAnno(doc, page, annotationPtr, index) {
|
|
5409
5438
|
const pageRect = this.readPageAnnoRect(annotationPtr);
|
|
5410
|
-
const rect = this.convertPageRectToDeviceRect(page, pageRect);
|
|
5439
|
+
const rect = this.convertPageRectToDeviceRect(doc, page, pageRect);
|
|
5411
5440
|
return {
|
|
5412
5441
|
pageIndex: page.index,
|
|
5413
5442
|
id: index,
|
|
@@ -5425,10 +5454,10 @@ class PdfiumNative {
|
|
|
5425
5454
|
*
|
|
5426
5455
|
* @private
|
|
5427
5456
|
*/
|
|
5428
|
-
readPdfRedactAnno(page, annotationPtr, index) {
|
|
5457
|
+
readPdfRedactAnno(doc, page, annotationPtr, index) {
|
|
5429
5458
|
const pageRect = this.readPageAnnoRect(annotationPtr);
|
|
5430
|
-
const rect = this.convertPageRectToDeviceRect(page, pageRect);
|
|
5431
|
-
const segmentRects = this.getQuadPointsAnno(page, annotationPtr);
|
|
5459
|
+
const rect = this.convertPageRectToDeviceRect(doc, page, pageRect);
|
|
5460
|
+
const segmentRects = this.getQuadPointsAnno(doc, page, annotationPtr);
|
|
5432
5461
|
const color = this.getAnnotationColor(annotationPtr, PdfAnnotationColorType.InteriorColor);
|
|
5433
5462
|
const overlayColor = this.getAnnotationColor(
|
|
5434
5463
|
annotationPtr,
|
|
@@ -5468,9 +5497,9 @@ class PdfiumNative {
|
|
|
5468
5497
|
*
|
|
5469
5498
|
* @private
|
|
5470
5499
|
*/
|
|
5471
|
-
readPdfStampAnno(page, annotationPtr, index) {
|
|
5500
|
+
readPdfStampAnno(doc, page, annotationPtr, index) {
|
|
5472
5501
|
const pageRect = this.readPageAnnoRect(annotationPtr);
|
|
5473
|
-
const rect = this.convertPageRectToDeviceRect(page, pageRect);
|
|
5502
|
+
const rect = this.convertPageRectToDeviceRect(doc, page, pageRect);
|
|
5474
5503
|
return {
|
|
5475
5504
|
pageIndex: page.index,
|
|
5476
5505
|
id: index,
|
|
@@ -5711,9 +5740,9 @@ class PdfiumNative {
|
|
|
5711
5740
|
*
|
|
5712
5741
|
* @private
|
|
5713
5742
|
*/
|
|
5714
|
-
readPdfCircleAnno(page, annotationPtr, index) {
|
|
5743
|
+
readPdfCircleAnno(doc, page, annotationPtr, index) {
|
|
5715
5744
|
const pageRect = this.readPageAnnoRect(annotationPtr);
|
|
5716
|
-
const rect = this.convertPageRectToDeviceRect(page, pageRect);
|
|
5745
|
+
const rect = this.convertPageRectToDeviceRect(doc, page, pageRect);
|
|
5717
5746
|
const interiorColor = this.getAnnotationColor(
|
|
5718
5747
|
annotationPtr,
|
|
5719
5748
|
PdfAnnotationColorType.InteriorColor
|
|
@@ -5751,9 +5780,9 @@ class PdfiumNative {
|
|
|
5751
5780
|
*
|
|
5752
5781
|
* @private
|
|
5753
5782
|
*/
|
|
5754
|
-
readPdfSquareAnno(page, annotationPtr, index) {
|
|
5783
|
+
readPdfSquareAnno(doc, page, annotationPtr, index) {
|
|
5755
5784
|
const pageRect = this.readPageAnnoRect(annotationPtr);
|
|
5756
|
-
const rect = this.convertPageRectToDeviceRect(page, pageRect);
|
|
5785
|
+
const rect = this.convertPageRectToDeviceRect(doc, page, pageRect);
|
|
5757
5786
|
const interiorColor = this.getAnnotationColor(
|
|
5758
5787
|
annotationPtr,
|
|
5759
5788
|
PdfAnnotationColorType.InteriorColor
|
|
@@ -5792,9 +5821,9 @@ class PdfiumNative {
|
|
|
5792
5821
|
*
|
|
5793
5822
|
* @private
|
|
5794
5823
|
*/
|
|
5795
|
-
readPdfAnno(page, type, annotationPtr, index) {
|
|
5824
|
+
readPdfAnno(doc, page, type, annotationPtr, index) {
|
|
5796
5825
|
const pageRect = this.readPageAnnoRect(annotationPtr);
|
|
5797
|
-
const rect = this.convertPageRectToDeviceRect(page, pageRect);
|
|
5826
|
+
const rect = this.convertPageRectToDeviceRect(doc, page, pageRect);
|
|
5798
5827
|
return {
|
|
5799
5828
|
pageIndex: page.index,
|
|
5800
5829
|
id: index,
|
|
@@ -6095,13 +6124,14 @@ class PdfiumNative {
|
|
|
6095
6124
|
}
|
|
6096
6125
|
/**
|
|
6097
6126
|
* Read vertices of pdf annotation
|
|
6127
|
+
* @param doc - pdf document object
|
|
6098
6128
|
* @param page - pdf page infor
|
|
6099
6129
|
* @param annotationPtr - pointer to pdf annotation
|
|
6100
6130
|
* @returns vertices of pdf annotation
|
|
6101
6131
|
*
|
|
6102
6132
|
* @private
|
|
6103
6133
|
*/
|
|
6104
|
-
readPdfAnnoVertices(page, annotationPtr) {
|
|
6134
|
+
readPdfAnnoVertices(doc, page, annotationPtr) {
|
|
6105
6135
|
const vertices = [];
|
|
6106
6136
|
const count = this.pdfiumModule.FPDFAnnot_GetVertices(annotationPtr, 0, 0);
|
|
6107
6137
|
const pointMemorySize = 8;
|
|
@@ -6113,7 +6143,7 @@ class PdfiumNative {
|
|
|
6113
6143
|
pointsPtr + i * pointMemorySize + 4,
|
|
6114
6144
|
"float"
|
|
6115
6145
|
);
|
|
6116
|
-
const { x, y } = this.convertPagePointToDevicePoint(page, {
|
|
6146
|
+
const { x, y } = this.convertPagePointToDevicePoint(doc, page, {
|
|
6117
6147
|
x: pointX,
|
|
6118
6148
|
y: pointY
|
|
6119
6149
|
});
|
|
@@ -6128,6 +6158,7 @@ class PdfiumNative {
|
|
|
6128
6158
|
/**
|
|
6129
6159
|
* Sync the vertices of a polygon or polyline annotation.
|
|
6130
6160
|
*
|
|
6161
|
+
* @param doc - pdf document object
|
|
6131
6162
|
* @param page - pdf page infor
|
|
6132
6163
|
* @param annotPtr - pointer to pdf annotation
|
|
6133
6164
|
* @param vertices - the vertices to be set
|
|
@@ -6135,12 +6166,12 @@ class PdfiumNative {
|
|
|
6135
6166
|
*
|
|
6136
6167
|
* @private
|
|
6137
6168
|
*/
|
|
6138
|
-
setPdfAnnoVertices(page, annotPtr, vertices) {
|
|
6169
|
+
setPdfAnnoVertices(doc, page, annotPtr, vertices) {
|
|
6139
6170
|
const pdf = this.pdfiumModule.pdfium;
|
|
6140
6171
|
const FS_POINTF_SIZE = 8;
|
|
6141
6172
|
const buf = this.memoryManager.malloc(FS_POINTF_SIZE * vertices.length);
|
|
6142
6173
|
vertices.forEach((v, i) => {
|
|
6143
|
-
const pagePt = this.convertDevicePointToPagePoint(page, v);
|
|
6174
|
+
const pagePt = this.convertDevicePointToPagePoint(doc, page, v);
|
|
6144
6175
|
pdf.setValue(buf + i * FS_POINTF_SIZE + 0, pagePt.x, "float");
|
|
6145
6176
|
pdf.setValue(buf + i * FS_POINTF_SIZE + 4, pagePt.y, "float");
|
|
6146
6177
|
});
|
|
@@ -6894,16 +6925,17 @@ class PdfiumNative {
|
|
|
6894
6925
|
}
|
|
6895
6926
|
/**
|
|
6896
6927
|
* Convert coordinate of point from device coordinate to page coordinate
|
|
6928
|
+
* @param doc - pdf document object
|
|
6897
6929
|
* @param page - pdf page infor
|
|
6898
6930
|
* @param position - position of point
|
|
6899
6931
|
* @returns converted position
|
|
6900
6932
|
*
|
|
6901
6933
|
* @private
|
|
6902
6934
|
*/
|
|
6903
|
-
convertDevicePointToPagePoint(page, position) {
|
|
6935
|
+
convertDevicePointToPagePoint(doc, page, position) {
|
|
6904
6936
|
const DW = page.size.width;
|
|
6905
6937
|
const DH = page.size.height;
|
|
6906
|
-
const r = page.rotation & 3;
|
|
6938
|
+
const r = doc.normalizedRotation ? 0 : page.rotation & 3;
|
|
6907
6939
|
if (r === 0) {
|
|
6908
6940
|
return { x: position.x, y: DH - position.y };
|
|
6909
6941
|
}
|
|
@@ -6919,16 +6951,17 @@ class PdfiumNative {
|
|
|
6919
6951
|
}
|
|
6920
6952
|
/**
|
|
6921
6953
|
* Convert coordinate of point from page coordinate to device coordinate
|
|
6954
|
+
* @param doc - pdf document object
|
|
6922
6955
|
* @param page - pdf page infor
|
|
6923
6956
|
* @param position - position of point
|
|
6924
6957
|
* @returns converted position
|
|
6925
6958
|
*
|
|
6926
6959
|
* @private
|
|
6927
6960
|
*/
|
|
6928
|
-
convertPagePointToDevicePoint(page, position) {
|
|
6961
|
+
convertPagePointToDevicePoint(doc, page, position) {
|
|
6929
6962
|
const DW = page.size.width;
|
|
6930
6963
|
const DH = page.size.height;
|
|
6931
|
-
const r = page.rotation & 3;
|
|
6964
|
+
const r = doc.normalizedRotation ? 0 : page.rotation & 3;
|
|
6932
6965
|
if (r === 0) {
|
|
6933
6966
|
return { x: position.x, y: DH - position.y };
|
|
6934
6967
|
}
|
|
@@ -6944,6 +6977,7 @@ class PdfiumNative {
|
|
|
6944
6977
|
}
|
|
6945
6978
|
/**
|
|
6946
6979
|
* Convert coordinate of rectangle from page coordinate to device coordinate
|
|
6980
|
+
* @param doc - pdf document object
|
|
6947
6981
|
* @param page - pdf page infor
|
|
6948
6982
|
* @param pagePtr - pointer to pdf page object
|
|
6949
6983
|
* @param pageRect - rectangle that needs to be converted
|
|
@@ -6951,8 +6985,8 @@ class PdfiumNative {
|
|
|
6951
6985
|
*
|
|
6952
6986
|
* @private
|
|
6953
6987
|
*/
|
|
6954
|
-
convertPageRectToDeviceRect(page, pageRect) {
|
|
6955
|
-
const { x, y } = this.convertPagePointToDevicePoint(page, {
|
|
6988
|
+
convertPageRectToDeviceRect(doc, page, pageRect) {
|
|
6989
|
+
const { x, y } = this.convertPagePointToDevicePoint(doc, page, {
|
|
6956
6990
|
x: pageRect.left,
|
|
6957
6991
|
y: pageRect.top
|
|
6958
6992
|
});
|
|
@@ -7022,6 +7056,7 @@ class PdfiumNative {
|
|
|
7022
7056
|
}
|
|
7023
7057
|
/**
|
|
7024
7058
|
* Set the rect of specified annotation
|
|
7059
|
+
* @param doc - pdf document object
|
|
7025
7060
|
* @param page - page info that the annotation is belonged to
|
|
7026
7061
|
* @param annotationPtr - pointer to annotation object
|
|
7027
7062
|
* @param rect - target rectangle
|
|
@@ -7029,15 +7064,15 @@ class PdfiumNative {
|
|
|
7029
7064
|
*
|
|
7030
7065
|
* @private
|
|
7031
7066
|
*/
|
|
7032
|
-
setPageAnnoRect(page, annotPtr, rect) {
|
|
7067
|
+
setPageAnnoRect(doc, page, annotPtr, rect) {
|
|
7033
7068
|
const x0d = Math.floor(rect.origin.x);
|
|
7034
7069
|
const y0d = Math.floor(rect.origin.y);
|
|
7035
7070
|
const x1d = Math.floor(rect.origin.x + rect.size.width);
|
|
7036
7071
|
const y1d = Math.floor(rect.origin.y + rect.size.height);
|
|
7037
|
-
const TL = this.convertDevicePointToPagePoint(page, { x: x0d, y: y0d });
|
|
7038
|
-
const TR = this.convertDevicePointToPagePoint(page, { x: x1d, y: y0d });
|
|
7039
|
-
const BR = this.convertDevicePointToPagePoint(page, { x: x1d, y: y1d });
|
|
7040
|
-
const BL = this.convertDevicePointToPagePoint(page, { x: x0d, y: y1d });
|
|
7072
|
+
const TL = this.convertDevicePointToPagePoint(doc, page, { x: x0d, y: y0d });
|
|
7073
|
+
const TR = this.convertDevicePointToPagePoint(doc, page, { x: x1d, y: y0d });
|
|
7074
|
+
const BR = this.convertDevicePointToPagePoint(doc, page, { x: x1d, y: y1d });
|
|
7075
|
+
const BL = this.convertDevicePointToPagePoint(doc, page, { x: x0d, y: y1d });
|
|
7041
7076
|
let left = Math.min(TL.x, TR.x, BR.x, BL.x);
|
|
7042
7077
|
let right = Math.max(TL.x, TR.x, BR.x, BL.x);
|
|
7043
7078
|
let bottom = Math.min(TL.y, TR.y, BR.y, BL.y);
|
|
@@ -7080,6 +7115,7 @@ class PdfiumNative {
|
|
|
7080
7115
|
}
|
|
7081
7116
|
/**
|
|
7082
7117
|
* Get highlight rects for a specific character range (for search highlighting)
|
|
7118
|
+
* @param doc - pdf document object
|
|
7083
7119
|
* @param page - pdf page info
|
|
7084
7120
|
* @param pagePtr - pointer to pdf page
|
|
7085
7121
|
* @param textPagePtr - pointer to pdf text page
|
|
@@ -7089,7 +7125,7 @@ class PdfiumNative {
|
|
|
7089
7125
|
*
|
|
7090
7126
|
* @private
|
|
7091
7127
|
*/
|
|
7092
|
-
getHighlightRects(page, textPagePtr, startIndex, charCount) {
|
|
7128
|
+
getHighlightRects(doc, page, textPagePtr, startIndex, charCount) {
|
|
7093
7129
|
const rectsCount = this.pdfiumModule.FPDFText_CountRects(textPagePtr, startIndex, charCount);
|
|
7094
7130
|
const highlightRects = [];
|
|
7095
7131
|
const l = this.memoryManager.malloc(8);
|
|
@@ -7103,10 +7139,10 @@ class PdfiumNative {
|
|
|
7103
7139
|
const top = this.pdfiumModule.pdfium.getValue(t, "double");
|
|
7104
7140
|
const right = this.pdfiumModule.pdfium.getValue(r, "double");
|
|
7105
7141
|
const bottom = this.pdfiumModule.pdfium.getValue(b, "double");
|
|
7106
|
-
const p1 = this.convertPagePointToDevicePoint(page, { x: left, y: top });
|
|
7107
|
-
const p2 = this.convertPagePointToDevicePoint(page, { x: right, y: top });
|
|
7108
|
-
const p3 = this.convertPagePointToDevicePoint(page, { x: right, y: bottom });
|
|
7109
|
-
const p4 = this.convertPagePointToDevicePoint(page, { x: left, y: bottom });
|
|
7142
|
+
const p1 = this.convertPagePointToDevicePoint(doc, page, { x: left, y: top });
|
|
7143
|
+
const p2 = this.convertPagePointToDevicePoint(doc, page, { x: right, y: top });
|
|
7144
|
+
const p3 = this.convertPagePointToDevicePoint(doc, page, { x: right, y: bottom });
|
|
7145
|
+
const p4 = this.convertPagePointToDevicePoint(doc, page, { x: left, y: bottom });
|
|
7110
7146
|
const xs = [p1.x, p2.x, p3.x, p4.x];
|
|
7111
7147
|
const ys = [p1.y, p2.y, p3.y, p4.y];
|
|
7112
7148
|
const x = Math.min(...xs);
|
|
@@ -7147,7 +7183,7 @@ class PdfiumNative {
|
|
|
7147
7183
|
const keywordPtr = this.memoryManager.malloc(length);
|
|
7148
7184
|
this.pdfiumModule.pdfium.stringToUTF16(keyword, keywordPtr, length);
|
|
7149
7185
|
try {
|
|
7150
|
-
const results = this.searchAllInPage(ctx, page, keywordPtr, flags);
|
|
7186
|
+
const results = this.searchAllInPage(doc, ctx, page, keywordPtr, flags);
|
|
7151
7187
|
return PdfTaskHelper.resolve(results);
|
|
7152
7188
|
} finally {
|
|
7153
7189
|
this.memoryManager.free(keywordPtr);
|
|
@@ -7177,7 +7213,7 @@ class PdfiumNative {
|
|
|
7177
7213
|
const total = pages.length;
|
|
7178
7214
|
for (let i = 0; i < pages.length; i++) {
|
|
7179
7215
|
const page = pages[i];
|
|
7180
|
-
const annotations = this.readPageAnnotationsRaw(ctx, page);
|
|
7216
|
+
const annotations = this.readPageAnnotationsRaw(doc, ctx, page);
|
|
7181
7217
|
results[page.index] = annotations;
|
|
7182
7218
|
task.progress({
|
|
7183
7219
|
pageIndex: page.index,
|
|
@@ -7221,7 +7257,7 @@ class PdfiumNative {
|
|
|
7221
7257
|
const total = pages.length;
|
|
7222
7258
|
for (let i = 0; i < pages.length; i++) {
|
|
7223
7259
|
const page = pages[i];
|
|
7224
|
-
const pageResults = this.searchAllInPage(ctx, page, keywordPtr, flags);
|
|
7260
|
+
const pageResults = this.searchAllInPage(doc, ctx, page, keywordPtr, flags);
|
|
7225
7261
|
results[page.index] = pageResults;
|
|
7226
7262
|
task.progress({
|
|
7227
7263
|
pageIndex: page.index,
|
|
@@ -7306,7 +7342,7 @@ class PdfiumNative {
|
|
|
7306
7342
|
*
|
|
7307
7343
|
* @private
|
|
7308
7344
|
*/
|
|
7309
|
-
searchAllInPage(ctx, page, keywordPtr, flag) {
|
|
7345
|
+
searchAllInPage(doc, ctx, page, keywordPtr, flag) {
|
|
7310
7346
|
return ctx.borrowPage(page.index, (pageCtx) => {
|
|
7311
7347
|
const textPagePtr = pageCtx.getTextPage();
|
|
7312
7348
|
const total = this.pdfiumModule.FPDFText_CountChars(textPagePtr);
|
|
@@ -7325,7 +7361,7 @@ class PdfiumNative {
|
|
|
7325
7361
|
while (this.pdfiumModule.FPDFText_FindNext(searchHandle)) {
|
|
7326
7362
|
const charIndex = this.pdfiumModule.FPDFText_GetSchResultIndex(searchHandle);
|
|
7327
7363
|
const charCount = this.pdfiumModule.FPDFText_GetSchCount(searchHandle);
|
|
7328
|
-
const rects = this.getHighlightRects(page, textPagePtr, charIndex, charCount);
|
|
7364
|
+
const rects = this.getHighlightRects(doc, page, textPagePtr, charIndex, charCount);
|
|
7329
7365
|
const context = this.buildContext(fullText, charIndex, charCount);
|
|
7330
7366
|
pageResults.push({
|
|
7331
7367
|
pageIndex: page.index,
|
|
@@ -7600,4 +7636,4 @@ export {
|
|
|
7600
7636
|
isValidCustomKey as i,
|
|
7601
7637
|
readString as r
|
|
7602
7638
|
};
|
|
7603
|
-
//# sourceMappingURL=direct-engine-
|
|
7639
|
+
//# sourceMappingURL=direct-engine-D8HGqcIt.js.map
|