@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.cjs +33 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +33 -5
- package/dist/index.js.map +1 -1
- package/dist/{svgTextToPath-CBcIgtk1.cjs → svgTextToPath-B4SihUQv.cjs} +40 -17
- package/dist/svgTextToPath-B4SihUQv.cjs.map +1 -0
- package/dist/{svgTextToPath-CShDi4Ky.js → svgTextToPath-BmOzWJsV.js} +40 -17
- package/dist/svgTextToPath-BmOzWJsV.js.map +1 -0
- package/package.json +1 -1
- package/dist/svgTextToPath-CBcIgtk1.cjs.map +0 -1
- package/dist/svgTextToPath-CShDi4Ky.js.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -14700,6 +14700,13 @@ function containsDevanagari(text) {
|
|
|
14700
14700
|
}
|
|
14701
14701
|
return false;
|
|
14702
14702
|
}
|
|
14703
|
+
function containsSymbol(text) {
|
|
14704
|
+
if (!text) return false;
|
|
14705
|
+
for (const char of text) {
|
|
14706
|
+
if (classifyChar(char) === "symbol") return true;
|
|
14707
|
+
}
|
|
14708
|
+
return false;
|
|
14709
|
+
}
|
|
14703
14710
|
function isBasicLatinOrLatin1(char) {
|
|
14704
14711
|
const c = char.codePointAt(0) ?? 0;
|
|
14705
14712
|
return c <= 591;
|
|
@@ -14732,7 +14739,7 @@ function rewriteSvgFontsForJsPDF(svgStr) {
|
|
|
14732
14739
|
var _a, _b;
|
|
14733
14740
|
const parser = new DOMParser();
|
|
14734
14741
|
const doc = parser.parseFromString(svgStr, "image/svg+xml");
|
|
14735
|
-
const
|
|
14742
|
+
const allTextEls = Array.from(doc.querySelectorAll("text, tspan, textPath"));
|
|
14736
14743
|
const readStyleToken = (style, prop) => {
|
|
14737
14744
|
var _a2;
|
|
14738
14745
|
const match = style.match(new RegExp(`${prop}\\s*:\\s*([^;]+)`, "i"));
|
|
@@ -14761,7 +14768,17 @@ function rewriteSvgFontsForJsPDF(svgStr) {
|
|
|
14761
14768
|
stylePairs.push(`font-style: normal`);
|
|
14762
14769
|
return stylePairs.join("; ");
|
|
14763
14770
|
};
|
|
14764
|
-
|
|
14771
|
+
const getDepth = (el) => {
|
|
14772
|
+
let depth = 0;
|
|
14773
|
+
let current = el.parentElement;
|
|
14774
|
+
while (current) {
|
|
14775
|
+
depth++;
|
|
14776
|
+
current = current.parentElement;
|
|
14777
|
+
}
|
|
14778
|
+
return depth;
|
|
14779
|
+
};
|
|
14780
|
+
const sourceMeta = /* @__PURE__ */ new Map();
|
|
14781
|
+
for (const el of allTextEls) {
|
|
14765
14782
|
const inlineStyle = el.getAttribute("style") || "";
|
|
14766
14783
|
const rawFf = resolveInheritedValue(el, "font-family");
|
|
14767
14784
|
if (!rawFf) continue;
|
|
@@ -14773,12 +14790,21 @@ function rewriteSvgFontsForJsPDF(svgStr) {
|
|
|
14773
14790
|
const resolved = resolveFontWeight(weight);
|
|
14774
14791
|
const isItalic = /italic|oblique/i.test(styleRaw);
|
|
14775
14792
|
const jsPdfName = getEmbeddedJsPDFFontName(clean, resolved, isItalic);
|
|
14793
|
+
sourceMeta.set(el, { clean, resolved, isItalic, jsPdfName, inlineStyle, weight });
|
|
14794
|
+
}
|
|
14795
|
+
const textEls = allTextEls.sort((a, b) => getDepth(b) - getDepth(a));
|
|
14796
|
+
for (const el of textEls) {
|
|
14797
|
+
if (!el.isConnected) continue;
|
|
14798
|
+
const meta = sourceMeta.get(el);
|
|
14799
|
+
if (!meta) continue;
|
|
14800
|
+
const { clean, resolved, isItalic, jsPdfName, inlineStyle, weight } = meta;
|
|
14776
14801
|
el.setAttribute("data-source-font-family", clean);
|
|
14777
14802
|
el.setAttribute("data-source-font-weight", String(resolved));
|
|
14778
14803
|
el.setAttribute("data-source-font-style", isItalic ? "italic" : "normal");
|
|
14779
14804
|
const directText = Array.from(el.childNodes).filter((n) => n.nodeType === 3).map((n) => n.textContent || "").join("");
|
|
14780
14805
|
const hasDevanagari = containsDevanagari(directText);
|
|
14781
|
-
|
|
14806
|
+
const hasSymbol = containsSymbol(directText);
|
|
14807
|
+
if ((hasDevanagari || hasSymbol) && directText.length > 0) {
|
|
14782
14808
|
const devanagariWeight = resolveFontWeight(weight);
|
|
14783
14809
|
const devanagariJsPdfName = getEmbeddedJsPDFFontName(FONT_FALLBACK_DEVANAGARI, devanagariWeight);
|
|
14784
14810
|
const symbolJsPdfName = isFontAvailable(FONT_FALLBACK_SYMBOLS) ? getEmbeddedJsPDFFontName(FONT_FALLBACK_SYMBOLS, 400) : jsPdfName;
|
|
@@ -14786,7 +14812,7 @@ function rewriteSvgFontsForJsPDF(svgStr) {
|
|
|
14786
14812
|
for (const node of childNodes) {
|
|
14787
14813
|
if (node.nodeType !== 3 || !node.textContent) continue;
|
|
14788
14814
|
const runs = splitIntoRuns(node.textContent);
|
|
14789
|
-
if (runs.length <= 1 && ((_b = runs[0]) == null ? void 0 : _b.runType)
|
|
14815
|
+
if (runs.length <= 1 && ((_b = runs[0]) == null ? void 0 : _b.runType) === "main") continue;
|
|
14790
14816
|
const fragment = doc.createDocumentFragment();
|
|
14791
14817
|
for (const run of runs) {
|
|
14792
14818
|
const tspan = doc.createElementNS("http://www.w3.org/2000/svg", "tspan");
|
|
@@ -14837,6 +14863,8 @@ async function embedFontsInPdf(pdf, fontFamilies, fontBaseUrl) {
|
|
|
14837
14863
|
const embedded = /* @__PURE__ */ new Set();
|
|
14838
14864
|
const weights = [300, 400, 500, 600, 700];
|
|
14839
14865
|
const tasks = [];
|
|
14866
|
+
fontFamilies.add(FONT_FALLBACK_SYMBOLS);
|
|
14867
|
+
fontFamilies.add(FONT_FALLBACK_DEVANAGARI);
|
|
14840
14868
|
for (const family of fontFamilies) {
|
|
14841
14869
|
if (!isFontAvailable(family)) {
|
|
14842
14870
|
console.warn(`[pdf-fonts] No TTF mapping for "${family}" — will use Helvetica fallback`);
|
|
@@ -16302,7 +16330,7 @@ async function assemblePdfFromSvgs(svgResults, options = {}) {
|
|
|
16302
16330
|
}
|
|
16303
16331
|
if (shouldOutlineText) {
|
|
16304
16332
|
try {
|
|
16305
|
-
const { convertAllTextToPath } = await Promise.resolve().then(() => require("./svgTextToPath-
|
|
16333
|
+
const { convertAllTextToPath } = await Promise.resolve().then(() => require("./svgTextToPath-B4SihUQv.cjs"));
|
|
16306
16334
|
pageSvg = await convertAllTextToPath(pageSvg, fontBaseUrl, { mode: outlineSubMode });
|
|
16307
16335
|
try {
|
|
16308
16336
|
dumpSvgTextDiagnostics(pageSvg, i, PARITY_TAG, "STAGE-1b-after-text-to-path-raw");
|