@embedpdf/engines 1.0.13 → 1.0.15

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 (38) hide show
  1. package/dist/{engine-B0ZTENqz.js → engine-B11yoQGd.js} +378 -214
  2. package/dist/engine-B11yoQGd.js.map +1 -0
  3. package/dist/engine-v2kq6ghL.cjs +2 -0
  4. package/dist/engine-v2kq6ghL.cjs.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 +89 -31
  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 +2 -3
  19. package/dist/lib/webworker/engine.js +122 -289
  20. package/dist/lib/webworker/engine.js.map +1 -1
  21. package/dist/lib/webworker/runner.d.ts +12 -0
  22. package/dist/preact/index.cjs +1 -1
  23. package/dist/preact/index.js +1 -1
  24. package/dist/react/index.cjs +1 -1
  25. package/dist/react/index.js +1 -1
  26. package/dist/{runner-B-s0R7NN.js → runner-D9_9TvyZ.js} +2 -5
  27. package/dist/runner-D9_9TvyZ.js.map +1 -0
  28. package/dist/runner-Dnb6tfxR.cjs +2 -0
  29. package/dist/runner-Dnb6tfxR.cjs.map +1 -0
  30. package/dist/vue/index.cjs +1 -1
  31. package/dist/vue/index.js +1 -1
  32. package/package.json +3 -3
  33. package/dist/engine-B0ZTENqz.js.map +0 -1
  34. package/dist/engine-BB5n-Wej.cjs +0 -2
  35. package/dist/engine-BB5n-Wej.cjs.map +0 -1
  36. package/dist/runner-B-s0R7NN.js.map +0 -1
  37. package/dist/runner-BBBtCHic.cjs +0 -2
  38. package/dist/runner-BBBtCHic.cjs.map +0 -1
