@embedpdf/engines 2.4.1 → 2.6.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-qfUHZxQ6.js → browser-BISJ9naB.js} +3 -3
- package/dist/{browser-qfUHZxQ6.js.map → browser-BISJ9naB.js.map} +1 -1
- package/dist/{direct-engine-5RWKENek.js → direct-engine-CvfzIn2D.js} +648 -228
- package/dist/direct-engine-CvfzIn2D.js.map +1 -0
- package/dist/direct-engine-DITdlET4.cjs +2 -0
- package/dist/direct-engine-DITdlET4.cjs.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +10 -10
- package/dist/lib/converters/index.js +3 -3
- package/dist/lib/pdfium/cache.d.ts +9 -1
- package/dist/lib/pdfium/engine.d.ts +97 -4
- package/dist/lib/pdfium/index.cjs +1 -1
- package/dist/lib/pdfium/index.js +11 -11
- package/dist/lib/pdfium/web/direct-engine.cjs +1 -1
- package/dist/lib/pdfium/web/direct-engine.js +4 -4
- package/dist/lib/pdfium/web/worker-engine.cjs +1 -1
- package/dist/lib/pdfium/web/worker-engine.js +3 -3
- package/dist/lib/webworker/engine.js +1 -1
- package/dist/pdf-engine-BmrecQLq.cjs +2 -0
- package/dist/pdf-engine-BmrecQLq.cjs.map +1 -0
- package/dist/{pdf-engine-CVXuu1xQ.js → pdf-engine-aJNoNMbt.js} +3 -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-5RWKENek.js.map +0 -1
- package/dist/direct-engine-DnHo6z8a.cjs +0 -2
- package/dist/direct-engine-DnHo6z8a.cjs.map +0 -1
- package/dist/pdf-engine-B4lt8-5f.cjs +0 -2
- package/dist/pdf-engine-B4lt8-5f.cjs.map +0 -1
- package/dist/pdf-engine-CVXuu1xQ.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-BISJ9naB.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(
|
|
@@ -1557,49 +1567,100 @@ class PdfiumNative {
|
|
|
1557
1567
|
message: "can not set the rect of the annotation"
|
|
1558
1568
|
});
|
|
1559
1569
|
}
|
|
1570
|
+
const saveAnnotation = this.prepareAnnotationForSave(annotation);
|
|
1560
1571
|
let isSucceed = false;
|
|
1561
|
-
switch (
|
|
1572
|
+
switch (saveAnnotation.type) {
|
|
1562
1573
|
case PdfAnnotationSubtype.INK:
|
|
1563
|
-
isSucceed = this.addInkStroke(
|
|
1574
|
+
isSucceed = this.addInkStroke(
|
|
1575
|
+
doc,
|
|
1576
|
+
page,
|
|
1577
|
+
pageCtx.pagePtr,
|
|
1578
|
+
annotationPtr,
|
|
1579
|
+
saveAnnotation
|
|
1580
|
+
);
|
|
1564
1581
|
break;
|
|
1565
1582
|
case PdfAnnotationSubtype.STAMP:
|
|
1566
1583
|
isSucceed = this.addStampContent(
|
|
1584
|
+
doc,
|
|
1567
1585
|
ctx.docPtr,
|
|
1568
1586
|
page,
|
|
1569
1587
|
pageCtx.pagePtr,
|
|
1570
1588
|
annotationPtr,
|
|
1571
|
-
|
|
1589
|
+
saveAnnotation,
|
|
1572
1590
|
context == null ? void 0 : context.imageData
|
|
1573
1591
|
);
|
|
1574
1592
|
break;
|
|
1575
1593
|
case PdfAnnotationSubtype.TEXT:
|
|
1576
|
-
isSucceed = this.addTextContent(
|
|
1594
|
+
isSucceed = this.addTextContent(
|
|
1595
|
+
doc,
|
|
1596
|
+
page,
|
|
1597
|
+
pageCtx.pagePtr,
|
|
1598
|
+
annotationPtr,
|
|
1599
|
+
saveAnnotation
|
|
1600
|
+
);
|
|
1577
1601
|
break;
|
|
1578
1602
|
case PdfAnnotationSubtype.FREETEXT:
|
|
1579
|
-
isSucceed = this.addFreeTextContent(
|
|
1603
|
+
isSucceed = this.addFreeTextContent(
|
|
1604
|
+
doc,
|
|
1605
|
+
page,
|
|
1606
|
+
pageCtx.pagePtr,
|
|
1607
|
+
annotationPtr,
|
|
1608
|
+
saveAnnotation
|
|
1609
|
+
);
|
|
1580
1610
|
break;
|
|
1581
1611
|
case PdfAnnotationSubtype.LINE:
|
|
1582
|
-
isSucceed = this.addLineContent(
|
|
1612
|
+
isSucceed = this.addLineContent(
|
|
1613
|
+
doc,
|
|
1614
|
+
page,
|
|
1615
|
+
pageCtx.pagePtr,
|
|
1616
|
+
annotationPtr,
|
|
1617
|
+
saveAnnotation
|
|
1618
|
+
);
|
|
1583
1619
|
break;
|
|
1584
1620
|
case PdfAnnotationSubtype.POLYLINE:
|
|
1585
1621
|
case PdfAnnotationSubtype.POLYGON:
|
|
1586
|
-
isSucceed = this.addPolyContent(
|
|
1622
|
+
isSucceed = this.addPolyContent(
|
|
1623
|
+
doc,
|
|
1624
|
+
page,
|
|
1625
|
+
pageCtx.pagePtr,
|
|
1626
|
+
annotationPtr,
|
|
1627
|
+
saveAnnotation
|
|
1628
|
+
);
|
|
1587
1629
|
break;
|
|
1588
1630
|
case PdfAnnotationSubtype.CIRCLE:
|
|
1589
1631
|
case PdfAnnotationSubtype.SQUARE:
|
|
1590
|
-
isSucceed = this.addShapeContent(page, pageCtx.pagePtr, annotationPtr,
|
|
1632
|
+
isSucceed = this.addShapeContent(doc, page, pageCtx.pagePtr, annotationPtr, saveAnnotation);
|
|
1591
1633
|
break;
|
|
1592
1634
|
case PdfAnnotationSubtype.UNDERLINE:
|
|
1593
1635
|
case PdfAnnotationSubtype.STRIKEOUT:
|
|
1594
1636
|
case PdfAnnotationSubtype.SQUIGGLY:
|
|
1595
1637
|
case PdfAnnotationSubtype.HIGHLIGHT:
|
|
1596
|
-
isSucceed = this.addTextMarkupContent(
|
|
1638
|
+
isSucceed = this.addTextMarkupContent(
|
|
1639
|
+
doc,
|
|
1640
|
+
page,
|
|
1641
|
+
pageCtx.pagePtr,
|
|
1642
|
+
annotationPtr,
|
|
1643
|
+
saveAnnotation
|
|
1644
|
+
);
|
|
1597
1645
|
break;
|
|
1598
1646
|
case PdfAnnotationSubtype.LINK:
|
|
1599
|
-
isSucceed = this.addLinkContent(
|
|
1647
|
+
isSucceed = this.addLinkContent(
|
|
1648
|
+
doc,
|
|
1649
|
+
page,
|
|
1650
|
+
ctx.docPtr,
|
|
1651
|
+
pageCtx.pagePtr,
|
|
1652
|
+
annotationPtr,
|
|
1653
|
+
saveAnnotation
|
|
1654
|
+
);
|
|
1600
1655
|
break;
|
|
1601
1656
|
case PdfAnnotationSubtype.REDACT:
|
|
1602
|
-
isSucceed = this.addRedactContent(
|
|
1657
|
+
isSucceed = this.addRedactContent(
|
|
1658
|
+
doc,
|
|
1659
|
+
page,
|
|
1660
|
+
pageCtx.pagePtr,
|
|
1661
|
+
annotationPtr,
|
|
1662
|
+
saveAnnotation
|
|
1663
|
+
);
|
|
1603
1664
|
break;
|
|
1604
1665
|
}
|
|
1605
1666
|
if (!isSucceed) {
|
|
@@ -1679,7 +1740,7 @@ class PdfiumNative {
|
|
|
1679
1740
|
);
|
|
1680
1741
|
return PdfTaskHelper.reject({ code: PdfErrorCode.NotFound, message: "annotation not found" });
|
|
1681
1742
|
}
|
|
1682
|
-
if (!this.setPageAnnoRect(page, annotPtr, annotation.rect)) {
|
|
1743
|
+
if (!this.setPageAnnoRect(doc, page, annotPtr, annotation.rect)) {
|
|
1683
1744
|
this.pdfiumModule.FPDFPage_CloseAnnot(annotPtr);
|
|
1684
1745
|
pageCtx.release();
|
|
1685
1746
|
this.logger.perf(
|
|
@@ -1694,43 +1755,81 @@ class PdfiumNative {
|
|
|
1694
1755
|
message: "failed to move annotation"
|
|
1695
1756
|
});
|
|
1696
1757
|
}
|
|
1758
|
+
const saveAnnotation = this.prepareAnnotationForSave(annotation);
|
|
1697
1759
|
let ok = false;
|
|
1698
|
-
switch (
|
|
1760
|
+
switch (saveAnnotation.type) {
|
|
1699
1761
|
/* ── Ink ─────────────────────────────────────────────────────────────── */
|
|
1700
1762
|
case PdfAnnotationSubtype.INK: {
|
|
1701
1763
|
if (!this.pdfiumModule.FPDFAnnot_RemoveInkList(annotPtr)) break;
|
|
1702
|
-
ok = this.addInkStroke(
|
|
1764
|
+
ok = this.addInkStroke(
|
|
1765
|
+
doc,
|
|
1766
|
+
page,
|
|
1767
|
+
pageCtx.pagePtr,
|
|
1768
|
+
annotPtr,
|
|
1769
|
+
saveAnnotation
|
|
1770
|
+
);
|
|
1703
1771
|
break;
|
|
1704
1772
|
}
|
|
1705
1773
|
/* ── Stamp ───────────────────────────────────────────────────────────── */
|
|
1706
1774
|
case PdfAnnotationSubtype.STAMP: {
|
|
1707
|
-
ok = this.addStampContent(
|
|
1775
|
+
ok = this.addStampContent(
|
|
1776
|
+
doc,
|
|
1777
|
+
ctx.docPtr,
|
|
1778
|
+
page,
|
|
1779
|
+
pageCtx.pagePtr,
|
|
1780
|
+
annotPtr,
|
|
1781
|
+
saveAnnotation
|
|
1782
|
+
);
|
|
1708
1783
|
break;
|
|
1709
1784
|
}
|
|
1710
1785
|
case PdfAnnotationSubtype.TEXT: {
|
|
1711
|
-
ok = this.addTextContent(
|
|
1786
|
+
ok = this.addTextContent(
|
|
1787
|
+
doc,
|
|
1788
|
+
page,
|
|
1789
|
+
pageCtx.pagePtr,
|
|
1790
|
+
annotPtr,
|
|
1791
|
+
saveAnnotation
|
|
1792
|
+
);
|
|
1712
1793
|
break;
|
|
1713
1794
|
}
|
|
1714
1795
|
/* ── Free text ────────────────────────────────────────────────────────── */
|
|
1715
1796
|
case PdfAnnotationSubtype.FREETEXT: {
|
|
1716
|
-
ok = this.addFreeTextContent(
|
|
1797
|
+
ok = this.addFreeTextContent(
|
|
1798
|
+
doc,
|
|
1799
|
+
page,
|
|
1800
|
+
pageCtx.pagePtr,
|
|
1801
|
+
annotPtr,
|
|
1802
|
+
saveAnnotation
|
|
1803
|
+
);
|
|
1717
1804
|
break;
|
|
1718
1805
|
}
|
|
1719
1806
|
/* ── Shape ───────────────────────────────────────────────────────────── */
|
|
1720
1807
|
case PdfAnnotationSubtype.CIRCLE:
|
|
1721
1808
|
case PdfAnnotationSubtype.SQUARE: {
|
|
1722
|
-
ok = this.addShapeContent(page, pageCtx.pagePtr, annotPtr,
|
|
1809
|
+
ok = this.addShapeContent(doc, page, pageCtx.pagePtr, annotPtr, saveAnnotation);
|
|
1723
1810
|
break;
|
|
1724
1811
|
}
|
|
1725
1812
|
/* ── Line ─────────────────────────────────────────────────────────────── */
|
|
1726
1813
|
case PdfAnnotationSubtype.LINE: {
|
|
1727
|
-
ok = this.addLineContent(
|
|
1814
|
+
ok = this.addLineContent(
|
|
1815
|
+
doc,
|
|
1816
|
+
page,
|
|
1817
|
+
pageCtx.pagePtr,
|
|
1818
|
+
annotPtr,
|
|
1819
|
+
saveAnnotation
|
|
1820
|
+
);
|
|
1728
1821
|
break;
|
|
1729
1822
|
}
|
|
1730
1823
|
/* ── Polygon / Polyline ───────────────────────────────────────────────── */
|
|
1731
1824
|
case PdfAnnotationSubtype.POLYGON:
|
|
1732
1825
|
case PdfAnnotationSubtype.POLYLINE: {
|
|
1733
|
-
ok = this.addPolyContent(
|
|
1826
|
+
ok = this.addPolyContent(
|
|
1827
|
+
doc,
|
|
1828
|
+
page,
|
|
1829
|
+
pageCtx.pagePtr,
|
|
1830
|
+
annotPtr,
|
|
1831
|
+
saveAnnotation
|
|
1832
|
+
);
|
|
1734
1833
|
break;
|
|
1735
1834
|
}
|
|
1736
1835
|
/* ── Text-markup family ──────────────────────────────────────────────── */
|
|
@@ -1738,17 +1837,36 @@ class PdfiumNative {
|
|
|
1738
1837
|
case PdfAnnotationSubtype.UNDERLINE:
|
|
1739
1838
|
case PdfAnnotationSubtype.STRIKEOUT:
|
|
1740
1839
|
case PdfAnnotationSubtype.SQUIGGLY: {
|
|
1741
|
-
ok = this.addTextMarkupContent(
|
|
1840
|
+
ok = this.addTextMarkupContent(
|
|
1841
|
+
doc,
|
|
1842
|
+
page,
|
|
1843
|
+
pageCtx.pagePtr,
|
|
1844
|
+
annotPtr,
|
|
1845
|
+
saveAnnotation
|
|
1846
|
+
);
|
|
1742
1847
|
break;
|
|
1743
1848
|
}
|
|
1744
1849
|
/* ── Link ─────────────────────────────────────────────────────────────── */
|
|
1745
1850
|
case PdfAnnotationSubtype.LINK: {
|
|
1746
|
-
ok = this.addLinkContent(
|
|
1851
|
+
ok = this.addLinkContent(
|
|
1852
|
+
doc,
|
|
1853
|
+
page,
|
|
1854
|
+
ctx.docPtr,
|
|
1855
|
+
pageCtx.pagePtr,
|
|
1856
|
+
annotPtr,
|
|
1857
|
+
saveAnnotation
|
|
1858
|
+
);
|
|
1747
1859
|
break;
|
|
1748
1860
|
}
|
|
1749
1861
|
/* ── Redact ───────────────────────────────────────────────────────────── */
|
|
1750
1862
|
case PdfAnnotationSubtype.REDACT: {
|
|
1751
|
-
ok = this.addRedactContent(
|
|
1863
|
+
ok = this.addRedactContent(
|
|
1864
|
+
doc,
|
|
1865
|
+
page,
|
|
1866
|
+
pageCtx.pagePtr,
|
|
1867
|
+
annotPtr,
|
|
1868
|
+
saveAnnotation
|
|
1869
|
+
);
|
|
1752
1870
|
break;
|
|
1753
1871
|
}
|
|
1754
1872
|
/* ── Unsupported edits – fall through to error ───────────────────────── */
|
|
@@ -2732,7 +2850,7 @@ class PdfiumNative {
|
|
|
2732
2850
|
*
|
|
2733
2851
|
* @private
|
|
2734
2852
|
*/
|
|
2735
|
-
addTextContent(page, pagePtr, annotationPtr, annotation) {
|
|
2853
|
+
addTextContent(doc, page, pagePtr, annotationPtr, annotation) {
|
|
2736
2854
|
if (!this.setAnnotationIcon(annotationPtr, annotation.icon || PdfAnnotationIcon.Comment)) {
|
|
2737
2855
|
return false;
|
|
2738
2856
|
}
|
|
@@ -2747,7 +2865,7 @@ class PdfiumNative {
|
|
|
2747
2865
|
return false;
|
|
2748
2866
|
}
|
|
2749
2867
|
}
|
|
2750
|
-
return this.applyBaseAnnotationProperties(pagePtr, annotationPtr, annotation);
|
|
2868
|
+
return this.applyBaseAnnotationProperties(doc, page, pagePtr, annotationPtr, annotation);
|
|
2751
2869
|
}
|
|
2752
2870
|
/**
|
|
2753
2871
|
* Add free text content to annotation
|
|
@@ -2759,7 +2877,7 @@ class PdfiumNative {
|
|
|
2759
2877
|
*
|
|
2760
2878
|
* @private
|
|
2761
2879
|
*/
|
|
2762
|
-
addFreeTextContent(page, pagePtr, annotationPtr, annotation) {
|
|
2880
|
+
addFreeTextContent(doc, page, pagePtr, annotationPtr, annotation) {
|
|
2763
2881
|
if (!this.setBorderStyle(annotationPtr, PdfAnnotationBorderStyle.SOLID, 0)) {
|
|
2764
2882
|
return false;
|
|
2765
2883
|
}
|
|
@@ -2791,7 +2909,7 @@ class PdfiumNative {
|
|
|
2791
2909
|
} else if (!this.setAnnotationColor(annotationPtr, bgColor ?? "#FFFFFF", PdfAnnotationColorType.Color)) {
|
|
2792
2910
|
return false;
|
|
2793
2911
|
}
|
|
2794
|
-
return this.applyBaseAnnotationProperties(pagePtr, annotationPtr, annotation);
|
|
2912
|
+
return this.applyBaseAnnotationProperties(doc, page, pagePtr, annotationPtr, annotation);
|
|
2795
2913
|
}
|
|
2796
2914
|
/**
|
|
2797
2915
|
* Set the rect of specified annotation
|
|
@@ -2803,11 +2921,11 @@ class PdfiumNative {
|
|
|
2803
2921
|
*
|
|
2804
2922
|
* @private
|
|
2805
2923
|
*/
|
|
2806
|
-
addInkStroke(page, pagePtr, annotationPtr, annotation) {
|
|
2924
|
+
addInkStroke(doc, page, pagePtr, annotationPtr, annotation) {
|
|
2807
2925
|
if (!this.setBorderStyle(annotationPtr, PdfAnnotationBorderStyle.SOLID, annotation.strokeWidth)) {
|
|
2808
2926
|
return false;
|
|
2809
2927
|
}
|
|
2810
|
-
if (!this.setInkList(page, annotationPtr, annotation.inkList)) {
|
|
2928
|
+
if (!this.setInkList(doc, page, annotationPtr, annotation.inkList)) {
|
|
2811
2929
|
return false;
|
|
2812
2930
|
}
|
|
2813
2931
|
if (!this.setAnnotationOpacity(annotationPtr, annotation.opacity ?? 1)) {
|
|
@@ -2817,7 +2935,7 @@ class PdfiumNative {
|
|
|
2817
2935
|
if (!this.setAnnotationColor(annotationPtr, strokeColor, PdfAnnotationColorType.Color)) {
|
|
2818
2936
|
return false;
|
|
2819
2937
|
}
|
|
2820
|
-
return this.applyBaseAnnotationProperties(pagePtr, annotationPtr, annotation);
|
|
2938
|
+
return this.applyBaseAnnotationProperties(doc, page, pagePtr, annotationPtr, annotation);
|
|
2821
2939
|
}
|
|
2822
2940
|
/**
|
|
2823
2941
|
* Add line content to annotation
|
|
@@ -2829,9 +2947,10 @@ class PdfiumNative {
|
|
|
2829
2947
|
*
|
|
2830
2948
|
* @private
|
|
2831
2949
|
*/
|
|
2832
|
-
addLineContent(page, pagePtr, annotationPtr, annotation) {
|
|
2950
|
+
addLineContent(doc, page, pagePtr, annotationPtr, annotation) {
|
|
2833
2951
|
var _a, _b;
|
|
2834
2952
|
if (!this.setLinePoints(
|
|
2953
|
+
doc,
|
|
2835
2954
|
page,
|
|
2836
2955
|
annotationPtr,
|
|
2837
2956
|
annotation.linePoints.start,
|
|
@@ -2876,7 +2995,7 @@ class PdfiumNative {
|
|
|
2876
2995
|
)) {
|
|
2877
2996
|
return false;
|
|
2878
2997
|
}
|
|
2879
|
-
return this.applyBaseAnnotationProperties(pagePtr, annotationPtr, annotation);
|
|
2998
|
+
return this.applyBaseAnnotationProperties(doc, page, pagePtr, annotationPtr, annotation);
|
|
2880
2999
|
}
|
|
2881
3000
|
/**
|
|
2882
3001
|
* Add polygon or polyline content to annotation
|
|
@@ -2888,7 +3007,7 @@ class PdfiumNative {
|
|
|
2888
3007
|
*
|
|
2889
3008
|
* @private
|
|
2890
3009
|
*/
|
|
2891
|
-
addPolyContent(page, pagePtr, annotationPtr, annotation) {
|
|
3010
|
+
addPolyContent(doc, page, pagePtr, annotationPtr, annotation) {
|
|
2892
3011
|
var _a, _b;
|
|
2893
3012
|
if (annotation.type === PdfAnnotationSubtype.POLYLINE && !this.setLineEndings(
|
|
2894
3013
|
annotationPtr,
|
|
@@ -2897,7 +3016,7 @@ class PdfiumNative {
|
|
|
2897
3016
|
)) {
|
|
2898
3017
|
return false;
|
|
2899
3018
|
}
|
|
2900
|
-
if (!this.setPdfAnnoVertices(page, annotationPtr, annotation.vertices)) {
|
|
3019
|
+
if (!this.setPdfAnnoVertices(doc, page, annotationPtr, annotation.vertices)) {
|
|
2901
3020
|
return false;
|
|
2902
3021
|
}
|
|
2903
3022
|
if (!this.setBorderStyle(annotationPtr, annotation.strokeStyle, annotation.strokeWidth)) {
|
|
@@ -2930,7 +3049,7 @@ class PdfiumNative {
|
|
|
2930
3049
|
)) {
|
|
2931
3050
|
return false;
|
|
2932
3051
|
}
|
|
2933
|
-
return this.applyBaseAnnotationProperties(pagePtr, annotationPtr, annotation);
|
|
3052
|
+
return this.applyBaseAnnotationProperties(doc, page, pagePtr, annotationPtr, annotation);
|
|
2934
3053
|
}
|
|
2935
3054
|
/**
|
|
2936
3055
|
* Add link content (action or destination) to a link annotation
|
|
@@ -2942,7 +3061,7 @@ class PdfiumNative {
|
|
|
2942
3061
|
*
|
|
2943
3062
|
* @private
|
|
2944
3063
|
*/
|
|
2945
|
-
addLinkContent(docPtr, pagePtr, annotationPtr, annotation) {
|
|
3064
|
+
addLinkContent(doc, page, docPtr, pagePtr, annotationPtr, annotation) {
|
|
2946
3065
|
const style = annotation.strokeStyle ?? PdfAnnotationBorderStyle.UNDERLINE;
|
|
2947
3066
|
const width = annotation.strokeWidth ?? 2;
|
|
2948
3067
|
if (!this.setBorderStyle(annotationPtr, style, width)) {
|
|
@@ -2965,7 +3084,7 @@ class PdfiumNative {
|
|
|
2965
3084
|
return false;
|
|
2966
3085
|
}
|
|
2967
3086
|
}
|
|
2968
|
-
return this.applyBaseAnnotationProperties(pagePtr, annotationPtr, annotation);
|
|
3087
|
+
return this.applyBaseAnnotationProperties(doc, page, pagePtr, annotationPtr, annotation);
|
|
2969
3088
|
}
|
|
2970
3089
|
/**
|
|
2971
3090
|
* Add shape content to annotation
|
|
@@ -2977,7 +3096,7 @@ class PdfiumNative {
|
|
|
2977
3096
|
*
|
|
2978
3097
|
* @private
|
|
2979
3098
|
*/
|
|
2980
|
-
addShapeContent(page, pagePtr, annotationPtr, annotation) {
|
|
3099
|
+
addShapeContent(doc, page, pagePtr, annotationPtr, annotation) {
|
|
2981
3100
|
if (!this.setBorderStyle(annotationPtr, annotation.strokeStyle, annotation.strokeWidth)) {
|
|
2982
3101
|
return false;
|
|
2983
3102
|
}
|
|
@@ -3005,7 +3124,7 @@ class PdfiumNative {
|
|
|
3005
3124
|
)) {
|
|
3006
3125
|
return false;
|
|
3007
3126
|
}
|
|
3008
|
-
return this.applyBaseAnnotationProperties(pagePtr, annotationPtr, annotation);
|
|
3127
|
+
return this.applyBaseAnnotationProperties(doc, page, pagePtr, annotationPtr, annotation);
|
|
3009
3128
|
}
|
|
3010
3129
|
/**
|
|
3011
3130
|
* Add highlight content to annotation
|
|
@@ -3016,8 +3135,8 @@ class PdfiumNative {
|
|
|
3016
3135
|
*
|
|
3017
3136
|
* @private
|
|
3018
3137
|
*/
|
|
3019
|
-
addTextMarkupContent(page, pagePtr, annotationPtr, annotation) {
|
|
3020
|
-
if (!this.syncQuadPointsAnno(page, annotationPtr, annotation.segmentRects)) {
|
|
3138
|
+
addTextMarkupContent(doc, page, pagePtr, annotationPtr, annotation) {
|
|
3139
|
+
if (!this.syncQuadPointsAnno(doc, page, annotationPtr, annotation.segmentRects)) {
|
|
3021
3140
|
return false;
|
|
3022
3141
|
}
|
|
3023
3142
|
if (!this.setAnnotationOpacity(annotationPtr, annotation.opacity ?? 1)) {
|
|
@@ -3027,7 +3146,7 @@ class PdfiumNative {
|
|
|
3027
3146
|
if (!this.setAnnotationColor(annotationPtr, strokeColor, PdfAnnotationColorType.Color)) {
|
|
3028
3147
|
return false;
|
|
3029
3148
|
}
|
|
3030
|
-
return this.applyBaseAnnotationProperties(pagePtr, annotationPtr, annotation);
|
|
3149
|
+
return this.applyBaseAnnotationProperties(doc, page, pagePtr, annotationPtr, annotation);
|
|
3031
3150
|
}
|
|
3032
3151
|
/**
|
|
3033
3152
|
* Add content to redact annotation
|
|
@@ -3039,8 +3158,8 @@ class PdfiumNative {
|
|
|
3039
3158
|
*
|
|
3040
3159
|
* @private
|
|
3041
3160
|
*/
|
|
3042
|
-
addRedactContent(page, pagePtr, annotationPtr, annotation) {
|
|
3043
|
-
if (!this.syncQuadPointsAnno(page, annotationPtr, annotation.segmentRects)) {
|
|
3161
|
+
addRedactContent(doc, page, pagePtr, annotationPtr, annotation) {
|
|
3162
|
+
if (!this.syncQuadPointsAnno(doc, page, annotationPtr, annotation.segmentRects)) {
|
|
3044
3163
|
return false;
|
|
3045
3164
|
}
|
|
3046
3165
|
if (!this.setAnnotationOpacity(annotationPtr, annotation.opacity ?? 1)) {
|
|
@@ -3094,10 +3213,11 @@ class PdfiumNative {
|
|
|
3094
3213
|
if (annotation.textAlign !== void 0 && !this.setAnnotationTextAlignment(annotationPtr, annotation.textAlign)) {
|
|
3095
3214
|
return false;
|
|
3096
3215
|
}
|
|
3097
|
-
return this.applyBaseAnnotationProperties(pagePtr, annotationPtr, annotation);
|
|
3216
|
+
return this.applyBaseAnnotationProperties(doc, page, pagePtr, annotationPtr, annotation);
|
|
3098
3217
|
}
|
|
3099
3218
|
/**
|
|
3100
3219
|
* Add contents to stamp annotation
|
|
3220
|
+
* @param doc - pdf document object
|
|
3101
3221
|
* @param docPtr - pointer to pdf document object
|
|
3102
3222
|
* @param page - page info
|
|
3103
3223
|
* @param pagePtr - pointer to page object
|
|
@@ -3108,7 +3228,7 @@ class PdfiumNative {
|
|
|
3108
3228
|
*
|
|
3109
3229
|
* @private
|
|
3110
3230
|
*/
|
|
3111
|
-
addStampContent(docPtr, page, pagePtr, annotationPtr, annotation, imageData) {
|
|
3231
|
+
addStampContent(doc, docPtr, page, pagePtr, annotationPtr, annotation, imageData) {
|
|
3112
3232
|
if (annotation.icon && !this.setAnnotationIcon(annotationPtr, annotation.icon)) {
|
|
3113
3233
|
return false;
|
|
3114
3234
|
}
|
|
@@ -3119,17 +3239,18 @@ class PdfiumNative {
|
|
|
3119
3239
|
for (let i = this.pdfiumModule.FPDFAnnot_GetObjectCount(annotationPtr) - 1; i >= 0; i--) {
|
|
3120
3240
|
this.pdfiumModule.FPDFAnnot_RemoveObject(annotationPtr, i);
|
|
3121
3241
|
}
|
|
3122
|
-
if (!this.addImageObject(docPtr, page, pagePtr, annotationPtr, annotation.rect, imageData)) {
|
|
3242
|
+
if (!this.addImageObject(doc, docPtr, page, pagePtr, annotationPtr, annotation.rect, imageData)) {
|
|
3123
3243
|
return false;
|
|
3124
3244
|
}
|
|
3125
3245
|
}
|
|
3126
|
-
if (!this.
|
|
3246
|
+
if (!this.applyBaseAnnotationProperties(doc, page, pagePtr, annotationPtr, annotation)) {
|
|
3127
3247
|
return false;
|
|
3128
3248
|
}
|
|
3129
|
-
return this.
|
|
3249
|
+
return !!this.pdfiumModule.EPDFAnnot_UpdateAppearanceToRect(annotationPtr, PdfStampFit.Cover);
|
|
3130
3250
|
}
|
|
3131
3251
|
/**
|
|
3132
3252
|
* Add image object to annotation
|
|
3253
|
+
* @param doc - pdf document object
|
|
3133
3254
|
* @param docPtr - pointer to pdf document object
|
|
3134
3255
|
* @param page - page info
|
|
3135
3256
|
* @param pagePtr - pointer to page object
|
|
@@ -3140,7 +3261,7 @@ class PdfiumNative {
|
|
|
3140
3261
|
*
|
|
3141
3262
|
* @private
|
|
3142
3263
|
*/
|
|
3143
|
-
addImageObject(docPtr, page, pagePtr, annotationPtr, rect, imageData) {
|
|
3264
|
+
addImageObject(doc, docPtr, page, pagePtr, annotationPtr, rect, imageData) {
|
|
3144
3265
|
const bytesPerPixel = 4;
|
|
3145
3266
|
const pixelCount = imageData.width * imageData.height;
|
|
3146
3267
|
const bitmapBufferPtr = this.memoryManager.malloc(bytesPerPixel * pixelCount);
|
|
@@ -3196,7 +3317,7 @@ class PdfiumNative {
|
|
|
3196
3317
|
return false;
|
|
3197
3318
|
}
|
|
3198
3319
|
this.memoryManager.free(matrixPtr);
|
|
3199
|
-
const pagePos = this.convertDevicePointToPagePoint(page, {
|
|
3320
|
+
const pagePos = this.convertDevicePointToPagePoint(doc, page, {
|
|
3200
3321
|
x: rect.origin.x,
|
|
3201
3322
|
y: rect.origin.y + imageData.height
|
|
3202
3323
|
// shift down by the image height
|
|
@@ -3821,19 +3942,20 @@ class PdfiumNative {
|
|
|
3821
3942
|
/**
|
|
3822
3943
|
* Read page annotations
|
|
3823
3944
|
*
|
|
3945
|
+
* @param doc - pdf document object
|
|
3824
3946
|
* @param ctx - document context
|
|
3825
3947
|
* @param page - page info
|
|
3826
3948
|
* @returns annotations on the pdf page
|
|
3827
3949
|
*
|
|
3828
3950
|
* @private
|
|
3829
3951
|
*/
|
|
3830
|
-
readPageAnnotations(ctx, page) {
|
|
3952
|
+
readPageAnnotations(doc, ctx, page) {
|
|
3831
3953
|
return ctx.borrowPage(page.index, (pageCtx) => {
|
|
3832
3954
|
const annotationCount = this.pdfiumModule.FPDFPage_GetAnnotCount(pageCtx.pagePtr);
|
|
3833
3955
|
const annotations = [];
|
|
3834
3956
|
for (let i = 0; i < annotationCount; i++) {
|
|
3835
3957
|
pageCtx.withAnnotation(i, (annotPtr) => {
|
|
3836
|
-
const anno = this.readPageAnnotation(ctx.docPtr, page, annotPtr, pageCtx);
|
|
3958
|
+
const anno = this.readPageAnnotation(doc, ctx.docPtr, page, annotPtr, pageCtx);
|
|
3837
3959
|
if (anno) annotations.push(anno);
|
|
3838
3960
|
});
|
|
3839
3961
|
}
|
|
@@ -3843,13 +3965,14 @@ class PdfiumNative {
|
|
|
3843
3965
|
/**
|
|
3844
3966
|
* Read page annotations without loading the page (raw approach)
|
|
3845
3967
|
*
|
|
3968
|
+
* @param doc - pdf document object
|
|
3846
3969
|
* @param ctx - document context
|
|
3847
3970
|
* @param page - page info
|
|
3848
3971
|
* @returns annotations on the pdf page
|
|
3849
3972
|
*
|
|
3850
3973
|
* @private
|
|
3851
3974
|
*/
|
|
3852
|
-
readPageAnnotationsRaw(ctx, page) {
|
|
3975
|
+
readPageAnnotationsRaw(doc, ctx, page) {
|
|
3853
3976
|
const count = this.pdfiumModule.EPDFPage_GetAnnotCountRaw(ctx.docPtr, page.index);
|
|
3854
3977
|
if (count <= 0) return [];
|
|
3855
3978
|
const out = [];
|
|
@@ -3857,7 +3980,7 @@ class PdfiumNative {
|
|
|
3857
3980
|
const annotPtr = this.pdfiumModule.EPDFPage_GetAnnotRaw(ctx.docPtr, page.index, i);
|
|
3858
3981
|
if (!annotPtr) continue;
|
|
3859
3982
|
try {
|
|
3860
|
-
const anno = this.readPageAnnotation(ctx.docPtr, page, annotPtr);
|
|
3983
|
+
const anno = this.readPageAnnotation(doc, ctx.docPtr, page, annotPtr);
|
|
3861
3984
|
if (anno) out.push(anno);
|
|
3862
3985
|
} finally {
|
|
3863
3986
|
this.pdfiumModule.FPDFPage_CloseAnnot(annotPtr);
|
|
@@ -3890,7 +4013,7 @@ class PdfiumNative {
|
|
|
3890
4013
|
message: "document does not open"
|
|
3891
4014
|
});
|
|
3892
4015
|
}
|
|
3893
|
-
const out = this.readPageAnnotationsRaw(ctx, page);
|
|
4016
|
+
const out = this.readPageAnnotationsRaw(doc, ctx, page);
|
|
3894
4017
|
this.logger.perf(
|
|
3895
4018
|
LOG_SOURCE,
|
|
3896
4019
|
LOG_CATEGORY,
|
|
@@ -3910,6 +4033,7 @@ class PdfiumNative {
|
|
|
3910
4033
|
/**
|
|
3911
4034
|
* Read pdf annotation from pdf document
|
|
3912
4035
|
*
|
|
4036
|
+
* @param doc - pdf document object
|
|
3913
4037
|
* @param docPtr - pointer to pdf document
|
|
3914
4038
|
* @param page - page info
|
|
3915
4039
|
* @param annotationPtr - pointer to pdf annotation
|
|
@@ -3918,7 +4042,7 @@ class PdfiumNative {
|
|
|
3918
4042
|
*
|
|
3919
4043
|
* @private
|
|
3920
4044
|
*/
|
|
3921
|
-
readPageAnnotation(docPtr, page, annotationPtr, pageCtx) {
|
|
4045
|
+
readPageAnnotation(doc, docPtr, page, annotationPtr, pageCtx) {
|
|
3922
4046
|
let index = this.getAnnotString(annotationPtr, "NM");
|
|
3923
4047
|
if (!index || !isUuidV4(index)) {
|
|
3924
4048
|
index = uuidV4();
|
|
@@ -3931,99 +4055,153 @@ class PdfiumNative {
|
|
|
3931
4055
|
switch (subType) {
|
|
3932
4056
|
case PdfAnnotationSubtype.TEXT:
|
|
3933
4057
|
{
|
|
3934
|
-
annotation = this.readPdfTextAnno(page, annotationPtr, index);
|
|
4058
|
+
annotation = this.readPdfTextAnno(doc, page, annotationPtr, index);
|
|
3935
4059
|
}
|
|
3936
4060
|
break;
|
|
3937
4061
|
case PdfAnnotationSubtype.FREETEXT:
|
|
3938
4062
|
{
|
|
3939
|
-
annotation = this.readPdfFreeTextAnno(page, annotationPtr, index);
|
|
4063
|
+
annotation = this.readPdfFreeTextAnno(doc, page, annotationPtr, index);
|
|
3940
4064
|
}
|
|
3941
4065
|
break;
|
|
3942
4066
|
case PdfAnnotationSubtype.LINK:
|
|
3943
4067
|
{
|
|
3944
|
-
annotation = this.readPdfLinkAnno(page, docPtr, annotationPtr, index);
|
|
4068
|
+
annotation = this.readPdfLinkAnno(doc, page, docPtr, annotationPtr, index);
|
|
3945
4069
|
}
|
|
3946
4070
|
break;
|
|
3947
4071
|
case PdfAnnotationSubtype.WIDGET:
|
|
3948
4072
|
if (pageCtx) {
|
|
3949
|
-
return this.readPdfWidgetAnno(page, annotationPtr, pageCtx.getFormHandle(), index);
|
|
4073
|
+
return this.readPdfWidgetAnno(doc, page, annotationPtr, pageCtx.getFormHandle(), index);
|
|
3950
4074
|
}
|
|
3951
4075
|
case PdfAnnotationSubtype.FILEATTACHMENT:
|
|
3952
4076
|
{
|
|
3953
|
-
annotation = this.readPdfFileAttachmentAnno(page, annotationPtr, index);
|
|
4077
|
+
annotation = this.readPdfFileAttachmentAnno(doc, page, annotationPtr, index);
|
|
3954
4078
|
}
|
|
3955
4079
|
break;
|
|
3956
4080
|
case PdfAnnotationSubtype.INK:
|
|
3957
4081
|
{
|
|
3958
|
-
annotation = this.readPdfInkAnno(page, annotationPtr, index);
|
|
4082
|
+
annotation = this.readPdfInkAnno(doc, page, annotationPtr, index);
|
|
3959
4083
|
}
|
|
3960
4084
|
break;
|
|
3961
4085
|
case PdfAnnotationSubtype.POLYGON:
|
|
3962
4086
|
{
|
|
3963
|
-
annotation = this.readPdfPolygonAnno(page, annotationPtr, index);
|
|
4087
|
+
annotation = this.readPdfPolygonAnno(doc, page, annotationPtr, index);
|
|
3964
4088
|
}
|
|
3965
4089
|
break;
|
|
3966
4090
|
case PdfAnnotationSubtype.POLYLINE:
|
|
3967
4091
|
{
|
|
3968
|
-
annotation = this.readPdfPolylineAnno(page, annotationPtr, index);
|
|
4092
|
+
annotation = this.readPdfPolylineAnno(doc, page, annotationPtr, index);
|
|
3969
4093
|
}
|
|
3970
4094
|
break;
|
|
3971
4095
|
case PdfAnnotationSubtype.LINE:
|
|
3972
4096
|
{
|
|
3973
|
-
annotation = this.readPdfLineAnno(page, annotationPtr, index);
|
|
4097
|
+
annotation = this.readPdfLineAnno(doc, page, annotationPtr, index);
|
|
3974
4098
|
}
|
|
3975
4099
|
break;
|
|
3976
4100
|
case PdfAnnotationSubtype.HIGHLIGHT:
|
|
3977
|
-
annotation = this.readPdfHighlightAnno(page, annotationPtr, index);
|
|
4101
|
+
annotation = this.readPdfHighlightAnno(doc, page, annotationPtr, index);
|
|
3978
4102
|
break;
|
|
3979
4103
|
case PdfAnnotationSubtype.STAMP:
|
|
3980
4104
|
{
|
|
3981
|
-
annotation = this.readPdfStampAnno(page, annotationPtr, index);
|
|
4105
|
+
annotation = this.readPdfStampAnno(doc, page, annotationPtr, index);
|
|
3982
4106
|
}
|
|
3983
4107
|
break;
|
|
3984
4108
|
case PdfAnnotationSubtype.SQUARE:
|
|
3985
4109
|
{
|
|
3986
|
-
annotation = this.readPdfSquareAnno(page, annotationPtr, index);
|
|
4110
|
+
annotation = this.readPdfSquareAnno(doc, page, annotationPtr, index);
|
|
3987
4111
|
}
|
|
3988
4112
|
break;
|
|
3989
4113
|
case PdfAnnotationSubtype.CIRCLE:
|
|
3990
4114
|
{
|
|
3991
|
-
annotation = this.readPdfCircleAnno(page, annotationPtr, index);
|
|
4115
|
+
annotation = this.readPdfCircleAnno(doc, page, annotationPtr, index);
|
|
3992
4116
|
}
|
|
3993
4117
|
break;
|
|
3994
4118
|
case PdfAnnotationSubtype.UNDERLINE:
|
|
3995
4119
|
{
|
|
3996
|
-
annotation = this.readPdfUnderlineAnno(page, annotationPtr, index);
|
|
4120
|
+
annotation = this.readPdfUnderlineAnno(doc, page, annotationPtr, index);
|
|
3997
4121
|
}
|
|
3998
4122
|
break;
|
|
3999
4123
|
case PdfAnnotationSubtype.SQUIGGLY:
|
|
4000
4124
|
{
|
|
4001
|
-
annotation = this.readPdfSquigglyAnno(page, annotationPtr, index);
|
|
4125
|
+
annotation = this.readPdfSquigglyAnno(doc, page, annotationPtr, index);
|
|
4002
4126
|
}
|
|
4003
4127
|
break;
|
|
4004
4128
|
case PdfAnnotationSubtype.STRIKEOUT:
|
|
4005
4129
|
{
|
|
4006
|
-
annotation = this.readPdfStrikeOutAnno(page, annotationPtr, index);
|
|
4130
|
+
annotation = this.readPdfStrikeOutAnno(doc, page, annotationPtr, index);
|
|
4007
4131
|
}
|
|
4008
4132
|
break;
|
|
4009
4133
|
case PdfAnnotationSubtype.CARET:
|
|
4010
4134
|
{
|
|
4011
|
-
annotation = this.readPdfCaretAnno(page, annotationPtr, index);
|
|
4135
|
+
annotation = this.readPdfCaretAnno(doc, page, annotationPtr, index);
|
|
4012
4136
|
}
|
|
4013
4137
|
break;
|
|
4014
4138
|
case PdfAnnotationSubtype.REDACT:
|
|
4015
4139
|
{
|
|
4016
|
-
annotation = this.readPdfRedactAnno(page, annotationPtr, index);
|
|
4140
|
+
annotation = this.readPdfRedactAnno(doc, page, annotationPtr, index);
|
|
4017
4141
|
}
|
|
4018
4142
|
break;
|
|
4019
4143
|
default:
|
|
4020
4144
|
{
|
|
4021
|
-
annotation = this.readPdfAnno(page, subType, annotationPtr, index);
|
|
4145
|
+
annotation = this.readPdfAnno(doc, page, subType, annotationPtr, index);
|
|
4022
4146
|
}
|
|
4023
4147
|
break;
|
|
4024
4148
|
}
|
|
4149
|
+
if (annotation) {
|
|
4150
|
+
annotation = this.reverseRotateAnnotationOnLoad(annotation);
|
|
4151
|
+
}
|
|
4025
4152
|
return annotation;
|
|
4026
4153
|
}
|
|
4154
|
+
/**
|
|
4155
|
+
* On load, if a vertex-type annotation has rotation metadata in EPDFCustom,
|
|
4156
|
+
* reverse-rotate the PDF's physically rotated vertices by -rotation to recover
|
|
4157
|
+
* the unrotated vertices for runtime editing.
|
|
4158
|
+
*/
|
|
4159
|
+
reverseRotateAnnotationOnLoad(annotation) {
|
|
4160
|
+
const rotation = annotation.rotation;
|
|
4161
|
+
const unrotatedRect = annotation.unrotatedRect;
|
|
4162
|
+
if (!rotation || rotation === 0 || !unrotatedRect) {
|
|
4163
|
+
return annotation;
|
|
4164
|
+
}
|
|
4165
|
+
const center = {
|
|
4166
|
+
x: unrotatedRect.origin.x + unrotatedRect.size.width / 2,
|
|
4167
|
+
y: unrotatedRect.origin.y + unrotatedRect.size.height / 2
|
|
4168
|
+
};
|
|
4169
|
+
switch (annotation.type) {
|
|
4170
|
+
case PdfAnnotationSubtype.INK: {
|
|
4171
|
+
const ink = annotation;
|
|
4172
|
+
const unrotatedInkList = ink.inkList.map((stroke) => ({
|
|
4173
|
+
points: stroke.points.map((p) => this.rotatePointForSave(p, center, -rotation))
|
|
4174
|
+
}));
|
|
4175
|
+
return { ...ink, inkList: unrotatedInkList };
|
|
4176
|
+
}
|
|
4177
|
+
case PdfAnnotationSubtype.LINE: {
|
|
4178
|
+
const line = annotation;
|
|
4179
|
+
return {
|
|
4180
|
+
...line,
|
|
4181
|
+
linePoints: {
|
|
4182
|
+
start: this.rotatePointForSave(line.linePoints.start, center, -rotation),
|
|
4183
|
+
end: this.rotatePointForSave(line.linePoints.end, center, -rotation)
|
|
4184
|
+
}
|
|
4185
|
+
};
|
|
4186
|
+
}
|
|
4187
|
+
case PdfAnnotationSubtype.POLYGON: {
|
|
4188
|
+
const poly = annotation;
|
|
4189
|
+
return {
|
|
4190
|
+
...poly,
|
|
4191
|
+
vertices: poly.vertices.map((v) => this.rotatePointForSave(v, center, -rotation))
|
|
4192
|
+
};
|
|
4193
|
+
}
|
|
4194
|
+
case PdfAnnotationSubtype.POLYLINE: {
|
|
4195
|
+
const polyline = annotation;
|
|
4196
|
+
return {
|
|
4197
|
+
...polyline,
|
|
4198
|
+
vertices: polyline.vertices.map((v) => this.rotatePointForSave(v, center, -rotation))
|
|
4199
|
+
};
|
|
4200
|
+
}
|
|
4201
|
+
default:
|
|
4202
|
+
return annotation;
|
|
4203
|
+
}
|
|
4204
|
+
}
|
|
4027
4205
|
/**
|
|
4028
4206
|
* Return the colour stored directly in the annotation dictionary's `/C` entry.
|
|
4029
4207
|
*
|
|
@@ -4116,6 +4294,125 @@ class PdfiumNative {
|
|
|
4116
4294
|
const pdfOpacity = webOpacityToPdfAlpha(opacity);
|
|
4117
4295
|
return this.pdfiumModule.EPDFAnnot_SetOpacity(annotationPtr, pdfOpacity & 255);
|
|
4118
4296
|
}
|
|
4297
|
+
/**
|
|
4298
|
+
* Get the rotation angle (in degrees) from the annotation's /Rotate entry.
|
|
4299
|
+
* Returns 0 if no rotation is set or on error.
|
|
4300
|
+
*
|
|
4301
|
+
* @param annotationPtr - pointer to the annotation
|
|
4302
|
+
* @returns rotation in degrees (0 if not set)
|
|
4303
|
+
*/
|
|
4304
|
+
getAnnotationRotation(annotationPtr) {
|
|
4305
|
+
const rotationPtr = this.memoryManager.malloc(4);
|
|
4306
|
+
const ok = this.pdfiumModule.EPDFAnnot_GetRotate(annotationPtr, rotationPtr);
|
|
4307
|
+
if (!ok) {
|
|
4308
|
+
this.memoryManager.free(rotationPtr);
|
|
4309
|
+
return 0;
|
|
4310
|
+
}
|
|
4311
|
+
const rotation = this.pdfiumModule.pdfium.getValue(rotationPtr, "float");
|
|
4312
|
+
this.memoryManager.free(rotationPtr);
|
|
4313
|
+
return rotation;
|
|
4314
|
+
}
|
|
4315
|
+
/**
|
|
4316
|
+
* Set the rotation angle (in degrees) on the annotation's /Rotate entry.
|
|
4317
|
+
* A value of 0 removes the /Rotate key.
|
|
4318
|
+
*
|
|
4319
|
+
* @param annotationPtr - pointer to the annotation
|
|
4320
|
+
* @param rotation - rotation in degrees (clockwise)
|
|
4321
|
+
* @returns true on success
|
|
4322
|
+
*/
|
|
4323
|
+
setAnnotationRotation(annotationPtr, rotation) {
|
|
4324
|
+
return !!this.pdfiumModule.EPDFAnnot_SetRotate(annotationPtr, rotation);
|
|
4325
|
+
}
|
|
4326
|
+
/**
|
|
4327
|
+
* Get the EmbedPDF extended rotation (in degrees) from the annotation's
|
|
4328
|
+
* /EPDFRotate entry. Returns 0 if not set or on error.
|
|
4329
|
+
*
|
|
4330
|
+
* @param annotationPtr - pointer to the annotation
|
|
4331
|
+
* @returns rotation in degrees (0 if not set)
|
|
4332
|
+
*/
|
|
4333
|
+
getAnnotExtendedRotation(annotationPtr) {
|
|
4334
|
+
const rotationPtr = this.memoryManager.malloc(4);
|
|
4335
|
+
const ok = this.pdfiumModule.EPDFAnnot_GetExtendedRotation(annotationPtr, rotationPtr);
|
|
4336
|
+
if (!ok) {
|
|
4337
|
+
this.memoryManager.free(rotationPtr);
|
|
4338
|
+
return 0;
|
|
4339
|
+
}
|
|
4340
|
+
const rotation = this.pdfiumModule.pdfium.getValue(rotationPtr, "float");
|
|
4341
|
+
this.memoryManager.free(rotationPtr);
|
|
4342
|
+
return rotation;
|
|
4343
|
+
}
|
|
4344
|
+
/**
|
|
4345
|
+
* Set the EmbedPDF extended rotation (in degrees) on the annotation's
|
|
4346
|
+
* /EPDFRotate entry. A value of 0 removes the key.
|
|
4347
|
+
*
|
|
4348
|
+
* @param annotationPtr - pointer to the annotation
|
|
4349
|
+
* @param rotation - rotation in degrees
|
|
4350
|
+
* @returns true on success
|
|
4351
|
+
*/
|
|
4352
|
+
setAnnotExtendedRotation(annotationPtr, rotation) {
|
|
4353
|
+
return !!this.pdfiumModule.EPDFAnnot_SetExtendedRotation(annotationPtr, rotation);
|
|
4354
|
+
}
|
|
4355
|
+
/**
|
|
4356
|
+
* Read the EmbedPDF unrotated rect from the annotation's /EPDFUnrotatedRect
|
|
4357
|
+
* entry. Returns the raw page-space rect (same format as `readPageAnnoRect`)
|
|
4358
|
+
* or null if not set.
|
|
4359
|
+
*
|
|
4360
|
+
* @param annotationPtr - pointer to the annotation
|
|
4361
|
+
* @returns raw `{ left, top, right, bottom }` in page coords, or null
|
|
4362
|
+
*/
|
|
4363
|
+
readAnnotUnrotatedRect(annotationPtr) {
|
|
4364
|
+
const rectPtr = this.memoryManager.malloc(4 * 4);
|
|
4365
|
+
const ok = this.pdfiumModule.EPDFAnnot_GetUnrotatedRect(annotationPtr, rectPtr);
|
|
4366
|
+
if (!ok) {
|
|
4367
|
+
this.memoryManager.free(rectPtr);
|
|
4368
|
+
return null;
|
|
4369
|
+
}
|
|
4370
|
+
const left = this.pdfiumModule.pdfium.getValue(rectPtr, "float");
|
|
4371
|
+
const top = this.pdfiumModule.pdfium.getValue(rectPtr + 4, "float");
|
|
4372
|
+
const right = this.pdfiumModule.pdfium.getValue(rectPtr + 8, "float");
|
|
4373
|
+
const bottom = this.pdfiumModule.pdfium.getValue(rectPtr + 12, "float");
|
|
4374
|
+
this.memoryManager.free(rectPtr);
|
|
4375
|
+
if (left === 0 && top === 0 && right === 0 && bottom === 0) {
|
|
4376
|
+
return null;
|
|
4377
|
+
}
|
|
4378
|
+
return { left, top, right, bottom };
|
|
4379
|
+
}
|
|
4380
|
+
/**
|
|
4381
|
+
* Write the EmbedPDF unrotated rect (/EPDFUnrotatedRect) for an annotation.
|
|
4382
|
+
* Accepts a device-space `Rect` and converts to page coordinates internally,
|
|
4383
|
+
* following the same pattern as `setPageAnnoRect`.
|
|
4384
|
+
*
|
|
4385
|
+
* @param doc - pdf document object
|
|
4386
|
+
* @param page - pdf page object
|
|
4387
|
+
* @param annotPtr - pointer to the annotation
|
|
4388
|
+
* @param rect - device-space rect to store as the unrotated rect
|
|
4389
|
+
* @returns true on success
|
|
4390
|
+
*/
|
|
4391
|
+
setAnnotUnrotatedRect(doc, page, annotPtr, rect) {
|
|
4392
|
+
const x0d = Math.floor(rect.origin.x);
|
|
4393
|
+
const y0d = Math.floor(rect.origin.y);
|
|
4394
|
+
const x1d = Math.floor(rect.origin.x + rect.size.width);
|
|
4395
|
+
const y1d = Math.floor(rect.origin.y + rect.size.height);
|
|
4396
|
+
const TL = this.convertDevicePointToPagePoint(doc, page, { x: x0d, y: y0d });
|
|
4397
|
+
const TR = this.convertDevicePointToPagePoint(doc, page, { x: x1d, y: y0d });
|
|
4398
|
+
const BR = this.convertDevicePointToPagePoint(doc, page, { x: x1d, y: y1d });
|
|
4399
|
+
const BL = this.convertDevicePointToPagePoint(doc, page, { x: x0d, y: y1d });
|
|
4400
|
+
let left = Math.min(TL.x, TR.x, BR.x, BL.x);
|
|
4401
|
+
let right = Math.max(TL.x, TR.x, BR.x, BL.x);
|
|
4402
|
+
let bottom = Math.min(TL.y, TR.y, BR.y, BL.y);
|
|
4403
|
+
let top = Math.max(TL.y, TR.y, BR.y, BL.y);
|
|
4404
|
+
if (left > right) [left, right] = [right, left];
|
|
4405
|
+
if (bottom > top) [bottom, top] = [top, bottom];
|
|
4406
|
+
const ptr = this.memoryManager.malloc(16);
|
|
4407
|
+
const pdf = this.pdfiumModule.pdfium;
|
|
4408
|
+
pdf.setValue(ptr + 0, left, "float");
|
|
4409
|
+
pdf.setValue(ptr + 4, top, "float");
|
|
4410
|
+
pdf.setValue(ptr + 8, right, "float");
|
|
4411
|
+
pdf.setValue(ptr + 12, bottom, "float");
|
|
4412
|
+
const ok = this.pdfiumModule.EPDFAnnot_SetUnrotatedRect(annotPtr, ptr);
|
|
4413
|
+
this.memoryManager.free(ptr);
|
|
4414
|
+
return !!ok;
|
|
4415
|
+
}
|
|
4119
4416
|
/**
|
|
4120
4417
|
* Fetch the `/Q` text-alignment value from a **FreeText** annotation.
|
|
4121
4418
|
*
|
|
@@ -4265,10 +4562,11 @@ class PdfiumNative {
|
|
|
4265
4562
|
* @returns `true` on success
|
|
4266
4563
|
*/
|
|
4267
4564
|
setAnnotationDefaultAppearance(annotationPtr, font, fontSize, color) {
|
|
4565
|
+
const resolvedFont = font === PdfStandardFont.Unknown ? PdfStandardFont.Helvetica : font;
|
|
4268
4566
|
const { red, green, blue } = webColorToPdfColor(color);
|
|
4269
4567
|
return !!this.pdfiumModule.EPDFAnnot_SetDefaultAppearance(
|
|
4270
4568
|
annotationPtr,
|
|
4271
|
-
|
|
4569
|
+
resolvedFont,
|
|
4272
4570
|
fontSize,
|
|
4273
4571
|
red & 255,
|
|
4274
4572
|
green & 255,
|
|
@@ -4539,11 +4837,12 @@ class PdfiumNative {
|
|
|
4539
4837
|
}
|
|
4540
4838
|
/**
|
|
4541
4839
|
* Get the start and end points of a LINE / POLYLINE annot.
|
|
4840
|
+
* @param doc - pdf document object
|
|
4542
4841
|
* @param annotationPtr - pointer to an `FPDF_ANNOTATION`
|
|
4543
4842
|
* @param page - logical page info object (`PdfPageObject`)
|
|
4544
4843
|
* @returns `{ start, end }` or `undefined` when PDFium can't read them
|
|
4545
4844
|
*/
|
|
4546
|
-
getLinePoints(page, annotationPtr) {
|
|
4845
|
+
getLinePoints(doc, page, annotationPtr) {
|
|
4547
4846
|
const startPtr = this.memoryManager.malloc(8);
|
|
4548
4847
|
const endPtr = this.memoryManager.malloc(8);
|
|
4549
4848
|
const ok = this.pdfiumModule.FPDFAnnot_GetLine(annotationPtr, startPtr, endPtr);
|
|
@@ -4559,22 +4858,23 @@ class PdfiumNative {
|
|
|
4559
4858
|
const ey = pdf.getValue(endPtr + 4, "float");
|
|
4560
4859
|
this.memoryManager.free(startPtr);
|
|
4561
4860
|
this.memoryManager.free(endPtr);
|
|
4562
|
-
const start = this.convertPagePointToDevicePoint(page, { x: sx, y: sy });
|
|
4563
|
-
const end = this.convertPagePointToDevicePoint(page, { x: ex, y: ey });
|
|
4861
|
+
const start = this.convertPagePointToDevicePoint(doc, page, { x: sx, y: sy });
|
|
4862
|
+
const end = this.convertPagePointToDevicePoint(doc, page, { x: ex, y: ey });
|
|
4564
4863
|
return { start, end };
|
|
4565
4864
|
}
|
|
4566
4865
|
/**
|
|
4567
4866
|
* Set the two end‑points of a **Line** annotation
|
|
4568
4867
|
* by writing a new /L array `[ x1 y1 x2 y2 ]`.
|
|
4868
|
+
* @param doc - pdf document object
|
|
4569
4869
|
* @param page - logical page info object (`PdfPageObject`)
|
|
4570
4870
|
* @param annotPtr - pointer to the annotation whose line points are needed
|
|
4571
4871
|
* @param start - start point
|
|
4572
4872
|
* @param end - end point
|
|
4573
4873
|
* @returns true on success
|
|
4574
4874
|
*/
|
|
4575
|
-
setLinePoints(page, annotPtr, start, end) {
|
|
4576
|
-
const p1 = this.convertDevicePointToPagePoint(page, start);
|
|
4577
|
-
const p2 = this.convertDevicePointToPagePoint(page, end);
|
|
4875
|
+
setLinePoints(doc, page, annotPtr, start, end) {
|
|
4876
|
+
const p1 = this.convertDevicePointToPagePoint(doc, page, start);
|
|
4877
|
+
const p2 = this.convertDevicePointToPagePoint(doc, page, end);
|
|
4578
4878
|
if (!p1 || !p2) return false;
|
|
4579
4879
|
const buf = this.memoryManager.malloc(16);
|
|
4580
4880
|
const pdf = this.pdfiumModule.pdfium;
|
|
@@ -4595,13 +4895,14 @@ class PdfiumNative {
|
|
|
4595
4895
|
* This preserves the true shape for rotated / skewed text, whereas callers
|
|
4596
4896
|
* that only need axis-aligned boxes can collapse each quad themselves.
|
|
4597
4897
|
*
|
|
4898
|
+
* @param doc - pdf document object
|
|
4598
4899
|
* @param page - logical page info object (`PdfPageObject`)
|
|
4599
4900
|
* @param annotationPtr - pointer to the annotation whose quads are needed
|
|
4600
4901
|
* @returns Array of `Rect` objects (`[]` if the annotation has no quads)
|
|
4601
4902
|
*
|
|
4602
4903
|
* @private
|
|
4603
4904
|
*/
|
|
4604
|
-
getQuadPointsAnno(page, annotationPtr) {
|
|
4905
|
+
getQuadPointsAnno(doc, page, annotationPtr) {
|
|
4605
4906
|
const quadCount = this.pdfiumModule.FPDFAnnot_CountAttachmentPoints(annotationPtr);
|
|
4606
4907
|
if (quadCount === 0) return [];
|
|
4607
4908
|
const FS_QUADPOINTSF_SIZE = 8 * 4;
|
|
@@ -4617,10 +4918,10 @@ class PdfiumNative {
|
|
|
4617
4918
|
xs.push(this.pdfiumModule.pdfium.getValue(base, "float"));
|
|
4618
4919
|
ys.push(this.pdfiumModule.pdfium.getValue(base + 4, "float"));
|
|
4619
4920
|
}
|
|
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] });
|
|
4921
|
+
const p1 = this.convertPagePointToDevicePoint(doc, page, { x: xs[0], y: ys[0] });
|
|
4922
|
+
const p2 = this.convertPagePointToDevicePoint(doc, page, { x: xs[1], y: ys[1] });
|
|
4923
|
+
const p3 = this.convertPagePointToDevicePoint(doc, page, { x: xs[2], y: ys[2] });
|
|
4924
|
+
const p4 = this.convertPagePointToDevicePoint(doc, page, { x: xs[3], y: ys[3] });
|
|
4624
4925
|
quads.push({ p1, p2, p3, p4 });
|
|
4625
4926
|
}
|
|
4626
4927
|
this.memoryManager.free(quadPtr);
|
|
@@ -4630,6 +4931,7 @@ class PdfiumNative {
|
|
|
4630
4931
|
/**
|
|
4631
4932
|
* Set the quadrilaterals for a **Highlight / Underline / StrikeOut / Squiggly** markup annotation.
|
|
4632
4933
|
*
|
|
4934
|
+
* @param doc - pdf document object
|
|
4633
4935
|
* @param page - logical page info object (`PdfPageObject`)
|
|
4634
4936
|
* @param annotationPtr - pointer to the annotation whose quads are needed
|
|
4635
4937
|
* @param rects - array of `Rect` objects (`[]` if the annotation has no quads)
|
|
@@ -4637,17 +4939,17 @@ class PdfiumNative {
|
|
|
4637
4939
|
*
|
|
4638
4940
|
* @private
|
|
4639
4941
|
*/
|
|
4640
|
-
syncQuadPointsAnno(page, annotPtr, rects) {
|
|
4942
|
+
syncQuadPointsAnno(doc, page, annotPtr, rects) {
|
|
4641
4943
|
const FS_QUADPOINTSF_SIZE = 8 * 4;
|
|
4642
4944
|
const pdf = this.pdfiumModule.pdfium;
|
|
4643
4945
|
const count = this.pdfiumModule.FPDFAnnot_CountAttachmentPoints(annotPtr);
|
|
4644
4946
|
const buf = this.memoryManager.malloc(FS_QUADPOINTSF_SIZE);
|
|
4645
4947
|
const writeQuad = (r) => {
|
|
4646
4948
|
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);
|
|
4949
|
+
const p1 = this.convertDevicePointToPagePoint(doc, page, q.p1);
|
|
4950
|
+
const p2 = this.convertDevicePointToPagePoint(doc, page, q.p2);
|
|
4951
|
+
const p3 = this.convertDevicePointToPagePoint(doc, page, q.p3);
|
|
4952
|
+
const p4 = this.convertDevicePointToPagePoint(doc, page, q.p4);
|
|
4651
4953
|
pdf.setValue(buf + 0, p1.x, "float");
|
|
4652
4954
|
pdf.setValue(buf + 4, p1.y, "float");
|
|
4653
4955
|
pdf.setValue(buf + 8, p2.x, "float");
|
|
@@ -4710,7 +5012,7 @@ class PdfiumNative {
|
|
|
4710
5012
|
return PdfTaskHelper.resolve(false);
|
|
4711
5013
|
}
|
|
4712
5014
|
const pageCtx = ctx.acquirePage(page.index);
|
|
4713
|
-
const { ptr, count } = this.allocFSQuadsBufferFromRects(page, clean);
|
|
5015
|
+
const { ptr, count } = this.allocFSQuadsBufferFromRects(doc, page, clean);
|
|
4714
5016
|
let ok = false;
|
|
4715
5017
|
try {
|
|
4716
5018
|
ok = !!this.pdfiumModule.EPDFText_RedactInQuads(
|
|
@@ -4718,7 +5020,7 @@ class PdfiumNative {
|
|
|
4718
5020
|
ptr,
|
|
4719
5021
|
count,
|
|
4720
5022
|
recurseForms ? true : false,
|
|
4721
|
-
|
|
5023
|
+
false
|
|
4722
5024
|
);
|
|
4723
5025
|
} finally {
|
|
4724
5026
|
this.memoryManager.free(ptr);
|
|
@@ -4857,7 +5159,7 @@ class PdfiumNative {
|
|
|
4857
5159
|
return PdfTaskHelper.resolve(!!ok);
|
|
4858
5160
|
}
|
|
4859
5161
|
/** Pack device-space Rects into an FS_QUADPOINTSF[] buffer (page space). */
|
|
4860
|
-
allocFSQuadsBufferFromRects(page, rects) {
|
|
5162
|
+
allocFSQuadsBufferFromRects(doc, page, rects) {
|
|
4861
5163
|
const STRIDE = 32;
|
|
4862
5164
|
const count = rects.length;
|
|
4863
5165
|
const ptr = this.memoryManager.malloc(STRIDE * count);
|
|
@@ -4865,10 +5167,10 @@ class PdfiumNative {
|
|
|
4865
5167
|
for (let i = 0; i < count; i++) {
|
|
4866
5168
|
const r = rects[i];
|
|
4867
5169
|
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);
|
|
5170
|
+
const p1 = this.convertDevicePointToPagePoint(doc, page, q.p1);
|
|
5171
|
+
const p2 = this.convertDevicePointToPagePoint(doc, page, q.p2);
|
|
5172
|
+
const p3 = this.convertDevicePointToPagePoint(doc, page, q.p3);
|
|
5173
|
+
const p4 = this.convertDevicePointToPagePoint(doc, page, q.p4);
|
|
4872
5174
|
const base = ptr + i * STRIDE;
|
|
4873
5175
|
pdf.setValue(base + 0, p1.x, "float");
|
|
4874
5176
|
pdf.setValue(base + 4, p1.y, "float");
|
|
@@ -4883,12 +5185,13 @@ class PdfiumNative {
|
|
|
4883
5185
|
}
|
|
4884
5186
|
/**
|
|
4885
5187
|
* Read ink list from annotation
|
|
5188
|
+
* @param doc - pdf document object
|
|
4886
5189
|
* @param page - logical page info object (`PdfPageObject`)
|
|
4887
5190
|
* @param pagePtr - pointer to the page
|
|
4888
5191
|
* @param annotationPtr - pointer to the annotation whose ink list is needed
|
|
4889
5192
|
* @returns ink list
|
|
4890
5193
|
*/
|
|
4891
|
-
getInkList(page, annotationPtr) {
|
|
5194
|
+
getInkList(doc, page, annotationPtr) {
|
|
4892
5195
|
const inkList = [];
|
|
4893
5196
|
const pathCount = this.pdfiumModule.FPDFAnnot_GetInkListCount(annotationPtr);
|
|
4894
5197
|
if (pathCount <= 0) return inkList;
|
|
@@ -4904,7 +5207,7 @@ class PdfiumNative {
|
|
|
4904
5207
|
const base = buf + j * POINT_STRIDE;
|
|
4905
5208
|
const px = pdf.getValue(base + 0, "float");
|
|
4906
5209
|
const py = pdf.getValue(base + 4, "float");
|
|
4907
|
-
const d = this.convertPagePointToDevicePoint(page, { x: px, y: py });
|
|
5210
|
+
const d = this.convertPagePointToDevicePoint(doc, page, { x: px, y: py });
|
|
4908
5211
|
points.push({ x: d.x, y: d.y });
|
|
4909
5212
|
}
|
|
4910
5213
|
this.memoryManager.free(buf);
|
|
@@ -4915,13 +5218,14 @@ class PdfiumNative {
|
|
|
4915
5218
|
}
|
|
4916
5219
|
/**
|
|
4917
5220
|
* Add ink list to annotation
|
|
5221
|
+
* @param doc - pdf document object
|
|
4918
5222
|
* @param page - logical page info object (`PdfPageObject`)
|
|
4919
5223
|
* @param pagePtr - pointer to the page
|
|
4920
5224
|
* @param annotationPtr - pointer to the annotation whose ink list is needed
|
|
4921
5225
|
* @param inkList - ink list array of `PdfInkListObject`
|
|
4922
5226
|
* @returns `true` if the operation was successful
|
|
4923
5227
|
*/
|
|
4924
|
-
setInkList(page, annotationPtr, inkList) {
|
|
5228
|
+
setInkList(doc, page, annotationPtr, inkList) {
|
|
4925
5229
|
const pdf = this.pdfiumModule.pdfium;
|
|
4926
5230
|
const POINT_STRIDE = 8;
|
|
4927
5231
|
for (const stroke of inkList) {
|
|
@@ -4930,7 +5234,7 @@ class PdfiumNative {
|
|
|
4930
5234
|
const buf = this.memoryManager.malloc(n * POINT_STRIDE);
|
|
4931
5235
|
for (let i = 0; i < n; i++) {
|
|
4932
5236
|
const pDev = stroke.points[i];
|
|
4933
|
-
const pPage = this.convertDevicePointToPagePoint(page, pDev);
|
|
5237
|
+
const pPage = this.convertDevicePointToPagePoint(doc, page, pDev);
|
|
4934
5238
|
pdf.setValue(buf + i * POINT_STRIDE + 0, pPage.x, "float");
|
|
4935
5239
|
pdf.setValue(buf + i * POINT_STRIDE + 4, pPage.y, "float");
|
|
4936
5240
|
}
|
|
@@ -4951,9 +5255,9 @@ class PdfiumNative {
|
|
|
4951
5255
|
*
|
|
4952
5256
|
* @private
|
|
4953
5257
|
*/
|
|
4954
|
-
readPdfTextAnno(page, annotationPtr, index) {
|
|
5258
|
+
readPdfTextAnno(doc, page, annotationPtr, index) {
|
|
4955
5259
|
const annoRect = this.readPageAnnoRect(annotationPtr);
|
|
4956
|
-
const rect = this.convertPageRectToDeviceRect(page, annoRect);
|
|
5260
|
+
const rect = this.convertPageRectToDeviceRect(doc, page, annoRect);
|
|
4957
5261
|
const state = this.getAnnotString(annotationPtr, "State");
|
|
4958
5262
|
const stateModel = this.getAnnotString(annotationPtr, "StateModel");
|
|
4959
5263
|
const color = this.getAnnotationColor(annotationPtr);
|
|
@@ -4969,7 +5273,7 @@ class PdfiumNative {
|
|
|
4969
5273
|
state,
|
|
4970
5274
|
stateModel,
|
|
4971
5275
|
icon,
|
|
4972
|
-
...this.readBaseAnnotationProperties(annotationPtr)
|
|
5276
|
+
...this.readBaseAnnotationProperties(doc, page, annotationPtr)
|
|
4973
5277
|
};
|
|
4974
5278
|
}
|
|
4975
5279
|
/**
|
|
@@ -4981,9 +5285,9 @@ class PdfiumNative {
|
|
|
4981
5285
|
*
|
|
4982
5286
|
* @private
|
|
4983
5287
|
*/
|
|
4984
|
-
readPdfFreeTextAnno(page, annotationPtr, index) {
|
|
5288
|
+
readPdfFreeTextAnno(doc, page, annotationPtr, index) {
|
|
4985
5289
|
const annoRect = this.readPageAnnoRect(annotationPtr);
|
|
4986
|
-
const rect = this.convertPageRectToDeviceRect(page, annoRect);
|
|
5290
|
+
const rect = this.convertPageRectToDeviceRect(doc, page, annoRect);
|
|
4987
5291
|
const defaultStyle = this.getAnnotString(annotationPtr, "DS");
|
|
4988
5292
|
const da = this.getAnnotationDefaultAppearance(annotationPtr);
|
|
4989
5293
|
const bgColor = this.getAnnotationColor(annotationPtr);
|
|
@@ -5008,7 +5312,7 @@ class PdfiumNative {
|
|
|
5008
5312
|
textAlign,
|
|
5009
5313
|
defaultStyle,
|
|
5010
5314
|
richContent,
|
|
5011
|
-
...this.readBaseAnnotationProperties(annotationPtr)
|
|
5315
|
+
...this.readBaseAnnotationProperties(doc, page, annotationPtr)
|
|
5012
5316
|
};
|
|
5013
5317
|
}
|
|
5014
5318
|
/**
|
|
@@ -5021,13 +5325,13 @@ class PdfiumNative {
|
|
|
5021
5325
|
*
|
|
5022
5326
|
* @private
|
|
5023
5327
|
*/
|
|
5024
|
-
readPdfLinkAnno(page, docPtr, annotationPtr, index) {
|
|
5328
|
+
readPdfLinkAnno(doc, page, docPtr, annotationPtr, index) {
|
|
5025
5329
|
const linkPtr = this.pdfiumModule.FPDFAnnot_GetLink(annotationPtr);
|
|
5026
5330
|
if (!linkPtr) {
|
|
5027
5331
|
return;
|
|
5028
5332
|
}
|
|
5029
5333
|
const annoRect = this.readPageAnnoRect(annotationPtr);
|
|
5030
|
-
const rect = this.convertPageRectToDeviceRect(page, annoRect);
|
|
5334
|
+
const rect = this.convertPageRectToDeviceRect(doc, page, annoRect);
|
|
5031
5335
|
const { style: strokeStyle, width: strokeWidth } = this.getBorderStyle(annotationPtr);
|
|
5032
5336
|
const strokeColor = this.getAnnotationColor(annotationPtr, PdfAnnotationColorType.Color);
|
|
5033
5337
|
let strokeDashArray;
|
|
@@ -5056,7 +5360,7 @@ class PdfiumNative {
|
|
|
5056
5360
|
strokeWidth,
|
|
5057
5361
|
strokeStyle,
|
|
5058
5362
|
strokeDashArray,
|
|
5059
|
-
...this.readBaseAnnotationProperties(annotationPtr)
|
|
5363
|
+
...this.readBaseAnnotationProperties(doc, page, annotationPtr)
|
|
5060
5364
|
};
|
|
5061
5365
|
}
|
|
5062
5366
|
/**
|
|
@@ -5069,9 +5373,9 @@ class PdfiumNative {
|
|
|
5069
5373
|
*
|
|
5070
5374
|
* @private
|
|
5071
5375
|
*/
|
|
5072
|
-
readPdfWidgetAnno(page, annotationPtr, formHandle, index) {
|
|
5376
|
+
readPdfWidgetAnno(doc, page, annotationPtr, formHandle, index) {
|
|
5073
5377
|
const pageRect = this.readPageAnnoRect(annotationPtr);
|
|
5074
|
-
const rect = this.convertPageRectToDeviceRect(page, pageRect);
|
|
5378
|
+
const rect = this.convertPageRectToDeviceRect(doc, page, pageRect);
|
|
5075
5379
|
const field = this.readPdfWidgetAnnoField(formHandle, annotationPtr);
|
|
5076
5380
|
return {
|
|
5077
5381
|
pageIndex: page.index,
|
|
@@ -5079,7 +5383,7 @@ class PdfiumNative {
|
|
|
5079
5383
|
type: PdfAnnotationSubtype.WIDGET,
|
|
5080
5384
|
rect,
|
|
5081
5385
|
field,
|
|
5082
|
-
...this.readBaseAnnotationProperties(annotationPtr)
|
|
5386
|
+
...this.readBaseAnnotationProperties(doc, page, annotationPtr)
|
|
5083
5387
|
};
|
|
5084
5388
|
}
|
|
5085
5389
|
/**
|
|
@@ -5091,15 +5395,15 @@ class PdfiumNative {
|
|
|
5091
5395
|
*
|
|
5092
5396
|
* @private
|
|
5093
5397
|
*/
|
|
5094
|
-
readPdfFileAttachmentAnno(page, annotationPtr, index) {
|
|
5398
|
+
readPdfFileAttachmentAnno(doc, page, annotationPtr, index) {
|
|
5095
5399
|
const pageRect = this.readPageAnnoRect(annotationPtr);
|
|
5096
|
-
const rect = this.convertPageRectToDeviceRect(page, pageRect);
|
|
5400
|
+
const rect = this.convertPageRectToDeviceRect(doc, page, pageRect);
|
|
5097
5401
|
return {
|
|
5098
5402
|
pageIndex: page.index,
|
|
5099
5403
|
id: index,
|
|
5100
5404
|
type: PdfAnnotationSubtype.FILEATTACHMENT,
|
|
5101
5405
|
rect,
|
|
5102
|
-
...this.readBaseAnnotationProperties(annotationPtr)
|
|
5406
|
+
...this.readBaseAnnotationProperties(doc, page, annotationPtr)
|
|
5103
5407
|
};
|
|
5104
5408
|
}
|
|
5105
5409
|
/**
|
|
@@ -5111,13 +5415,13 @@ class PdfiumNative {
|
|
|
5111
5415
|
*
|
|
5112
5416
|
* @private
|
|
5113
5417
|
*/
|
|
5114
|
-
readPdfInkAnno(page, annotationPtr, index) {
|
|
5418
|
+
readPdfInkAnno(doc, page, annotationPtr, index) {
|
|
5115
5419
|
const pageRect = this.readPageAnnoRect(annotationPtr);
|
|
5116
|
-
const rect = this.convertPageRectToDeviceRect(page, pageRect);
|
|
5420
|
+
const rect = this.convertPageRectToDeviceRect(doc, page, pageRect);
|
|
5117
5421
|
const strokeColor = this.getAnnotationColor(annotationPtr) ?? "#FF0000";
|
|
5118
5422
|
const opacity = this.getAnnotationOpacity(annotationPtr);
|
|
5119
5423
|
const { width: strokeWidth } = this.getBorderStyle(annotationPtr);
|
|
5120
|
-
const inkList = this.getInkList(page, annotationPtr);
|
|
5424
|
+
const inkList = this.getInkList(doc, page, annotationPtr);
|
|
5121
5425
|
const blendMode = this.pdfiumModule.EPDFAnnot_GetBlendMode(annotationPtr);
|
|
5122
5426
|
const intent = this.getAnnotIntent(annotationPtr);
|
|
5123
5427
|
return {
|
|
@@ -5133,7 +5437,7 @@ class PdfiumNative {
|
|
|
5133
5437
|
opacity,
|
|
5134
5438
|
strokeWidth: strokeWidth === 0 ? 1 : strokeWidth,
|
|
5135
5439
|
inkList,
|
|
5136
|
-
...this.readBaseAnnotationProperties(annotationPtr)
|
|
5440
|
+
...this.readBaseAnnotationProperties(doc, page, annotationPtr)
|
|
5137
5441
|
};
|
|
5138
5442
|
}
|
|
5139
5443
|
/**
|
|
@@ -5145,10 +5449,10 @@ class PdfiumNative {
|
|
|
5145
5449
|
*
|
|
5146
5450
|
* @private
|
|
5147
5451
|
*/
|
|
5148
|
-
readPdfPolygonAnno(page, annotationPtr, index) {
|
|
5452
|
+
readPdfPolygonAnno(doc, page, annotationPtr, index) {
|
|
5149
5453
|
const pageRect = this.readPageAnnoRect(annotationPtr);
|
|
5150
|
-
const rect = this.convertPageRectToDeviceRect(page, pageRect);
|
|
5151
|
-
const vertices = this.readPdfAnnoVertices(page, annotationPtr);
|
|
5454
|
+
const rect = this.convertPageRectToDeviceRect(doc, page, pageRect);
|
|
5455
|
+
const vertices = this.readPdfAnnoVertices(doc, page, annotationPtr);
|
|
5152
5456
|
const strokeColor = this.getAnnotationColor(annotationPtr);
|
|
5153
5457
|
const interiorColor = this.getAnnotationColor(
|
|
5154
5458
|
annotationPtr,
|
|
@@ -5182,7 +5486,7 @@ class PdfiumNative {
|
|
|
5182
5486
|
strokeStyle,
|
|
5183
5487
|
strokeDashArray,
|
|
5184
5488
|
vertices,
|
|
5185
|
-
...this.readBaseAnnotationProperties(annotationPtr)
|
|
5489
|
+
...this.readBaseAnnotationProperties(doc, page, annotationPtr)
|
|
5186
5490
|
};
|
|
5187
5491
|
}
|
|
5188
5492
|
/**
|
|
@@ -5194,10 +5498,10 @@ class PdfiumNative {
|
|
|
5194
5498
|
*
|
|
5195
5499
|
* @private
|
|
5196
5500
|
*/
|
|
5197
|
-
readPdfPolylineAnno(page, annotationPtr, index) {
|
|
5501
|
+
readPdfPolylineAnno(doc, page, annotationPtr, index) {
|
|
5198
5502
|
const pageRect = this.readPageAnnoRect(annotationPtr);
|
|
5199
|
-
const rect = this.convertPageRectToDeviceRect(page, pageRect);
|
|
5200
|
-
const vertices = this.readPdfAnnoVertices(page, annotationPtr);
|
|
5503
|
+
const rect = this.convertPageRectToDeviceRect(doc, page, pageRect);
|
|
5504
|
+
const vertices = this.readPdfAnnoVertices(doc, page, annotationPtr);
|
|
5201
5505
|
const strokeColor = this.getAnnotationColor(annotationPtr);
|
|
5202
5506
|
const interiorColor = this.getAnnotationColor(
|
|
5203
5507
|
annotationPtr,
|
|
@@ -5226,7 +5530,7 @@ class PdfiumNative {
|
|
|
5226
5530
|
strokeDashArray,
|
|
5227
5531
|
lineEndings,
|
|
5228
5532
|
vertices,
|
|
5229
|
-
...this.readBaseAnnotationProperties(annotationPtr)
|
|
5533
|
+
...this.readBaseAnnotationProperties(doc, page, annotationPtr)
|
|
5230
5534
|
};
|
|
5231
5535
|
}
|
|
5232
5536
|
/**
|
|
@@ -5238,10 +5542,10 @@ class PdfiumNative {
|
|
|
5238
5542
|
*
|
|
5239
5543
|
* @private
|
|
5240
5544
|
*/
|
|
5241
|
-
readPdfLineAnno(page, annotationPtr, index) {
|
|
5545
|
+
readPdfLineAnno(doc, page, annotationPtr, index) {
|
|
5242
5546
|
const pageRect = this.readPageAnnoRect(annotationPtr);
|
|
5243
|
-
const rect = this.convertPageRectToDeviceRect(page, pageRect);
|
|
5244
|
-
const linePoints = this.getLinePoints(page, annotationPtr);
|
|
5547
|
+
const rect = this.convertPageRectToDeviceRect(doc, page, pageRect);
|
|
5548
|
+
const linePoints = this.getLinePoints(doc, page, annotationPtr);
|
|
5245
5549
|
const lineEndings = this.getLineEndings(annotationPtr);
|
|
5246
5550
|
const strokeColor = this.getAnnotationColor(annotationPtr);
|
|
5247
5551
|
const interiorColor = this.getAnnotationColor(
|
|
@@ -5273,7 +5577,7 @@ class PdfiumNative {
|
|
|
5273
5577
|
start: PdfAnnotationLineEnding.None,
|
|
5274
5578
|
end: PdfAnnotationLineEnding.None
|
|
5275
5579
|
},
|
|
5276
|
-
...this.readBaseAnnotationProperties(annotationPtr)
|
|
5580
|
+
...this.readBaseAnnotationProperties(doc, page, annotationPtr)
|
|
5277
5581
|
};
|
|
5278
5582
|
}
|
|
5279
5583
|
/**
|
|
@@ -5285,10 +5589,10 @@ class PdfiumNative {
|
|
|
5285
5589
|
*
|
|
5286
5590
|
* @private
|
|
5287
5591
|
*/
|
|
5288
|
-
readPdfHighlightAnno(page, annotationPtr, index) {
|
|
5592
|
+
readPdfHighlightAnno(doc, page, annotationPtr, index) {
|
|
5289
5593
|
const pageRect = this.readPageAnnoRect(annotationPtr);
|
|
5290
|
-
const rect = this.convertPageRectToDeviceRect(page, pageRect);
|
|
5291
|
-
const segmentRects = this.getQuadPointsAnno(page, annotationPtr);
|
|
5594
|
+
const rect = this.convertPageRectToDeviceRect(doc, page, pageRect);
|
|
5595
|
+
const segmentRects = this.getQuadPointsAnno(doc, page, annotationPtr);
|
|
5292
5596
|
const strokeColor = this.getAnnotationColor(annotationPtr) ?? "#FFFF00";
|
|
5293
5597
|
const opacity = this.getAnnotationOpacity(annotationPtr);
|
|
5294
5598
|
const blendMode = this.pdfiumModule.EPDFAnnot_GetBlendMode(annotationPtr);
|
|
@@ -5303,7 +5607,7 @@ class PdfiumNative {
|
|
|
5303
5607
|
color: strokeColor,
|
|
5304
5608
|
// deprecated alias
|
|
5305
5609
|
opacity,
|
|
5306
|
-
...this.readBaseAnnotationProperties(annotationPtr)
|
|
5610
|
+
...this.readBaseAnnotationProperties(doc, page, annotationPtr)
|
|
5307
5611
|
};
|
|
5308
5612
|
}
|
|
5309
5613
|
/**
|
|
@@ -5315,10 +5619,10 @@ class PdfiumNative {
|
|
|
5315
5619
|
*
|
|
5316
5620
|
* @private
|
|
5317
5621
|
*/
|
|
5318
|
-
readPdfUnderlineAnno(page, annotationPtr, index) {
|
|
5622
|
+
readPdfUnderlineAnno(doc, page, annotationPtr, index) {
|
|
5319
5623
|
const pageRect = this.readPageAnnoRect(annotationPtr);
|
|
5320
|
-
const rect = this.convertPageRectToDeviceRect(page, pageRect);
|
|
5321
|
-
const segmentRects = this.getQuadPointsAnno(page, annotationPtr);
|
|
5624
|
+
const rect = this.convertPageRectToDeviceRect(doc, page, pageRect);
|
|
5625
|
+
const segmentRects = this.getQuadPointsAnno(doc, page, annotationPtr);
|
|
5322
5626
|
const strokeColor = this.getAnnotationColor(annotationPtr) ?? "#FF0000";
|
|
5323
5627
|
const opacity = this.getAnnotationOpacity(annotationPtr);
|
|
5324
5628
|
const blendMode = this.pdfiumModule.EPDFAnnot_GetBlendMode(annotationPtr);
|
|
@@ -5333,7 +5637,7 @@ class PdfiumNative {
|
|
|
5333
5637
|
color: strokeColor,
|
|
5334
5638
|
// deprecated alias
|
|
5335
5639
|
opacity,
|
|
5336
|
-
...this.readBaseAnnotationProperties(annotationPtr)
|
|
5640
|
+
...this.readBaseAnnotationProperties(doc, page, annotationPtr)
|
|
5337
5641
|
};
|
|
5338
5642
|
}
|
|
5339
5643
|
/**
|
|
@@ -5345,10 +5649,10 @@ class PdfiumNative {
|
|
|
5345
5649
|
*
|
|
5346
5650
|
* @private
|
|
5347
5651
|
*/
|
|
5348
|
-
readPdfStrikeOutAnno(page, annotationPtr, index) {
|
|
5652
|
+
readPdfStrikeOutAnno(doc, page, annotationPtr, index) {
|
|
5349
5653
|
const pageRect = this.readPageAnnoRect(annotationPtr);
|
|
5350
|
-
const rect = this.convertPageRectToDeviceRect(page, pageRect);
|
|
5351
|
-
const segmentRects = this.getQuadPointsAnno(page, annotationPtr);
|
|
5654
|
+
const rect = this.convertPageRectToDeviceRect(doc, page, pageRect);
|
|
5655
|
+
const segmentRects = this.getQuadPointsAnno(doc, page, annotationPtr);
|
|
5352
5656
|
const strokeColor = this.getAnnotationColor(annotationPtr) ?? "#FF0000";
|
|
5353
5657
|
const opacity = this.getAnnotationOpacity(annotationPtr);
|
|
5354
5658
|
const blendMode = this.pdfiumModule.EPDFAnnot_GetBlendMode(annotationPtr);
|
|
@@ -5363,7 +5667,7 @@ class PdfiumNative {
|
|
|
5363
5667
|
color: strokeColor,
|
|
5364
5668
|
// deprecated alias
|
|
5365
5669
|
opacity,
|
|
5366
|
-
...this.readBaseAnnotationProperties(annotationPtr)
|
|
5670
|
+
...this.readBaseAnnotationProperties(doc, page, annotationPtr)
|
|
5367
5671
|
};
|
|
5368
5672
|
}
|
|
5369
5673
|
/**
|
|
@@ -5375,10 +5679,10 @@ class PdfiumNative {
|
|
|
5375
5679
|
*
|
|
5376
5680
|
* @private
|
|
5377
5681
|
*/
|
|
5378
|
-
readPdfSquigglyAnno(page, annotationPtr, index) {
|
|
5682
|
+
readPdfSquigglyAnno(doc, page, annotationPtr, index) {
|
|
5379
5683
|
const pageRect = this.readPageAnnoRect(annotationPtr);
|
|
5380
|
-
const rect = this.convertPageRectToDeviceRect(page, pageRect);
|
|
5381
|
-
const segmentRects = this.getQuadPointsAnno(page, annotationPtr);
|
|
5684
|
+
const rect = this.convertPageRectToDeviceRect(doc, page, pageRect);
|
|
5685
|
+
const segmentRects = this.getQuadPointsAnno(doc, page, annotationPtr);
|
|
5382
5686
|
const strokeColor = this.getAnnotationColor(annotationPtr) ?? "#FF0000";
|
|
5383
5687
|
const opacity = this.getAnnotationOpacity(annotationPtr);
|
|
5384
5688
|
const blendMode = this.pdfiumModule.EPDFAnnot_GetBlendMode(annotationPtr);
|
|
@@ -5393,7 +5697,7 @@ class PdfiumNative {
|
|
|
5393
5697
|
color: strokeColor,
|
|
5394
5698
|
// deprecated alias
|
|
5395
5699
|
opacity,
|
|
5396
|
-
...this.readBaseAnnotationProperties(annotationPtr)
|
|
5700
|
+
...this.readBaseAnnotationProperties(doc, page, annotationPtr)
|
|
5397
5701
|
};
|
|
5398
5702
|
}
|
|
5399
5703
|
/**
|
|
@@ -5405,15 +5709,15 @@ class PdfiumNative {
|
|
|
5405
5709
|
*
|
|
5406
5710
|
* @private
|
|
5407
5711
|
*/
|
|
5408
|
-
readPdfCaretAnno(page, annotationPtr, index) {
|
|
5712
|
+
readPdfCaretAnno(doc, page, annotationPtr, index) {
|
|
5409
5713
|
const pageRect = this.readPageAnnoRect(annotationPtr);
|
|
5410
|
-
const rect = this.convertPageRectToDeviceRect(page, pageRect);
|
|
5714
|
+
const rect = this.convertPageRectToDeviceRect(doc, page, pageRect);
|
|
5411
5715
|
return {
|
|
5412
5716
|
pageIndex: page.index,
|
|
5413
5717
|
id: index,
|
|
5414
5718
|
type: PdfAnnotationSubtype.CARET,
|
|
5415
5719
|
rect,
|
|
5416
|
-
...this.readBaseAnnotationProperties(annotationPtr)
|
|
5720
|
+
...this.readBaseAnnotationProperties(doc, page, annotationPtr)
|
|
5417
5721
|
};
|
|
5418
5722
|
}
|
|
5419
5723
|
/**
|
|
@@ -5425,10 +5729,10 @@ class PdfiumNative {
|
|
|
5425
5729
|
*
|
|
5426
5730
|
* @private
|
|
5427
5731
|
*/
|
|
5428
|
-
readPdfRedactAnno(page, annotationPtr, index) {
|
|
5732
|
+
readPdfRedactAnno(doc, page, annotationPtr, index) {
|
|
5429
5733
|
const pageRect = this.readPageAnnoRect(annotationPtr);
|
|
5430
|
-
const rect = this.convertPageRectToDeviceRect(page, pageRect);
|
|
5431
|
-
const segmentRects = this.getQuadPointsAnno(page, annotationPtr);
|
|
5734
|
+
const rect = this.convertPageRectToDeviceRect(doc, page, pageRect);
|
|
5735
|
+
const segmentRects = this.getQuadPointsAnno(doc, page, annotationPtr);
|
|
5432
5736
|
const color = this.getAnnotationColor(annotationPtr, PdfAnnotationColorType.InteriorColor);
|
|
5433
5737
|
const overlayColor = this.getAnnotationColor(
|
|
5434
5738
|
annotationPtr,
|
|
@@ -5456,7 +5760,7 @@ class PdfiumNative {
|
|
|
5456
5760
|
fontSize: da == null ? void 0 : da.fontSize,
|
|
5457
5761
|
fontColor: da == null ? void 0 : da.fontColor,
|
|
5458
5762
|
textAlign,
|
|
5459
|
-
...this.readBaseAnnotationProperties(annotationPtr)
|
|
5763
|
+
...this.readBaseAnnotationProperties(doc, page, annotationPtr)
|
|
5460
5764
|
};
|
|
5461
5765
|
}
|
|
5462
5766
|
/**
|
|
@@ -5468,15 +5772,15 @@ class PdfiumNative {
|
|
|
5468
5772
|
*
|
|
5469
5773
|
* @private
|
|
5470
5774
|
*/
|
|
5471
|
-
readPdfStampAnno(page, annotationPtr, index) {
|
|
5775
|
+
readPdfStampAnno(doc, page, annotationPtr, index) {
|
|
5472
5776
|
const pageRect = this.readPageAnnoRect(annotationPtr);
|
|
5473
|
-
const rect = this.convertPageRectToDeviceRect(page, pageRect);
|
|
5777
|
+
const rect = this.convertPageRectToDeviceRect(doc, page, pageRect);
|
|
5474
5778
|
return {
|
|
5475
5779
|
pageIndex: page.index,
|
|
5476
5780
|
id: index,
|
|
5477
5781
|
type: PdfAnnotationSubtype.STAMP,
|
|
5478
5782
|
rect,
|
|
5479
|
-
...this.readBaseAnnotationProperties(annotationPtr)
|
|
5783
|
+
...this.readBaseAnnotationProperties(doc, page, annotationPtr)
|
|
5480
5784
|
};
|
|
5481
5785
|
}
|
|
5482
5786
|
/**
|
|
@@ -5711,9 +6015,9 @@ class PdfiumNative {
|
|
|
5711
6015
|
*
|
|
5712
6016
|
* @private
|
|
5713
6017
|
*/
|
|
5714
|
-
readPdfCircleAnno(page, annotationPtr, index) {
|
|
6018
|
+
readPdfCircleAnno(doc, page, annotationPtr, index) {
|
|
5715
6019
|
const pageRect = this.readPageAnnoRect(annotationPtr);
|
|
5716
|
-
const rect = this.convertPageRectToDeviceRect(page, pageRect);
|
|
6020
|
+
const rect = this.convertPageRectToDeviceRect(doc, page, pageRect);
|
|
5717
6021
|
const interiorColor = this.getAnnotationColor(
|
|
5718
6022
|
annotationPtr,
|
|
5719
6023
|
PdfAnnotationColorType.InteriorColor
|
|
@@ -5739,7 +6043,7 @@ class PdfiumNative {
|
|
|
5739
6043
|
strokeColor: strokeColor ?? "#FF0000",
|
|
5740
6044
|
strokeStyle,
|
|
5741
6045
|
...strokeDashArray !== void 0 && { strokeDashArray },
|
|
5742
|
-
...this.readBaseAnnotationProperties(annotationPtr)
|
|
6046
|
+
...this.readBaseAnnotationProperties(doc, page, annotationPtr)
|
|
5743
6047
|
};
|
|
5744
6048
|
}
|
|
5745
6049
|
/**
|
|
@@ -5751,9 +6055,9 @@ class PdfiumNative {
|
|
|
5751
6055
|
*
|
|
5752
6056
|
* @private
|
|
5753
6057
|
*/
|
|
5754
|
-
readPdfSquareAnno(page, annotationPtr, index) {
|
|
6058
|
+
readPdfSquareAnno(doc, page, annotationPtr, index) {
|
|
5755
6059
|
const pageRect = this.readPageAnnoRect(annotationPtr);
|
|
5756
|
-
const rect = this.convertPageRectToDeviceRect(page, pageRect);
|
|
6060
|
+
const rect = this.convertPageRectToDeviceRect(doc, page, pageRect);
|
|
5757
6061
|
const interiorColor = this.getAnnotationColor(
|
|
5758
6062
|
annotationPtr,
|
|
5759
6063
|
PdfAnnotationColorType.InteriorColor
|
|
@@ -5779,7 +6083,7 @@ class PdfiumNative {
|
|
|
5779
6083
|
strokeWidth,
|
|
5780
6084
|
strokeStyle,
|
|
5781
6085
|
...strokeDashArray !== void 0 && { strokeDashArray },
|
|
5782
|
-
...this.readBaseAnnotationProperties(annotationPtr)
|
|
6086
|
+
...this.readBaseAnnotationProperties(doc, page, annotationPtr)
|
|
5783
6087
|
};
|
|
5784
6088
|
}
|
|
5785
6089
|
/**
|
|
@@ -5792,15 +6096,15 @@ class PdfiumNative {
|
|
|
5792
6096
|
*
|
|
5793
6097
|
* @private
|
|
5794
6098
|
*/
|
|
5795
|
-
readPdfAnno(page, type, annotationPtr, index) {
|
|
6099
|
+
readPdfAnno(doc, page, type, annotationPtr, index) {
|
|
5796
6100
|
const pageRect = this.readPageAnnoRect(annotationPtr);
|
|
5797
|
-
const rect = this.convertPageRectToDeviceRect(page, pageRect);
|
|
6101
|
+
const rect = this.convertPageRectToDeviceRect(doc, page, pageRect);
|
|
5798
6102
|
return {
|
|
5799
6103
|
pageIndex: page.index,
|
|
5800
6104
|
id: index,
|
|
5801
6105
|
type,
|
|
5802
6106
|
rect,
|
|
5803
|
-
...this.readBaseAnnotationProperties(annotationPtr)
|
|
6107
|
+
...this.readBaseAnnotationProperties(doc, page, annotationPtr)
|
|
5804
6108
|
};
|
|
5805
6109
|
}
|
|
5806
6110
|
/**
|
|
@@ -5832,6 +6136,73 @@ class PdfiumNative {
|
|
|
5832
6136
|
if (!parentPtr) return false;
|
|
5833
6137
|
return this.pdfiumModule.EPDFAnnot_SetLinkedAnnot(annotationPtr, "IRT", parentPtr);
|
|
5834
6138
|
}
|
|
6139
|
+
/**
|
|
6140
|
+
* Rotate a point around a center by the given angle in degrees.
|
|
6141
|
+
* Used to rotate vertices for PDF storage.
|
|
6142
|
+
*/
|
|
6143
|
+
rotatePointForSave(point, center, angleDegrees) {
|
|
6144
|
+
const rad = angleDegrees * Math.PI / 180;
|
|
6145
|
+
const cos = Math.cos(rad);
|
|
6146
|
+
const sin = Math.sin(rad);
|
|
6147
|
+
const dx = point.x - center.x;
|
|
6148
|
+
const dy = point.y - center.y;
|
|
6149
|
+
return {
|
|
6150
|
+
x: center.x + dx * cos - dy * sin,
|
|
6151
|
+
y: center.y + dx * sin + dy * cos
|
|
6152
|
+
};
|
|
6153
|
+
}
|
|
6154
|
+
/**
|
|
6155
|
+
* Prepare an annotation for saving to PDF.
|
|
6156
|
+
* For vertex types (ink, line, polygon, polyline) with rotation,
|
|
6157
|
+
* physically rotates the vertices by +rotation so that other PDF viewers
|
|
6158
|
+
* see the correct visual result. Our viewer reverse-rotates on load.
|
|
6159
|
+
*/
|
|
6160
|
+
prepareAnnotationForSave(annotation) {
|
|
6161
|
+
const rotation = annotation.rotation;
|
|
6162
|
+
const unrotatedRect = annotation.unrotatedRect;
|
|
6163
|
+
if (!rotation || rotation === 0 || !unrotatedRect) {
|
|
6164
|
+
return annotation;
|
|
6165
|
+
}
|
|
6166
|
+
const center = {
|
|
6167
|
+
x: unrotatedRect.origin.x + unrotatedRect.size.width / 2,
|
|
6168
|
+
y: unrotatedRect.origin.y + unrotatedRect.size.height / 2
|
|
6169
|
+
};
|
|
6170
|
+
switch (annotation.type) {
|
|
6171
|
+
case PdfAnnotationSubtype.INK: {
|
|
6172
|
+
const ink = annotation;
|
|
6173
|
+
const rotatedInkList = ink.inkList.map((stroke) => ({
|
|
6174
|
+
points: stroke.points.map((p) => this.rotatePointForSave(p, center, rotation))
|
|
6175
|
+
}));
|
|
6176
|
+
return { ...ink, inkList: rotatedInkList };
|
|
6177
|
+
}
|
|
6178
|
+
case PdfAnnotationSubtype.LINE: {
|
|
6179
|
+
const line = annotation;
|
|
6180
|
+
return {
|
|
6181
|
+
...line,
|
|
6182
|
+
linePoints: {
|
|
6183
|
+
start: this.rotatePointForSave(line.linePoints.start, center, rotation),
|
|
6184
|
+
end: this.rotatePointForSave(line.linePoints.end, center, rotation)
|
|
6185
|
+
}
|
|
6186
|
+
};
|
|
6187
|
+
}
|
|
6188
|
+
case PdfAnnotationSubtype.POLYGON: {
|
|
6189
|
+
const poly = annotation;
|
|
6190
|
+
return {
|
|
6191
|
+
...poly,
|
|
6192
|
+
vertices: poly.vertices.map((v) => this.rotatePointForSave(v, center, rotation))
|
|
6193
|
+
};
|
|
6194
|
+
}
|
|
6195
|
+
case PdfAnnotationSubtype.POLYLINE: {
|
|
6196
|
+
const polyline = annotation;
|
|
6197
|
+
return {
|
|
6198
|
+
...polyline,
|
|
6199
|
+
vertices: polyline.vertices.map((v) => this.rotatePointForSave(v, center, rotation))
|
|
6200
|
+
};
|
|
6201
|
+
}
|
|
6202
|
+
default:
|
|
6203
|
+
return annotation;
|
|
6204
|
+
}
|
|
6205
|
+
}
|
|
5835
6206
|
/**
|
|
5836
6207
|
* Apply all base annotation properties from PdfAnnotationObjectBase.
|
|
5837
6208
|
* The setInReplyToId and setReplyType functions handle clearing when undefined.
|
|
@@ -5841,7 +6212,7 @@ class PdfiumNative {
|
|
|
5841
6212
|
* @param annotation - the annotation object containing properties to apply
|
|
5842
6213
|
* @returns `true` on success
|
|
5843
6214
|
*/
|
|
5844
|
-
applyBaseAnnotationProperties(pagePtr, annotationPtr, annotation) {
|
|
6215
|
+
applyBaseAnnotationProperties(doc, page, pagePtr, annotationPtr, annotation) {
|
|
5845
6216
|
if (!this.setAnnotString(annotationPtr, "T", annotation.author || "")) {
|
|
5846
6217
|
return false;
|
|
5847
6218
|
}
|
|
@@ -5863,11 +6234,32 @@ class PdfiumNative {
|
|
|
5863
6234
|
return false;
|
|
5864
6235
|
}
|
|
5865
6236
|
}
|
|
5866
|
-
|
|
5867
|
-
|
|
6237
|
+
const existingCustom = this.getAnnotCustom(annotationPtr) ?? {};
|
|
6238
|
+
const customData = {
|
|
6239
|
+
...existingCustom,
|
|
6240
|
+
...annotation.custom ?? {}
|
|
6241
|
+
};
|
|
6242
|
+
delete customData.unrotatedRect;
|
|
6243
|
+
delete customData.rotation;
|
|
6244
|
+
const hasCustomData = Object.keys(customData).length > 0;
|
|
6245
|
+
if (hasCustomData) {
|
|
6246
|
+
if (!this.setAnnotCustom(annotationPtr, customData)) {
|
|
6247
|
+
return false;
|
|
6248
|
+
}
|
|
6249
|
+
} else if (Object.keys(existingCustom).length > 0) {
|
|
6250
|
+
if (!this.setAnnotCustom(annotationPtr, null)) {
|
|
5868
6251
|
return false;
|
|
5869
6252
|
}
|
|
5870
6253
|
}
|
|
6254
|
+
if (annotation.rotation !== void 0) {
|
|
6255
|
+
const pdfRotation = annotation.rotation ? (360 - annotation.rotation) % 360 : 0;
|
|
6256
|
+
this.setAnnotExtendedRotation(annotationPtr, pdfRotation);
|
|
6257
|
+
}
|
|
6258
|
+
if (annotation.unrotatedRect) {
|
|
6259
|
+
this.setAnnotUnrotatedRect(doc, page, annotationPtr, annotation.unrotatedRect);
|
|
6260
|
+
} else if (annotation.rotation && annotation.rotation !== 0) {
|
|
6261
|
+
this.setAnnotUnrotatedRect(doc, page, annotationPtr, annotation.rect);
|
|
6262
|
+
}
|
|
5871
6263
|
if (!this.setInReplyToId(pagePtr, annotationPtr, annotation.inReplyToId)) {
|
|
5872
6264
|
return false;
|
|
5873
6265
|
}
|
|
@@ -5880,10 +6272,12 @@ class PdfiumNative {
|
|
|
5880
6272
|
* Read all base annotation properties from PdfAnnotationObjectBase.
|
|
5881
6273
|
* Returns an object that can be spread into the annotation return value.
|
|
5882
6274
|
*
|
|
6275
|
+
* @param doc - pdf document object
|
|
6276
|
+
* @param page - pdf page object
|
|
5883
6277
|
* @param annotationPtr - pointer to annotation object
|
|
5884
6278
|
* @returns object with base annotation properties
|
|
5885
6279
|
*/
|
|
5886
|
-
readBaseAnnotationProperties(annotationPtr) {
|
|
6280
|
+
readBaseAnnotationProperties(doc, page, annotationPtr) {
|
|
5887
6281
|
const author = this.getAnnotString(annotationPtr, "T");
|
|
5888
6282
|
const contents = this.getAnnotString(annotationPtr, "Contents") || "";
|
|
5889
6283
|
const modified = this.getAnnotationDate(annotationPtr, "M");
|
|
@@ -5892,6 +6286,10 @@ class PdfiumNative {
|
|
|
5892
6286
|
const custom = this.getAnnotCustom(annotationPtr);
|
|
5893
6287
|
const inReplyToId = this.getInReplyToId(annotationPtr);
|
|
5894
6288
|
const replyType = this.getReplyType(annotationPtr);
|
|
6289
|
+
const pdfRotation = this.getAnnotExtendedRotation(annotationPtr);
|
|
6290
|
+
const rotation = pdfRotation !== 0 ? (360 - pdfRotation) % 360 : 0;
|
|
6291
|
+
const rawUnrotatedRect = this.readAnnotUnrotatedRect(annotationPtr);
|
|
6292
|
+
const unrotatedRect = rawUnrotatedRect ? this.convertPageRectToDeviceRect(doc, page, rawUnrotatedRect) : void 0;
|
|
5895
6293
|
return {
|
|
5896
6294
|
author,
|
|
5897
6295
|
contents,
|
|
@@ -5902,7 +6300,9 @@ class PdfiumNative {
|
|
|
5902
6300
|
// Only include IRT if present
|
|
5903
6301
|
...inReplyToId && { inReplyToId },
|
|
5904
6302
|
// Only include RT if present and not the default (Reply)
|
|
5905
|
-
...replyType && replyType !== PdfAnnotationReplyType.Reply && { replyType }
|
|
6303
|
+
...replyType && replyType !== PdfAnnotationReplyType.Reply && { replyType },
|
|
6304
|
+
...rotation !== 0 && { rotation },
|
|
6305
|
+
...unrotatedRect !== void 0 && { unrotatedRect }
|
|
5906
6306
|
};
|
|
5907
6307
|
}
|
|
5908
6308
|
/**
|
|
@@ -6095,13 +6495,14 @@ class PdfiumNative {
|
|
|
6095
6495
|
}
|
|
6096
6496
|
/**
|
|
6097
6497
|
* Read vertices of pdf annotation
|
|
6498
|
+
* @param doc - pdf document object
|
|
6098
6499
|
* @param page - pdf page infor
|
|
6099
6500
|
* @param annotationPtr - pointer to pdf annotation
|
|
6100
6501
|
* @returns vertices of pdf annotation
|
|
6101
6502
|
*
|
|
6102
6503
|
* @private
|
|
6103
6504
|
*/
|
|
6104
|
-
readPdfAnnoVertices(page, annotationPtr) {
|
|
6505
|
+
readPdfAnnoVertices(doc, page, annotationPtr) {
|
|
6105
6506
|
const vertices = [];
|
|
6106
6507
|
const count = this.pdfiumModule.FPDFAnnot_GetVertices(annotationPtr, 0, 0);
|
|
6107
6508
|
const pointMemorySize = 8;
|
|
@@ -6113,7 +6514,7 @@ class PdfiumNative {
|
|
|
6113
6514
|
pointsPtr + i * pointMemorySize + 4,
|
|
6114
6515
|
"float"
|
|
6115
6516
|
);
|
|
6116
|
-
const { x, y } = this.convertPagePointToDevicePoint(page, {
|
|
6517
|
+
const { x, y } = this.convertPagePointToDevicePoint(doc, page, {
|
|
6117
6518
|
x: pointX,
|
|
6118
6519
|
y: pointY
|
|
6119
6520
|
});
|
|
@@ -6128,6 +6529,7 @@ class PdfiumNative {
|
|
|
6128
6529
|
/**
|
|
6129
6530
|
* Sync the vertices of a polygon or polyline annotation.
|
|
6130
6531
|
*
|
|
6532
|
+
* @param doc - pdf document object
|
|
6131
6533
|
* @param page - pdf page infor
|
|
6132
6534
|
* @param annotPtr - pointer to pdf annotation
|
|
6133
6535
|
* @param vertices - the vertices to be set
|
|
@@ -6135,12 +6537,12 @@ class PdfiumNative {
|
|
|
6135
6537
|
*
|
|
6136
6538
|
* @private
|
|
6137
6539
|
*/
|
|
6138
|
-
setPdfAnnoVertices(page, annotPtr, vertices) {
|
|
6540
|
+
setPdfAnnoVertices(doc, page, annotPtr, vertices) {
|
|
6139
6541
|
const pdf = this.pdfiumModule.pdfium;
|
|
6140
6542
|
const FS_POINTF_SIZE = 8;
|
|
6141
6543
|
const buf = this.memoryManager.malloc(FS_POINTF_SIZE * vertices.length);
|
|
6142
6544
|
vertices.forEach((v, i) => {
|
|
6143
|
-
const pagePt = this.convertDevicePointToPagePoint(page, v);
|
|
6545
|
+
const pagePt = this.convertDevicePointToPagePoint(doc, page, v);
|
|
6144
6546
|
pdf.setValue(buf + i * FS_POINTF_SIZE + 0, pagePt.x, "float");
|
|
6145
6547
|
pdf.setValue(buf + i * FS_POINTF_SIZE + 4, pagePt.y, "float");
|
|
6146
6548
|
});
|
|
@@ -6328,7 +6730,9 @@ class PdfiumNative {
|
|
|
6328
6730
|
return PdfTaskHelper.reject({ code: PdfErrorCode.NotFound, message: "annotation not found" });
|
|
6329
6731
|
}
|
|
6330
6732
|
const finalScale = Math.max(0.01, scaleFactor * dpr);
|
|
6331
|
-
const
|
|
6733
|
+
const unrotated = !!(options == null ? void 0 : options.unrotated) && !!annotation.unrotatedRect;
|
|
6734
|
+
const renderRect = unrotated ? annotation.unrotatedRect : annotation.rect;
|
|
6735
|
+
const rect = toIntRect(renderRect);
|
|
6332
6736
|
const devRect = toIntRect(transformRect(page.size, rect, rotation, finalScale));
|
|
6333
6737
|
const wDev = Math.max(1, devRect.size.width);
|
|
6334
6738
|
const hDev = Math.max(1, devRect.size.height);
|
|
@@ -6356,14 +6760,25 @@ class PdfiumNative {
|
|
|
6356
6760
|
const FLAGS = 16;
|
|
6357
6761
|
let ok = false;
|
|
6358
6762
|
try {
|
|
6359
|
-
|
|
6360
|
-
|
|
6361
|
-
|
|
6362
|
-
|
|
6363
|
-
|
|
6364
|
-
|
|
6365
|
-
|
|
6366
|
-
|
|
6763
|
+
if (unrotated) {
|
|
6764
|
+
ok = !!this.pdfiumModule.EPDF_RenderAnnotBitmapUnrotated(
|
|
6765
|
+
bitmapPtr,
|
|
6766
|
+
pageCtx.pagePtr,
|
|
6767
|
+
annotPtr,
|
|
6768
|
+
mode,
|
|
6769
|
+
mPtr,
|
|
6770
|
+
FLAGS
|
|
6771
|
+
);
|
|
6772
|
+
} else {
|
|
6773
|
+
ok = !!this.pdfiumModule.EPDF_RenderAnnotBitmap(
|
|
6774
|
+
bitmapPtr,
|
|
6775
|
+
pageCtx.pagePtr,
|
|
6776
|
+
annotPtr,
|
|
6777
|
+
mode,
|
|
6778
|
+
mPtr,
|
|
6779
|
+
FLAGS
|
|
6780
|
+
);
|
|
6781
|
+
}
|
|
6367
6782
|
} finally {
|
|
6368
6783
|
this.memoryManager.free(mPtr);
|
|
6369
6784
|
this.pdfiumModule.FPDFBitmap_Destroy(bitmapPtr);
|
|
@@ -6894,16 +7309,17 @@ class PdfiumNative {
|
|
|
6894
7309
|
}
|
|
6895
7310
|
/**
|
|
6896
7311
|
* Convert coordinate of point from device coordinate to page coordinate
|
|
7312
|
+
* @param doc - pdf document object
|
|
6897
7313
|
* @param page - pdf page infor
|
|
6898
7314
|
* @param position - position of point
|
|
6899
7315
|
* @returns converted position
|
|
6900
7316
|
*
|
|
6901
7317
|
* @private
|
|
6902
7318
|
*/
|
|
6903
|
-
convertDevicePointToPagePoint(page, position) {
|
|
7319
|
+
convertDevicePointToPagePoint(doc, page, position) {
|
|
6904
7320
|
const DW = page.size.width;
|
|
6905
7321
|
const DH = page.size.height;
|
|
6906
|
-
const r = page.rotation & 3;
|
|
7322
|
+
const r = doc.normalizedRotation ? 0 : page.rotation & 3;
|
|
6907
7323
|
if (r === 0) {
|
|
6908
7324
|
return { x: position.x, y: DH - position.y };
|
|
6909
7325
|
}
|
|
@@ -6919,16 +7335,17 @@ class PdfiumNative {
|
|
|
6919
7335
|
}
|
|
6920
7336
|
/**
|
|
6921
7337
|
* Convert coordinate of point from page coordinate to device coordinate
|
|
7338
|
+
* @param doc - pdf document object
|
|
6922
7339
|
* @param page - pdf page infor
|
|
6923
7340
|
* @param position - position of point
|
|
6924
7341
|
* @returns converted position
|
|
6925
7342
|
*
|
|
6926
7343
|
* @private
|
|
6927
7344
|
*/
|
|
6928
|
-
convertPagePointToDevicePoint(page, position) {
|
|
7345
|
+
convertPagePointToDevicePoint(doc, page, position) {
|
|
6929
7346
|
const DW = page.size.width;
|
|
6930
7347
|
const DH = page.size.height;
|
|
6931
|
-
const r = page.rotation & 3;
|
|
7348
|
+
const r = doc.normalizedRotation ? 0 : page.rotation & 3;
|
|
6932
7349
|
if (r === 0) {
|
|
6933
7350
|
return { x: position.x, y: DH - position.y };
|
|
6934
7351
|
}
|
|
@@ -6944,6 +7361,7 @@ class PdfiumNative {
|
|
|
6944
7361
|
}
|
|
6945
7362
|
/**
|
|
6946
7363
|
* Convert coordinate of rectangle from page coordinate to device coordinate
|
|
7364
|
+
* @param doc - pdf document object
|
|
6947
7365
|
* @param page - pdf page infor
|
|
6948
7366
|
* @param pagePtr - pointer to pdf page object
|
|
6949
7367
|
* @param pageRect - rectangle that needs to be converted
|
|
@@ -6951,8 +7369,8 @@ class PdfiumNative {
|
|
|
6951
7369
|
*
|
|
6952
7370
|
* @private
|
|
6953
7371
|
*/
|
|
6954
|
-
convertPageRectToDeviceRect(page, pageRect) {
|
|
6955
|
-
const { x, y } = this.convertPagePointToDevicePoint(page, {
|
|
7372
|
+
convertPageRectToDeviceRect(doc, page, pageRect) {
|
|
7373
|
+
const { x, y } = this.convertPagePointToDevicePoint(doc, page, {
|
|
6956
7374
|
x: pageRect.left,
|
|
6957
7375
|
y: pageRect.top
|
|
6958
7376
|
});
|
|
@@ -7022,6 +7440,7 @@ class PdfiumNative {
|
|
|
7022
7440
|
}
|
|
7023
7441
|
/**
|
|
7024
7442
|
* Set the rect of specified annotation
|
|
7443
|
+
* @param doc - pdf document object
|
|
7025
7444
|
* @param page - page info that the annotation is belonged to
|
|
7026
7445
|
* @param annotationPtr - pointer to annotation object
|
|
7027
7446
|
* @param rect - target rectangle
|
|
@@ -7029,15 +7448,15 @@ class PdfiumNative {
|
|
|
7029
7448
|
*
|
|
7030
7449
|
* @private
|
|
7031
7450
|
*/
|
|
7032
|
-
setPageAnnoRect(page, annotPtr, rect) {
|
|
7451
|
+
setPageAnnoRect(doc, page, annotPtr, rect) {
|
|
7033
7452
|
const x0d = Math.floor(rect.origin.x);
|
|
7034
7453
|
const y0d = Math.floor(rect.origin.y);
|
|
7035
7454
|
const x1d = Math.floor(rect.origin.x + rect.size.width);
|
|
7036
7455
|
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 });
|
|
7456
|
+
const TL = this.convertDevicePointToPagePoint(doc, page, { x: x0d, y: y0d });
|
|
7457
|
+
const TR = this.convertDevicePointToPagePoint(doc, page, { x: x1d, y: y0d });
|
|
7458
|
+
const BR = this.convertDevicePointToPagePoint(doc, page, { x: x1d, y: y1d });
|
|
7459
|
+
const BL = this.convertDevicePointToPagePoint(doc, page, { x: x0d, y: y1d });
|
|
7041
7460
|
let left = Math.min(TL.x, TR.x, BR.x, BL.x);
|
|
7042
7461
|
let right = Math.max(TL.x, TR.x, BR.x, BL.x);
|
|
7043
7462
|
let bottom = Math.min(TL.y, TR.y, BR.y, BL.y);
|
|
@@ -7080,6 +7499,7 @@ class PdfiumNative {
|
|
|
7080
7499
|
}
|
|
7081
7500
|
/**
|
|
7082
7501
|
* Get highlight rects for a specific character range (for search highlighting)
|
|
7502
|
+
* @param doc - pdf document object
|
|
7083
7503
|
* @param page - pdf page info
|
|
7084
7504
|
* @param pagePtr - pointer to pdf page
|
|
7085
7505
|
* @param textPagePtr - pointer to pdf text page
|
|
@@ -7089,7 +7509,7 @@ class PdfiumNative {
|
|
|
7089
7509
|
*
|
|
7090
7510
|
* @private
|
|
7091
7511
|
*/
|
|
7092
|
-
getHighlightRects(page, textPagePtr, startIndex, charCount) {
|
|
7512
|
+
getHighlightRects(doc, page, textPagePtr, startIndex, charCount) {
|
|
7093
7513
|
const rectsCount = this.pdfiumModule.FPDFText_CountRects(textPagePtr, startIndex, charCount);
|
|
7094
7514
|
const highlightRects = [];
|
|
7095
7515
|
const l = this.memoryManager.malloc(8);
|
|
@@ -7103,10 +7523,10 @@ class PdfiumNative {
|
|
|
7103
7523
|
const top = this.pdfiumModule.pdfium.getValue(t, "double");
|
|
7104
7524
|
const right = this.pdfiumModule.pdfium.getValue(r, "double");
|
|
7105
7525
|
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 });
|
|
7526
|
+
const p1 = this.convertPagePointToDevicePoint(doc, page, { x: left, y: top });
|
|
7527
|
+
const p2 = this.convertPagePointToDevicePoint(doc, page, { x: right, y: top });
|
|
7528
|
+
const p3 = this.convertPagePointToDevicePoint(doc, page, { x: right, y: bottom });
|
|
7529
|
+
const p4 = this.convertPagePointToDevicePoint(doc, page, { x: left, y: bottom });
|
|
7110
7530
|
const xs = [p1.x, p2.x, p3.x, p4.x];
|
|
7111
7531
|
const ys = [p1.y, p2.y, p3.y, p4.y];
|
|
7112
7532
|
const x = Math.min(...xs);
|
|
@@ -7147,7 +7567,7 @@ class PdfiumNative {
|
|
|
7147
7567
|
const keywordPtr = this.memoryManager.malloc(length);
|
|
7148
7568
|
this.pdfiumModule.pdfium.stringToUTF16(keyword, keywordPtr, length);
|
|
7149
7569
|
try {
|
|
7150
|
-
const results = this.searchAllInPage(ctx, page, keywordPtr, flags);
|
|
7570
|
+
const results = this.searchAllInPage(doc, ctx, page, keywordPtr, flags);
|
|
7151
7571
|
return PdfTaskHelper.resolve(results);
|
|
7152
7572
|
} finally {
|
|
7153
7573
|
this.memoryManager.free(keywordPtr);
|
|
@@ -7177,7 +7597,7 @@ class PdfiumNative {
|
|
|
7177
7597
|
const total = pages.length;
|
|
7178
7598
|
for (let i = 0; i < pages.length; i++) {
|
|
7179
7599
|
const page = pages[i];
|
|
7180
|
-
const annotations = this.readPageAnnotationsRaw(ctx, page);
|
|
7600
|
+
const annotations = this.readPageAnnotationsRaw(doc, ctx, page);
|
|
7181
7601
|
results[page.index] = annotations;
|
|
7182
7602
|
task.progress({
|
|
7183
7603
|
pageIndex: page.index,
|
|
@@ -7221,7 +7641,7 @@ class PdfiumNative {
|
|
|
7221
7641
|
const total = pages.length;
|
|
7222
7642
|
for (let i = 0; i < pages.length; i++) {
|
|
7223
7643
|
const page = pages[i];
|
|
7224
|
-
const pageResults = this.searchAllInPage(ctx, page, keywordPtr, flags);
|
|
7644
|
+
const pageResults = this.searchAllInPage(doc, ctx, page, keywordPtr, flags);
|
|
7225
7645
|
results[page.index] = pageResults;
|
|
7226
7646
|
task.progress({
|
|
7227
7647
|
pageIndex: page.index,
|
|
@@ -7306,7 +7726,7 @@ class PdfiumNative {
|
|
|
7306
7726
|
*
|
|
7307
7727
|
* @private
|
|
7308
7728
|
*/
|
|
7309
|
-
searchAllInPage(ctx, page, keywordPtr, flag) {
|
|
7729
|
+
searchAllInPage(doc, ctx, page, keywordPtr, flag) {
|
|
7310
7730
|
return ctx.borrowPage(page.index, (pageCtx) => {
|
|
7311
7731
|
const textPagePtr = pageCtx.getTextPage();
|
|
7312
7732
|
const total = this.pdfiumModule.FPDFText_CountChars(textPagePtr);
|
|
@@ -7325,7 +7745,7 @@ class PdfiumNative {
|
|
|
7325
7745
|
while (this.pdfiumModule.FPDFText_FindNext(searchHandle)) {
|
|
7326
7746
|
const charIndex = this.pdfiumModule.FPDFText_GetSchResultIndex(searchHandle);
|
|
7327
7747
|
const charCount = this.pdfiumModule.FPDFText_GetSchCount(searchHandle);
|
|
7328
|
-
const rects = this.getHighlightRects(page, textPagePtr, charIndex, charCount);
|
|
7748
|
+
const rects = this.getHighlightRects(doc, page, textPagePtr, charIndex, charCount);
|
|
7329
7749
|
const context = this.buildContext(fullText, charIndex, charCount);
|
|
7330
7750
|
pageResults.push({
|
|
7331
7751
|
pageIndex: page.index,
|
|
@@ -7593,11 +8013,11 @@ export {
|
|
|
7593
8013
|
PdfiumErrorCode as P,
|
|
7594
8014
|
RenderFlag as R,
|
|
7595
8015
|
PdfiumNative as a,
|
|
7596
|
-
|
|
7597
|
-
|
|
7598
|
-
|
|
7599
|
-
|
|
8016
|
+
createNodeFontLoader as b,
|
|
8017
|
+
computeFormDrawParams as c,
|
|
8018
|
+
createPdfiumEngine as d,
|
|
8019
|
+
readString as e,
|
|
7600
8020
|
isValidCustomKey as i,
|
|
7601
|
-
|
|
8021
|
+
readArrayBuffer as r
|
|
7602
8022
|
};
|
|
7603
|
-
//# sourceMappingURL=direct-engine-
|
|
8023
|
+
//# sourceMappingURL=direct-engine-CvfzIn2D.js.map
|