@embedpdf/engines 1.0.12 → 1.0.13

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.
@@ -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, pdfAlphaColorToWebAlphaColor, webAlphaColorToPdfAlphaColor, quadToRect, pdfDateToDate, 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,17 @@ class PdfiumEngine {
982
982
  annotation.contents
983
983
  );
984
984
  break;
985
+ case PdfAnnotationSubtype.LINE:
986
+ isSucceed = this.addLineContent(page, pageCtx.pagePtr, annotationPtr, annotation);
987
+ break;
988
+ case PdfAnnotationSubtype.POLYLINE:
989
+ case PdfAnnotationSubtype.POLYGON:
990
+ isSucceed = this.addPolyContent(page, pageCtx.pagePtr, annotationPtr, annotation);
991
+ break;
992
+ case PdfAnnotationSubtype.CIRCLE:
993
+ case PdfAnnotationSubtype.SQUARE:
994
+ isSucceed = this.addShapeContent(page, pageCtx.pagePtr, annotationPtr, annotation);
995
+ break;
985
996
  case PdfAnnotationSubtype.UNDERLINE:
986
997
  case PdfAnnotationSubtype.STRIKEOUT:
987
998
  case PdfAnnotationSubtype.SQUIGGLY:
@@ -1108,6 +1119,23 @@ class PdfiumEngine {
1108
1119
  );
1109
1120
  break;
1110
1121
  }
1122
+ /* ── Shape ───────────────────────────────────────────────────────────── */
1123
+ case PdfAnnotationSubtype.CIRCLE:
1124
+ case PdfAnnotationSubtype.SQUARE: {
1125
+ ok = this.addShapeContent(page, pageCtx.pagePtr, annotPtr, annotation);
1126
+ break;
1127
+ }
1128
+ /* ── Line ─────────────────────────────────────────────────────────────── */
1129
+ case PdfAnnotationSubtype.LINE: {
1130
+ ok = this.addLineContent(page, pageCtx.pagePtr, annotPtr, annotation);
1131
+ break;
1132
+ }
1133
+ /* ── Polygon / Polyline ───────────────────────────────────────────────── */
1134
+ case PdfAnnotationSubtype.POLYGON:
1135
+ case PdfAnnotationSubtype.POLYLINE: {
1136
+ ok = this.addPolyContent(page, pageCtx.pagePtr, annotPtr, annotation);
1137
+ break;
1138
+ }
1111
1139
  /* ── Text-markup family ──────────────────────────────────────────────── */
1112
1140
  case PdfAnnotationSubtype.HIGHLIGHT:
1113
1141
  case PdfAnnotationSubtype.UNDERLINE:
@@ -1930,6 +1958,207 @@ class PdfiumEngine {
1930
1958
  }
1931
1959
  return true;
1932
1960
  }
