@embedpdf/engines 2.13.0 → 2.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  import { init } from "@embedpdf/pdfium";
2
- import { Rotation, NoopLogger, PdfTaskHelper, PdfErrorCode, pdfDateToDate, PdfJavaScriptActionTrigger, PdfAnnotationSubtype, isUuidV4, uuidV4, PdfJavaScriptWidgetEventType, PDF_ANNOT_AACTION_EVENT, PDF_FORM_FIELD_TYPE, PdfPageFlattenFlag, stripPdfUnwantedMarkers, PdfAnnotationName, PdfAnnotationColorType, PdfAnnotationBorderStyle, PdfStandardFont, PDF_FORM_FIELD_FLAG, webColorToPdfColor, pdfColorToWebColor, PdfAnnotationLineEnding, getImageMetadata, PdfStampFit, PdfTrappedStatus, pdfAlphaToWebOpacity, webOpacityToPdfAlpha, PdfAnnotationReplyType, dateToPdfDate, quadToRect, rectToQuad, PdfPageObjectType, flagsToNames, namesToFlags, AppearanceMode, Task, toIntRect, transformRect, buildUserToDeviceMatrix, AP_MODE_NORMAL, AP_MODE_ROLLOVER, AP_MODE_DOWN, PdfZoomMode, PdfActionType } from "@embedpdf/models";
2
+ import { Rotation, NoopLogger, PdfTaskHelper, PdfErrorCode, pdfDateToDate, PdfJavaScriptActionTrigger, PdfAnnotationSubtype, isUuidV4, uuidV4, PdfJavaScriptWidgetEventType, PDF_ANNOT_AACTION_EVENT, PDF_FORM_FIELD_TYPE, PdfPageFlattenFlag, stripPdfUnwantedMarkers, PdfAnnotationName, PdfAnnotationColorType, PdfAnnotationBorderStyle, PdfStandardFont, PdfAnnotationLineEnding, PDF_FORM_FIELD_FLAG, webColorToPdfColor, pdfColorToWebColor, getImageMetadata, PdfStampFit, PdfTrappedStatus, pdfAlphaToWebOpacity, webOpacityToPdfAlpha, PdfAnnotationReplyType, dateToPdfDate, quadToRect, rectToQuad, PdfPageObjectType, flagsToNames, namesToFlags, AppearanceMode, Task, toIntRect, transformRect, buildUserToDeviceMatrix, AP_MODE_NORMAL, AP_MODE_ROLLOVER, AP_MODE_DOWN, PdfZoomMode, PdfActionType } from "@embedpdf/models";
3
3
  import { P as PdfEngine } from "./pdf-engine-D9v0RfKe.js";
4
4
  import { b as browserImageDataToBlobConverter } from "./browser-BKLM0ThC.js";
