@postermywall/fabricjs-2 7.4.0-pmw-70 → 7.4.0-pmw-71

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 (35) hide show
  1. package/.vitest-attachments/23b206d0e2c2cbf41ea4d8dd1b0758f9c3447d6f.png +0 -0
  2. package/CHANGELOG.md +1 -0
  3. package/dist/index.js +16 -8
  4. package/dist/index.js.map +1 -1
  5. package/dist/index.min.js +25 -25
  6. package/dist/index.min.js.map +1 -1
  7. package/dist/index.min.mjs +25 -25
  8. package/dist/index.min.mjs.map +1 -1
  9. package/dist/index.mjs +16 -8
  10. package/dist/index.mjs.map +1 -1
  11. package/dist/index.node.cjs +16 -8
  12. package/dist/index.node.cjs.map +1 -1
  13. package/dist/index.node.mjs +16 -8
  14. package/dist/index.node.mjs.map +1 -1
  15. package/dist/package.min.mjs +1 -1
  16. package/dist/package.mjs +1 -1
  17. package/dist/src/parser/normalizeValue.d.ts.map +1 -1
  18. package/dist/src/parser/normalizeValue.min.mjs +1 -1
  19. package/dist/src/parser/normalizeValue.min.mjs.map +1 -1
  20. package/dist/src/parser/normalizeValue.mjs +4 -2
  21. package/dist/src/parser/normalizeValue.mjs.map +1 -1
  22. package/dist/src/shapes/Text/Text.d.ts.map +1 -1
  23. package/dist/src/shapes/Text/Text.min.mjs +2 -2
  24. package/dist/src/shapes/Text/Text.min.mjs.map +1 -1
  25. package/dist/src/shapes/Text/Text.mjs +11 -5
  26. package/dist/src/shapes/Text/Text.mjs.map +1 -1
  27. package/dist-extensions/src/parser/normalizeValue.d.ts.map +1 -1
  28. package/dist-extensions/src/shapes/Text/Text.d.ts.map +1 -1
  29. package/package.json +1 -1
  30. package/src/__screenshots__/__tmp_real_svg.spec.ts/real-Office-exported-SVG-from-order-42675801-parses--measures-and-renders-its-clipped-text-without-throwing-1.png +0 -0
  31. package/src/parser/loadSVGFromString.test.ts +26 -0
  32. package/src/parser/normalizeValue.ts +6 -0
  33. package/src/shapes/Text/Text.ts +18 -6
  34. package/src/shapes/Text/glyphOverhang.spec.ts +18 -0
  35. package/postermywall-fabricjs-2-7.4.0-pmw-70.tgz +0 -0
package/CHANGELOG.md CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  ## [next]
4
4
 
5
+ - fix(text): an SVG `letter-spacing: normal` (Office exports) reads as no extra spacing instead of the raw string, and a non-finite glyph reach can no longer size a text cache canvas to 0 and crash the render with `drawImage ... width or height of 0` (pmw-71)
5
6
  - feat(text): export list markers as SVG spans where the canvas draws them, write the gradient definitions of per-character fills, and read a right-to-left line's glyph reach by each glyph's own ink (pmw-70)
6
7
  - feat(text): measure each glyph's ink reach and size the text and group caches from it, so swashes and descenders of any font are not cut (pmw-69)
7
8
  - Upgrade 7.4.0 [#4](https://github.com/fabricjs/fabric.js/pull/4)
package/dist/index.js CHANGED
@@ -452,7 +452,7 @@
452
452
  const cache = new Cache();
453
453
  //#endregion
454
454
  //#region src/constants.ts
455
- const VERSION = "7.4.0-pmw-70";
455
+ const VERSION = "7.4.0-pmw-71";
456
456
  function noop() {}
457
457
  const halfPI = Math.PI / 2;
458
458
  const quarterPI = Math.PI / 4;
@@ -8745,8 +8745,10 @@
8745
8745
  ouputValue = parseFloat(value);
8746
8746
  if (parentAttributes && typeof parentAttributes.opacity !== "undefined") ouputValue *= parentAttributes.opacity;
8747
8747
  } else if (attr === "textAnchor") ouputValue = value === "start" ? LEFT : value === "end" ? RIGHT : CENTER;
8748
- else if (attr === "charSpacing" || attr === "textDecorationThickness") parsed = parseUnit(value, fontSize) / fontSize * 1e3;
8749
- else if (attr === "paintFirst") {
8748
+ else if (attr === "charSpacing" || attr === "textDecorationThickness") {
8749
+ parsed = parseUnit(value, fontSize) / fontSize * 1e3;
8750
+ if (attr === "charSpacing" && !Number.isFinite(parsed)) parsed = 0;
8751
+ } else if (attr === "paintFirst") {
8750
8752
  const fillIndex = value.indexOf(FILL);
8751
8753
  const strokeIndex = value.indexOf(STROKE);
8752
8754
  ouputValue = FILL;
@@ -16125,6 +16127,12 @@
16125
16127
  /** Peak rise = (period / 2) × this factor: 6.75 text units at the reference size. */
16126
16128
  const SQUIGGLY_LINE_WAVE_RISE_FACTOR = 5 * .45;
16127
16129
  /**
16130
+ * *PMW* `Math.max` over the finite candidates only. A NaN or infinite reach (a character
16131
+ * bound poisoned by bad input) must never size a cache canvas: `canvas.width = NaN` is 0 and
16132
+ * the next `drawImage` of that canvas throws.
16133
+ */
16134
+ const maxFinite = (current, ...candidates) => candidates.reduce((max, candidate) => Number.isFinite(candidate) ? Math.max(max, candidate) : max, current);
16135
+ /**
16128
16136
  * Text class
16129
16137
  * @see {@link http://fabric5.fabricjs.com/fabric-intro-part-2#text}
16130
16138
  */
@@ -16347,16 +16355,16 @@
16347
16355
  for (let charIndex = 0; bounds && charIndex < this._textLines[lineIndex].length; charIndex++) {
16348
16356
  const box = bounds[charIndex], ink = box.ink;
16349
16357
  if (!ink) continue;
16350
- horizontal = isRtl ? Math.max(horizontal, ink.left, ink.right - box.width) : Math.max(horizontal, ink.left - box.left - leftOffset, box.left + ink.right - rightEdge);
16351
- if (lineIndex === 0) vertical = Math.max(vertical, ink.ascent - box.deltaY - baselineFromTop);
16352
- if (lineIndex === lineCount - 1) vertical = Math.max(vertical, ink.descent + box.deltaY - roomBelowBaseline);
16358
+ horizontal = isRtl ? maxFinite(horizontal, ink.left, ink.right - box.width) : maxFinite(horizontal, ink.left - box.left - leftOffset, box.left + ink.right - rightEdge);
16359
+ if (lineIndex === 0) vertical = maxFinite(vertical, ink.ascent - box.deltaY - baselineFromTop);
16360
+ if (lineIndex === lineCount - 1) vertical = maxFinite(vertical, ink.descent + box.deltaY - roomBelowBaseline);
16353
16361
  }
16354
16362
  lineTop += this.getHeightOfLine(lineIndex);
16355
16363
  }
16356
16364
  const strokeReach = this.stroke ? this.strokeWidth / 2 : 0;
16357
16365
  return {
16358
- horizontal: Math.max(0, horizontal + strokeReach),
16359
- vertical: Math.max(0, vertical + strokeReach)
16366
+ horizontal: maxFinite(0, horizontal + strokeReach),
16367
+ vertical: maxFinite(0, vertical + strokeReach)
16360
16368
  };
16361
16369
  }
16362
16370
  /**