@embedpdf/engines 1.0.12 → 1.0.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/dist/engine-1ZSXSAtm.cjs +2 -0
  2. package/dist/engine-1ZSXSAtm.cjs.map +1 -0
  3. package/dist/{engine-M0_XZhss.js → engine-O49988D4.js} +716 -189
  4. package/dist/engine-O49988D4.js.map +1 -0
  5. package/dist/index.cjs +1 -1
  6. package/dist/index.cjs.map +1 -1
  7. package/dist/index.js +2 -5
  8. package/dist/index.js.map +1 -1
  9. package/dist/lib/pdfium/engine.d.ts +180 -29
  10. package/dist/lib/pdfium/index.cjs +1 -1
  11. package/dist/lib/pdfium/index.js +2 -2
  12. package/dist/lib/pdfium/web/direct-engine.cjs +1 -1
  13. package/dist/lib/pdfium/web/direct-engine.js +1 -1
  14. package/dist/lib/pdfium/web/worker-engine.cjs +1 -1
  15. package/dist/lib/pdfium/web/worker-engine.js +1 -1
  16. package/dist/lib/webworker/engine.cjs +1 -1
  17. package/dist/lib/webworker/engine.cjs.map +1 -1
  18. package/dist/lib/webworker/engine.d.ts +1 -2
  19. package/dist/lib/webworker/engine.js +1 -16
  20. package/dist/lib/webworker/engine.js.map +1 -1
  21. package/dist/preact/index.cjs +1 -1
  22. package/dist/preact/index.js +1 -1
  23. package/dist/react/index.cjs +1 -1
  24. package/dist/react/index.js +1 -1
  25. package/dist/runner-Br_PKNmU.cjs +2 -0
  26. package/dist/{runner-BcS-WEof.cjs.map → runner-Br_PKNmU.cjs.map} +1 -1
  27. package/dist/{runner-DUp_7Uu_.js → runner-CABEqeFp.js} +2 -5
  28. package/dist/{runner-DUp_7Uu_.js.map → runner-CABEqeFp.js.map} +1 -1
  29. package/dist/vue/index.cjs +1 -1
  30. package/dist/vue/index.js +1 -1
  31. package/package.json +3 -3
  32. package/dist/engine-B7CS6Qyp.cjs +0 -2
  33. package/dist/engine-B7CS6Qyp.cjs.map +0 -1
  34. package/dist/engine-M0_XZhss.js.map +0 -1
  35. package/dist/runner-BcS-WEof.cjs +0 -2
