@openpresentation/opf-render 0.33.0 → 0.34.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +28 -15
- package/dist/chart-options.js +4 -2
- package/dist/charts.js +99 -91
- package/dist/export-browser.d.ts +7 -0
- package/dist/export-browser.js +18 -6
- package/dist/font-demand.js +673 -0
- package/dist/font-files.js +43 -0
- package/dist/font-registry.js +62 -23
- package/dist/font-selection-metadata.js +21 -0
- package/dist/font-selection.js +6 -0
- package/dist/fonts-browser.d.ts +4 -3
- package/dist/fonts-browser.js +19 -8
- package/dist/fonts-node.d.ts +7 -6
- package/dist/fonts-node.js +30 -10
- package/dist/fonts.d.ts +13 -3
- package/dist/hb-shape.js +4 -4
- package/dist/index.d.ts +6 -0
- package/dist/lazy-fonts.js +209 -44
- package/dist/pdf-fonts.js +1 -1
- package/dist/pdf-text.js +10 -2
- package/dist/pdf-vector.js +2 -31
- package/dist/preview-fonts-cli.js +14 -4
- package/dist/preview-fonts-node.d.ts +18 -0
- package/dist/preview-fonts-node.js +37 -0
- package/dist/raster-markers.js +46 -0
- package/dist/raster.js +7 -4
- package/dist/script-font-pack.js +65 -4
- package/dist/script-fonts.js +6 -90
- package/dist/svg.d.ts +6 -0
- package/dist/svg.js +179 -74
- package/dist/text-paths.js +48 -16
- package/package.json +6 -6
package/dist/svg.js
CHANGED
|
@@ -2,11 +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, colorTransform, applyColorTransform, stackedText, 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, intrinsicImageAspect, intrinsicImageSize, diagramPalette, paintDiagramGroup, iconPathData,
|
|
9
|
+
codeHighlightLines, codeLineNumbers, codeHighlightBands, codeHighlightColors, fitImage, pictureOverlay, intrinsicImageAspect, intrinsicImageSize, diagramPalette, paintDiagramGroup, iconPathData,
|
|
10
10
|
ENGINE_DEFAULT_THEME, ENGINE_DEFAULT_COLOR_SCHEME, ENGINE_DEFAULT_FONT_SCHEME, ENGINE_DEFAULT_CHART_TYPES
|
|
11
11
|
} from "@openpresentation/opf/composition";
|
|
12
12
|
// The renderer is a library: it never imports a catalog. Hosts register theirs (`options.catalogs`, core `Catalog[]`, for
|
|
@@ -89,54 +89,54 @@ const ROOT_PAYLOAD_FIELDS = [
|
|
|
89
89
|
];
|
|
90
90
|
|
|
91
91
|
const PROMOTED_REGION_KEYS = [
|
|
92
|
-
"
|
|
92
|
+
"start",
|
|
93
93
|
"center",
|
|
94
|
-
"
|
|
95
|
-
"
|
|
96
|
-
"center+
|
|
97
|
-
"
|
|
94
|
+
"end",
|
|
95
|
+
"start+center",
|
|
96
|
+
"center+end",
|
|
97
|
+
"start+center+end",
|
|
98
98
|
"top",
|
|
99
99
|
"middle",
|
|
100
100
|
"bottom",
|
|
101
101
|
"top+middle",
|
|
102
102
|
"middle+bottom",
|
|
103
103
|
"top+middle+bottom",
|
|
104
|
-
"top:
|
|
104
|
+
"top:start",
|
|
105
105
|
"top:center",
|
|
106
|
-
"top:
|
|
107
|
-
"top:
|
|
108
|
-
"top:center+
|
|
109
|
-
"top:
|
|
110
|
-
"middle:
|
|
106
|
+
"top:end",
|
|
107
|
+
"top:start+center",
|
|
108
|
+
"top:center+end",
|
|
109
|
+
"top:start+center+end",
|
|
110
|
+
"middle:start",
|
|
111
111
|
"middle:center",
|
|
112
|
-
"middle:
|
|
113
|
-
"middle:
|
|
114
|
-
"middle:center+
|
|
115
|
-
"middle:
|
|
116
|
-
"bottom:
|
|
112
|
+
"middle:end",
|
|
113
|
+
"middle:start+center",
|
|
114
|
+
"middle:center+end",
|
|
115
|
+
"middle:start+center+end",
|
|
116
|
+
"bottom:start",
|
|
117
117
|
"bottom:center",
|
|
118
|
-
"bottom:
|
|
119
|
-
"bottom:
|
|
120
|
-
"bottom:center+
|
|
121
|
-
"bottom:
|
|
122
|
-
"top+middle:
|
|
118
|
+
"bottom:end",
|
|
119
|
+
"bottom:start+center",
|
|
120
|
+
"bottom:center+end",
|
|
121
|
+
"bottom:start+center+end",
|
|
122
|
+
"top+middle:start",
|
|
123
123
|
"top+middle:center",
|
|
124
|
-
"top+middle:
|
|
125
|
-
"top+middle:
|
|
126
|
-
"top+middle:center+
|
|
127
|
-
"top+middle:
|
|
128
|
-
"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",
|
|
129
129
|
"middle+bottom:center",
|
|
130
|
-
"middle+bottom:
|
|
131
|
-
"middle+bottom:
|
|
132
|
-
"middle+bottom:center+
|
|
133
|
-
"middle+bottom:
|
|
134
|
-
"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",
|
|
135
135
|
"top+middle+bottom:center",
|
|
136
|
-
"top+middle+bottom:
|
|
137
|
-
"top+middle+bottom:
|
|
138
|
-
"top+middle+bottom:center+
|
|
139
|
-
"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"
|
|
140
140
|
];
|
|
141
141
|
|
|
142
142
|
|
|
@@ -591,13 +591,15 @@ function bindSlide(presentation, index, context) {
|
|
|
591
591
|
const blocks = blockContent(slide, slidePath);
|
|
592
592
|
|
|
593
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)]));
|
|
594
596
|
// Script fonts (FF-19): each text run is measured and drawn with its script
|
|
595
597
|
// slot's face; the latin slot stays the design font scheme's family.
|
|
596
598
|
const scriptFonts = createScriptFonts(scriptProfile(presentation, index, design, context), context.options.textMeasurement, {
|
|
597
599
|
glyphFallback: context.options.glyphFallback,
|
|
598
600
|
onFallback: note => reportGlyphFallback(context, note)
|
|
599
601
|
});
|
|
600
|
-
// 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
|
|
601
603
|
// script fonts of that language (the Japanese or the Simplified Chinese face for Han text); every other run uses the deck's.
|
|
602
604
|
const languageScripts = new Map();
|
|
603
605
|
const scriptFontsFor = lang => {
|
|
@@ -621,6 +623,14 @@ function bindSlide(presentation, index, context) {
|
|
|
621
623
|
textMeasurement = { ...deckMeasurement, measure: (text, size, style) => pick(style).measure(text, size, style) };
|
|
622
624
|
if (typeof deckMeasurement.outlineBounds === "function") textMeasurement.outlineBounds = (text, size, style) => (pick(style).outlineBounds ?? deckMeasurement.outlineBounds)(text, size, style);
|
|
623
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
|
+
}
|
|
624
634
|
// fontScheme.accent (the tag and quote text) takes the same look-alike policy.
|
|
625
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
|
|
626
636
|
// resolves it again and draws the replacement's encoded weight (Montserrat 900, Red Hat Display 600 and 300); resolving the role to the
|
|
@@ -887,7 +897,10 @@ function renderImageBlock(item, bound, options) {
|
|
|
887
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 });
|
|
888
898
|
const picture = renderImage(item, image.box, bound, { ...options, imageFit: image.fit, imageFocus: image.focus, imagePicture: image.picture });
|
|
889
899
|
const trace = options.trace && image.placement ? { "data-opf-image-placement": image.placement.edge } : {};
|
|
890
|
-
|
|
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;
|
|
891
904
|
const id = `opf-s${bound.index + 1}-image-${item.path.replace(/[^A-Za-z0-9]+/g, "-")}`, shape = image.shape, defs = [];
|
|
892
905
|
// A sketched stroke (core stroke.sketched) clips the picture to its sketched outline, as PowerPoint draws it.
|
|
893
906
|
const sketched = image.stroke?.sketched?.fills[0];
|
|
@@ -904,7 +917,11 @@ function renderImageBlock(item, bound, options) {
|
|
|
904
917
|
if (stroke.defs) children[0] = (children[0] ? children[0].replace(/<\/defs>$/, "") : "<defs>") + stroke.defs + "</defs>";
|
|
905
918
|
children.push(stroke.elements);
|
|
906
919
|
}
|
|
907
|
-
|
|
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);
|
|
908
925
|
if (children.length === 2 && !children[0] && !Object.keys(trace).length) return pixels;
|
|
909
926
|
return tag("g", trace, children.filter(Boolean).join(""));
|
|
910
927
|
}
|
|
@@ -1013,11 +1030,15 @@ function renderArrangements(bound, options) {
|
|
|
1013
1030
|
const {x, y, width, height} = arrangement.background;
|
|
1014
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}));
|
|
1015
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'}));
|
|
1016
1034
|
for (const node of arrangement.nodes) {
|
|
1017
1035
|
const trace = options.trace && node.path ? {'data-opf-arrangement-path': node.path} : {};
|
|
1018
|
-
if
|
|
1019
|
-
|
|
1020
|
-
|
|
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}));
|
|
1021
1042
|
// SH-18: a cycle's arrow after its node, as PowerPoint stacks them (an arrow of two entries runs under the next circle).
|
|
1022
1043
|
for (const arrow of arrangement.arrows?.filter(entry => entry.index === node.index) ?? []) parts.push(cycleArrowPath(arrow, paint.arrow.hex));
|
|
1023
1044
|
}
|
|
@@ -1216,7 +1237,7 @@ function listEntriesSvg(item, fit, bound, options) {
|
|
|
1216
1237
|
for(const entry of fit.listEntries){
|
|
1217
1238
|
if(entry.marker.none){/* design.listBullet: none draws no marker */}
|
|
1218
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'}:{})}));}
|
|
1219
|
-
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)));
|
|
1220
1241
|
// LH-133: a glossary's term (entry.accent) draws in the tag's color on its backdrop, as the export writes it.
|
|
1221
1242
|
// SH-09: an entry of a pyramid or matrix (geometry.arrangements) is centered on its node, as the export writes it.
|
|
1222
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};
|
|
@@ -1242,6 +1263,24 @@ function numberMarkerStyle(marker) {
|
|
|
1242
1263
|
return {'font-weight':marker.style.fontWeight===400?undefined:marker.style.fontWeight,'font-style':marker.style.italic?'italic':undefined};
|
|
1243
1264
|
}
|
|
1244
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
|
+
|
|
1245
1284
|
// Follows asset: references and the host imageResolver to the drawable source of an image value.
|
|
1246
1285
|
function resolveImageSource(item, bound, options) {
|
|
1247
1286
|
let asset = normalizeAsset(item.value);
|
|
@@ -1503,8 +1542,23 @@ function renderImage(item, box, bound, options) {
|
|
|
1503
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"));
|
|
1504
1543
|
}
|
|
1505
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
|
+
|
|
1506
1560
|
function renderMedia(item, box, bound, options) {
|
|
1507
|
-
const asset =
|
|
1561
|
+
const asset = mediaAsset(item.value, bound.assets);
|
|
1508
1562
|
const iconBox = centeredBox(box, 72, 72);
|
|
1509
1563
|
const children = [
|
|
1510
1564
|
tag("rect", {
|
|
@@ -1636,7 +1690,10 @@ function renderMetric(item, box, bound, options) {
|
|
|
1636
1690
|
const factor=layout.alignment==='right'?1:layout.alignment==='center'?.5:0;
|
|
1637
1691
|
const lines=part.fit.sourceLines.map((line,index)=>{
|
|
1638
1692
|
const origin=part.linePositions[index];
|
|
1639
|
-
|
|
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',
|
|
1640
1697
|
'font-family':fontStack(part.style.fontFamily,bound.design.fontScheme.type),'font-size':stableNumber(part.fit.fontSize),
|
|
1641
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,
|
|
1642
1699
|
'xml:space':'preserve',style:'white-space:pre','text-rendering':'geometricPrecision',fill:partFill(part),
|
|
@@ -1646,6 +1703,7 @@ function renderMetric(item, box, bound, options) {
|
|
|
1646
1703
|
...(options.trace?{'data-opf-segment':segment.kind,'data-opf-text-start':segment.start,'data-opf-text-end':segment.end}:{}),
|
|
1647
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(''));
|
|
1648
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)}:{}),
|
|
1649
1707
|
'font-family':fontStack(part.style.fontFamily,bound.design.fontScheme.type),'font-size':stableNumber(part.fit.fontSize),
|
|
1650
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,
|
|
1651
1709
|
'xml:space':'preserve',style:'white-space:pre','text-rendering':'geometricPrecision',fill:partFill(part),
|
|
@@ -1711,11 +1769,13 @@ function renderTimeline(item, box, bound, options) {
|
|
|
1711
1769
|
const layout=item.timelineLayout;
|
|
1712
1770
|
if(!layout)throw new OPFRenderError('missing-timeline-layout','Timeline rendering requires a coordinated core build with shared timeline geometry.',{path:item.path});
|
|
1713
1771
|
const scale=Math.min(bound.design.dimensions.width,bound.design.dimensions.height)/720;
|
|
1772
|
+
const background=bound.design.backgroundColor??bound.design.colors.background;
|
|
1714
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}:{})}));
|
|
1715
1776
|
// LH-121: the connector up to the current event in the primary color, over the border-colored rest.
|
|
1716
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'}:{})}));
|
|
1717
1778
|
// FA-11: status colors come from the deck (core's timelineMarkerShapes / timelineTextColor); a marker with no status draws the plain primary circle.
|
|
1718
|
-
const background=bound.design.backgroundColor??bound.design.colors.background;
|
|
1719
1779
|
const statusColors={background,primary:bound.design.colors.primary,text:bound.design.colors.text,mutedText:bound.design.colors.mutedText};
|
|
1720
1780
|
for(const marker of layout.markers){
|
|
1721
1781
|
if(!marker.status){
|
|
@@ -1744,7 +1804,7 @@ function renderTimeline(item, box, bound, options) {
|
|
|
1744
1804
|
|
|
1745
1805
|
function renderTable(item, box, bound, options) {
|
|
1746
1806
|
const scale = Math.min(bound.design.dimensions.width, bound.design.dimensions.height) / 720;
|
|
1747
|
-
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} : {})});
|
|
1748
1808
|
const children = [];
|
|
1749
1809
|
// LH-113: a highlighted row (table.highlight, or the rows the slide's texts name) draws on an accent tint of the surface.
|
|
1750
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;
|
|
@@ -1815,7 +1875,8 @@ function renderTableBorders(defaultEdges, explicitEdges, scale, bound, options)
|
|
|
1815
1875
|
? [start,axis.fixed,end,axis.fixed] : [axis.fixed,start,axis.fixed,end]}));
|
|
1816
1876
|
});
|
|
1817
1877
|
return [...defaults,...explicitEdges].flatMap(({coordinates:[x1,y1,x2,y2],border,path}) => {
|
|
1818
|
-
|
|
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;
|
|
1819
1880
|
if (width === 0) return [];
|
|
1820
1881
|
const stroke = border?.color == null
|
|
1821
1882
|
? defaultColor
|
|
@@ -1868,7 +1929,7 @@ function renderDiagram(item, box, bound, options) {
|
|
|
1868
1929
|
function renderChart(item, box, bound, options) {
|
|
1869
1930
|
// Catalog chart types preview the native
|
|
1870
1931
|
// construct opf-pptx exports; other ids keep the legacy single-series preview.
|
|
1871
|
-
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) });
|
|
1872
1933
|
if (rendered) return rendered;
|
|
1873
1934
|
const chart = item.value ?? {};
|
|
1874
1935
|
const chartType = chart.type ?? engineDefaults.chartType;
|
|
@@ -2256,9 +2317,20 @@ function embeddable(font) {
|
|
|
2256
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
|
|
2257
2318
|
// megabytes.
|
|
2258
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
|
+
}
|
|
2259
2331
|
function assertEmbeddableFont(font) {
|
|
2260
2332
|
const valid = typeof font?.family === "string" && !/[\u0000-\u001f"'\\<>;]/.test(font.family) && Number.isInteger(font.weight) && font.weight >= 1 && font.weight <= 1000
|
|
2261
|
-
&& (checkedDataUrls.get(font) === font.dataUrl ||
|
|
2333
|
+
&& (checkedDataUrls.get(font) === font.dataUrl || isFontDataUrl(font.dataUrl));
|
|
2262
2334
|
if (!valid) throw new OPFRenderError("invalid-embedded-font", "Embedded fonts require a plain family name, valid weight, and a font data URI.");
|
|
2263
2335
|
checkedDataUrls.set(font, font.dataUrl);
|
|
2264
2336
|
}
|
|
@@ -2300,9 +2372,8 @@ function trimRichLineEdges(line,textMeasurement) {
|
|
|
2300
2372
|
return {...line,fragments,width:x};
|
|
2301
2373
|
}
|
|
2302
2374
|
|
|
2303
|
-
function
|
|
2304
|
-
|
|
2305
|
-
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);
|
|
2306
2377
|
// Each line takes its paragraph's direction from core (every wrapped line shares it) and its physical edge from that.
|
|
2307
2378
|
const lineAlignment=index=>fit.placement?.lines[index]?.alignment??physicalAlignment(logicalAlignment,fit.directions?.[index]);
|
|
2308
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.
|
|
@@ -2313,21 +2384,30 @@ function renderRichLines(value,fit,box,bound,config) {
|
|
|
2313
2384
|
// shape adjacent runs naturally inside each estimated line instead of turning
|
|
2314
2385
|
// those estimates into visible gaps. Supplied measurements keep exact origins.
|
|
2315
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);
|
|
2316
2401
|
const hasTabs=fit.richLines.some(line=>line.fragments.some(fragment=>fragment.kind==='tab'));
|
|
2317
2402
|
const content=fit.richLines.map((sourceLine,lineIndex)=>{
|
|
2318
2403
|
const alignment=lineAlignment(lineIndex);
|
|
2319
2404
|
const sourceFirst=sourceLine.fragments[0],rtl=fit.directions?fit.directions[lineIndex]==='rtl':richRtl(sourceFirst?runOffsets[sourceFirst.runIndex]+sourceFirst.start:0);
|
|
2320
|
-
//
|
|
2321
|
-
const edgeTrim=
|
|
2322
|
-
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);
|
|
2323
2407
|
const lineHasTab=line.fragments.some(fragment=>fragment.kind==='tab');
|
|
2324
2408
|
const flow=naturalFlow&&!lineHasTab;
|
|
2325
2409
|
const offset=alignment==='right'?box.width-line.width:alignment==='center'?(box.width-line.width)/2:0;
|
|
2326
|
-
const placed
|
|
2327
|
-
// RR-38: a line with runs in a policy replacement (Arabic Typesetting) takes PowerPoint's baseline of the real font, above core's.
|
|
2328
|
-
const lineShift=bound.scriptFonts?baselineShift(...line.fragments.filter(fragment=>fragment.kind!=='tab'&&fragment.text).map(fragment=>bound.scriptFonts.plan(fragment.text,fragment.style))):0;
|
|
2329
|
-
const shiftPx=lineShift*Math.max(fit.fontSize,...line.fragments.map(fragment=>fragment.fontSize));
|
|
2330
|
-
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;
|
|
2331
2411
|
const firstFragment=line.fragments[0];
|
|
2332
2412
|
const renderFragment=(fragment,asFlow,edges={})=>{
|
|
2333
2413
|
const run=fragment.run;
|
|
@@ -2349,7 +2429,17 @@ function renderRichLines(value,fit,box,bound,config) {
|
|
|
2349
2429
|
const measuredLine=!asFlow&&!naturalFlow&&fragment.kind!=='tab'&&fragment.width>0;
|
|
2350
2430
|
// A right-to-left fragment draws without its trailing white space, after that white space's measured advance (rtlTrailingSpace).
|
|
2351
2431
|
const trail=rtl&&measuredLine&&fragment.kind!=='marker'?rtlTrailingSpace(fragment.text):'';
|
|
2352
|
-
|
|
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
|
+
}
|
|
2353
2443
|
if(trail){
|
|
2354
2444
|
const measure=textWidthMeasurer(fragment.style,config.options.textMeasurement),full=measure(fragment.text,fragment.fontSize);
|
|
2355
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;
|
|
@@ -2359,7 +2449,7 @@ function renderRichLines(value,fit,box,bound,config) {
|
|
|
2359
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
|
|
2360
2450
|
// trailing spacing to each rasterizer's own reading.
|
|
2361
2451
|
const tracked=fragment.kind!=='tab'&&!!fragment.style.tracking;
|
|
2362
|
-
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;
|
|
2363
2453
|
// FA-13: an inline code run falls back to a monospace face, and a run with its own language declares it.
|
|
2364
2454
|
const runLang=fragment.kind!=='tab'&&fragment.style.lang?(bound.scriptFontsFor?.(fragment.style.lang)?.profile.bcp47??fragment.style.lang):undefined;
|
|
2365
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,
|
|
@@ -2370,9 +2460,13 @@ function renderRichLines(value,fit,box,bound,config) {
|
|
|
2370
2460
|
// RR-34: a citation/footnote marker is generated text (no source range): it is traced as a marker
|
|
2371
2461
|
// segment without text offsets, so editors never read it as part of the run, and it is not linked.
|
|
2372
2462
|
const marker=fragment.kind==='marker';
|
|
2373
|
-
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);
|
|
2374
|
-
|
|
2375
|
-
|
|
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;
|
|
2376
2470
|
};
|
|
2377
2471
|
if(naturalFlow&&lineHasTab) {
|
|
2378
2472
|
const chunks=[];let textChunk=[];
|
|
@@ -2388,7 +2482,7 @@ function renderRichLines(value,fit,box,bound,config) {
|
|
|
2388
2482
|
if(!flow)return fragments.join('\n');
|
|
2389
2483
|
const x=alignment==='right'?box.x+box.width:alignment==='center'?box.x+box.width/2:box.x;
|
|
2390
2484
|
const first=line.fragments[0];
|
|
2391
|
-
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(''));
|
|
2392
2486
|
});
|
|
2393
2487
|
let cursor=0;
|
|
2394
2488
|
const whole=value.map(run=>typeof run==='string'?run:run.text).join('');
|
|
@@ -2426,7 +2520,7 @@ function renderTextBox(text, box, bound, config) {
|
|
|
2426
2520
|
const totalHeight = fit.lines.length * fit.lineHeight;
|
|
2427
2521
|
const startY = config.verticalAlign === "middle"
|
|
2428
2522
|
? box.y + Math.max(0, (box.height - totalHeight) / 2) + size : box.y + size;
|
|
2429
|
-
const logicalAlignment=fit.placement?.alignment??config.align??bound.geometry.design.contentAlignment;
|
|
2523
|
+
const logicalAlignment=fit.placement?.alignment??config.align??itemAlignment(bound.geometry.design.contentAlignment);
|
|
2430
2524
|
const type = config.fontFamily === bound.design.fonts.code ? "monospace" : bound.design.fontScheme.type;
|
|
2431
2525
|
const source = String(text ?? ""), boxRtl = paragraphRtl(bound, source);
|
|
2432
2526
|
// LH-76: one part of a split "Topic: qualifier" title traces its source ranges in the authored title, the value at its path.
|
|
@@ -2468,10 +2562,18 @@ function renderTextBox(text, box, bound, config) {
|
|
|
2468
2562
|
const start=tabs||positioned;
|
|
2469
2563
|
// LH-32: core spaces an eyebrow's letters between characters, so its last character draws with no spacing after it: rasterizers
|
|
2470
2564
|
// differ on whether a trailing spacing counts toward a middle or end anchor.
|
|
2471
|
-
|
|
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);
|
|
2472
2574
|
return tag("text", {
|
|
2473
|
-
x: stableNumber(tabs?origin:positioned?placed.x:placed?placed.x+placed.width*factor:x), y: stableNumber((placed?.baseline??startY + index * fit.lineHeight) - shift * size),
|
|
2474
|
-
"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),
|
|
2475
2577
|
"font-size": stableNumber(adjustedFontSize(size,sizeAdjust)), "font-weight": style.fontWeight, "font-style": style.italic ? "italic" : undefined, fill: config.fill,
|
|
2476
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
|
|
2477
2579
|
// natural advance (no textLength: rasterizers differ on whether the spacing after the last letter counts toward it).
|
|
@@ -2480,6 +2582,9 @@ function renderTextBox(text, box, bound, config) {
|
|
|
2480
2582
|
textLength:!start&&placed?.width>0&&!style.tracking?stableNumber(placed.width-trimWidth):undefined,lengthAdjust:!start&&placed?.width>0&&!style.tracking?'spacingAndGlyphs':undefined,
|
|
2481
2583
|
...traceAttrs(config.options, config.path),
|
|
2482
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)}:{}),
|
|
2483
2588
|
}, content);
|
|
2484
2589
|
});
|
|
2485
2590
|
return tag("g", { ...traceAttrs(config.options, config.path),
|
|
@@ -2615,9 +2720,9 @@ deckInternals.openDeck = (input, options = {}) => {
|
|
|
2615
2720
|
const slideContext = resolveContext(presentation, index, { presentation, options: drawn });
|
|
2616
2721
|
return resolveDesign(presentation, slideContext.slide, slideContext);
|
|
2617
2722
|
},
|
|
2618
|
-
bind(index, textMeasurement = drawn.textMeasurement) {
|
|
2723
|
+
bind(index, textMeasurement = drawn.textMeasurement, {mapInputFamily, resolveInputStyle} = {}) {
|
|
2619
2724
|
measurements[index] = textMeasurement;
|
|
2620
|
-
resolved.slides[index] = bindSlide(presentation, index, { presentation, options: { ...drawn, textMeasurement } });
|
|
2725
|
+
resolved.slides[index] = bindSlide(presentation, index, { presentation, options: { ...drawn, textMeasurement }, mapInputFamily, resolveInputStyle });
|
|
2621
2726
|
},
|
|
2622
2727
|
render(index) { return renderResolvedSlide(resolved, index, { ...drawn, textMeasurement: measurements[index] }); },
|
|
2623
2728
|
};
|