@embedpdf/engines 2.6.0 → 2.6.1

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 (43) hide show
  1. package/dist/direct-engine-BaKyNZkO.cjs +2 -0
  2. package/dist/direct-engine-BaKyNZkO.cjs.map +1 -0
  3. package/dist/{direct-engine-CvfzIn2D.js → direct-engine-BmntIHbH.js} +181 -3
  4. package/dist/direct-engine-BmntIHbH.js.map +1 -0
  5. package/dist/index.cjs +1 -1
  6. package/dist/index.cjs.map +1 -1
  7. package/dist/index.js +11 -2
  8. package/dist/index.js.map +1 -1
  9. package/dist/lib/orchestrator/pdf-engine.d.ts +4 -1
  10. package/dist/lib/orchestrator/remote-executor.d.ts +2 -1
  11. package/dist/lib/pdfium/engine.d.ts +13 -1
  12. package/dist/lib/pdfium/index.cjs +1 -1
  13. package/dist/lib/pdfium/index.js +3 -3
  14. package/dist/lib/pdfium/web/direct-engine.cjs +1 -1
  15. package/dist/lib/pdfium/web/direct-engine.js +2 -2
  16. package/dist/lib/pdfium/web/worker-engine.cjs +1 -1
  17. package/dist/lib/pdfium/web/worker-engine.cjs.map +1 -1
  18. package/dist/lib/pdfium/web/worker-engine.js +5 -2
  19. package/dist/lib/pdfium/web/worker-engine.js.map +1 -1
  20. package/dist/lib/webworker/engine.cjs +1 -1
  21. package/dist/lib/webworker/engine.cjs.map +1 -1
  22. package/dist/lib/webworker/engine.d.ts +19 -1
  23. package/dist/lib/webworker/engine.js +44 -0
  24. package/dist/lib/webworker/engine.js.map +1 -1
  25. package/dist/{pdf-engine-aJNoNMbt.js → pdf-engine-C07l7iNd.js} +29 -1
  26. package/dist/pdf-engine-C07l7iNd.js.map +1 -0
  27. package/dist/pdf-engine-DUjCt3HC.cjs +2 -0
  28. package/dist/pdf-engine-DUjCt3HC.cjs.map +1 -0
  29. package/dist/preact/index.cjs +1 -1
  30. package/dist/preact/index.js +1 -1
  31. package/dist/react/index.cjs +1 -1
  32. package/dist/react/index.js +1 -1
  33. package/dist/svelte/index.cjs +1 -1
  34. package/dist/svelte/index.js +1 -1
  35. package/dist/vue/index.cjs +1 -1
  36. package/dist/vue/index.js +1 -1
  37. package/package.json +6 -6
  38. package/dist/direct-engine-CvfzIn2D.js.map +0 -1
  39. package/dist/direct-engine-DITdlET4.cjs +0 -2
  40. package/dist/direct-engine-DITdlET4.cjs.map +0 -1
  41. package/dist/pdf-engine-BmrecQLq.cjs +0 -2
  42. package/dist/pdf-engine-BmrecQLq.cjs.map +0 -1
  43. package/dist/pdf-engine-aJNoNMbt.js.map +0 -1
@@ -1,6 +1,6 @@
1
1
  import { init } from "@embedpdf/pdfium";
2
2
  import { Rotation, NoopLogger, PdfTaskHelper, PdfErrorCode, pdfDateToDate, isUuidV4, uuidV4, PdfAnnotationSubtype, PdfPageFlattenFlag, stripPdfUnwantedMarkers, PdfAnnotationIcon, PdfAnnotationBorderStyle, PdfAnnotationColorType, PdfAnnotationLineEnding, PdfStandardFont, PdfStampFit, PdfTrappedStatus, pdfColorToWebColor, webColorToPdfColor, pdfAlphaToWebOpacity, webOpacityToPdfAlpha, PdfAnnotationReplyType, dateToPdfDate, quadToRect, rectToQuad, PdfPageObjectType, flagsToNames, namesToFlags, PDF_FORM_FIELD_TYPE, AppearanceMode, Task, toIntRect, transformRect, buildUserToDeviceMatrix, PdfZoomMode, PdfActionType } from "@embedpdf/models";
