@pixldocs/canvas-renderer 0.5.91 → 0.5.92

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.js CHANGED
@@ -14681,6 +14681,13 @@ function containsDevanagari(text) {
14681
14681
  }
14682
14682
  return false;
14683
14683
  }
14684
+ function containsSymbol(text) {
14685
+ if (!text) return false;
14686
+ for (const char of text) {
14687
+ if (classifyChar(char) === "symbol") return true;
14688
+ }
14689
+ return false;
14690
+ }
14684
14691
  function isBasicLatinOrLatin1(char) {
14685
14692
  const c = char.codePointAt(0) ?? 0;
14686
14693
  return c <= 591;
@@ -14713,7 +14720,7 @@ function rewriteSvgFontsForJsPDF(svgStr) {
14713
14720
  var _a, _b;
14714
14721
  const parser = new DOMParser();
14715
14722
  const doc = parser.parseFromString(svgStr, "image/svg+xml");
14716
- const textEls = doc.querySelectorAll("text, tspan, textPath");
14723
+ const allTextEls = Array.from(doc.querySelectorAll("text, tspan, textPath"));
14717
14724
  const readStyleToken = (style, prop) => {
14718
14725
  var _a2;
14719
14726
  const match = style.match(new RegExp(`${prop}\\s*:\\s*([^;]+)`, "i"));
@@ -14742,7 +14749,17 @@ function rewriteSvgFontsForJsPDF(svgStr) {
14742
14749
  stylePairs.push(`font-style: normal`);
14743
14750
  return stylePairs.join("; ");
14744
14751
  };
14745
- for (const el of textEls) {
14752
+ const getDepth = (el) => {
14753
+ let depth = 0;
14754
+ let current = el.parentElement;
14755
+ while (current) {
14756
+ depth++;
14757
+ current = current.parentElement;
14758
+ }
14759
+ return depth;
14760
+ };
14761
+ const sourceMeta = /* @__PURE__ */ new Map();
14762
+ for (const el of allTextEls) {
14746
14763
  const inlineStyle = el.getAttribute("style") || "";
14747
14764
  const rawFf = resolveInheritedValue(el, "font-family");
14748
14765
  if (!rawFf) continue;
@@ -14754,12 +14771,21 @@ function rewriteSvgFontsForJsPDF(svgStr) {
14754
14771
  const resolved = resolveFontWeight(weight);
14755
14772
  const isItalic = /italic|oblique/i.test(styleRaw);
14756
14773
  const jsPdfName = getEmbeddedJsPDFFontName(clean, resolved, isItalic);
14774
+ sourceMeta.set(el, { clean, resolved, isItalic, jsPdfName, inlineStyle, weight });
14775
+ }
14776
+ const textEls = allTextEls.sort((a, b) => getDepth(b) - getDepth(a));
14777
+ for (const el of textEls) {
14778
+ if (!el.isConnected) continue;
14779
+ const meta = sourceMeta.get(el);
14780
+ if (!meta) continue;
14781
+ const { clean, resolved, isItalic, jsPdfName, inlineStyle, weight } = meta;
14757
14782
  el.setAttribute("data-source-font-family", clean);
14758
14783
  el.setAttribute("data-source-font-weight", String(resolved));
14759
14784
  el.setAttribute("data-source-font-style", isItalic ? "italic" : "normal");
14760
14785
  const directText = Array.from(el.childNodes).filter((n) => n.nodeType === 3).map((n) => n.textContent || "").join("");
14761
14786
  const hasDevanagari = containsDevanagari(directText);
14762
- if (hasDevanagari && directText.length > 0) {
14787
+ const hasSymbol = containsSymbol(directText);
14788
+ if ((hasDevanagari || hasSymbol) && directText.length > 0) {
14763
14789
  const devanagariWeight = resolveFontWeight(weight);
14764
14790
  const devanagariJsPdfName = getEmbeddedJsPDFFontName(FONT_FALLBACK_DEVANAGARI, devanagariWeight);
14765
14791
  const symbolJsPdfName = isFontAvailable(FONT_FALLBACK_SYMBOLS) ? getEmbeddedJsPDFFontName(FONT_FALLBACK_SYMBOLS, 400) : jsPdfName;
@@ -14767,7 +14793,7 @@ function rewriteSvgFontsForJsPDF(svgStr) {
14767
14793
  for (const node of childNodes) {
14768
14794
  if (node.nodeType !== 3 || !node.textContent) continue;
14769
14795
  const runs = splitIntoRuns(node.textContent);
14770
- if (runs.length <= 1 && ((_b = runs[0]) == null ? void 0 : _b.runType) !== "devanagari") continue;
14796
+ if (runs.length <= 1 && ((_b = runs[0]) == null ? void 0 : _b.runType) === "main") continue;
14771
14797
  const fragment = doc.createDocumentFragment();
14772
14798
  for (const run of runs) {
14773
14799
  const tspan = doc.createElementNS("http://www.w3.org/2000/svg", "tspan");
@@ -14818,6 +14844,8 @@ async function embedFontsInPdf(pdf, fontFamilies, fontBaseUrl) {
14818
14844
  const embedded = /* @__PURE__ */ new Set();
14819
14845
  const weights = [300, 400, 500, 600, 700];
14820
14846
  const tasks = [];
14847
+ fontFamilies.add(FONT_FALLBACK_SYMBOLS);
14848
+ fontFamilies.add(FONT_FALLBACK_DEVANAGARI);
14821
14849
  for (const family of fontFamilies) {
14822
14850
  if (!isFontAvailable(family)) {
14823
14851
  console.warn(`[pdf-fonts] No TTF mapping for "${family}" — will use Helvetica fallback`);
@@ -16283,7 +16311,7 @@ async function assemblePdfFromSvgs(svgResults, options = {}) {
16283
16311
  }
16284
16312
  if (shouldOutlineText) {
16285
16313
  try {
16286
- const { convertAllTextToPath } = await import("./svgTextToPath-CShDi4Ky.js");
16314
+ const { convertAllTextToPath } = await import("./svgTextToPath-BmOzWJsV.js");
16287
16315
  pageSvg = await convertAllTextToPath(pageSvg, fontBaseUrl, { mode: outlineSubMode });
16288
16316
  try {
16289
16317
  dumpSvgTextDiagnostics(pageSvg, i, PARITY_TAG, "STAGE-1b-after-text-to-path-raw");