@@ -1,4 +1,4 @@
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";
1
+ import { NoopLogger, PdfTaskHelper, PdfErrorCode, Rotation, Task, PdfAnnotationSubtype, stripPdfUnwantedMarkers, PdfAnnotationBorderStyle, dateToPdfDate, PdfAnnotationColorType, PdfAnnotationLineEnding, pdfColorToWebColor, webColorToPdfColor, pdfAlphaToWebOpacity, webOpacityToPdfAlpha, quadToRect, pdfDateToDate, PdfStandardFont, PdfPageObjectType, 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++) {
@@ -913,7 +913,7 @@ class PdfiumEngine {
913
913
  *
914
914
  * @public
915
915
  */
916
- createPageAnnotation(doc, page, annotation) {
916
+ createPageAnnotation(doc, page, annotation, context) {
917
917
  this.logger.debug(LOG_SOURCE, LOG_CATEGORY, "createPageAnnotation", doc, page, annotation);
918
918
  this.logger.perf(
919
919
  LOG_SOURCE,
@@ -978,10 +978,13 @@ class PdfiumEngine {
978
978
  page,
979
979
  pageCtx.pagePtr,
980
980
  annotationPtr,
981
- annotation.rect,
982
- annotation.contents
981
+ annotation,
982
+ context == null ? void 0 : context.imageData
983
983
  );
984
984
  break;
985
+ case PdfAnnotationSubtype.FREETEXT:
986
+ isSucceed = this.addFreeTextContent(page, pageCtx.pagePtr, annotationPtr, annotation);
987
+ break;
985
988
  case PdfAnnotationSubtype.LINE:
986
989
  isSucceed = this.addLineContent(page, pageCtx.pagePtr, annotationPtr, annotation);
987
990
  break;
@@ -1106,17 +1109,12 @@ class PdfiumEngine {
1106
1109
  }
1107
1110
  /* ── Stamp ───────────────────────────────────────────────────────────── */
1108
1111
  case PdfAnnotationSubtype.STAMP: {
1109
- for (let i = this.pdfiumModule.FPDFAnnot_GetObjectCount(annotPtr) - 1; i >= 0; i--) {
1110
- this.pdfiumModule.FPDFAnnot_RemoveObject(annotPtr, i);
1111
- }
1112
- ok = this.addStampContent(
1113
- ctx.docPtr,
1114
- page,
1115
- pageCtx.pagePtr,
1116
- annotPtr,
1117
- annotation.rect,
1118
- annotation.contents
1119
- );
1112
+ ok = this.addStampContent(ctx.docPtr, page, pageCtx.pagePtr, annotPtr, annotation);
1113
+ break;
1114
+ }
1115
+ /* ── Free text ────────────────────────────────────────────────────────── */
1116
+ case PdfAnnotationSubtype.FREETEXT: {
1117
+ ok = this.addFreeTextContent(page, pageCtx.pagePtr, annotPtr, annotation);
1120
1118
  break;
1121
1119
  }
1122
1120
  /* ── Shape ───────────────────────────────────────────────────────────── */
@@ -1920,6 +1918,55 @@ class PdfiumEngine {
1920
1918
  free(ptr) {
1921
1919
  this.pdfiumModule.pdfium.wasmExports.free(ptr);
1922
1920
  }
1921
+ addFreeTextContent(page, pagePtr, annotationPtr, annotation) {
1922
+ if (!this.setBorderStyle(annotationPtr, PdfAnnotationBorderStyle.SOLID, 0)) {
1923
+ return false;
1924
+ }
1925
+ if (!this.setAnnotString(annotationPtr, "Contents", annotation.contents ?? "")) {
1926
+ return false;
1927
+ }
1928
+ if (!this.setPageAnnoRect(page, pagePtr, annotationPtr, annotation.rect)) {
1929
+ return false;
1930
+ }
1931
+ if (!this.setAnnotString(annotationPtr, "T", annotation.author || "")) {
1932
+ return false;
1933
+ }
1934
+ if (!this.setAnnotString(annotationPtr, "M", dateToPdfDate(annotation.modified))) {
1935
+ return false;
1936
+ }
1937
+ if (!this.setAnnotationOpacity(annotationPtr, annotation.opacity ?? 1)) {
1938
+ return false;
1939
+ }
1940
+ if (!this.setAnnotationTextAlignment(annotationPtr, annotation.textAlign)) {
1941
+ return false;
1942
+ }
1943
+ if (!this.setAnnotationVerticalAlignment(annotationPtr, annotation.verticalAlign)) {
1944
+ return false;
1945
+ }
1946
+ if (!this.setAnnotationDefaultAppearance(
1947
+ annotationPtr,
1948
+ annotation.fontFamily,
1949
+ annotation.fontSize,
1950
+ annotation.fontColor
1951
+ )) {
1952
+ return false;
1953
+ }
1954
+ if (annotation.intent && !this.setAnnotIntent(annotationPtr, annotation.intent)) {
1955
+ return false;
1956
+ }
1957
+ if (!annotation.backgroundColor || annotation.backgroundColor === "transparent") {
1958
+ if (!this.pdfiumModule.EPDFAnnot_ClearColor(annotationPtr, PdfAnnotationColorType.Color)) {
1959
+ return false;
1960
+ }
1961
+ } else if (!this.setAnnotationColor(
1962
+ annotationPtr,
1963
+ annotation.backgroundColor ?? "#FFFFFF",
1964
+ PdfAnnotationColorType.Color
1965
+ )) {
1966
+ return false;
1967
+ }
1968
+ return true;
1969
+ }
1923
1970
  /**
1924
1971
  * Set the rect of specified annotation
1925
1972
  * @param page - page info that the annotation is belonged to
@@ -1946,12 +1993,12 @@ class PdfiumEngine {
1946
1993
  if (!this.setAnnotString(annotationPtr, "M", dateToPdfDate(annotation.modified))) {
1947
1994
  return false;
1948
1995
  }
1996
+ if (!this.setAnnotationOpacity(annotationPtr, annotation.opacity ?? 1)) {
1997
+ return false;
1998
+ }
1949
1999
  if (!this.setAnnotationColor(
1950
2000
  annotationPtr,
1951
- {
1952
- color: annotation.color ?? "#FFFF00",
1953
- opacity: annotation.opacity ?? 1
1954
- },
2001
+ annotation.color ?? "#FFFF00",
1955
2002
  PdfAnnotationColorType.Color
1956
2003
  )) {
1957
2004
  return false;
@@ -2012,20 +2059,17 @@ class PdfiumEngine {
2012
2059
  }
2013
2060
  } else if (!this.setAnnotationColor(
2014
2061
  annotationPtr,
2015
- {
2016
- color: annotation.color ?? "#FFFF00",
2017
- opacity: annotation.opacity ?? 1
2018
- },
2062
+ annotation.color ?? "#FFFF00",
2019
2063
  PdfAnnotationColorType.InteriorColor
2020
2064
  )) {
2021
2065
  return false;
2022
2066
  }
2067
+ if (!this.setAnnotationOpacity(annotationPtr, annotation.opacity ?? 1)) {
2068
+ return false;
2069
+ }
2023
2070
  if (!this.setAnnotationColor(
2024
2071
  annotationPtr,
2025
- {
2026
- color: annotation.strokeColor ?? "#FFFF00",
2027
- opacity: annotation.opacity ?? 1
2028
- },
2072
+ annotation.strokeColor ?? "#FFFF00",
2029
2073
  PdfAnnotationColorType.Color
2030
2074
  )) {
2031
2075
  return false;
@@ -2081,20 +2125,17 @@ class PdfiumEngine {
2081
2125
  }
2082
2126
  } else if (!this.setAnnotationColor(
2083
2127
  annotationPtr,
2084
- {
2085
- color: annotation.color ?? "#FFFF00",
2086
- opacity: annotation.opacity ?? 1
2087
- },
2128
+ annotation.color ?? "#FFFF00",
2088
2129
  PdfAnnotationColorType.InteriorColor
2089
2130
  )) {
2090
2131
  return false;
2091
2132
  }
2133
+ if (!this.setAnnotationOpacity(annotationPtr, annotation.opacity ?? 1)) {
2134
+ return false;
2135
+ }
2092
2136
  if (!this.setAnnotationColor(
2093
2137
  annotationPtr,
2094
- {
2095
- color: annotation.strokeColor ?? "#FFFF00",
2096
- opacity: annotation.opacity ?? 1
2097
- },
2138
+ annotation.strokeColor ?? "#FFFF00",
2098
2139
  PdfAnnotationColorType.Color
2099
2140
  )) {
2100
2141
  return false;
@@ -2139,20 +2180,17 @@ class PdfiumEngine {
2139
2180
  }
2140
2181
  } else if (!this.setAnnotationColor(
2141
2182
  annotationPtr,
2142
- {
2143
- color: annotation.color ?? "#FFFF00",
2144
- opacity: annotation.opacity ?? 1
2145
- },
2183
+ annotation.color ?? "#FFFF00",
2146
2184
  PdfAnnotationColorType.InteriorColor
2147
2185
  )) {
2148
2186
  return false;
2149
2187
  }
2188
+ if (!this.setAnnotationOpacity(annotationPtr, annotation.opacity ?? 1)) {
2189
+ return false;
2190
+ }
2150
2191
  if (!this.setAnnotationColor(
2151
2192
  annotationPtr,
2152
- {
2153
- color: annotation.strokeColor ?? "#FFFF00",
2154
- opacity: annotation.opacity ?? 1
2155
- },
2193
+ annotation.strokeColor ?? "#FFFF00",
2156
2194
  PdfAnnotationColorType.Color
2157
2195
  )) {
2158
2196
  return false;
@@ -2184,12 +2222,12 @@ class PdfiumEngine {
2184
2222
  if (!this.setAnnotString(annotationPtr, "M", dateToPdfDate(annotation.modified))) {
2185
2223
  return false;
2186
2224
  }
2225
+ if (!this.setAnnotationOpacity(annotationPtr, annotation.opacity ?? 1)) {
2226
+ return false;
2227
+ }
2187
2228
  if (!this.setAnnotationColor(
2188
2229
  annotationPtr,
2189
- {
2190
- color: annotation.color ?? "#FFFF00",
2191
- opacity: annotation.opacity ?? 1
2192
- },
2230
+ annotation.color ?? "#FFFF00",
2193
2231
  PdfAnnotationColorType.Color
2194
2232
  )) {
2195
2233
  return false;
@@ -2208,21 +2246,21 @@ class PdfiumEngine {
2208
2246
  *
2209
2247
  * @private
2210
2248
  */
2211
- addStampContent(docPtr, page, pagePtr, annotationPtr, rect, contents) {
2212
- for (const content of contents) {
2213
- switch (content.type) {
2214
- case PdfPageObjectType.IMAGE:
2215
- return this.addImageObject(
2216
- docPtr,
2217
- page,
2218
- pagePtr,
2219
- annotationPtr,
2220
- rect.origin,
2221
- content.imageData
2222
- );
2249
+ addStampContent(docPtr, page, pagePtr, annotationPtr, annotation, imageData) {
2250
+ if (imageData) {
2251
+ for (let i = this.pdfiumModule.FPDFAnnot_GetObjectCount(annotationPtr) - 1; i >= 0; i--) {
2252
+ this.pdfiumModule.FPDFAnnot_RemoveObject(annotationPtr, i);
2223
2253
  }
2254
+ return this.addImageObject(
2255
+ docPtr,
2256
+ page,
2257
+ pagePtr,
2258
+ annotationPtr,
2259
+ annotation.rect.origin,
2260
+ imageData
2261
+ );
2224
2262
  }
2225
- return false;
2263
+ return true;
2226
2264
  }
2227
2265
  /**
2228
2266
  * Add image object to annotation
@@ -2292,14 +2330,18 @@ class PdfiumEngine {
2292
2330
  return false;
2293
2331
  }
2294
2332
  this.free(matrixPtr);
2295
- this.pdfiumModule.FPDFPageObj_Transform(imageObjectPtr, 1, 0, 0, 1, position.x, position.y);
2333
+ const pagePos = this.convertDevicePointToPagePoint(page, {
2334
+ x: position.x,
2335
+ y: position.y + imageData.height
2336
+ // shift down by the image height
2337
+ });
2338
+ this.pdfiumModule.FPDFPageObj_Transform(imageObjectPtr, 1, 0, 0, 1, pagePos.x, pagePos.y);
2296
2339
  if (!this.pdfiumModule.FPDFAnnot_AppendObject(annotationPtr, imageObjectPtr)) {
2297
2340
  this.pdfiumModule.FPDFBitmap_Destroy(bitmapPtr);
2298
2341
  this.pdfiumModule.FPDFPageObj_Destroy(imageObjectPtr);
2299
2342
  this.free(bitmapBufferPtr);
2300
2343
  return false;
2301
2344
  }
2302
- this.pdfiumModule.FPDFPage_GenerateContent(pagePtr);
2303
2345
  this.pdfiumModule.FPDFBitmap_Destroy(bitmapPtr);
2304
2346
  this.free(bitmapBufferPtr);
2305
2347
  return true;
@@ -2953,41 +2995,32 @@ class PdfiumEngine {
2953
2995
  const rPtr = this.malloc(4);
2954
2996
  const gPtr = this.malloc(4);
2955
2997
  const bPtr = this.malloc(4);
2956
- const aPtr = this.malloc(4);
2957
- const ok = this.pdfiumModule.EPDFAnnot_GetColor(
2958
- annotationPtr,
2959
- colorType,
2960
- rPtr,
2961
- gPtr,
2962
- bPtr,
2963
- aPtr
2964
- );
2998
+ const ok = this.pdfiumModule.EPDFAnnot_GetColor(annotationPtr, colorType, rPtr, gPtr, bPtr);
2965
2999
  let colour;
2966
3000
  if (ok) {
2967
3001
  colour = {
2968
3002
  red: this.pdfiumModule.pdfium.getValue(rPtr, "i32") & 255,
2969
3003
  green: this.pdfiumModule.pdfium.getValue(gPtr, "i32") & 255,
2970
- blue: this.pdfiumModule.pdfium.getValue(bPtr, "i32") & 255,
2971
- alpha: this.pdfiumModule.pdfium.getValue(aPtr, "i32") & 255
2972
- // 0 = transparent, 255 = opaque
3004
+ blue: this.pdfiumModule.pdfium.getValue(bPtr, "i32") & 255
2973
3005
  };
2974
3006
  }
2975
3007
  this.free(rPtr);
2976
3008
  this.free(gPtr);
2977
3009
  this.free(bPtr);
2978
- this.free(aPtr);
2979
3010
  return colour;
2980
3011
  }
2981
- // 2) Implementation
2982
- resolveAnnotationColor(annotationPtr, colorType = PdfAnnotationColorType.Color, fallback) {
3012
+ /**
3013
+ * Get the fill/stroke colour annotation.
3014
+ *
3015
+ * @param annotationPtr - pointer to the annotation whose colour is being set
3016
+ * @param colorType - which colour to get (0 = fill, 1 = stroke)
3017
+ * @returns WebColor with hex color
3018
+ *
3019
+ * @private
3020
+ */
3021
+ getAnnotationColor(annotationPtr, colorType = PdfAnnotationColorType.Color) {
2983
3022
  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;
3023
+ return annotationColor ? pdfColorToWebColor(annotationColor) : void 0;
2991
3024
  }
2992
3025
  /**
2993
3026
  * Set the fill/stroke colour for a **Highlight / Underline / StrikeOut / Squiggly** markup annotation.
@@ -3000,15 +3033,143 @@ class PdfiumEngine {
3000
3033
  *
3001
3034
  * @private
3002
3035
  */
3003
- setAnnotationColor(annotationPtr, webAlphaColor, colorType = PdfAnnotationColorType.Color) {
3004
- const pdfAlphaColor = webAlphaColorToPdfAlphaColor(webAlphaColor);
3036
+ setAnnotationColor(annotationPtr, webColor, colorType = PdfAnnotationColorType.Color) {
3037
+ const pdfColor = webColorToPdfColor(webColor);
3005
3038
  return this.pdfiumModule.EPDFAnnot_SetColor(
3006
3039
  annotationPtr,
3007
3040
  colorType,
3008
- pdfAlphaColor.red & 255,
3009
- pdfAlphaColor.green & 255,
3010
- pdfAlphaColor.blue & 255,
3011
- (pdfAlphaColor.alpha ?? 255) & 255
3041
+ pdfColor.red & 255,
3042
+ pdfColor.green & 255,
3043
+ pdfColor.blue & 255
3044
+ );
3045
+ }
3046
+ /**
3047
+ * Get the opacity of the annotation.
3048
+ *
3049
+ * @param annotationPtr - pointer to the annotation whose opacity is being set
3050
+ * @returns opacity (0-1)
3051
+ *
3052
+ * @private
3053
+ */
3054
+ getAnnotationOpacity(annotationPtr) {
3055
+ const opacityPtr = this.malloc(4);
3056
+ const ok = this.pdfiumModule.EPDFAnnot_GetOpacity(annotationPtr, opacityPtr);
3057
+ const opacity = ok ? this.pdfiumModule.pdfium.getValue(opacityPtr, "i32") : 255;
3058
+ this.free(opacityPtr);
3059
+ return pdfAlphaToWebOpacity(opacity);
3060
+ }
3061
+ /**
3062
+ * Set the opacity of the annotation.
3063
+ *
3064
+ * @param annotationPtr - pointer to the annotation whose opacity is being set
3065
+ * @param opacity - opacity (0-1)
3066
+ * @returns true on success
3067
+ *
3068
+ * @private
3069
+ */
3070
+ setAnnotationOpacity(annotationPtr, opacity) {
3071
+ const pdfOpacity = webOpacityToPdfAlpha(opacity);
3072
+ return this.pdfiumModule.EPDFAnnot_SetOpacity(annotationPtr, pdfOpacity & 255);
3073
+ }
3074
+ /**
3075
+ * Fetch the `/Q` text-alignment value from a **FreeText** annotation.
3076
+ *
3077
+ * @param annotationPtr pointer returned by `FPDFPage_GetAnnot`
3078
+ * @returns `PdfTextAlignment`
3079
+ */
3080
+ getAnnotationTextAlignment(annotationPtr) {
3081
+ return this.pdfiumModule.EPDFAnnot_GetTextAlignment(annotationPtr);
3082
+ }
3083
+ /**
3084
+ * Write the `/Q` text-alignment value into a **FreeText** annotation
3085
+ * and clear the existing appearance stream so it can be regenerated.
3086
+ *
3087
+ * @param annotationPtr pointer returned by `FPDFPage_GetAnnot`
3088
+ * @param alignment `PdfTextAlignment`
3089
+ * @returns `true` on success
3090
+ */
3091
+ setAnnotationTextAlignment(annotationPtr, alignment) {
3092
+ return !!this.pdfiumModule.EPDFAnnot_SetTextAlignment(annotationPtr, alignment);
3093
+ }
3094
+ /**
3095
+ * Fetch the `/EPDF:VerticalAlignment` vertical-alignment value from a **FreeText** annotation.
3096
+ *
3097
+ * @param annotationPtr pointer returned by `FPDFPage_GetAnnot`
3098
+ * @returns `PdfVerticalAlignment`
3099
+ */
3100
+ getAnnotationVerticalAlignment(annotationPtr) {
3101
+ return this.pdfiumModule.EPDFAnnot_GetVerticalAlignment(annotationPtr);
3102
+ }
3103
+ /**
3104
+ * Write the `/EPDF:VerticalAlignment` vertical-alignment value into a **FreeText** annotation
3105
+ * and clear the existing appearance stream so it can be regenerated.
3106
+ *
3107
+ * @param annotationPtr pointer returned by `FPDFPage_GetAnnot`
3108
+ * @param alignment `PdfVerticalAlignment`
3109
+ * @returns `true` on success
3110
+ */
3111
+ setAnnotationVerticalAlignment(annotationPtr, alignment) {
3112
+ return !!this.pdfiumModule.EPDFAnnot_SetVerticalAlignment(annotationPtr, alignment);
3113
+ }
3114
+ /**
3115
+ * Return the **default appearance** (font, size, colour) declared in the
3116
+ * `/DA` string of a **FreeText** annotation.
3117
+ *
3118
+ * @param annotationPtr pointer to `FPDF_ANNOTATION`
3119
+ * @returns `{ font, fontSize, color }` or `undefined` when PDFium returns false
3120
+ *
3121
+ * NOTE – `font` is the raw `FPDF_STANDARD_FONT` enum value that PDFium uses
3122
+ * (same range as the C API: 0 = Courier, 12 = ZapfDingbats, …).
3123
+ */
3124
+ getAnnotationDefaultAppearance(annotationPtr) {
3125
+ const fontPtr = this.malloc(4);
3126
+ const sizePtr = this.malloc(4);
3127
+ const rPtr = this.malloc(4);
3128
+ const gPtr = this.malloc(4);
3129
+ const bPtr = this.malloc(4);
3130
+ const ok = !!this.pdfiumModule.EPDFAnnot_GetDefaultAppearance(
3131
+ annotationPtr,
3132
+ fontPtr,
3133
+ sizePtr,
3134
+ rPtr,
3135
+ gPtr,
3136
+ bPtr
3137
+ );
3138
+ if (!ok) {
3139
+ [fontPtr, sizePtr, rPtr, gPtr, bPtr].forEach((p) => this.free(p));
3140
+ return;
3141
+ }
3142
+ const pdf = this.pdfiumModule.pdfium;
3143
+ const font = pdf.getValue(fontPtr, "i32");
3144
+ const fontSize = pdf.getValue(sizePtr, "float");
3145
+ const red = pdf.getValue(rPtr, "i32") & 255;
3146
+ const green = pdf.getValue(gPtr, "i32") & 255;
3147
+ const blue = pdf.getValue(bPtr, "i32") & 255;
3148
+ [fontPtr, sizePtr, rPtr, gPtr, bPtr].forEach((p) => this.free(p));
3149
+ return {
3150
+ fontFamily: font,
3151
+ fontSize,
3152
+ fontColor: pdfColorToWebColor({ red, green, blue })
3153
+ };
3154
+ }
3155
+ /**
3156
+ * Write a **default appearance** (`/DA`) into a FreeText annotation.
3157
+ *
3158
+ * @param annotationPtr pointer to `FPDF_ANNOTATION`
3159
+ * @param font `FPDF_STANDARD_FONT` enum value
3160
+ * @param fontSize size in points (≥ 0)
3161
+ * @param color CSS-style `#rrggbb` string (alpha ignored)
3162
+ * @returns `true` on success
3163
+ */
3164
+ setAnnotationDefaultAppearance(annotationPtr, font, fontSize, color) {
3165
+ const { red, green, blue } = webColorToPdfColor(color);
3166
+ return !!this.pdfiumModule.EPDFAnnot_SetDefaultAppearance(
3167
+ annotationPtr,
3168
+ font,
3169
+ fontSize,
3170
+ red & 255,
3171
+ green & 255,
3172
+ blue & 255
3012
3173
  );
3013
3174
  }
3014
3175
  /**
@@ -3397,14 +3558,18 @@ class PdfiumEngine {
3397
3558
  const contents = this.getAnnotString(annotationPtr, "Contents") || "";
3398
3559
  const state = this.getAnnotString(annotationPtr, "State");
3399
3560
  const stateModel = this.getAnnotString(annotationPtr, "StateModel");
3400
- const webAlphaColor = this.resolveAnnotationColor(annotationPtr);
3561
+ const color = this.getAnnotationColor(annotationPtr);
3562
+ const opacity = this.getAnnotationOpacity(annotationPtr);
3401
3563
  const inReplyToId = this.getInReplyToId(pagePtr, annotationPtr);
3564
+ const flags = this.getAnnotationFlags(annotationPtr);
3402
3565
  return {
3403
3566
  pageIndex: page.index,
3404
3567
  id: index,
3405
3568
  type: PdfAnnotationSubtype.TEXT,
3569
+ flags,
3406
3570
  contents,
3407
- ...webAlphaColor,
3571
+ color: color ?? "#FFFF00",
3572
+ opacity,
3408
3573
  rect,
3409
3574
  inReplyToId,
3410
3575
  author,
@@ -3429,12 +3594,28 @@ class PdfiumEngine {
3429
3594
  const contents = this.getAnnotString(annotationPtr, "Contents") || "";
3430
3595
  const author = this.getAnnotString(annotationPtr, "T");
3431
3596
  const modifiedRaw = this.getAnnotString(annotationPtr, "M");
3597
+ const defaultStyle = this.getAnnotString(annotationPtr, "DS");
3598
+ const da = this.getAnnotationDefaultAppearance(annotationPtr);
3599
+ const backgroundColor = this.getAnnotationColor(annotationPtr);
3600
+ const textAlign = this.getAnnotationTextAlignment(annotationPtr);
3601
+ const verticalAlign = this.getAnnotationVerticalAlignment(annotationPtr);
3602
+ const opacity = this.getAnnotationOpacity(annotationPtr);
3432
3603
  const modified = pdfDateToDate(modifiedRaw);
3433
3604
  const richContent = this.getAnnotRichContent(annotationPtr);
3605
+ const flags = this.getAnnotationFlags(annotationPtr);
3434
3606
  return {
3435
3607
  pageIndex: page.index,
3436
3608
  id: index,
3437
3609
  type: PdfAnnotationSubtype.FREETEXT,
3610
+ fontFamily: (da == null ? void 0 : da.fontFamily) ?? PdfStandardFont.Unknown,
3611
+ fontSize: (da == null ? void 0 : da.fontSize) ?? 12,
3612
+ fontColor: (da == null ? void 0 : da.fontColor) ?? "#000000",
3613
+ verticalAlign,
3614
+ backgroundColor,
3615
+ flags,
3616
+ opacity,
3617
+ textAlign,
3618
+ defaultStyle,
3438
3619
  richContent,
3439
3620
  contents,
3440
3621
  author,
@@ -3465,6 +3646,7 @@ class PdfiumEngine {
3465
3646
  const author = this.getAnnotString(annotationPtr, "T");
3466
3647
  const modifiedRaw = this.getAnnotString(annotationPtr, "M");
3467
3648
  const modified = pdfDateToDate(modifiedRaw);
3649
+ const flags = this.getAnnotationFlags(annotationPtr);
3468
3650
  const utf16Length = this.pdfiumModule.FPDFText_GetBoundedText(
3469
3651
  textPagePtr,
3470
3652
  left,
@@ -3500,6 +3682,7 @@ class PdfiumEngine {
3500
3682
  pageIndex: page.index,
3501
3683
  id: index,
3502
3684
  type: PdfAnnotationSubtype.LINK,
3685
+ flags,
3503
3686
  text,
3504
3687
  target,
3505
3688
  rect,
@@ -3524,11 +3707,13 @@ class PdfiumEngine {
3524
3707
  const author = this.getAnnotString(annotationPtr, "T");
3525
3708
  const modifiedRaw = this.getAnnotString(annotationPtr, "M");
3526
3709
  const modified = pdfDateToDate(modifiedRaw);
3710
+ const flags = this.getAnnotationFlags(annotationPtr);
3527
3711
  const field = this.readPdfWidgetAnnoField(formHandle, annotationPtr);
3528
3712
  return {
3529
3713
  pageIndex: page.index,
3530
3714
  id: index,
3531
3715
  type: PdfAnnotationSubtype.WIDGET,
3716
+ flags,
3532
3717
  rect,
3533
3718
  field,
3534
3719
  author,
@@ -3551,10 +3736,12 @@ class PdfiumEngine {
3551
3736
  const author = this.getAnnotString(annotationPtr, "T");
3552
3737
  const modifiedRaw = this.getAnnotString(annotationPtr, "M");
3553
3738
  const modified = pdfDateToDate(modifiedRaw);
3739
+ const flags = this.getAnnotationFlags(annotationPtr);
3554
3740
  return {
3555
3741
  pageIndex: page.index,
3556
3742
  id: index,
3557
3743
  type: PdfAnnotationSubtype.FILEATTACHMENT,
3744
+ flags,
3558
3745
  rect,
3559
3746
  author,
3560
3747
  modified
@@ -3576,19 +3763,23 @@ class PdfiumEngine {
3576
3763
  const author = this.getAnnotString(annotationPtr, "T");
3577
3764
  const modifiedRaw = this.getAnnotString(annotationPtr, "M");
3578
3765
  const modified = pdfDateToDate(modifiedRaw);
3579
- const webAlphaColor = this.resolveAnnotationColor(annotationPtr);
3766
+ const color = this.getAnnotationColor(annotationPtr);
3767
+ const opacity = this.getAnnotationOpacity(annotationPtr);
3580
3768
  const { width: strokeWidth } = this.getBorderStyle(annotationPtr);
3581
3769
  const inkList = this.getInkList(page, annotationPtr);
3582
3770
  const blendMode = this.pdfiumModule.EPDFAnnot_GetBlendMode(annotationPtr);
3583
3771
  const intent = this.getAnnotIntent(annotationPtr);
3772
+ const flags = this.getAnnotationFlags(annotationPtr);
3584
3773
  return {
3585
3774
  pageIndex: page.index,
3586
3775
  id: index,
3587
3776
  type: PdfAnnotationSubtype.INK,
3588
3777
  ...intent && { intent },
3589
3778
  blendMode,
3590
- ...webAlphaColor,
3591
- strokeWidth,
3779
+ flags,
3780
+ color: color ?? "#FF0000",
3781
+ opacity,
3782
+ strokeWidth: strokeWidth === 0 ? 1 : strokeWidth,
3592
3783
  rect,
3593
3784
  inkList,
3594
3785
  author,
@@ -3613,12 +3804,13 @@ class PdfiumEngine {
3613
3804
  const modified = pdfDateToDate(modifiedRaw);
3614
3805
  const vertices = this.readPdfAnnoVertices(page, pagePtr, annotationPtr);
3615
3806
  const contents = this.getAnnotString(annotationPtr, "Contents") || "";
3616
- const strokeColor = this.resolveAnnotationColor(annotationPtr);
3617
- const interiorColor = this.resolveAnnotationColor(
3807
+ const flags = this.getAnnotationFlags(annotationPtr);
3808
+ const strokeColor = this.getAnnotationColor(annotationPtr);
3809
+ const interiorColor = this.getAnnotationColor(
3618
3810
  annotationPtr,
3619
- PdfAnnotationColorType.InteriorColor,
3620
- void 0
3811
+ PdfAnnotationColorType.InteriorColor
3621
3812
  );
3813
+ const opacity = this.getAnnotationOpacity(annotationPtr);
3622
3814
  let { style: strokeStyle, width: strokeWidth } = this.getBorderStyle(annotationPtr);
3623
3815
  let strokeDashArray;
3624
3816
  if (strokeStyle === PdfAnnotationBorderStyle.DASHED) {
@@ -3639,9 +3831,10 @@ class PdfiumEngine {
3639
3831
  id: index,
3640
3832
  type: PdfAnnotationSubtype.POLYGON,
3641
3833
  contents,
3642
- strokeColor: strokeColor.color,
3643
- color: (interiorColor == null ? void 0 : interiorColor.color) ?? "transparent",
3644
- opacity: (interiorColor == null ? void 0 : interiorColor.opacity) ?? strokeColor.opacity,
3834
+ flags,
3835
+ strokeColor: strokeColor ?? "#FF0000",
3836
+ color: interiorColor ?? "transparent",
3837
+ opacity,
3645
3838
  strokeWidth: strokeWidth === 0 ? 1 : strokeWidth,
3646
3839
  strokeStyle,
3647
3840
  strokeDashArray,
@@ -3669,12 +3862,13 @@ class PdfiumEngine {
3669
3862
  const modified = pdfDateToDate(modifiedRaw);
3670
3863
  const vertices = this.readPdfAnnoVertices(page, pagePtr, annotationPtr);
3671
3864
  const contents = this.getAnnotString(annotationPtr, "Contents") || "";
3672
- const strokeColor = this.resolveAnnotationColor(annotationPtr);
3673
- const interiorColor = this.resolveAnnotationColor(
3865
+ const strokeColor = this.getAnnotationColor(annotationPtr);
3866
+ const flags = this.getAnnotationFlags(annotationPtr);
3867
+ const interiorColor = this.getAnnotationColor(
3674
3868
  annotationPtr,
3675
- PdfAnnotationColorType.InteriorColor,
3676
- void 0
3869
+ PdfAnnotationColorType.InteriorColor
3677
3870
  );
3871
+ const opacity = this.getAnnotationOpacity(annotationPtr);
3678
3872
  let { style: strokeStyle, width: strokeWidth } = this.getBorderStyle(annotationPtr);
3679
3873
  let strokeDashArray;
3680
3874
  if (strokeStyle === PdfAnnotationBorderStyle.DASHED) {
@@ -3689,9 +3883,10 @@ class PdfiumEngine {
3689
3883
  id: index,
3690
3884
  type: PdfAnnotationSubtype.POLYLINE,
3691
3885
  contents,
3692
- strokeColor: strokeColor.color,
3693
- color: (interiorColor == null ? void 0 : interiorColor.color) ?? "transparent",
3694
- opacity: (interiorColor == null ? void 0 : interiorColor.opacity) ?? strokeColor.opacity,
3886
+ flags,
3887
+ strokeColor: strokeColor ?? "#FF0000",
3888
+ color: interiorColor ?? "transparent",
3889
+ opacity,
3695
3890
  strokeWidth: strokeWidth === 0 ? 1 : strokeWidth,
3696
3891
  strokeStyle,
3697
3892
  strokeDashArray,
@@ -3721,12 +3916,13 @@ class PdfiumEngine {
3721
3916
  const linePoints = this.getLinePoints(annotationPtr, page);
3722
3917
  const lineEndings = this.getLineEndings(annotationPtr);
3723
3918
  const contents = this.getAnnotString(annotationPtr, "Contents") || "";
3724
- const strokeColor = this.resolveAnnotationColor(annotationPtr);
3725
- const interiorColor = this.resolveAnnotationColor(
3919
+ const strokeColor = this.getAnnotationColor(annotationPtr);
3920
+ const flags = this.getAnnotationFlags(annotationPtr);
3921
+ const interiorColor = this.getAnnotationColor(
3726
3922
  annotationPtr,
3727
- PdfAnnotationColorType.InteriorColor,
3728
- void 0
3923
+ PdfAnnotationColorType.InteriorColor
3729
3924
  );
3925
+ const opacity = this.getAnnotationOpacity(annotationPtr);
3730
3926
  let { style: strokeStyle, width: strokeWidth } = this.getBorderStyle(annotationPtr);
3731
3927
  let strokeDashArray;
3732
3928
  if (strokeStyle === PdfAnnotationBorderStyle.DASHED) {
@@ -3739,14 +3935,15 @@ class PdfiumEngine {
3739
3935
  pageIndex: page.index,
3740
3936
  id: index,
3741
3937
  type: PdfAnnotationSubtype.LINE,
3938
+ flags,
3742
3939
  rect,
3743
3940
  contents,
3744
3941
  strokeWidth: strokeWidth === 0 ? 1 : strokeWidth,
3745
3942
  strokeStyle,
3746
3943
  strokeDashArray,
3747
- strokeColor: strokeColor.color,
3748
- color: (interiorColor == null ? void 0 : interiorColor.color) ?? "transparent",
3749
- opacity: (interiorColor == null ? void 0 : interiorColor.opacity) ?? strokeColor.opacity,
3944
+ strokeColor: strokeColor ?? "#FF0000",
3945
+ color: interiorColor ?? "transparent",
3946
+ opacity,
3750
3947
  linePoints: linePoints || { start: { x: 0, y: 0 }, end: { x: 0, y: 0 } },
3751
3948
  lineEndings: lineEndings || {
3752
3949
  start: PdfAnnotationLineEnding.None,
@@ -3770,21 +3967,25 @@ class PdfiumEngine {
3770
3967
  const pageRect = this.readPageAnnoRect(annotationPtr);
3771
3968
  const rect = this.convertPageRectToDeviceRect(page, pagePtr, pageRect);
3772
3969
  const segmentRects = this.getQuadPointsAnno(page, annotationPtr);
3773
- const webAlphaColor = this.resolveAnnotationColor(annotationPtr);
3970
+ const color = this.getAnnotationColor(annotationPtr);
3971
+ const opacity = this.getAnnotationOpacity(annotationPtr);
3774
3972
  const blendMode = this.pdfiumModule.EPDFAnnot_GetBlendMode(annotationPtr);
3775
3973
  const author = this.getAnnotString(annotationPtr, "T");
3776
3974
  const modifiedRaw = this.getAnnotString(annotationPtr, "M");
3777
3975
  const modified = pdfDateToDate(modifiedRaw);
3778
3976
  const contents = this.getAnnotString(annotationPtr, "Contents") || "";
3977
+ const flags = this.getAnnotationFlags(annotationPtr);
3779
3978
  return {
3780
3979
  pageIndex: page.index,
3781
3980
  id: index,
3782
3981
  blendMode,
3783
3982
  type: PdfAnnotationSubtype.HIGHLIGHT,
3784
3983
  rect,
3984
+ flags,
3785
3985
  contents,
3786
3986
  segmentRects,
3787
- ...webAlphaColor,
3987
+ color: color ?? "#FFFF00",
3988
+ opacity,
3788
3989
  author,
3789
3990
  modified
3790
3991
  };
@@ -3807,17 +4008,21 @@ class PdfiumEngine {
3807
4008
  const modified = pdfDateToDate(modifiedRaw);
3808
4009
  const segmentRects = this.getQuadPointsAnno(page, annotationPtr);
3809
4010
  const contents = this.getAnnotString(annotationPtr, "Contents") || "";
3810
- const webAlphaColor = this.resolveAnnotationColor(annotationPtr);
4011
+ const color = this.getAnnotationColor(annotationPtr);
4012
+ const opacity = this.getAnnotationOpacity(annotationPtr);
3811
4013
  const blendMode = this.pdfiumModule.EPDFAnnot_GetBlendMode(annotationPtr);
4014
+ const flags = this.getAnnotationFlags(annotationPtr);
3812
4015
  return {
3813
4016
  pageIndex: page.index,
3814
4017
  id: index,
3815
4018
  blendMode,
3816
4019
  type: PdfAnnotationSubtype.UNDERLINE,
3817
4020
  rect,
4021
+ flags,
3818
4022
  contents,
3819
4023
  segmentRects,
3820
- ...webAlphaColor,
4024
+ color: color ?? "#FF0000",
4025
+ opacity,
3821
4026
  author,
3822
4027
  modified
3823
4028
  };
@@ -3840,17 +4045,21 @@ class PdfiumEngine {
3840
4045
  const modified = pdfDateToDate(modifiedRaw);
3841
4046
  const segmentRects = this.getQuadPointsAnno(page, annotationPtr);
3842
4047
  const contents = this.getAnnotString(annotationPtr, "Contents") || "";
3843
- const webAlphaColor = this.resolveAnnotationColor(annotationPtr);
4048
+ const color = this.getAnnotationColor(annotationPtr);
4049
+ const opacity = this.getAnnotationOpacity(annotationPtr);
3844
4050
  const blendMode = this.pdfiumModule.EPDFAnnot_GetBlendMode(annotationPtr);
4051
+ const flags = this.getAnnotationFlags(annotationPtr);
3845
4052
  return {
3846
4053
  pageIndex: page.index,
3847
4054
  id: index,
3848
4055
  blendMode,
3849
4056
  type: PdfAnnotationSubtype.STRIKEOUT,
4057
+ flags,
3850
4058
  rect,
3851
4059
  contents,
3852
4060
  segmentRects,
3853
- ...webAlphaColor,
4061
+ color: color ?? "#FF0000",
4062
+ opacity,
3854
4063
  author,
3855
4064
  modified
3856
4065
  };
@@ -3873,17 +4082,21 @@ class PdfiumEngine {
3873
4082
  const modified = pdfDateToDate(modifiedRaw);
3874
4083
  const segmentRects = this.getQuadPointsAnno(page, annotationPtr);
3875
4084
  const contents = this.getAnnotString(annotationPtr, "Contents") || "";
3876
- const webAlphaColor = this.resolveAnnotationColor(annotationPtr);
4085
+ const color = this.getAnnotationColor(annotationPtr);
4086
+ const opacity = this.getAnnotationOpacity(annotationPtr);
3877
4087
  const blendMode = this.pdfiumModule.EPDFAnnot_GetBlendMode(annotationPtr);
4088
+ const flags = this.getAnnotationFlags(annotationPtr);
3878
4089
  return {
3879
4090
  pageIndex: page.index,
3880
4091
  id: index,
3881
4092
  blendMode,
3882
4093
  type: PdfAnnotationSubtype.SQUIGGLY,
3883
4094
  rect,
4095
+ flags,
3884
4096
  contents,
3885
4097
  segmentRects,
3886
- ...webAlphaColor,
4098
+ color: color ?? "#FF0000",
4099
+ opacity,
3887
4100
  author,
3888
4101
  modified
3889
4102
  };
@@ -3904,11 +4117,13 @@ class PdfiumEngine {
3904
4117
  const author = this.getAnnotString(annotationPtr, "T");
3905
4118
  const modifiedRaw = this.getAnnotString(annotationPtr, "M");
3906
4119
  const modified = pdfDateToDate(modifiedRaw);
4120
+ const flags = this.getAnnotationFlags(annotationPtr);
3907
4121
  return {
3908
4122
  pageIndex: page.index,
3909
4123
  id: index,
3910
4124
  type: PdfAnnotationSubtype.CARET,
3911
4125
  rect,
4126
+ flags,
3912
4127
  author,
3913
4128
  modified
3914
4129
  };
@@ -3930,23 +4145,15 @@ class PdfiumEngine {
3930
4145
  const author = this.getAnnotString(annotationPtr, "T");
3931
4146
  const modifiedRaw = this.getAnnotString(annotationPtr, "M");
3932
4147
  const modified = pdfDateToDate(modifiedRaw);
3933
- const contents = [];
3934
- const objectCount = this.pdfiumModule.FPDFAnnot_GetObjectCount(annotationPtr);
3935
- for (let i = 0; i < objectCount; i++) {
3936
- const annotationObjectPtr = this.pdfiumModule.FPDFAnnot_GetObject(annotationPtr, i);
3937
- const pageObj = this.readPdfPageObject(annotationObjectPtr);
3938
- if (pageObj) {
3939
- contents.push(pageObj);
3940
- }
3941
- }
4148
+ const flags = this.getAnnotationFlags(annotationPtr);
3942
4149
  return {
3943
4150
  pageIndex: page.index,
3944
4151
  id: index,
3945
4152
  type: PdfAnnotationSubtype.STAMP,
3946
4153
  rect,
3947
- contents,
3948
4154
  author,
3949
- modified
4155
+ modified,
4156
+ flags
3950
4157
  };
3951
4158
  }
3952
4159
  /**
@@ -4113,6 +4320,25 @@ class PdfiumEngine {
4113
4320
  this.free(matrixPtr);
4114
4321
  return { a: 1, b: 0, c: 0, d: 1, e: 0, f: 0 };
4115
4322
  }
4323
+ /**
4324
+ * Read contents of a stamp annotation
4325
+ * @param annotationPtr - pointer to pdf annotation
4326
+ * @returns contents of the stamp annotation
4327
+ *
4328
+ * @private
4329
+ */
4330
+ readStampAnnotationContents(annotationPtr) {
4331
+ const contents = [];
4332
+ const objectCount = this.pdfiumModule.FPDFAnnot_GetObjectCount(annotationPtr);
4333
+ for (let i = 0; i < objectCount; i++) {
4334
+ const annotationObjectPtr = this.pdfiumModule.FPDFAnnot_GetObject(annotationPtr, i);
4335
+ const pageObj = this.readPdfPageObject(annotationObjectPtr);
4336
+ if (pageObj) {
4337
+ contents.push(pageObj);
4338
+ }
4339
+ }
4340
+ return contents;
4341
+ }
4116
4342
  /**
4117
4343
  * Return the stroke-width declared in the annotation’s /Border or /BS entry.
4118
4344
  * Falls back to 1 pt when nothing is defined.
@@ -4166,12 +4392,12 @@ class PdfiumEngine {
4166
4392
  const author = this.getAnnotString(annotationPtr, "T");
4167
4393
  const modifiedRaw = this.getAnnotString(annotationPtr, "M");
4168
4394
  const modified = pdfDateToDate(modifiedRaw);
4169
- const interiorColor = this.resolveAnnotationColor(
4395
+ const interiorColor = this.getAnnotationColor(
4170
4396
  annotationPtr,
4171
- PdfAnnotationColorType.InteriorColor,
4172
- void 0
4397
+ PdfAnnotationColorType.InteriorColor
4173
4398
  );
4174
- const { color: strokeColor, opacity: strokeOpacity } = this.resolveAnnotationColor(annotationPtr);
4399
+ const strokeColor = this.getAnnotationColor(annotationPtr);
4400
+ const opacity = this.getAnnotationOpacity(annotationPtr);
4175
4401
  let { style: strokeStyle, width: strokeWidth } = this.getBorderStyle(annotationPtr);
4176
4402
  let strokeDashArray;
4177
4403
  if (strokeStyle === PdfAnnotationBorderStyle.DASHED) {
@@ -4185,10 +4411,10 @@ class PdfiumEngine {
4185
4411
  id: index,
4186
4412
  type: PdfAnnotationSubtype.CIRCLE,
4187
4413
  flags,
4188
- color: (interiorColor == null ? void 0 : interiorColor.color) ?? "transparent",
4189
- opacity: (interiorColor == null ? void 0 : interiorColor.opacity) ?? strokeOpacity,
4414
+ color: interiorColor ?? "transparent",
4415
+ opacity,
4190
4416
  strokeWidth,
4191
- strokeColor,
4417
+ strokeColor: strokeColor ?? "#FF0000",
4192
4418
  strokeStyle,
4193
4419
  rect,
4194
4420
  author,
@@ -4213,12 +4439,12 @@ class PdfiumEngine {
4213
4439
  const author = this.getAnnotString(annotationPtr, "T");
4214
4440
  const modifiedRaw = this.getAnnotString(annotationPtr, "M");
4215
4441
  const modified = pdfDateToDate(modifiedRaw);
4216
- const interiorColor = this.resolveAnnotationColor(
4442
+ const interiorColor = this.getAnnotationColor(
4217
4443
  annotationPtr,
4218
- PdfAnnotationColorType.InteriorColor,
4219
- void 0
4444
+ PdfAnnotationColorType.InteriorColor
4220
4445
  );
4221
- const { color: strokeColor, opacity: strokeOpacity } = this.resolveAnnotationColor(annotationPtr);
4446
+ const strokeColor = this.getAnnotationColor(annotationPtr);
4447
+ const opacity = this.getAnnotationOpacity(annotationPtr);
4222
4448
  let { style: strokeStyle, width: strokeWidth } = this.getBorderStyle(annotationPtr);
4223
4449
  let strokeDashArray;
4224
4450
  if (strokeStyle === PdfAnnotationBorderStyle.DASHED) {
@@ -4232,9 +4458,9 @@ class PdfiumEngine {
4232
4458
  id: index,
4233
4459
  type: PdfAnnotationSubtype.SQUARE,
4234
4460
  flags,
4235
- color: (interiorColor == null ? void 0 : interiorColor.color) ?? "transparent",
4236
- opacity: (interiorColor == null ? void 0 : interiorColor.opacity) ?? strokeOpacity,
4237
- strokeColor,
4461
+ color: interiorColor ?? "transparent",
4462
+ opacity,
4463
+ strokeColor: strokeColor ?? "#FF0000",
4238
4464
  strokeWidth,
4239
4465
  strokeStyle,
4240
4466
  rect,
@@ -4260,9 +4486,11 @@ class PdfiumEngine {
4260
4486
  const author = this.getAnnotString(annotationPtr, "T");
4261
4487
  const modifiedRaw = this.getAnnotString(annotationPtr, "M");
4262
4488
  const modified = pdfDateToDate(modifiedRaw);
4489
+ const flags = this.getAnnotationFlags(annotationPtr);
4263
4490
  return {
4264
4491
  pageIndex: page.index,
4265
4492
  id: index,
4493
+ flags,
4266
4494
  type,
4267
4495
  rect,
4268
4496
  author,
@@ -5069,70 +5297,6 @@ class PdfiumEngine {
5069
5297
  this.free(bufferPtr);
5070
5298
  return ap;
5071
5299
  }
5072
- /**
5073
- * Change the visible colour (and opacity) of an existing annotation.
5074
- *
5075
- * For markup annotations (highlight / underline / strikeout / squiggly) we
5076
- * first clear the AP dictionary entry, otherwise the stored appearance stream
5077
- * will override the new tint. For all other sub-types we keep the existing
5078
- * AP so custom artwork isn't lost.
5079
- *
5080
- * @param doc logical document object
5081
- * @param page logical page object
5082
- * @param annotation the annotation we want to recolour
5083
- * @param colour RGBA tuple (0-255 per channel)
5084
- * @param which 0 = stroke/fill colour (PDFium's "colourType" param)
5085
- *
5086
- * @returns `true` when the operation succeeded
5087
- */
5088
- updateAnnotationColor(doc, page, annotation, color, which = 0) {
5089
- this.logger.debug(
5090
- LOG_SOURCE,
5091
- LOG_CATEGORY,
5092
- "setAnnotationColor",
5093
- doc,
5094
- page,
5095
- annotation,
5096
- color,
5097
- which
5098
- );
5099
- this.logger.perf(LOG_SOURCE, LOG_CATEGORY, "setAnnotationColor", "Begin", doc.id);
5100
- const task = PdfTaskHelper.create();
5101
- try {
5102
- const ctx = this.cache.getContext(doc.id);
5103
- if (!ctx) {
5104
- this.logger.perf(LOG_SOURCE, LOG_CATEGORY, "setAnnotationColor", "End", doc.id);
5105
- this.logger.warn(LOG_SOURCE, LOG_CATEGORY, "setAnnotationColor: doc closed");
5106
- task.resolve(false);
5107
- return task;
5108
- }
5109
- const pageCtx = ctx.acquirePage(page.index);
5110
- const annotPtr = this.pdfiumModule.FPDFPage_GetAnnot(pageCtx.pagePtr, annotation.id);
5111
- if (!annotPtr) {
5112
- this.logger.perf(LOG_SOURCE, LOG_CATEGORY, "setAnnotationColor", "End", doc.id);
5113
- this.logger.warn(LOG_SOURCE, LOG_CATEGORY, "setAnnotationColor: annot not found");
5114
- pageCtx.release();
5115
- task.resolve(false);
5116
- return task;
5117
- }
5118
- const ok = this.setAnnotationColor(annotPtr, color, which);
5119
- if (ok) {
5120
- this.pdfiumModule.FPDFPage_GenerateContent(pageCtx.pagePtr);
5121
- }
5122
- this.pdfiumModule.FPDFPage_CloseAnnot(annotPtr);
5123
- pageCtx.release();
5124
- this.logger.perf(LOG_SOURCE, LOG_CATEGORY, "setAnnotationColor", "End", doc.id);
5125
- task.resolve(!!ok);
5126
- } catch (error) {
5127
- this.logger.perf(LOG_SOURCE, LOG_CATEGORY, "setAnnotationColor", "End", doc.id);
5128
- this.logger.error(LOG_SOURCE, LOG_CATEGORY, "setAnnotationColor: error", error);
5129
- task.reject({
5130
- code: PdfErrorCode.Unknown,
5131
- message: `Failed to set annotation color: ${error instanceof Error ? error.message : String(error)}`
5132
- });
5133
- }
5134
- return task;
5135
- }
5136
5300
  /**
5137
5301
  * Set the rect of specified annotation
5138
5302
  * @param page - page info that the annotation is belonged to
@@ -5438,4 +5602,4 @@ export {
5438
5602
  readArrayBuffer as c,
5439
5603
  readString as r
5440
5604
  };
5441
- //# sourceMappingURL=engine-B0ZTENqz.js.map
5605
+ //# sourceMappingURL=engine-B11yoQGd.js.map