@embedpdf/engines 1.3.2 → 1.3.4

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.
@@ -724,12 +724,14 @@ class PdfiumEngine {
724
724
  message: `FPDF_GetPageSizeByIndexF failed`
725
725
  });
726
726
  }
727
+ const rotation = this.pdfiumModule.EPDF_GetPageRotationByIndex(docPtr, index);
727
728
  const page = {
728
729
  index,
729
730
  size: {
730
731
  width: this.pdfiumModule.pdfium.getValue(sizePtr, "float"),
731
732
  height: this.pdfiumModule.pdfium.getValue(sizePtr + 4, "float")
732
- }
733
+ },
734
+ rotation
733
735
  };
734
736
  pages.push(page);
735
737
  }
@@ -806,12 +808,14 @@ class PdfiumEngine {
806
808
  message: `FPDF_GetPageSizeByIndexF failed`
807
809
  });
808
810
  }
811
+ const rotation = this.pdfiumModule.EPDF_GetPageRotationByIndex(docPtr, index);
809
812
  const page = {
810
813
  index,
811
814
  size: {
812
815
  width: this.pdfiumModule.pdfium.getValue(sizePtr, "float"),
813
816
  height: this.pdfiumModule.pdfium.getValue(sizePtr + 4, "float")
814
- }
817
+ },
818
+ rotation
815
819
  };
816
820
  pages.push(page);
817
821
  }
@@ -1301,7 +1305,7 @@ class PdfiumEngine {
1301
1305
  message: "can not set the name of the annotation"
1302
1306
  });
1303
1307
  }