1961
+ /**
1962
+ * Add line content to annotation
1963
+ * @param page - page info
1964
+ * @param pagePtr - pointer to page object
1965
+ * @param annotationPtr - pointer to line annotation
1966
+ * @param annotation - line annotation
1967
+ * @returns whether line content is added to annotation
1968
+ *
1969
+ * @private
1970
+ */
1971
+ addLineContent(page, pagePtr, annotationPtr, annotation) {
1972
+ var _a, _b;
1973
+ if (!this.setPageAnnoRect(page, pagePtr, annotationPtr, annotation.rect)) {
1974
+ return false;
1975
+ }
1976
+ if (!this.setLinePoints(
1977
+ page,
1978
+ annotationPtr,
1979
+ annotation.linePoints.start,
1980
+ annotation.linePoints.end
1981
+ )) {
1982
+ return false;
1983
+ }
1984
+ if (!this.setLineEndings(
1985
+ annotationPtr,
1986
+ ((_a = annotation.lineEndings) == null ? void 0 : _a.start) ?? PdfAnnotationLineEnding.None,
1987
+ ((_b = annotation.lineEndings) == null ? void 0 : _b.end) ?? PdfAnnotationLineEnding.None
1988
+ )) {
1989
+ return false;
1990
+ }
1991
+ if (!this.setAnnotString(annotationPtr, "Contents", annotation.contents ?? "")) {
1992
+ return false;
1993
+ }
1994
+ if (!this.setAnnotString(annotationPtr, "T", annotation.author || "")) {
1995
+ return false;
1996
+ }
1997
+ if (!this.setAnnotString(annotationPtr, "M", dateToPdfDate(annotation.modified))) {
1998
+ return false;
1999
+ }
2000
+ if (!this.setBorderStyle(annotationPtr, annotation.strokeStyle, annotation.strokeWidth)) {
2001
+ return false;
2002
+ }
2003
+ if (!this.setBorderDashPattern(annotationPtr, annotation.strokeDashArray ?? [])) {
2004
+ return false;
2005
+ }
2006
+ if (annotation.intent && !this.setAnnotIntent(annotationPtr, annotation.intent)) {
2007
+ return false;
2008
+ }
2009
+ if (!annotation.color || annotation.color === "transparent") {
2010
+ if (!this.pdfiumModule.EPDFAnnot_ClearColor(annotationPtr, PdfAnnotationColorType.InteriorColor)) {
2011
+ return false;
2012
+ }
2013
+ } else if (!this.setAnnotationColor(
2014
+ annotationPtr,
2015
+ {
2016
+ color: annotation.color ?? "#FFFF00",
2017
+ opacity: annotation.opacity ?? 1
2018
+ },
2019
+ PdfAnnotationColorType.InteriorColor
2020
+ )) {
2021
+ return false;
2022
+ }
2023
+ if (!this.setAnnotationColor(
2024
+ annotationPtr,
2025
+ {
2026
+ color: annotation.strokeColor ?? "#FFFF00",
2027
+ opacity: annotation.opacity ?? 1
2028
+ },
2029
+ PdfAnnotationColorType.Color
2030
+ )) {
2031
+ return false;
2032
+ }
2033
+ return true;
2034
+ }
2035
+ /**
2036
+ * Add polygon or polyline content to annotation
2037
+ * @param page - page info
2038
+ * @param pagePtr - pointer to page object
2039
+ * @param annotationPtr - pointer to polygon or polyline annotation
2040
+ * @param annotation - polygon or polyline annotation
2041
+ * @returns whether polygon or polyline content is added to annotation
2042
+ *
2043
+ * @private
2044
+ */
2045
+ addPolyContent(page, pagePtr, annotationPtr, annotation) {
2046
+ var _a, _b;
2047
+ if (!this.setPageAnnoRect(page, pagePtr, annotationPtr, annotation.rect)) {
2048
+ return false;
2049
+ }
2050
+ if (annotation.type === PdfAnnotationSubtype.POLYLINE && !this.setLineEndings(
2051
+ annotationPtr,
2052
+ ((_a = annotation.lineEndings) == null ? void 0 : _a.start) ?? PdfAnnotationLineEnding.None,
2053
+ ((_b = annotation.lineEndings) == null ? void 0 : _b.end) ?? PdfAnnotationLineEnding.None
2054
+ )) {
2055
+ return false;
2056
+ }
2057
+ if (!this.setPdfAnnoVertices(page, annotationPtr, annotation.vertices)) {
2058
+ return false;
2059
+ }
2060
+ if (!this.setAnnotString(annotationPtr, "Contents", annotation.contents ?? "")) {
2061
+ return false;
2062
+ }
2063
+ if (!this.setAnnotString(annotationPtr, "T", annotation.author || "")) {
2064
+ return false;
2065
+ }
2066
+ if (!this.setAnnotString(annotationPtr, "M", dateToPdfDate(annotation.modified))) {
2067
+ return false;
2068
+ }
2069
+ if (!this.setBorderStyle(annotationPtr, annotation.strokeStyle, annotation.strokeWidth)) {
2070
+ return false;
2071
+ }
2072
+ if (!this.setBorderDashPattern(annotationPtr, annotation.strokeDashArray ?? [])) {
2073
+ return false;
2074
+ }
2075
+ if (annotation.intent && !this.setAnnotIntent(annotationPtr, annotation.intent)) {
2076
+ return false;
2077
+ }
2078
+ if (!annotation.color || annotation.color === "transparent") {
2079
+ if (!this.pdfiumModule.EPDFAnnot_ClearColor(annotationPtr, PdfAnnotationColorType.InteriorColor)) {
2080
+ return false;
2081
+ }
2082
+ } else if (!this.setAnnotationColor(
2083
+ annotationPtr,
2084
+ {
2085
+ color: annotation.color ?? "#FFFF00",
2086
+ opacity: annotation.opacity ?? 1
2087
+ },
2088
+ PdfAnnotationColorType.InteriorColor
2089
+ )) {
2090
+ return false;
2091
+ }
2092
+ if (!this.setAnnotationColor(
2093
+ annotationPtr,
2094
+ {
2095
+ color: annotation.strokeColor ?? "#FFFF00",
2096
+ opacity: annotation.opacity ?? 1
2097
+ },
2098
+ PdfAnnotationColorType.Color
2099
+ )) {
2100
+ return false;
2101
+ }
2102
+ return true;
2103
+ }
2104
+ /**
2105
+ * Add shape content to annotation
2106
+ * @param page - page info
2107
+ * @param pagePtr - pointer to page object
2108
+ * @param annotationPtr - pointer to shape annotation
2109
+ * @param annotation - shape annotation
2110
+ * @returns whether shape content is added to annotation
2111
+ *
2112
+ * @private
2113
+ */
2114
+ addShapeContent(page, pagePtr, annotationPtr, annotation) {
2115
+ if (!this.setPageAnnoRect(page, pagePtr, annotationPtr, annotation.rect)) {
2116
+ return false;
2117
+ }
2118
+ if (!this.setAnnotString(annotationPtr, "Contents", annotation.contents ?? "")) {
2119
+ return false;
2120
+ }
2121
+ if (!this.setAnnotString(annotationPtr, "T", annotation.author || "")) {
2122
+ return false;
2123
+ }
2124
+ if (!this.setAnnotString(annotationPtr, "M", dateToPdfDate(annotation.modified))) {
2125
+ return false;
2126
+ }
2127
+ if (!this.setBorderStyle(annotationPtr, annotation.strokeStyle, annotation.strokeWidth)) {
2128
+ return false;
2129
+ }
2130
+ if (!this.setBorderDashPattern(annotationPtr, annotation.strokeDashArray ?? [])) {
2131
+ return false;
2132
+ }
2133
+ if (!this.setAnnotationFlags(annotationPtr, annotation.flags)) {
2134
+ return false;
2135
+ }
2136
+ if (!annotation.color || annotation.color === "transparent") {
2137
+ if (!this.pdfiumModule.EPDFAnnot_ClearColor(annotationPtr, PdfAnnotationColorType.InteriorColor)) {
2138
+ return false;
2139
+ }
2140
+ } else if (!this.setAnnotationColor(
2141
+ annotationPtr,
2142
+ {
2143
+ color: annotation.color ?? "#FFFF00",
2144
+ opacity: annotation.opacity ?? 1
2145
+ },
2146
+ PdfAnnotationColorType.InteriorColor
2147
+ )) {
2148
+ return false;
2149
+ }
2150
+ if (!this.setAnnotationColor(
2151
+ annotationPtr,
2152
+ {
2153
+ color: annotation.strokeColor ?? "#FFFF00",
2154
+ opacity: annotation.opacity ?? 1
2155
+ },
2156
+ PdfAnnotationColorType.Color
2157
+ )) {
2158
+ return false;
2159
+ }
2160
+ return true;
2161
+ }
1933
2162
  /**
1934
2163
  * Add highlight content to annotation
1935
2164
  * @param page - page info
@@ -2749,25 +2978,16 @@ class PdfiumEngine {
2749
2978
  this.free(aPtr);
2750
2979
  return colour;
2751
2980
  }
2752
- /* --------------------------------------------------------------------------- */
2753
- /**
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)
2761
- *
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)
2765
- *
2766
- * @private
2767
- */
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);
2981
+ // 2) Implementation
2982
+ resolveAnnotationColor(annotationPtr, colorType = PdfAnnotationColorType.Color, fallback) {
2983
+ const annotationColor = this.readAnnotationColor(annotationPtr, colorType);
2984
+ if (annotationColor) {
2985
+ return pdfAlphaColorToWebAlphaColor(annotationColor);
2986
+ }
2987
+ if (fallback !== void 0) {
2988
+ return pdfAlphaColorToWebAlphaColor(fallback);
2989
+ }
2990
+ return void 0;
2771
2991
  }
