@openpresentation/opf-render 0.33.0 → 0.34.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/README.md +28 -15
- package/dist/chart-options.js +4 -2
- package/dist/charts.js +99 -91
- package/dist/export-browser.d.ts +7 -0
- package/dist/export-browser.js +18 -6
- package/dist/font-demand.js +673 -0
- package/dist/font-files.js +43 -0
- package/dist/font-registry.js +62 -23
- package/dist/font-selection-metadata.js +21 -0
- package/dist/font-selection.js +6 -0
- package/dist/fonts-browser.d.ts +4 -3
- package/dist/fonts-browser.js +19 -8
- package/dist/fonts-node.d.ts +7 -6
- package/dist/fonts-node.js +30 -10
- package/dist/fonts.d.ts +13 -3
- package/dist/hb-shape.js +4 -4
- package/dist/index.d.ts +6 -0
- package/dist/lazy-fonts.js +209 -44
- package/dist/pdf-fonts.js +1 -1
- package/dist/pdf-text.js +10 -2
- package/dist/pdf-vector.js +2 -31
- package/dist/preview-fonts-cli.js +14 -4
- package/dist/preview-fonts-node.d.ts +18 -0
- package/dist/preview-fonts-node.js +37 -0
- package/dist/raster-markers.js +46 -0
- package/dist/raster.js +7 -4
- package/dist/script-font-pack.js +65 -4
- package/dist/script-fonts.js +6 -90
- package/dist/svg.d.ts +6 -0
- package/dist/svg.js +179 -74
- package/dist/text-paths.js +48 -16
- package/package.json +6 -6
package/dist/raster.js
CHANGED
|
@@ -4,6 +4,7 @@ import {slideArguments,slideSources} from './slide-sources.js';
|
|
|
4
4
|
import {separateLigatures} from './font-compatibility.js';
|
|
5
5
|
import {monochromeColorFonts,rasterFontFiles} from './color-fonts.js';
|
|
6
6
|
import {pinScriptClusters} from './raster-text.js';
|
|
7
|
+
import {outlineRasterMarkers} from './raster-markers.js';
|
|
7
8
|
import {loadConverter} from './converters.js';
|
|
8
9
|
const DEFAULT_DIMENSIONS = { width: 1280, height: 720 };
|
|
9
10
|
const DEFAULT_RASTER_SCALE = 1;
|
|
@@ -58,7 +59,7 @@ export async function toPdf(source, slides, options) {
|
|
|
58
59
|
for (const input of pdfInputs) {
|
|
59
60
|
const svg = normalizeSvgInput(input);
|
|
60
61
|
const pageSize = svgPageSize(svg);
|
|
61
|
-
const rendered = await rasterizeSvg(svg, options);
|
|
62
|
+
const rendered = await rasterizeSvg(svg, options, {strictMarker:options.strict===true});
|
|
62
63
|
const image = await pdf.embedPng(rendered.png);
|
|
63
64
|
const page = pdf.addPage([pageSize.width, pageSize.height]);
|
|
64
65
|
page.drawImage(image, {
|
|
@@ -108,7 +109,7 @@ async function vectorPdf(inputs, options) {
|
|
|
108
109
|
onProgress: typeof options.onProgress === "function" ? options.onProgress : undefined,
|
|
109
110
|
producer: packageName,
|
|
110
111
|
ErrorClass: OPFRenderError,
|
|
111
|
-
rasterize: (svg, factor) => rasterizeSvg(svg, { ...options, scale: factor, background: "rgba(0, 0, 0, 0)" })
|
|
112
|
+
rasterize: (svg, factor) => rasterizeSvg(svg, { ...options, scale: factor, background: "rgba(0, 0, 0, 0)" }, {strictMarker:options.strict===true})
|
|
112
113
|
});
|
|
113
114
|
}
|
|
114
115
|
|
|
@@ -125,7 +126,7 @@ function sharpImageCodec() {
|
|
|
125
126
|
};
|
|
126
127
|
}
|
|
127
128
|
|
|
128
|
-
async function rasterizeSvg(svgInput, options) {
|
|
129
|
+
async function rasterizeSvg(svgInput, options, {strictMarker=false}={}) {
|
|
129
130
|
const { Resvg } = await loadResvg();
|
|
130
131
|
const scale = positiveNumber(options.scale, "scale", DEFAULT_RASTER_SCALE);
|
|
131
132
|
// FF-45: resvg draws no COLRv1 or OT-SVG colour glyphs; the colour faces stay out of its font list (see color-fonts.js).
|
|
@@ -165,7 +166,9 @@ async function rasterizeSvg(svgInput, options) {
|
|
|
165
166
|
// FF-31: resvg ignores the SVG's ligature properties, so separate the letters a Gelasio ligature would join.
|
|
166
167
|
// FF-45: colour families (Noto Color Emoji) are drawn with their monochrome stand-in, which resvg can draw.
|
|
167
168
|
// FF-44: resvg loses the advance of a vowel sign or space inside a complex-script cluster, so pin each cluster (raster-text.js).
|
|
168
|
-
const
|
|
169
|
+
const prepared=separateLigatures(monochromeColorFonts(await prepareRasterImages(normalizeSvgInput(svgInput), { nestedSvg })));
|
|
170
|
+
const markers=await outlineRasterMarkers(prepared,{font,shape,report:options.onDiagnostic,strict:strictMarker,fail:(code,message)=>new OPFRenderError(code,message)});
|
|
171
|
+
const svg = await pinScriptClusters(markers, pinning);
|
|
169
172
|
|
|
170
173
|
try {
|
|
171
174
|
const image = new Resvg(svg, renderOptions).render();
|
package/dist/script-font-pack.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
import { BUNDLED_FONT_MANIFEST } from "./font-manifest.js";
|
|
5
5
|
import { OPFFontError } from "./font-registry.js";
|
|
6
6
|
import { SCRIPT_FONT_REPLACEMENTS, glyphFallbackFamilies, scriptOfCharacter, scriptsOfText } from "./script-fonts.js";
|
|
7
|
-
import { resolveScriptFonts } from "@openpresentation/opf/composition";
|
|
7
|
+
import { MAX_COMPOSITION_DEPTH, languageInEffect, numeralScripts, quoteLanguage, resolveScriptFonts, timelineStatusWordsFor } from "@openpresentation/opf/composition";
|
|
8
8
|
import { createFontAnalysis } from "./lazy-fonts.js";
|
|
9
9
|
import { SYMBOL_SCRIPT, isSymbolEncodedFamily } from "./symbol-fonts.js";
|
|
10
10
|
|
|
@@ -96,13 +96,36 @@ export function* drawnStrings(presentation) {
|
|
|
96
96
|
yield* walkStrings(presentation, undrawn, undrawnRoot, undrawnSlide);
|
|
97
97
|
}
|
|
98
98
|
|
|
99
|
+
// Generated words are measured before the guarded status rule decides whether they draw. Source enum values alone do not cover them.
|
|
100
|
+
// Only content payloads count: arbitrary variables, metadata, notes, catalogs and extensions never synthesize timeline labels.
|
|
101
|
+
const PROMOTED_REGION = /^(?:(?:top|middle|bottom)(?:\+(?:top|middle|bottom))*(?::(?:start|center|end)(?:\+(?:start|center|end))*)?|(?:start|center|end)(?:\+(?:start|center|end))*)$/;
|
|
102
|
+
function* generatedTimelineWords(presentation) {
|
|
103
|
+
if (!Array.isArray(presentation?.slides)) return;
|
|
104
|
+
for (const [slideIndex, slide] of presentation.slides.entries()) {
|
|
105
|
+
if (!slide || typeof slide !== "object" || Array.isArray(slide)) continue;
|
|
106
|
+
const statuses = new Set();
|
|
107
|
+
const visit = (payload, depth = -1, ancestors = []) => {
|
|
108
|
+
if (!payload || typeof payload !== "object" || Array.isArray(payload) || depth > MAX_COMPOSITION_DEPTH || ancestors.includes(payload)) return;
|
|
109
|
+
const timeline = payload.timeline, events = Array.isArray(timeline) ? timeline : timeline?.events;
|
|
110
|
+
if (Array.isArray(events)) for (const event of events) if (typeof event?.status === "string") statuses.add(event.status);
|
|
111
|
+
if (Array.isArray(payload.blocks)) for (const block of payload.blocks) visit(block, depth + 1, [...ancestors, payload]);
|
|
112
|
+
};
|
|
113
|
+
visit(slide);
|
|
114
|
+
for (const [key, payload] of Object.entries(slide)) if (PROMOTED_REGION.test(key)) visit(payload);
|
|
115
|
+
if (!statuses.size) continue;
|
|
116
|
+
const words = timelineStatusWordsFor(quoteLanguage(presentation, slideIndex));
|
|
117
|
+
if (!words) continue;
|
|
118
|
+
for (const status of statuses) if (typeof words[status] === "string") yield {text: words[status], slideIndex};
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
99
122
|
/**
|
|
100
123
|
* The script profile of a presentation: core `resolveScriptFonts` output, exactly what the renderer plans
|
|
101
124
|
* with. When it throws, the renderer ignores the document language, so the profile is empty and Han text is
|
|
102
125
|
* Simplified Chinese, as drawn. `renderOptions.catalogs` (the host's registered catalogs) resolve as they do for the renderer.
|
|
103
126
|
*/
|
|
104
|
-
export function presentationScriptProfile(presentation, renderOptions) {
|
|
105
|
-
try { return resolveScriptFonts(presentation, renderOptions?.catalogs !== undefined ? { catalogs: renderOptions.catalogs } : {}); } catch { /* the renderer falls back the same way */ }
|
|
127
|
+
export function presentationScriptProfile(presentation, renderOptions, slideIndex) {
|
|
128
|
+
try { return resolveScriptFonts(presentation, { ...(renderOptions?.catalogs !== undefined ? { catalogs: renderOptions.catalogs } : {}), ...(slideIndex !== undefined ? {slideIndex} : {}) }); } catch { /* the renderer falls back the same way */ }
|
|
106
129
|
return {};
|
|
107
130
|
}
|
|
108
131
|
|
|
@@ -191,7 +214,45 @@ export function analyzePresentationScripts(presentation, profile, renderOptions,
|
|
|
191
214
|
for (const script of found.scripts) scripts.add(script);
|
|
192
215
|
for (const character of found.cjk) cjk.add(character);
|
|
193
216
|
}
|
|
194
|
-
|
|
217
|
+
const generatedProfiles = new Map();
|
|
218
|
+
for (const {text, slideIndex} of generatedTimelineWords(presentation)) {
|
|
219
|
+
// A generated Han label follows its own slide locale (for example zh-TW on an English deck), not the deck's default script.
|
|
220
|
+
if (!generatedProfiles.has(slideIndex)) generatedProfiles.set(slideIndex, presentationScriptProfile(presentation, renderOptions, slideIndex));
|
|
221
|
+
const found = memory.scanner(generatedProfiles.get(slideIndex))(text);
|
|
222
|
+
for (const script of found.scripts) scripts.add(script);
|
|
223
|
+
for (const character of found.cjk) cjk.add(character);
|
|
224
|
+
}
|
|
225
|
+
return { profile, detected: [...scripts].sort(), design: [...new Set([...design.scripts, ...generatedNumeralScripts(presentation)])].sort(), cjk };
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* LH-106: the scripts of the digits the engines generate (metric values, chart labels and ticks, table numbers, list numerals,
|
|
230
|
+
* step badges, slide numbers) on each slide whose language (its own, else the deck's) has digits of its own: Arab for `ar-SA` and
|
|
231
|
+
* `fa-IR`, Beng for `bn`, none for `ar-AE` or `ar-SA-u-nu-latn`. Like a font scheme's scripts they are faces the deck may draw
|
|
232
|
+
* without one authored character in the script (an `ar-SA` deck titled "T" with the metric 1000 draws ١٬٠٠٠), so their packages
|
|
233
|
+
* are offered to the drawn-face analysis, which loads only the faces the composed slides actually draw. A slide counts when it may
|
|
234
|
+
* generate a number (`generatesNumbers`); a slide of words alone (a timeline of "Week 1" labels) offers nothing.
|
|
235
|
+
*/
|
|
236
|
+
function generatedNumeralScripts(presentation) {
|
|
237
|
+
const slides = Array.isArray(presentation?.slides) ? presentation.slides : [];
|
|
238
|
+
const furniture = generatesNumbers(presentation?.design?.header) || generatesNumbers(presentation?.design?.footer);
|
|
239
|
+
return numeralScripts(slides.map((slide, index) => furniture || generatesNumbers(slide) || generatesNumbers(slide?.design?.header) || generatesNumbers(slide?.design?.footer) ? languageInEffect(presentation, index) : undefined));
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
// Payload keys whose content the engines number: a chart's labels and ticks, a table's cells, a metric, list numerals and step badges
|
|
243
|
+
// (a list or a layout's sequence), and a slide that names a layout (whose regions may badge its blocks).
|
|
244
|
+
const NUMBERED_KEYS = new Set(["chart", "table", "metric", "numbering", "items", "bullets", "blocks", "layout"]);
|
|
245
|
+
/** True when a slide (or a header or footer) may draw a number the engines generate: a JSON number, a numbered payload or a `{{token}}`. */
|
|
246
|
+
function generatesNumbers(value, depth = 0) {
|
|
247
|
+
if (typeof value === "number") return Number.isFinite(value);
|
|
248
|
+
if (typeof value === "string") return value.includes("{{");
|
|
249
|
+
if (!value || typeof value !== "object" || depth > MAX_COMPOSITION_DEPTH + 8) return false;
|
|
250
|
+
if (Array.isArray(value)) return value.some(entry => generatesNumbers(entry, depth + 1));
|
|
251
|
+
for (const [key, entry] of Object.entries(value)) {
|
|
252
|
+
if (UNDRAWN_KEYS.includes(key) || key === "language" || key === "design" || key === "composition") continue;
|
|
253
|
+
if (NUMBERED_KEYS.has(key) || generatesNumbers(entry, depth + 1)) return true;
|
|
254
|
+
}
|
|
255
|
+
return false;
|
|
195
256
|
}
|
|
196
257
|
|
|
197
258
|
/** One string's scripts (`scriptsOfText`) and the Han, kana and Hangul characters it draws, in order. One pass over the characters. */
|
package/dist/script-fonts.js
CHANGED
|
@@ -17,9 +17,9 @@
|
|
|
17
17
|
// faces and lets a missing glyph raise `missing-glyph`.
|
|
18
18
|
|
|
19
19
|
import { fontPolicyFor } from "@openpresentation/opf/font-policy";
|
|
20
|
-
import { scriptFontRole } from "@openpresentation/opf/composition";
|
|
20
|
+
import { scriptFontRole, scriptOfCharacter, itemizeScripts } from "@openpresentation/opf/composition";
|
|
21
21
|
import { SYMBOL_PLACEHOLDER, SYMBOL_SCRIPT, mapSymbolAdvances, symbolEncodingFamily, symbolPreviewFaces } from "./symbol-fonts.js";
|
|
22
|
-
export { scriptFontRole };
|
|
22
|
+
export { scriptFontRole, scriptOfCharacter, itemizeScripts };
|
|
23
23
|
|
|
24
24
|
const freeze = value => { if (value && typeof value === "object") { for (const child of Object.values(value)) freeze(child); Object.freeze(value); } return value; };
|
|
25
25
|
|
|
@@ -179,34 +179,6 @@ const rtlScripts = new Set(["Arab", "Hebr", "Syrc", "Thaa", "Nkoo", "Adlm", "Roh
|
|
|
179
179
|
/** Scripts the latin slot covers directly; never split from the surrounding Latin run. */
|
|
180
180
|
const latinGroup = new Set(["Latn", "Cyrl", "Grek", "Zyyy", "Zinh", "Zzzz"]);
|
|
181
181
|
|
|
182
|
-
const detected = ["Latn", "Cyrl", "Grek", "Hani", "Hira", "Kana", "Hang", "Bopo", "Yiii", "Arab", "Hebr", "Syrc", "Thaa", "Nkoo", "Adlm", "Rohg", "Mand", "Samr",
|
|
183
|
-
"Deva", "Beng", "Guru", "Gujr", "Orya", "Taml", "Telu", "Knda", "Mlym", "Sinh", "Thai", "Laoo", "Tibt", "Mymr", "Khmr", "Mong", "Bali", "Java", "Lana",
|
|
184
|
-
"Tale", "Talu", "Cakm", "Olck", "Armn", "Geor", "Ethi", "Cher", "Tfng", "Vaii", "Zinh", "Zyyy"];
|
|
185
|
-
// One precompiled pattern for every script, a capture group each, tried in the list's order (the first match wins, as with one
|
|
186
|
-
// pattern per script): a character is classified by one match instead of up to 48 tests.
|
|
187
|
-
const detectedPattern = new RegExp(`^(?:${detected.map(code => String.raw`(\p{Script=${code}})`).join("|")})$`, "u");
|
|
188
|
-
const ignorable = /^\p{Default_Ignorable_Code_Point}$/u;
|
|
189
|
-
const scriptCache = new Map();
|
|
190
|
-
function classify(character) {
|
|
191
|
-
const match = detectedPattern.exec(character);
|
|
192
|
-
if (!match) return "Zzzz";
|
|
193
|
-
for (let group = 1; group < match.length; group++) if (match[group] !== undefined) return detected[group - 1];
|
|
194
|
-
return "Zzzz";
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
/** ISO 15924 script of one character: `Zyyy` common, `Zinh` inherited, `Zzzz` otherwise unknown. */
|
|
198
|
-
export function scriptOfCharacter(character) {
|
|
199
|
-
let script = scriptCache.get(character);
|
|
200
|
-
if (script === undefined) {
|
|
201
|
-
const code = character.codePointAt(0);
|
|
202
|
-
script = code < 0x80 ? (/[A-Za-z]/.test(character) ? "Latn" : "Zyyy")
|
|
203
|
-
: ignorable.test(character) ? "Zinh"
|
|
204
|
-
: classify(character);
|
|
205
|
-
if (scriptCache.size < 65536) scriptCache.set(character, script);
|
|
206
|
-
}
|
|
207
|
-
return script;
|
|
208
|
-
}
|
|
209
|
-
|
|
210
182
|
/** Latin, Greek, Cyrillic, general punctuation and letterlike text: no script split is possible. */
|
|
211
183
|
const latinOnly = /^[\u0000-\u036F\u0370-\u052F\u1E00-\u1FFF\u2000-\u2065\u206A-\u20CF\u2100-\u218F]*$/;
|
|
212
184
|
|
|
@@ -230,70 +202,12 @@ function fontKey(script, text, profile, han = () => hanScript(text, profile)) {
|
|
|
230
202
|
return latinGroup.has(script) ? "Latn" : script;
|
|
231
203
|
}
|
|
232
204
|
|
|
233
|
-
// East Asian common characters that PowerPoint always draws with the East Asian
|
|
234
|
-
// (a:ea) font: CJK symbols and punctuation, kana marks, enclosed CJK, CJK
|
|
235
|
-
// compatibility, vertical and small forms, and halfwidth/fullwidth forms.
|
|
236
|
-
const eastAsianCommon = /[\u3000-\u303F\u3040-\u30FF\u31F0-\u31FF\u3200-\u33FF\uFE30-\uFE4F\uFF00-\uFFEF]/u;
|
|
237
205
|
// Characters whose font PowerPoint picks from the run language: with an East
|
|
238
206
|
// Asian language they use the a:ea font (curly quotes, dashes, ellipsis,
|
|
239
207
|
// daggers, per-mille, primes, reference mark).
|
|
240
208
|
const eastAsianAmbiguous = /[\u2010-\u2016\u2018-\u2022\u2025\u2026\u2030\u2032\u2033\u203B]/u;
|
|
241
209
|
const eastAsianLanguage = profile => profile?.scriptRole === "eastAsian" || /^(ja|zh|ko)\b/i.test(String(profile?.bcp47 ?? ""));
|
|
242
210
|
|
|
243
|
-
/**
|
|
244
|
-
* Split text into font runs by Unicode script, following PowerPoint's
|
|
245
|
-
* character-to-slot rules where they are known:
|
|
246
|
-
* - Letters take their script's slot. Latin, Greek and Cyrillic share one run.
|
|
247
|
-
* - East Asian common characters (CJK punctuation U+3000-303F, fullwidth forms
|
|
248
|
-
* U+FF00-FFEF and similar) are East Asian, also at the start of a text; with
|
|
249
|
-
* an East Asian language, curly quotes, dashes and the ellipsis are too.
|
|
250
|
-
* - ASCII spaces, digits and punctuation use the latin slot next to East Asian
|
|
251
|
-
* text, and stay in a complex-script run (as PowerPoint draws them with the
|
|
252
|
-
* complex-script font inside Arabic, Hebrew, Indic or Thai text).
|
|
253
|
-
* - Other common and inherited characters (combining marks, other punctuation)
|
|
254
|
-
* join the preceding run, or the following run at the start of the text.
|
|
255
|
-
* `profile` (for example core `resolveScriptFonts` output) supplies the
|
|
256
|
-
* language, which disambiguates Han and the language-dependent characters.
|
|
257
|
-
*/
|
|
258
|
-
export function itemizeScripts(text, profile) {
|
|
259
|
-
const source = String(text);
|
|
260
|
-
const runs = [];
|
|
261
|
-
let pending = "";
|
|
262
|
-
const eastAsian = eastAsianLanguage(profile);
|
|
263
|
-
// The Han key depends on the whole text and the profile only: work it out once per text, not once per Han character.
|
|
264
|
-
let han;
|
|
265
|
-
const hanOfText = () => han ??= hanScript(source, profile);
|
|
266
|
-
const push = (character, key) => {
|
|
267
|
-
const last = runs.at(-1);
|
|
268
|
-
if (last && last.script === key) last.text += character;
|
|
269
|
-
else runs.push({text: character, script: key, role: scriptFontRole(key)});
|
|
270
|
-
};
|
|
271
|
-
const strong = (character, key) => {
|
|
272
|
-
// Leading neutrals join a complex-script run; otherwise they are Latin.
|
|
273
|
-
if (!runs.length && pending) {
|
|
274
|
-
if (scriptFontRole(key) === "complexScript") { runs.push({text: pending, script: key, role: "complexScript"}); }
|
|
275
|
-
else push(pending, "Latn");
|
|
276
|
-
pending = "";
|
|
277
|
-
}
|
|
278
|
-
push(character, key);
|
|
279
|
-
};
|
|
280
|
-
for (const character of source) {
|
|
281
|
-
const script = scriptOfCharacter(character);
|
|
282
|
-
if (eastAsianCommon.test(character) || (eastAsian && eastAsianAmbiguous.test(character))) {
|
|
283
|
-
strong(character, script === "Hira" || script === "Kana" ? "Jpan" : hanOfText());
|
|
284
|
-
} else if (script === "Zinh") {
|
|
285
|
-
if (runs.length) runs.at(-1).text += character; else pending += character;
|
|
286
|
-
} else if (script === "Zyyy") {
|
|
287
|
-
const last = runs.at(-1);
|
|
288
|
-
if (!last) pending += character;
|
|
289
|
-
else if (character.codePointAt(0) < 0x80 && last.role === "eastAsian") push(character, "Latn");
|
|
290
|
-
else last.text += character;
|
|
291
|
-
} else strong(character, fontKey(script, source, profile, hanOfText));
|
|
292
|
-
}
|
|
293
|
-
if (!runs.length) return [{text: pending, script: "Latn", role: "latin"}];
|
|
294
|
-
return runs;
|
|
295
|
-
}
|
|
296
|
-
|
|
297
211
|
/**
|
|
298
212
|
* Non-Latin script keys the renderer would plan runs for in `text`. It applies the same shortcut as drawing
|
|
299
213
|
* (`createScriptFonts().plan`): Latin, Greek and Cyrillic text is one run in the design font, except that
|
|
@@ -438,6 +352,8 @@ const scriptMeasurement = Symbol.for("@openpresentation/opf-render/script-measur
|
|
|
438
352
|
* receives each new substitution note `{fontFamily, fallbackFamily, scripts,
|
|
439
353
|
* characters, path?}` once; `fallbacks` lists them all.
|
|
440
354
|
*/
|
|
355
|
+
// Internal recording planners need strict coverage probes but may finish recording unsupported text before optional fonts arrive.
|
|
356
|
+
export const fontCoverageProbe = Symbol('opf.font-analysis-coverage');
|
|
441
357
|
export function createScriptFonts(profile = {}, measurement, options = {}) {
|
|
442
358
|
const wrapped = measurement?.[scriptMeasurement];
|
|
443
359
|
const inner = wrapped?.inner ?? measurement;
|
|
@@ -474,7 +390,7 @@ export function createScriptFonts(profile = {}, measurement, options = {}) {
|
|
|
474
390
|
const key = `${family}\u0000${style.fontWeight ?? 400}\u0000${!!style.italic}\u0000${text}`;
|
|
475
391
|
if (coverage.has(key)) return coverage.get(key);
|
|
476
392
|
let result = true;
|
|
477
|
-
try { inner.measure(text, 1, {...style, fontFamily: family}); }
|
|
393
|
+
try { if (inner[fontCoverageProbe]) inner[fontCoverageProbe](text, 1, {...style, fontFamily: family}); else inner.measure(text, 1, {...style, fontFamily: family}); }
|
|
478
394
|
catch (error) { if (error?.code !== "missing-glyph" && !softErrors.has(error?.code)) throw error; result = false; }
|
|
479
395
|
if (coverage.size >= 8192) coverage.delete(coverage.keys().next().value);
|
|
480
396
|
coverage.set(key, result);
|
|
@@ -613,7 +529,7 @@ export function createScriptFonts(profile = {}, measurement, options = {}) {
|
|
|
613
529
|
// (Cyrillic or Greek beyond a Latin replacement): then it is planned per character below.
|
|
614
530
|
if (!fallbackEnabled || !nonAscii.test(text)) return [{text, family: style.fontFamily, own: true}];
|
|
615
531
|
if (!measured) return cyrillicOrGreek.test(text) ? [{text, family: style.fontFamily, own: false, stack: [style.fontFamily, ...designatedFamilies("Latn", serif)]}] : [{text, family: style.fontFamily, own: true}];
|
|
616
|
-
if (ownFace === null || covers(
|
|
532
|
+
if (ownFace === null || covers(style.fontFamily, text, style)) return [{text, family: style.fontFamily, own: true}];
|
|
617
533
|
}
|
|
618
534
|
const cacheKey = `${style.fontFamily}\u0000${style.fontWeight ?? 400}\u0000${!!style.italic}\u0000${textRole(style) ?? ""}\u0000${style.path ?? ""}\u0000${text}`;
|
|
619
535
|
const cached = plans.get(cacheKey);
|
package/dist/svg.d.ts
CHANGED
|
@@ -28,6 +28,12 @@ export declare const engineDefaults: Readonly<{
|
|
|
28
28
|
}>;
|
|
29
29
|
|
|
30
30
|
export type RenderDiagnostic = LayoutDiagnostic | {
|
|
31
|
+
/** A generated RTL numbered marker stayed text; this PNG/raster-PDF marker is not direction-qualified. */
|
|
32
|
+
code: "raster-marker-unavailable";
|
|
33
|
+
reason: "unresolved" | "restricted" | "colour-font" | "shaping" | "system-fonts";
|
|
34
|
+
fontFamily?: string;
|
|
35
|
+
message: string;
|
|
36
|
+
} | {
|
|
31
37
|
/** LH-145: a picture background could not be read or decoded by `measurePictures`; its scrim is sized for any picture. */
|
|
32
38
|
code: "picture-not-measured";
|
|
33
39
|
path: string;
|