@embedpdf/engines 1.3.3 → 1.3.5
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.
- package/dist/{engine-B2N46cyz.js → engine-N_GwaBxA.js} +74 -79
- package/dist/engine-N_GwaBxA.js.map +1 -0
- package/dist/engine-Z4iXwySK.cjs +2 -0
- package/dist/engine-Z4iXwySK.cjs.map +1 -0
- package/dist/{index-D_lC16Zk.js → index-BBm1qwuu.js} +3 -3
- package/dist/{index-D_lC16Zk.js.map → index-BBm1qwuu.js.map} +1 -1
- package/dist/{index-CEwZ7c1k.cjs → index-eFYRRCNt.cjs} +2 -2
- package/dist/{index-CEwZ7c1k.cjs.map → index-eFYRRCNt.cjs.map} +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +2 -2
- package/dist/lib/pdfium/engine.d.ts +0 -3
- package/dist/lib/pdfium/index.cjs +1 -1
- package/dist/lib/pdfium/index.js +2 -2
- package/dist/lib/pdfium/web/direct-engine.cjs +1 -1
- package/dist/lib/pdfium/web/direct-engine.js +1 -1
- package/dist/lib/pdfium/web/worker-engine.cjs +1 -1
- package/dist/lib/pdfium/web/worker-engine.js +1 -1
- package/dist/preact/index.cjs +1 -1
- package/dist/preact/index.js +1 -1
- package/dist/react/index.cjs +1 -1
- package/dist/react/index.js +1 -1
- package/dist/vue/index.cjs +1 -1
- package/dist/vue/index.js +1 -1
- package/package.json +3 -3
- package/dist/engine-B2N46cyz.js.map +0 -1
- package/dist/engine-CqHqGfLG.cjs +0 -2
- package/dist/engine-CqHqGfLG.cjs.map +0 -1
|
@@ -2795,23 +2795,6 @@ class PdfiumEngine {
|
|
|
2795
2795
|
}
|
|
2796
2796
|
return true;
|
|
2797
2797
|
}
|
|
2798
|
-
/** Build page-space image placement matrix from a device-space rect. */
|
|
2799
|
-
imageMatrixFromDeviceRect(page, rect) {
|
|
2800
|
-
const x0 = rect.origin.x;
|
|
2801
|
-
const y0 = rect.origin.y;
|
|
2802
|
-
const x1 = x0 + rect.size.width;
|
|
2803
|
-
const y1 = y0 + rect.size.height;
|
|
2804
|
-
const BL = this.convertDevicePointToPagePoint(page, { x: x0, y: y1 });
|
|
2805
|
-
const BR = this.convertDevicePointToPagePoint(page, { x: x1, y: y1 });
|
|
2806
|
-
const TL = this.convertDevicePointToPagePoint(page, { x: x0, y: y0 });
|
|
2807
|
-
const a = BR.x - BL.x;
|
|
2808
|
-
const b = BR.y - BL.y;
|
|
2809
|
-
const c = TL.x - BL.x;
|
|
2810
|
-
const d = TL.y - BL.y;
|
|
2811
|
-
const e = BL.x;
|
|
2812
|
-
const f = BL.y;
|
|
2813
|
-
return { a, b, c, d, e, f };
|
|
2814
|
-
}
|
|
2815
2798
|
/**
|
|
2816
2799
|
* Add image object to annotation
|
|
2817
2800
|
* @param docPtr - pointer to pdf document object
|
|
@@ -2825,63 +2808,76 @@ class PdfiumEngine {
|
|
|
2825
2808
|
* @private
|
|
2826
2809
|
*/
|
|
2827
2810
|
addImageObject(docPtr, page, pagePtr, annotationPtr, rect, imageData) {
|
|
2828
|
-
const
|
|
2811
|
+
const bytesPerPixel = 4;
|
|
2829
2812
|
const pixelCount = imageData.width * imageData.height;
|
|
2830
|
-
const
|
|
2831
|
-
if (!
|
|
2832
|
-
|
|
2833
|
-
const r = imageData.data[i * 4 + 0];
|
|
2834
|
-
const g = imageData.data[i * 4 + 1];
|
|
2835
|
-
const b = imageData.data[i * 4 + 2];
|
|
2836
|
-
const a = imageData.data[i * 4 + 3];
|
|
2837
|
-
this.pdfiumModule.pdfium.setValue(bufPtr + i * 4 + 0, b, "i8");
|
|
2838
|
-
this.pdfiumModule.pdfium.setValue(bufPtr + i * 4 + 1, g, "i8");
|
|
2839
|
-
this.pdfiumModule.pdfium.setValue(bufPtr + i * 4 + 2, r, "i8");
|
|
2840
|
-
this.pdfiumModule.pdfium.setValue(bufPtr + i * 4 + 3, a, "i8");
|
|
2813
|
+
const bitmapBufferPtr = this.memoryManager.malloc(bytesPerPixel * pixelCount);
|
|
2814
|
+
if (!bitmapBufferPtr) {
|
|
2815
|
+
return false;
|
|
2841
2816
|
}
|
|
2817
|
+
for (let i = 0; i < pixelCount; i++) {
|
|
2818
|
+
const red = imageData.data[i * bytesPerPixel];
|
|
2819
|
+
const green = imageData.data[i * bytesPerPixel + 1];
|
|
2820
|
+
const blue = imageData.data[i * bytesPerPixel + 2];
|
|
2821
|
+
const alpha = imageData.data[i * bytesPerPixel + 3];
|
|
2822
|
+
this.pdfiumModule.pdfium.setValue(bitmapBufferPtr + i * bytesPerPixel, blue, "i8");
|
|
2823
|
+
this.pdfiumModule.pdfium.setValue(bitmapBufferPtr + i * bytesPerPixel + 1, green, "i8");
|
|
2824
|
+
this.pdfiumModule.pdfium.setValue(bitmapBufferPtr + i * bytesPerPixel + 2, red, "i8");
|
|
2825
|
+
this.pdfiumModule.pdfium.setValue(bitmapBufferPtr + i * bytesPerPixel + 3, alpha, "i8");
|
|
2826
|
+
}
|
|
2827
|
+
const format = 4;
|
|
2842
2828
|
const bitmapPtr = this.pdfiumModule.FPDFBitmap_CreateEx(
|
|
2843
2829
|
imageData.width,
|
|
2844
2830
|
imageData.height,
|
|
2845
|
-
|
|
2846
|
-
|
|
2831
|
+
format,
|
|
2832
|
+
bitmapBufferPtr,
|
|
2847
2833
|
0
|
|
2848
2834
|
);
|
|
2849
2835
|
if (!bitmapPtr) {
|
|
2850
|
-
this.memoryManager.free(
|
|
2836
|
+
this.memoryManager.free(bitmapBufferPtr);
|
|
2851
2837
|
return false;
|
|
2852
2838
|
}
|
|
2853
|
-
const
|
|
2854
|
-
if (!
|
|
2839
|
+
const imageObjectPtr = this.pdfiumModule.FPDFPageObj_NewImageObj(docPtr);
|
|
2840
|
+
if (!imageObjectPtr) {
|
|
2855
2841
|
this.pdfiumModule.FPDFBitmap_Destroy(bitmapPtr);
|
|
2856
|
-
this.memoryManager.free(
|
|
2842
|
+
this.memoryManager.free(bitmapBufferPtr);
|
|
2857
2843
|
return false;
|
|
2858
2844
|
}
|
|
2859
|
-
if (!this.pdfiumModule.FPDFImageObj_SetBitmap(pagePtr, 0,
|
|
2860
|
-
this.pdfiumModule.FPDFPageObj_Destroy(imgPtr);
|
|
2845
|
+
if (!this.pdfiumModule.FPDFImageObj_SetBitmap(pagePtr, 0, imageObjectPtr, bitmapPtr)) {
|
|
2861
2846
|
this.pdfiumModule.FPDFBitmap_Destroy(bitmapPtr);
|
|
2862
|
-
this.
|
|
2847
|
+
this.pdfiumModule.FPDFPageObj_Destroy(imageObjectPtr);
|
|
2848
|
+
this.memoryManager.free(bitmapBufferPtr);
|
|
2863
2849
|
return false;
|
|
2864
2850
|
}
|
|
2865
|
-
const
|
|
2866
|
-
|
|
2867
|
-
this.pdfiumModule.pdfium.setValue(
|
|
2868
|
-
this.pdfiumModule.pdfium.setValue(
|
|
2869
|
-
this.pdfiumModule.pdfium.setValue(
|
|
2870
|
-
this.pdfiumModule.pdfium.setValue(
|
|
2871
|
-
this.pdfiumModule.pdfium.setValue(
|
|
2872
|
-
this.pdfiumModule.
|
|
2873
|
-
|
|
2874
|
-
this.memoryManager.free(mPtr);
|
|
2875
|
-
if (!setOk) {
|
|
2876
|
-
this.pdfiumModule.FPDFPageObj_Destroy(imgPtr);
|
|
2851
|
+
const matrixPtr = this.memoryManager.malloc(6 * 4);
|
|
2852
|
+
this.pdfiumModule.pdfium.setValue(matrixPtr, imageData.width, "float");
|
|
2853
|
+
this.pdfiumModule.pdfium.setValue(matrixPtr + 4, 0, "float");
|
|
2854
|
+
this.pdfiumModule.pdfium.setValue(matrixPtr + 8, 0, "float");
|
|
2855
|
+
this.pdfiumModule.pdfium.setValue(matrixPtr + 12, imageData.height, "float");
|
|
2856
|
+
this.pdfiumModule.pdfium.setValue(matrixPtr + 16, 0, "float");
|
|
2857
|
+
this.pdfiumModule.pdfium.setValue(matrixPtr + 20, 0, "float");
|
|
2858
|
+
if (!this.pdfiumModule.FPDFPageObj_SetMatrix(imageObjectPtr, matrixPtr)) {
|
|
2859
|
+
this.memoryManager.free(matrixPtr);
|
|
2877
2860
|
this.pdfiumModule.FPDFBitmap_Destroy(bitmapPtr);
|
|
2878
|
-
this.
|
|
2861
|
+
this.pdfiumModule.FPDFPageObj_Destroy(imageObjectPtr);
|
|
2862
|
+
this.memoryManager.free(bitmapBufferPtr);
|
|
2863
|
+
return false;
|
|
2864
|
+
}
|
|
2865
|
+
this.memoryManager.free(matrixPtr);
|
|
2866
|
+
const pagePos = this.convertDevicePointToPagePoint(page, {
|
|
2867
|
+
x: rect.origin.x,
|
|
2868
|
+
y: rect.origin.y + imageData.height
|
|
2869
|
+
// shift down by the image height
|
|
2870
|
+
});
|
|
2871
|
+
this.pdfiumModule.FPDFPageObj_Transform(imageObjectPtr, 1, 0, 0, 1, pagePos.x, pagePos.y);
|
|
2872
|
+
if (!this.pdfiumModule.FPDFAnnot_AppendObject(annotationPtr, imageObjectPtr)) {
|
|
2873
|
+
this.pdfiumModule.FPDFBitmap_Destroy(bitmapPtr);
|
|
2874
|
+
this.pdfiumModule.FPDFPageObj_Destroy(imageObjectPtr);
|
|
2875
|
+
this.memoryManager.free(bitmapBufferPtr);
|
|
2879
2876
|
return false;
|
|
2880
2877
|
}
|
|
2881
|
-
const ok = this.pdfiumModule.FPDFAnnot_AppendObject(annotationPtr, imgPtr);
|
|
2882
2878
|
this.pdfiumModule.FPDFBitmap_Destroy(bitmapPtr);
|
|
2883
|
-
this.memoryManager.free(
|
|
2884
|
-
return
|
|
2879
|
+
this.memoryManager.free(bitmapBufferPtr);
|
|
2880
|
+
return true;
|
|
2885
2881
|
}
|
|
2886
2882
|
/**
|
|
2887
2883
|
* Save document to array buffer
|
|
@@ -6497,36 +6493,35 @@ class PdfiumEngine {
|
|
|
6497
6493
|
/**
|
|
6498
6494
|
* Set the rect of specified annotation
|
|
6499
6495
|
* @param page - page info that the annotation is belonged to
|
|
6500
|
-
* @param pagePtr - pointer of page object
|
|
6501
6496
|
* @param annotationPtr - pointer to annotation object
|
|
6502
6497
|
* @param rect - target rectangle
|
|
6503
6498
|
* @returns whether the rect is setted
|
|
6504
6499
|
*
|
|
6505
6500
|
* @private
|
|
6506
6501
|
*/
|
|
6507
|
-
setPageAnnoRect(page,
|
|
6508
|
-
const
|
|
6509
|
-
const
|
|
6510
|
-
const
|
|
6511
|
-
const
|
|
6512
|
-
const
|
|
6513
|
-
const
|
|
6514
|
-
const
|
|
6515
|
-
const
|
|
6516
|
-
|
|
6517
|
-
|
|
6518
|
-
|
|
6519
|
-
|
|
6520
|
-
|
|
6521
|
-
|
|
6522
|
-
const
|
|
6523
|
-
const
|
|
6524
|
-
|
|
6525
|
-
|
|
6526
|
-
|
|
6527
|
-
|
|
6528
|
-
const ok = this.pdfiumModule.FPDFAnnot_SetRect(
|
|
6529
|
-
this.memoryManager.free(
|
|
6502
|
+
setPageAnnoRect(page, annotPtr, rect) {
|
|
6503
|
+
const x0d = Math.floor(rect.origin.x);
|
|
6504
|
+
const y0d = Math.floor(rect.origin.y);
|
|
6505
|
+
const x1d = Math.floor(rect.origin.x + rect.size.width);
|
|
6506
|
+
const y1d = Math.floor(rect.origin.y + rect.size.height);
|
|
6507
|
+
const TL = this.convertDevicePointToPagePoint(page, { x: x0d, y: y0d });
|
|
6508
|
+
const TR = this.convertDevicePointToPagePoint(page, { x: x1d, y: y0d });
|
|
6509
|
+
const BR = this.convertDevicePointToPagePoint(page, { x: x1d, y: y1d });
|
|
6510
|
+
const BL = this.convertDevicePointToPagePoint(page, { x: x0d, y: y1d });
|
|
6511
|
+
let left = Math.min(TL.x, TR.x, BR.x, BL.x);
|
|
6512
|
+
let right = Math.max(TL.x, TR.x, BR.x, BL.x);
|
|
6513
|
+
let bottom = Math.min(TL.y, TR.y, BR.y, BL.y);
|
|
6514
|
+
let top = Math.max(TL.y, TR.y, BR.y, BL.y);
|
|
6515
|
+
if (left > right) [left, right] = [right, left];
|
|
6516
|
+
if (bottom > top) [bottom, top] = [top, bottom];
|
|
6517
|
+
const ptr = this.memoryManager.malloc(16);
|
|
6518
|
+
const pdf = this.pdfiumModule.pdfium;
|
|
6519
|
+
pdf.setValue(ptr + 0, left, "float");
|
|
6520
|
+
pdf.setValue(ptr + 4, top, "float");
|
|
6521
|
+
pdf.setValue(ptr + 8, right, "float");
|
|
6522
|
+
pdf.setValue(ptr + 12, bottom, "float");
|
|
6523
|
+
const ok = this.pdfiumModule.FPDFAnnot_SetRect(annotPtr, ptr);
|
|
6524
|
+
this.memoryManager.free(ptr);
|
|
6530
6525
|
return !!ok;
|
|
6531
6526
|
}
|
|
6532
6527
|
/**
|
|
@@ -7025,4 +7020,4 @@ export {
|
|
|
7025
7020
|
isValidCustomKey as i,
|
|
7026
7021
|
readString as r
|
|
7027
7022
|
};
|
|
7028
|
-
//# sourceMappingURL=engine-
|
|
7023
|
+
//# sourceMappingURL=engine-N_GwaBxA.js.map
|