@@ -1,4 +1,4 @@
1
- import { NoopLogger, PdfTaskHelper, PdfErrorCode, Rotation, Task, PdfAnnotationSubtype, stripPdfUnwantedMarkers, PdfAnnotationBorderStyle, dateToPdfDate, PdfAnnotationColorType, PdfPageObjectType, pdfAlphaColorToWebAlphaColor, webAlphaColorToPdfAlphaColor, quadToRect, pdfDateToDate, flagsToNames, PDF_FORM_FIELD_TYPE, AppearanceMode, toIntRect, transformRect, makeMatrix, toIntSize, transformSize, PdfActionType, PdfZoomMode, MatchFlag, rectToQuad } from "@embedpdf/models";
1
+ import { NoopLogger, PdfTaskHelper, PdfErrorCode, Rotation, Task, PdfAnnotationSubtype, stripPdfUnwantedMarkers, PdfAnnotationBorderStyle, dateToPdfDate, PdfAnnotationColorType, PdfAnnotationLineEnding, PdfPageObjectType, pdfColorToWebColor, webColorToPdfColor, pdfAlphaToWebOpacity, webOpacityToPdfAlpha, quadToRect, pdfDateToDate, PdfStandardFont, flagsToNames, namesToFlags, PDF_FORM_FIELD_TYPE, AppearanceMode, toIntRect, transformRect, makeMatrix, toIntSize, transformSize, PdfActionType, PdfZoomMode, MatchFlag, rectToQuad } from "@embedpdf/models";
2
2
  function readString(wasmModule, readChars, parseChars, defaultLength = 100) {
3
3
  let buffer = wasmModule.wasmExports.malloc(defaultLength);
4
4
  for (let i = 0; i < defaultLength; i++) {
@@ -982,6 +982,20 @@ class PdfiumEngine {
982
982
  annotation.contents
983
983
  );
984
984
  break;
985
+ case PdfAnnotationSubtype.FREETEXT:
986
+ isSucceed = this.addFreeTextContent(page, pageCtx.pagePtr, annotationPtr, annotation);
987
+ break;
988
+ case PdfAnnotationSubtype.LINE:
989
+ isSucceed = this.addLineContent(page, pageCtx.pagePtr, annotationPtr, annotation);
990
+ break;
991
+ case PdfAnnotationSubtype.POLYLINE:
992
+ case PdfAnnotationSubtype.POLYGON:
993
+ isSucceed = this.addPolyContent(page, pageCtx.pagePtr, annotationPtr, annotation);
994
+ break;
995
+ case PdfAnnotationSubtype.CIRCLE:
996
+ case PdfAnnotationSubtype.SQUARE:
997
+ isSucceed = this.addShapeContent(page, pageCtx.pagePtr, annotationPtr, annotation);
998
+ break;
985
999
  case PdfAnnotationSubtype.UNDERLINE:
986
1000
  case PdfAnnotationSubtype.STRIKEOUT:
987
1001
  case PdfAnnotationSubtype.SQUIGGLY:
@@ -1108,6 +1122,28 @@ class PdfiumEngine {
1108
1122
  );
1109
1123
  break;
1110
1124
  }
1125
+ /* ── Free text ────────────────────────────────────────────────────────── */
1126
+ case PdfAnnotationSubtype.FREETEXT: {
1127
+ ok = this.addFreeTextContent(page, pageCtx.pagePtr, annotPtr, annotation);
1128
+ break;
1129
+ }
1130
+ /* ── Shape ───────────────────────────────────────────────────────────── */
1131
+ case PdfAnnotationSubtype.CIRCLE:
1132
+ case PdfAnnotationSubtype.SQUARE: {
1133
+ ok = this.addShapeContent(page, pageCtx.pagePtr, annotPtr, annotation);
1134
+ break;
1135
+ }
1136
+ /* ── Line ─────────────────────────────────────────────────────────────── */
1137
+ case PdfAnnotationSubtype.LINE: {
1138
+ ok = this.addLineContent(page, pageCtx.pagePtr, annotPtr, annotation);
1139
+ break;
1140
+ }
1141
+ /* ── Polygon / Polyline ───────────────────────────────────────────────── */
1142
+ case PdfAnnotationSubtype.POLYGON:
1143
+ case PdfAnnotationSubtype.POLYLINE: {
1144
+ ok = this.addPolyContent(page, pageCtx.pagePtr, annotPtr, annotation);
1145
+ break;
1146
+ }
1111
1147
  /* ── Text-markup family ──────────────────────────────────────────────── */
1112
1148
  case PdfAnnotationSubtype.HIGHLIGHT:
1113
1149
  case PdfAnnotationSubtype.UNDERLINE:
@@ -1892,6 +1928,55 @@ class PdfiumEngine {
1892
1928
  free(ptr) {
1893
1929
  this.pdfiumModule.pdfium.wasmExports.free(ptr);
1894
1930
  }
1931
+ addFreeTextContent(page, pagePtr, annotationPtr, annotation) {
1932
+ if (!this.setBorderStyle(annotationPtr, PdfAnnotationBorderStyle.SOLID, 0)) {
1933
+ return false;
1934
+ }
1935
+ if (!this.setAnnotString(annotationPtr, "Contents", annotation.contents ?? "")) {
1936
+ return false;
1937
+ }
1938
+ if (!this.setPageAnnoRect(page, pagePtr, annotationPtr, annotation.rect)) {
1939
+ return false;
1940
+ }
1941
+ if (!this.setAnnotString(annotationPtr, "T", annotation.author || "")) {
1942
+ return false;
1943
+ }
1944
+ if (!this.setAnnotString(annotationPtr, "M", dateToPdfDate(annotation.modified))) {
1945
+ return false;
1946
+ }
1947
+ if (!this.setAnnotationOpacity(annotationPtr, annotation.opacity ?? 1)) {
1948
+ return false;
1949
+ }
1950
+ if (!this.setAnnotationTextAlignment(annotationPtr, annotation.textAlign)) {
1951
+ return false;
1952
+ }
1953
+ if (!this.setAnnotationVerticalAlignment(annotationPtr, annotation.verticalAlign)) {
1954
+ return false;
1955
+ }
1956
+ if (!this.setAnnotationDefaultAppearance(
1957
+ annotationPtr,
1958
+ annotation.fontFamily,
1959
+ annotation.fontSize,
1960
+ annotation.fontColor
1961
+ )) {
1962
+ return false;
1963
+ }
1964
+ if (annotation.intent && !this.setAnnotIntent(annotationPtr, annotation.intent)) {
1965
+ return false;
1966
+ }
1967
+ if (!annotation.backgroundColor || annotation.backgroundColor === "transparent") {
1968
+ if (!this.pdfiumModule.EPDFAnnot_ClearColor(annotationPtr, PdfAnnotationColorType.Color)) {
1969
+ return false;
1970
+ }
1971
+ } else if (!this.setAnnotationColor(
1972
+ annotationPtr,
1973
+ annotation.backgroundColor ?? "#FFFFFF",
1974
+ PdfAnnotationColorType.Color
1975
+ )) {
1976
+ return false;
1977
+ }
1978
+ return true;
1979
+ }
1895
1980
  /**
1896
1981
  * Set the rect of specified annotation
1897
1982
  * @param page - page info that the annotation is belonged to
@@ -1918,12 +2003,204 @@ class PdfiumEngine {
1918
2003
  if (!this.setAnnotString(annotationPtr, "M", dateToPdfDate(annotation.modified))) {
1919
2004
  return false;
1920
2005
  }
2006
+ if (!this.setAnnotationOpacity(annotationPtr, annotation.opacity ?? 1)) {
2007
+ return false;
2008
+ }
1921
2009
  if (!this.setAnnotationColor(
1922
2010
  annotationPtr,
1923
- {
1924
- color: annotation.color ?? "#FFFF00",
1925
- opacity: annotation.opacity ?? 1
1926
- },
2011
+ annotation.color ?? "#FFFF00",
2012
+ PdfAnnotationColorType.Color
2013
+ )) {
2014
+ return false;
2015
+ }
2016
+ return true;
2017
+ }
2018
+ /**
2019
+ * Add line content to annotation
2020
+ * @param page - page info
2021
+ * @param pagePtr - pointer to page object
2022
+ * @param annotationPtr - pointer to line annotation
2023
+ * @param annotation - line annotation
2024
+ * @returns whether line content is added to annotation
2025
+ *
2026
+ * @private
2027
+ */
2028
+ addLineContent(page, pagePtr, annotationPtr, annotation) {
2029
+ var _a, _b;
2030
+ if (!this.setPageAnnoRect(page, pagePtr, annotationPtr, annotation.rect)) {
2031
+ return false;
2032
+ }
2033
+ if (!this.setLinePoints(
2034
+ page,
2035
+ annotationPtr,
2036
+ annotation.linePoints.start,
2037
+ annotation.linePoints.end
2038
+ )) {
2039
+ return false;
2040
+ }
2041
+ if (!this.setLineEndings(
2042
+ annotationPtr,
2043
+ ((_a = annotation.lineEndings) == null ? void 0 : _a.start) ?? PdfAnnotationLineEnding.None,
2044
+ ((_b = annotation.lineEndings) == null ? void 0 : _b.end) ?? PdfAnnotationLineEnding.None
2045
+ )) {
2046
+ return false;
2047
+ }
2048
+ if (!this.setAnnotString(annotationPtr, "Contents", annotation.contents ?? "")) {
2049
+ return false;
2050
+ }
2051
+ if (!this.setAnnotString(annotationPtr, "T", annotation.author || "")) {
2052
+ return false;
2053
+ }
2054
+ if (!this.setAnnotString(annotationPtr, "M", dateToPdfDate(annotation.modified))) {
2055
+ return false;
2056
+ }
2057
+ if (!this.setBorderStyle(annotationPtr, annotation.strokeStyle, annotation.strokeWidth)) {
2058
+ return false;
2059
+ }
2060
+ if (!this.setBorderDashPattern(annotationPtr, annotation.strokeDashArray ?? [])) {
2061
+ return false;
2062
+ }
2063
+ if (annotation.intent && !this.setAnnotIntent(annotationPtr, annotation.intent)) {
2064
+ return false;
2065
+ }
2066
+ if (!annotation.color || annotation.color === "transparent") {
2067
+ if (!this.pdfiumModule.EPDFAnnot_ClearColor(annotationPtr, PdfAnnotationColorType.InteriorColor)) {
2068
+ return false;
2069
+ }
2070
+ } else if (!this.setAnnotationColor(
2071
+ annotationPtr,
2072
+ annotation.color ?? "#FFFF00",
2073
+ PdfAnnotationColorType.InteriorColor
2074
+ )) {
2075
+ return false;
2076
+ }
2077
+ if (!this.setAnnotationOpacity(annotationPtr, annotation.opacity ?? 1)) {
2078
+ return false;
2079
+ }
2080
+ if (!this.setAnnotationColor(
2081
+ annotationPtr,
2082
+ annotation.strokeColor ?? "#FFFF00",
2083
+ PdfAnnotationColorType.Color
2084
+ )) {
2085
+ return false;
2086
+ }
2087
+ return true;
2088
+ }
2089
+ /**
2090
+ * Add polygon or polyline content to annotation
2091
+ * @param page - page info
2092
+ * @param pagePtr - pointer to page object
2093
+ * @param annotationPtr - pointer to polygon or polyline annotation
2094
+ * @param annotation - polygon or polyline annotation
2095
+ * @returns whether polygon or polyline content is added to annotation
2096
+ *
2097
+ * @private
2098
+ */
2099
+ addPolyContent(page, pagePtr, annotationPtr, annotation) {
2100
+ var _a, _b;
2101
+ if (!this.setPageAnnoRect(page, pagePtr, annotationPtr, annotation.rect)) {
2102
+ return false;
2103
+ }
2104
+ if (annotation.type === PdfAnnotationSubtype.POLYLINE && !this.setLineEndings(
2105
+ annotationPtr,
2106
+ ((_a = annotation.lineEndings) == null ? void 0 : _a.start) ?? PdfAnnotationLineEnding.None,
2107
+ ((_b = annotation.lineEndings) == null ? void 0 : _b.end) ?? PdfAnnotationLineEnding.None
2108
+ )) {
2109
+ return false;
2110
+ }
2111
+ if (!this.setPdfAnnoVertices(page, annotationPtr, annotation.vertices)) {
2112
+ return false;
2113
+ }
2114
+ if (!this.setAnnotString(annotationPtr, "Contents", annotation.contents ?? "")) {
2115
+ return false;
2116
+ }
2117
+ if (!this.setAnnotString(annotationPtr, "T", annotation.author || "")) {
2118
+ return false;
2119
+ }
2120
+ if (!this.setAnnotString(annotationPtr, "M", dateToPdfDate(annotation.modified))) {
2121
+ return false;
2122
+ }
2123
+ if (!this.setBorderStyle(annotationPtr, annotation.strokeStyle, annotation.strokeWidth)) {
2124
+ return false;
2125
+ }
2126
+ if (!this.setBorderDashPattern(annotationPtr, annotation.strokeDashArray ?? [])) {
2127
+ return false;
2128
+ }
2129
+ if (annotation.intent && !this.setAnnotIntent(annotationPtr, annotation.intent)) {
2130
+ return false;
2131
+ }
2132
+ if (!annotation.color || annotation.color === "transparent") {
2133
+ if (!this.pdfiumModule.EPDFAnnot_ClearColor(annotationPtr, PdfAnnotationColorType.InteriorColor)) {
2134
+ return false;
2135
+ }
2136
+ } else if (!this.setAnnotationColor(
2137
+ annotationPtr,
2138
+ annotation.color ?? "#FFFF00",
2139
+ PdfAnnotationColorType.InteriorColor
2140
+ )) {
2141
+ return false;
2142
+ }
2143
+ if (!this.setAnnotationOpacity(annotationPtr, annotation.opacity ?? 1)) {
2144
+ return false;
2145
+ }
2146
+ if (!this.setAnnotationColor(
2147
+ annotationPtr,
2148
+ annotation.strokeColor ?? "#FFFF00",
2149
+ PdfAnnotationColorType.Color
2150
+ )) {
2151
+ return false;
2152
+ }
2153
+ return true;
2154
+ }
2155
+ /**
2156
+ * Add shape content to annotation
2157
+ * @param page - page info
2158
+ * @param pagePtr - pointer to page object
2159
+ * @param annotationPtr - pointer to shape annotation
2160
+ * @param annotation - shape annotation
2161
+ * @returns whether shape content is added to annotation
2162
+ *
2163
+ * @private
2164
+ */
2165
+ addShapeContent(page, pagePtr, annotationPtr, annotation) {
2166
+ if (!this.setPageAnnoRect(page, pagePtr, annotationPtr, annotation.rect)) {
2167
+ return false;
2168
+ }
2169
+ if (!this.setAnnotString(annotationPtr, "Contents", annotation.contents ?? "")) {
2170
+ return false;
2171
+ }
2172
+ if (!this.setAnnotString(annotationPtr, "T", annotation.author || "")) {
2173
+ return false;
2174
+ }
2175
+ if (!this.setAnnotString(annotationPtr, "M", dateToPdfDate(annotation.modified))) {
2176
+ return false;
2177
+ }
2178
+ if (!this.setBorderStyle(annotationPtr, annotation.strokeStyle, annotation.strokeWidth)) {
2179
+ return false;
2180
+ }
2181
+ if (!this.setBorderDashPattern(annotationPtr, annotation.strokeDashArray ?? [])) {
2182
+ return false;
2183
+ }
2184
+ if (!this.setAnnotationFlags(annotationPtr, annotation.flags)) {
2185
+ return false;
2186
+ }
2187
+ if (!annotation.color || annotation.color === "transparent") {
2188
+ if (!this.pdfiumModule.EPDFAnnot_ClearColor(annotationPtr, PdfAnnotationColorType.InteriorColor)) {
2189
+ return false;
2190
+ }
2191
+ } else if (!this.setAnnotationColor(
2192
+ annotationPtr,
2193
+ annotation.color ?? "#FFFF00",
2194
+ PdfAnnotationColorType.InteriorColor
2195
+ )) {
2196
+ return false;
2197
+ }
2198
+ if (!this.setAnnotationOpacity(annotationPtr, annotation.opacity ?? 1)) {
2199
+ return false;
2200
+ }
2201
+ if (!this.setAnnotationColor(
2202
+ annotationPtr,
2203
+ annotation.strokeColor ?? "#FFFF00",
1927
2204
  PdfAnnotationColorType.Color
1928
2205
  )) {
1929
2206
  return false;
@@ -1955,12 +2232,12 @@ class PdfiumEngine {
1955
2232
  if (!this.setAnnotString(annotationPtr, "M", dateToPdfDate(annotation.modified))) {
1956
2233
  return false;
1957
2234
  }
2235
+ if (!this.setAnnotationOpacity(annotationPtr, annotation.opacity ?? 1)) {
2236
+ return false;
2237
+ }
1958
2238
  if (!this.setAnnotationColor(
1959
2239
  annotationPtr,
1960
- {
1961
- color: annotation.color ?? "#FFFF00",
1962
- opacity: annotation.opacity ?? 1
1963
- },
2240
+ annotation.color ?? "#FFFF00",
1964
2241
  PdfAnnotationColorType.Color
1965
2242
  )) {
1966
2243
  return false;
@@ -2724,50 +3001,32 @@ class PdfiumEngine {
2724
3001
  const rPtr = this.malloc(4);
2725
3002
  const gPtr = this.malloc(4);
2726
3003
  const bPtr = this.malloc(4);
2727
- const aPtr = this.malloc(4);
2728
- const ok = this.pdfiumModule.EPDFAnnot_GetColor(
2729
- annotationPtr,
2730
- colorType,
2731
- rPtr,
2732
- gPtr,
2733
- bPtr,
2734
- aPtr
2735
- );
3004
+ const ok = this.pdfiumModule.EPDFAnnot_GetColor(annotationPtr, colorType, rPtr, gPtr, bPtr);
2736
3005
  let colour;
2737
3006
  if (ok) {
2738
3007
  colour = {
2739
3008
  red: this.pdfiumModule.pdfium.getValue(rPtr, "i32") & 255,
2740
3009
  green: this.pdfiumModule.pdfium.getValue(gPtr, "i32") & 255,
2741
- blue: this.pdfiumModule.pdfium.getValue(bPtr, "i32") & 255,
2742
- alpha: this.pdfiumModule.pdfium.getValue(aPtr, "i32") & 255
2743
- // 0 = transparent, 255 = opaque
3010
+ blue: this.pdfiumModule.pdfium.getValue(bPtr, "i32") & 255
2744
3011
  };
2745
3012
  }
2746
3013
  this.free(rPtr);
2747
3014
  this.free(gPtr);
2748
3015
  this.free(bPtr);
2749
- this.free(aPtr);
2750
3016
  return colour;
2751
3017
  }
2752
- /* --------------------------------------------------------------------------- */
2753
3018
  /**
2754
- * Resolve the visible fill colour for **Highlight / Underline / StrikeOut /
2755
- * Squiggly** markup annotations.
2756
- *
2757
- * Resolution order (first non-`undefined` wins):
2758
- * 1. `/C` dictionary entry – fast, present in Acrobat / Office PDFs
2759
- * 2. Appearance-stream objects – drills into paths & nested forms
2760
- * 3. Hard-coded fallback (Acrobat-style opaque yellow)
3019
+ * Get the fill/stroke colour annotation.
2761
3020
  *
2762
- * @param annotationPtr - pointer to an `FPDF_ANNOTATION`
2763
- * @param fallback - colour to use when the PDF stores no tint at all
2764
- * @returns WebAlphaColor with hex color and opacity (0-1)
3021
+ * @param annotationPtr - pointer to the annotation whose colour is being set
3022
+ * @param colorType - which colour to get (0 = fill, 1 = stroke)
3023
+ * @returns WebColor with hex color
2765
3024
  *
2766
3025
  * @private
2767
3026
  */
2768
- resolveAnnotationColor(annotationPtr, colorType = PdfAnnotationColorType.Color, fallback = { red: 255, green: 245, blue: 155, alpha: 255 }) {
2769
- const pdfColor = this.readAnnotationColor(annotationPtr, colorType) ?? fallback;
2770
- return pdfAlphaColorToWebAlphaColor(pdfColor);
3027
+ getAnnotationColor(annotationPtr, colorType = PdfAnnotationColorType.Color) {
3028
+ const annotationColor = this.readAnnotationColor(annotationPtr, colorType);
3029
+ return annotationColor ? pdfColorToWebColor(annotationColor) : void 0;
2771
3030
  }
2772
3031
  /**
2773
3032
  * Set the fill/stroke colour for a **Highlight / Underline / StrikeOut / Squiggly** markup annotation.
@@ -2780,15 +3039,143 @@ class PdfiumEngine {
2780
3039
  *
2781
3040
  * @private
2782
3041
  */
2783
- setAnnotationColor(annotationPtr, webAlphaColor, colorType = PdfAnnotationColorType.Color) {
2784
- const pdfAlphaColor = webAlphaColorToPdfAlphaColor(webAlphaColor);
3042
+ setAnnotationColor(annotationPtr, webColor, colorType = PdfAnnotationColorType.Color) {
3043
+ const pdfColor = webColorToPdfColor(webColor);
2785
3044
  return this.pdfiumModule.EPDFAnnot_SetColor(
2786
3045
  annotationPtr,
2787
3046
  colorType,
2788
- pdfAlphaColor.red & 255,
2789
- pdfAlphaColor.green & 255,
2790
- pdfAlphaColor.blue & 255,
2791
- (pdfAlphaColor.alpha ?? 255) & 255
3047
+ pdfColor.red & 255,
3048
+ pdfColor.green & 255,
3049
+ pdfColor.blue & 255
3050
+ );
3051
+ }
3052
+ /**
3053
+ * Get the opacity of the annotation.
3054
+ *
3055
+ * @param annotationPtr - pointer to the annotation whose opacity is being set
3056
+ * @returns opacity (0-1)
3057
+ *
3058
+ * @private
3059
+ */
3060
+ getAnnotationOpacity(annotationPtr) {
3061
+ const opacityPtr = this.malloc(4);
3062
+ const ok = this.pdfiumModule.EPDFAnnot_GetOpacity(annotationPtr, opacityPtr);
3063
+ const opacity = ok ? this.pdfiumModule.pdfium.getValue(opacityPtr, "i32") : 255;
3064
+ this.free(opacityPtr);
3065
+ return pdfAlphaToWebOpacity(opacity);
3066
+ }
3067
+ /**
3068
+ * Set the opacity of the annotation.
3069
+ *
3070
+ * @param annotationPtr - pointer to the annotation whose opacity is being set
3071
+ * @param opacity - opacity (0-1)
3072
+ * @returns true on success
3073
+ *
3074
+ * @private
3075
+ */
3076
+ setAnnotationOpacity(annotationPtr, opacity) {
3077
+ const pdfOpacity = webOpacityToPdfAlpha(opacity);
3078
+ return this.pdfiumModule.EPDFAnnot_SetOpacity(annotationPtr, pdfOpacity & 255);
3079
+ }
3080
+ /**
3081
+ * Fetch the `/Q` text-alignment value from a **FreeText** annotation.
3082
+ *
3083
+ * @param annotationPtr pointer returned by `FPDFPage_GetAnnot`
3084
+ * @returns `PdfTextAlignment`
3085
+ */
3086
+ getAnnotationTextAlignment(annotationPtr) {
3087
+ return this.pdfiumModule.EPDFAnnot_GetTextAlignment(annotationPtr);
3088
+ }
3089
+ /**
3090
+ * Write the `/Q` text-alignment value into a **FreeText** annotation
3091
+ * and clear the existing appearance stream so it can be regenerated.
3092
+ *
3093
+ * @param annotationPtr pointer returned by `FPDFPage_GetAnnot`
3094
+ * @param alignment `PdfTextAlignment`
3095
+ * @returns `true` on success
3096
+ */
3097
+ setAnnotationTextAlignment(annotationPtr, alignment) {
3098
+ return !!this.pdfiumModule.EPDFAnnot_SetTextAlignment(annotationPtr, alignment);
3099
+ }
3100
+ /**
3101
+ * Fetch the `/EPDF:VerticalAlignment` vertical-alignment value from a **FreeText** annotation.
3102
+ *
3103
+ * @param annotationPtr pointer returned by `FPDFPage_GetAnnot`
3104
+ * @returns `PdfVerticalAlignment`
3105
+ */
3106
+ getAnnotationVerticalAlignment(annotationPtr) {
3107
+ return this.pdfiumModule.EPDFAnnot_GetVerticalAlignment(annotationPtr);
3108
+ }
3109
+ /**
3110
+ * Write the `/EPDF:VerticalAlignment` vertical-alignment value into a **FreeText** annotation
3111
+ * and clear the existing appearance stream so it can be regenerated.
3112
+ *
3113
+ * @param annotationPtr pointer returned by `FPDFPage_GetAnnot`
3114
+ * @param alignment `PdfVerticalAlignment`
3115
+ * @returns `true` on success
3116
+ */
3117
+ setAnnotationVerticalAlignment(annotationPtr, alignment) {
3118
+ return !!this.pdfiumModule.EPDFAnnot_SetVerticalAlignment(annotationPtr, alignment);
3119
+ }
3120
+ /**
3121
+ * Return the **default appearance** (font, size, colour) declared in the
3122
+ * `/DA` string of a **FreeText** annotation.
3123
+ *
3124
+ * @param annotationPtr pointer to `FPDF_ANNOTATION`
3125
+ * @returns `{ font, fontSize, color }` or `undefined` when PDFium returns false
3126
+ *
3127
+ * NOTE – `font` is the raw `FPDF_STANDARD_FONT` enum value that PDFium uses
3128
+ * (same range as the C API: 0 = Courier, 12 = ZapfDingbats, …).
3129
+ */
3130
+ getAnnotationDefaultAppearance(annotationPtr) {
3131
+ const fontPtr = this.malloc(4);
3132
+ const sizePtr = this.malloc(4);
3133
+ const rPtr = this.malloc(4);
3134
+ const gPtr = this.malloc(4);
3135
+ const bPtr = this.malloc(4);
3136
+ const ok = !!this.pdfiumModule.EPDFAnnot_GetDefaultAppearance(
3137
+ annotationPtr,
3138
+ fontPtr,
3139
+ sizePtr,
3140
+ rPtr,
3141
+ gPtr,
3142
+ bPtr
3143
+ );
3144
+ if (!ok) {
3145
+ [fontPtr, sizePtr, rPtr, gPtr, bPtr].forEach((p) => this.free(p));
3146
+ return;
3147
+ }
3148
+ const pdf = this.pdfiumModule.pdfium;
3149
+ const font = pdf.getValue(fontPtr, "i32");
3150
+ const fontSize = pdf.getValue(sizePtr, "float");
3151
+ const red = pdf.getValue(rPtr, "i32") & 255;
3152
+ const green = pdf.getValue(gPtr, "i32") & 255;
3153
+ const blue = pdf.getValue(bPtr, "i32") & 255;
3154
+ [fontPtr, sizePtr, rPtr, gPtr, bPtr].forEach((p) => this.free(p));
3155
+ return {
3156
+ fontFamily: font,
3157
+ fontSize,
3158
+ fontColor: pdfColorToWebColor({ red, green, blue })
3159
+ };
3160
+ }
3161
+ /**
3162
+ * Write a **default appearance** (`/DA`) into a FreeText annotation.
3163
+ *
3164
+ * @param annotationPtr pointer to `FPDF_ANNOTATION`
3165
+ * @param font `FPDF_STANDARD_FONT` enum value
3166
+ * @param fontSize size in points (≥ 0)
3167
+ * @param color CSS-style `#rrggbb` string (alpha ignored)
3168
+ * @returns `true` on success
3169
+ */
3170
+ setAnnotationDefaultAppearance(annotationPtr, font, fontSize, color) {
3171
+ const { red, green, blue } = webColorToPdfColor(color);
3172
+ return !!this.pdfiumModule.EPDFAnnot_SetDefaultAppearance(
3173
+ annotationPtr,
3174
+ font,
3175
+ fontSize,
3176
+ red & 255,
3177
+ green & 255,
3178
+ blue & 255
2792
3179
  );
2793
3180
  }
2794
3181
  /**
@@ -2902,6 +3289,117 @@ class PdfiumEngine {
2902
3289
  this.free(arrPtr);
2903
3290
  return { ok: okNative, pattern };
2904
3291
  }
3292
+ /**
3293
+ * Write the /BS /D dash pattern array for an annotation border.
3294
+ *
3295
+ * @param annotationPtr Pointer to FPDF_ANNOTATION
3296
+ * @param pattern Array of dash/space lengths in *points* (e.g. [3, 2])
3297
+ * Empty array clears the pattern (solid line).
3298
+ * @returns true on success
3299
+ *
3300
+ * @private
3301
+ */
3302
+ setBorderDashPattern(annotationPtr, pattern) {
3303
+ if (!pattern || pattern.length === 0) {
3304
+ return this.pdfiumModule.EPDFAnnot_SetBorderDashPattern(annotationPtr, 0, 0);
3305
+ }
3306
+ const clean = pattern.map((n) => Number.isFinite(n) && n > 0 ? n : 0).filter((n) => n > 0);
3307
+ if (clean.length === 0) {
3308
+ return this.pdfiumModule.EPDFAnnot_SetBorderDashPattern(annotationPtr, 0, 0);
3309
+ }
3310
+ const bytes = 4 * clean.length;
3311
+ const bufPtr = this.malloc(bytes);
3312
+ for (let i = 0; i < clean.length; i++) {
3313
+ this.pdfiumModule.pdfium.setValue(bufPtr + 4 * i, clean[i], "float");
3314
+ }
3315
+ const ok = !!this.pdfiumModule.EPDFAnnot_SetBorderDashPattern(
3316
+ annotationPtr,
3317
+ bufPtr,
3318
+ clean.length
3319
+ );
3320
+ this.free(bufPtr);
3321
+ return ok;
3322
+ }
3323
+ /**
3324
+ * Return the `/LE` array (start/end line-ending styles) for a LINE / POLYLINE annot.
3325
+ *
3326
+ * @param annotationPtr - pointer to an `FPDF_ANNOTATION`
3327
+ * @returns `{ start, end }` or `undefined` when PDFium can't read them
3328
+ *
3329
+ * @private
3330
+ */
3331
+ getLineEndings(annotationPtr) {
3332
+ const startPtr = this.malloc(4);
3333
+ const endPtr = this.malloc(4);
3334
+ const ok = !!this.pdfiumModule.EPDFAnnot_GetLineEndings(annotationPtr, startPtr, endPtr);
3335
+ if (!ok) {
3336
+ this.free(startPtr);
3337
+ this.free(endPtr);
3338
+ return void 0;
3339
+ }
3340
+ const start = this.pdfiumModule.pdfium.getValue(startPtr, "i32");
3341
+ const end = this.pdfiumModule.pdfium.getValue(endPtr, "i32");
3342
+ this.free(startPtr);
3343
+ this.free(endPtr);
3344
+ return { start, end };
3345
+ }
3346
+ /**
3347
+ * Write the `/LE` array (start/end line-ending styles) for a LINE / POLYLINE annot.
3348
+ * @param annotationPtr - pointer to an `FPDF_ANNOTATION`
3349
+ * @param start - start line ending style
3350
+ * @param end - end line ending style
3351
+ * @returns `true` on success
3352
+ */
3353
+ setLineEndings(annotationPtr, start, end) {
3354
+ return !!this.pdfiumModule.EPDFAnnot_SetLineEndings(annotationPtr, start, end);
3355
+ }
3356
+ /**
3357
+ * Get the start and end points of a LINE / POLYLINE annot.
3358
+ * @param annotationPtr - pointer to an `FPDF_ANNOTATION`
3359
+ * @param page - logical page info object (`PdfPageObject`)
3360
+ * @returns `{ start, end }` or `undefined` when PDFium can't read them
3361
+ */
3362
+ getLinePoints(annotationPtr, page) {
3363
+ const startPointPtr = this.malloc(8);
3364
+ const endPointPtr = this.malloc(8);
3365
+ this.pdfiumModule.FPDFAnnot_GetLine(annotationPtr, startPointPtr, endPointPtr);
3366
+ const startPointX = this.pdfiumModule.pdfium.getValue(startPointPtr, "float");
3367
+ const startPointY = this.pdfiumModule.pdfium.getValue(startPointPtr + 4, "float");
3368
+ const start = this.convertPagePointToDevicePoint(page, {
3369
+ x: startPointX,
3370
+ y: startPointY
3371
+ });
3372
+ const endPointX = this.pdfiumModule.pdfium.getValue(endPointPtr, "float");
3373
+ const endPointY = this.pdfiumModule.pdfium.getValue(endPointPtr + 4, "float");
3374
+ const end = this.convertPagePointToDevicePoint(page, {
3375
+ x: endPointX,
3376
+ y: endPointY
3377
+ });
3378
+ this.free(startPointPtr);
3379
+ this.free(endPointPtr);
3380
+ return { start, end };
3381
+ }
3382
+ /**
3383
+ * Set the two end‑points of a **Line** annotation
3384
+ * by writing a new /L array `[ x1 y1 x2 y2 ]`.
3385
+ * @param page - logical page info object (`PdfPageObject`)
3386
+ * @param annotPtr - pointer to the annotation whose line points are needed
3387
+ * @param start - start point
3388
+ * @param end - end point
3389
+ * @returns true on success
3390
+ */
3391
+ setLinePoints(page, annotPtr, start, end) {
3392
+ const buf = this.malloc(16);
3393
+ const p1 = this.convertDevicePointToPagePoint(page, start);
3394
+ const p2 = this.convertDevicePointToPagePoint(page, end);
3395
+ this.pdfiumModule.pdfium.setValue(buf + 0, p1.x, "float");
3396
+ this.pdfiumModule.pdfium.setValue(buf + 4, p1.y, "float");
3397
+ this.pdfiumModule.pdfium.setValue(buf + 8, p2.x, "float");
3398
+ this.pdfiumModule.pdfium.setValue(buf + 12, p2.y, "float");
3399
+ const ok = this.pdfiumModule.EPDFAnnot_SetLine(annotPtr, buf, buf + 8);
3400
+ this.free(buf);
3401
+ return ok;
3402
+ }
2905
3403
  /**
2906
3404
  * Read `/QuadPoints` from any annotation and convert each quadrilateral to
2907
3405
  * device-space coordinates.
@@ -3066,14 +3564,16 @@ class PdfiumEngine {
3066
3564
  const contents = this.getAnnotString(annotationPtr, "Contents") || "";
3067
3565
  const state = this.getAnnotString(annotationPtr, "State");
3068
3566
  const stateModel = this.getAnnotString(annotationPtr, "StateModel");
3069
- const webAlphaColor = this.resolveAnnotationColor(annotationPtr);
3567
+ const color = this.getAnnotationColor(annotationPtr);
3568
+ const opacity = this.getAnnotationOpacity(annotationPtr);
3070
3569
  const inReplyToId = this.getInReplyToId(pagePtr, annotationPtr);
3071
3570
  return {
3072
3571
  pageIndex: page.index,
3073
3572
  id: index,
3074
3573
  type: PdfAnnotationSubtype.TEXT,
3075
3574
  contents,
3076
- ...webAlphaColor,
3575
+ color: color ?? "#FFFF00",
3576
+ opacity,
3077
3577
  rect,
3078
3578
  inReplyToId,
3079
3579
  author,
@@ -3098,12 +3598,26 @@ class PdfiumEngine {
3098
3598
  const contents = this.getAnnotString(annotationPtr, "Contents") || "";
3099
3599
  const author = this.getAnnotString(annotationPtr, "T");
3100
3600
  const modifiedRaw = this.getAnnotString(annotationPtr, "M");
3601
+ const defaultStyle = this.getAnnotString(annotationPtr, "DS");
3602
+ const da = this.getAnnotationDefaultAppearance(annotationPtr);
3603
+ const backgroundColor = this.getAnnotationColor(annotationPtr);
3604
+ const textAlign = this.getAnnotationTextAlignment(annotationPtr);
3605
+ const verticalAlign = this.getAnnotationVerticalAlignment(annotationPtr);
3606
+ const opacity = this.getAnnotationOpacity(annotationPtr);
3101
3607
  const modified = pdfDateToDate(modifiedRaw);
3102
3608
  const richContent = this.getAnnotRichContent(annotationPtr);
3103
3609
  return {
3104
3610
  pageIndex: page.index,
3105
3611
  id: index,
3106
3612
  type: PdfAnnotationSubtype.FREETEXT,
3613
+ fontFamily: (da == null ? void 0 : da.fontFamily) ?? PdfStandardFont.Unknown,
3614
+ fontSize: (da == null ? void 0 : da.fontSize) ?? 12,
3615
+ fontColor: (da == null ? void 0 : da.fontColor) ?? "#000000",
3616
+ verticalAlign,
3617
+ backgroundColor,
3618
+ opacity,
3619
+ textAlign,
3620
+ defaultStyle,
3107
3621
  richContent,
3108
3622
  contents,
3109
3623
  author,
@@ -3245,7 +3759,8 @@ class PdfiumEngine {
3245
3759
  const author = this.getAnnotString(annotationPtr, "T");
3246
3760
  const modifiedRaw = this.getAnnotString(annotationPtr, "M");
3247
3761
  const modified = pdfDateToDate(modifiedRaw);
3248
- const webAlphaColor = this.resolveAnnotationColor(annotationPtr);
3762
+ const color = this.getAnnotationColor(annotationPtr);
3763
+ const opacity = this.getAnnotationOpacity(annotationPtr);
3249
3764
  const { width: strokeWidth } = this.getBorderStyle(annotationPtr);
3250
3765
  const inkList = this.getInkList(page, annotationPtr);
3251
3766
  const blendMode = this.pdfiumModule.EPDFAnnot_GetBlendMode(annotationPtr);
@@ -3256,8 +3771,9 @@ class PdfiumEngine {
3256
3771
  type: PdfAnnotationSubtype.INK,
3257
3772
  ...intent && { intent },
3258
3773
  blendMode,
3259
- ...webAlphaColor,
3260
- strokeWidth,
3774
+ color: color ?? "#FF0000",
3775
+ opacity,
3776
+ strokeWidth: strokeWidth === 0 ? 1 : strokeWidth,
3261
3777
  rect,
3262
3778
  inkList,
3263
3779
  author,
@@ -3281,10 +3797,39 @@ class PdfiumEngine {
3281
3797
  const modifiedRaw = this.getAnnotString(annotationPtr, "M");
3282
3798
  const modified = pdfDateToDate(modifiedRaw);
3283
3799
  const vertices = this.readPdfAnnoVertices(page, pagePtr, annotationPtr);
3800
+ const contents = this.getAnnotString(annotationPtr, "Contents") || "";
3801
+ const strokeColor = this.getAnnotationColor(annotationPtr);
3802
+ const interiorColor = this.getAnnotationColor(
3803
+ annotationPtr,
3804
+ PdfAnnotationColorType.InteriorColor
3805
+ );
3806
+ const opacity = this.getAnnotationOpacity(annotationPtr);
3807
+ let { style: strokeStyle, width: strokeWidth } = this.getBorderStyle(annotationPtr);
3808
+ let strokeDashArray;
3809
+ if (strokeStyle === PdfAnnotationBorderStyle.DASHED) {
3810
+ const { ok, pattern } = this.getBorderDashPattern(annotationPtr);
3811
+ if (ok) {
3812
+ strokeDashArray = pattern;
3813
+ }
3814
+ }
3815
+ if (vertices.length > 1) {
3816
+ const first = vertices[0];
3817
+ const last = vertices[vertices.length - 1];
3818
+ if (first.x === last.x && first.y === last.y) {
3819
+ vertices.pop();
3820
+ }
3821
+ }
3284
3822
  return {
3285
3823
  pageIndex: page.index,
3286
3824
  id: index,
3287
3825
  type: PdfAnnotationSubtype.POLYGON,
3826
+ contents,
3827
+ strokeColor: strokeColor ?? "#FF0000",
3828
+ color: interiorColor ?? "transparent",
3829
+ opacity,
3830
+ strokeWidth: strokeWidth === 0 ? 1 : strokeWidth,
3831
+ strokeStyle,
3832
+ strokeDashArray,
3288
3833
  rect,
3289
3834
  vertices,
3290
3835
  author,
@@ -3308,10 +3853,34 @@ class PdfiumEngine {
3308
3853
  const modifiedRaw = this.getAnnotString(annotationPtr, "M");
3309
3854
  const modified = pdfDateToDate(modifiedRaw);
3310
3855
  const vertices = this.readPdfAnnoVertices(page, pagePtr, annotationPtr);
3856
+ const contents = this.getAnnotString(annotationPtr, "Contents") || "";
3857
+ const strokeColor = this.getAnnotationColor(annotationPtr);
3858
+ const interiorColor = this.getAnnotationColor(
3859
+ annotationPtr,
3860
+ PdfAnnotationColorType.InteriorColor
3861
+ );
3862
+ const opacity = this.getAnnotationOpacity(annotationPtr);
3863
+ let { style: strokeStyle, width: strokeWidth } = this.getBorderStyle(annotationPtr);
3864
+ let strokeDashArray;
3865
+ if (strokeStyle === PdfAnnotationBorderStyle.DASHED) {
3866
+ const { ok, pattern } = this.getBorderDashPattern(annotationPtr);
3867
+ if (ok) {
3868
+ strokeDashArray = pattern;
3869
+ }
3870
+ }
3871
+ const lineEndings = this.getLineEndings(annotationPtr);
3311
3872
  return {
3312
3873
  pageIndex: page.index,
3313
3874
  id: index,
3314
3875
  type: PdfAnnotationSubtype.POLYLINE,
3876
+ contents,
3877
+ strokeColor: strokeColor ?? "#FF0000",
3878
+ color: interiorColor ?? "transparent",
3879
+ opacity,
3880
+ strokeWidth: strokeWidth === 0 ? 1 : strokeWidth,
3881
+ strokeStyle,
3882
+ strokeDashArray,
3883
+ lineEndings,
3315
3884
  rect,
3316
3885
  vertices,
3317
3886
  author,
@@ -3334,30 +3903,40 @@ class PdfiumEngine {
3334
3903
  const author = this.getAnnotString(annotationPtr, "T");
3335
3904
  const modifiedRaw = this.getAnnotString(annotationPtr, "M");
3336
3905
  const modified = pdfDateToDate(modifiedRaw);
3337
- const startPointPtr = this.malloc(8);
3338
- const endPointPtr = this.malloc(8);
3339
- this.pdfiumModule.FPDFAnnot_GetLine(annotationPtr, startPointPtr, endPointPtr);
3340
- const startPointX = this.pdfiumModule.pdfium.getValue(startPointPtr, "float");
3341
- const startPointY = this.pdfiumModule.pdfium.getValue(startPointPtr + 4, "float");
3342
- const startPoint = this.convertPagePointToDevicePoint(page, {
3343
- x: startPointX,
3344
- y: startPointY
3345
- });
3346
- const endPointX = this.pdfiumModule.pdfium.getValue(endPointPtr, "float");
3347
- const endPointY = this.pdfiumModule.pdfium.getValue(endPointPtr + 4, "float");
3348
- const endPoint = this.convertPagePointToDevicePoint(page, {
3349
- x: endPointX,
3350
- y: endPointY
3351
- });
3352
- this.free(startPointPtr);
3353
- this.free(endPointPtr);
3906
+ const linePoints = this.getLinePoints(annotationPtr, page);
3907
+ const lineEndings = this.getLineEndings(annotationPtr);
3908
+ const contents = this.getAnnotString(annotationPtr, "Contents") || "";
3909
+ const strokeColor = this.getAnnotationColor(annotationPtr);
3910
+ const interiorColor = this.getAnnotationColor(
3911
+ annotationPtr,
3912
+ PdfAnnotationColorType.InteriorColor
3913
+ );
3914
+ const opacity = this.getAnnotationOpacity(annotationPtr);
3915
+ let { style: strokeStyle, width: strokeWidth } = this.getBorderStyle(annotationPtr);
3916
+ let strokeDashArray;
3917
+ if (strokeStyle === PdfAnnotationBorderStyle.DASHED) {
3918
+ const { ok, pattern } = this.getBorderDashPattern(annotationPtr);
3919
+ if (ok) {
3920
+ strokeDashArray = pattern;
3921
+ }
3922
+ }
3354
3923
  return {
3355
3924
  pageIndex: page.index,
3356
3925
  id: index,
3357
3926
  type: PdfAnnotationSubtype.LINE,
3358
3927
  rect,
3359
- startPoint,
3360
- endPoint,
3928
+ contents,
3929
+ strokeWidth: strokeWidth === 0 ? 1 : strokeWidth,
3930
+ strokeStyle,
3931
+ strokeDashArray,
3932
+ strokeColor: strokeColor ?? "#FF0000",
3933
+ color: interiorColor ?? "transparent",
3934
+ opacity,
3935
+ linePoints: linePoints || { start: { x: 0, y: 0 }, end: { x: 0, y: 0 } },
3936
+ lineEndings: lineEndings || {
3937
+ start: PdfAnnotationLineEnding.None,
3938
+ end: PdfAnnotationLineEnding.None
3939
+ },
3361
3940
  author,
3362
3941
  modified
3363
3942
  };
@@ -3376,7 +3955,8 @@ class PdfiumEngine {
3376
3955
  const pageRect = this.readPageAnnoRect(annotationPtr);
3377
3956
  const rect = this.convertPageRectToDeviceRect(page, pagePtr, pageRect);
3378
3957
  const segmentRects = this.getQuadPointsAnno(page, annotationPtr);
3379
- const webAlphaColor = this.resolveAnnotationColor(annotationPtr);
3958
+ const color = this.getAnnotationColor(annotationPtr);
3959
+ const opacity = this.getAnnotationOpacity(annotationPtr);
3380
3960
  const blendMode = this.pdfiumModule.EPDFAnnot_GetBlendMode(annotationPtr);
3381
3961
  const author = this.getAnnotString(annotationPtr, "T");
3382
3962
  const modifiedRaw = this.getAnnotString(annotationPtr, "M");
@@ -3390,7 +3970,8 @@ class PdfiumEngine {
3390
3970
  rect,
3391
3971
  contents,
3392
3972
  segmentRects,
3393
- ...webAlphaColor,
3973
+ color: color ?? "#FFFF00",
3974
+ opacity,
3394
3975
  author,
3395
3976
  modified
3396
3977
  };
@@ -3413,7 +3994,8 @@ class PdfiumEngine {
3413
3994
  const modified = pdfDateToDate(modifiedRaw);
3414
3995
  const segmentRects = this.getQuadPointsAnno(page, annotationPtr);
3415
3996
  const contents = this.getAnnotString(annotationPtr, "Contents") || "";
3416
- const webAlphaColor = this.resolveAnnotationColor(annotationPtr);
3997
+ const color = this.getAnnotationColor(annotationPtr);
3998
+ const opacity = this.getAnnotationOpacity(annotationPtr);
3417
3999
  const blendMode = this.pdfiumModule.EPDFAnnot_GetBlendMode(annotationPtr);
3418
4000
  return {
3419
4001
  pageIndex: page.index,
@@ -3423,7 +4005,8 @@ class PdfiumEngine {
3423
4005
  rect,
3424
4006
  contents,
3425
4007
  segmentRects,
3426
- ...webAlphaColor,
4008
+ color: color ?? "#FF0000",
4009
+ opacity,
3427
4010
  author,
3428
4011
  modified
3429
4012
  };
@@ -3446,7 +4029,8 @@ class PdfiumEngine {
3446
4029
  const modified = pdfDateToDate(modifiedRaw);
3447
4030
  const segmentRects = this.getQuadPointsAnno(page, annotationPtr);
3448
4031
  const contents = this.getAnnotString(annotationPtr, "Contents") || "";
3449
- const webAlphaColor = this.resolveAnnotationColor(annotationPtr);
4032
+ const color = this.getAnnotationColor(annotationPtr);
4033
+ const opacity = this.getAnnotationOpacity(annotationPtr);
3450
4034
  const blendMode = this.pdfiumModule.EPDFAnnot_GetBlendMode(annotationPtr);
3451
4035
  return {
3452
4036
  pageIndex: page.index,
@@ -3456,7 +4040,8 @@ class PdfiumEngine {
3456
4040
  rect,
3457
4041
  contents,
3458
4042
  segmentRects,
3459
- ...webAlphaColor,
4043
+ color: color ?? "#FF0000",
4044
+ opacity,
3460
4045
  author,
3461
4046
  modified
3462
4047
  };
@@ -3479,7 +4064,8 @@ class PdfiumEngine {
3479
4064
  const modified = pdfDateToDate(modifiedRaw);
3480
4065
  const segmentRects = this.getQuadPointsAnno(page, annotationPtr);
3481
4066
  const contents = this.getAnnotString(annotationPtr, "Contents") || "";
3482
- const webAlphaColor = this.resolveAnnotationColor(annotationPtr);
4067
+ const color = this.getAnnotationColor(annotationPtr);
4068
+ const opacity = this.getAnnotationOpacity(annotationPtr);
3483
4069
  const blendMode = this.pdfiumModule.EPDFAnnot_GetBlendMode(annotationPtr);
3484
4070
  return {
3485
4071
  pageIndex: page.index,
@@ -3489,7 +4075,8 @@ class PdfiumEngine {
3489
4075
  rect,
3490
4076
  contents,
3491
4077
  segmentRects,
3492
- ...webAlphaColor,
4078
+ color: color ?? "#FF0000",
4079
+ opacity,
3493
4080
  author,
3494
4081
  modified
3495
4082
  };
@@ -3751,6 +4338,10 @@ class PdfiumEngine {
3751
4338
  const rawFlags = this.pdfiumModule.FPDFAnnot_GetFlags(annotationPtr);
3752
4339
  return flagsToNames(rawFlags);
3753
4340
  }
4341
+ setAnnotationFlags(annotationPtr, flags) {
4342
+ const rawFlags = namesToFlags(flags);
4343
+ return this.pdfiumModule.FPDFAnnot_SetFlags(annotationPtr, rawFlags);
4344
+ }
3754
4345
  /**
3755
4346
  * Read circle annotation
3756
4347
  * @param page - pdf page infor
@@ -3768,29 +4359,13 @@ class PdfiumEngine {
3768
4359
  const author = this.getAnnotString(annotationPtr, "T");
3769
4360
  const modifiedRaw = this.getAnnotString(annotationPtr, "M");
3770
4361
  const modified = pdfDateToDate(modifiedRaw);
3771
- const { color, opacity } = this.resolveAnnotationColor(
4362
+ const interiorColor = this.getAnnotationColor(
3772
4363
  annotationPtr,
3773
4364
  PdfAnnotationColorType.InteriorColor
3774
4365
  );
3775
- const { color: strokeColor } = this.resolveAnnotationColor(annotationPtr);
4366
+ const strokeColor = this.getAnnotationColor(annotationPtr);
4367
+ const opacity = this.getAnnotationOpacity(annotationPtr);
3776
4368
  let { style: strokeStyle, width: strokeWidth } = this.getBorderStyle(annotationPtr);
3777
- let cloudyBorderIntensity;
3778
- let cloudyBorderInset;
3779
- if (strokeStyle === PdfAnnotationBorderStyle.CLOUDY || strokeStyle === PdfAnnotationBorderStyle.UNKNOWN) {
3780
- const { ok: hasEffect, intensity } = this.getBorderEffect(annotationPtr);
3781
- if (hasEffect) {
3782
- cloudyBorderIntensity = intensity;
3783
- strokeStyle = PdfAnnotationBorderStyle.CLOUDY;
3784
- const {
3785
- ok: hasInset,
3786
- left,
3787
- top,
3788
- right,
3789
- bottom
3790
- } = this.getRectangleDifferences(annotationPtr);
3791
- if (hasInset) cloudyBorderInset = [left, top, right, bottom];
3792
- }
3793
- }
3794
4369
  let strokeDashArray;
3795
4370
  if (strokeStyle === PdfAnnotationBorderStyle.DASHED) {
3796
4371
  const { ok, pattern } = this.getBorderDashPattern(annotationPtr);
@@ -3803,16 +4378,14 @@ class PdfiumEngine {
3803
4378
  id: index,
3804
4379
  type: PdfAnnotationSubtype.CIRCLE,
3805
4380
  flags,
3806
- color,
4381
+ color: interiorColor ?? "transparent",
3807
4382
  opacity,
3808
4383
  strokeWidth,
3809
- strokeColor,
4384
+ strokeColor: strokeColor ?? "#FF0000",
3810
4385
  strokeStyle,
3811
4386
  rect,
3812
4387
  author,
3813
4388
  modified,
3814
- ...cloudyBorderIntensity !== void 0 && { cloudyBorderIntensity },
3815
- ...cloudyBorderInset !== void 0 && { cloudyBorderInset },
3816
4389
  ...strokeDashArray !== void 0 && { strokeDashArray }
3817
4390
  };
3818
4391
  }
@@ -3833,29 +4406,13 @@ class PdfiumEngine {
3833
4406
  const author = this.getAnnotString(annotationPtr, "T");
3834
4407
  const modifiedRaw = this.getAnnotString(annotationPtr, "M");
3835
4408
  const modified = pdfDateToDate(modifiedRaw);
3836
- const { color, opacity } = this.resolveAnnotationColor(
4409
+ const interiorColor = this.getAnnotationColor(
3837
4410
  annotationPtr,
3838
4411
  PdfAnnotationColorType.InteriorColor
3839
4412
  );
3840
- const { color: strokeColor } = this.resolveAnnotationColor(annotationPtr);
4413
+ const strokeColor = this.getAnnotationColor(annotationPtr);
4414
+ const opacity = this.getAnnotationOpacity(annotationPtr);
3841
4415
  let { style: strokeStyle, width: strokeWidth } = this.getBorderStyle(annotationPtr);
3842
- let cloudyBorderIntensity;
3843
- let cloudyBorderInset;
3844
- if (strokeStyle === PdfAnnotationBorderStyle.CLOUDY || strokeStyle === PdfAnnotationBorderStyle.UNKNOWN) {
3845
- const { ok: hasEffect, intensity } = this.getBorderEffect(annotationPtr);
3846
- if (hasEffect) {
3847
- cloudyBorderIntensity = intensity;
3848
- strokeStyle = PdfAnnotationBorderStyle.CLOUDY;
3849
- const {
3850
- ok: hasInset,
3851
- left,
3852
- top,
3853
- right,
3854
- bottom
3855
- } = this.getRectangleDifferences(annotationPtr);
3856
- if (hasInset) cloudyBorderInset = [left, top, right, bottom];
3857
- }
3858
- }
3859
4416
  let strokeDashArray;
3860
4417
  if (strokeStyle === PdfAnnotationBorderStyle.DASHED) {
3861
4418
  const { ok, pattern } = this.getBorderDashPattern(annotationPtr);
@@ -3868,16 +4425,14 @@ class PdfiumEngine {
3868
4425
  id: index,
3869
4426
  type: PdfAnnotationSubtype.SQUARE,
3870
4427
  flags,
3871
- color,
4428
+ color: interiorColor ?? "transparent",
3872
4429
  opacity,
3873
- strokeColor,
4430
+ strokeColor: strokeColor ?? "#FF0000",
3874
4431
  strokeWidth,
3875
4432
  strokeStyle,
3876
4433
  rect,
3877
4434
  author,
3878
4435
  modified,
3879
- ...cloudyBorderIntensity !== void 0 && { cloudyBorderIntensity },
3880
- ...cloudyBorderInset !== void 0 && { cloudyBorderInset },
3881
4436
  ...strokeDashArray !== void 0 && { strokeDashArray }
3882
4437
  };
3883
4438
  }
@@ -3956,6 +4511,19 @@ class PdfiumEngine {
3956
4511
  this.free(ptr);
3957
4512
  return value && value !== "undefined" ? value : void 0;
3958
4513
  }
4514
+ /**
4515
+ * Write the `/IT` (Intent) name into an annotation dictionary.
4516
+ *
4517
+ * Mirrors EPDFAnnot_SetIntent in PDFium (expects a UTF‑8 FPDF_BYTESTRING).
4518
+ *
4519
+ * @param annotationPtr Pointer returned by FPDFPage_GetAnnot
4520
+ * @param intent Name without leading slash, e.g. `"PolygonCloud"`
4521
+ * A leading “/” will be stripped for convenience.
4522
+ * @returns true on success, false otherwise
4523
+ */
4524
+ setAnnotIntent(annotationPtr, intent) {
4525
+ return this.pdfiumModule.EPDFAnnot_SetIntent(annotationPtr, intent);
4526
+ }
3959
4527
  /**
3960
4528
  * Returns the rich‑content string stored in the annotation’s `/RC` entry.
3961
4529
  *
@@ -4013,14 +4581,37 @@ class PdfiumEngine {
4013
4581
  x: pointX,
4014
4582
  y: pointY
4015
4583
  });
4016
- vertices.push({
4017
- x,
4018
- y
4019
- });
4584
+ const last = vertices[vertices.length - 1];
4585
+ if (!last || last.x !== x || last.y !== y) {
4586
+ vertices.push({ x, y });
4587
+ }
4020
4588
  }
4021
4589
  this.free(pointsPtr);
4022
4590
  return vertices;
4023
4591
  }
4592
+ /**
4593
+ * Sync the vertices of a polygon or polyline annotation.
4594
+ *
4595
+ * @param page - pdf page infor
4596
+ * @param annotPtr - pointer to pdf annotation
4597
+ * @param vertices - the vertices to be set
4598
+ * @returns true on success
4599
+ *
4600
+ * @private
4601
+ */
4602
+ setPdfAnnoVertices(page, annotPtr, vertices) {
4603
+ const pdf = this.pdfiumModule.pdfium;
4604
+ const FS_POINTF_SIZE = 8;
4605
+ const buf = this.malloc(FS_POINTF_SIZE * vertices.length);
4606
+ vertices.forEach((v, i) => {
4607
+ const pagePt = this.convertDevicePointToPagePoint(page, v);
4608
+ pdf.setValue(buf + i * FS_POINTF_SIZE + 0, pagePt.x, "float");
4609
+ pdf.setValue(buf + i * FS_POINTF_SIZE + 4, pagePt.y, "float");
4610
+ });
4611
+ const ok = this.pdfiumModule.EPDFAnnot_SetVertices(annotPtr, buf, vertices.length);
4612
+ this.free(buf);
4613
+ return ok;
4614
+ }
4024
4615
  /**
4025
4616
  * Read the target of pdf bookmark
4026
4617
  * @param docPtr - pointer to pdf document object
@@ -4671,70 +5262,6 @@ class PdfiumEngine {
4671
5262
  this.free(bufferPtr);
4672
5263
  return ap;
4673
5264
  }
4674
- /**
4675
- * Change the visible colour (and opacity) of an existing annotation.
4676
- *
4677
- * For markup annotations (highlight / underline / strikeout / squiggly) we
4678
- * first clear the AP dictionary entry, otherwise the stored appearance stream
4679
- * will override the new tint. For all other sub-types we keep the existing
4680
- * AP so custom artwork isn't lost.
4681
- *
4682
- * @param doc logical document object
4683
- * @param page logical page object
4684
- * @param annotation the annotation we want to recolour
4685
- * @param colour RGBA tuple (0-255 per channel)
4686
- * @param which 0 = stroke/fill colour (PDFium's "colourType" param)
4687
- *
4688
- * @returns `true` when the operation succeeded
4689
- */
4690
- updateAnnotationColor(doc, page, annotation, color, which = 0) {
4691
- this.logger.debug(
4692
- LOG_SOURCE,
4693
- LOG_CATEGORY,
4694
- "setAnnotationColor",
4695
- doc,
4696
- page,
4697
- annotation,
4698
- color,
4699
- which
4700
- );
4701
- this.logger.perf(LOG_SOURCE, LOG_CATEGORY, "setAnnotationColor", "Begin", doc.id);
4702
- const task = PdfTaskHelper.create();
4703
- try {
4704
- const ctx = this.cache.getContext(doc.id);
4705
- if (!ctx) {
4706
- this.logger.perf(LOG_SOURCE, LOG_CATEGORY, "setAnnotationColor", "End", doc.id);
4707
- this.logger.warn(LOG_SOURCE, LOG_CATEGORY, "setAnnotationColor: doc closed");
4708
- task.resolve(false);
4709
- return task;
4710
- }
4711
- const pageCtx = ctx.acquirePage(page.index);
4712
- const annotPtr = this.pdfiumModule.FPDFPage_GetAnnot(pageCtx.pagePtr, annotation.id);
4713
- if (!annotPtr) {
4714
- this.logger.perf(LOG_SOURCE, LOG_CATEGORY, "setAnnotationColor", "End", doc.id);
4715
- this.logger.warn(LOG_SOURCE, LOG_CATEGORY, "setAnnotationColor: annot not found");
4716
- pageCtx.release();
4717
- task.resolve(false);
4718
- return task;
4719
- }
4720
- const ok = this.setAnnotationColor(annotPtr, color, which);
4721
- if (ok) {
4722
- this.pdfiumModule.FPDFPage_GenerateContent(pageCtx.pagePtr);
4723
- }
4724
- this.pdfiumModule.FPDFPage_CloseAnnot(annotPtr);
4725
- pageCtx.release();
4726
- this.logger.perf(LOG_SOURCE, LOG_CATEGORY, "setAnnotationColor", "End", doc.id);
4727
- task.resolve(!!ok);
4728
- } catch (error) {
4729
- this.logger.perf(LOG_SOURCE, LOG_CATEGORY, "setAnnotationColor", "End", doc.id);
4730
- this.logger.error(LOG_SOURCE, LOG_CATEGORY, "setAnnotationColor: error", error);
4731
- task.reject({
4732
- code: PdfErrorCode.Unknown,
4733
- message: `Failed to set annotation color: ${error instanceof Error ? error.message : String(error)}`
4734
- });
4735
- }
4736
- return task;
4737
- }
4738
5265
  /**
4739
5266
  * Set the rect of specified annotation
4740
5267
  * @param page - page info that the annotation is belonged to
@@ -5040,4 +5567,4 @@ export {
5040
5567
  readArrayBuffer as c,
5041
5568
  readString as r
5042
5569
  };
5043
- //# sourceMappingURL=engine-M0_XZhss.js.map
5570
+ //# sourceMappingURL=engine-O49988D4.js.map