@pixldocs/canvas-renderer 0.5.22 → 0.5.24

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/index.cjs CHANGED
@@ -12590,8 +12590,8 @@ class PixldocsRenderer {
12590
12590
  return;
12591
12591
  }
12592
12592
  const exportCanvas = document.createElement("canvas");
12593
- exportCanvas.width = sourceCanvas.width;
12594
- exportCanvas.height = sourceCanvas.height;
12593
+ exportCanvas.width = Math.round(canvasWidth * pixelRatio);
12594
+ exportCanvas.height = Math.round(canvasHeight * pixelRatio);
12595
12595
  const exportCtx = exportCanvas.getContext("2d");
12596
12596
  if (!exportCtx) {
12597
12597
  cleanup();
@@ -12599,10 +12599,10 @@ class PixldocsRenderer {
12599
12599
  return;
12600
12600
  }
12601
12601
  exportCtx.save();
12602
- exportCtx.scale(sourceCanvas.width / canvasWidth, sourceCanvas.height / canvasHeight);
12602
+ exportCtx.scale(exportCanvas.width / canvasWidth, exportCanvas.height / canvasHeight);
12603
12603
  this.paintPageBackground(exportCtx, config.pages[pageIndex], canvasWidth, canvasHeight);
12604
12604
  exportCtx.restore();
12605
- exportCtx.drawImage(sourceCanvas, 0, 0);
12605
+ exportCtx.drawImage(sourceCanvas, 0, 0, exportCanvas.width, exportCanvas.height);
12606
12606
  const mimeType = format === "jpeg" ? "image/jpeg" : format === "webp" ? "image/webp" : "image/png";
12607
12607
  const dataUrl = exportCanvas.toDataURL(mimeType, quality);
12608
12608
  cleanup();
@@ -12618,7 +12618,7 @@ class PixldocsRenderer {
12618
12618
  react.createElement(PreviewCanvas2, {
12619
12619
  config,
12620
12620
  pageIndex,
12621
- zoom: pixelRatio,
12621
+ zoom: 1,
12622
12622
  absoluteZoom: true,
12623
12623
  onReady
12624
12624
  })
@@ -14546,19 +14546,21 @@ function convertTextDecorationsToLines(svg) {
14546
14546
  const fontFamily = tspan.getAttribute("font-family") || textEl.getAttribute("font-family") || "sans-serif";
14547
14547
  const fontWeight = tspan.getAttribute("font-weight") || textEl.getAttribute("font-weight") || "normal";
14548
14548
  const fill = tspan.getAttribute("fill") || textEl.getAttribute("fill") || "#000000";
14549
- let textWidth;
14550
- if (ctx) {
14551
- ctx.font = `${fontWeight} ${fontSize}px ${fontFamily.replace(/'/g, "")}`;
14552
- textWidth = ctx.measureText(content).width;
14553
- } else {
14554
- textWidth = content.length * fontSize * 0.6;
14555
- }
14549
+ let textWidth = 0;
14556
14550
  if (typeof tspan.getComputedTextLength === "function") {
14557
14551
  try {
14558
- textWidth = Math.max(textWidth, tspan.getComputedTextLength());
14552
+ textWidth = tspan.getComputedTextLength();
14559
14553
  } catch {
14560
14554
  }
14561
14555
  }
14556
+ if (!Number.isFinite(textWidth) || textWidth <= 0) {
14557
+ if (ctx) {
14558
+ ctx.font = `${fontWeight} ${fontSize}px ${fontFamily.replace(/'/g, "")}`;
14559
+ textWidth = ctx.measureText(content).width;
14560
+ } else {
14561
+ textWidth = content.length * fontSize * 0.6;
14562
+ }
14563
+ }
14562
14564
  const underlineY = y + fontSize * 0.15;
14563
14565
  const thickness = Math.max(0.5, fontSize * 0.066667);
14564
14566
  const line = doc.createElementNS("http://www.w3.org/2000/svg", "line");