@openpresentation/opf-render 0.32.1 → 0.34.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 +28 -15
- package/dist/chart-options.js +4 -2
- package/dist/charts.js +162 -163
- package/dist/effects.js +302 -0
- package/dist/export-browser.d.ts +7 -0
- package/dist/export-browser.js +18 -6
- package/dist/font-demand.js +673 -0
- package/dist/font-files.js +43 -0
- package/dist/font-registry.js +57 -20
- package/dist/font-selection-metadata.js +21 -0
- package/dist/font-selection.js +6 -0
- package/dist/fonts-browser.d.ts +4 -3
- package/dist/fonts-browser.js +27 -10
- package/dist/fonts-node.d.ts +6 -5
- package/dist/fonts-node.js +27 -7
- package/dist/fonts.d.ts +13 -3
- package/dist/hb-shape.js +4 -4
- package/dist/index.d.ts +6 -0
- package/dist/lazy-fonts.js +209 -44
- package/dist/pdf-fonts.js +1 -1
- package/dist/pdf-text.js +10 -2
- package/dist/pdf-vector.js +2 -31
- package/dist/preview-fonts-cli.js +14 -4
- package/dist/preview-fonts-node.d.ts +18 -0
- package/dist/preview-fonts-node.js +37 -0
- package/dist/raster-markers.js +46 -0
- package/dist/raster.js +7 -4
- package/dist/script-font-pack.js +65 -4
- package/dist/script-fonts.js +6 -90
- package/dist/shapes.js +308 -0
- package/dist/svg.d.ts +6 -0
- package/dist/svg.js +319 -83
- package/dist/text-paths.js +48 -16
- package/package.json +6 -6
package/dist/svg.js
CHANGED
|
@@ -2,10 +2,11 @@
|
|
|
2
2
|
// load instead of switching a feature (script fonts, right-to-left, patterns, code colours, 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
|
-
resolveColorRef as resolveCoreColorRef, resolveScriptFonts, paragraphDirection, physicalAlignment, patternRuns, isolateNumbers,
|
|
5
|
+
resolveColorRef as resolveCoreColorRef, colorTransform, applyColorTransform, stackedText, resolveScriptFonts, paragraphDirection, physicalAlignment, itemAlignment, patternRuns, isolateNumbers,
|
|
6
6
|
metricTrendMark as coreMetricTrendMark, metricPillFill, metricValueColor, tokenizeCode, codeLineRuns, codeSyntaxPaletteForRoles, readableSchemeColor, resolveChartData,
|
|
7
7
|
timelineMarkerShapes, timelineTextColor, layoutWatermark, tableHighlightColor,
|
|
8
|
-
|
|
8
|
+
arrangementPaint, colorContrast,
|
|
9
|
+
codeHighlightLines, codeLineNumbers, codeHighlightBands, codeHighlightColors, fitImage, pictureOverlay, intrinsicImageAspect, intrinsicImageSize, diagramPalette, paintDiagramGroup, iconPathData,
|
|
9
10
|
ENGINE_DEFAULT_THEME, ENGINE_DEFAULT_COLOR_SCHEME, ENGINE_DEFAULT_FONT_SCHEME, ENGINE_DEFAULT_CHART_TYPES
|
|
10
11
|
} from "@openpresentation/opf/composition";
|
|
11
12
|
// The renderer is a library: it never imports a catalog. Hosts register theirs (`options.catalogs`, core `Catalog[]`, for
|
|
@@ -24,6 +25,7 @@ import { fontPolicyFor } from "@openpresentation/opf/font-policy";
|
|
|
24
25
|
import { disabledFeaturesStyle } from "./font-compatibility.js";
|
|
25
26
|
import { isDatasetChart, isDatasetTable, renderCatalogChart } from "./charts.js";
|
|
26
27
|
import { renderCaption, renderFootnotes } from "./annotations.js";
|
|
28
|
+
import { renderConnector, renderShapeBlock, strokeElements } from "./shapes.js";
|
|
27
29
|
import { drawnFaces } from "./drawn-faces.js";
|
|
28
30
|
import { dataUrlFsType, embeddingAllowed } from "./font-fstype.js";
|
|
29
31
|
import { rejectRenamedOptions, selectSlides } from "./slide-sources.js";
|
|
@@ -87,54 +89,54 @@ const ROOT_PAYLOAD_FIELDS = [
|
|
|
87
89
|
];
|
|
88
90
|
|
|
89
91
|
const PROMOTED_REGION_KEYS = [
|
|
90
|
-
"
|
|
92
|
+
"start",
|
|
91
93
|
"center",
|
|
92
|
-
"
|
|
93
|
-
"
|
|
94
|
-
"center+
|
|
95
|
-
"
|
|
94
|
+
"end",
|
|
95
|
+
"start+center",
|
|
96
|
+
"center+end",
|
|
97
|
+
"start+center+end",
|
|
96
98
|
"top",
|
|
97
99
|
"middle",
|
|
98
100
|
"bottom",
|
|
99
101
|
"top+middle",
|
|
100
102
|
"middle+bottom",
|
|
101
103
|
"top+middle+bottom",
|
|
102
|
-
"top:
|
|
104
|
+
"top:start",
|
|
103
105
|
"top:center",
|
|
104
|
-
"top:
|
|
105
|
-
"top:
|
|
106
|
-
"top:center+
|
|
107
|
-
"top:
|
|
108
|
-
"middle:
|
|
106
|
+
"top:end",
|
|
107
|
+
"top:start+center",
|
|
108
|
+
"top:center+end",
|
|
109
|
+
"top:start+center+end",
|
|
110
|
+
"middle:start",
|
|
109
111
|
"middle:center",
|
|
110
|
-
"middle:
|
|
111
|
-
"middle:
|
|
112
|
-
"middle:center+
|
|
113
|
-
"middle:
|
|
114
|
-
"bottom:
|
|
112
|
+
"middle:end",
|
|
113
|
+
"middle:start+center",
|
|
114
|
+
"middle:center+end",
|
|
115
|
+
"middle:start+center+end",
|
|
116
|
+
"bottom:start",
|
|
115
117
|
"bottom:center",
|
|
116
|
-
"bottom:
|
|
117
|
-
"bottom:
|
|
118
|
-
"bottom:center+
|
|
119
|
-
"bottom:
|
|
120
|
-
"top+middle:
|
|
118
|
+
"bottom:end",
|
|
119
|
+
"bottom:start+center",
|
|
120
|
+
"bottom:center+end",
|
|
121
|
+
"bottom:start+center+end",
|
|
122
|
+
"top+middle:start",
|
|
121
123
|
"top+middle:center",
|
|
122
|
-
"top+middle:
|
|
123
|
-
"top+middle:
|
|
124
|
-
"top+middle:center+
|
|
125
|
-
"top+middle:
|
|
126
|
-
"middle+bottom:
|
|
124
|
+
"top+middle:end",
|
|
125
|
+
"top+middle:start+center",
|
|
126
|
+
"top+middle:center+end",
|
|
127
|
+
"top+middle:start+center+end",
|
|
128
|
+
"middle+bottom:start",
|
|
127
129
|
"middle+bottom:center",
|
|
128
|
-
"middle+bottom:
|
|
129
|
-
"middle+bottom:
|
|
130
|
-
"middle+bottom:center+
|
|
131
|
-
"middle+bottom:
|
|
132
|
-
"top+middle+bottom:
|
|
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",
|
|
133
135
|
"top+middle+bottom:center",
|
|
134
|
-
"top+middle+bottom:
|
|
135
|
-
"top+middle+bottom:
|
|
136
|
-
"top+middle+bottom:center+
|
|
137
|
-
"top+middle+bottom:
|
|
136
|
+
"top+middle+bottom:end",
|
|
137
|
+
"top+middle+bottom:start+center",
|
|
138
|
+
"top+middle+bottom:center+end",
|
|
139
|
+
"top+middle+bottom:start+center+end"
|
|
138
140
|
];
|
|
139
141
|
|
|
140
142
|
|
|
@@ -264,6 +266,12 @@ function resolveColorRef(value, bound, fallback) {
|
|
|
264
266
|
// partial one for the background, before the text-dependent roles exist.
|
|
265
267
|
function resolveColorRefIn(value, design, fallback) {
|
|
266
268
|
if (value == null || value === "") return fallback;
|
|
269
|
+
// SH-02: { color, lighten } or { color, darken } resolves its base, then applies core's transform (an alpha byte is kept).
|
|
270
|
+
const transform = colorTransform(value);
|
|
271
|
+
if (transform) {
|
|
272
|
+
const base = resolveColorRefIn(transform.color, design, fallback);
|
|
273
|
+
return typeof base === "string" ? applyColorTransform(base, transform) : base;
|
|
274
|
+
}
|
|
267
275
|
if (typeof value !== "string") return fallback;
|
|
268
276
|
const trimmed = value.trim();
|
|
269
277
|
// Core normalizeHexColor uppercases literals and strips #RRGGBBAA alpha.
|
|
@@ -583,13 +591,15 @@ function bindSlide(presentation, index, context) {
|
|
|
583
591
|
const blocks = blockContent(slide, slidePath);
|
|
584
592
|
|
|
585
593
|
const design = resolveDesign(presentation, slide, slideContext);
|
|
594
|
+
// Private native-font analysis maps authored roles before planning; generated fallback names remain raw.
|
|
595
|
+
if (context.mapInputFamily) design.fonts = Object.fromEntries(Object.entries(design.fonts).map(([role, family]) => [role, context.mapInputFamily(family)]));
|
|
586
596
|
// Script fonts (FF-19): each text run is measured and drawn with its script
|
|
587
597
|
// slot's face; the latin slot stays the design font scheme's family.
|
|
588
598
|
const scriptFonts = createScriptFonts(scriptProfile(presentation, index, design, context), context.options.textMeasurement, {
|
|
589
599
|
glyphFallback: context.options.glyphFallback,
|
|
590
600
|
onFallback: note => reportGlyphFallback(context, note)
|
|
591
601
|
});
|
|
592
|
-
// FA-13: a run with its own language (TextRun.
|
|
602
|
+
// FA-13: a run with its own language (TextRun.language, which core puts on the fragment style as `lang`) is measured and drawn with the
|
|
593
603
|
// script fonts of that language (the Japanese or the Simplified Chinese face for Han text); every other run uses the deck's.
|
|
594
604
|
const languageScripts = new Map();
|
|
595
605
|
const scriptFontsFor = lang => {
|
|
@@ -613,6 +623,14 @@ function bindSlide(presentation, index, context) {
|
|
|
613
623
|
textMeasurement = { ...deckMeasurement, measure: (text, size, style) => pick(style).measure(text, size, style) };
|
|
614
624
|
if (typeof deckMeasurement.outlineBounds === "function") textMeasurement.outlineBounds = (text, size, style) => (pick(style).outlineBounds ?? deckMeasurement.outlineBounds)(text, size, style);
|
|
615
625
|
}
|
|
626
|
+
// Only the outer native preparation resolver retains substituted chosen families/weights. Raw glyph planning stays physical.
|
|
627
|
+
if (context.resolveInputStyle && textMeasurement) textMeasurement = {...textMeasurement, resolveStyle: context.resolveInputStyle};
|
|
628
|
+
if (context.mapInputFamily && textMeasurement) {
|
|
629
|
+
const raw = textMeasurement, style = value => value && typeof value.fontFamily === "string" ? {...value, fontFamily: context.mapInputFamily(value.fontFamily)} : value;
|
|
630
|
+
textMeasurement = {...raw, measure: (text, size, value) => raw.measure(text, size, style(value))};
|
|
631
|
+
for (const name of ["resolveStyle", "resolveFont"]) if (typeof raw[name] === "function") textMeasurement[name] = (value, ...rest) => raw[name](style(value), ...rest);
|
|
632
|
+
if (typeof raw.outlineBounds === "function") textMeasurement.outlineBounds = (text, size, value) => raw.outlineBounds(text, size, style(value));
|
|
633
|
+
}
|
|
616
634
|
// fontScheme.accent (the tag and quote text) takes the same look-alike policy.
|
|
617
635
|
// RR-17 (FF-41): a family that names its weight (Arial Black, Segoe UI Semibold and Light) keeps its own name through composition, so each run
|
|
618
636
|
// resolves it again and draws the replacement's encoded weight (Montserrat 900, Red Hat Display 600 and 300); resolving the role to the
|
|
@@ -723,13 +741,19 @@ function renderResolvedSlide(resolved, slideIndex, options) {
|
|
|
723
741
|
let content = [
|
|
724
742
|
renderBackground(bound, width, height, options),
|
|
725
743
|
renderBranding(bound, resolved.presentation, width, height, options),
|
|
744
|
+
// SH-04: the back layer of the overlay, above the background and the watermark, below the content and the furniture.
|
|
745
|
+
renderOverlayShapes(bound, options, "back"),
|
|
726
746
|
renderSteps(bound, options),
|
|
747
|
+
renderArrangements(bound, options),
|
|
727
748
|
renderTitleRule(bound, options),
|
|
728
749
|
...renderSlideContent(bound, width, height, options),
|
|
750
|
+
renderIcons(bound, options),
|
|
729
751
|
// RR-34: the footnote area core reserved above the footer band, after the content and before the furniture.
|
|
730
752
|
renderFootnotes(bound, options, drawHelpers),
|
|
731
753
|
renderFurniture(bound, resolved.presentation, width, height, options, "header"),
|
|
732
|
-
renderFurniture(bound, resolved.presentation, width, height, options, "footer")
|
|
754
|
+
renderFurniture(bound, resolved.presentation, width, height, options, "footer"),
|
|
755
|
+
// SH-04: the slide's overlay (geometry.overlayShapes) over everything, in array order.
|
|
756
|
+
renderOverlayShapes(bound, options, "front")
|
|
733
757
|
].filter(Boolean);
|
|
734
758
|
// RR-64: text as glyph outlines. The used-face rule below then embeds only the faces of text that stays text.
|
|
735
759
|
let glyphs = "";
|
|
@@ -873,24 +897,52 @@ function renderImageBlock(item, bound, options) {
|
|
|
873
897
|
if (!image) throw new OPFRenderError("missing-image-geometry", "Image rendering requires a coordinated core build with image block geometry (ComposedItem.image).", { path: item.path });
|
|
874
898
|
const picture = renderImage(item, image.box, bound, { ...options, imageFit: image.fit, imageFocus: image.focus, imagePicture: image.picture });
|
|
875
899
|
const trace = options.trace && image.placement ? { "data-opf-image-placement": image.placement.edge } : {};
|
|
876
|
-
|
|
900
|
+
const labels = (image.callouts ?? []).map(callout => tag('g', options.trace ? {'data-opf-image-callout': callout.path} : {},
|
|
901
|
+
tag('rect', {x: stableNumber(callout.box.x), y: stableNumber(callout.box.y), width: stableNumber(callout.box.width), height: stableNumber(callout.box.height), fill: bound.design.colors.background}) +
|
|
902
|
+
renderTextBox(callout.text, callout.textBox, bound, {path: callout.path + '.text', fit: callout.fit, textStyle: callout.textStyle, fill: bound.design.colors.text, align: 'center', diagnosticsHandled: true, options}))).join('');
|
|
903
|
+
if (isImagePlaceholder(picture)) return labels || Object.keys(trace).length ? tag('g', trace, picture + labels) : picture;
|
|
877
904
|
const id = `opf-s${bound.index + 1}-image-${item.path.replace(/[^A-Za-z0-9]+/g, "-")}`, shape = image.shape, defs = [];
|
|
878
|
-
|
|
879
|
-
|
|
905
|
+
// A sketched stroke (core stroke.sketched) clips the picture to its sketched outline, as PowerPoint draws it.
|
|
906
|
+
const sketched = image.stroke?.sketched?.fills[0];
|
|
907
|
+
const masked = sketched || (shape && shape.preset !== "rect");
|
|
908
|
+
if (masked) defs.push(tag("clipPath", { id: `${id}-clip` }, tag("path", { d: sketched ?? shape.path })));
|
|
880
909
|
const matrix = imageRecolorMatrix(image.recolor, bound);
|
|
881
910
|
if (matrix) defs.push(tag("filter", { id: `${id}-recolor`, "color-interpolation-filters": "sRGB" }, tag("feColorMatrix", { type: "matrix", values: matrix })));
|
|
882
911
|
let pixels = matrix || image.opacity !== undefined ? tag("g", { filter: matrix ? `url(#${id}-recolor)` : undefined, opacity: image.opacity === undefined ? undefined : preciseNumber(image.opacity) }, picture) : picture;
|
|
883
912
|
if (masked) pixels = tag("g", { "clip-path": `url(#${id}-clip)` }, pixels);
|
|
884
913
|
const children = [defs.length ? tag("defs", {}, defs.join("")) : "", pixels];
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
914
|
+
// SH-02: the picture's stroke (renamed from border) takes every stroke property, along the frame's preset outline.
|
|
915
|
+
if (image.stroke) {
|
|
916
|
+
const stroke = strokeElements(image.stroke, image.stroke.sketched?.lines[0] ?? shape?.path ?? rectanglePath(image.box), `${id}-stroke`, { box: image.box, closed: true, helpers: shapeHelpers(item, bound, options) });
|
|
917
|
+
if (stroke.defs) children[0] = (children[0] ? children[0].replace(/<\/defs>$/, "") : "<defs>") + stroke.defs + "</defs>";
|
|
918
|
+
children.push(stroke.elements);
|
|
888
919
|
}
|
|
889
|
-
|
|
920
|
+
// RR-105: the overlay covers the drawn picture; a contained picture whose aspect core could not read (a file or a host imageResolver's
|
|
921
|
+
// source) is measured here, from the drawable source, as the PPTX export does.
|
|
922
|
+
const overlay = image.overlay && !image.picture && image.fit === "contain" ? pictureOverlay(image, intrinsicImageAspect(resolveImageSource(item, bound, options).source)) : image.overlay;
|
|
923
|
+
if (overlay) children.push(renderImageOverlay(overlay, bound, options));
|
|
924
|
+
if (labels) children.push(labels);
|
|
890
925
|
if (children.length === 2 && !children[0] && !Object.keys(trace).length) return pixels;
|
|
891
926
|
return tag("g", trace, children.filter(Boolean).join(""));
|
|
892
927
|
}
|
|
893
928
|
|
|
929
|
+
// SH-02: what the shape drawing (src/shapes.js) needs from the renderer: its tag writer, the slide's colors and ColorRef resolution, and
|
|
930
|
+
// the text drawing of a composed item (a shape's text, fitted by core, drawn at the box it was fitted for).
|
|
931
|
+
function shapeHelpers(item, bound, options) {
|
|
932
|
+
const colors = bound.design.colors;
|
|
933
|
+
return {
|
|
934
|
+
tag, idPrefix: `opf-s${bound.index + 1}`, trace: traceAttrs(options, item.path),
|
|
935
|
+
colors: { primary: colors.primary, background: bound.design.backgroundColor ?? colors.background, text: colors.text, border: colors.border },
|
|
936
|
+
resolveColorRef: (value, fallback) => resolveColorRef(value, bound, fallback),
|
|
937
|
+
report: diagnostic => reportDiagnostic({ ...diagnostic, path: item.path }, options),
|
|
938
|
+
drawText: (shapeItem, area, fill) => {
|
|
939
|
+
const value = shapeItem.shape.textDirection === "stacked" ? stackedText(shapeItem.payload.text) : shapeItem.payload.text;
|
|
940
|
+
const config = { path: `${shapeItem.path.replace(/\.(shape|path)$/, "")}.text`, align: "center", fit: shapeItem.text, textStyle: shapeItem.textStyle, fill, fontSize: 25, fontFamily: bound.design.fonts.body, fontWeight: shapeItem.shape.textBold ? 700 : 400, diagnosticsHandled: true, options };
|
|
941
|
+
return Array.isArray(value) ? renderRichTextBox(value, area, bound, config) : renderTextBox(flattenText(value), area, bound, config);
|
|
942
|
+
},
|
|
943
|
+
};
|
|
944
|
+
}
|
|
945
|
+
|
|
894
946
|
// One overlay (shared by image backgrounds and image blocks): its outline filled with the colour, the colour's alpha times the
|
|
895
947
|
// overlay opacity.
|
|
896
948
|
function renderImageOverlay(overlay, bound, options) {
|
|
@@ -952,6 +1004,82 @@ function renderSteps(bound, options) {
|
|
|
952
1004
|
return tag('g', options.trace ? {'data-opf-steps': step.form, 'data-opf-region': step.region} : {}, parts.join('\n'));
|
|
953
1005
|
}).join('\n');
|
|
954
1006
|
}
|
|
1007
|
+
// SH-09: core's pyramids and matrices (geometry.arrangements; SH-18: cycles, circles or rounded rectangles with an arrow after each; SH-17: chevrons and flows), under the text of their entries, as the PPTX export draws them (live
|
|
1008
|
+
// SmartArt or native shapes): the matrix's diamond in the primary lightened 80%, then every node (an empty quadrant too) in the primary with
|
|
1009
|
+
// a centered outline in the background color, core's lineWidth wide. A pyramid level is its trapezoid's polygon (the apex a triangle), a
|
|
1010
|
+
// quadrant a rounded square of core's corner radius (DrawingML roundRect's circular corners). With trace each shape names the entry it
|
|
1011
|
+
// holds in data-opf-arrangement-path, not data-opf-path: it is the layout's drawing.
|
|
1012
|
+
// SH-18: a cycle's circle (DrawingML ellipse) and its arrow (rightArrow, core's outline turned by its rotation), the arrow without an outline.
|
|
1013
|
+
function cycleCircle(node, fill, stroke, trace) {
|
|
1014
|
+
const {x, y, width, height} = node.box, n = stableNumber;
|
|
1015
|
+
return tag('ellipse', {...HIDDEN, cx: n(x + width / 2), cy: n(y + height / 2), rx: n(width / 2), ry: n(height / 2), fill, ...stroke, ...trace});
|
|
1016
|
+
}
|
|
1017
|
+
function cycleArrowPath(arrow, fill) {
|
|
1018
|
+
const n = stableNumber;
|
|
1019
|
+
return tag('path', {...HIDDEN, d: `M${arrow.points.map(([px, py]) => `${n(px)} ${n(py)}`).join(' L')} Z`, fill});
|
|
1020
|
+
}
|
|
1021
|
+
function renderArrangements(bound, options) {
|
|
1022
|
+
const arrangements = bound.geometry.arrangements;
|
|
1023
|
+
if (!arrangements?.length) return '';
|
|
1024
|
+
const roles = bound.design.roles, paint = arrangementPaint(bound.design.colors.primary, roles.background, roles.text, colorContrast, applyColorTransform), n = stableNumber;
|
|
1025
|
+
return arrangements.map(arrangement => {
|
|
1026
|
+
// A card grid (a matrix of other than four entries) is drawn in the card neutral with its border, as every OPF card.
|
|
1027
|
+
const card = arrangement.paint === 'card', fill = card ? roles.neutrals.card.hex : paint.fill.hex;
|
|
1028
|
+
const parts = [], stroke = {stroke: card ? roles.neutrals.cardBorder.hex : paint.line.hex, 'stroke-width': n(arrangement.lineWidth), 'stroke-linejoin': 'miter', 'stroke-miterlimit': 8};
|
|
1029
|
+
if (arrangement.background) {
|
|
1030
|
+
const {x, y, width, height} = arrangement.background;
|
|
1031
|
+
parts.push(tag('path', {...HIDDEN, d: `M${n(x + width / 2)} ${n(y)} L${n(x + width)} ${n(y + height / 2)} L${n(x + width / 2)} ${n(y + height)} L${n(x)} ${n(y + height / 2)} Z`, fill: paint.background.hex}));
|
|
1032
|
+
}
|
|
1033
|
+
for(const edge of arrangement.connectors??[])parts.push(tag('path',{...HIDDEN,d:'M'+edge.points.map(([x,y])=>n(x)+' '+n(y)).join(' L'),fill:'none',stroke:paint.fill.hex,'stroke-width':n(arrangement.lineWidth),'stroke-linecap':'butt','stroke-linejoin':'miter'}));
|
|
1034
|
+
for (const node of arrangement.nodes) {
|
|
1035
|
+
const trace = options.trace && node.path ? {'data-opf-arrangement-path': node.path} : {};
|
|
1036
|
+
if(node.background)parts.push(tag('rect',{...HIDDEN,x:n(node.background.x),y:n(node.background.y),width:n(node.background.width),height:n(node.background.height),rx:n(node.radius??0),fill:paint.fill.hex,...stroke,...trace}));
|
|
1037
|
+
const nodeFill=arrangement.kind==='hierarchy'?paint.line.hex:fill,nodeStroke=arrangement.kind==='hierarchy'?{...stroke,stroke:paint.fill.hex}:stroke,alpha=arrangement.kind==='venn'&&node.preset==='ellipse'?.5:arrangement.kind==='hierarchy'?.9:1;
|
|
1038
|
+
const nodePaint=alpha===1?nodeStroke:{...nodeStroke,'fill-opacity':alpha};
|
|
1039
|
+
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
|
+
else if (node.preset === 'ellipse') parts.push(cycleCircle(node, nodeFill, nodePaint, trace));
|
|
1041
|
+
else parts.push(tag('rect', {...HIDDEN, x: n(node.box.x), y: n(node.box.y), width: n(node.box.width), height: n(node.box.height), rx: n(node.radius ?? 0), fill:nodeFill, ...nodePaint, ...trace}));
|
|
1042
|
+
// SH-18: a cycle's arrow after its node, as PowerPoint stacks them (an arrow of two entries runs under the next circle).
|
|
1043
|
+
for (const arrow of arrangement.arrows?.filter(entry => entry.index === node.index) ?? []) parts.push(cycleArrowPath(arrow, paint.arrow.hex));
|
|
1044
|
+
}
|
|
1045
|
+
return tag('g', options.trace ? {'data-opf-arrangement': arrangement.kind, 'data-opf-arrangement-design': arrangement.design, 'data-opf-region': arrangement.region} : {}, parts.join(''));
|
|
1046
|
+
}).join('\n');
|
|
1047
|
+
}
|
|
1048
|
+
// LH-14: core's icons (geometry.icons) on their chips, over the cards they sit on, as the PPTX export draws them: the chip a circle in
|
|
1049
|
+
// core's chip color; a monochrome glyph core's placed path commands in its glyph color, each part filled (nonzero or even-odd), stroked at
|
|
1050
|
+
// its width with its caps and joins, or both; a multicolor SVG a picture contained in the chip's square, with no chip, in its own colors.
|
|
1051
|
+
// With trace each icon names its path in data-opf-icon (and the entry, metric or group it marks in data-opf-icon-owner), not
|
|
1052
|
+
// data-opf-path: it is decoration, so hit-testing still finds each item by its own text.
|
|
1053
|
+
function renderIcons(bound, options) {
|
|
1054
|
+
const icons = bound.geometry.icons;
|
|
1055
|
+
if (!icons?.length) return "";
|
|
1056
|
+
return icons.map(icon => {
|
|
1057
|
+
const parts = [], glyph = icon.colors.glyph.hex, n = stableNumber;
|
|
1058
|
+
if (icon.picture) parts.push(tag("image", { ...HIDDEN, x: n(icon.box.x), y: n(icon.box.y), width: n(icon.box.width), height: n(icon.box.height), preserveAspectRatio: "xMidYMid meet", href: svgTextDataUri(icon.picture.svg) }));
|
|
1059
|
+
else {
|
|
1060
|
+
parts.push(tag("circle", { ...HIDDEN, cx: n(icon.chip.cx), cy: n(icon.chip.cy), r: n(icon.chip.radius), fill: icon.colors.chip.hex }));
|
|
1061
|
+
for (const part of icon.parts ?? []) parts.push(tag("path", { ...HIDDEN, d: iconPathData(part.commands), fill: part.fill ? glyph : "none", ...(part.fill && part.evenOdd ? { "fill-rule": "evenodd" } : {}),
|
|
1062
|
+
...(part.stroke !== undefined ? { stroke: glyph, "stroke-width": n(part.stroke), "stroke-linecap": part.linecap ?? "butt", "stroke-linejoin": part.linejoin ?? "miter" } : {}) }));
|
|
1063
|
+
}
|
|
1064
|
+
return tag("g", options.trace ? { "data-opf-icon": icon.path, "data-opf-icon-owner": icon.owner } : {}, parts.join(""));
|
|
1065
|
+
}).join("\n");
|
|
1066
|
+
}
|
|
1067
|
+
// An SVG text as a base64 data URI (UTF-8), for an icon drawn as a picture.
|
|
1068
|
+
function svgTextDataUri(text) {
|
|
1069
|
+
const bytes = new TextEncoder().encode(text);
|
|
1070
|
+
let binary = "";
|
|
1071
|
+
for (let index = 0; index < bytes.length; index += 0x8000) binary += String.fromCharCode(...bytes.subarray(index, index + 0x8000));
|
|
1072
|
+
return `data:image/svg+xml;base64,${btoa(binary)}`;
|
|
1073
|
+
}
|
|
1074
|
+
// SH-04: core's overlay (geometry.overlayShapes) in one of its layers, in array order, as the PPTX export writes it: the front layer (and
|
|
1075
|
+
// every connector) over the content and the furniture, the back layer behind the content, over the background and the watermark;
|
|
1076
|
+
// an overlay shape with the shape block's drawing (it is a shape block item, its text fitted by core), a connector its route stroked with
|
|
1077
|
+
// the shape stroke drawing. With trace each names its entry (slides.N.shapes.I) in data-opf-path, as a block does.
|
|
1078
|
+
function renderOverlayShapes(bound, options, layer) {
|
|
1079
|
+
const overlay = bound.geometry.overlayShapes?.filter(entry => (entry.kind === "shape" && entry.layer === "back" ? "back" : "front") === layer);
|
|
1080
|
+
if (!overlay?.length) return "";
|
|
1081
|
+
return overlay.map(entry => entry.kind === "connector" ? renderConnector(entry, shapeHelpers(entry, bound, options)) : renderShapeBlock(entry, shapeHelpers(entry, bound, options))).join("\n");
|
|
1082
|
+
}
|
|
955
1083
|
// LH-130: the short accent rule core sets above a cover's or section's title (geometry.titleRule), filled in the tag's color (tagFill), as
|
|
956
1084
|
// the PPTX export draws it. With trace it names the title it stands for in data-opf-title-rule, not data-opf-path: it is the layout's
|
|
957
1085
|
// drawing, so hit-testing still finds the title by its own text.
|
|
@@ -977,8 +1105,12 @@ function renderSlideContent(bound, width, height, options) {
|
|
|
977
1105
|
const emphasis=bound.geometry.emphasis;
|
|
978
1106
|
const onSurface=emphasis ? emphasisBound(bound, emphasisSurface(bound.design.colorScheme, bound.design.roles)) : undefined;
|
|
979
1107
|
let surfaceDrawn=false,previousFrame;
|
|
1108
|
+
// SH-09: the entries of a pyramid or matrix (geometry.arrangements) are drawn on its nodes, in the color arrangementPaint reads on the primary.
|
|
1109
|
+
// Only entries drawn on their nodes take the color that reads on the primary; beside a level or on a card they keep the slide's.
|
|
1110
|
+
const arranged=new Set((bound.geometry.arrangements??[]).filter(arrangement=>arrangement.text==='node').map(arrangement=>arrangement.path));
|
|
1111
|
+
const onNodes=arranged.size ? {...bound,design:{...bound.design,colors:{...bound.design.colors,text:arrangementPaint(bound.design.colors.primary,bound.design.roles.background,bound.design.roles.text,colorContrast,applyColorTransform).text.hex}}} : undefined;
|
|
980
1112
|
return bound.geometry.items.map(item => {
|
|
981
|
-
const itemBound=item.emphasis&&onSurface ? onSurface : bound;
|
|
1113
|
+
const itemBound=item.emphasis&&onSurface ? onSurface : arranged.has(item.path) ? onNodes : bound;
|
|
982
1114
|
// LH-131: a featured before and after pair's arrow (emphasis.arrow), a primary block arrow as LH-07's flows draw theirs, with the surface.
|
|
983
1115
|
const under=item.emphasis&&onSurface&&!surfaceDrawn ? (surfaceDrawn=true, tag('rect',{...HIDDEN,x:emphasis.box.x,y:emphasis.box.y,width:emphasis.box.width,height:emphasis.box.height,rx:emphasis.radius,fill:onSurface.design.colors.background,...traceAttrs(options,emphasis.path)})
|
|
984
1116
|
+(emphasis.arrow?tag('path',{...HIDDEN,d:blockArrowPath(emphasis.arrow.box,emphasis.arrow.direction),fill:bound.design.colors.primary,...(options.trace?{'data-opf-emphasis-arrow':emphasis.path}:{})}):'')) : '';
|
|
@@ -1032,6 +1164,8 @@ function renderPayload(item, box, bound, options) {
|
|
|
1032
1164
|
return altText(renderTable(item, box, bound, options), item.value?.alt, "group");
|
|
1033
1165
|
case "image":
|
|
1034
1166
|
return renderImageBlock(item, bound, options);
|
|
1167
|
+
case "shape":
|
|
1168
|
+
return renderShapeBlock(item, shapeHelpers(item, bound, options));
|
|
1035
1169
|
case "video":
|
|
1036
1170
|
return renderMedia(item, box, bound, options);
|
|
1037
1171
|
case "code":
|
|
@@ -1052,7 +1186,9 @@ function renderPayload(item, box, bound, options) {
|
|
|
1052
1186
|
}
|
|
1053
1187
|
|
|
1054
1188
|
function renderTextPayload(item, box, bound, options) {
|
|
1055
|
-
|
|
1189
|
+
// LH-63: a text whose first line is a run-in heading draws core's runs (item.runs: the same characters, the heading bold).
|
|
1190
|
+
const value = item.runs ?? item.value;
|
|
1191
|
+
return (Array.isArray(value) ? renderRichTextBox : renderTextBox)(Array.isArray(value) ? value : flattenText(value), box, bound, {
|
|
1056
1192
|
path: item.path,
|
|
1057
1193
|
// Core resolves one alignment per composed item for every engine, from the slide's design, the deck's design
|
|
1058
1194
|
// and the layout record's design (SlideComposition.design).
|
|
@@ -1097,12 +1233,14 @@ function listEntriesSvg(item, fit, bound, options) {
|
|
|
1097
1233
|
const children=[];
|
|
1098
1234
|
// design.listBullet=image: core attaches the icon logo as item.bulletImage and its box (entry.bulletBox: 0.65 em, as PowerPoint draws a:buBlip). An icon that cannot be drawn keeps the glyph marker.
|
|
1099
1235
|
const bullet=item.bulletImage?resolveBulletImage(item.bulletImage,bound,options):undefined;
|
|
1236
|
+
const arranged=bound.geometry.arrangements?.find(arrangement=>arrangement.path===item.path)?.align==='center';
|
|
1100
1237
|
for(const entry of fit.listEntries){
|
|
1101
1238
|
if(entry.marker.none){/* design.listBullet: none draws no marker */}
|
|
1102
1239
|
else if(bullet){const box=entry.bulletBox??{x:entry.marker.x,y:entry.marker.y-entry.marker.fontSize*.65,width:entry.marker.fontSize*.65,height:entry.marker.fontSize*.65};children.push(tag('image',{x:stableNumber(box.x),y:stableNumber(box.y),width:stableNumber(box.width),height:stableNumber(box.height),href:bullet,preserveAspectRatio:'xMidYMid meet','aria-hidden':'true',...(options.trace?{'data-opf-generated':'true'}:{})}));}
|
|
1103
|
-
else children.push(tag('text',{x:stableNumber(entry.marker.x),y:stableNumber(entry
|
|
1240
|
+
else children.push(tag('text',{x:stableNumber(entry.marker.x),y:stableNumber(textMarkerBaseline(entry,bound,arranged,options)),'font-family':fontStack(entry.marker.style.fontFamily,bound.design.fontScheme.type),'font-size':stableNumber(entry.marker.fontSize),...numberMarkerStyle(entry.marker),fill:bound.design.colors.text,'aria-hidden':'true',...markerDirection(entry)},escapeText(entry.marker.text)));
|
|
1104
1241
|
// LH-133: a glossary's term (entry.accent) draws in the tag's color on its backdrop, as the export writes it.
|
|
1105
|
-
|
|
1242
|
+
// SH-09: an entry of a pyramid or matrix (geometry.arrangements) is centered on its node, as the export writes it.
|
|
1243
|
+
const config={path:entry.textPath,align:arranged?'center':'left',fill:entry.accent?eyebrowFill(bound.design,item):bound.design.colors.text,rich:Array.isArray(entry.value),options};
|
|
1106
1244
|
children.push(renderRichLines(typeof entry.value==='string'?[entry.value]:entry.value,entry.text,entry.textBox,bound,config));
|
|
1107
1245
|
if(entry.description)children.push(renderRichLines(typeof entry.descriptionValue==='string'?[entry.descriptionValue]:entry.descriptionValue,entry.description,entry.descriptionBox,bound,{...config,path:entry.descriptionPath,rich:Array.isArray(entry.descriptionValue),fill:bound.design.colors.mutedText}));
|
|
1108
1246
|
}
|
|
@@ -1125,6 +1263,24 @@ function numberMarkerStyle(marker) {
|
|
|
1125
1263
|
return {'font-weight':marker.style.fontWeight===400?undefined:marker.style.fontWeight,'font-style':marker.style.italic?'italic':undefined};
|
|
1126
1264
|
}
|
|
1127
1265
|
|
|
1266
|
+
// Text bullets and numbers share the body's first rendered baseline. Image
|
|
1267
|
+
// bullet boxes keep their existing core geometry; no image metric is inferred.
|
|
1268
|
+
function textMarkerBaseline(entry, bound, arranged, options) {
|
|
1269
|
+
const value=typeof entry.value==='string'?[entry.value]:entry.value,fit=entry.text,line=fit.richLines[0];
|
|
1270
|
+
if(!line)return entry.marker.y;
|
|
1271
|
+
const context=richLineContext(value,fit,bound,{align:arranged?'center':'left',options});
|
|
1272
|
+
const first=line.fragments[0],rtl=fit.directions?fit.directions[0]==='rtl':context.richRtl(first?context.runOffsets[first.runIndex]+first.start:0);
|
|
1273
|
+
return richLineGeometry(line,0,fit,entry.textBox,bound,context.lineAlignment(0),rtl,options.textMeasurement).baseline;
|
|
1274
|
+
}
|
|
1275
|
+
|
|
1276
|
+
function markerDirection(entry) {
|
|
1277
|
+
// The marker's text is the unchanged logical numbering token. A native RTL
|
|
1278
|
+
// auto-number uses its paragraph's base direction; isolate that same token
|
|
1279
|
+
// here while keeping core's EXISTING physical anchor, not a new text box.
|
|
1280
|
+
if (entry.marker.number && entry.direction === 'rtl') return {'data-opf-number-marker':'rtl',direction:'rtl','unicode-bidi':'isolate','text-anchor':entry.marker.anchor==='end'?'start':'end'};
|
|
1281
|
+
return entry.marker.anchor === 'end' ? {'text-anchor':'end'} : {};
|
|
1282
|
+
}
|
|
1283
|
+
|
|
1128
1284
|
// Follows asset: references and the host imageResolver to the drawable source of an image value.
|
|
1129
1285
|
function resolveImageSource(item, bound, options) {
|
|
1130
1286
|
let asset = normalizeAsset(item.value);
|
|
@@ -1386,8 +1542,23 @@ function renderImage(item, box, bound, options) {
|
|
|
1386
1542
|
return tag("g", {...traceAttrs(options,item.path),...generatedAttrs(options),'data-opf-asset-status':'unresolved',role:'img','aria-label':`Image unavailable: ${description}`},children.join("\n"));
|
|
1387
1543
|
}
|
|
1388
1544
|
|
|
1545
|
+
// RR-105: the placeholder's caption is the asset's title, never its id: an `asset:` reference is followed through the deck's assets
|
|
1546
|
+
// (the fields the value writes win, as images layer them); one that does not resolve shows "Media". opf-pptx's mediaCaption is the same.
|
|
1547
|
+
function mediaAsset(value, assets) {
|
|
1548
|
+
let asset = normalizeAsset(value);
|
|
1549
|
+
const seen = new Set();
|
|
1550
|
+
while (typeof asset.src === "string" && asset.src.startsWith("asset:")) {
|
|
1551
|
+
const id = asset.src.slice(6);
|
|
1552
|
+
if (seen.has(id) || !Object.hasOwn(assets ?? {}, id)) return { ...asset, src: "" };
|
|
1553
|
+
seen.add(id);
|
|
1554
|
+
const { src: _source, ...overrides } = asset;
|
|
1555
|
+
asset = { ...normalizeAsset(assets[id]), ...overrides };
|
|
1556
|
+
}
|
|
1557
|
+
return asset;
|
|
1558
|
+
}
|
|
1559
|
+
|
|
1389
1560
|
function renderMedia(item, box, bound, options) {
|
|
1390
|
-
const asset =
|
|
1561
|
+
const asset = mediaAsset(item.value, bound.assets);
|
|
1391
1562
|
const iconBox = centeredBox(box, 72, 72);
|
|
1392
1563
|
const children = [
|
|
1393
1564
|
tag("rect", {
|
|
@@ -1519,7 +1690,10 @@ function renderMetric(item, box, bound, options) {
|
|
|
1519
1690
|
const factor=layout.alignment==='right'?1:layout.alignment==='center'?.5:0;
|
|
1520
1691
|
const lines=part.fit.sourceLines.map((line,index)=>{
|
|
1521
1692
|
const origin=part.linePositions[index];
|
|
1522
|
-
|
|
1693
|
+
// opf#1322: a tracked display line measured with the host's real faces starts at core's own position (below), because a browser
|
|
1694
|
+
// counts the spacing after the last character toward a middle or end anchor and resvg does not.
|
|
1695
|
+
const exactStart=part.style.tracking<0&&!!options.textMeasurement?.measure&&!partRtl(line.start);
|
|
1696
|
+
if(factor&&!exactStart&&!line.segments.some(segment=>segment.kind==='tab'))return tag('text',{x:stableNumber(origin.x+line.width*factor),y:stableNumber(origin.baseline),'text-anchor':factor===1?'end':'middle',
|
|
1523
1697
|
'font-family':fontStack(part.style.fontFamily,bound.design.fontScheme.type),'font-size':stableNumber(part.fit.fontSize),
|
|
1524
1698
|
'font-weight':part.style.fontWeight,'font-style':part.style.italic?'italic':undefined,'letter-spacing':part.style.tracking?stableNumber(part.style.tracking*part.fit.fontSize):undefined,
|
|
1525
1699
|
'xml:space':'preserve',style:'white-space:pre','text-rendering':'geometricPrecision',fill:partFill(part),
|
|
@@ -1529,6 +1703,7 @@ function renderMetric(item, box, bound, options) {
|
|
|
1529
1703
|
...(options.trace?{'data-opf-segment':segment.kind,'data-opf-text-start':segment.start,'data-opf-text-end':segment.end}:{}),
|
|
1530
1704
|
},segment,styledText(part.text.slice(segment.start,segment.end),part.style),part.style,bound,bound.design.fontScheme.type,{rtl:partRtl(line.start),fontSize:part.fit.fontSize})).join(''));
|
|
1531
1705
|
return tag('text',{x:stableNumber(origin.x),y:stableNumber(origin.baseline),'text-anchor':'start',
|
|
1706
|
+
...(exactStart&&factor?{'data-opf-anchor':factor===1?'end':'middle','data-opf-anchor-x':stableNumber(origin.x+line.width*factor)}:{}),
|
|
1532
1707
|
'font-family':fontStack(part.style.fontFamily,bound.design.fontScheme.type),'font-size':stableNumber(part.fit.fontSize),
|
|
1533
1708
|
'font-weight':part.style.fontWeight,'font-style':part.style.italic?'italic':undefined,'letter-spacing':part.style.tracking?stableNumber(part.style.tracking*part.fit.fontSize):undefined,
|
|
1534
1709
|
'xml:space':'preserve',style:'white-space:pre','text-rendering':'geometricPrecision',fill:partFill(part),
|
|
@@ -1559,7 +1734,7 @@ function renderQuote(item, box, bound, options) {
|
|
|
1559
1734
|
if (!part.fit) throw new OPFRenderError('layout-overflow', 'Quote content has no usable internal space; increase its cell size before rendering.', {path:part.path,diagnostics:layout.diagnostics});
|
|
1560
1735
|
const fill=part.role==='footer'?bound.design.colors.mutedText:bound.design.colors.text;
|
|
1561
1736
|
// FA-10: a TextRun[] quote body is laid out by core's rich-text layouter; its runs (quotation marks joined to the first and last) draw like body runs.
|
|
1562
|
-
if(part.runs&&part.fit.richLines)return renderRichLines(part.runs,part.fit,part.box,bound,{path:part.path,fill,fontFamily:part.requestedStyle.fontFamily,diagnosticsHandled:true,textOffset:-1,options});
|
|
1737
|
+
if(part.runs&&part.fit.richLines)return renderRichLines(part.runs,part.fit,part.box,bound,{path:part.path,fill,fontFamily:part.requestedStyle.fontFamily,diagnosticsHandled:true,textOffset:layout.mark?.hidden?0:-1,options});
|
|
1563
1738
|
return renderTextBox(part.text,part.box,bound,{
|
|
1564
1739
|
path:part.path,fit:part.fit,textStyle:part.style,fontFamily:part.requestedStyle.fontFamily,
|
|
1565
1740
|
fill,
|
|
@@ -1568,13 +1743,22 @@ function renderQuote(item, box, bound, options) {
|
|
|
1568
1743
|
});
|
|
1569
1744
|
// FA-12: the attributed person's headshot, cropped to fill the core circle frame (the clip is the outline the native ellipse picture uses).
|
|
1570
1745
|
if (layout.photo) children.push(renderQuotePhoto(layout.photo, item, bound, options));
|
|
1746
|
+
// LH-78: a quote card's decorative mark, in the primary color against the card (as a metric's value is); core places it in the room above the text.
|
|
1747
|
+
if (layout.mark) {
|
|
1748
|
+
const backdrop = item.frameBox ? bound.design.roles.neutrals.card.hex : bound.design.backgroundColor ?? bound.design.colors.background, mark = layout.mark;
|
|
1749
|
+
children.push(tag('g', options.trace ? {'data-opf-quote-mark': 'true'} : {}, renderTextBox(mark.text, mark.box, bound, {
|
|
1750
|
+
path: item.path, fit: mark.fit, textStyle: mark.style, fontFamily: mark.requestedStyle.fontFamily,
|
|
1751
|
+
fill: metricValueColor(bound.design.colors.primary, backdrop, bound.design.colors.text), diagnosticsHandled: true, options,
|
|
1752
|
+
})));
|
|
1753
|
+
}
|
|
1571
1754
|
// LH-114: a pull line's accent rule, in the primary color (core places it; the PPTX export draws the same rectangle).
|
|
1572
1755
|
if (layout.rule) children.unshift(tag('rect', {...HIDDEN, x: stableNumber(layout.rule.x), y: stableNumber(layout.rule.y), width: stableNumber(layout.rule.width), height: stableNumber(layout.rule.height), fill: bound.design.colors.primary, ...(options.trace ? {'data-opf-quote-rule': 'true'} : {})}));
|
|
1573
1756
|
return tag("g", traceAttrs(options, item.path), children.join("\n"));
|
|
1574
1757
|
}
|
|
1575
1758
|
|
|
1576
1759
|
function renderQuotePhoto(photo, item, bound, options) {
|
|
1577
|
-
|
|
1760
|
+
// LH-132: a portrait beside the quote crops around the focus core gave it (the upper third), as the export does.
|
|
1761
|
+
const picture = renderImage({ value: photo.value, path: photo.path }, photo.box, bound, { ...options, imageFit: 'cover', ...(photo.focus ? { imageFocus: photo.focus } : {}) });
|
|
1578
1762
|
// An unresolved source keeps the ordinary placeholder, unmasked, like the export.
|
|
1579
1763
|
if (isImagePlaceholder(picture)) return picture;
|
|
1580
1764
|
const id = `opf-s${bound.index + 1}-quote-photo-${item.path.replace(/[^A-Za-z0-9]+/g, '-')}`;
|
|
@@ -1585,11 +1769,13 @@ function renderTimeline(item, box, bound, options) {
|
|
|
1585
1769
|
const layout=item.timelineLayout;
|
|
1586
1770
|
if(!layout)throw new OPFRenderError('missing-timeline-layout','Timeline rendering requires a coordinated core build with shared timeline geometry.',{path:item.path});
|
|
1587
1771
|
const scale=Math.min(bound.design.dimensions.width,bound.design.dimensions.height)/720;
|
|
1772
|
+
const background=bound.design.backgroundColor??bound.design.colors.background;
|
|
1588
1773
|
const children=[tag('line',{...HIDDEN,...layout.connector,stroke:bound.design.colors.border,'stroke-width':3*scale,...traceAttrs(options,item.path)})];
|
|
1774
|
+
for(const range of layout.ranges??[])children.push(tag('rect',{...HIDDEN,x:stableNumber(range.box.x),y:stableNumber(range.box.y),width:stableNumber(range.box.width),height:stableNumber(range.box.height),fill:bound.design.colors.primary,'fill-opacity':.32,stroke:background,'stroke-width':stableNumber(2*scale),...traceAttrs(options,range.path),...(options.trace?{'data-opf-timeline-range':range.eventIndex}:{})}));
|
|
1775
|
+
for(const link of layout.rangeLinks??[])children.push(tag('line',{...HIDDEN,x1:stableNumber(link.x1),y1:stableNumber(link.y1),x2:stableNumber(link.x2),y2:stableNumber(link.y2),stroke:bound.design.colors.border,'stroke-width':stableNumber(scale),...traceAttrs(options,link.path),...(options.trace?{'data-opf-timeline-range-link':link.eventIndex}:{})}));
|
|
1589
1776
|
// LH-121: the connector up to the current event in the primary color, over the border-colored rest.
|
|
1590
1777
|
if(layout.progress)children.push(tag('line',{...HIDDEN,...layout.progress,stroke:bound.design.colors.primary,'stroke-width':3*scale,...traceAttrs(options,item.path),...(options.trace?{'data-opf-timeline-progress':'true'}:{})}));
|
|
1591
1778
|
// FA-11: status colors come from the deck (core's timelineMarkerShapes / timelineTextColor); a marker with no status draws the plain primary circle.
|
|
1592
|
-
const background=bound.design.backgroundColor??bound.design.colors.background;
|
|
1593
1779
|
const statusColors={background,primary:bound.design.colors.primary,text:bound.design.colors.text,mutedText:bound.design.colors.mutedText};
|
|
1594
1780
|
for(const marker of layout.markers){
|
|
1595
1781
|
if(!marker.status){
|
|
@@ -1618,7 +1804,7 @@ function renderTimeline(item, box, bound, options) {
|
|
|
1618
1804
|
|
|
1619
1805
|
function renderTable(item, box, bound, options) {
|
|
1620
1806
|
const scale = Math.min(bound.design.dimensions.width, bound.design.dimensions.height) / 720;
|
|
1621
|
-
const layout = layoutTable(item.value, box, {scale, minFontSize:(bound.composition ?? bound.geometry.composition).minFontSize, fontFamily:bound.design.fonts.body, ...(bound.design.fonts.code ? {codeFontFamily:bound.design.fonts.code} : {}), textMeasurement:options.textMeasurement, path:item.path, presentation:bound.presentation, alignment:bound.geometry.design.contentAlignment, ...(bound.geometry?.direction === "rtl" ? {direction:"rtl"} : {}), ...(item.tableGrowth ? {growth:item.tableGrowth} : {}), ...(item.tableHighlight ? {highlight:item.tableHighlight} : {})});
|
|
1807
|
+
const layout = layoutTable(item.value, box, {scale, minFontSize:(bound.composition ?? bound.geometry.composition).minFontSize, fontFamily:bound.design.fonts.body, ...(bound.design.fonts.code ? {codeFontFamily:bound.design.fonts.code} : {}), textMeasurement:options.textMeasurement, path:item.path, presentation:bound.presentation, ...(typeof bound.scriptFonts?.profile?.bcp47 === "string" ? {language:bound.scriptFonts.profile.bcp47} : {}), alignment:itemAlignment(bound.geometry.design.contentAlignment), ...(bound.geometry?.direction === "rtl" ? {direction:"rtl"} : {}), ...(item.tableGrowth ? {growth:item.tableGrowth} : {}), ...(item.tableHighlight ? {highlight:item.tableHighlight} : {})});
|
|
1622
1808
|
const children = [];
|
|
1623
1809
|
// LH-113: a highlighted row (table.highlight, or the rows the slide's texts name) draws on an accent tint of the surface.
|
|
1624
1810
|
const highlightFill = layout.rows.some((row) => row.cells.some((cell) => cell.highlighted)) ? tableHighlightColor(bound.design.colors.surface, bound.design.colors.primary, bound.design.colors.text) : undefined;
|
|
@@ -1689,7 +1875,8 @@ function renderTableBorders(defaultEdges, explicitEdges, scale, bound, options)
|
|
|
1689
1875
|
? [start,axis.fixed,end,axis.fixed] : [axis.fixed,start,axis.fixed,end]}));
|
|
1690
1876
|
});
|
|
1691
1877
|
return [...defaults,...explicitEdges].flatMap(({coordinates:[x1,y1,x2,y2],border,path}) => {
|
|
1692
|
-
|
|
1878
|
+
// An explicit border without a width keeps the table rule's own (one slide pixel).
|
|
1879
|
+
const width = border?.width != null ? border.width * scale : 1;
|
|
1693
1880
|
if (width === 0) return [];
|
|
1694
1881
|
const stroke = border?.color == null
|
|
1695
1882
|
? defaultColor
|
|
@@ -1742,7 +1929,7 @@ function renderDiagram(item, box, bound, options) {
|
|
|
1742
1929
|
function renderChart(item, box, bound, options) {
|
|
1743
1930
|
// Catalog chart types preview the native
|
|
1744
1931
|
// construct opf-pptx exports; other ids keep the legacy single-series preview.
|
|
1745
|
-
const rendered = renderCatalogChart(item, box, bound, options, { tag, traceAttrs, stableNumber, renderTextBox, reportDiagnostic });
|
|
1932
|
+
const rendered = renderCatalogChart(item, box, bound, options, { tag, traceAttrs, stableNumber, renderTextBox, reportDiagnostic, resolveColorRef: (value, fallback) => resolveColorRef(value, bound, fallback) });
|
|
1746
1933
|
if (rendered) return rendered;
|
|
1747
1934
|
const chart = item.value ?? {};
|
|
1748
1935
|
const chartType = chart.type ?? engineDefaults.chartType;
|
|
@@ -1887,7 +2074,12 @@ function renderBranding(bound,presentation,width,height,options) {
|
|
|
1887
2074
|
}
|
|
1888
2075
|
} else if(design.watermark){
|
|
1889
2076
|
// The group keeps its bare opacity attribute (opf-pptx's watermark parity test reads it); the picture itself is hidden.
|
|
1890
|
-
|
|
2077
|
+
const mark=renderImage({value:design.watermark,path:rootFor('watermark')},{x:width*.3,y:height*.3,width:width*.4,height:height*.4},bound,{...options,imageFit:'contain',imageDecorative:true});
|
|
2078
|
+
// LH-164: on the accent surface of a message-only slide the mark is drawn in the slide's text color (the export's one-color duotone), so a mark made for the plain surface still reads.
|
|
2079
|
+
const matrix=bound.geometry?.surface&&!isImagePlaceholder(mark)?imageRecolorMatrix({type:'duotone',dark:bound.design.colors.text,light:bound.design.colors.text},bound):undefined, filterId=`opf-s${bound.index+1}-watermark-recolor`;
|
|
2080
|
+
// The filter and the opacity sit on one group: the vector PDF rasterizes a filtered group on its own, without its ancestors' opacity.
|
|
2081
|
+
const watermarkOpacity=typeof design.watermark==='object'?design.watermark.opacity??.08:.08;
|
|
2082
|
+
pieces.push(matrix?tag('g',{opacity:watermarkOpacity,filter:`url(#${filterId})`},tag('defs',{},tag('filter',{id:filterId,'color-interpolation-filters':'sRGB'},tag('feColorMatrix',{type:'matrix',values:matrix})))+mark):tag('g',{opacity:watermarkOpacity},mark));
|
|
1891
2083
|
}
|
|
1892
2084
|
// Cover and section slides: the logo core composed (the primary organization's full logo, or the design.logo override, in the
|
|
1893
2085
|
// variant for this slide's background) at the top-left of the free area, anchored left. RR-71: the picture is named by its
|
|
@@ -2125,9 +2317,20 @@ function embeddable(font) {
|
|
|
2125
2317
|
// object while its dataUrl is unchanged: the handle's list holds the same objects on every slide, and its URIs run to tens of
|
|
2126
2318
|
// megabytes.
|
|
2127
2319
|
const checkedDataUrls = new WeakMap();
|
|
2320
|
+
function isFontDataUrl(value) {
|
|
2321
|
+
// The MIME prefix has a fixed maximum length. Scan the unbounded payload without a regexp stack or a suffix copy.
|
|
2322
|
+
// exec's input retains the same coercion (and throwing conversions) as the former whole-URI RegExp.test.
|
|
2323
|
+
const prefix = /^data:font\/(ttf|otf|woff|woff2);base64,/.exec(value);
|
|
2324
|
+
if (!prefix || prefix[0].length === prefix.input.length) return false;
|
|
2325
|
+
for (let index = prefix[0].length; index < prefix.input.length; index++) {
|
|
2326
|
+
const code = prefix.input.charCodeAt(index);
|
|
2327
|
+
if (!((code >= 65 && code <= 90) || (code >= 97 && code <= 122) || (code >= 48 && code <= 57) || code === 43 || code === 47 || code === 61)) return false;
|
|
2328
|
+
}
|
|
2329
|
+
return true;
|
|
2330
|
+
}
|
|
2128
2331
|
function assertEmbeddableFont(font) {
|
|
2129
2332
|
const valid = typeof font?.family === "string" && !/[\u0000-\u001f"'\\<>;]/.test(font.family) && Number.isInteger(font.weight) && font.weight >= 1 && font.weight <= 1000
|
|
2130
|
-
&& (checkedDataUrls.get(font) === font.dataUrl ||
|
|
2333
|
+
&& (checkedDataUrls.get(font) === font.dataUrl || isFontDataUrl(font.dataUrl));
|
|
2131
2334
|
if (!valid) throw new OPFRenderError("invalid-embedded-font", "Embedded fonts require a plain family name, valid weight, and a font data URI.");
|
|
2132
2335
|
checkedDataUrls.set(font, font.dataUrl);
|
|
2133
2336
|
}
|
|
@@ -2169,9 +2372,8 @@ function trimRichLineEdges(line,textMeasurement) {
|
|
|
2169
2372
|
return {...line,fragments,width:x};
|
|
2170
2373
|
}
|
|
2171
2374
|
|
|
2172
|
-
function
|
|
2173
|
-
|
|
2174
|
-
const logicalAlignment=fit.placement?.alignment??config.align??bound.geometry.design.contentAlignment;
|
|
2375
|
+
function richLineContext(value,fit,bound,config) {
|
|
2376
|
+
const logicalAlignment=fit.placement?.alignment??config.align??itemAlignment(bound.geometry.design.contentAlignment);
|
|
2175
2377
|
// Each line takes its paragraph's direction from core (every wrapped line shares it) and its physical edge from that.
|
|
2176
2378
|
const lineAlignment=index=>fit.placement?.lines[index]?.alignment??physicalAlignment(logicalAlignment,fit.directions?.[index]);
|
|
2177
2379
|
// A rich quote body draws its quotation marks inside the first and last run; config.textOffset (-1) keeps every traced offset on the authored text.
|
|
@@ -2182,21 +2384,30 @@ function renderRichLines(value,fit,box,bound,config) {
|
|
|
2182
2384
|
// shape adjacent runs naturally inside each estimated line instead of turning
|
|
2183
2385
|
// those estimates into visible gaps. Supplied measurements keep exact origins.
|
|
2184
2386
|
const naturalFlow=!config.options.textMeasurement?.measure&&!fit.placement;
|
|
2387
|
+
return {lineAlignment,runOffsets,richRtl,naturalFlow};
|
|
2388
|
+
}
|
|
2389
|
+
|
|
2390
|
+
function richLineGeometry(sourceLine,lineIndex,fit,box,bound,alignment,rtl,measurement) {
|
|
2391
|
+
const edgeTrim=rtl&&alignment==='right'?trimRichLineEdges(sourceLine,measurement):null;
|
|
2392
|
+
const line=edgeTrim??sourceLine,placed=fit.placement?.lines[lineIndex];
|
|
2393
|
+
const lineShift=bound.scriptFonts?baselineShift(...line.fragments.filter(fragment=>fragment.kind!=='tab'&&fragment.text).map(fragment=>bound.scriptFonts.plan(fragment.text,fragment.style))):0;
|
|
2394
|
+
const shiftPx=lineShift*Math.max(fit.fontSize,...line.fragments.map(fragment=>fragment.fontSize));
|
|
2395
|
+
return {edgeTrim,line,placed,baseline:(placed?.baseline??box.y+line.baseline)-shiftPx};
|
|
2396
|
+
}
|
|
2397
|
+
|
|
2398
|
+
function renderRichLines(value,fit,box,bound,config) {
|
|
2399
|
+
for (const run of value) assertXmlText(typeof run === 'string' ? run : run.text, config.path);
|
|
2400
|
+
const {lineAlignment,runOffsets,richRtl,naturalFlow}=richLineContext(value,fit,bound,config);
|
|
2185
2401
|
const hasTabs=fit.richLines.some(line=>line.fragments.some(fragment=>fragment.kind==='tab'));
|
|
2186
2402
|
const content=fit.richLines.map((sourceLine,lineIndex)=>{
|
|
2187
2403
|
const alignment=lineAlignment(lineIndex);
|
|
2188
2404
|
const sourceFirst=sourceLine.fragments[0],rtl=fit.directions?fit.directions[lineIndex]==='rtl':richRtl(sourceFirst?runOffsets[sourceFirst.runIndex]+sourceFirst.start:0);
|
|
2189
|
-
//
|
|
2190
|
-
const edgeTrim=
|
|
2191
|
-
const line=edgeTrim??sourceLine;
|
|
2405
|
+
// Shared with text list markers, including the actual post-trim policy plan.
|
|
2406
|
+
const {edgeTrim,line,placed,baseline}=richLineGeometry(sourceLine,lineIndex,fit,box,bound,alignment,rtl,config.options.textMeasurement);
|
|
2192
2407
|
const lineHasTab=line.fragments.some(fragment=>fragment.kind==='tab');
|
|
2193
2408
|
const flow=naturalFlow&&!lineHasTab;
|
|
2194
2409
|
const offset=alignment==='right'?box.width-line.width:alignment==='center'?(box.width-line.width)/2:0;
|
|
2195
|
-
const placed
|
|
2196
|
-
// RR-38: a line with runs in a policy replacement (Arabic Typesetting) takes PowerPoint's baseline of the real font, above core's.
|
|
2197
|
-
const lineShift=bound.scriptFonts?baselineShift(...line.fragments.filter(fragment=>fragment.kind!=='tab'&&fragment.text).map(fragment=>bound.scriptFonts.plan(fragment.text,fragment.style))):0;
|
|
2198
|
-
const shiftPx=lineShift*Math.max(fit.fontSize,...line.fragments.map(fragment=>fragment.fontSize));
|
|
2199
|
-
const originX=placed?placed.x+(edgeTrim?sourceLine.width-line.width:0):box.x+offset,baseline=(placed?.baseline??box.y+line.baseline)-shiftPx;
|
|
2410
|
+
const originX=placed?placed.x+(edgeTrim?sourceLine.width-line.width:0):box.x+offset;
|
|
2200
2411
|
const firstFragment=line.fragments[0];
|
|
2201
2412
|
const renderFragment=(fragment,asFlow,edges={})=>{
|
|
2202
2413
|
const run=fragment.run;
|
|
@@ -2218,7 +2429,17 @@ function renderRichLines(value,fit,box,bound,config) {
|
|
|
2218
2429
|
const measuredLine=!asFlow&&!naturalFlow&&fragment.kind!=='tab'&&fragment.width>0;
|
|
2219
2430
|
// A right-to-left fragment draws without its trailing white space, after that white space's measured advance (rtlTrailingSpace).
|
|
2220
2431
|
const trail=rtl&&measuredLine&&fragment.kind!=='marker'?rtlTrailingSpace(fragment.text):'';
|
|
2221
|
-
|
|
2432
|
+
// RR-105: an underline, link or strikethrough ends with the line's last visible character, as PowerPoint draws it: a decorated fragment
|
|
2433
|
+
// at the end of a left-to-right line draws without its trailing white space (it has nothing after it), and white space alone there
|
|
2434
|
+
// draws undecorated (measured or flowing: nothing after it is visible).
|
|
2435
|
+
const decorated=fragment.kind!=='marker'&&fragment.kind!=='tab'&&(run.underline||linked||run.strikethrough);
|
|
2436
|
+
const atLineEnd=decorated&&!rtl&&line.fragments.slice(line.fragments.indexOf(fragment)+1).every(next=>next.kind!=='marker'&&!/\S/u.test(next.text));
|
|
2437
|
+
const endTrail=atLineEnd?rtlTrailingSpace(fragment.text):'',blankEnd=atLineEnd&&!/\S/u.test(fragment.text);
|
|
2438
|
+
let gap=0,endGap=0;
|
|
2439
|
+
if(endTrail){
|
|
2440
|
+
const measure=textWidthMeasurer(fragment.style,config.options.textMeasurement),full=measure(fragment.text,fragment.fontSize);
|
|
2441
|
+
endGap=full>0?Math.min(fragment.width,Math.max(0,fragment.width*(1-measure(fragment.text.slice(0,-endTrail.length),fragment.fontSize)/full))):0;
|
|
2442
|
+
}
|
|
2222
2443
|
if(trail){
|
|
2223
2444
|
const measure=textWidthMeasurer(fragment.style,config.options.textMeasurement),full=measure(fragment.text,fragment.fontSize);
|
|
2224
2445
|
gap=full>0?Math.min(fragment.width,Math.max(0,fragment.width*(1-measure(fragment.text.slice(0,-trail.length),fragment.fontSize)/full))):0;
|
|
@@ -2228,7 +2449,7 @@ function renderRichLines(value,fit,box,bound,config) {
|
|
|
2228
2449
|
// LH-32: a tracked run (an eyebrow) keeps its natural advance: its letter spacing is in core's width, and a textLength would leave the
|
|
2229
2450
|
// trailing spacing to each rasterizer's own reading.
|
|
2230
2451
|
const tracked=fragment.kind!=='tab'&&!!fragment.style.tracking;
|
|
2231
|
-
const drawnText=styledText(trail?fragment.text.slice(0,-trail.length):fragment.text,fragment.style),drawnWidth=fragment.width-gap;
|
|
2452
|
+
const drawnText=styledText(trail?fragment.text.slice(0,-trail.length):endTrail?fragment.text.slice(0,-endTrail.length):fragment.text,fragment.style),drawnWidth=fragment.width-gap-endGap;
|
|
2232
2453
|
// FA-13: an inline code run falls back to a monospace face, and a run with its own language declares it.
|
|
2233
2454
|
const runLang=fragment.kind!=='tab'&&fragment.style.lang?(bound.scriptFontsFor?.(fragment.style.lang)?.profile.bcp47??fragment.style.lang):undefined;
|
|
2234
2455
|
const scripted=fragment.kind==='tab'?{content:escapeText(fragment.text)}:scriptLine(drawnText,fragment.style,bound,run.code===true?'monospace':bound.design.fontScheme.type,{rtl:rtl&&!asFlow,numbers:rtl&&run.code!==true,
|
|
@@ -2239,9 +2460,13 @@ function renderRichLines(value,fit,box,bound,config) {
|
|
|
2239
2460
|
// RR-34: a citation/footnote marker is generated text (no source range): it is traced as a marker
|
|
2240
2461
|
// segment without text offsets, so editors never read it as part of the run, and it is not linked.
|
|
2241
2462
|
const marker=fragment.kind==='marker';
|
|
2242
|
-
const rendered=tag(asFlow?'tspan':'text',{...(runLang?{lang:runLang,'xml:lang':runLang}:{}),...(config.options.trace?marker?{'data-opf-segment':'marker','data-opf-marker':fragment.text}:{'data-opf-text-start':runOffsets[fragment.runIndex]+fragment.start,'data-opf-text-end':runOffsets[fragment.runIndex]+fragment.end-trail.length,'data-opf-segment':fragment.kind}:{}),...position,'xml:space':'preserve','text-rendering':asFlow?undefined:'geometricPrecision',textLength:fixedAdvance&&!tracked?stableNumber(drawnWidth):undefined,lengthAdjust:fixedAdvance&&!tracked?'spacingAndGlyphs':undefined,'font-family':scripted.family??fontStack(fragment.style.fontFamily,run.code===true?'monospace':bound.design.fontScheme.type),'font-size':stableNumber(adjustedFontSize(fragment.fontSize,scripted.sizeAdjust)),'font-weight':fragment.style.fontWeight,'font-style':fragment.style.italic?'italic':asFlow?'normal':undefined,'letter-spacing':fragment.kind!=='tab'&&fragment.style.tracking?stableNumber(fragment.style.tracking*fragment.fontSize):undefined,'text-decoration':marker?undefined:[run.underline||linked?'underline':'',run.strikethrough?'line-through':''].filter(Boolean).join(' ')||undefined,fill:runFill},content);
|
|
2243
|
-
|
|
2244
|
-
|
|
2463
|
+
const rendered=tag(asFlow?'tspan':'text',{...(runLang?{lang:runLang,'xml:lang':runLang}:{}),...(config.options.trace?marker?{'data-opf-segment':'marker','data-opf-marker':fragment.text}:{'data-opf-text-start':runOffsets[fragment.runIndex]+fragment.start,'data-opf-text-end':runOffsets[fragment.runIndex]+fragment.end-trail.length-endTrail.length,'data-opf-segment':fragment.kind}:{}),...position,'xml:space':'preserve','text-rendering':asFlow?undefined:'geometricPrecision',textLength:fixedAdvance&&!tracked?stableNumber(drawnWidth):undefined,lengthAdjust:fixedAdvance&&!tracked?'spacingAndGlyphs':undefined,'font-family':scripted.family??fontStack(fragment.style.fontFamily,run.code===true?'monospace':bound.design.fontScheme.type),'font-size':stableNumber(adjustedFontSize(fragment.fontSize,scripted.sizeAdjust)),'font-weight':fragment.style.fontWeight,'font-style':fragment.style.italic?'italic':asFlow?'normal':undefined,'letter-spacing':fragment.kind!=='tab'&&fragment.style.tracking?stableNumber(fragment.style.tracking*fragment.fontSize):undefined,'text-decoration':marker||blankEnd?undefined:[run.underline||linked?'underline':'',run.strikethrough?'line-through':''].filter(Boolean).join(' ')||undefined,fill:runFill},content);
|
|
2464
|
+
// RR-105 (2026-11-13): with a trace, the white space cut from a decorated fragment at a line end keeps a node of its own, undecorated
|
|
2465
|
+
// and outside the link, so every source offset still has a traced node whose text is its source text (an editor selects by offset;
|
|
2466
|
+
// a selection ending after that space found no node). Without a trace the output is unchanged.
|
|
2467
|
+
const cutSpace=config.options.trace&&endTrail&&!marker?tag(asFlow?'tspan':'text',{'data-opf-text-start':runOffsets[fragment.runIndex]+fragment.end-endTrail.length,'data-opf-text-end':runOffsets[fragment.runIndex]+fragment.end,'data-opf-segment':fragment.kind,...(asFlow?{}:{x:stableNumber(originX+fragmentX+gap+drawnWidth),y:position.y}),'xml:space':'preserve','font-family':scripted.family??fontStack(fragment.style.fontFamily,run.code===true?'monospace':bound.design.fontScheme.type),'font-size':stableNumber(adjustedFontSize(fragment.fontSize,scripted.sizeAdjust)),'font-weight':fragment.style.fontWeight,'font-style':fragment.style.italic?'italic':asFlow?'normal':undefined,fill:runFill},escapeText(endTrail)):'';
|
|
2468
|
+
if(linked)return tag('a',{href:run.link,target:'_blank',rel:'noopener noreferrer'},rendered)+cutSpace;
|
|
2469
|
+
return rendered+cutSpace;
|
|
2245
2470
|
};
|
|
2246
2471
|
if(naturalFlow&&lineHasTab) {
|
|
2247
2472
|
const chunks=[];let textChunk=[];
|
|
@@ -2257,7 +2482,7 @@ function renderRichLines(value,fit,box,bound,config) {
|
|
|
2257
2482
|
if(!flow)return fragments.join('\n');
|
|
2258
2483
|
const x=alignment==='right'?box.x+box.width:alignment==='center'?box.x+box.width/2:box.x;
|
|
2259
2484
|
const first=line.fragments[0];
|
|
2260
|
-
return tag('text',{x:stableNumber(x),y:stableNumber(
|
|
2485
|
+
return tag('text',{x:stableNumber(x),y:stableNumber(baseline),'text-anchor':alignment==='right'?'end':alignment==='center'?'middle':'start','xml:space':'preserve','font-family':fontStack(first?.style.fontFamily??config.fontFamily,bound.design.fontScheme.type),'font-size':stableNumber(first?.fontSize??fit.fontSize),'font-weight':first?.style.fontWeight??config.fontWeight??400,'font-style':first?.style.italic?'italic':undefined,[NO_POLICY_FEATURES]:true},fragments.join(''));
|
|
2261
2486
|
});
|
|
2262
2487
|
let cursor=0;
|
|
2263
2488
|
const whole=value.map(run=>typeof run==='string'?run:run.text).join('');
|
|
@@ -2295,7 +2520,7 @@ function renderTextBox(text, box, bound, config) {
|
|
|
2295
2520
|
const totalHeight = fit.lines.length * fit.lineHeight;
|
|
2296
2521
|
const startY = config.verticalAlign === "middle"
|
|
2297
2522
|
? box.y + Math.max(0, (box.height - totalHeight) / 2) + size : box.y + size;
|
|
2298
|
-
const logicalAlignment=fit.placement?.alignment??config.align??bound.geometry.design.contentAlignment;
|
|
2523
|
+
const logicalAlignment=fit.placement?.alignment??config.align??itemAlignment(bound.geometry.design.contentAlignment);
|
|
2299
2524
|
const type = config.fontFamily === bound.design.fonts.code ? "monospace" : bound.design.fontScheme.type;
|
|
2300
2525
|
const source = String(text ?? ""), boxRtl = paragraphRtl(bound, source);
|
|
2301
2526
|
// LH-76: one part of a split "Topic: qualifier" title traces its source ranges in the authored title, the value at its path.
|
|
@@ -2337,10 +2562,18 @@ function renderTextBox(text, box, bound, config) {
|
|
|
2337
2562
|
const start=tabs||positioned;
|
|
2338
2563
|
// LH-32: core spaces an eyebrow's letters between characters, so its last character draws with no spacing after it: rasterizers
|
|
2339
2564
|
// differ on whether a trailing spacing counts toward a middle or end anchor.
|
|
2340
|
-
|
|
2565
|
+
// LH-189: display tracking (negative) keeps the line one run, so its last character keeps its kerning with the one before it (a tspan
|
|
2566
|
+
// split there drops the pair's kerning). The spacing after its last character does not count toward its anchor in resvg, and the
|
|
2567
|
+
// outlined text and the PDF anchor it the same way (pdf-text).
|
|
2568
|
+
if(style.tracking>0&&!start)content=untrackLast(content);
|
|
2569
|
+
// opf#1322: a browser counts that trailing spacing, so a centered or end-aligned display line drew half or one spacing to the right
|
|
2570
|
+
// there (3.8 px on a 252 px figure). Where the line was measured with the host's real faces, core's own start is exact in every
|
|
2571
|
+
// rasterizer, so the line starts there instead of hanging from its middle or end. Estimated widths keep the anchor: the shaper's
|
|
2572
|
+
// width differs from core's there, and the anchor keeps the edge.
|
|
2573
|
+
const exactStart=!start&&factor>0&&style.tracking<0&&!rtl&&!trimWidth&&!!config.options.textMeasurement?.measure&&(placed?.width>0||sourceLine?.width>0);
|
|
2341
2574
|
return tag("text", {
|
|
2342
|
-
x: stableNumber(tabs?origin:positioned?placed.x:placed?placed.x+placed.width*factor:x), y: stableNumber((placed?.baseline??startY + index * fit.lineHeight) - shift * size),
|
|
2343
|
-
"text-anchor": start?'start':anchor, "font-family": family ?? fontStack(style.fontFamily, type),
|
|
2575
|
+
x: stableNumber(tabs||exactStart?origin:positioned?placed.x:placed?placed.x+placed.width*factor:x), y: stableNumber((placed?.baseline??startY + index * fit.lineHeight) - shift * size),
|
|
2576
|
+
"text-anchor": start||exactStart?'start':anchor, "font-family": family ?? fontStack(style.fontFamily, type),
|
|
2344
2577
|
"font-size": stableNumber(adjustedFontSize(size,sizeAdjust)), "font-weight": style.fontWeight, "font-style": style.italic ? "italic" : undefined, fill: config.fill,
|
|
2345
2578
|
// LH-32: an eyebrow (the tag, a label core sets as one) draws its capitals with core's letter spacing, as core measured it, at its
|
|
2346
2579
|
// natural advance (no textLength: rasterizers differ on whether the spacing after the last letter counts toward it).
|
|
@@ -2349,6 +2582,9 @@ function renderTextBox(text, box, bound, config) {
|
|
|
2349
2582
|
textLength:!start&&placed?.width>0&&!style.tracking?stableNumber(placed.width-trimWidth):undefined,lengthAdjust:!start&&placed?.width>0&&!style.tracking?'spacingAndGlyphs':undefined,
|
|
2350
2583
|
...traceAttrs(config.options, config.path),
|
|
2351
2584
|
...(config.options.trace&&sourceLine?{'data-opf-source-start':sourceOffset+sourceLine.start,'data-opf-source-end':sourceOffset+sourceLine.end,'data-opf-source-next-start':sourceOffset+sourceLine.nextStart,'data-opf-line-boundary':sourceLine.boundary}:{}),
|
|
2585
|
+
// opf#1322: a line that starts at core's x still says how it is aligned and where its anchor point is (text-anchor no longer does):
|
|
2586
|
+
// an editor lays its input over the line from them, and a reader of the SVG compares them with the native export.
|
|
2587
|
+
...(exactStart?{'data-opf-anchor':anchor,'data-opf-anchor-x':stableNumber(placed?placed.x+placed.width*factor:x)}:{}),
|
|
2352
2588
|
}, content);
|
|
2353
2589
|
});
|
|
2354
2590
|
return tag("g", { ...traceAttrs(config.options, config.path),
|
|
@@ -2484,9 +2720,9 @@ deckInternals.openDeck = (input, options = {}) => {
|
|
|
2484
2720
|
const slideContext = resolveContext(presentation, index, { presentation, options: drawn });
|
|
2485
2721
|
return resolveDesign(presentation, slideContext.slide, slideContext);
|
|
2486
2722
|
},
|
|
2487
|
-
bind(index, textMeasurement = drawn.textMeasurement) {
|
|
2723
|
+
bind(index, textMeasurement = drawn.textMeasurement, {mapInputFamily, resolveInputStyle} = {}) {
|
|
2488
2724
|
measurements[index] = textMeasurement;
|
|
2489
|
-
resolved.slides[index] = bindSlide(presentation, index, { presentation, options: { ...drawn, textMeasurement } });
|
|
2725
|
+
resolved.slides[index] = bindSlide(presentation, index, { presentation, options: { ...drawn, textMeasurement }, mapInputFamily, resolveInputStyle });
|
|
2490
2726
|
},
|
|
2491
2727
|
render(index) { return renderResolvedSlide(resolved, index, { ...drawn, textMeasurement: measurements[index] }); },
|
|
2492
2728
|
};
|