@embedpdf/engines 1.4.1 → 1.5.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,4 +1,4 @@
1
- import { NoopLogger, PdfTaskHelper, PdfErrorCode, pdfDateToDate, ignore, isUuidV4, uuidV4, PdfAnnotationSubtype, PdfPageFlattenFlag, stripPdfUnwantedMarkers, PdfAnnotationIcon, PdfAnnotationBorderStyle, PdfAnnotationColorType, PdfAnnotationLineEnding, PdfStampFit, PdfTrappedStatus, pdfColorToWebColor, webColorToPdfColor, pdfAlphaToWebOpacity, webOpacityToPdfAlpha, dateToPdfDate, quadToRect, rectToQuad, PdfStandardFont, PdfPageObjectType, flagsToNames, namesToFlags, PDF_FORM_FIELD_TYPE, Rotation, AppearanceMode, Task, toIntRect, transformRect, buildUserToDeviceMatrix, PdfZoomMode, PdfActionType, MatchFlag } from "@embedpdf/models";
1
+ import { Rotation, NoopLogger, PdfTaskHelper, PdfErrorCode, pdfDateToDate, ignore, isUuidV4, uuidV4, PdfAnnotationSubtype, PdfPageFlattenFlag, stripPdfUnwantedMarkers, PdfAnnotationIcon, PdfAnnotationBorderStyle, PdfAnnotationColorType, PdfAnnotationLineEnding, PdfStampFit, PdfTrappedStatus, pdfColorToWebColor, webColorToPdfColor, pdfAlphaToWebOpacity, webOpacityToPdfAlpha, dateToPdfDate, quadToRect, rectToQuad, PdfStandardFont, PdfPageObjectType, flagsToNames, namesToFlags, PDF_FORM_FIELD_TYPE, AppearanceMode, Task, toIntRect, transformRect, buildUserToDeviceMatrix, PdfZoomMode, PdfActionType, MatchFlag } 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++) {
@@ -53,6 +53,44 @@ function isValidCustomKey(key) {
53
53
  }
54
54
  return true;
55
55
  }
56
+ function computeFormDrawParams(matrix, rect, pageSize, rotation) {
57
+ const rectLeft = rect.origin.x;
58
+ const rectBottom = rect.origin.y;
59
+ const rectRight = rectLeft + rect.size.width;
60
+ const rectTop = rectBottom + rect.size.height;
61
+ const pageWidth = pageSize.width;
62
+ const pageHeight = pageSize.height;
63
+ const scaleX = Math.hypot(matrix.a, matrix.b);
64
+ const scaleY = Math.hypot(matrix.c, matrix.d);
65
+ const swap = (rotation & 1) === 1;
66
+ const formsWidth = swap ? Math.max(1, Math.round(pageHeight * scaleX)) : Math.max(1, Math.round(pageWidth * scaleX));
67
+ const formsHeight = swap ? Math.max(1, Math.round(pageWidth * scaleY)) : Math.max(1, Math.round(pageHeight * scaleY));
68
+ let startX;
69
+ let startY;
70
+ switch (rotation) {
71
+ case Rotation.Degree0:
72
+ startX = -Math.round(rectLeft * scaleX);
73
+ startY = -Math.round(rectBottom * scaleY);
74
+ break;
75
+ case Rotation.Degree90:
76
+ startX = Math.round((rectTop - pageHeight) * scaleX);
77
+ startY = -Math.round(rectLeft * scaleY);
78
+ break;
79
+ case Rotation.Degree180:
80
+ startX = Math.round((rectRight - pageWidth) * scaleX);
81
+ startY = Math.round((rectTop - pageHeight) * scaleY);
82
+ break;
83
+ case Rotation.Degree270:
84
+ startX = -Math.round(rectBottom * scaleX);
85
+ startY = Math.round((rectRight - pageWidth) * scaleY);
86
+ break;
87
+ default:
88
+ startX = -Math.round(rectLeft * scaleX);
89
+ startY = -Math.round(rectBottom * scaleY);
90
+ break;
91
+ }
92
+ return { startX, startY, formsWidth, formsHeight, scaleX, scaleY };
93
+ }
56
94
  const DEFAULT_CONFIG = {
57
95
  pageTtl: 5e3,
58
96
  // 5 seconds
@@ -5951,6 +5989,8 @@ class PdfiumEngine {
5951
5989
  const stride = wDev * 4;
5952
5990
  const bytes = stride * hDev;
5953
5991
  const pageCtx = ctx.acquirePage(page.index);
5992
+ const shouldRenderForms = (options == null ? void 0 : options.withForms) ?? false;
5993
+ const formHandle = shouldRenderForms ? pageCtx.getFormHandle() : void 0;
5954
5994
  const heapPtr = this.memoryManager.malloc(bytes);
5955
5995
  const bitmapPtr = this.pdfiumModule.FPDFBitmap_CreateEx(
5956
5996
  wDev,
@@ -5977,6 +6017,21 @@ class PdfiumEngine {
5977
6017
  clipPtr,
5978
6018
  flags
5979
6019
  );
6020
+ if (formHandle !== void 0) {
6021
+ const formParams = computeFormDrawParams(M, rect, page.size, rotation);
6022
+ const { startX, startY, formsWidth, formsHeight, scaleX, scaleY } = formParams;
6023
+ this.pdfiumModule.FPDF_FFLDraw(
6024
+ formHandle,
6025
+ bitmapPtr,
6026
+ pageCtx.pagePtr,
6027
+ startX,
6028
+ startY,
6029
+ formsWidth,
6030
+ formsHeight,
6031
+ rotation,
6032
+ flags
6033
+ );
6034
+ }
5980
6035
  } finally {
5981
6036
  pageCtx.release();
5982
6037
  this.memoryManager.free(mPtr);
@@ -7017,7 +7072,8 @@ export {
7017
7072
  PdfiumEngine as a,
7018
7073
  browserImageDataToBlobConverter as b,
7019
7074
  readArrayBuffer as c,
7075
+ computeFormDrawParams as d,
7020
7076
  isValidCustomKey as i,
7021
7077
  readString as r
7022
7078
  };
7023
- //# sourceMappingURL=engine-N_GwaBxA.js.map
7079
+ //# sourceMappingURL=engine-LzpGkzoU.js.map