@openpresentation/opf-render 0.34.1 → 0.35.0
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 +23 -23
- package/dist/annotations.js +3 -3
- package/dist/chart-options.js +12 -12
- package/dist/charts.js +43 -40
- package/dist/color-fonts.js +5 -5
- package/dist/deck-runtime.js +2 -2
- package/dist/export-browser.d.ts +1 -1
- package/dist/export-browser.js +1 -1
- package/dist/font-demand.js +8 -9
- package/dist/font-manifest.js +7 -7
- package/dist/font-registry.js +4 -35
- package/dist/fonts-node.js +10 -4
- package/dist/fonts.d.ts +1 -1
- package/dist/index.d.ts +7 -7
- package/dist/pdf-fonts.js +9 -9
- package/dist/pdf-text.js +75 -19
- package/dist/pdf-vector.js +32 -17
- package/dist/raster-text.js +7 -7
- package/dist/raster.js +2 -2
- package/dist/script-font-message.js +9 -0
- package/dist/script-font-pack.js +0 -2
- package/dist/script-fonts.js +48 -18
- package/dist/svg.d.ts +4 -6
- package/dist/svg.js +36 -96
- package/dist/text-paths.js +11 -20
- package/package.json +10 -10
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,
|
|
@@ -293,8 +289,12 @@ export class FontEmbedder {
|
|
|
293
289
|
);
|
|
294
290
|
const toUnicode = file.addStream("", toUnicodeCMap(cids));
|
|
295
291
|
file.set(entry.object, "/Type/Font/Subtype/Type0/BaseFont" + name(base) + "/Encoding/Identity-H/DescendantFonts[" + cidFont + " 0 R]/ToUnicode " + toUnicode + " 0 R");
|
|
292
|
+
const label = `${face.postscriptName} (${[...face.names][0]} ${face.weight}${face.italic ? " italic" : ""})`;
|
|
293
|
+
const how = embedding === "subset" ? `as a subset of the ${used.length} glyphs the PDF draws` : `whole, because its fsType forbids subsetting (the PDF draws ${used.length} of its glyphs)`;
|
|
294
|
+
const restricted = face.restriction ? "; its fsType allows the PDF to be viewed and printed only, not edited" : "";
|
|
296
295
|
return {
|
|
297
|
-
code: "pdf-font-embedded",
|
|
296
|
+
code: "pdf-font-embedded", message: `The font ${label} is embedded in the PDF ${how}, ${fontBytes.length} bytes${restricted}.`,
|
|
297
|
+
family: [...face.names][0], postscriptName: face.postscriptName, weight: face.weight, italic: face.italic,
|
|
298
298
|
glyphs: used.length, bytes: fontBytes.length, embedding, fsType: face.fsType, ...(face.restriction ? { embeddingRestriction: face.restriction } : {}),
|
|
299
299
|
...(face.license ? { license: face.license } : {}), origin: face.origin,
|
|
300
300
|
};
|
|
@@ -316,7 +316,7 @@ export function nominalAdvance(face, gid, cache) {
|
|
|
316
316
|
}
|
|
317
317
|
|
|
318
318
|
// A glyph that stands for no character of its own (a diacritic or dot the font split off a letter) maps to a zero width
|
|
319
|
-
// space: extractors drop it, and viewers that
|
|
319
|
+
// space: extractors drop it, and viewers that honor /ActualText never see it.
|
|
320
320
|
function toUnicodeCMap(cids) {
|
|
321
321
|
const pairs = cids.map((item) => [item.cid, item.codePoints]).sort((a, b) => a[0] - b[0]);
|
|
322
322
|
let body = "/CIDInit /ProcSet findresource begin\n12 dict begin\nbegincmap\n/CIDSystemInfo<</Registry(Adobe)/Ordering(UCS)/Supplement 0>> def\n/CMapName/Adobe-Identity-UCS def\n/CMapType 2 def\n1 begincodespacerange\n<0000> <FFFF>\nendcodespacerange\n";
|
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";
|
|
@@ -506,7 +506,7 @@ class Converter {
|
|
|
506
506
|
}
|
|
507
507
|
const color = parseColor(text, parseColor(style.color));
|
|
508
508
|
if (!color) {
|
|
509
|
-
if (!/^(none|inherit|context-(fill|stroke))$/i.test(text)) this.unsupported("pdf-unsupported-paint", `The
|
|
509
|
+
if (!/^(none|inherit|context-(fill|stroke))$/i.test(text)) this.unsupported("pdf-unsupported-paint", `The color "${text.slice(0, 40)}" is not understood; nothing is drawn for it.`, { kind });
|
|
510
510
|
return null;
|
|
511
511
|
}
|
|
512
512
|
return color.a === 0 ? null : { color };
|
|
@@ -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);
|
|
@@ -888,7 +889,7 @@ class Converter {
|
|
|
888
889
|
const commands = glyphOutline(run.face.font, glyph.gid, (x, y) => [run.x + (origin + (glyph.xOffset + x) * scale) * run.scaleX, run.y - (glyph.yOffset + y) * scale]);
|
|
889
890
|
if (commands.length) content.op(`${pathOps(commands)} f`);
|
|
890
891
|
}
|
|
891
|
-
// Underline / strike-through / overline in the text
|
|
892
|
+
// Underline / strike-through / overline in the text color, from the font's own metrics.
|
|
892
893
|
if (run.decoration.size && solidFill) {
|
|
893
894
|
const font = run.face.font, scale = size / upem;
|
|
894
895
|
for (const kind of run.decoration) {
|
|
@@ -940,6 +941,20 @@ class Converter {
|
|
|
940
941
|
const defs = [];
|
|
941
942
|
const collect = (element) => { for (const child of element.children ?? []) if (isElement(child)) { if (child.name === "defs") defs.push(serialize(child, onlyLocalReferences)); collect(child); } };
|
|
942
943
|
collect(page.svg);
|
|
944
|
+
// A <use> may point at drawn content outside <defs> (a shape effect draws its shadow from a <use> of the shape it
|
|
945
|
+
// follows): that element, and what it references in turn, goes into the standalone SVG too, or the copy draws nothing.
|
|
946
|
+
const referenced = [], seen = new Set();
|
|
947
|
+
const insideDefs = (element) => { for (let at = element.parent; at; at = at.parent) if (at.name === "defs") return true; return false; };
|
|
948
|
+
const follow = (element) => {
|
|
949
|
+
if (element.name === "use") {
|
|
950
|
+
const id = String(element.attrs.href ?? element.attrs["xlink:href"] ?? "").trim().replace(/^#/, "");
|
|
951
|
+
const target = id ? page.defs.get(id) : undefined;
|
|
952
|
+
if (target && !seen.has(target) && !insideDefs(target)) { seen.add(target); referenced.push(target); follow(target); }
|
|
953
|
+
}
|
|
954
|
+
for (const child of element.children ?? []) if (isElement(child)) follow(child);
|
|
955
|
+
};
|
|
956
|
+
follow(node);
|
|
957
|
+
if (referenced.length) defs.push(`<defs>${referenced.map((element) => serialize(element, onlyLocalReferences)).join("")}</defs>`);
|
|
943
958
|
const rootAttrs = page.svg.attrs;
|
|
944
959
|
const standalone = `<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="${page.width}" height="${page.height}" viewBox="${escapeAttribute(rootAttrs.viewBox ?? `0 0 ${page.width} ${page.height}`)}">${defs.join("")}${open}${serialize(node, onlyLocalReferences)}${"</g>".repeat(chain.length)}</svg>`;
|
|
945
960
|
const scale = this.options.rasterFallbackScale;
|
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.
|
|
@@ -326,7 +326,9 @@ function rewriteText(text, db, generics, shape) {
|
|
|
326
326
|
for (const line of decorationLines(run.face, decoration, scale)) parts.push(`<rect${paint} x="${stable(piece.x)}" y="${stable(y + line.offset)}" width="${stable(piece.advance)}" height="${stable(line.thickness)}"/>`);
|
|
327
327
|
continue;
|
|
328
328
|
}
|
|
329
|
-
|
|
329
|
+
// The piece states its own xml:space (its white space is already resolved), so a span's copy is not repeated: an attribute
|
|
330
|
+
// written twice is not XML, and resvg refuses the whole slide.
|
|
331
|
+
const attrs = [...spanAttrs].filter(([key]) => key !== "xml:space").map(([key, value]) => ` ${key}="${escapeAttr(value)}"`).join("");
|
|
330
332
|
parts.push(`<text x="${stable(piece.x)}" y="${stable(y)}"${attrs} text-anchor="start" xml:space="preserve">${escapeText(value)}</text>`);
|
|
331
333
|
}
|
|
332
334
|
}
|
|
@@ -425,13 +427,12 @@ function faceRuns(db, base, text) {
|
|
|
425
427
|
return runs;
|
|
426
428
|
}
|
|
427
429
|
|
|
428
|
-
/** fontkit's glyph run of `value` in `face`, shaped like the renderer measures (language, policy features)
|
|
430
|
+
/** fontkit's glyph run of `value` in `face`, shaped like the renderer measures (language, policy features). */
|
|
429
431
|
function shapeRun(face, value, props) {
|
|
430
432
|
const language = openTypeLanguage(props.lang);
|
|
431
433
|
const off = disabledFeaturesFor([...face.families][0]), policyFeatures = off && Object.fromEntries(off.map(tag => [tag, false]));
|
|
432
434
|
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 }; }
|
|
435
|
+
return { run: layout() };
|
|
435
436
|
}
|
|
436
437
|
|
|
437
438
|
/** 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 +534,10 @@ function harfBuzzPens(face, value, props, shape) {
|
|
|
533
534
|
|
|
534
535
|
const hexDigest = bytes => Array.from(bytes, byte => byte.toString(16).toUpperCase().padStart(2, "0")).join("");
|
|
535
536
|
|
|
536
|
-
/** The glyph outlines of one cluster, or null when fontkit
|
|
537
|
+
/** The glyph outlines of one cluster, or null when fontkit cannot shape it. */
|
|
537
538
|
function shapeOutlines(face, value, props) {
|
|
538
539
|
let shaped;
|
|
539
540
|
try { shaped = shapeRun(face, value, props); } catch { return null; }
|
|
540
|
-
if (shaped.retry) return null;
|
|
541
541
|
const glyphs = [];
|
|
542
542
|
for (const [index, glyph] of shaped.run.glyphs.entries()) {
|
|
543
543
|
const position = shaped.run.positions[index];
|
package/dist/raster.js
CHANGED
|
@@ -129,7 +129,7 @@ function sharpImageCodec() {
|
|
|
129
129
|
async function rasterizeSvg(svgInput, options, {strictMarker=false}={}) {
|
|
130
130
|
const { Resvg } = await loadResvg();
|
|
131
131
|
const scale = positiveNumber(options.scale, "scale", DEFAULT_RASTER_SCALE);
|
|
132
|
-
// FF-45: resvg draws no COLRv1 or OT-SVG
|
|
132
|
+
// FF-45: resvg draws no COLRv1 or OT-SVG color glyphs; the color faces stay out of its font list (see color-fonts.js).
|
|
133
133
|
const settings = fontSettings(options);
|
|
134
134
|
const fontFiles = rasterFontFiles([
|
|
135
135
|
...(settings.useBundledFonts ? await bundledFontFiles() : []),
|
|
@@ -164,7 +164,7 @@ async function rasterizeSvg(svgInput, options, {strictMarker=false}={}) {
|
|
|
164
164
|
return new Resvg(pinned, { ...renderOptions, fitTo: { mode: "zoom", value: zoom }, background: "rgba(0, 0, 0, 0)" }).render().asPng();
|
|
165
165
|
};
|
|
166
166
|
// FF-31: resvg ignores the SVG's ligature properties, so separate the letters a Gelasio ligature would join.
|
|
167
|
-
// FF-45:
|
|
167
|
+
// FF-45: color families (Noto Color Emoji) are drawn with their monochrome stand-in, which resvg can draw.
|
|
168
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).
|
|
169
169
|
const prepared=separateLigatures(monochromeColorFonts(await prepareRasterImages(normalizeSvgInput(svgInput), { nestedSvg })));
|
|
170
170
|
const markers=await outlineRasterMarkers(prepared,{font,shape,report:options.onDiagnostic,strict:strictMarker,fail:(code,message)=>new OPFRenderError(code,message)});
|
|
@@ -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/script-font-pack.js
CHANGED
|
@@ -98,7 +98,6 @@ export function* drawnStrings(presentation) {
|
|
|
98
98
|
|
|
99
99
|
// Generated words are measured before the guarded status rule decides whether they draw. Source enum values alone do not cover them.
|
|
100
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
101
|
function* generatedTimelineWords(presentation) {
|
|
103
102
|
if (!Array.isArray(presentation?.slides)) return;
|
|
104
103
|
for (const [slideIndex, slide] of presentation.slides.entries()) {
|
|
@@ -111,7 +110,6 @@ function* generatedTimelineWords(presentation) {
|
|
|
111
110
|
if (Array.isArray(payload.blocks)) for (const block of payload.blocks) visit(block, depth + 1, [...ancestors, payload]);
|
|
112
111
|
};
|
|
113
112
|
visit(slide);
|
|
114
|
-
for (const [key, payload] of Object.entries(slide)) if (PROMOTED_REGION.test(key)) visit(payload);
|
|
115
113
|
if (!statuses.size) continue;
|
|
116
114
|
const words = timelineStatusWordsFor(quoteLanguage(presentation, slideIndex));
|
|
117
115
|
if (!words) continue;
|
package/dist/script-fonts.js
CHANGED
|
@@ -44,10 +44,10 @@ export const SCRIPT_FONT_FAMILIES = freeze({
|
|
|
44
44
|
Tibt: {serif: "Noto Serif Tibetan"},
|
|
45
45
|
// FF-45 special families. Zsye (emoji symbols) and Zmth (mathematical notation) are ISO 15924 keys for
|
|
46
46
|
// text, not scripts a character carries: emoji and math characters are Common, so they stay in their
|
|
47
|
-
//
|
|
47
|
+
// neighbors' run and reach these faces through the glyph fallback chain (emoji-presentation clusters
|
|
48
48
|
// take the emoji face first). The keys are last so the chain tries every real script face before them.
|
|
49
|
-
// `fallback` is a further designated face, tried after the
|
|
50
|
-
// still previews and exports emoji. The
|
|
49
|
+
// `fallback` is a further designated face, tried after the color face: a host that installed only the monochrome Noto Emoji package
|
|
50
|
+
// still previews and exports emoji. The color face stays first wherever it is loaded.
|
|
51
51
|
Zsye: {sans: "Noto Color Emoji", fallback: "Noto Emoji"},
|
|
52
52
|
Zmth: {serif: "STIX Two Math", sans: "Noto Sans Math"},
|
|
53
53
|
});
|
|
@@ -117,7 +117,7 @@ export const SCRIPT_FONT_REPLACEMENTS = freeze([
|
|
|
117
117
|
...replacement("Thaa", sansThenSerif("Thaa"), ["MV Boli"]),
|
|
118
118
|
...replacement("Syrc", sansThenSerif("Syrc"), ["Estrangelo Edessa"]),
|
|
119
119
|
...replacement("Tibt", serifThenSans("Tibt"), ["Microsoft Himalaya"]),
|
|
120
|
-
// FF-45: Segoe UI Emoji previews with Noto Color Emoji (COLRv1 and SVG
|
|
120
|
+
// FF-45: Segoe UI Emoji previews with Noto Color Emoji (COLRv1 and SVG color glyphs; Noto Emoji is the monochrome
|
|
121
121
|
// face the raster path draws), Cambria Math with STIX Two Math (serif math face with a MATH table; Noto Sans Math
|
|
122
122
|
// is the sans alternative). Both are visual: advances differ from the Microsoft fonts (see the policy rows).
|
|
123
123
|
...replacement("Zsye", ["Noto Color Emoji", "Noto Emoji"], ["Segoe UI Emoji"]),
|
|
@@ -130,21 +130,32 @@ export const SCRIPT_FONT_REPLACEMENTS = freeze([
|
|
|
130
130
|
* replacement's font size by it in measurement and drawing alike, so a replacement much wider than the real font (Noto Naskh Arabic
|
|
131
131
|
* for Arabic Typesetting: 1/0.64) draws lines of the length PowerPoint draws. The exported size and core's geometry never change.
|
|
132
132
|
*/
|
|
133
|
-
export function sizeAdjustFor(row, drawnFamily) {
|
|
134
|
-
const
|
|
135
|
-
const replacement = policy?.replacement, adjust = replacement?.sizeAdjust;
|
|
133
|
+
export function sizeAdjustFor(row, drawnFamily, script) {
|
|
134
|
+
const replacement = replacementFor(row, script), adjust = replacement?.sizeAdjust;
|
|
136
135
|
return typeof adjust === "number" && adjust !== 1 && typeof replacement.family === "string" && replacement.family.toLowerCase() === String(drawnFamily).toLowerCase() ? adjust : undefined;
|
|
137
136
|
}
|
|
138
137
|
|
|
139
138
|
/**
|
|
140
|
-
*
|
|
141
|
-
* (`
|
|
142
|
-
*
|
|
139
|
+
* The replacement a policy row names for runs of `script` (an ISO 15924 key such as `Arab`): the row's script replacement
|
|
140
|
+
* (`replacement.scripts[script]`) when it has one, otherwise its replacement. A Latin family whose own replacement is metric can draw
|
|
141
|
+
* another script with another face: Arial and Times New Roman draw Latin text with Arimo and Tinos, and Arabic-script runs with Noto
|
|
142
|
+
* Naskh Arabic at the multiplier measured on those runs. `row` is a policy row, or the requested family name.
|
|
143
143
|
*/
|
|
144
|
-
export function
|
|
144
|
+
export function replacementFor(row, script) {
|
|
145
145
|
const policy = typeof row === "string" ? fontPolicyFor(row) : row;
|
|
146
146
|
const replacement = policy?.replacement;
|
|
147
|
-
|
|
147
|
+
return (typeof script === "string" && replacement?.scripts?.[script]) || replacement || undefined;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* RR-38: where PowerPoint puts the baseline of a line below its top, in em, for the policy row's replacement drawn as `drawnFamily`
|
|
152
|
+
* (`{lineAscent, lineAscentMixed}`: a line in the real font alone, and a line that also holds other fonts), or undefined. Measured in
|
|
153
|
+
* a native PowerPoint probe (Arabic Typesetting 0.70 and 0.78); core places baselines one em below the line top. `script` picks a
|
|
154
|
+
* script replacement as `sizeAdjustFor` does.
|
|
155
|
+
*/
|
|
156
|
+
export function lineAscentFor(row, drawnFamily, script) {
|
|
157
|
+
const replacement = replacementFor(row, script);
|
|
158
|
+
if (!sizeAdjustFor(row, drawnFamily, script) || typeof replacement.lineAscent !== "number") return undefined;
|
|
148
159
|
return {lineAscent: replacement.lineAscent, lineAscentMixed: typeof replacement.lineAscentMixed === "number" ? replacement.lineAscentMixed : replacement.lineAscent};
|
|
149
160
|
}
|
|
150
161
|
|
|
@@ -439,6 +450,18 @@ export function createScriptFonts(profile = {}, measurement, options = {}) {
|
|
|
439
450
|
if (isNew) options.onFallback?.(note);
|
|
440
451
|
}
|
|
441
452
|
};
|
|
453
|
+
const scriptReplacementOf = (family, script) => (family ? fontPolicyFor(String(family))?.replacement?.scripts?.[script] : undefined);
|
|
454
|
+
/**
|
|
455
|
+
* The slot family whose policy row decides a run's multiplier (the family the slot names, before a script replacement takes its place).
|
|
456
|
+
* A script the Latin slot covers (Ethiopic) has no slot of its own: the theme's script entry names its family (Ebrima), so that
|
|
457
|
+
* family's row decides when it has a replacement for the script. Without one (Sylfaen for Armenian and Georgian) the Latin family does.
|
|
458
|
+
*/
|
|
459
|
+
const slotFamilyFor = (run, slots) => {
|
|
460
|
+
if (run.role === "eastAsian") return slots.eastAsian;
|
|
461
|
+
if (run.role === "complexScript") return slots.complexScript;
|
|
462
|
+
const entry = run.script !== "Latn" && slots.supplement?.script === run.script ? slots.supplement.family : undefined;
|
|
463
|
+
return entry && scriptReplacementOf(entry, run.script) ? entry : slots.latin;
|
|
464
|
+
};
|
|
442
465
|
const candidatesFor = (run, slots) => {
|
|
443
466
|
const list = [run.role === "eastAsian" ? slots.eastAsian : run.role === "complexScript" ? slots.complexScript : slots.latin];
|
|
444
467
|
if (run.script !== "Latn") {
|
|
@@ -448,8 +471,13 @@ export function createScriptFonts(profile = {}, measurement, options = {}) {
|
|
|
448
471
|
// proprietary script families keep the designated order below until they carry a measured multiplier of their own.
|
|
449
472
|
const scriptRule = list[0] ? SCRIPT_FONT_REPLACEMENTS.find(rule => rule.script === run.script && rule.requestedFamily.toLowerCase() === String(list[0]).toLowerCase()) : undefined;
|
|
450
473
|
if (scriptRule && sizeAdjustFor(list[0], scriptRule.substitutes[0])) list.push(scriptRule.substitutes[0]);
|
|
474
|
+
// A slot family whose policy row names a replacement for this script (Arial and Times New Roman: Noto Naskh Arabic for Arabic-script
|
|
475
|
+
// runs) is drawn as that replacement for these runs, as Arabic Typesetting resolves to its own: the replacement takes the family's
|
|
476
|
+
// place, so the family's Latin replacement (Arimo, Tinos, which have no Arabic) is never probed, loaded or reported as lacking glyphs.
|
|
477
|
+
// The theme's script supplement (the Arab entry names Times New Roman or Arial too) takes it the same way.
|
|
451
478
|
if (slots.supplement && slots.supplement.script === run.script) list.push(slots.supplement.family);
|
|
452
479
|
list.push(...designatedFamilies(run.script, serif));
|
|
480
|
+
return [...new Set(list.filter(Boolean).map(family => scriptReplacementOf(family, run.script)?.family ?? family))];
|
|
453
481
|
}
|
|
454
482
|
return [...new Set(list.filter(Boolean))];
|
|
455
483
|
};
|
|
@@ -535,7 +563,7 @@ export function createScriptFonts(profile = {}, measurement, options = {}) {
|
|
|
535
563
|
const cached = plans.get(cacheKey);
|
|
536
564
|
if (cached) return cached;
|
|
537
565
|
const slots = slotsFor(style);
|
|
538
|
-
const runs = itemizeScripts(text, profile).map(run => ({...run, candidates: candidatesFor(run, slots)}));
|
|
566
|
+
const runs = itemizeScripts(text, profile).map(run => ({...run, candidates: candidatesFor(run, slots), slotFamily: slotFamilyFor(run, slots)}));
|
|
539
567
|
const pending = new Map();
|
|
540
568
|
const global = [...new Set([...runs.flatMap(run => run.candidates), ...designatedFamilies(fontKey(profile.script ?? "Zzzz", text, profile), serif), ...designatedFamilies("Latn", serif)])];
|
|
541
569
|
const unique = names => names.map(name => resolveName(name, style)).filter((name, index, all) => name && all.indexOf(name) === index);
|
|
@@ -557,11 +585,13 @@ export function createScriptFonts(profile = {}, measurement, options = {}) {
|
|
|
557
585
|
// RR-38: the slot family's replacement draws at the policy's size multiplier. Unmeasured, the replacement is the first face
|
|
558
586
|
// the stack names after the requested family; the requested name leaves the stack so a host that has the real font installed
|
|
559
587
|
// (a browser on Windows) cannot draw it at the reduced size.
|
|
560
|
-
const adjustOf = family => sizeAdjustFor(run.candidates[0], family);
|
|
561
|
-
const ascentOf = family => lineAscentFor(run.candidates[0], family);
|
|
588
|
+
const adjustOf = family => sizeAdjustFor(run.slotFamily ?? run.candidates[0], family, run.script);
|
|
589
|
+
const ascentOf = family => lineAscentFor(run.slotFamily ?? run.candidates[0], family, run.script);
|
|
562
590
|
if (!measured) {
|
|
563
|
-
|
|
564
|
-
|
|
591
|
+
// The adjusted face is the first candidate when a script replacement took the slot family's place, else the one after the family.
|
|
592
|
+
const lead = run.candidates[0] !== run.slotFamily && adjustOf(run.candidates[0]) ? 0 : 1;
|
|
593
|
+
const adjust = adjustOf(run.candidates[lead]);
|
|
594
|
+
push(run.text, adjust ? run.candidates[lead] : run.candidates[0], adjust ? run.candidates.slice(lead) : run.candidates, adjust, ascentOf(run.candidates[lead]));
|
|
565
595
|
continue;
|
|
566
596
|
}
|
|
567
597
|
const chosen = resolveName(run.candidates[0], style);
|
|
@@ -577,7 +607,7 @@ export function createScriptFonts(profile = {}, measurement, options = {}) {
|
|
|
577
607
|
}
|
|
578
608
|
// No single candidate covers the run. Split it into grapheme clusters (a base character with
|
|
579
609
|
// the combining marks and joiners that follow it) and group those into script segments
|
|
580
|
-
// (common characters stay with their
|
|
610
|
+
// (common characters stay with their neighbors; white space ends a word). Each segment takes the first face that
|
|
581
611
|
// covers all of its letters and marks: the chosen face, the previous fallback face, the
|
|
582
612
|
// other candidates, then the fallback chain. A word is never drawn in two faces when one
|
|
583
613
|
// face has all of it (Greek beside a Latin serif, a kanji run beside Hangul). A cluster
|
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" | "
|
|
33
|
+
reason: "unresolved" | "restricted" | "color-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: "
|
|
44
|
+
reason: "color-font" | "restricted";
|
|
45
45
|
fontFamily: string;
|
|
46
46
|
message: string;
|
|
47
47
|
} | {
|
|
@@ -93,9 +93,8 @@ export interface ToSvgOptions {
|
|
|
93
93
|
* cannot be edited in place. The glyphs are shaped by HarfBuzz (the browser's shaper; the Node handle always, a browser handle
|
|
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
|
-
* A run stays text, reported as `text-as-paths-fallback` with a `reason`, when its font is a
|
|
97
|
-
* (`"
|
|
98
|
-
* layout's measurement disagree on it (`"shaping"`). Use it for thumbnails, previews and portable SVG files, not for an editing
|
|
96
|
+
* A run stays text, reported as `text-as-paths-fallback` with a `reason`, when its font is a color or bitmap font
|
|
97
|
+
* (`"color-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";
|
|
@@ -195,7 +194,6 @@ export interface RenderBinding {
|
|
|
195
194
|
field?: string;
|
|
196
195
|
value: unknown;
|
|
197
196
|
path: string;
|
|
198
|
-
regionKey?: string;
|
|
199
197
|
}
|
|
200
198
|
|
|
201
199
|
export declare class OPFRenderError extends Error {
|