@openpresentation/opf-render 0.34.0 → 0.34.2
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/charts.js +3 -0
- package/dist/font-demand.js +8 -9
- package/dist/font-manifest.js +7 -7
- package/dist/font-registry.js +6 -35
- package/dist/fonts-node.d.ts +1 -1
- package/dist/fonts-node.js +10 -4
- package/dist/index.d.ts +3 -4
- package/dist/pdf-fonts.js +3 -7
- package/dist/pdf-text.js +75 -19
- package/dist/pdf-vector.js +16 -15
- package/dist/raster-text.js +4 -6
- package/dist/script-font-message.js +9 -0
- package/dist/svg.d.ts +3 -4
- package/dist/svg.js +2 -1
- package/dist/text-paths.js +4 -13
- package/package.json +10 -10
package/dist/charts.js
CHANGED
|
@@ -192,6 +192,9 @@ export function renderCatalogChart(item, box, bound, options, svg) {
|
|
|
192
192
|
// RR-35: a chart with axis titles, a legend position or data labels reserves their space before the plot is laid out. A chart
|
|
193
193
|
// with none of them skips this block entirely, so its output is unchanged. LH-03: a small chart's default value labels count as data labels.
|
|
194
194
|
const resolved = chartLayerDataLabels(resolveOptions(item.value, authoredSpec), layer, spec.kind);
|
|
195
|
+
const doughnutFit = layer?.doughnut?.labels;
|
|
196
|
+
const fitReport = doughnutFit && { code: "chart-option-adapted", option: "dataLabels.content", reason: "unsupported-content", message: `The labels of a doughnut sit inside their slices, and '${doughnutFit.from.join(', ')}' does not fit the ring, so ${doughnutFit.content ? `they show '${doughnutFit.content.join(', ')}' instead (the legend names the slices)` : 'no labels are drawn (the legend names the slices)'}.` };
|
|
197
|
+
if (fitReport && authoredSpec) resolved.diagnostics = [...resolved.diagnostics, fitReport];
|
|
195
198
|
// FA-14: a highlight changes colours only (no space is reserved), so it is resolved whether or not an option is active.
|
|
196
199
|
c.highlight = highlightFor(c, resolved, spec, data) ?? focusFor(c, layer, spec) ?? emphasisFor(c, layer);
|
|
197
200
|
// LH-03, LH-142: no value axis (a small chart's labels or a horizontal stacked bar chart's segment values carry the values): core decides it.
|
package/dist/font-demand.js
CHANGED
|
@@ -4,6 +4,7 @@ import { FONT_SELECTION_METADATA } from './font-selection-metadata.js';
|
|
|
4
4
|
import { createFontRegistry, pickFace, OPFFontError } from './font-registry.js';
|
|
5
5
|
import { createFontAnalysis } from './lazy-fonts.js';
|
|
6
6
|
import { scriptFontAliases } from './script-fonts.js';
|
|
7
|
+
import { scriptFontNotInstalledMessage } from './script-font-message.js';
|
|
7
8
|
import {
|
|
8
9
|
analyzePresentationScripts,
|
|
9
10
|
createScriptAnalysis,
|
|
@@ -463,7 +464,7 @@ export async function createNodeDemand(
|
|
|
463
464
|
optional = selected.filter((pkg) => !required(pkg));
|
|
464
465
|
const batches = await Promise.all([
|
|
465
466
|
loadPackages(mandatory, undefined, {
|
|
466
|
-
what: '
|
|
467
|
+
what: 'This presentation',
|
|
467
468
|
}),
|
|
468
469
|
loadPackages(optional, missing),
|
|
469
470
|
]);
|
|
@@ -509,14 +510,12 @@ export async function createNodeDemand(
|
|
|
509
510
|
loaded.selection.notInstalled.push(item.package);
|
|
510
511
|
notify(
|
|
511
512
|
'script-font-not-installed',
|
|
512
|
-
{ package: item.package, scripts: item.scripts },
|
|
513
|
-
|
|
514
|
-
item.package +
|
|
515
|
-
|
|
516
|
-
item.version
|
|
517
|
-
|
|
518
|
-
item.scripts.join(', ') +
|
|
519
|
-
' text with its designated open font.',
|
|
513
|
+
{ package: item.package, version: item.version, scripts: item.scripts },
|
|
514
|
+
scriptFontNotInstalledMessage(
|
|
515
|
+
'Install ' + item.package + '@' + item.version + ' to preview ' + item.scripts.join(', ') + ' text with its designated open font.',
|
|
516
|
+
item.package,
|
|
517
|
+
item.version,
|
|
518
|
+
),
|
|
520
519
|
onDiagnostic,
|
|
521
520
|
);
|
|
522
521
|
}
|
package/dist/font-manifest.js
CHANGED
|
@@ -2434,15 +2434,15 @@ export const BUNDLED_FONT_MANIFEST=freeze({
|
|
|
2434
2434
|
},
|
|
2435
2435
|
{
|
|
2436
2436
|
"name": "@expo-google-fonts/noto-sans-mongolian",
|
|
2437
|
-
"version": "0.4.
|
|
2437
|
+
"version": "0.4.2",
|
|
2438
2438
|
"pack": "scripts",
|
|
2439
2439
|
"scripts": [
|
|
2440
2440
|
"Mong"
|
|
2441
2441
|
],
|
|
2442
|
-
"source": "https://www.npmjs.com/package/@expo-google-fonts/noto-sans-mongolian/v/0.4.
|
|
2442
|
+
"source": "https://www.npmjs.com/package/@expo-google-fonts/noto-sans-mongolian/v/0.4.2",
|
|
2443
2443
|
"license": "OFL-1.1",
|
|
2444
2444
|
"licenseFile": "LICENSE_FONT",
|
|
2445
|
-
"licenseSha256": "
|
|
2445
|
+
"licenseSha256": "dbaad9386f1579930e60139d1cf36913da6c45f032433798bb8bf2e5912c8467",
|
|
2446
2446
|
"reservedFontNames": [],
|
|
2447
2447
|
"upstream": "https://github.com/notofonts/mongolian",
|
|
2448
2448
|
"copyright": "Copyright 2022 The Noto Project Authors (https://github.com/notofonts/mongolian)",
|
|
@@ -2452,7 +2452,7 @@ export const BUNDLED_FONT_MANIFEST=freeze({
|
|
|
2452
2452
|
"family": "Noto Sans Mongolian",
|
|
2453
2453
|
"weight": 400,
|
|
2454
2454
|
"italic": false,
|
|
2455
|
-
"sha256": "
|
|
2455
|
+
"sha256": "009317e64d43aae7daa08657d1dd0259c5f603faba1ee8f4b4d729b8c462864d"
|
|
2456
2456
|
}
|
|
2457
2457
|
]
|
|
2458
2458
|
},
|
|
@@ -2551,7 +2551,7 @@ export const BUNDLED_FONT_MANIFEST=freeze({
|
|
|
2551
2551
|
},
|
|
2552
2552
|
{
|
|
2553
2553
|
"name": "@expo-google-fonts/noto-color-emoji",
|
|
2554
|
-
"version": "0.4.
|
|
2554
|
+
"version": "0.4.8",
|
|
2555
2555
|
"pack": "scripts",
|
|
2556
2556
|
"scripts": [
|
|
2557
2557
|
"Zsye"
|
|
@@ -2560,7 +2560,7 @@ export const BUNDLED_FONT_MANIFEST=freeze({
|
|
|
2560
2560
|
"format": "COLRv1, SVG",
|
|
2561
2561
|
"rasterFamily": "Noto Emoji"
|
|
2562
2562
|
},
|
|
2563
|
-
"source": "https://www.npmjs.com/package/@expo-google-fonts/noto-color-emoji/v/0.4.
|
|
2563
|
+
"source": "https://www.npmjs.com/package/@expo-google-fonts/noto-color-emoji/v/0.4.8",
|
|
2564
2564
|
"license": "OFL-1.1",
|
|
2565
2565
|
"licenseFile": "LICENSE_FONT",
|
|
2566
2566
|
"licenseSha256": "ac564676d10054a8445923dfc2dfb13c042d97888bd27c1b6ec6dfe89a9d8d62",
|
|
@@ -2573,7 +2573,7 @@ export const BUNDLED_FONT_MANIFEST=freeze({
|
|
|
2573
2573
|
"family": "Noto Color Emoji",
|
|
2574
2574
|
"weight": 400,
|
|
2575
2575
|
"italic": false,
|
|
2576
|
-
"sha256": "
|
|
2576
|
+
"sha256": "d8c8a5e2eaecf93bf46be895640139d344ace174e2cdb6b0d988f7e83fd97844"
|
|
2577
2577
|
}
|
|
2578
2578
|
]
|
|
2579
2579
|
},
|
package/dist/font-registry.js
CHANGED
|
@@ -27,7 +27,8 @@ function validFamily(family) {
|
|
|
27
27
|
}
|
|
28
28
|
// The open families load with the office pack (loadFonts({pack:"office"})).
|
|
29
29
|
|
|
30
|
-
const
|
|
30
|
+
const packageFor = family => BUNDLED_FONT_MANIFEST.packages.find(pkg=>pkg.renamedFrom?.toLowerCase()===family.toLowerCase() || pkg.faces.some(face=>face.family.toLowerCase()===family.toLowerCase()));
|
|
31
|
+
const packFor = family => { const pack = packageFor(family)?.pack; return pack==="open" ? "office" : pack; };
|
|
31
32
|
const percent = value => `${(value*100).toFixed(1)}%`;
|
|
32
33
|
/** FF-31: say why a family has no face and what the caller can do, from the OPF font policy. */
|
|
33
34
|
function unavailableFontError(family, style, policy) {
|
|
@@ -36,8 +37,9 @@ function unavailableFontError(family, style, policy) {
|
|
|
36
37
|
if (!row) return new OPFFontError("font-unavailable", `No local font face for '${family}'. '${family}' is not in the OPF font policy table, so there is no declared replacement: ${hook}, add an alias, or set fallbackFamily.`, {...details, licenseClass:"unknown"});
|
|
37
38
|
Object.assign(details, {licenseClass:row.licenseClass});
|
|
38
39
|
if (!row.replacement) {
|
|
39
|
-
const pack = packFor(family);
|
|
40
|
-
|
|
40
|
+
const pack = packFor(family), npm = pack === "scripts" ? packageFor(family) : undefined;
|
|
41
|
+
const how = npm ? `; install ${npm.name}@${npm.version} (an optional npm package of the 'scripts' font pack)` : pack ? `; load the '${pack}' font pack` : undefined;
|
|
42
|
+
return new OPFFontError("font-unavailable", `No local font face for '${family}'. '${family}' is ${row.licenseClass === "open" ? `openly licensed (${row.license})` : row.license}${how ?? `; no pinned renderer pack ships it yet, so supply its font files (for example from @expo-google-fonts/${family.toLowerCase().replace(/ +/g,"-")})`}.`, {...details, ...(pack?{pack}:{}), ...(npm?{package:npm.name, version:npm.version}:{})});
|
|
41
43
|
}
|
|
42
44
|
const {family:replacement, compatibility, measured} = row.replacement;
|
|
43
45
|
const candidates = [replacement, ...(row.alternates ?? [])], packs = [...new Set(candidates.map(packFor).filter(Boolean))];
|
|
@@ -51,27 +53,6 @@ function unavailableFontError(family, style, policy) {
|
|
|
51
53
|
return new OPFFontError("font-unavailable", `No local font face for '${family}'. ${owner} None of its replacements (${candidates.join(", ")}) is loaded${packs.length ? `; load the ${packs.map(pack=>"'"+pack+"'").join(" or ")} font pack` : ""}, or ${hook}. The PPTX names '${family}' either way.`, details);
|
|
52
54
|
}
|
|
53
55
|
/** Local font files only. The caller explicitly chooses aliases and fallback. */
|
|
54
|
-
// fontkit 2.0.4 cannot decode every OpenType lookup: its GSUB type 8 (reverse chaining contextual single substitution) struct lacks the
|
|
55
|
-
// backtrackGlyphCount field, so the lookup fails with "Not a fixed size" when a feature that references it is applied, and it has no processor
|
|
56
|
-
// for the type anyway. Noto Sans Mongolian 3.x has such a lookup under calt and rclt in every script, so every shaping of the face threw (FF-44).
|
|
57
|
-
// A lookup that cannot be decoded is treated as one that applies nothing (no subtables), so the rest of the feature still runs: advances equal
|
|
58
|
-
// a browser's for the face's Latin and Mongolian samples (test/mongolian-shaping.mjs). Applied only after shaping failed, once per font.
|
|
59
|
-
const lookupsGuarded = new WeakSet();
|
|
60
|
-
export function skipUndecodableLookups(font) {
|
|
61
|
-
if (lookupsGuarded.has(font)) return false;
|
|
62
|
-
lookupsGuarded.add(font);
|
|
63
|
-
let guarded = false;
|
|
64
|
-
for (const tag of ["GSUB", "GPOS"]) {
|
|
65
|
-
let list;
|
|
66
|
-
try { list = font[tag]?.lookupList; } catch { continue; }
|
|
67
|
-
if (typeof list?.get !== "function") continue;
|
|
68
|
-
const get = list.get.bind(list);
|
|
69
|
-
list.get = index => { try { return get(index); } catch { return { lookupType: 1, flags: {}, subTables: [] }; } };
|
|
70
|
-
guarded = true;
|
|
71
|
-
}
|
|
72
|
-
return guarded;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
56
|
// opf-render#125: fontkit 2.0.4 caches one Glyph per glyph id (font._glyphs) with the code points of the call that created it, and
|
|
76
57
|
// its layout reads the input's code points back from that cache (glyphsForString -> getGlyph(id, [codePoint]) -> GlyphInfo). A glyph
|
|
77
58
|
// first reached another way keeps other code points: a composite outline (run.bbox for outlineBounds, glyph.path) reaches its
|
|
@@ -349,17 +330,7 @@ export function createFontRegistry(entries, options = {}, {allowEmpty = false, c
|
|
|
349
330
|
throw new OPFFontError("font-shaping-failed", `Font '${face.family}' cannot shape this text with HarfBuzz.`, {path:style.path,fontFamily:face.family,cause:error?.message});
|
|
350
331
|
}
|
|
351
332
|
} else try { run=shape(); }
|
|
352
|
-
catch (error) {
|
|
353
|
-
// A lookup fontkit cannot decode (GSUB type 8 in Noto Sans Mongolian) applies nothing; shape again with the rest (FF-44).
|
|
354
|
-
if (skipUndecodableLookups(face.font)) { try { run=shape(); } catch { /* the mark retry below */ } }
|
|
355
|
-
// fontkit rejects some mark-attachment lookups (null anchors, for example
|
|
356
|
-
// Gurmukhi tippi in Noto Sans Gurmukhi). Mark positioning moves marks
|
|
357
|
-
// without changing advances, so measure again without it (FF-19).
|
|
358
|
-
if (!run) {
|
|
359
|
-
try { run=shape({abvm:false,blwm:false,mark:false,mkmk:false}); }
|
|
360
|
-
catch { throw new OPFFontError("font-shaping-failed", `Font '${face.family}' cannot shape this text.`, {path:style.path,fontFamily:face.family,cause:error?.message}); }
|
|
361
|
-
}
|
|
362
|
-
}
|
|
333
|
+
catch (error) { throw new OPFFontError("font-shaping-failed", `Font '${face.family}' cannot shape this text.`, {path:style.path,fontFamily:face.family,cause:error?.message}); }
|
|
363
334
|
value={width:run.positions.reduce((total,position)=>total+position.xAdvance,0)/face.font.unitsPerEm,...value};
|
|
364
335
|
if(includeOutline) {
|
|
365
336
|
const unit=face.font.unitsPerEm;
|
package/dist/fonts-node.d.ts
CHANGED
|
@@ -38,7 +38,7 @@ export interface ScriptPackOptions {
|
|
|
38
38
|
* `harfbuzz-unavailable` when a harfbuzzjs .wasm (`file`) cannot be loaded, for example in a bundled server that did not ship it:
|
|
39
39
|
* the handle then has no `subsets`, or shapes outlines with fontkit.
|
|
40
40
|
*/
|
|
41
|
-
onDiagnostic?: (diagnostic: {code: string; message: string; script?: string; package?: string; scripts?: string[]; file?: string}) => void;
|
|
41
|
+
onDiagnostic?: (diagnostic: {code: string; message: string; script?: string; package?: string; version?: string; scripts?: string[]; file?: string}) => void;
|
|
42
42
|
}
|
|
43
43
|
/** A vendored face that an SVG embeds only when its text names the family (the open families and Intos), and that browser hosts load on demand from a separate hash-pinned file. */
|
|
44
44
|
export interface LazyFont { readonly package: string; readonly family: string; readonly weight: number; readonly italic: boolean; /** Path relative to the package root, for example fonts/intos/Intos-Regular.ttf. */ readonly file: string; readonly sha256: string; readonly license: string; readonly renamedFrom?: string; /** Set on a host's extra lazy face (`extraLazyFonts`, `package: "host"`): where the host serves the file from. */ readonly url?: string }
|
package/dist/fonts-node.js
CHANGED
|
@@ -9,6 +9,7 @@ import { textOutlines } from "./text-paths.js";
|
|
|
9
9
|
import { createSubsetter, fontSubsets } from "./font-subset.js";
|
|
10
10
|
import { createShaper } from "./hb-shape.js";
|
|
11
11
|
import { packageRoot, resolveInstalled } from "./node-resolve.js";
|
|
12
|
+
import { scriptFontNotInstalledMessage } from "./script-font-message.js";
|
|
12
13
|
export { BUNDLED_FONT_MANIFEST } from "./font-manifest.js";
|
|
13
14
|
import { analyzePresentationScripts, autoScriptSelection, createScriptAnalysis, nextFallbackPackage, scriptFontPackages, scriptSelectionOf, uncoveredCjkCharacters } from "./script-font-pack.js";
|
|
14
15
|
export { autoScriptSelection, detectPresentationScripts, scriptFontPackages } from "./script-font-pack.js";
|
|
@@ -36,7 +37,12 @@ function requireInstalled(packages, what) {
|
|
|
36
37
|
});
|
|
37
38
|
if (!missing.length) return;
|
|
38
39
|
const install = `npm install ${missing.map(pkg => `${pkg.name}@${pkg.version}`).join(" ")}`;
|
|
39
|
-
|
|
40
|
+
// The families each package serves here (for a presentation: only the faces it selects), so the message says what needs it.
|
|
41
|
+
const familiesOf = pkg => [...new Set((pkg.faces ?? []).map(face => face.family).filter(Boolean))];
|
|
42
|
+
const faces = [...new Set(missing.flatMap(familiesOf))];
|
|
43
|
+
const named = missing.map(pkg => { const families = familiesOf(pkg); return families.length ? `${pkg.name} (${families.join(", ")})` : pkg.name; }).join(", ");
|
|
44
|
+
const one = missing.length === 1;
|
|
45
|
+
throw new OPFFontError("font-resource-unavailable", `${what} needs ${one ? "a font package that is" : "font packages that are"} not installed (${one ? "an optional peer dependency" : "optional peer dependencies"} of @openpresentation/opf-render): ${named}. Run \`${install}\`.`, {packages: missing.map(pkg => pkg.name), faces, install});
|
|
40
46
|
}
|
|
41
47
|
|
|
42
48
|
// `skipped`: an optional npm package that is not installed is recorded there instead of failing (scripts: 'auto').
|
|
@@ -109,7 +115,7 @@ async function withScripts(loaded, scripts, {presentation, onDiagnostic, renderO
|
|
|
109
115
|
const selection = scriptSelectionOf(analyzePresentationScripts(presentation, undefined, renderOptions)), skipped = [];
|
|
110
116
|
const extra = await loadPackages(notLoaded(scriptFontPackages(selection.scripts)), skipped);
|
|
111
117
|
for (const script of selection.unavailable) onDiagnostic?.({code: "script-font-unavailable", script, message: `No pinned open font serves script '${script}'; that text uses the design font.`});
|
|
112
|
-
for (const item of skipped) onDiagnostic?.({code: "script-font-not-installed", package: item.package, scripts: item.scripts, message: `Install ${item.package}@${item.version} to preview ${item.scripts.join(", ")} text with its designated open font
|
|
118
|
+
for (const item of skipped) onDiagnostic?.({code: "script-font-not-installed", package: item.package, version: item.version, scripts: item.scripts, message: scriptFontNotInstalledMessage(`Install ${item.package}@${item.version} to preview ${item.scripts.join(", ")} text with its designated open font.`, item.package, item.version)});
|
|
113
119
|
return {entries:[...loaded.entries, ...embedUsed(extra.entries)], fontFiles:[...loaded.fontFiles, ...extra.fontFiles], packages:[...(loaded.packages ?? []), ...extra.packages],
|
|
114
120
|
selection:{...selection, packages: scriptFontPackages(selection.scripts).map(item => item.name).filter(name => !skipped.some(item => item.package === name)), notInstalled: skipped.map(item => item.package)}};
|
|
115
121
|
}
|
|
@@ -135,7 +141,7 @@ async function completeFallback(registry, presentation, loaded, onDiagnostic, re
|
|
|
135
141
|
const skipped = [], extra = await loadPackages([next], skipped);
|
|
136
142
|
if (skipped.length) {
|
|
137
143
|
selection.notInstalled.push(next.name);
|
|
138
|
-
onDiagnostic?.({code: "script-font-not-installed", package: next.name, scripts: [...next.scripts], message: `Install ${next.name}@${next.version} for glyphs the loaded CJK faces lack
|
|
144
|
+
onDiagnostic?.({code: "script-font-not-installed", package: next.name, version: next.version, scripts: [...next.scripts], message: scriptFontNotInstalledMessage(`Install ${next.name}@${next.version} for glyphs the loaded CJK faces lack.`, next.name, next.version)});
|
|
139
145
|
continue;
|
|
140
146
|
}
|
|
141
147
|
registry.addFaces(embedUsed(extra.entries));
|
|
@@ -238,7 +244,7 @@ async function ensureFonts(registry, loaded, presentation, {onDiagnostic, render
|
|
|
238
244
|
selection.packages.push(...extra.packages);
|
|
239
245
|
for (const item of skipped) {
|
|
240
246
|
selection.notInstalled.push(item.package);
|
|
241
|
-
onDiagnostic?.({code: "script-font-not-installed", package: item.package, scripts: item.scripts, message: `Install ${item.package}@${item.version} to preview ${item.scripts.join(", ")} text with its designated open font
|
|
247
|
+
onDiagnostic?.({code: "script-font-not-installed", package: item.package, version: item.version, scripts: item.scripts, message: scriptFontNotInstalledMessage(`Install ${item.package}@${item.version} to preview ${item.scripts.join(", ")} text with its designated open font.`, item.package, item.version)});
|
|
242
248
|
}
|
|
243
249
|
for (const script of wanted.unavailable) if (!selection.unavailable.includes(script)) {
|
|
244
250
|
selection.unavailable.push(script);
|
package/dist/index.d.ts
CHANGED
|
@@ -30,7 +30,7 @@ export declare const engineDefaults: Readonly<{
|
|
|
30
30
|
export type RenderDiagnostic = LayoutDiagnostic | {
|
|
31
31
|
/** A generated RTL numbered marker stayed text; this PNG/raster-PDF marker is not direction-qualified. */
|
|
32
32
|
code: "raster-marker-unavailable";
|
|
33
|
-
reason: "unresolved" | "restricted" | "colour-font" | "
|
|
33
|
+
reason: "unresolved" | "restricted" | "colour-font" | "system-fonts";
|
|
34
34
|
fontFamily?: string;
|
|
35
35
|
message: string;
|
|
36
36
|
} | {
|
|
@@ -41,7 +41,7 @@ export type RenderDiagnostic = LayoutDiagnostic | {
|
|
|
41
41
|
} | {
|
|
42
42
|
/** A run stays text because its face cannot safely be written as outlines. */
|
|
43
43
|
code: "text-as-paths-fallback";
|
|
44
|
-
reason: "colour-font" | "restricted"
|
|
44
|
+
reason: "colour-font" | "restricted";
|
|
45
45
|
fontFamily: string;
|
|
46
46
|
message: string;
|
|
47
47
|
} | {
|
|
@@ -94,8 +94,7 @@ export interface ToSvgOptions {
|
|
|
94
94
|
* given `shapeWasm`), are hidden from assistive technology, and each outlined line is also invisible real text pinned to the
|
|
95
95
|
* drawn width, so screen readers, selection, copy and find-in-page get the words. Each element keeps its `data-opf-*` trace.
|
|
96
96
|
* A run stays text, reported as `text-as-paths-fallback` with a `reason`, when its font is a colour or bitmap font
|
|
97
|
-
* (`"colour-font"`)
|
|
98
|
-
* layout's measurement disagree on it (`"shaping"`). Use it for thumbnails, previews and portable SVG files, not for an editing
|
|
97
|
+
* (`"colour-font"`) or its face's fsType restricts embedding (`"restricted"`). Use it for thumbnails, previews and portable SVG files, not for an editing
|
|
99
98
|
* surface or the vector PDF (which keeps real text from `<text>` SVG).
|
|
100
99
|
*/
|
|
101
100
|
text?: "fonts" | "system" | "paths";
|
package/dist/pdf-fonts.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { create } from "fontkit";
|
|
2
|
-
import { skipUndecodableLookups } from "./font-registry.js";
|
|
3
2
|
import { isTrueTypeOutlines, subsetTrueType } from "./pdf-subset.js";
|
|
4
3
|
import { hex, name, num, sha256, textString, utf16Hex } from "./pdf-writer.js";
|
|
5
4
|
|
|
@@ -181,8 +180,8 @@ function bestStyle(group, weight, italic) {
|
|
|
181
180
|
/**
|
|
182
181
|
* Shape `text` with `face` and return glyphs left to right: {gid, codePoints, advance, xOffset, yOffset} in font units.
|
|
183
182
|
* `direction` is "ltr" or "rtl" (the caller has already applied the bidirectional algorithm), `features` an object of
|
|
184
|
-
* OpenType feature booleans, `language` an OpenType language tag.
|
|
185
|
-
*
|
|
183
|
+
* OpenType feature booleans, `language` an OpenType language tag. Text that fontkit cannot shape is drawn with the
|
|
184
|
+
* font's plain character mapping.
|
|
186
185
|
*/
|
|
187
186
|
export function shape(face, text, { features, language, direction } = {}) {
|
|
188
187
|
const font = face.font;
|
|
@@ -191,10 +190,7 @@ export function shape(face, text, { features, language, direction } = {}) {
|
|
|
191
190
|
return font.layout(text, merged, undefined, language, direction);
|
|
192
191
|
};
|
|
193
192
|
let run;
|
|
194
|
-
try { run = attempt(); } catch {
|
|
195
|
-
if (skipUndecodableLookups(font)) { try { run = attempt(); } catch { /* fall through */ } }
|
|
196
|
-
if (!run) { try { run = attempt({ abvm: false, blwm: false, mark: false, mkmk: false }); } catch { /* fall through */ } }
|
|
197
|
-
}
|
|
193
|
+
try { run = attempt(); } catch { /* the plain character mapping below */ }
|
|
198
194
|
if (run) {
|
|
199
195
|
return run.glyphs.map((glyph, index) => ({
|
|
200
196
|
gid: glyph.id,
|
package/dist/pdf-text.js
CHANGED
|
@@ -305,19 +305,71 @@ export function actualTextFor(run, glyph) {
|
|
|
305
305
|
const NON_ASCII_SPACE = new RegExp("[" + [" ", " ", " - ", " ", " ", " "].join("") + "]");
|
|
306
306
|
|
|
307
307
|
/**
|
|
308
|
-
* Split a left-to-right run into clusters
|
|
309
|
-
*
|
|
310
|
-
* glyphs
|
|
311
|
-
* and
|
|
308
|
+
* Split a left-to-right run into clusters (the shortest glyph groups whose characters are exactly the next characters of the
|
|
309
|
+
* logical text: a reordered Indic syllable is one cluster) and set `run.clusters` to its words and spaces, or null when the
|
|
310
|
+
* glyphs and the text do not line up. A cluster whose glyphs do not carry its characters in logical order (a pre-base vowel
|
|
311
|
+
* sign or medial drawn before its consonant, a Thai or Lao am split into its nikhahit and aa, a two-part vowel split into its
|
|
312
|
+
* parts) gets its whole logical text on one glyph, the first that advances the pen (else the first), and its other glyphs are
|
|
313
|
+
* `silent`: drawn as text that maps to no character. The glyph-to-Unicode map, read in drawing order, then gives the author's
|
|
314
|
+
* text to readers that ignore /ActualText (pdf.js), and the word's `actual` (its text; for a space the map copies as a plain
|
|
315
|
+
* space, that space) is written as /ActualText for those that honor it. Right-to-left runs keep the shaper's attribution:
|
|
316
|
+
* their glyphs are read back to front, with /ActualText per glyph where that is not enough.
|
|
312
317
|
*/
|
|
313
|
-
export function
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
318
|
+
export function attributeClusters(run) {
|
|
319
|
+
run.clusters = null;
|
|
320
|
+
if (run.level % 2 === 1) return;
|
|
321
|
+
const clusters = alignedClusters(run);
|
|
322
|
+
if (!clusters) return;
|
|
323
|
+
for (const cluster of clusters) {
|
|
324
|
+
if (cluster.inOrder) continue;
|
|
325
|
+
const carrier = cluster.glyphs.find((glyph) => glyph.advance !== 0) ?? cluster.glyphs[0];
|
|
326
|
+
for (const glyph of cluster.glyphs) {
|
|
327
|
+
if (glyph === carrier) glyph.codePoints = [...cluster.text].map((character) => character.codePointAt(0));
|
|
328
|
+
else { glyph.codePoints = []; glyph.silent = true; }
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
// One /ActualText span per word that holds such a cluster: a span ends the text item in pdf.js, which then reads the gap
|
|
332
|
+
// to the next item as a space, so spans end only where the text has one. A plain space next to such a word goes inside
|
|
333
|
+
// its span, the word before it first (PDFium drops a space glyph that a span's glyphs overlap, and a span of a space
|
|
334
|
+
// alone); any other space is a unit of its own, with /ActualText when it is not U+0020.
|
|
335
|
+
const units = [];
|
|
336
|
+
let word = null;
|
|
337
|
+
for (const cluster of clusters) {
|
|
338
|
+
if (/^\s+$/u.test(cluster.text)) {
|
|
339
|
+
word = null;
|
|
340
|
+
units.push({ glyphs: cluster.glyphs, text: cluster.text, space: true, actual: NON_ASCII_SPACE.test(cluster.text) ? cluster.text : null });
|
|
341
|
+
continue;
|
|
342
|
+
}
|
|
343
|
+
if (!word) { word = { glyphs: [], text: "", actual: null, reordered: false }; units.push(word); }
|
|
344
|
+
word.glyphs.push(...cluster.glyphs);
|
|
345
|
+
word.text += cluster.text;
|
|
346
|
+
word.reordered ||= !cluster.inOrder;
|
|
347
|
+
}
|
|
348
|
+
const merged = [];
|
|
349
|
+
units.forEach((unit, index) => {
|
|
350
|
+
const before = merged.at(-1), after = units[index + 1];
|
|
351
|
+
if (unit.space && unit.actual === null && (before?.reordered || after?.reordered)) {
|
|
352
|
+
if (before?.reordered) { before.glyphs.push(...unit.glyphs); before.text += unit.text; }
|
|
353
|
+
else { after.glyphs.unshift(...unit.glyphs); after.text = unit.text + after.text; }
|
|
354
|
+
return;
|
|
355
|
+
}
|
|
356
|
+
merged.push(unit);
|
|
357
|
+
});
|
|
358
|
+
for (const unit of merged) if (unit.reordered) unit.actual = unit.text;
|
|
359
|
+
run.clusters = merged;
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
// Fonts decompose some characters (a Bengali two-part vowel becomes its parts, a Thai am its nikhahit and aa) and compose
|
|
363
|
+
// others, so the glyphs are matched against the text as written, then against each character's canonical and then its
|
|
364
|
+
// compatibility decomposition; a cluster always ends on a character boundary of the text as written.
|
|
365
|
+
function alignedClusters(run) {
|
|
366
|
+
return alignClusters(run, null) ?? alignClusters(run, "NFD") ?? alignClusters(run, "NFKD");
|
|
317
367
|
}
|
|
318
368
|
|
|
319
|
-
function alignClusters(run,
|
|
320
|
-
const
|
|
369
|
+
function alignClusters(run, form) {
|
|
370
|
+
const characters = [...run.logical];
|
|
371
|
+
const points = (text) => [...text].map((character) => character.codePointAt(0));
|
|
372
|
+
const expansions = characters.map((character) => points(form ? character.normalize(form) : character));
|
|
321
373
|
const balance = new Map();
|
|
322
374
|
let open = 0;
|
|
323
375
|
const add = (point, delta) => {
|
|
@@ -327,25 +379,29 @@ function alignClusters(run, text) {
|
|
|
327
379
|
else if (before !== 0 && after === 0) open--;
|
|
328
380
|
};
|
|
329
381
|
const clusters = [];
|
|
330
|
-
let group = [], taken = [],
|
|
382
|
+
let group = [], taken = [], takenCount = 0, consumedCount = 0, next = 0, start = 0;
|
|
331
383
|
for (const glyph of run.glyphs) {
|
|
332
384
|
group.push(glyph);
|
|
333
385
|
for (const point of glyph.codePoints) {
|
|
334
|
-
if (consumed >= logical.length) return null;
|
|
335
386
|
add(point, 1);
|
|
336
|
-
add(logical[consumed++], -1);
|
|
337
387
|
taken.push(point);
|
|
388
|
+
takenCount++;
|
|
389
|
+
while (consumedCount < takenCount) {
|
|
390
|
+
if (next >= characters.length) return null;
|
|
391
|
+
for (const expected of expansions[next]) { add(expected, -1); consumedCount++; }
|
|
392
|
+
next++;
|
|
393
|
+
}
|
|
338
394
|
}
|
|
339
395
|
if (open === 0 && taken.length) {
|
|
340
|
-
const
|
|
341
|
-
const
|
|
342
|
-
clusters.push({ glyphs: group,
|
|
343
|
-
group = []; taken = []; start =
|
|
396
|
+
const text = characters.slice(start, next).join("");
|
|
397
|
+
const written = points(text);
|
|
398
|
+
clusters.push({ glyphs: group, text, inOrder: written.length === taken.length && written.every((point, index) => point === taken[index]) });
|
|
399
|
+
group = []; taken = []; start = next;
|
|
344
400
|
}
|
|
345
401
|
}
|
|
346
|
-
if (group.length ||
|
|
402
|
+
if (group.length || next !== characters.length) {
|
|
347
403
|
// Trailing glyphs without characters join the last cluster; anything else means no alignment.
|
|
348
|
-
if (!group.length || taken.length || !clusters.length) return null;
|
|
404
|
+
if (!group.length || taken.length || !clusters.length || next !== characters.length) return null;
|
|
349
405
|
clusters.at(-1).glyphs.push(...group);
|
|
350
406
|
}
|
|
351
407
|
return clusters;
|
package/dist/pdf-vector.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { loadFontFiles } from './font-files.js';
|
|
2
2
|
import { FontEmbedder, FontLibrary, nominalAdvance } from "./pdf-fonts.js";
|
|
3
|
-
import { actualTextFor,
|
|
3
|
+
import { actualTextFor, attributeClusters, layoutText } from "./pdf-text.js";
|
|
4
4
|
import { IDENTITY, viewBoxTransform, applyPoint, applyStyleSheets, attributesOf, inheritStyle, invert, multiply, parseColor, parseFontWeight, parseLength, parseNumberList, parsePath, parseTransform, pathBounds, ROOT_STYLE, shapeToPath, transformPath } from "./pdf-style.js";
|
|
5
5
|
import { PdfFile, asciiString, name, num, ref, sha256, hex, textString, utf16Hex, utf8Encoder } from "./pdf-writer.js";
|
|
6
6
|
import { isElement, parseXml, serialize, escapeAttribute } from "./pdf-xml.js";
|
|
@@ -752,9 +752,11 @@ class Converter {
|
|
|
752
752
|
if (!runs.some((run) => run.fill || run.stroke)) return;
|
|
753
753
|
// Runs are drawn in visual (left to right) order. Right-to-left runs are marked /ReversedChars so extractors read
|
|
754
754
|
// their characters back to front, and a cluster whose glyph-to-Unicode map cannot give its text (a ligature, a
|
|
755
|
-
// letter split into base and dots, a mirrored bracket) carries /ActualText
|
|
756
|
-
//
|
|
755
|
+
// letter split into base and dots, a mirrored bracket) carries /ActualText. In a left-to-right run a reordered or
|
|
756
|
+
// decomposed cluster (an Indic, Khmer or Myanmar pre-base sign, a Thai am) puts its whole text on one glyph, so the map
|
|
757
|
+
// gives it in drawing order; a run the glyphs cannot be aligned with, or a no-break space, carries /ActualText.
|
|
757
758
|
for (const run of runs) {
|
|
759
|
+
attributeClusters(run);
|
|
758
760
|
run.entry = this.embedder.use(run.face);
|
|
759
761
|
for (const glyph of run.glyphs) glyph.cid = this.embedder.record(run.entry, glyph);
|
|
760
762
|
}
|
|
@@ -774,7 +776,6 @@ class Converter {
|
|
|
774
776
|
const solidFill = fill;
|
|
775
777
|
if (!solidFill && !stroke) return;
|
|
776
778
|
const rtl = run.level % 2 === 1;
|
|
777
|
-
const runActual = !rtl && (!sameText(run) || NON_ASCII_SPACE.test(run.logical)) ? run.logical : null;
|
|
778
779
|
const operations = [];
|
|
779
780
|
let current = null, pending = 0, hex = "";
|
|
780
781
|
const flushHex = () => { if (hex) { current.items.push(`<${hex}>`); hex = ""; } };
|
|
@@ -819,15 +820,14 @@ class Converter {
|
|
|
819
820
|
hex += code;
|
|
820
821
|
pending += nominal - shaped + shift;
|
|
821
822
|
};
|
|
822
|
-
// Each unit is a glyph, or
|
|
823
|
-
//
|
|
824
|
-
// unit as Chromium writes them; a run
|
|
823
|
+
// Each unit is a glyph, or in a left-to-right run with a reordered or decomposed cluster or a no-break space (see
|
|
824
|
+
// attributeClusters) a cluster of glyphs. A unit whose text the glyph map alone does not give carries it as /ActualText,
|
|
825
|
+
// one span per unit as Chromium writes them; a left-to-right run whose glyphs cannot be aligned with its text gets one
|
|
826
|
+
// span for the whole run.
|
|
825
827
|
let units, wholeRun = false;
|
|
826
|
-
if (
|
|
827
|
-
else {
|
|
828
|
-
|
|
829
|
-
if (units === null) { wholeRun = true; units = [{ glyphs: run.glyphs, actual: null }]; }
|
|
830
|
-
}
|
|
828
|
+
if (!rtl && run.clusters?.some((cluster) => cluster.actual !== null)) units = run.clusters;
|
|
829
|
+
else if (!rtl && (!sameText(run) || NON_ASCII_SPACE.test(run.logical))) { wholeRun = true; units = [{ glyphs: run.glyphs, actual: null }]; }
|
|
830
|
+
else units = run.glyphs.map((glyph) => ({ glyphs: [glyph], actual: actualTextFor(run, glyph) }));
|
|
831
831
|
const openSpan = (text) => {
|
|
832
832
|
if (current) { addNumber(); flushHex(); }
|
|
833
833
|
current = null;
|
|
@@ -838,14 +838,15 @@ class Converter {
|
|
|
838
838
|
current = null;
|
|
839
839
|
operations.push({ end: true });
|
|
840
840
|
};
|
|
841
|
-
if (wholeRun) openSpan(
|
|
841
|
+
if (wholeRun) openSpan(run.logical);
|
|
842
842
|
for (const unit of units) {
|
|
843
843
|
if (unit.actual !== null) openSpan(unit.actual);
|
|
844
844
|
for (const glyph of unit.glyphs) {
|
|
845
845
|
const advance = glyph.advance * scale + glyph.spacing + extra;
|
|
846
|
-
if (glyph.codePoints.length === 0) {
|
|
846
|
+
if (glyph.codePoints.length === 0 && !glyph.silent) {
|
|
847
847
|
// A glyph that stands for no character (a dot or mark the font split off a letter) is drawn as a filled outline,
|
|
848
|
-
// so extractors see only the letters.
|
|
848
|
+
// so extractors see only the letters. A silent glyph of a reordered cluster stays text (its cluster's text is on
|
|
849
|
+
// another glyph): an outline there would leave a gap that extractors read as a space inside the word.
|
|
849
850
|
decorations.push({ glyph, pen });
|
|
850
851
|
pending -= advance * 1000 / size;
|
|
851
852
|
} else showGlyph(glyph, pen);
|
package/dist/raster-text.js
CHANGED
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
// - a cluster of a script whose fontkit glyph runs equal HarfBuzz's in the corpus (Devanagari, Gujarati, Oriya, Tamil, Kannada,
|
|
21
21
|
// Sinhala) is drawn as fontkit's glyph outlines (<path> per glyph), so a conjunct under a pre-base vowel is the browser's;
|
|
22
22
|
// - any other cluster (Bengali, Gurmukhi, Telugu, Malayalam, Thai, Lao, Khmer and Myanmar, where fontkit orders marks differently
|
|
23
|
-
// or
|
|
23
|
+
// or (fontkit 2) needed a no-mark-positioning retry; every grapheme of a KOR text, where fontkit's outlines of the KOR punctuation composites
|
|
24
24
|
// lack their shift) is its own <text x y> that resvg shapes correctly in isolation (its glyphs are placed by the sum of the
|
|
25
25
|
// advances; only the cluster's own advance is wrong, and that is not needed when the next cluster is pinned);
|
|
26
26
|
// - runs of other scripts in such a text stay one <text> each, so they keep their own shaping and kerning.
|
|
@@ -425,13 +425,12 @@ function faceRuns(db, base, text) {
|
|
|
425
425
|
return runs;
|
|
426
426
|
}
|
|
427
427
|
|
|
428
|
-
/** fontkit's glyph run of `value` in `face`, shaped like the renderer measures (language, policy features)
|
|
428
|
+
/** fontkit's glyph run of `value` in `face`, shaped like the renderer measures (language, policy features). */
|
|
429
429
|
function shapeRun(face, value, props) {
|
|
430
430
|
const language = openTypeLanguage(props.lang);
|
|
431
431
|
const off = disabledFeaturesFor([...face.families][0]), policyFeatures = off && Object.fromEntries(off.map(tag => [tag, false]));
|
|
432
432
|
const layout = extra => face.font.layout(value, policyFeatures || extra ? { ...policyFeatures, ...extra } : undefined, undefined, language);
|
|
433
|
-
|
|
434
|
-
catch { return { run: layout({ abvm: false, blwm: false, mark: false, mkmk: false }), retry: true }; }
|
|
433
|
+
return { run: layout() };
|
|
435
434
|
}
|
|
436
435
|
|
|
437
436
|
/** Advance widths (px) of the prefixes of the runs' text ending at each offset of `ends`, at HarfBuzz's pens when `shape` is given. */
|
|
@@ -533,11 +532,10 @@ function harfBuzzPens(face, value, props, shape) {
|
|
|
533
532
|
|
|
534
533
|
const hexDigest = bytes => Array.from(bytes, byte => byte.toString(16).toUpperCase().padStart(2, "0")).join("");
|
|
535
534
|
|
|
536
|
-
/** The glyph outlines of one cluster, or null when fontkit
|
|
535
|
+
/** The glyph outlines of one cluster, or null when fontkit cannot shape it. */
|
|
537
536
|
function shapeOutlines(face, value, props) {
|
|
538
537
|
let shaped;
|
|
539
538
|
try { shaped = shapeRun(face, value, props); } catch { return null; }
|
|
540
|
-
if (shaped.retry) return null;
|
|
541
539
|
const glyphs = [];
|
|
542
540
|
for (const [index, glyph] of shaped.run.glyphs.entries()) {
|
|
543
541
|
const position = shaped.run.positions[index];
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// The one wording of "this script's font package is not installed", for every path that reports it (loadFonts with scripts "auto" or a list,
|
|
2
|
+
// ensure, the glyph-fallback chain, demand loading): what to preview and which package at which pinned version, then how to install it.
|
|
3
|
+
// The renderer cannot know how its caller was installed (a global CLI, a project's dependency, one npx run), so it names the three forms.
|
|
4
|
+
|
|
5
|
+
/** `lead` says what the package is for; the result adds the pinned package and the install commands. */
|
|
6
|
+
export function scriptFontNotInstalledMessage(lead, packageName, version) {
|
|
7
|
+
const pinned = typeof version === "string" && version ? `${packageName}@${version}` : packageName;
|
|
8
|
+
return `${lead} Install it where the CLI runs, at that version: npm install -g ${pinned} for a global CLI, npm install ${pinned} in the project that depends on the CLI, or add -p ${pinned} to an npx run. Then run the command again to draw this script with a bundled open font.`;
|
|
9
|
+
}
|
package/dist/svg.d.ts
CHANGED
|
@@ -30,7 +30,7 @@ export declare const engineDefaults: Readonly<{
|
|
|
30
30
|
export type RenderDiagnostic = LayoutDiagnostic | {
|
|
31
31
|
/** A generated RTL numbered marker stayed text; this PNG/raster-PDF marker is not direction-qualified. */
|
|
32
32
|
code: "raster-marker-unavailable";
|
|
33
|
-
reason: "unresolved" | "restricted" | "colour-font" | "
|
|
33
|
+
reason: "unresolved" | "restricted" | "colour-font" | "system-fonts";
|
|
34
34
|
fontFamily?: string;
|
|
35
35
|
message: string;
|
|
36
36
|
} | {
|
|
@@ -41,7 +41,7 @@ export type RenderDiagnostic = LayoutDiagnostic | {
|
|
|
41
41
|
} | {
|
|
42
42
|
/** A run stays text because its face cannot safely be written as outlines. */
|
|
43
43
|
code: "text-as-paths-fallback";
|
|
44
|
-
reason: "colour-font" | "restricted"
|
|
44
|
+
reason: "colour-font" | "restricted";
|
|
45
45
|
fontFamily: string;
|
|
46
46
|
message: string;
|
|
47
47
|
} | {
|
|
@@ -94,8 +94,7 @@ export interface ToSvgOptions {
|
|
|
94
94
|
* given `shapeWasm`), are hidden from assistive technology, and each outlined line is also invisible real text pinned to the
|
|
95
95
|
* drawn width, so screen readers, selection, copy and find-in-page get the words. Each element keeps its `data-opf-*` trace.
|
|
96
96
|
* A run stays text, reported as `text-as-paths-fallback` with a `reason`, when its font is a colour or bitmap font
|
|
97
|
-
* (`"colour-font"`)
|
|
98
|
-
* layout's measurement disagree on it (`"shaping"`). Use it for thumbnails, previews and portable SVG files, not for an editing
|
|
97
|
+
* (`"colour-font"`) or its face's fsType restricts embedding (`"restricted"`). Use it for thumbnails, previews and portable SVG files, not for an editing
|
|
99
98
|
* surface or the vector PDF (which keeps real text from `<text>` SVG).
|
|
100
99
|
*/
|
|
101
100
|
text?: "fonts" | "system" | "paths";
|
package/dist/svg.js
CHANGED
|
@@ -1034,7 +1034,8 @@ function renderArrangements(bound, options) {
|
|
|
1034
1034
|
for (const node of arrangement.nodes) {
|
|
1035
1035
|
const trace = options.trace && node.path ? {'data-opf-arrangement-path': node.path} : {};
|
|
1036
1036
|
if(node.background)parts.push(tag('rect',{...HIDDEN,x:n(node.background.x),y:n(node.background.y),width:n(node.background.width),height:n(node.background.height),rx:n(node.radius??0),fill:paint.fill.hex,...stroke,...trace}));
|
|
1037
|
-
|
|
1037
|
+
// A hierarchy's foreground card and a Venn's overlap label are in the background color with the primary outline.
|
|
1038
|
+
const nodeFill=arrangement.kind==='hierarchy'||node.overlap?paint.line.hex:fill,nodeStroke=arrangement.kind==='hierarchy'||node.overlap?{...stroke,stroke:paint.fill.hex}:stroke,alpha=arrangement.kind==='venn'&&node.preset==='ellipse'?.5:arrangement.kind==='hierarchy'?.9:1;
|
|
1038
1039
|
const nodePaint=alpha===1?nodeStroke:{...nodeStroke,'fill-opacity':alpha};
|
|
1039
1040
|
if (node.points) parts.push(tag('path', {...HIDDEN, d: `M${node.points.map(([px, py]) => `${n(px)} ${n(py)}`).join(' L')} Z`, fill:nodeFill, ...nodePaint, ...trace}));
|
|
1040
1041
|
else if (node.preset === 'ellipse') parts.push(cycleCircle(node, nodeFill, nodePaint, trace));
|
package/dist/text-paths.js
CHANGED
|
@@ -12,10 +12,9 @@ import { embeddingAllowed, fsTypeOf } from './font-fstype.js';
|
|
|
12
12
|
// the font's own metrics. Text drawn with a colour or bitmap font (COLR, CBDT, sbix, SVG tables) stays <text>, reported as
|
|
13
13
|
// `text-as-paths-kept-text`, and the SVG then embeds that face as usual.
|
|
14
14
|
|
|
15
|
-
import { FontLibrary
|
|
16
|
-
import {
|
|
15
|
+
import { FontLibrary } from "./pdf-fonts.js";
|
|
16
|
+
import { layoutText } from "./pdf-text.js";
|
|
17
17
|
import { ROOT_STYLE, attributesOf, inheritStyle, parseFontFamilies, parseFontWeight, parseLength } from "./pdf-style.js";
|
|
18
|
-
import { openTypeLanguage } from "./script-fonts.js";
|
|
19
18
|
import { decodeEntities, escapeAttribute, escapeText, parseXml } from "./pdf-xml.js";
|
|
20
19
|
|
|
21
20
|
const TOKENS = /<(\/?)([A-Za-z][\w:.-]*)((?:[^>"']|"[^"]*"|'[^']*')*?)(\/?)>|<!--[\s\S]*?-->|<!\[CDATA\[[\s\S]*?\]\]>|[^<]+/g;
|
|
@@ -126,7 +125,6 @@ export function outlineSlideText(content, { library, shaper, shape, selectText,
|
|
|
126
125
|
const REASONS = {
|
|
127
126
|
"colour-font": "is a colour or bitmap font, which has no plain outlines",
|
|
128
127
|
restricted: "forbids embedding (OS/2 fsType), so its outlines are not written",
|
|
129
|
-
shaping: "shapes differently in HarfBuzz and in the layout's measurement on text with no pinned width",
|
|
130
128
|
};
|
|
131
129
|
const keep = (family, reason) => {
|
|
132
130
|
if (reported.has(`${family}|${reason}`)) return;
|
|
@@ -233,21 +231,14 @@ function readableText(runs) {
|
|
|
233
231
|
}).join("");
|
|
234
232
|
}
|
|
235
233
|
|
|
236
|
-
// Why a run stays text, or null: a colour or bitmap font
|
|
237
|
-
// another face)
|
|
238
|
-
// the layout measured by more than 0.1 px (inside a textLength the run is scaled to the measured width, as the browser does).
|
|
234
|
+
// Why a run stays text, or null: a colour or bitmap font, or a family whose fsType restricts embedding (the run was laid out with
|
|
235
|
+
// another face).
|
|
239
236
|
function fallbackReason(run, env) {
|
|
240
237
|
if (COLOUR_TABLES.some((table) => run.face.font.directory?.tables?.[table])) return "colour-font";
|
|
241
238
|
for (const family of parseFontFamilies(run.style["font-family"])) {
|
|
242
239
|
if (env.fonts.restricted?.has(family.toLowerCase())) return "restricted";
|
|
243
240
|
if (run.face.names.has(family.toLowerCase()) || (env.onRefusal && env.validateFace && env.fonts.match([family],parseFontWeight(run.style["font-weight"],400),/italic|oblique/i.test(run.style["font-style"]??""))?.face===run.face)) break;
|
|
244
241
|
}
|
|
245
|
-
if (env.shape && !run.scope) {
|
|
246
|
-
const direction = run.level % 2 === 1 ? "rtl" : "ltr", language = openTypeLanguage(run.style.lang ?? run.style["xml:lang"]);
|
|
247
|
-
const measured = fontkitShape(run.face, run.text, { features: featuresOf(run.style), language, direction }).reduce((sum, glyph) => sum + glyph.advance, 0);
|
|
248
|
-
const shaped = run.glyphs.reduce((sum, glyph) => sum + glyph.advance, 0);
|
|
249
|
-
if (Math.abs(measured - shaped) * run.scale > 0.1) return "shaping";
|
|
250
|
-
}
|
|
251
242
|
return null;
|
|
252
243
|
}
|
|
253
244
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openpresentation/opf-render",
|
|
3
|
-
"version": "0.34.
|
|
3
|
+
"version": "0.34.2",
|
|
4
4
|
"description": "Deterministic local OPF renderer for SVG, PNG, and PDF output.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -91,17 +91,17 @@
|
|
|
91
91
|
],
|
|
92
92
|
"dependencies": {
|
|
93
93
|
"bidi-js": "1.1.0",
|
|
94
|
-
"fontkit": "^
|
|
94
|
+
"fontkit": "^3.0.0",
|
|
95
95
|
"harfbuzzjs": "1.6.4",
|
|
96
96
|
"pako": "3.0.3",
|
|
97
|
-
"@openpresentation/opf": "^0.34.
|
|
97
|
+
"@openpresentation/opf": "^0.34.2"
|
|
98
98
|
},
|
|
99
99
|
"peerDependencies": {
|
|
100
100
|
"@expo-google-fonts/arimo": "0.4.3",
|
|
101
101
|
"@expo-google-fonts/caladea": "0.4.2",
|
|
102
102
|
"@expo-google-fonts/cousine": "0.4.3",
|
|
103
103
|
"@expo-google-fonts/gelasio": "0.4.1",
|
|
104
|
-
"@expo-google-fonts/noto-color-emoji": "0.4.
|
|
104
|
+
"@expo-google-fonts/noto-color-emoji": "0.4.8",
|
|
105
105
|
"@expo-google-fonts/noto-emoji": "0.4.8",
|
|
106
106
|
"@expo-google-fonts/noto-naskh-arabic": "0.4.5",
|
|
107
107
|
"@expo-google-fonts/noto-nastaliq-urdu": "0.4.2",
|
|
@@ -122,7 +122,7 @@
|
|
|
122
122
|
"@expo-google-fonts/noto-sans-lao": "0.4.2",
|
|
123
123
|
"@expo-google-fonts/noto-sans-malayalam": "0.4.2",
|
|
124
124
|
"@expo-google-fonts/noto-sans-math": "0.4.2",
|
|
125
|
-
"@expo-google-fonts/noto-sans-mongolian": "0.4.
|
|
125
|
+
"@expo-google-fonts/noto-sans-mongolian": "0.4.2",
|
|
126
126
|
"@expo-google-fonts/noto-sans-myanmar": "0.4.2",
|
|
127
127
|
"@expo-google-fonts/noto-sans-oriya": "0.4.2",
|
|
128
128
|
"@expo-google-fonts/noto-sans-sc": "0.4.4",
|
|
@@ -293,7 +293,7 @@
|
|
|
293
293
|
"@expo-google-fonts/caladea": "0.4.2",
|
|
294
294
|
"@expo-google-fonts/cousine": "0.4.3",
|
|
295
295
|
"@expo-google-fonts/gelasio": "0.4.1",
|
|
296
|
-
"@expo-google-fonts/noto-color-emoji": "0.4.
|
|
296
|
+
"@expo-google-fonts/noto-color-emoji": "0.4.8",
|
|
297
297
|
"@expo-google-fonts/noto-emoji": "0.4.8",
|
|
298
298
|
"@expo-google-fonts/noto-naskh-arabic": "0.4.5",
|
|
299
299
|
"@expo-google-fonts/noto-nastaliq-urdu": "0.4.2",
|
|
@@ -314,7 +314,7 @@
|
|
|
314
314
|
"@expo-google-fonts/noto-sans-lao": "0.4.2",
|
|
315
315
|
"@expo-google-fonts/noto-sans-malayalam": "0.4.2",
|
|
316
316
|
"@expo-google-fonts/noto-sans-math": "0.4.2",
|
|
317
|
-
"@expo-google-fonts/noto-sans-mongolian": "0.4.
|
|
317
|
+
"@expo-google-fonts/noto-sans-mongolian": "0.4.2",
|
|
318
318
|
"@expo-google-fonts/noto-sans-myanmar": "0.4.2",
|
|
319
319
|
"@expo-google-fonts/noto-sans-oriya": "0.4.2",
|
|
320
320
|
"@expo-google-fonts/noto-sans-sc": "0.4.4",
|
|
@@ -335,7 +335,7 @@
|
|
|
335
335
|
"@expo-google-fonts/tinos": "0.4.2",
|
|
336
336
|
"@hyzyla/pdfium": "3.0.0",
|
|
337
337
|
"@jspawn/qpdf-wasm": "0.0.2",
|
|
338
|
-
"@napi-rs/canvas": "1.1.
|
|
338
|
+
"@napi-rs/canvas": "1.1.1",
|
|
339
339
|
"@resvg/resvg-js": "2.6.2",
|
|
340
340
|
"axe-core": "4.14.0",
|
|
341
341
|
"esbuild": "0.28.2",
|
|
@@ -343,7 +343,7 @@
|
|
|
343
343
|
"pdfjs-dist": "6.5.438",
|
|
344
344
|
"playwright": "1.65.0",
|
|
345
345
|
"sharp": "0.35.5",
|
|
346
|
-
"@openpresentation/gallery": "0.34.
|
|
346
|
+
"@openpresentation/gallery": "0.34.2"
|
|
347
347
|
},
|
|
348
348
|
"bin": {
|
|
349
349
|
"opf-preview-fonts": "./dist/preview-fonts-cli.js"
|
|
@@ -400,5 +400,5 @@
|
|
|
400
400
|
"test:preview-a11y-browser": "node test/preview-a11y-browser.mjs",
|
|
401
401
|
"test:forced-colors-browser": "node test/forced-colors-browser.mjs artifacts/forced-colors"
|
|
402
402
|
},
|
|
403
|
-
"gitHead": "
|
|
403
|
+
"gitHead": "6ebaaf5bfd81f113b3faad288048d942bbe5e339"
|
|
404
404
|
}
|