pptx-glimpse 0.2.0 → 0.2.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.
package/dist/index.cjs CHANGED
@@ -2078,14 +2078,16 @@ function measureTextWidth(text, fontSizePt, bold, fontFamily, fontFamilyEa) {
2078
2078
  const codePoint = char.codePointAt(0);
2079
2079
  const isEa = isCjkCodePoint(codePoint);
2080
2080
  const metrics = isEa && eaMetrics ? eaMetrics : latinMetrics;
2081
+ let charWidth;
2081
2082
  if (metrics) {
2082
- totalWidth += measureCharMetrics(char, codePoint, baseSizePx, metrics);
2083
+ charWidth = measureCharMetrics(char, codePoint, baseSizePx, metrics);
2083
2084
  } else {
2084
- totalWidth += measureCharHeuristic(codePoint, baseSizePx);
2085
+ charWidth = measureCharHeuristic(codePoint, baseSizePx);
2085
2086
  }
2086
- }
2087
- if (bold) {
2088
- totalWidth *= BOLD_FACTOR;
2087
+ if (bold && !isEa) {
2088
+ charWidth *= BOLD_FACTOR;
2089
+ }
2090
+ totalWidth += charWidth;
2089
2091
  }
2090
2092
  return totalWidth;
2091
2093
  }
@@ -7939,11 +7941,16 @@ var OpentypeTextMeasurer = class {
7939
7941
  const fontSizePx = fontSizePt * PX_PER_PT3;
7940
7942
  const scale = fontSizePx / font.unitsPerEm;
7941
7943
  let totalWidth = 0;
7944
+ const chars = [...text];
7942
7945
  const glyphs = font.stringToGlyphs(text);
7943
- for (const glyph of glyphs) {
7944
- totalWidth += (glyph.advanceWidth ?? font.unitsPerEm * 0.6) * scale;
7946
+ for (let i = 0; i < glyphs.length; i++) {
7947
+ let charWidth = (glyphs[i].advanceWidth ?? font.unitsPerEm * 0.6) * scale;
7948
+ const codePoint = chars[i]?.codePointAt(0);
7949
+ if (bold && (codePoint === void 0 || !isCjkCodePoint(codePoint))) {
7950
+ charWidth *= BOLD_FACTOR2;
7951
+ }
7952
+ totalWidth += charWidth;
7945
7953
  }
7946
- if (bold) totalWidth *= BOLD_FACTOR2;
7947
7954
  return totalWidth;
7948
7955
  }
7949
7956
  getLineHeightRatio(fontFamily, fontFamilyEa) {
package/dist/index.js CHANGED
@@ -2035,14 +2035,16 @@ function measureTextWidth(text, fontSizePt, bold, fontFamily, fontFamilyEa) {
2035
2035
  const codePoint = char.codePointAt(0);
2036
2036
  const isEa = isCjkCodePoint(codePoint);
2037
2037
  const metrics = isEa && eaMetrics ? eaMetrics : latinMetrics;
2038
+ let charWidth;
2038
2039
  if (metrics) {
2039
- totalWidth += measureCharMetrics(char, codePoint, baseSizePx, metrics);
2040
+ charWidth = measureCharMetrics(char, codePoint, baseSizePx, metrics);
2040
2041
  } else {
2041
- totalWidth += measureCharHeuristic(codePoint, baseSizePx);
2042
+ charWidth = measureCharHeuristic(codePoint, baseSizePx);
2042
2043
  }
2043
- }
2044
- if (bold) {
2045
- totalWidth *= BOLD_FACTOR;
2044
+ if (bold && !isEa) {
2045
+ charWidth *= BOLD_FACTOR;
2046
+ }
2047
+ totalWidth += charWidth;
2046
2048
  }
2047
2049
  return totalWidth;
2048
2050
  }
@@ -7896,11 +7898,16 @@ var OpentypeTextMeasurer = class {
7896
7898
  const fontSizePx = fontSizePt * PX_PER_PT3;
7897
7899
  const scale = fontSizePx / font.unitsPerEm;
7898
7900
  let totalWidth = 0;
7901
+ const chars = [...text];
7899
7902
  const glyphs = font.stringToGlyphs(text);
7900
- for (const glyph of glyphs) {
7901
- totalWidth += (glyph.advanceWidth ?? font.unitsPerEm * 0.6) * scale;
7903
+ for (let i = 0; i < glyphs.length; i++) {
7904
+ let charWidth = (glyphs[i].advanceWidth ?? font.unitsPerEm * 0.6) * scale;
7905
+ const codePoint = chars[i]?.codePointAt(0);
7906
+ if (bold && (codePoint === void 0 || !isCjkCodePoint(codePoint))) {
7907
+ charWidth *= BOLD_FACTOR2;
7908
+ }
7909
+ totalWidth += charWidth;
7902
7910
  }
7903
- if (bold) totalWidth *= BOLD_FACTOR2;
7904
7911
  return totalWidth;
7905
7912
  }
7906
7913
  getLineHeightRatio(fontFamily, fontFamilyEa) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pptx-glimpse",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "A Node.js library to render PPTX as SVG / PNG.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -62,7 +62,7 @@
62
62
  "author": "hirokisakabe",
63
63
  "license": "MIT",
64
64
  "dependencies": {
65
- "fast-xml-parser": "^4.5.0",
65
+ "fast-xml-parser": "^5.3.6",
66
66
  "fflate": "^0.8.2",
67
67
  "opentype.js": "^1.3.4",
68
68
  "sharp": "^0.34.5"