3
- import { P as PdfEngine } from "./pdf-engine-aJNoNMbt.js";
3
+ import { P as PdfEngine } from "./pdf-engine-C07l7iNd.js";
4
4
  import { b as browserImageDataToBlobConverter } from "./browser-BISJ9naB.js";
5
5
  function readString(wasmModule, readChars, parseChars, defaultLength = 100) {
6
6
  let buffer = wasmModule.wasmExports.malloc(defaultLength);
@@ -3765,6 +3765,184 @@ class PdfiumNative {
3765
3765
  }
3766
3766
  return runs;
3767
3767
  }
3768
+ /**
3769
+ * Rich text runs: groups consecutive characters sharing the same
3770
+ * text object, font, size, and fill color into structured segments
3771
+ * with full font metadata and bounding boxes in PDF page coordinates.
3772
+ *
3773
+ * @public
3774
+ */
3775
+ getPageTextRuns(doc, page) {
3776
+ const label = "getPageTextRuns";
3777
+ this.logger.perf(LOG_SOURCE, LOG_CATEGORY, label, "Begin", doc.id);
3778
+ const ctx = this.cache.getContext(doc.id);
3779
+ if (!ctx) {
3780
+ this.logger.perf(LOG_SOURCE, LOG_CATEGORY, label, "End", doc.id);
3781
+ return PdfTaskHelper.reject({
3782
+ code: PdfErrorCode.DocNotOpen,
3783
+ message: "document does not open"
3784
+ });
3785
+ }
3786
+ const pageCtx = ctx.acquirePage(page.index);
3787
+ const textPagePtr = pageCtx.getTextPage();
3788
+ const charCount = this.pdfiumModule.FPDFText_CountChars(textPagePtr);
3789
+ const runs = [];
3790
+ let runStart = 0;
3791
+ let curObjPtr = null;
3792
+ let curFont = null;
3793
+ let curFontSize = 0;
3794
+ let curColor = null;
3795
+ let bounds = null;
3796
+ const flushRun = (end) => {
3797
+ if (curObjPtr === null || curFont === null || curColor === null || bounds === null) return;
3798
+ const count = end - runStart;
3799
+ if (count <= 0) return;
3800
+ const bufPtr = this.memoryManager.malloc(2 * (count + 1));
3801
+ this.pdfiumModule.FPDFText_GetText(textPagePtr, runStart, count, bufPtr);
3802
+ const text = stripPdfUnwantedMarkers(this.pdfiumModule.pdfium.UTF16ToString(bufPtr));
3803
+ this.memoryManager.free(bufPtr);
3804
+ runs.push({
3805
+ text,
3806
+ rect: {
3807
+ origin: { x: bounds.minX, y: bounds.minY },
3808
+ size: {
3809
+ width: Math.max(1, bounds.maxX - bounds.minX),
3810
+ height: Math.max(1, bounds.maxY - bounds.minY)
3811
+ }
3812
+ },
3813
+ font: curFont,
3814
+ fontSize: curFontSize,
3815
+ color: curColor,
3816
+ charIndex: runStart,
3817
+ charCount: count
3818
+ });
3819
+ };
3820
+ const rPtr = this.memoryManager.malloc(4);
3821
+ const gPtr = this.memoryManager.malloc(4);
3822
+ const bPtr = this.memoryManager.malloc(4);
3823
+ const aPtr = this.memoryManager.malloc(4);
3824
+ const rectPtr = this.memoryManager.malloc(16);
3825
+ const dx1Ptr = this.memoryManager.malloc(4);
3826
+ const dy1Ptr = this.memoryManager.malloc(4);
3827
+ const dx2Ptr = this.memoryManager.malloc(4);
3828
+ const dy2Ptr = this.memoryManager.malloc(4);
3829
+ const italicAnglePtr = this.memoryManager.malloc(4);
3830
+ for (let i = 0; i < charCount; i++) {
3831
+ const uc = this.pdfiumModule.FPDFText_GetUnicode(textPagePtr, i);
3832
+ if (uc === 65534 || uc === 65533) continue;
3833
+ const objPtr = this.pdfiumModule.FPDFText_GetTextObject(textPagePtr, i);
3834
+ if (objPtr === 0) continue;
3835
+ const fontSize = this.pdfiumModule.FPDFText_GetFontSize(textPagePtr, i);
3836
+ this.pdfiumModule.FPDFText_GetFillColor(textPagePtr, i, rPtr, gPtr, bPtr, aPtr);
3837
+ const red = this.pdfiumModule.pdfium.getValue(rPtr, "i32") & 255;
3838
+ const green = this.pdfiumModule.pdfium.getValue(gPtr, "i32") & 255;
3839
+ const blue = this.pdfiumModule.pdfium.getValue(bPtr, "i32") & 255;
3840
+ const alpha = this.pdfiumModule.pdfium.getValue(aPtr, "i32") & 255;
3841
+ const fontInfo = this.readFontInfoFromTextObject(objPtr, italicAnglePtr);
3842
+ const needNewRun = curObjPtr === null || objPtr !== curObjPtr || fontInfo.name !== curFont.name || Math.abs(fontSize - curFontSize) > 0.01 || red !== curColor.red || green !== curColor.green || blue !== curColor.blue;
3843
+ if (needNewRun) {
3844
+ flushRun(i);
3845
+ curObjPtr = objPtr;
3846
+ curFont = fontInfo;
3847
+ curFontSize = fontSize;
3848
+ curColor = { red, green, blue, alpha };
3849
+ runStart = i;
3850
+ bounds = null;
3851
+ }
3852
+ if (this.pdfiumModule.FPDFText_GetLooseCharBox(textPagePtr, i, rectPtr)) {
3853
+ const left = this.pdfiumModule.pdfium.getValue(rectPtr, "float");
3854
+ const top = this.pdfiumModule.pdfium.getValue(rectPtr + 4, "float");
3855
+ const right = this.pdfiumModule.pdfium.getValue(rectPtr + 8, "float");
3856
+ const bottom = this.pdfiumModule.pdfium.getValue(rectPtr + 12, "float");
3857
+ if (left !== right && top !== bottom) {
3858
+ this.pdfiumModule.FPDF_PageToDevice(
3859
+ pageCtx.pagePtr,
3860
+ 0,
3861
+ 0,
3862
+ page.size.width,
3863
+ page.size.height,
3864
+ 0,
3865
+ left,
3866
+ top,
3867
+ dx1Ptr,
3868
+ dy1Ptr
3869
+ );
3870
+ this.pdfiumModule.FPDF_PageToDevice(
3871
+ pageCtx.pagePtr,
3872
+ 0,
3873
+ 0,
3874
+ page.size.width,
3875
+ page.size.height,
3876
+ 0,
3877
+ right,
3878
+ bottom,
3879
+ dx2Ptr,
3880
+ dy2Ptr
3881
+ );
3882
+ const x1 = this.pdfiumModule.pdfium.getValue(dx1Ptr, "i32");
3883
+ const y1 = this.pdfiumModule.pdfium.getValue(dy1Ptr, "i32");
3884
+ const x2 = this.pdfiumModule.pdfium.getValue(dx2Ptr, "i32");
3885
+ const y2 = this.pdfiumModule.pdfium.getValue(dy2Ptr, "i32");
3886
+ const cx = Math.min(x1, x2);
3887
+ const cy = Math.min(y1, y2);
3888
+ const cw = Math.abs(x2 - x1);
3889
+ const ch = Math.abs(y2 - y1);
3890
+ if (bounds === null) {
3891
+ bounds = { minX: cx, minY: cy, maxX: cx + cw, maxY: cy + ch };
3892
+ } else {
3893
+ bounds.minX = Math.min(bounds.minX, cx);
3894
+ bounds.minY = Math.min(bounds.minY, cy);
3895
+ bounds.maxX = Math.max(bounds.maxX, cx + cw);
3896
+ bounds.maxY = Math.max(bounds.maxY, cy + ch);
3897
+ }
3898
+ }
3899
+ }
3900
+ }
3901
+ flushRun(charCount);
3902
+ [rPtr, gPtr, bPtr, aPtr, rectPtr, dx1Ptr, dy1Ptr, dx2Ptr, dy2Ptr, italicAnglePtr].forEach(
3903
+ (p) => this.memoryManager.free(p)
3904
+ );
3905
+ pageCtx.release();
3906
+ this.logger.perf(LOG_SOURCE, LOG_CATEGORY, label, "End", doc.id);
3907
+ return PdfTaskHelper.resolve({ runs });
3908
+ }
3909
+ /**
3910
+ * Read font metadata from a text object handle via FPDFFont_* APIs.
3911
+ */
3912
+ readFontInfoFromTextObject(textObjPtr, italicAnglePtr) {
3913
+ const fontPtr = this.pdfiumModule.FPDFTextObj_GetFont(textObjPtr);
3914
+ let name = "";
3915
+ let familyName = "";
3916
+ let weight = 400;
3917
+ let italic = false;
3918
+ let monospaced = false;
3919
+ let embedded = false;
3920
+ if (fontPtr) {
3921
+ const nameLen = this.pdfiumModule.FPDFFont_GetBaseFontName(fontPtr, 0, 0);
3922
+ if (nameLen > 0) {
3923
+ const nameBuf = this.memoryManager.malloc(nameLen + 1);
3924
+ this.pdfiumModule.FPDFFont_GetBaseFontName(fontPtr, nameBuf, nameLen + 1);
3925
+ name = this.pdfiumModule.pdfium.UTF8ToString(nameBuf);
3926
+ this.memoryManager.free(nameBuf);
3927
+ }
3928
+ const famLen = this.pdfiumModule.FPDFFont_GetFamilyName(fontPtr, 0, 0);
3929
+ if (famLen > 0) {
3930
+ const famBuf = this.memoryManager.malloc(famLen + 1);
3931
+ this.pdfiumModule.FPDFFont_GetFamilyName(fontPtr, famBuf, famLen + 1);
3932
+ familyName = this.pdfiumModule.pdfium.UTF8ToString(famBuf);
3933
+ this.memoryManager.free(famBuf);
3934
+ }
3935
+ weight = this.pdfiumModule.FPDFFont_GetWeight(fontPtr);
3936
+ embedded = this.pdfiumModule.FPDFFont_GetIsEmbedded(fontPtr) !== 0;
3937
+ if (this.pdfiumModule.FPDFFont_GetItalicAngle(fontPtr, italicAnglePtr)) {
3938
+ const angle = this.pdfiumModule.pdfium.getValue(italicAnglePtr, "i32");
3939
+ italic = angle !== 0;
3940
+ }
3941
+ const flags = this.pdfiumModule.FPDFFont_GetFlags(fontPtr);
3942
+ monospaced = (flags & 1) !== 0;
3943
+ }
3944
+ return { name, familyName, weight, italic, monospaced, embedded };
3945
+ }
3768
3946
  /**
3769
3947
  * Extract glyph geometry + metadata for `charIndex`
3770
3948
  *
@@ -7488,7 +7666,7 @@ class PdfiumNative {
7488
7666
  right: 0,
7489
7667
  bottom: 0
7490
7668
  };
7491
- if (this.pdfiumModule.FPDFAnnot_GetRect(annotationPtr, pageRectPtr)) {
7669
+ if (this.pdfiumModule.EPDFAnnot_GetRect(annotationPtr, pageRectPtr)) {
7492
7670
  pageRect.left = this.pdfiumModule.pdfium.getValue(pageRectPtr, "float");
7493
7671
  pageRect.top = this.pdfiumModule.pdfium.getValue(pageRectPtr + 4, "float");
7494
7672
  pageRect.right = this.pdfiumModule.pdfium.getValue(pageRectPtr + 8, "float");
@@ -8020,4 +8198,4 @@ export {
8020
8198
  isValidCustomKey as i,
8021
8199
  readArrayBuffer as r
8022
8200
  };
8023
- //# sourceMappingURL=direct-engine-CvfzIn2D.js.map
8201
+ //# sourceMappingURL=direct-engine-BmntIHbH.js.map