@openpresentation/opf-render 0.34.2 → 0.35.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 +23 -23
- package/dist/annotations.js +3 -3
- package/dist/chart-options.js +17 -13
- package/dist/charts.js +40 -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 +1 -1
- package/dist/font-registry.js +3 -3
- package/dist/fonts.d.ts +1 -1
- package/dist/index.d.ts +7 -6
- package/dist/pdf-fonts.js +6 -2
- package/dist/pdf-vector.js +16 -2
- package/dist/raster-text.js +3 -1
- package/dist/raster.js +2 -2
- package/dist/script-font-pack.js +0 -2
- package/dist/script-fonts.js +48 -18
- package/dist/svg.d.ts +4 -5
- package/dist/svg.js +34 -95
- package/dist/text-paths.js +8 -8
- package/package.json +4 -4
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,8 +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
|
-
* (`"
|
|
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
|
|
98
98
|
* surface or the vector PDF (which keeps real text from `<text>` SVG).
|
|
99
99
|
*/
|
|
100
100
|
text?: "fonts" | "system" | "paths";
|
|
@@ -194,7 +194,6 @@ export interface RenderBinding {
|
|
|
194
194
|
field?: string;
|
|
195
195
|
value: unknown;
|
|
196
196
|
path: string;
|
|
197
|
-
regionKey?: string;
|
|
198
197
|
}
|
|
199
198
|
|
|
200
199
|
export declare class OPFRenderError extends Error {
|
package/dist/svg.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// The layout engine lives in core's `/composition` entry. Every name is a static import, so a core without one fails to
|
|
2
|
-
// load instead of switching a feature (script fonts, right-to-left, patterns, code
|
|
2
|
+
// load instead of switching a feature (script fonts, right-to-left, patterns, code colors, trend arrows) off.
|
|
3
3
|
import {
|
|
4
4
|
layoutTable, fitList, fitRichText, composeSlide, emphasisSurface, resolveTextStyle, textWidthMeasurer, fitText, styledText, LIST_RULE_WIDTH, LIST_ACCENT_RULE_WIDTH, textColorForFill, chartColorForFill,
|
|
5
5
|
resolveColorRef as resolveCoreColorRef, colorTransform, applyColorTransform, stackedText, resolveScriptFonts, paragraphDirection, physicalAlignment, itemAlignment, patternRuns, isolateNumbers,
|
|
@@ -88,58 +88,6 @@ const ROOT_PAYLOAD_FIELDS = [
|
|
|
88
88
|
"timeline"
|
|
89
89
|
];
|
|
90
90
|
|
|
91
|
-
const PROMOTED_REGION_KEYS = [
|
|
92
|
-
"start",
|
|
93
|
-
"center",
|
|
94
|
-
"end",
|
|
95
|
-
"start+center",
|
|
96
|
-
"center+end",
|
|
97
|
-
"start+center+end",
|
|
98
|
-
"top",
|
|
99
|
-
"middle",
|
|
100
|
-
"bottom",
|
|
101
|
-
"top+middle",
|
|
102
|
-
"middle+bottom",
|
|
103
|
-
"top+middle+bottom",
|
|
104
|
-
"top:start",
|
|
105
|
-
"top:center",
|
|
106
|
-
"top:end",
|
|
107
|
-
"top:start+center",
|
|
108
|
-
"top:center+end",
|
|
109
|
-
"top:start+center+end",
|
|
110
|
-
"middle:start",
|
|
111
|
-
"middle:center",
|
|
112
|
-
"middle:end",
|
|
113
|
-
"middle:start+center",
|
|
114
|
-
"middle:center+end",
|
|
115
|
-
"middle:start+center+end",
|
|
116
|
-
"bottom:start",
|
|
117
|
-
"bottom:center",
|
|
118
|
-
"bottom:end",
|
|
119
|
-
"bottom:start+center",
|
|
120
|
-
"bottom:center+end",
|
|
121
|
-
"bottom:start+center+end",
|
|
122
|
-
"top+middle:start",
|
|
123
|
-
"top+middle:center",
|
|
124
|
-
"top+middle:end",
|
|
125
|
-
"top+middle:start+center",
|
|
126
|
-
"top+middle:center+end",
|
|
127
|
-
"top+middle:start+center+end",
|
|
128
|
-
"middle+bottom:start",
|
|
129
|
-
"middle+bottom:center",
|
|
130
|
-
"middle+bottom:end",
|
|
131
|
-
"middle+bottom:start+center",
|
|
132
|
-
"middle+bottom:center+end",
|
|
133
|
-
"middle+bottom:start+center+end",
|
|
134
|
-
"top+middle+bottom:start",
|
|
135
|
-
"top+middle+bottom:center",
|
|
136
|
-
"top+middle+bottom:end",
|
|
137
|
-
"top+middle+bottom:start+center",
|
|
138
|
-
"top+middle+bottom:center+end",
|
|
139
|
-
"top+middle+bottom:start+center+end"
|
|
140
|
-
];
|
|
141
|
-
|
|
142
|
-
|
|
143
91
|
const FIELD_TYPE = Object.freeze({
|
|
144
92
|
text: "text",
|
|
145
93
|
items: "list",
|
|
@@ -295,10 +243,10 @@ function resolveColorRefIn(value, design, fallback) {
|
|
|
295
243
|
});
|
|
296
244
|
}
|
|
297
245
|
|
|
298
|
-
// Background fills: a literal hex keeps normalizeColor's
|
|
246
|
+
// Background fills: a literal hex keeps normalizeColor's behavior (uppercase, alpha kept);
|
|
299
247
|
// anything else is a ColorRef (var:id, scheme slot or role) resolved like table fills and run
|
|
300
|
-
//
|
|
301
|
-
// Roles resolve through the
|
|
248
|
+
// colors, falling back exactly as an unparseable literal did.
|
|
249
|
+
// Roles resolve through the color scheme only: background, surface and text are derived from the
|
|
302
250
|
// background itself (the contrast text), so a reference must not see them.
|
|
303
251
|
function resolveBackgroundColor(value, design, fallback) {
|
|
304
252
|
const literal = normalizeColor(value, null);
|
|
@@ -307,7 +255,7 @@ function resolveBackgroundColor(value, design, fallback) {
|
|
|
307
255
|
return resolveColorRefIn(value, { colorScheme: design.colorScheme, colors: { primary, secondary, accent }, variables: design.variables }, fallback);
|
|
308
256
|
}
|
|
309
257
|
|
|
310
|
-
// Image sources the background string shorthand accepts (a cover image); any other string is a theme slot or a hex
|
|
258
|
+
// Image sources the background string shorthand accepts (a cover image); any other string is a theme slot or a hex color.
|
|
311
259
|
const IMAGE_BACKGROUND_SOURCE = /^(asset:|https:\/\/|data:|\.\/|\.\.\/)/;
|
|
312
260
|
|
|
313
261
|
// The slide's single background color, or null when there is none (a gradient, or no color the engine can read).
|
|
@@ -323,7 +271,7 @@ function resolveBackground(background, colorScheme, design, canvas) {
|
|
|
323
271
|
}
|
|
324
272
|
|
|
325
273
|
|
|
326
|
-
// An unparseable
|
|
274
|
+
// An unparseable color measures as white: this is a luminance for the contrast tests below, never a color that is drawn.
|
|
327
275
|
function colorLuminance(color) {
|
|
328
276
|
const hex = normalizeColor(color, "#FFFFFF").replace("#", "");
|
|
329
277
|
const channels = [0, 2, 4].map(offset => {
|
|
@@ -334,15 +282,15 @@ function colorLuminance(color) {
|
|
|
334
282
|
}
|
|
335
283
|
|
|
336
284
|
// FF-61: WCAG 2.x contrast ratio, (L1 + 0.05) / (L2 + 0.05) with L1 the lighter relative luminance. The slide tag
|
|
337
|
-
// draws in the primary
|
|
338
|
-
// rule with the same arithmetic (test/tag-colour.mjs in both repositories pins the same
|
|
285
|
+
// draws in the primary color unless that is under 4.5:1 against the slide background; opf-pptx applies the same
|
|
286
|
+
// rule with the same arithmetic (test/tag-colour.mjs in both repositories pins the same color pairs).
|
|
339
287
|
const TAG_MIN_CONTRAST = 4.5;
|
|
340
288
|
function contrastRatio(first, second) {
|
|
341
289
|
const a = colorLuminance(first), b = colorLuminance(second);
|
|
342
290
|
return (Math.max(a, b) + 0.05) / (Math.min(a, b) + 0.05);
|
|
343
291
|
}
|
|
344
|
-
// The slide background the tag sits on: the resolved solid or pattern
|
|
345
|
-
// the
|
|
292
|
+
// The slide background the tag sits on: the resolved solid or pattern color, else (gradient) the scheme light1,
|
|
293
|
+
// the color the background rect also falls back to and opf-pptx uses for a background that is not one color.
|
|
346
294
|
function tagFill(design) {
|
|
347
295
|
const background = design.backgroundColor ?? design.colors.background;
|
|
348
296
|
return contrastRatio(design.colors.primary, background) < TAG_MIN_CONTRAST ? design.colors.text : design.colors.primary;
|
|
@@ -364,7 +312,7 @@ const sameBox = (a, b) => !!a && !!b && a.x === b.x && a.y === b.y && a.width ==
|
|
|
364
312
|
const LINK_URL = /^(https?:|mailto:|tel:)/i;
|
|
365
313
|
|
|
366
314
|
// What the renderer paints with, from the records core's `resolveSlideContext` resolved (slide design, then deck design, then
|
|
367
|
-
// theme, then the engine default, per field: the one order every engine uses). The theme and the
|
|
315
|
+
// theme, then the engine default, per field: the one order every engine uses). The theme and the color scheme keep their
|
|
368
316
|
// sorted keys, so the output does not depend on the order a catalog lists a field in. A reference that resolves nowhere never
|
|
369
317
|
// throws (unless `strictReferences`): the context falls back to core's engine defaults (ENGINE_DEFAULT_THEME, _COLOR_SCHEME,
|
|
370
318
|
// _FONT_SCHEME; a layout to automatic composition) and reports `unresolved-reference`, which is forwarded as a render diagnostic.
|
|
@@ -408,7 +356,7 @@ function resolveDesign(presentation, slide, slideContext) {
|
|
|
408
356
|
background: backgroundDefinition,
|
|
409
357
|
backgroundColor,
|
|
410
358
|
colors: {
|
|
411
|
-
// The slide's drawn single-
|
|
359
|
+
// The slide's drawn single-color background, else the variant's bg1 (a picture, gradient or none).
|
|
412
360
|
background: backgroundColor ?? roles.background,
|
|
413
361
|
surface: roles.surface,
|
|
414
362
|
text: roles.text,
|
|
@@ -535,17 +483,6 @@ function slideRootContent(slide, slidePath) {
|
|
|
535
483
|
return items;
|
|
536
484
|
}
|
|
537
485
|
|
|
538
|
-
function promotedRegionContent(slide, slidePath) {
|
|
539
|
-
const items = [];
|
|
540
|
-
for (const key of PROMOTED_REGION_KEYS) {
|
|
541
|
-
if (slide[key] !== undefined) {
|
|
542
|
-
const payload = contentPayloadFromHost(slide[key], `${slidePath}.${key}`);
|
|
543
|
-
items.push({ ...payload, regionKey: key });
|
|
544
|
-
}
|
|
545
|
-
}
|
|
546
|
-
return items;
|
|
547
|
-
}
|
|
548
|
-
|
|
549
486
|
function blockContent(slide, slidePath) {
|
|
550
487
|
if (!Array.isArray(slide.blocks)) return [];
|
|
551
488
|
return slide.blocks.map((block, index) => contentPayloadFromHost(block, `${slidePath}.blocks.${index}`));
|
|
@@ -574,7 +511,7 @@ function resolveContext(presentation, index, context) {
|
|
|
574
511
|
|
|
575
512
|
function bindSlide(presentation, index, context) {
|
|
576
513
|
const slidePath = `slides.${index}`;
|
|
577
|
-
// Core resolves the slide's canvas, layout, theme,
|
|
514
|
+
// Core resolves the slide's canvas, layout, theme, color scheme, font scheme and family names the one way every engine must
|
|
578
515
|
// (slide design, deck design, theme, engine default), from the records the document embeds and the catalogs the host
|
|
579
516
|
// registered (`options.catalogs`, passed unchanged); `fonts` carries the measurement the host loaded. A slide with no
|
|
580
517
|
// `layout` composes automatically; one whose reference resolves nowhere does too, with an `unresolved-reference` diagnostic,
|
|
@@ -584,10 +521,7 @@ function bindSlide(presentation, index, context) {
|
|
|
584
521
|
// {{deck.slideCount}} hold this slide's number, its section and the deck's slide count, the same values the furniture draws. Core resolved them.
|
|
585
522
|
const slide = slideContext.slide;
|
|
586
523
|
const layout = slideContext.options.layout;
|
|
587
|
-
const contentItems =
|
|
588
|
-
...slideRootContent(slide, slidePath),
|
|
589
|
-
...promotedRegionContent(slide, slidePath)
|
|
590
|
-
];
|
|
524
|
+
const contentItems = slideRootContent(slide, slidePath);
|
|
591
525
|
const blocks = blockContent(slide, slidePath);
|
|
592
526
|
|
|
593
527
|
const design = resolveDesign(presentation, slide, slideContext);
|
|
@@ -595,7 +529,12 @@ function bindSlide(presentation, index, context) {
|
|
|
595
529
|
if (context.mapInputFamily) design.fonts = Object.fromEntries(Object.entries(design.fonts).map(([role, family]) => [role, context.mapInputFamily(family)]));
|
|
596
530
|
// Script fonts (FF-19): each text run is measured and drawn with its script
|
|
597
531
|
// slot's face; the latin slot stays the design font scheme's family.
|
|
598
|
-
|
|
532
|
+
// The slots name the authored families. `design.fonts` is replaced below by the families the registry draws (Arabic Typesetting
|
|
533
|
+
// becomes Noto Naskh Arabic), and a run language's profile is built later, on first use: built from the drawn families, a slot that
|
|
534
|
+
// repeats the scheme's family (an `ar` run in an English deck on the arabic-typesetting scheme) named the replacement, whose policy
|
|
535
|
+
// row has no size multiplier, so that run was drawn at full size while the deck's own Arabic was drawn at the multiplier.
|
|
536
|
+
const slotDesign = { ...design };
|
|
537
|
+
const scriptFonts = createScriptFonts(scriptProfile(presentation, index, slotDesign, context), context.options.textMeasurement, {
|
|
599
538
|
glyphFallback: context.options.glyphFallback,
|
|
600
539
|
onFallback: note => reportGlyphFallback(context, note)
|
|
601
540
|
});
|
|
@@ -607,7 +546,7 @@ function bindSlide(presentation, index, context) {
|
|
|
607
546
|
if (!languageScripts.has(lang)) {
|
|
608
547
|
let own;
|
|
609
548
|
try {
|
|
610
|
-
const profile = scriptProfile(presentation, index,
|
|
549
|
+
const profile = scriptProfile(presentation, index, slotDesign, context, lang);
|
|
611
550
|
own = profile.languageSource === "option" && profile.bcp47?.toLowerCase() !== scriptFonts.profile?.bcp47?.toLowerCase()
|
|
612
551
|
? createScriptFonts(profile, context.options.textMeasurement, { glyphFallback: context.options.glyphFallback, onFallback: note => reportGlyphFallback(context, note) })
|
|
613
552
|
: undefined;
|
|
@@ -774,7 +713,7 @@ function renderResolvedSlide(resolved, slideIndex, options) {
|
|
|
774
713
|
"svg",
|
|
775
714
|
{
|
|
776
715
|
xmlns: "http://www.w3.org/2000/svg",
|
|
777
|
-
// FA-30: a
|
|
716
|
+
// FA-30: a labeled container, not an image: role="img" makes every text node inside presentational.
|
|
778
717
|
role: "group",
|
|
779
718
|
"aria-roledescription": "slide",
|
|
780
719
|
"aria-label": title,
|
|
@@ -844,7 +783,7 @@ function renderBackground(bound, width, height, options) {
|
|
|
844
783
|
});
|
|
845
784
|
}
|
|
846
785
|
|
|
847
|
-
// FA-22 image background, in the paint order of the geometry contract: the canvas
|
|
786
|
+
// FA-22 image background, in the paint order of the geometry contract: the canvas color (the color scheme's default slide
|
|
848
787
|
// background), the picture (recolor and opacity on its pixels only, as for an image block), then the overlay (the whole canvas
|
|
849
788
|
// or an edge band). cover, contain
|
|
850
789
|
// and stretch use the shared fit math with the focus point; tile repeats the picture at its intrinsic size (1 picture px = 1
|
|
@@ -943,7 +882,7 @@ function shapeHelpers(item, bound, options) {
|
|
|
943
882
|
};
|
|
944
883
|
}
|
|
945
884
|
|
|
946
|
-
// One overlay (shared by image backgrounds and image blocks): its outline filled with the
|
|
885
|
+
// One overlay (shared by image backgrounds and image blocks): its outline filled with the color, the color's alpha times the
|
|
947
886
|
// overlay opacity.
|
|
948
887
|
function renderImageOverlay(overlay, bound, options) {
|
|
949
888
|
const paint = imagePaint(overlay.color, bound, bound.design.colors.text);
|
|
@@ -1198,9 +1137,9 @@ function renderTextPayload(item, box, bound, options) {
|
|
|
1198
1137
|
// fontScheme.accent draws the tag; core's textStyle (item.textStyle) already carries it, this is the fallback family.
|
|
1199
1138
|
fontFamily: item.field === "title" ? bound.design.fonts.heading : item.field === "tag" ? bound.design.fonts.accent ?? bound.design.fonts.body : bound.design.fonts.body,
|
|
1200
1139
|
fontWeight: item.field === "title" ? 700 : 400,
|
|
1201
|
-
// The slide tag is the eyebrow label: it draws in the primary
|
|
1202
|
-
// PPTX export writes it, or in the text
|
|
1203
|
-
// slide background (FF-61). Every other text payload here uses the text
|
|
1140
|
+
// The slide tag is the eyebrow label: it draws in the primary color (scheme accent1), as the
|
|
1141
|
+
// PPTX export writes it, or in the text color when the primary is under 4.5:1 against the
|
|
1142
|
+
// slide background (FF-61). Every other text payload here uses the text color.
|
|
1204
1143
|
fill: item.field === "tag" ? tagFill(bound.design) : item.eyebrow ? eyebrowFill(bound.design, item) : bound.design.colors.text,
|
|
1205
1144
|
fit: item.text,
|
|
1206
1145
|
textStyle: item.textStyle,
|
|
@@ -1313,7 +1252,7 @@ const HIDDEN = Object.freeze({ "aria-hidden": "true" });
|
|
|
1313
1252
|
function imageAccessibility(asset, options) {
|
|
1314
1253
|
// An empty alt marks the picture decorative (FA-30), as it does a chart; a picture that is only furniture (a header or footer
|
|
1315
1254
|
// logo repeated on every slide) is decorative unless the author named it.
|
|
1316
|
-
if (options.imageDecorative || asset.alt === "" || (options.
|
|
1255
|
+
if (options.imageDecorative || asset.alt === "" || (options.imageUnlabeled && asset.alt === undefined)) return HIDDEN;
|
|
1317
1256
|
return { role: "img", "aria-label": asset.alt ?? options.imageLabel ?? "Image" };
|
|
1318
1257
|
}
|
|
1319
1258
|
|
|
@@ -1625,7 +1564,7 @@ function renderCode(item, box, bound, options) {
|
|
|
1625
1564
|
...traceAttrs(options, item.path)
|
|
1626
1565
|
})
|
|
1627
1566
|
];
|
|
1628
|
-
// FA-13: code.highlight is one band per run of marked lines, behind the line text; the marked lines keep the syntax
|
|
1567
|
+
// FA-13: code.highlight is one band per run of marked lines, behind the line text; the marked lines keep the syntax colors and
|
|
1629
1568
|
// the others are dimmed (core's codeHighlight* helpers, the same ones the PPTX export calls).
|
|
1630
1569
|
if (highlight) {
|
|
1631
1570
|
const body = layout.parts.find(part => part.role === "body");
|
|
@@ -1723,7 +1662,7 @@ function renderMetric(item, box, bound, options) {
|
|
|
1723
1662
|
return tag('g',{...traceAttrs(options,item.path),...(options.trace?{'data-opf-metric-container':'true'}:{})},children.join('\n'));
|
|
1724
1663
|
}
|
|
1725
1664
|
|
|
1726
|
-
// The trend arrow and
|
|
1665
|
+
// The trend arrow and color for a laid-out metric (core metricTrendMark); undefined without a trend.
|
|
1727
1666
|
function metricTrendMark(layout,bound,background) {
|
|
1728
1667
|
return coreMetricTrendMark(layout,{background,neutral:bound.design.roles.neutrals.trendNeutral.hex});
|
|
1729
1668
|
}
|
|
@@ -2056,14 +1995,14 @@ function renderFurniture(bound, presentation, width, height, options, kind) {
|
|
|
2056
1995
|
}
|
|
2057
1996
|
return tag('g',{},layout.parts.filter(part=>part.kind===kind).map(part=>{
|
|
2058
1997
|
const trace=options.trace?{'data-opf-furniture-kind':kind,'data-opf-furniture-field':part.field,'data-opf-furniture-generated':String(part.generated),'data-opf-furniture-editable':!part.generated?'true':undefined,'data-opf-furniture-source':part.sourcePath}:{};
|
|
2059
|
-
if(part.type==='image')return tag('g',trace,renderImage({value:part.image,path:part.path},part.box,bound,{...options,imageFit:'contain',
|
|
1998
|
+
if(part.type==='image')return tag('g',trace,renderImage({value:part.image,path:part.path},part.box,bound,{...options,imageFit:'contain',imageUnlabeled:true}));
|
|
2060
1999
|
return tag('g',trace,renderTextBox(part.text,part.box,bound,{path:part.path,fit:part.fit,textStyle:part.style,fontFamily:part.style.fontFamily,align:part.alignment,fill:bound.design.colors.mutedText,diagnosticsHandled:true,options}));
|
|
2061
2000
|
}).join(''));
|
|
2062
2001
|
}
|
|
2063
2002
|
function renderBranding(bound,presentation,width,height,options) {
|
|
2064
2003
|
const design={...presentation.design,...bound.slide.design}, pieces=[];
|
|
2065
2004
|
const rootFor=key=>bound.slide.design?.[key]!==undefined?`${bound.path}.design.${key}`:`design.${key}`;
|
|
2066
|
-
// FA-13: a text watermark is one line of the heading font in the theme text
|
|
2005
|
+
// FA-13: a text watermark is one line of the heading font in the theme text color, centered and rotated as core's layoutWatermark says.
|
|
2067
2006
|
if(design.watermark&&typeof design.watermark==='object'&&typeof design.watermark.text==='string'){
|
|
2068
2007
|
const mark=layoutWatermark(design.watermark.text,{width,height},{fontFamily:bound.design.fonts.heading,fontWeight:700,textMeasurement:options.textMeasurement});
|
|
2069
2008
|
if(mark){
|
|
@@ -2224,7 +2163,7 @@ function scriptLine(text, style, bound, type, { rtl = false, numbers = rtl, plac
|
|
|
2224
2163
|
/** One positioned code/metric segment tspan; its script runs flow inside it (no textLength). */
|
|
2225
2164
|
function segmentSpan(attrs, segment, text, style, bound, type, options, syntax) {
|
|
2226
2165
|
const scripted = segment.kind === "tab" ? { content: escapeText(text) } : scriptLine(text, style, bound, type, options);
|
|
2227
|
-
// Syntax highlighting (RR-07): a
|
|
2166
|
+
// Syntax highlighting (RR-07): a colored text segment becomes consecutive sibling tspans, one per run, each a
|
|
2228
2167
|
// traced segment of its own source range holding one text node (the editor's caret mapping reads that), the first
|
|
2229
2168
|
// keeping the accepted x and the rest flowing after it. Plain code keeps one tspan per accepted segment.
|
|
2230
2169
|
const runs = syntax && segment.kind !== "tab" ? codeLineRuns(syntax.tokens, segment.start, segment.end) : undefined;
|
|
@@ -2241,7 +2180,7 @@ function segmentSpan(attrs, segment, text, style, bound, type, options, syntax)
|
|
|
2241
2180
|
return tag("tspan", { ...attrs, "font-family": scripted.family, "font-size": scripted.sizeAdjust && options?.fontSize > 0 ? stableNumber(adjustedFontSize(options.fontSize, scripted.sizeAdjust)) : undefined }, scripted.content);
|
|
2242
2181
|
}
|
|
2243
2182
|
|
|
2244
|
-
// FA-13: the marked lines of code.highlight, their bands (runs of displayed lines) and the lit/dimmed
|
|
2183
|
+
// FA-13: the marked lines of code.highlight, their bands (runs of displayed lines) and the lit/dimmed colors, from core (the PPTX
|
|
2245
2184
|
// export calls the same functions); undefined when the code marks no line.
|
|
2246
2185
|
function codeHighlight(item, layout, bound) {
|
|
2247
2186
|
const highlight = item.value?.highlight;
|
package/dist/text-paths.js
CHANGED
|
@@ -7,9 +7,9 @@ import { embeddingAllowed, fsTypeOf } from './font-fstype.js';
|
|
|
7
7
|
// face's glyph. Everything outside the <text> elements is left byte for byte as the renderer wrote it.
|
|
8
8
|
//
|
|
9
9
|
// A <text> becomes a <g> that keeps the element's own attributes except the text-only ones (so its transform, opacity and
|
|
10
|
-
// data-opf-* trace stay),
|
|
11
|
-
// it on a nested <g>; a link becomes an <a> around its runs; underline and line-through are rectangles in the text
|
|
12
|
-
// the font's own metrics. Text drawn with a
|
|
10
|
+
// data-opf-* trace stay), labeled with its text for assistive technology unless it is aria-hidden; a tspan with a trace keeps
|
|
11
|
+
// it on a nested <g>; a link becomes an <a> around its runs; underline and line-through are rectangles in the text color from
|
|
12
|
+
// the font's own metrics. Text drawn with a color 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
15
|
import { FontLibrary } from "./pdf-fonts.js";
|
|
@@ -23,7 +23,7 @@ const ATTRIBUTE = /([^\s=/>"']+)\s*=\s*(?:"([^"]*)"|'([^']*)')/g;
|
|
|
23
23
|
const TEXT_ONLY = new Set(["x", "y", "dx", "dy", "rotate", "textLength", "lengthAdjust", "text-anchor", "text-rendering", "xml:space", "font-family", "font-size",
|
|
24
24
|
"font-weight", "font-style", "font-variant", "font-stretch", "font-feature-settings", "font-variant-ligatures", "letter-spacing", "word-spacing", "text-decoration",
|
|
25
25
|
"dominant-baseline", "alignment-baseline", "baseline-shift", "direction", "unicode-bidi", "writing-mode"]);
|
|
26
|
-
const
|
|
26
|
+
const COLOR_TABLES = ["COLR", "CBDT", "sbix", "SVG "];
|
|
27
27
|
const libraries = new WeakMap();
|
|
28
28
|
|
|
29
29
|
/**
|
|
@@ -123,7 +123,7 @@ export function outlineSlideText(content, { library, shaper, shape, selectText,
|
|
|
123
123
|
};
|
|
124
124
|
const base = inheritStyle(ROOT_STYLE, rootStyle);
|
|
125
125
|
const REASONS = {
|
|
126
|
-
"
|
|
126
|
+
"color-font": "is a color or bitmap font, which has no plain outlines",
|
|
127
127
|
restricted: "forbids embedding (OS/2 fsType), so its outlines are not written",
|
|
128
128
|
};
|
|
129
129
|
const keep = (family, reason) => {
|
|
@@ -231,10 +231,10 @@ function readableText(runs) {
|
|
|
231
231
|
}).join("");
|
|
232
232
|
}
|
|
233
233
|
|
|
234
|
-
// Why a run stays text, or null: a
|
|
234
|
+
// Why a run stays text, or null: a color or bitmap font, or a family whose fsType restricts embedding (the run was laid out with
|
|
235
235
|
// another face).
|
|
236
236
|
function fallbackReason(run, env) {
|
|
237
|
-
if (
|
|
237
|
+
if (COLOR_TABLES.some((table) => run.face.font.directory?.tables?.[table])) return "color-font";
|
|
238
238
|
for (const family of parseFontFamilies(run.style["font-family"])) {
|
|
239
239
|
if (env.fonts.restricted?.has(family.toLowerCase())) return "restricted";
|
|
240
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;
|
|
@@ -284,7 +284,7 @@ function drawRun(run, defs) {
|
|
|
284
284
|
return run.link ? element("a", [...Object.entries(run.link.node?.attrs ?? { href: run.link.href }), ["aria-label", run.logical]], drawn) : drawn;
|
|
285
285
|
}
|
|
286
286
|
|
|
287
|
-
// Underline, line-through and overline in the text
|
|
287
|
+
// Underline, line-through and overline in the text color, from the font's own metrics (the vector PDF draws the same).
|
|
288
288
|
function decorationRect(kind, run, scale) {
|
|
289
289
|
const font = run.face.font, upem = run.face.upem;
|
|
290
290
|
let position, thickness;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openpresentation/opf-render",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.35.1",
|
|
4
4
|
"description": "Deterministic local OPF renderer for SVG, PNG, and PDF output.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -94,7 +94,7 @@
|
|
|
94
94
|
"fontkit": "^3.0.0",
|
|
95
95
|
"harfbuzzjs": "1.6.4",
|
|
96
96
|
"pako": "3.0.3",
|
|
97
|
-
"@openpresentation/opf": "^0.
|
|
97
|
+
"@openpresentation/opf": "^0.35.1"
|
|
98
98
|
},
|
|
99
99
|
"peerDependencies": {
|
|
100
100
|
"@expo-google-fonts/arimo": "0.4.3",
|
|
@@ -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.
|
|
346
|
+
"@openpresentation/gallery": "0.35.1"
|
|
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": "f701ad61e2b608ac7df2cfd76c5ab52272be6200"
|
|
404
404
|
}
|