@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/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);
|
|
@@ -1034,7 +973,8 @@ function renderArrangements(bound, options) {
|
|
|
1034
973
|
for (const node of arrangement.nodes) {
|
|
1035
974
|
const trace = options.trace && node.path ? {'data-opf-arrangement-path': node.path} : {};
|
|
1036
975
|
if(node.background)parts.push(tag('rect',{...HIDDEN,x:n(node.background.x),y:n(node.background.y),width:n(node.background.width),height:n(node.background.height),rx:n(node.radius??0),fill:paint.fill.hex,...stroke,...trace}));
|
|
1037
|
-
|
|
976
|
+
// A hierarchy's foreground card and a Venn's overlap label are in the background color with the primary outline.
|
|
977
|
+
const nodeFill=arrangement.kind==='hierarchy'||node.overlap?paint.line.hex:fill,nodeStroke=arrangement.kind==='hierarchy'||node.overlap?{...stroke,stroke:paint.fill.hex}:stroke,alpha=arrangement.kind==='venn'&&node.preset==='ellipse'?.5:arrangement.kind==='hierarchy'?.9:1;
|
|
1038
978
|
const nodePaint=alpha===1?nodeStroke:{...nodeStroke,'fill-opacity':alpha};
|
|
1039
979
|
if (node.points) parts.push(tag('path', {...HIDDEN, d: `M${node.points.map(([px, py]) => `${n(px)} ${n(py)}`).join(' L')} Z`, fill:nodeFill, ...nodePaint, ...trace}));
|
|
1040
980
|
else if (node.preset === 'ellipse') parts.push(cycleCircle(node, nodeFill, nodePaint, trace));
|
|
@@ -1197,9 +1137,9 @@ function renderTextPayload(item, box, bound, options) {
|
|
|
1197
1137
|
// fontScheme.accent draws the tag; core's textStyle (item.textStyle) already carries it, this is the fallback family.
|
|
1198
1138
|
fontFamily: item.field === "title" ? bound.design.fonts.heading : item.field === "tag" ? bound.design.fonts.accent ?? bound.design.fonts.body : bound.design.fonts.body,
|
|
1199
1139
|
fontWeight: item.field === "title" ? 700 : 400,
|
|
1200
|
-
// The slide tag is the eyebrow label: it draws in the primary
|
|
1201
|
-
// PPTX export writes it, or in the text
|
|
1202
|
-
// 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.
|
|
1203
1143
|
fill: item.field === "tag" ? tagFill(bound.design) : item.eyebrow ? eyebrowFill(bound.design, item) : bound.design.colors.text,
|
|
1204
1144
|
fit: item.text,
|
|
1205
1145
|
textStyle: item.textStyle,
|
|
@@ -1312,7 +1252,7 @@ const HIDDEN = Object.freeze({ "aria-hidden": "true" });
|
|
|
1312
1252
|
function imageAccessibility(asset, options) {
|
|
1313
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
|
|
1314
1254
|
// logo repeated on every slide) is decorative unless the author named it.
|
|
1315
|
-
if (options.imageDecorative || asset.alt === "" || (options.
|
|
1255
|
+
if (options.imageDecorative || asset.alt === "" || (options.imageUnlabeled && asset.alt === undefined)) return HIDDEN;
|
|
1316
1256
|
return { role: "img", "aria-label": asset.alt ?? options.imageLabel ?? "Image" };
|
|
1317
1257
|
}
|
|
1318
1258
|
|
|
@@ -1624,7 +1564,7 @@ function renderCode(item, box, bound, options) {
|
|
|
1624
1564
|
...traceAttrs(options, item.path)
|
|
1625
1565
|
})
|
|
1626
1566
|
];
|
|
1627
|
-
// 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
|
|
1628
1568
|
// the others are dimmed (core's codeHighlight* helpers, the same ones the PPTX export calls).
|
|
1629
1569
|
if (highlight) {
|
|
1630
1570
|
const body = layout.parts.find(part => part.role === "body");
|
|
@@ -1722,7 +1662,7 @@ function renderMetric(item, box, bound, options) {
|
|
|
1722
1662
|
return tag('g',{...traceAttrs(options,item.path),...(options.trace?{'data-opf-metric-container':'true'}:{})},children.join('\n'));
|
|
1723
1663
|
}
|
|
1724
1664
|
|
|
1725
|
-
// The trend arrow and
|
|
1665
|
+
// The trend arrow and color for a laid-out metric (core metricTrendMark); undefined without a trend.
|
|
1726
1666
|
function metricTrendMark(layout,bound,background) {
|
|
1727
1667
|
return coreMetricTrendMark(layout,{background,neutral:bound.design.roles.neutrals.trendNeutral.hex});
|
|
1728
1668
|
}
|
|
@@ -2055,14 +1995,14 @@ function renderFurniture(bound, presentation, width, height, options, kind) {
|
|
|
2055
1995
|
}
|
|
2056
1996
|
return tag('g',{},layout.parts.filter(part=>part.kind===kind).map(part=>{
|
|
2057
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}:{};
|
|
2058
|
-
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}));
|
|
2059
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}));
|
|
2060
2000
|
}).join(''));
|
|
2061
2001
|
}
|
|
2062
2002
|
function renderBranding(bound,presentation,width,height,options) {
|
|
2063
2003
|
const design={...presentation.design,...bound.slide.design}, pieces=[];
|
|
2064
2004
|
const rootFor=key=>bound.slide.design?.[key]!==undefined?`${bound.path}.design.${key}`:`design.${key}`;
|
|
2065
|
-
// 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.
|
|
2066
2006
|
if(design.watermark&&typeof design.watermark==='object'&&typeof design.watermark.text==='string'){
|
|
2067
2007
|
const mark=layoutWatermark(design.watermark.text,{width,height},{fontFamily:bound.design.fonts.heading,fontWeight:700,textMeasurement:options.textMeasurement});
|
|
2068
2008
|
if(mark){
|
|
@@ -2223,7 +2163,7 @@ function scriptLine(text, style, bound, type, { rtl = false, numbers = rtl, plac
|
|
|
2223
2163
|
/** One positioned code/metric segment tspan; its script runs flow inside it (no textLength). */
|
|
2224
2164
|
function segmentSpan(attrs, segment, text, style, bound, type, options, syntax) {
|
|
2225
2165
|
const scripted = segment.kind === "tab" ? { content: escapeText(text) } : scriptLine(text, style, bound, type, options);
|
|
2226
|
-
// Syntax highlighting (RR-07): a
|
|
2166
|
+
// Syntax highlighting (RR-07): a colored text segment becomes consecutive sibling tspans, one per run, each a
|
|
2227
2167
|
// traced segment of its own source range holding one text node (the editor's caret mapping reads that), the first
|
|
2228
2168
|
// keeping the accepted x and the rest flowing after it. Plain code keeps one tspan per accepted segment.
|
|
2229
2169
|
const runs = syntax && segment.kind !== "tab" ? codeLineRuns(syntax.tokens, segment.start, segment.end) : undefined;
|
|
@@ -2240,7 +2180,7 @@ function segmentSpan(attrs, segment, text, style, bound, type, options, syntax)
|
|
|
2240
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);
|
|
2241
2181
|
}
|
|
2242
2182
|
|
|
2243
|
-
// 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
|
|
2244
2184
|
// export calls the same functions); undefined when the code marks no line.
|
|
2245
2185
|
function codeHighlight(item, layout, bound) {
|
|
2246
2186
|
const highlight = item.value?.highlight;
|
package/dist/text-paths.js
CHANGED
|
@@ -7,15 +7,14 @@ 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
|
-
import { FontLibrary
|
|
16
|
-
import {
|
|
15
|
+
import { FontLibrary } from "./pdf-fonts.js";
|
|
16
|
+
import { layoutText } from "./pdf-text.js";
|
|
17
17
|
import { ROOT_STYLE, attributesOf, inheritStyle, parseFontFamilies, parseFontWeight, parseLength } from "./pdf-style.js";
|
|
18
|
-
import { openTypeLanguage } from "./script-fonts.js";
|
|
19
18
|
import { decodeEntities, escapeAttribute, escapeText, parseXml } from "./pdf-xml.js";
|
|
20
19
|
|
|
21
20
|
const TOKENS = /<(\/?)([A-Za-z][\w:.-]*)((?:[^>"']|"[^"]*"|'[^']*')*?)(\/?)>|<!--[\s\S]*?-->|<!\[CDATA\[[\s\S]*?\]\]>|[^<]+/g;
|
|
@@ -24,7 +23,7 @@ const ATTRIBUTE = /([^\s=/>"']+)\s*=\s*(?:"([^"]*)"|'([^']*)')/g;
|
|
|
24
23
|
const TEXT_ONLY = new Set(["x", "y", "dx", "dy", "rotate", "textLength", "lengthAdjust", "text-anchor", "text-rendering", "xml:space", "font-family", "font-size",
|
|
25
24
|
"font-weight", "font-style", "font-variant", "font-stretch", "font-feature-settings", "font-variant-ligatures", "letter-spacing", "word-spacing", "text-decoration",
|
|
26
25
|
"dominant-baseline", "alignment-baseline", "baseline-shift", "direction", "unicode-bidi", "writing-mode"]);
|
|
27
|
-
const
|
|
26
|
+
const COLOR_TABLES = ["COLR", "CBDT", "sbix", "SVG "];
|
|
28
27
|
const libraries = new WeakMap();
|
|
29
28
|
|
|
30
29
|
/**
|
|
@@ -124,9 +123,8 @@ export function outlineSlideText(content, { library, shaper, shape, selectText,
|
|
|
124
123
|
};
|
|
125
124
|
const base = inheritStyle(ROOT_STYLE, rootStyle);
|
|
126
125
|
const REASONS = {
|
|
127
|
-
"
|
|
126
|
+
"color-font": "is a color or bitmap font, which has no plain outlines",
|
|
128
127
|
restricted: "forbids embedding (OS/2 fsType), so its outlines are not written",
|
|
129
|
-
shaping: "shapes differently in HarfBuzz and in the layout's measurement on text with no pinned width",
|
|
130
128
|
};
|
|
131
129
|
const keep = (family, reason) => {
|
|
132
130
|
if (reported.has(`${family}|${reason}`)) return;
|
|
@@ -233,21 +231,14 @@ function readableText(runs) {
|
|
|
233
231
|
}).join("");
|
|
234
232
|
}
|
|
235
233
|
|
|
236
|
-
// Why a run stays text, or null: a
|
|
237
|
-
// another face)
|
|
238
|
-
// the layout measured by more than 0.1 px (inside a textLength the run is scaled to the measured width, as the browser does).
|
|
234
|
+
// Why a run stays text, or null: a color or bitmap font, or a family whose fsType restricts embedding (the run was laid out with
|
|
235
|
+
// another face).
|
|
239
236
|
function fallbackReason(run, env) {
|
|
240
|
-
if (
|
|
237
|
+
if (COLOR_TABLES.some((table) => run.face.font.directory?.tables?.[table])) return "color-font";
|
|
241
238
|
for (const family of parseFontFamilies(run.style["font-family"])) {
|
|
242
239
|
if (env.fonts.restricted?.has(family.toLowerCase())) return "restricted";
|
|
243
240
|
if (run.face.names.has(family.toLowerCase()) || (env.onRefusal && env.validateFace && env.fonts.match([family],parseFontWeight(run.style["font-weight"],400),/italic|oblique/i.test(run.style["font-style"]??""))?.face===run.face)) break;
|
|
244
241
|
}
|
|
245
|
-
if (env.shape && !run.scope) {
|
|
246
|
-
const direction = run.level % 2 === 1 ? "rtl" : "ltr", language = openTypeLanguage(run.style.lang ?? run.style["xml:lang"]);
|
|
247
|
-
const measured = fontkitShape(run.face, run.text, { features: featuresOf(run.style), language, direction }).reduce((sum, glyph) => sum + glyph.advance, 0);
|
|
248
|
-
const shaped = run.glyphs.reduce((sum, glyph) => sum + glyph.advance, 0);
|
|
249
|
-
if (Math.abs(measured - shaped) * run.scale > 0.1) return "shaping";
|
|
250
|
-
}
|
|
251
242
|
return null;
|
|
252
243
|
}
|
|
253
244
|
|
|
@@ -293,7 +284,7 @@ function drawRun(run, defs) {
|
|
|
293
284
|
return run.link ? element("a", [...Object.entries(run.link.node?.attrs ?? { href: run.link.href }), ["aria-label", run.logical]], drawn) : drawn;
|
|
294
285
|
}
|
|
295
286
|
|
|
296
|
-
// 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).
|
|
297
288
|
function decorationRect(kind, run, scale) {
|
|
298
289
|
const font = run.face.font, upem = run.face.upem;
|
|
299
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.0",
|
|
4
4
|
"description": "Deterministic local OPF renderer for SVG, PNG, and PDF output.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -91,17 +91,17 @@
|
|
|
91
91
|
],
|
|
92
92
|
"dependencies": {
|
|
93
93
|
"bidi-js": "1.1.0",
|
|
94
|
-
"fontkit": "^
|
|
94
|
+
"fontkit": "^3.0.0",
|
|
95
95
|
"harfbuzzjs": "1.6.4",
|
|
96
96
|
"pako": "3.0.3",
|
|
97
|
-
"@openpresentation/opf": "^0.
|
|
97
|
+
"@openpresentation/opf": "^0.35.0"
|
|
98
98
|
},
|
|
99
99
|
"peerDependencies": {
|
|
100
100
|
"@expo-google-fonts/arimo": "0.4.3",
|
|
101
101
|
"@expo-google-fonts/caladea": "0.4.2",
|
|
102
102
|
"@expo-google-fonts/cousine": "0.4.3",
|
|
103
103
|
"@expo-google-fonts/gelasio": "0.4.1",
|
|
104
|
-
"@expo-google-fonts/noto-color-emoji": "0.4.
|
|
104
|
+
"@expo-google-fonts/noto-color-emoji": "0.4.8",
|
|
105
105
|
"@expo-google-fonts/noto-emoji": "0.4.8",
|
|
106
106
|
"@expo-google-fonts/noto-naskh-arabic": "0.4.5",
|
|
107
107
|
"@expo-google-fonts/noto-nastaliq-urdu": "0.4.2",
|
|
@@ -122,7 +122,7 @@
|
|
|
122
122
|
"@expo-google-fonts/noto-sans-lao": "0.4.2",
|
|
123
123
|
"@expo-google-fonts/noto-sans-malayalam": "0.4.2",
|
|
124
124
|
"@expo-google-fonts/noto-sans-math": "0.4.2",
|
|
125
|
-
"@expo-google-fonts/noto-sans-mongolian": "0.4.
|
|
125
|
+
"@expo-google-fonts/noto-sans-mongolian": "0.4.2",
|
|
126
126
|
"@expo-google-fonts/noto-sans-myanmar": "0.4.2",
|
|
127
127
|
"@expo-google-fonts/noto-sans-oriya": "0.4.2",
|
|
128
128
|
"@expo-google-fonts/noto-sans-sc": "0.4.4",
|
|
@@ -293,7 +293,7 @@
|
|
|
293
293
|
"@expo-google-fonts/caladea": "0.4.2",
|
|
294
294
|
"@expo-google-fonts/cousine": "0.4.3",
|
|
295
295
|
"@expo-google-fonts/gelasio": "0.4.1",
|
|
296
|
-
"@expo-google-fonts/noto-color-emoji": "0.4.
|
|
296
|
+
"@expo-google-fonts/noto-color-emoji": "0.4.8",
|
|
297
297
|
"@expo-google-fonts/noto-emoji": "0.4.8",
|
|
298
298
|
"@expo-google-fonts/noto-naskh-arabic": "0.4.5",
|
|
299
299
|
"@expo-google-fonts/noto-nastaliq-urdu": "0.4.2",
|
|
@@ -314,7 +314,7 @@
|
|
|
314
314
|
"@expo-google-fonts/noto-sans-lao": "0.4.2",
|
|
315
315
|
"@expo-google-fonts/noto-sans-malayalam": "0.4.2",
|
|
316
316
|
"@expo-google-fonts/noto-sans-math": "0.4.2",
|
|
317
|
-
"@expo-google-fonts/noto-sans-mongolian": "0.4.
|
|
317
|
+
"@expo-google-fonts/noto-sans-mongolian": "0.4.2",
|
|
318
318
|
"@expo-google-fonts/noto-sans-myanmar": "0.4.2",
|
|
319
319
|
"@expo-google-fonts/noto-sans-oriya": "0.4.2",
|
|
320
320
|
"@expo-google-fonts/noto-sans-sc": "0.4.4",
|
|
@@ -335,7 +335,7 @@
|
|
|
335
335
|
"@expo-google-fonts/tinos": "0.4.2",
|
|
336
336
|
"@hyzyla/pdfium": "3.0.0",
|
|
337
337
|
"@jspawn/qpdf-wasm": "0.0.2",
|
|
338
|
-
"@napi-rs/canvas": "1.1.
|
|
338
|
+
"@napi-rs/canvas": "1.1.1",
|
|
339
339
|
"@resvg/resvg-js": "2.6.2",
|
|
340
340
|
"axe-core": "4.14.0",
|
|
341
341
|
"esbuild": "0.28.2",
|
|
@@ -343,7 +343,7 @@
|
|
|
343
343
|
"pdfjs-dist": "6.5.438",
|
|
344
344
|
"playwright": "1.65.0",
|
|
345
345
|
"sharp": "0.35.5",
|
|
346
|
-
"@openpresentation/gallery": "0.
|
|
346
|
+
"@openpresentation/gallery": "0.35.0"
|
|
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": "7697b266464772a98b57070b0937938d3a12852d"
|
|
404
404
|
}
|