5
5
  function readString(wasmModule, readChars, parseChars, defaultLength = 100) {
@@ -3562,7 +3562,11 @@ class PdfiumNative {
3562
3562
  * @private
3563
3563
  */
3564
3564
  addFreeTextContent(doc, page, pagePtr, annotationPtr, annotation) {
3565
- if (!this.setBorderStyle(annotationPtr, PdfAnnotationBorderStyle.SOLID, 0)) {
3565
+ if (!this.setBorderStyle(
3566
+ annotationPtr,
3567
+ PdfAnnotationBorderStyle.SOLID,
3568
+ annotation.strokeWidth ?? 0
3569
+ )) {
3566
3570
  return false;
3567
3571
  }
3568
3572
  if (!this.setAnnotationOpacity(annotationPtr, annotation.opacity ?? 1)) {
@@ -3574,17 +3578,31 @@ class PdfiumNative {
3574
3578
  if (!this.setAnnotationVerticalAlignment(annotationPtr, annotation.verticalAlign)) {
3575
3579
  return false;
3576
3580
  }
3581
+ const daColor = annotation.strokeColor ?? annotation.fontColor;
3577
3582
  if (!this.setAnnotationDefaultAppearance(
3578
3583
  annotationPtr,
3579
3584
  annotation.fontFamily === PdfStandardFont.Unknown ? PdfStandardFont.Helvetica : annotation.fontFamily,
3580
3585
  annotation.fontSize,
3581
- annotation.fontColor
3586
+ daColor
3582
3587
  )) {
3583
3588
  return false;
3584
3589
  }
3590
+ if (annotation.strokeColor && annotation.strokeColor !== annotation.fontColor) {
3591
+ this.setAnnotationColor(
3592
+ annotationPtr,
3593
+ annotation.fontColor,
3594
+ PdfAnnotationColorType.TextColor
3595
+ );
3596
+ }
3585
3597
  if (annotation.intent && !this.setAnnotIntent(annotationPtr, annotation.intent)) {
3586
3598
  return false;
3587
3599
  }
3600
+ if (annotation.calloutLine && annotation.calloutLine.length >= 2 && !this.setCalloutLine(doc, page, annotationPtr, annotation.calloutLine)) {
3601
+ return false;
3602
+ }
3603
+ if (annotation.lineEnding !== void 0 && !this.setLineEndings(annotationPtr, PdfAnnotationLineEnding.None, annotation.lineEnding)) {
3604
+ return false;
3605
+ }
3588
3606
  const bgColor = annotation.color ?? annotation.backgroundColor;
3589
3607
  if (!bgColor || bgColor === "transparent") {
3590
3608
  if (!this.pdfiumModule.EPDFAnnot_ClearColor(annotationPtr, PdfAnnotationColorType.Color)) {
@@ -6021,28 +6039,31 @@ class PdfiumNative {
6021
6039
  * @returns `{ ok, left, top, right, bottom }`
6022
6040
  * • `ok` – `true` when the annotation *has* an /RD entry
6023
6041
  * • the four floats are 0 when `ok` is false
6042
+ *
6043
+ * Native PDFium exposes /RD as [left, bottom, right, top]. We remap it here
6044
+ * to the model's stable { left, top, right, bottom } shape.
6024
6045
  */
6025
6046
  getRectangleDifferences(annotationPtr) {
6026
6047
  const lPtr = this.memoryManager.malloc(4);
6027
- const tPtr = this.memoryManager.malloc(4);
6028
- const rPtr = this.memoryManager.malloc(4);
6029
6048
  const bPtr = this.memoryManager.malloc(4);
6049
+ const rPtr = this.memoryManager.malloc(4);
6050
+ const tPtr = this.memoryManager.malloc(4);
6030
6051
  const ok = !!this.pdfiumModule.EPDFAnnot_GetRectangleDifferences(
6031
6052
  annotationPtr,
6032
6053
  lPtr,
6033
- tPtr,
6054
+ bPtr,
6034
6055
  rPtr,
6035
- bPtr
6056
+ tPtr
6036
6057
  );
6037
6058
  const pdf = this.pdfiumModule.pdfium;
6038
6059
  const left = pdf.getValue(lPtr, "float");
6039
- const top = pdf.getValue(tPtr, "float");
6040
- const right = pdf.getValue(rPtr, "float");
6041
6060
  const bottom = pdf.getValue(bPtr, "float");
6061
+ const right = pdf.getValue(rPtr, "float");
6062
+ const top = pdf.getValue(tPtr, "float");
6042
6063
  this.memoryManager.free(lPtr);
6043
- this.memoryManager.free(tPtr);
6044
- this.memoryManager.free(rPtr);
6045
6064
  this.memoryManager.free(bPtr);
6065
+ this.memoryManager.free(rPtr);
6066
+ this.memoryManager.free(tPtr);
6046
6067
  return { ok, left, top, right, bottom };
6047
6068
  }
6048
6069
  /**
@@ -6059,9 +6080,9 @@ class PdfiumNative {
6059
6080
  return this.pdfiumModule.EPDFAnnot_SetRectangleDifferences(
6060
6081
  annotationPtr,
6061
6082
  rd.left,
6062
- rd.top,
6083
+ rd.bottom,
6063
6084
  rd.right,
6064
- rd.bottom
6085
+ rd.top
6065
6086
  );
6066
6087
  }
6067
6088
  /**
@@ -6816,11 +6837,16 @@ class PdfiumNative {
6816
6837
  const defaultStyle = this.getAnnotString(annotationPtr, "DS");
6817
6838
  const da = this.getAnnotationDefaultAppearance(annotationPtr);
6818
6839
  const bgColor = this.getAnnotationColor(annotationPtr);
6840
+ const textColor = this.getAnnotationColor(annotationPtr, PdfAnnotationColorType.TextColor);
6841
+ const borderStyle = this.getBorderStyle(annotationPtr);
6819
6842
  const textAlign = this.getAnnotationTextAlignment(annotationPtr);
6820
6843
  const verticalAlign = this.getAnnotationVerticalAlignment(annotationPtr);
6821
6844
  const opacity = this.getAnnotationOpacity(annotationPtr);
6822
6845
  const richContent = this.getAnnotRichContent(annotationPtr);
6823
6846
  const rd = this.getRectangleDifferences(annotationPtr);
6847
+ const intent = this.getAnnotIntent(annotationPtr);
6848
+ const calloutLine = this.getCalloutLine(doc, page, annotationPtr);
6849
+ const lineEndings = this.getLineEndings(annotationPtr);
6824
6850
  return {
6825
6851
  pageIndex: page.index,
6826
6852
  id: index,
@@ -6828,12 +6854,10 @@ class PdfiumNative {
6828
6854
  rect,
6829
6855
  fontFamily: (da == null ? void 0 : da.fontFamily) ?? PdfStandardFont.Unknown,
6830
6856
  fontSize: (da == null ? void 0 : da.fontSize) ?? 12,
6831
- fontColor: (da == null ? void 0 : da.fontColor) ?? "#000000",
6857
+ fontColor: textColor ?? (da == null ? void 0 : da.fontColor) ?? "#000000",
6832
6858
  verticalAlign,
6833
6859
  color: bgColor,
6834
- // fill color (matches shape convention)
6835
6860
  backgroundColor: bgColor,
6836
- // deprecated alias
6837
6861
  opacity,
6838
6862
  textAlign,
6839
6863
  defaultStyle,
@@ -6846,6 +6870,10 @@ class PdfiumNative {
6846
6870
  bottom: rd.bottom
6847
6871
  }
6848
6872
  },
6873
+ ...intent && { intent },
6874
+ ...calloutLine && { calloutLine },
6875
+ ...lineEndings && { lineEnding: lineEndings.end },
6876
+ ...borderStyle.width > 0 ? { strokeWidth: borderStyle.width, strokeColor: (da == null ? void 0 : da.fontColor) ?? "#000000" } : intent === "FreeTextCallout" ? { strokeWidth: 1, strokeColor: (da == null ? void 0 : da.fontColor) ?? "#000000" } : {},
6849
6877
  ...this.readBaseAnnotationProperties(doc, page, annotationPtr)
6850
6878
  };
6851
6879
  }
@@ -8161,6 +8189,52 @@ class PdfiumNative {
8161
8189
  this.memoryManager.free(buf);
8162
8190
  return ok;
8163
8191
  }
8192
+ /**
8193
+ * Read the callout line points (/CL) from a FreeText annotation.
8194
+ * Returns an array of 2 or 3 Position points in device coords, or undefined.
8195
+ *
8196
+ * @private
8197
+ */
8198
+ getCalloutLine(doc, page, annotationPtr) {
8199
+ const count = this.pdfiumModule.EPDFAnnot_GetCalloutLineCount(annotationPtr);
8200
+ if (count === 0) {
8201
+ return void 0;
8202
+ }
8203
+ const FS_POINTF_SIZE = 8;
8204
+ const pointsPtr = this.memoryManager.malloc(count * FS_POINTF_SIZE);
8205
+ const result = this.pdfiumModule.EPDFAnnot_GetCalloutLine(annotationPtr, pointsPtr, count);
8206
+ if (result === 0) {
8207
+ this.memoryManager.free(pointsPtr);
8208
+ return void 0;
8209
+ }
8210
+ const points = [];
8211
+ for (let i = 0; i < count; i++) {
8212
+ const px = this.pdfiumModule.pdfium.getValue(pointsPtr + i * FS_POINTF_SIZE, "float");
8213
+ const py = this.pdfiumModule.pdfium.getValue(pointsPtr + i * FS_POINTF_SIZE + 4, "float");
8214
+ points.push(this.convertPagePointToDevicePoint(doc, page, { x: px, y: py }));
8215
+ }
8216
+ this.memoryManager.free(pointsPtr);
8217
+ return points;
8218
+ }
8219
+ /**
8220
+ * Set the callout line points (/CL) on a FreeText annotation.
8221
+ * Converts from device coords to page coords before writing.
8222
+ *
8223
+ * @private
8224
+ */
8225
+ setCalloutLine(doc, page, annotPtr, points) {
8226
+ const pdf = this.pdfiumModule.pdfium;
8227
+ const FS_POINTF_SIZE = 8;
8228
+ const buf = this.memoryManager.malloc(FS_POINTF_SIZE * points.length);
8229
+ points.forEach((v, i) => {
8230
+ const pagePt = this.convertDevicePointToPagePoint(doc, page, v);
8231
+ pdf.setValue(buf + i * FS_POINTF_SIZE + 0, pagePt.x, "float");
8232
+ pdf.setValue(buf + i * FS_POINTF_SIZE + 4, pagePt.y, "float");
8233
+ });
8234
+ const ok = this.pdfiumModule.EPDFAnnot_SetCalloutLine(annotPtr, buf, points.length);
8235
+ this.memoryManager.free(buf);
8236
+ return ok;
8237
+ }
8164
8238
  /**
8165
8239
  * Read the target of pdf bookmark
8166
8240
  * @param docPtr - pointer to pdf document object
@@ -9832,4 +9906,4 @@ export {
9832
9906
  isValidCustomKey as i,
9833
9907
  readArrayBuffer as r
9834
9908
  };
9835
- //# sourceMappingURL=direct-engine-B7gUkBcT.js.map
9909
+ //# sourceMappingURL=direct-engine-DX7D1euc.js.map