2772
2992
  /**
2773
2993
  * Set the fill/stroke colour for a **Highlight / Underline / StrikeOut / Squiggly** markup annotation.
@@ -2902,6 +3122,117 @@ class PdfiumEngine {
2902
3122
  this.free(arrPtr);
2903
3123
  return { ok: okNative, pattern };
2904
3124
  }
3125
+ /**
3126
+ * Write the /BS /D dash pattern array for an annotation border.
3127
+ *
3128
+ * @param annotationPtr Pointer to FPDF_ANNOTATION
3129
+ * @param pattern Array of dash/space lengths in *points* (e.g. [3, 2])
3130
+ * Empty array clears the pattern (solid line).
3131
+ * @returns true on success
3132
+ *
3133
+ * @private
3134
+ */
3135
+ setBorderDashPattern(annotationPtr, pattern) {
3136
+ if (!pattern || pattern.length === 0) {
3137
+ return this.pdfiumModule.EPDFAnnot_SetBorderDashPattern(annotationPtr, 0, 0);
3138
+ }
3139
+ const clean = pattern.map((n) => Number.isFinite(n) && n > 0 ? n : 0).filter((n) => n > 0);
3140
+ if (clean.length === 0) {
3141
+ return this.pdfiumModule.EPDFAnnot_SetBorderDashPattern(annotationPtr, 0, 0);
3142
+ }
3143
+ const bytes = 4 * clean.length;
3144
+ const bufPtr = this.malloc(bytes);
3145
+ for (let i = 0; i < clean.length; i++) {
3146
+ this.pdfiumModule.pdfium.setValue(bufPtr + 4 * i, clean[i], "float");
3147
+ }
3148
+ const ok = !!this.pdfiumModule.EPDFAnnot_SetBorderDashPattern(
3149
+ annotationPtr,
3150
+ bufPtr,
3151
+ clean.length
3152
+ );
3153
+ this.free(bufPtr);
3154
+ return ok;
3155
+ }
3156
+ /**
3157
+ * Return the `/LE` array (start/end line-ending styles) for a LINE / POLYLINE annot.
3158
+ *
3159
+ * @param annotationPtr - pointer to an `FPDF_ANNOTATION`
3160
+ * @returns `{ start, end }` or `undefined` when PDFium can't read them
3161
+ *
3162
+ * @private
3163
+ */
3164
+ getLineEndings(annotationPtr) {
3165
+ const startPtr = this.malloc(4);
3166
+ const endPtr = this.malloc(4);
3167
+ const ok = !!this.pdfiumModule.EPDFAnnot_GetLineEndings(annotationPtr, startPtr, endPtr);
3168
+ if (!ok) {
3169
+ this.free(startPtr);
3170
+ this.free(endPtr);
3171
+ return void 0;
3172
+ }
3173
+ const start = this.pdfiumModule.pdfium.getValue(startPtr, "i32");
3174
+ const end = this.pdfiumModule.pdfium.getValue(endPtr, "i32");
3175
+ this.free(startPtr);
3176
+ this.free(endPtr);
3177
+ return { start, end };
3178
+ }
3179
+ /**
3180
+ * Write the `/LE` array (start/end line-ending styles) for a LINE / POLYLINE annot.
3181
+ * @param annotationPtr - pointer to an `FPDF_ANNOTATION`
3182
+ * @param start - start line ending style
3183
+ * @param end - end line ending style
3184
+ * @returns `true` on success
3185
+ */
3186
+ setLineEndings(annotationPtr, start, end) {
3187
+ return !!this.pdfiumModule.EPDFAnnot_SetLineEndings(annotationPtr, start, end);
3188
+ }
3189
+ /**
3190
+ * Get the start and end points of a LINE / POLYLINE annot.
3191
+ * @param annotationPtr - pointer to an `FPDF_ANNOTATION`
3192
+ * @param page - logical page info object (`PdfPageObject`)
3193
+ * @returns `{ start, end }` or `undefined` when PDFium can't read them
3194
+ */
3195
+ getLinePoints(annotationPtr, page) {
3196
+ const startPointPtr = this.malloc(8);
3197
+ const endPointPtr = this.malloc(8);
3198
+ this.pdfiumModule.FPDFAnnot_GetLine(annotationPtr, startPointPtr, endPointPtr);
3199
+ const startPointX = this.pdfiumModule.pdfium.getValue(startPointPtr, "float");
3200
+ const startPointY = this.pdfiumModule.pdfium.getValue(startPointPtr + 4, "float");
3201
+ const start = this.convertPagePointToDevicePoint(page, {
3202
+ x: startPointX,
3203
+ y: startPointY
3204
+ });
3205
+ const endPointX = this.pdfiumModule.pdfium.getValue(endPointPtr, "float");
3206
+ const endPointY = this.pdfiumModule.pdfium.getValue(endPointPtr + 4, "float");
3207
+ const end = this.convertPagePointToDevicePoint(page, {
3208
+ x: endPointX,
3209
+ y: endPointY
3210
+ });
3211
+ this.free(startPointPtr);
3212
+ this.free(endPointPtr);
3213
+ return { start, end };
3214
+ }
3215
+ /**
3216
+ * Set the two end‑points of a **Line** annotation
3217
+ * by writing a new /L array `[ x1 y1 x2 y2 ]`.
3218
+ * @param page - logical page info object (`PdfPageObject`)
3219
+ * @param annotPtr - pointer to the annotation whose line points are needed
3220
+ * @param start - start point
3221
+ * @param end - end point
3222
+ * @returns true on success
3223
+ */
3224
+ setLinePoints(page, annotPtr, start, end) {
3225
+ const buf = this.malloc(16);
3226
+ const p1 = this.convertDevicePointToPagePoint(page, start);
3227
+ const p2 = this.convertDevicePointToPagePoint(page, end);
3228
+ this.pdfiumModule.pdfium.setValue(buf + 0, p1.x, "float");
3229
+ this.pdfiumModule.pdfium.setValue(buf + 4, p1.y, "float");
3230
+ this.pdfiumModule.pdfium.setValue(buf + 8, p2.x, "float");
3231
+ this.pdfiumModule.pdfium.setValue(buf + 12, p2.y, "float");
3232
+ const ok = this.pdfiumModule.EPDFAnnot_SetLine(annotPtr, buf, buf + 8);
3233
+ this.free(buf);
3234
+ return ok;
3235
+ }
2905
3236
  /**
2906
3237
  * Read `/QuadPoints` from any annotation and convert each quadrilateral to
2907
3238
  * device-space coordinates.
@@ -3281,10 +3612,39 @@ class PdfiumEngine {
3281
3612
  const modifiedRaw = this.getAnnotString(annotationPtr, "M");
3282
3613
  const modified = pdfDateToDate(modifiedRaw);
3283
3614
  const vertices = this.readPdfAnnoVertices(page, pagePtr, annotationPtr);
3615
+ const contents = this.getAnnotString(annotationPtr, "Contents") || "";
3616
+ const strokeColor = this.resolveAnnotationColor(annotationPtr);
3617
+ const interiorColor = this.resolveAnnotationColor(
3618
+ annotationPtr,
3619
+ PdfAnnotationColorType.InteriorColor,
3620
+ void 0
3621
+ );
3622
+ let { style: strokeStyle, width: strokeWidth } = this.getBorderStyle(annotationPtr);
3623
+ let strokeDashArray;
3624
+ if (strokeStyle === PdfAnnotationBorderStyle.DASHED) {
3625
+ const { ok, pattern } = this.getBorderDashPattern(annotationPtr);
3626
+ if (ok) {
3627
+ strokeDashArray = pattern;
3628
+ }
3629
+ }
3630
+ if (vertices.length > 1) {
3631
+ const first = vertices[0];
3632
+ const last = vertices[vertices.length - 1];
3633
+ if (first.x === last.x && first.y === last.y) {
3634
+ vertices.pop();
3635
+ }
3636
+ }
3284
3637
  return {
3285
3638
  pageIndex: page.index,
3286
3639
  id: index,
3287
3640
  type: PdfAnnotationSubtype.POLYGON,
3641
+ contents,
3642
+ strokeColor: strokeColor.color,
3643
+ color: (interiorColor == null ? void 0 : interiorColor.color) ?? "transparent",
3644
+ opacity: (interiorColor == null ? void 0 : interiorColor.opacity) ?? strokeColor.opacity,
3645
+ strokeWidth: strokeWidth === 0 ? 1 : strokeWidth,
3646
+ strokeStyle,
3647
+ strokeDashArray,
3288
3648
  rect,
3289
3649
  vertices,
3290
3650
  author,
@@ -3308,10 +3668,34 @@ class PdfiumEngine {
3308
3668
  const modifiedRaw = this.getAnnotString(annotationPtr, "M");
3309
3669
  const modified = pdfDateToDate(modifiedRaw);
3310
3670
  const vertices = this.readPdfAnnoVertices(page, pagePtr, annotationPtr);
3671
+ const contents = this.getAnnotString(annotationPtr, "Contents") || "";
3672
+ const strokeColor = this.resolveAnnotationColor(annotationPtr);
3673
+ const interiorColor = this.resolveAnnotationColor(
3674
+ annotationPtr,
3675
+ PdfAnnotationColorType.InteriorColor,
3676
+ void 0
3677
+ );
3678
+ let { style: strokeStyle, width: strokeWidth } = this.getBorderStyle(annotationPtr);
3679
+ let strokeDashArray;
3680
+ if (strokeStyle === PdfAnnotationBorderStyle.DASHED) {
3681
+ const { ok, pattern } = this.getBorderDashPattern(annotationPtr);
3682
+ if (ok) {
3683
+ strokeDashArray = pattern;
3684
+ }
3685
+ }
3686
+ const lineEndings = this.getLineEndings(annotationPtr);
3311
3687
  return {
3312
3688
  pageIndex: page.index,
3313
3689
  id: index,
3314
3690
  type: PdfAnnotationSubtype.POLYLINE,
3691
+ contents,
3692
+ strokeColor: strokeColor.color,
3693
+ color: (interiorColor == null ? void 0 : interiorColor.color) ?? "transparent",
3694
+ opacity: (interiorColor == null ? void 0 : interiorColor.opacity) ?? strokeColor.opacity,
3695
+ strokeWidth: strokeWidth === 0 ? 1 : strokeWidth,
3696
+ strokeStyle,
3697
+ strokeDashArray,
3698
+ lineEndings,
3315
3699
  rect,
3316
3700
  vertices,
3317
3701
  author,
@@ -3334,30 +3718,40 @@ class PdfiumEngine {
3334
3718
  const author = this.getAnnotString(annotationPtr, "T");
3335
3719
  const modifiedRaw = this.getAnnotString(annotationPtr, "M");
3336
3720
  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);
3721
+ const linePoints = this.getLinePoints(annotationPtr, page);
3722
+ const lineEndings = this.getLineEndings(annotationPtr);
3723
+ const contents = this.getAnnotString(annotationPtr, "Contents") || "";
3724
+ const strokeColor = this.resolveAnnotationColor(annotationPtr);
3725
+ const interiorColor = this.resolveAnnotationColor(
3726
+ annotationPtr,
3727
+ PdfAnnotationColorType.InteriorColor,
3728
+ void 0
3729
+ );
3730
+ let { style: strokeStyle, width: strokeWidth } = this.getBorderStyle(annotationPtr);
3731
+ let strokeDashArray;
3732
+ if (strokeStyle === PdfAnnotationBorderStyle.DASHED) {
3733
+ const { ok, pattern } = this.getBorderDashPattern(annotationPtr);
3734
+ if (ok) {
3735
+ strokeDashArray = pattern;
3736
+ }
3737
+ }
3354
3738
  return {
3355
3739
  pageIndex: page.index,
3356
3740
  id: index,
3357
3741
  type: PdfAnnotationSubtype.LINE,
3358
3742
  rect,
3359
- startPoint,
3360
- endPoint,
3743
+ contents,
3744
+ strokeWidth: strokeWidth === 0 ? 1 : strokeWidth,
3745
+ strokeStyle,
3746
+ strokeDashArray,
3747
+ strokeColor: strokeColor.color,
3748
+ color: (interiorColor == null ? void 0 : interiorColor.color) ?? "transparent",
3749
+ opacity: (interiorColor == null ? void 0 : interiorColor.opacity) ?? strokeColor.opacity,
3750
+ linePoints: linePoints || { start: { x: 0, y: 0 }, end: { x: 0, y: 0 } },
3751
+ lineEndings: lineEndings || {
3752
+ start: PdfAnnotationLineEnding.None,
3753
+ end: PdfAnnotationLineEnding.None
3754
+ },
3361
3755
  author,
3362
3756
  modified
3363
3757
  };
@@ -3751,6 +4145,10 @@ class PdfiumEngine {
3751
4145
  const rawFlags = this.pdfiumModule.FPDFAnnot_GetFlags(annotationPtr);
3752
4146
  return flagsToNames(rawFlags);
3753
4147
  }
4148
+ setAnnotationFlags(annotationPtr, flags) {
4149
+ const rawFlags = namesToFlags(flags);
4150
+ return this.pdfiumModule.FPDFAnnot_SetFlags(annotationPtr, rawFlags);
4151
+ }
3754
4152
  /**
3755
4153
  * Read circle annotation
3756
4154
  * @param page - pdf page infor
@@ -3768,29 +4166,13 @@ class PdfiumEngine {
3768
4166
  const author = this.getAnnotString(annotationPtr, "T");
3769
4167
  const modifiedRaw = this.getAnnotString(annotationPtr, "M");
3770
4168
  const modified = pdfDateToDate(modifiedRaw);
3771
- const { color, opacity } = this.resolveAnnotationColor(
4169
+ const interiorColor = this.resolveAnnotationColor(
3772
4170
  annotationPtr,
3773
- PdfAnnotationColorType.InteriorColor
4171
+ PdfAnnotationColorType.InteriorColor,
4172
+ void 0
3774
4173
  );
3775
- const { color: strokeColor } = this.resolveAnnotationColor(annotationPtr);
4174
+ const { color: strokeColor, opacity: strokeOpacity } = this.resolveAnnotationColor(annotationPtr);
3776
4175
  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
4176
  let strokeDashArray;
3795
4177
  if (strokeStyle === PdfAnnotationBorderStyle.DASHED) {
3796
4178
  const { ok, pattern } = this.getBorderDashPattern(annotationPtr);
@@ -3803,16 +4185,14 @@ class PdfiumEngine {
3803
4185
  id: index,
3804
4186
  type: PdfAnnotationSubtype.CIRCLE,
3805
4187
  flags,
3806
- color,
3807
- opacity,
4188
+ color: (interiorColor == null ? void 0 : interiorColor.color) ?? "transparent",
4189
+ opacity: (interiorColor == null ? void 0 : interiorColor.opacity) ?? strokeOpacity,
3808
4190
  strokeWidth,
3809
4191
  strokeColor,
3810
4192
  strokeStyle,
3811
4193
  rect,
3812
4194
  author,
3813
4195
  modified,
3814
- ...cloudyBorderIntensity !== void 0 && { cloudyBorderIntensity },
3815
- ...cloudyBorderInset !== void 0 && { cloudyBorderInset },
3816
4196
  ...strokeDashArray !== void 0 && { strokeDashArray }
3817
4197
  };
3818
4198
  }
@@ -3833,29 +4213,13 @@ class PdfiumEngine {
3833
4213
  const author = this.getAnnotString(annotationPtr, "T");
3834
4214
  const modifiedRaw = this.getAnnotString(annotationPtr, "M");
3835
4215
  const modified = pdfDateToDate(modifiedRaw);
3836
- const { color, opacity } = this.resolveAnnotationColor(
4216
+ const interiorColor = this.resolveAnnotationColor(
3837
4217
  annotationPtr,
3838
- PdfAnnotationColorType.InteriorColor
4218
+ PdfAnnotationColorType.InteriorColor,
4219
+ void 0
3839
4220
  );
3840
- const { color: strokeColor } = this.resolveAnnotationColor(annotationPtr);
4221
+ const { color: strokeColor, opacity: strokeOpacity } = this.resolveAnnotationColor(annotationPtr);
3841
4222
  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
4223
  let strokeDashArray;
3860
4224
  if (strokeStyle === PdfAnnotationBorderStyle.DASHED) {
3861
4225
  const { ok, pattern } = this.getBorderDashPattern(annotationPtr);
@@ -3868,16 +4232,14 @@ class PdfiumEngine {
3868
4232
  id: index,
3869
4233
  type: PdfAnnotationSubtype.SQUARE,
3870
4234
  flags,
3871
- color,
3872
- opacity,
4235
+ color: (interiorColor == null ? void 0 : interiorColor.color) ?? "transparent",
4236
+ opacity: (interiorColor == null ? void 0 : interiorColor.opacity) ?? strokeOpacity,
3873
4237
  strokeColor,
3874
4238
  strokeWidth,
3875
4239
  strokeStyle,
3876
4240
  rect,
3877
4241
  author,
3878
4242
  modified,
3879
- ...cloudyBorderIntensity !== void 0 && { cloudyBorderIntensity },
3880
- ...cloudyBorderInset !== void 0 && { cloudyBorderInset },
3881
4243
  ...strokeDashArray !== void 0 && { strokeDashArray }
3882
4244
  };
3883
4245
  }
@@ -3956,6 +4318,19 @@ class PdfiumEngine {
3956
4318
  this.free(ptr);
3957
4319
  return value && value !== "undefined" ? value : void 0;
3958
4320
  }
4321
+ /**
4322
+ * Write the `/IT` (Intent) name into an annotation dictionary.
4323
+ *
4324
+ * Mirrors EPDFAnnot_SetIntent in PDFium (expects a UTF‑8 FPDF_BYTESTRING).
4325
+ *
4326
+ * @param annotationPtr Pointer returned by FPDFPage_GetAnnot
4327
+ * @param intent Name without leading slash, e.g. `"PolygonCloud"`
4328
+ * A leading “/” will be stripped for convenience.
4329
+ * @returns true on success, false otherwise
4330
+ */
4331
+ setAnnotIntent(annotationPtr, intent) {
4332
+ return this.pdfiumModule.EPDFAnnot_SetIntent(annotationPtr, intent);
4333
+ }
3959
4334
  /**
3960
4335
  * Returns the rich‑content string stored in the annotation’s `/RC` entry.
3961
4336
  *
@@ -4013,14 +4388,37 @@ class PdfiumEngine {
4013
4388
  x: pointX,
4014
4389
  y: pointY
4015
4390
  });
4016
- vertices.push({
4017
- x,
4018
- y
4019
- });
4391
+ const last = vertices[vertices.length - 1];
4392
+ if (!last || last.x !== x || last.y !== y) {
4393
+ vertices.push({ x, y });
4394
+ }
4020
4395
  }
4021
4396
  this.free(pointsPtr);
4022
4397
  return vertices;
4023
4398
  }
4399
+ /**
4400
+ * Sync the vertices of a polygon or polyline annotation.
4401
+ *
4402
+ * @param page - pdf page infor
4403
+ * @param annotPtr - pointer to pdf annotation
4404
+ * @param vertices - the vertices to be set
4405
+ * @returns true on success
4406
+ *
4407
+ * @private
4408
+ */
4409
+ setPdfAnnoVertices(page, annotPtr, vertices) {
4410
+ const pdf = this.pdfiumModule.pdfium;
4411
+ const FS_POINTF_SIZE = 8;
4412
+ const buf = this.malloc(FS_POINTF_SIZE * vertices.length);
4413
+ vertices.forEach((v, i) => {
4414
+ const pagePt = this.convertDevicePointToPagePoint(page, v);
4415
+ pdf.setValue(buf + i * FS_POINTF_SIZE + 0, pagePt.x, "float");
4416
+ pdf.setValue(buf + i * FS_POINTF_SIZE + 4, pagePt.y, "float");
4417
+ });
4418
+ const ok = this.pdfiumModule.EPDFAnnot_SetVertices(annotPtr, buf, vertices.length);
4419
+ this.free(buf);
4420
+ return ok;
4421
+ }
4024
4422
  /**
4025
4423
  * Read the target of pdf bookmark
4026
4424
  * @param docPtr - pointer to pdf document object
@@ -5040,4 +5438,4 @@ export {
5040
5438
  readArrayBuffer as c,
5041
5439
  readString as r
5042
5440
  };
5043
- //# sourceMappingURL=engine-M0_XZhss.js.map
5441
+ //# sourceMappingURL=engine-B0ZTENqz.js.map