1304
- if (!this.setPageAnnoRect(page, pageCtx.pagePtr, annotationPtr, annotation.rect)) {
1308
+ if (!this.setPageAnnoRect(page, annotationPtr, annotation.rect)) {
1305
1309
  this.pdfiumModule.FPDFPage_CloseAnnot(annotationPtr);
1306
1310
  pageCtx.release();
1307
1311
  this.logger.perf(
@@ -1432,7 +1436,7 @@ class PdfiumEngine {
1432
1436
  );
1433
1437
  return PdfTaskHelper.reject({ code: PdfErrorCode.NotFound, message: "annotation not found" });
1434
1438
  }
1435
- if (!this.setPageAnnoRect(page, pageCtx.pagePtr, annotPtr, annotation.rect)) {
1439
+ if (!this.setPageAnnoRect(page, annotPtr, annotation.rect)) {
1436
1440
  this.pdfiumModule.FPDFPage_CloseAnnot(annotPtr);
1437
1441
  pageCtx.release();
1438
1442
  this.logger.perf(
@@ -4079,24 +4083,24 @@ class PdfiumEngine {
4079
4083
  * @param page - logical page info object (`PdfPageObject`)
4080
4084
  * @returns `{ start, end }` or `undefined` when PDFium can't read them
4081
4085
  */
4082
- getLinePoints(annotationPtr, page) {
4083
- const startPointPtr = this.memoryManager.malloc(8);
4084
- const endPointPtr = this.memoryManager.malloc(8);
4085
- this.pdfiumModule.FPDFAnnot_GetLine(annotationPtr, startPointPtr, endPointPtr);
4086
- const startPointX = this.pdfiumModule.pdfium.getValue(startPointPtr, "float");
4087
- const startPointY = this.pdfiumModule.pdfium.getValue(startPointPtr + 4, "float");
4088
- const start = this.convertPagePointToDevicePoint(page, {
4089
- x: startPointX,
4090
- y: startPointY
4091
- });
4092
- const endPointX = this.pdfiumModule.pdfium.getValue(endPointPtr, "float");
4093
- const endPointY = this.pdfiumModule.pdfium.getValue(endPointPtr + 4, "float");
4094
- const end = this.convertPagePointToDevicePoint(page, {
4095
- x: endPointX,
4096
- y: endPointY
4097
- });
4098
- this.memoryManager.free(startPointPtr);
4099
- this.memoryManager.free(endPointPtr);
4086
+ getLinePoints(page, annotationPtr) {
4087
+ const startPtr = this.memoryManager.malloc(8);
4088
+ const endPtr = this.memoryManager.malloc(8);
4089
+ const ok = this.pdfiumModule.FPDFAnnot_GetLine(annotationPtr, startPtr, endPtr);
4090
+ if (!ok) {
4091
+ this.memoryManager.free(startPtr);
4092
+ this.memoryManager.free(endPtr);
4093
+ return void 0;
4094
+ }
4095
+ const pdf = this.pdfiumModule.pdfium;
4096
+ const sx = pdf.getValue(startPtr + 0, "float");
4097
+ const sy = pdf.getValue(startPtr + 4, "float");
4098
+ const ex = pdf.getValue(endPtr + 0, "float");
4099
+ const ey = pdf.getValue(endPtr + 4, "float");
4100
+ this.memoryManager.free(startPtr);
4101
+ this.memoryManager.free(endPtr);
4102
+ const start = this.convertPagePointToDevicePoint(page, { x: sx, y: sy });
4103
+ const end = this.convertPagePointToDevicePoint(page, { x: ex, y: ey });
4100
4104
  return { start, end };
4101
4105
  }
4102
4106
  /**
@@ -4109,16 +4113,18 @@ class PdfiumEngine {
4109
4113
  * @returns true on success
4110
4114
  */
4111
4115
  setLinePoints(page, annotPtr, start, end) {
4112
- const buf = this.memoryManager.malloc(16);
4113
4116
  const p1 = this.convertDevicePointToPagePoint(page, start);
4114
4117
  const p2 = this.convertDevicePointToPagePoint(page, end);
4115
- this.pdfiumModule.pdfium.setValue(buf + 0, p1.x, "float");
4116
- this.pdfiumModule.pdfium.setValue(buf + 4, p1.y, "float");
4117
- this.pdfiumModule.pdfium.setValue(buf + 8, p2.x, "float");
4118
- this.pdfiumModule.pdfium.setValue(buf + 12, p2.y, "float");
4118
+ if (!p1 || !p2) return false;
4119
+ const buf = this.memoryManager.malloc(16);
4120
+ const pdf = this.pdfiumModule.pdfium;
4121
+ pdf.setValue(buf + 0, p1.x, "float");
4122
+ pdf.setValue(buf + 4, p1.y, "float");
4123
+ pdf.setValue(buf + 8, p2.x, "float");
4124
+ pdf.setValue(buf + 12, p2.y, "float");
4119
4125
  const ok = this.pdfiumModule.EPDFAnnot_SetLine(annotPtr, buf, buf + 8);
4120
4126
  this.memoryManager.free(buf);
4121
- return ok;
4127
+ return !!ok;
4122
4128
  }
4123
4129
  /**
4124
4130
  * Read `/QuadPoints` from any annotation and convert each quadrilateral to
@@ -4292,29 +4298,30 @@ class PdfiumEngine {
4292
4298
  /**
4293
4299
  * Read ink list from annotation
4294
4300
  * @param page - logical page info object (`PdfPageObject`)
4301
+ * @param pagePtr - pointer to the page
4295
4302
  * @param annotationPtr - pointer to the annotation whose ink list is needed
4296
4303
  * @returns ink list
4297
4304
  */
4298
4305
  getInkList(page, annotationPtr) {
4299
4306
  const inkList = [];
4300
- const count = this.pdfiumModule.FPDFAnnot_GetInkListCount(annotationPtr);
4301
- for (let i = 0; i < count; i++) {
4307
+ const pathCount = this.pdfiumModule.FPDFAnnot_GetInkListCount(annotationPtr);
4308
+ if (pathCount <= 0) return inkList;
4309
+ const pdf = this.pdfiumModule.pdfium;
4310
+ const POINT_STRIDE = 8;
4311
+ for (let i = 0; i < pathCount; i++) {
4302
4312
  const points = [];
4303
- const pointsCount = this.pdfiumModule.FPDFAnnot_GetInkListPath(annotationPtr, i, 0, 0);
4304
- if (pointsCount > 0) {
4305
- const pointMemorySize = 8;
4306
- const pointsPtr = this.memoryManager.malloc(pointsCount * pointMemorySize);
4307
- this.pdfiumModule.FPDFAnnot_GetInkListPath(annotationPtr, i, pointsPtr, pointsCount);
4308
- for (let j = 0; j < pointsCount; j++) {
4309
- const pointX = this.pdfiumModule.pdfium.getValue(pointsPtr + j * 8, "float");
4310
- const pointY = this.pdfiumModule.pdfium.getValue(pointsPtr + j * 8 + 4, "float");
4311
- const { x, y } = this.convertPagePointToDevicePoint(page, {
4312
- x: pointX,
4313
- y: pointY
4314
- });
4315
- points.push({ x, y });
4313
+ const n = this.pdfiumModule.FPDFAnnot_GetInkListPath(annotationPtr, i, 0, 0);
4314
+ if (n > 0) {
4315
+ const buf = this.memoryManager.malloc(n * POINT_STRIDE);
4316
+ this.pdfiumModule.FPDFAnnot_GetInkListPath(annotationPtr, i, buf, n);
4317
+ for (let j = 0; j < n; j++) {
4318
+ const base = buf + j * POINT_STRIDE;
4319
+ const px = pdf.getValue(base + 0, "float");
4320
+ const py = pdf.getValue(base + 4, "float");
4321
+ const d = this.convertPagePointToDevicePoint(page, { x: px, y: py });
4322
+ points.push({ x: d.x, y: d.y });
4316
4323
  }
4317
- this.memoryManager.free(pointsPtr);
4324
+ this.memoryManager.free(buf);
4318
4325
  }
4319
4326
  inkList.push({ points });
4320
4327
  }
@@ -4323,25 +4330,29 @@ class PdfiumEngine {
4323
4330
  /**
4324
4331
  * Add ink list to annotation
4325
4332
  * @param page - logical page info object (`PdfPageObject`)
4333
+ * @param pagePtr - pointer to the page
4326
4334
  * @param annotationPtr - pointer to the annotation whose ink list is needed
4327
- * @param annotation - annotation object (`PdfInkAnnoObject`)
4335
+ * @param inkList - ink list array of `PdfInkListObject`
4328
4336
  * @returns `true` if the operation was successful
4329
4337
  */
4330
4338
  setInkList(page, annotationPtr, inkList) {
4331
- for (const inkStroke of inkList) {
4332
- const inkPointsCount = inkStroke.points.length;
4333
- const inkPointsPtr = this.memoryManager.malloc(inkPointsCount * 8);
4334
- for (let i = 0; i < inkPointsCount; i++) {
4335
- const point = inkStroke.points[i];
4336
- const { x, y } = this.convertDevicePointToPagePoint(page, point);
4337
- this.pdfiumModule.pdfium.setValue(inkPointsPtr + i * 8, x, "float");
4338
- this.pdfiumModule.pdfium.setValue(inkPointsPtr + i * 8 + 4, y, "float");
4339
+ const pdf = this.pdfiumModule.pdfium;
4340
+ const POINT_STRIDE = 8;
4341
+ for (const stroke of inkList) {
4342
+ const n = stroke.points.length;
4343
+ if (n === 0) continue;
4344
+ const buf = this.memoryManager.malloc(n * POINT_STRIDE);
4345
+ for (let i = 0; i < n; i++) {
4346
+ const pDev = stroke.points[i];
4347
+ const pPage = this.convertDevicePointToPagePoint(page, pDev);
4348
+ pdf.setValue(buf + i * POINT_STRIDE + 0, pPage.x, "float");
4349
+ pdf.setValue(buf + i * POINT_STRIDE + 4, pPage.y, "float");
4339
4350
  }
4340
- if (this.pdfiumModule.FPDFAnnot_AddInkStroke(annotationPtr, inkPointsPtr, inkPointsCount) === -1) {
4341
- this.memoryManager.free(inkPointsPtr);
4351
+ const idx = this.pdfiumModule.FPDFAnnot_AddInkStroke(annotationPtr, buf, n);
4352
+ this.memoryManager.free(buf);
4353
+ if (idx === -1) {
4342
4354
  return false;
4343
4355
  }
4344
- this.memoryManager.free(inkPointsPtr);
4345
4356
  }
4346
4357
  return true;
4347
4358
  }
@@ -4714,7 +4725,7 @@ class PdfiumEngine {
4714
4725
  const author = this.getAnnotString(annotationPtr, "T");
4715
4726
  const modified = this.getAnnotationDate(annotationPtr, "M");
4716
4727
  const created = this.getAnnotationDate(annotationPtr, "CreationDate");
4717
- const linePoints = this.getLinePoints(annotationPtr, page);
4728
+ const linePoints = this.getLinePoints(page, annotationPtr);
4718
4729
  const lineEndings = this.getLineEndings(annotationPtr);
4719
4730
  const contents = this.getAnnotString(annotationPtr, "Contents") || "";
4720
4731
  const strokeColor = this.getAnnotationColor(annotationPtr);
@@ -5939,6 +5950,7 @@ class PdfiumEngine {
5939
5950
  const hDev = Math.max(1, Math.round((swap ? baseW : baseH) * finalScale));
5940
5951
  const stride = wDev * 4;
5941
5952
  const bytes = stride * hDev;
5953
+ const pageCtx = ctx.acquirePage(page.index);
5942
5954
  const heapPtr = this.memoryManager.malloc(bytes);
5943
5955
  const bitmapPtr = this.pdfiumModule.FPDFBitmap_CreateEx(
5944
5956
  wDev,
@@ -5955,9 +5967,8 @@ class PdfiumEngine {
5955
5967
  const clipPtr = this.memoryManager.malloc(4 * 4);
5956
5968
  const clipView = new Float32Array(this.pdfiumModule.pdfium.HEAPF32.buffer, clipPtr, 4);
5957
5969
  clipView.set([0, 0, wDev, hDev]);
5958
- let flags = 2 | 16;
5970
+ let flags = 16;
5959
5971
  if ((options == null ? void 0 : options.withAnnotations) ?? false) flags |= 1;
5960
- const pageCtx = ctx.acquirePage(page.index);
5961
5972
  try {
5962
5973
  this.pdfiumModule.FPDF_RenderPageBitmapWithMatrix(
5963
5974
  bitmapPtr,
@@ -5977,13 +5988,12 @@ class PdfiumEngine {
5977
5988
  };
5978
5989
  this.imageDataConverter(
5979
5990
  () => {
5980
- const rgba = new Uint8ClampedArray(
5981
- this.pdfiumModule.pdfium.HEAPU8.subarray(heapPtr, heapPtr + bytes)
5982
- );
5991
+ const heapBuf = this.pdfiumModule.pdfium.HEAPU8.buffer;
5992
+ const data = new Uint8ClampedArray(heapBuf, heapPtr, bytes);
5983
5993
  return {
5984
5994
  width: wDev,
5985
5995
  height: hDev,
5986
- data: rgba
5996
+ data
5987
5997
  };
5988
5998
  },
5989
5999
  imageType,
@@ -6361,9 +6371,21 @@ class PdfiumEngine {
6361
6371
  * @private
6362
6372
  */
6363
6373
  convertDevicePointToPagePoint(page, position) {
6364
- const x = position.x;
6365
- const y = page.size.height - position.y;
6366
- return { x, y };
6374
+ const DW = page.size.width;
6375
+ const DH = page.size.height;
6376
+ const r = page.rotation & 3;
6377
+ if (r === 0) {
6378
+ return { x: position.x, y: DH - position.y };
6379
+ }
6380
+ if (r === 1) {
6381
+ return { x: position.y, y: position.x };
6382
+ }
6383
+ if (r === 2) {
6384
+ return { x: DW - position.x, y: position.y };
6385
+ }
6386
+ {
6387
+ return { x: DH - position.y, y: DW - position.x };
6388
+ }
6367
6389
  }
6368
6390
  /**
6369
6391
  * Convert coordinate of point from page coordinate to device coordinate
@@ -6374,9 +6396,21 @@ class PdfiumEngine {
6374
6396
  * @private
6375
6397
  */
6376
6398
  convertPagePointToDevicePoint(page, position) {
6377
- const x = position.x;
6378
- const y = page.size.height - position.y;
6379
- return { x, y };
6399
+ const DW = page.size.width;
6400
+ const DH = page.size.height;
6401
+ const r = page.rotation & 3;
6402
+ if (r === 0) {
6403
+ return { x: position.x, y: DH - position.y };
6404
+ }
6405
+ if (r === 1) {
6406
+ return { x: position.y, y: position.x };
6407
+ }
6408
+ if (r === 2) {
6409
+ return { x: DW - position.x, y: position.y };
6410
+ }
6411
+ {
6412
+ return { x: DW - position.y, y: DH - position.x };
6413
+ }
6380
6414
  }
6381
6415
  /**
6382
6416
  * Convert coordinate of rectangle from page coordinate to device coordinate
@@ -6459,47 +6493,36 @@ class PdfiumEngine {
6459
6493
  /**
6460
6494
  * Set the rect of specified annotation
6461
6495
  * @param page - page info that the annotation is belonged to
6462
- * @param pagePtr - pointer of page object
6463
6496
  * @param annotationPtr - pointer to annotation object
6464
6497
  * @param rect - target rectangle
6465
6498
  * @returns whether the rect is setted
6466
6499
  *
6467
6500
  * @private
6468
6501
  */
6469
- setPageAnnoRect(page, pagePtr, annotationPtr, rect) {
6470
- const pageXPtr = this.memoryManager.malloc(8);
6471
- const pageYPtr = this.memoryManager.malloc(8);
6472
- if (!this.pdfiumModule.FPDF_DeviceToPage(
6473
- pagePtr,
6474
- 0,
6475
- 0,
6476
- page.size.width,
6477
- page.size.height,
6478
- 0,
6479
- rect.origin.x,
6480
- rect.origin.y,
6481
- pageXPtr,
6482
- pageYPtr
6483
- )) {
6484
- this.memoryManager.free(pageXPtr);
6485
- this.memoryManager.free(pageYPtr);
6486
- return false;
6487
- }
6488
- const pageX = this.pdfiumModule.pdfium.getValue(pageXPtr, "double");
6489
- const pageY = this.pdfiumModule.pdfium.getValue(pageYPtr, "double");
6490
- this.memoryManager.free(pageXPtr);
6491
- this.memoryManager.free(pageYPtr);
6492
- const pageRectPtr = this.memoryManager.malloc(4 * 4);
6493
- this.pdfiumModule.pdfium.setValue(pageRectPtr, pageX, "float");
6494
- this.pdfiumModule.pdfium.setValue(pageRectPtr + 4, pageY, "float");
6495
- this.pdfiumModule.pdfium.setValue(pageRectPtr + 8, pageX + rect.size.width, "float");
6496
- this.pdfiumModule.pdfium.setValue(pageRectPtr + 12, pageY - rect.size.height, "float");
6497
- if (!this.pdfiumModule.FPDFAnnot_SetRect(annotationPtr, pageRectPtr)) {
6498
- this.memoryManager.free(pageRectPtr);
6499
- return false;
6500
- }
6501
- this.memoryManager.free(pageRectPtr);
6502
- return true;
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);
6525
+ return !!ok;
6503
6526
  }
6504
6527
  /**
6505
6528
  * Read the rectangle of annotation
@@ -6536,62 +6559,39 @@ class PdfiumEngine {
6536
6559
  *
6537
6560
  * @private
6538
6561
  */
6539
- getHighlightRects(page, pagePtr, textPagePtr, startIndex, charCount) {
6562
+ getHighlightRects(page, textPagePtr, startIndex, charCount) {
6540
6563
  const rectsCount = this.pdfiumModule.FPDFText_CountRects(textPagePtr, startIndex, charCount);
6541
6564
  const highlightRects = [];
6565
+ const l = this.memoryManager.malloc(8);
6566
+ const t = this.memoryManager.malloc(8);
6567
+ const r = this.memoryManager.malloc(8);
6568
+ const b = this.memoryManager.malloc(8);
6542
6569
  for (let i = 0; i < rectsCount; i++) {
6543
- const topPtr = this.memoryManager.malloc(8);
6544
- const leftPtr = this.memoryManager.malloc(8);
6545
- const rightPtr = this.memoryManager.malloc(8);
6546
- const bottomPtr = this.memoryManager.malloc(8);
6547
- const isSucceed = this.pdfiumModule.FPDFText_GetRect(
6548
- textPagePtr,
6549
- i,
6550
- leftPtr,
6551
- topPtr,
6552
- rightPtr,
6553
- bottomPtr
6554
- );
6555
- if (!isSucceed) {
6556
- this.memoryManager.free(leftPtr);
6557
- this.memoryManager.free(topPtr);
6558
- this.memoryManager.free(rightPtr);
6559
- this.memoryManager.free(bottomPtr);
6560
- continue;
6561
- }
6562
- const left = this.pdfiumModule.pdfium.getValue(leftPtr, "double");
6563
- const top = this.pdfiumModule.pdfium.getValue(topPtr, "double");
6564
- const right = this.pdfiumModule.pdfium.getValue(rightPtr, "double");
6565
- const bottom = this.pdfiumModule.pdfium.getValue(bottomPtr, "double");
6566
- this.memoryManager.free(leftPtr);
6567
- this.memoryManager.free(topPtr);
6568
- this.memoryManager.free(rightPtr);
6569
- this.memoryManager.free(bottomPtr);
6570
- const deviceXPtr = this.memoryManager.malloc(4);
6571
- const deviceYPtr = this.memoryManager.malloc(4);
6572
- this.pdfiumModule.FPDF_PageToDevice(
6573
- pagePtr,
6574
- 0,
6575
- 0,
6576
- page.size.width,
6577
- page.size.height,
6578
- 0,
6579
- left,
6580
- top,
6581
- deviceXPtr,
6582
- deviceYPtr
6583
- );
6584
- const x = this.pdfiumModule.pdfium.getValue(deviceXPtr, "i32");
6585
- const y = this.pdfiumModule.pdfium.getValue(deviceYPtr, "i32");
6586
- this.memoryManager.free(deviceXPtr);
6587
- this.memoryManager.free(deviceYPtr);
6588
- const width = Math.ceil(Math.abs(right - left));
6589
- const height = Math.ceil(Math.abs(top - bottom));
6570
+ const ok = this.pdfiumModule.FPDFText_GetRect(textPagePtr, i, l, t, r, b);
6571
+ if (!ok) continue;
6572
+ const left = this.pdfiumModule.pdfium.getValue(l, "double");
6573
+ const top = this.pdfiumModule.pdfium.getValue(t, "double");
6574
+ const right = this.pdfiumModule.pdfium.getValue(r, "double");
6575
+ const bottom = this.pdfiumModule.pdfium.getValue(b, "double");
6576
+ const p1 = this.convertPagePointToDevicePoint(page, { x: left, y: top });
6577
+ const p2 = this.convertPagePointToDevicePoint(page, { x: right, y: top });
6578
+ const p3 = this.convertPagePointToDevicePoint(page, { x: right, y: bottom });
6579
+ const p4 = this.convertPagePointToDevicePoint(page, { x: left, y: bottom });
6580
+ const xs = [p1.x, p2.x, p3.x, p4.x];
6581
+ const ys = [p1.y, p2.y, p3.y, p4.y];
6582
+ const x = Math.min(...xs);
6583
+ const y = Math.min(...ys);
6584
+ const width = Math.max(...xs) - x;
6585
+ const height = Math.max(...ys) - y;
6590
6586
  highlightRects.push({
6591
6587
  origin: { x, y },
6592
- size: { width, height }
6588
+ size: { width: Math.ceil(width), height: Math.ceil(height) }
6593
6589
  });
6594
6590
  }
6591
+ this.memoryManager.free(l);
6592
+ this.memoryManager.free(t);
6593
+ this.memoryManager.free(r);
6594
+ this.memoryManager.free(b);
6595
6595
  return highlightRects;
6596
6596
  }
6597
6597
  /**
@@ -6760,13 +6760,7 @@ class PdfiumEngine {
6760
6760
  while (this.pdfiumModule.FPDFText_FindNext(searchHandle)) {
6761
6761
  const charIndex = this.pdfiumModule.FPDFText_GetSchResultIndex(searchHandle);
6762
6762
  const charCount = this.pdfiumModule.FPDFText_GetSchCount(searchHandle);
6763
- const rects = this.getHighlightRects(
6764
- page,
6765
- pageCtx.pagePtr,
6766
- textPagePtr,
6767
- charIndex,
6768
- charCount
6769
- );
6763
+ const rects = this.getHighlightRects(page, textPagePtr, charIndex, charCount);
6770
6764
  const context = this.buildContext(fullText, charIndex, charCount);
6771
6765
  pageResults.push({
6772
6766
  pageIndex: page.index,
@@ -7026,4 +7020,4 @@ export {
7026
7020
  isValidCustomKey as i,
7027
7021
  readString as r
7028
7022
  };
7029
- //# sourceMappingURL=engine-BVe88qdX.js.map
7023
+ //# sourceMappingURL=engine-N_GwaBxA.js.map