@openpresentation/opf-render 0.34.1 → 0.35.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +23 -23
- package/dist/annotations.js +3 -3
- package/dist/chart-options.js +12 -12
- package/dist/charts.js +43 -40
- package/dist/color-fonts.js +5 -5
- package/dist/deck-runtime.js +2 -2
- package/dist/export-browser.d.ts +1 -1
- package/dist/export-browser.js +1 -1
- package/dist/font-demand.js +8 -9
- package/dist/font-manifest.js +7 -7
- package/dist/font-registry.js +4 -35
- package/dist/fonts-node.js +10 -4
- package/dist/fonts.d.ts +1 -1
- package/dist/index.d.ts +7 -7
- package/dist/pdf-fonts.js +9 -9
- package/dist/pdf-text.js +75 -19
- package/dist/pdf-vector.js +32 -17
- package/dist/raster-text.js +7 -7
- package/dist/raster.js +2 -2
- package/dist/script-font-message.js +9 -0
- package/dist/script-font-pack.js +0 -2
- package/dist/script-fonts.js +48 -18
- package/dist/svg.d.ts +4 -6
- package/dist/svg.js +36 -96
- package/dist/text-paths.js +11 -20
- package/package.json +10 -10
package/dist/charts.js
CHANGED
|
@@ -7,20 +7,20 @@
|
|
|
7
7
|
import { chartAxisFraction as axisFraction, chartAxisScale as composedScale, chartBarGeometry, chartBarSeriesOffset, chartDrawPlan, chartSlicePlan, CHART_SLICE_SEPARATOR_PX, histogramBins, paretoPlan, scottBinCount, chartWaterfallColors, waterfallLabelText, markLabelColor, chartEmphasisColors, chartSeriesLabelColor, chartContextColors, chartFocusContextColors, chartSeriesStrokes, chartHighlightColors, chartHighlightMarks, chartLayerDataLabels, chartNumber, chartValueAxisHidden, chartPaletteForFill, chartSchemeSeries, chartSeriesPalette as coreChartSeriesPalette, chartTextSize, CHART_MAX_INTERVALS, chartIntervalsFor, formatDataNumber, groupNumber, groupsAxisTicks, groupsDataRange, groupsThousands, maxIntervalsFor, niceScale, stackCategoryValues, waterfallSteps, numberFormatError, resolveChartData, resolveTextStyle, textColorForFill, textWidthMeasurer, formatNumber, formatPercentNumber, chartNumberLanguage } from "@openpresentation/opf/composition";
|
|
8
8
|
import { drawAxisTitles, drawBarLabel, drawCenteredLabel, drawPointLabel, drawSliceLabel, labelFill, labelString, outsideLabelReserve, reportOptionDiagnostics, reserveAxisTitles, resolveOptions } from "./chart-options.js";
|
|
9
9
|
|
|
10
|
-
// The series
|
|
10
|
+
// The series colors for a chart panel: core's `chartSeriesPalette` (the deck color scheme's accents, RR-89, with the chart's own
|
|
11
11
|
// `colors` entries replacing their positions) adjusted by core's `chartPaletteForFill` (contrast against the panel without letting
|
|
12
|
-
// two series merge). The PPTX export and the validator use the same pair, so the preview draws the
|
|
12
|
+
// two series merge). The PPTX export and the validator use the same pair, so the preview draws the colors they write.
|
|
13
13
|
// WI-5 (P18, D3) and LH-55: every series from the scheme reaches 4.5:1 on a dark panel, series 2 a lightness step from series 1 (an authored
|
|
14
14
|
// `colors` entry keeps the 3:1 floor).
|
|
15
15
|
// LH-105: `soften` mixes each scheme series a quarter of the way towards the backdrop (core softenChartPalette), keeping its contrast and its
|
|
16
|
-
// lightness step from its
|
|
16
|
+
// lightness step from its neighbors: ordinary data in soft colors, the full-strength color left for emphasis.
|
|
17
17
|
export function chartSeriesPalette(surface, colorScheme, colors, context, { soften = false } = {}) {
|
|
18
18
|
return chartPaletteForFill(surface, coreChartSeriesPalette(colorScheme, colors, context), { legible: chartSchemeSeries(colors, colorScheme, context), soften });
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
// FA-14: chart.highlight. Core resolves which series and categories are named (chartHighlightMarks) and the two
|
|
21
|
+
// FA-14: chart.highlight. Core resolves which series and categories are named (chartHighlightMarks) and the two colors
|
|
22
22
|
// (chartHighlightColors); a highlighted mark takes the accent, every other mark the muted neutral. A chart without a
|
|
23
|
-
// highlight has no `c.highlight`, and every
|
|
23
|
+
// highlight has no `c.highlight`, and every color below is the palette color it always was.
|
|
24
24
|
function highlightFor(c, resolved, spec, data) {
|
|
25
25
|
if (!resolved.highlight) return undefined;
|
|
26
26
|
const marks = chartHighlightMarks(resolved.highlight, { columns: data.columns, hasX: spec.kind === "scatter" && data.hasX, rows: data.rows });
|
|
@@ -28,19 +28,19 @@ function highlightFor(c, resolved, spec, data) {
|
|
|
28
28
|
return { ...marks, ...chartHighlightColors(c.surface, c.bound.design.colors.primary, c.labelColor) };
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
// LH-03, LH-95: a one-series small column or bar chart draws its
|
|
32
|
-
// the series
|
|
31
|
+
// LH-03, LH-95: a one-series small column or bar chart draws its emphasized point (core: the last one with a value) in a stronger shade of
|
|
32
|
+
// the series color and every other point in the series color (core chartEmphasisColors); it is drawn as a category highlight of that point.
|
|
33
33
|
function emphasisFor(c, layer) {
|
|
34
34
|
const row = layer?.small?.emphasis;
|
|
35
|
-
// LH-105: the
|
|
35
|
+
// LH-105: the emphasized point takes the series color at full strength (or a shade of it); the others keep the soft color.
|
|
36
36
|
const colors = row === undefined ? undefined : chartEmphasisColors(c.surface, c.colors[0], c.strongColors[0]);
|
|
37
37
|
return colors ? { series: [false], categories: c.rows.map((_, i) => i === row), ...colors } : undefined;
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
// LH-105: the series or categories the slide title names (core chart-focus.ts) take their full-strength
|
|
40
|
+
// LH-105: the series or categories the slide title names (core chart-focus.ts) take their full-strength color, the other marks the
|
|
41
41
|
// context neutrals (core chartContextColors: one gray per context series or slice, 11 L* apart, the first the strongest; 3:1 against the
|
|
42
|
-
// backdrop, or 1.6:1 when every context mark carries its text). It is drawn as a highlight whose accent is each series' own
|
|
43
|
-
// each slice's, on a pie) and whose muted
|
|
42
|
+
// backdrop, or 1.6:1 when every context mark carries its text). It is drawn as a highlight whose accent is each series' own color (and
|
|
43
|
+
// each slice's, on a pie) and whose muted color is each context series' (or slice's) own gray.
|
|
44
44
|
function focusFor(c, layer, spec) {
|
|
45
45
|
const focus = layer?.focus;
|
|
46
46
|
if (!focus) return undefined;
|
|
@@ -63,7 +63,7 @@ function focusFor(c, layer, spec) {
|
|
|
63
63
|
return { series, categories, accent: strong(0), muted: grays[0], accents: series.map((_, j) => strong(j)), mutedSeries };
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
-
// LH-81: the header row. The caption (bold, the full text
|
|
66
|
+
// LH-81: the header row. The caption (bold, the full text color) and the legend entries sit where core placed them; the band they take
|
|
67
67
|
// is carved from the top of the chart box, and a header legend replaces the side legend (c.legendManaged).
|
|
68
68
|
function drawHeader(c, spec, header) {
|
|
69
69
|
const rtl = c.bound.geometry?.direction === "rtl";
|
|
@@ -89,12 +89,12 @@ function drawHeader(c, spec, header) {
|
|
|
89
89
|
c.box = { x: outer.x, y: outer.y + header.height, width: outer.width, height: Math.max(1, outer.height - header.height) };
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
-
/** The
|
|
92
|
+
/** The color of series `j` as a whole (a line, an area, a legend key): the accent when highlighted, else muted. */
|
|
93
93
|
function seriesColor(c, j) {
|
|
94
94
|
return c.highlight ? (c.highlight.series[j] ? c.highlight.accents?.[j] ?? c.highlight.accent : c.highlight.mutedSeries?.[j] ?? c.highlight.muted) : c.colors[j % c.colors.length];
|
|
95
95
|
}
|
|
96
96
|
|
|
97
|
-
/** The
|
|
97
|
+
/** The color of the mark of series `j` at row `i`: highlighted when its series or its category is named. */
|
|
98
98
|
function markColor(c, j, i) {
|
|
99
99
|
return c.highlight ? (c.highlight.series[j] || c.highlight.categories[i] ? c.highlight.accents?.[j] ?? c.highlight.accent : c.highlight.mutedSeries?.[j] ?? c.highlight.muted) : c.colors[j % c.colors.length];
|
|
100
100
|
}
|
|
@@ -192,7 +192,10 @@ export function renderCatalogChart(item, box, bound, options, svg) {
|
|
|
192
192
|
// RR-35: a chart with axis titles, a legend position or data labels reserves their space before the plot is laid out. A chart
|
|
193
193
|
// with none of them skips this block entirely, so its output is unchanged. LH-03: a small chart's default value labels count as data labels.
|
|
194
194
|
const resolved = chartLayerDataLabels(resolveOptions(item.value, authoredSpec), layer, spec.kind);
|
|
195
|
-
|
|
195
|
+
const doughnutFit = layer?.doughnut?.labels;
|
|
196
|
+
const fitReport = doughnutFit && { code: "chart-option-adapted", option: "dataLabels.content", reason: "unsupported-content", message: `The labels of a doughnut sit inside their slices, and '${doughnutFit.from.join(', ')}' does not fit the ring, so ${doughnutFit.content ? `they show '${doughnutFit.content.join(', ')}' instead (the legend names the slices)` : 'no labels are drawn (the legend names the slices)'}.` };
|
|
197
|
+
if (fitReport && authoredSpec) resolved.diagnostics = [...resolved.diagnostics, fitReport];
|
|
198
|
+
// FA-14: a highlight changes colors only (no space is reserved), so it is resolved whether or not an option is active.
|
|
196
199
|
c.highlight = highlightFor(c, resolved, spec, data) ?? focusFor(c, layer, spec) ?? emphasisFor(c, layer);
|
|
197
200
|
// LH-03, LH-142: no value axis (a small chart's labels or a horizontal stacked bar chart's segment values carry the values): core decides it.
|
|
198
201
|
c.valueAxisHidden = chartValueAxisHidden(layer);
|
|
@@ -309,12 +312,12 @@ function chartContext(item, box, bound, options, svg, { rows, columns, formats,
|
|
|
309
312
|
const composition = bound.composition ?? bound.geometry.composition ?? {};
|
|
310
313
|
// RR-90: core's chart text size (20 px, shrunk only for a small box, never below minFontSize), the size core's value-axis density assumes.
|
|
311
314
|
const requested = chartTextSize({ width: box.width, height: box.height, scale: u, minFontSize: composition.minFontSize }), fontPx = requested * u;
|
|
312
|
-
// LH-03, LH-105: a chart has no panel, so its
|
|
315
|
+
// LH-03, LH-105: a chart has no panel, so its colors are judged against what it stands on: the card, or the slide background.
|
|
313
316
|
const surface = item.frameBox ? bound.design.roles.neutrals.card.hex : bound.design.backgroundColor ?? bound.design.colors.background;
|
|
314
|
-
// RR-96: every neutral comes from the slide's variant (core `roles.neutrals`: tx1 mixed into bg1, the
|
|
315
|
-
// scheme
|
|
317
|
+
// RR-96: every neutral comes from the slide's variant (core `roles.neutrals`: tx1 mixed into bg1, the colors the PPTX export writes as
|
|
318
|
+
// scheme colors): chart text, gridlines, axis lines and the outline between marks (bg1).
|
|
316
319
|
const neutrals = bound.design.roles.neutrals;
|
|
317
|
-
// The quiet
|
|
320
|
+
// The quiet color of axis, legend and category text; `labelColor` stays the full text color (highlight mutes toward it and labels inside
|
|
318
321
|
// marks contrast against it, as the PPTX export draws them).
|
|
319
322
|
const chartTextColor = textColorForFill(surface, neutrals.chartText.hex);
|
|
320
323
|
const labelColor = textColorForFill(surface, bound.design.colors.text);
|
|
@@ -337,7 +340,7 @@ const neutrals = bound.design.roles.neutrals;
|
|
|
337
340
|
pad: 10 * u,
|
|
338
341
|
lineHeight: fontPx * 1.5,
|
|
339
342
|
// One text line as renderTextBox lays it out (fitText line height), and the
|
|
340
|
-
// clear space kept between
|
|
343
|
+
// clear space kept between neighboring category labels.
|
|
341
344
|
textHeight: fontPx * 1.22,
|
|
342
345
|
labelGap: fontPx * 0.1,
|
|
343
346
|
colors: chartSeriesPalette(surface, bound.design.colorScheme, item.value?.colors, { accents: bound.design.roles.map.accents, roles: bound.design.colors, variables: bound.design.variables }, { soften: true }),
|
|
@@ -441,7 +444,7 @@ function dataGroup(c, format, values, options) {
|
|
|
441
444
|
|
|
442
445
|
// RR-54: a formatted horizontal axis (horizontal bars, the scatter X axis) can have end tick labels far wider than the margin the layout
|
|
443
446
|
// leaves beside the plot (a General label is a few characters, a long format code is not). Pull the plot in until the first and
|
|
444
|
-
// last labels,
|
|
447
|
+
// last labels, centered on their ticks, stay inside the chart, and lay the ticks out again for the new width. Only formatted axes call it,
|
|
445
448
|
// so a General axis keeps its placement.
|
|
446
449
|
function insetForEndLabels(c, x, width, format, scaleFor) {
|
|
447
450
|
const left = c.box.x + c.pad, right = c.box.x + c.box.width - c.pad;
|
|
@@ -527,7 +530,7 @@ function placeLegend(c, spec, position) {
|
|
|
527
530
|
c.box = { x: position === "left" ? outer.x + reserve : outer.x, y: outer.y, width: Math.max(1, outer.width - reserve), height: outer.height };
|
|
528
531
|
return;
|
|
529
532
|
}
|
|
530
|
-
// Top and bottom: entries flow left to right in rows, each row
|
|
533
|
+
// Top and bottom: entries flow left to right in rows, each row centered, wrapping when the row would pass the chart width.
|
|
531
534
|
const available = Math.max(1, outer.width - 2 * c.pad), spacing = c.fontPx * 0.8;
|
|
532
535
|
const sized = entries.map((entry) => ({ entry, width: Math.min(available, metrics.keyWidth + metrics.gap + c.width(entry.name) + spacing) }));
|
|
533
536
|
const rows = [];
|
|
@@ -718,8 +721,8 @@ function drawBottomLabels(c, plan, plot, entries, drop = 0) {
|
|
|
718
721
|
if (text) c.children.push(c.svg.tag("g", { transform: `rotate(${-plan.angle} ${c.num(px)} ${c.num(py)})` }, text));
|
|
719
722
|
continue;
|
|
720
723
|
}
|
|
721
|
-
const
|
|
722
|
-
const rect = plan.n === 1 &&
|
|
724
|
+
const centered = Math.abs(label.left - (label.cx - label.width / 2)) < 1e-6;
|
|
725
|
+
const rect = plan.n === 1 && centered && label.width <= band
|
|
723
726
|
? { x: plot.x + label.i * band, y, width: band, height: plan.reserve }
|
|
724
727
|
: { x: label.left - 1, y, width: label.width + 2, height: plan.reserve };
|
|
725
728
|
c.text(label.text, rect, path);
|
|
@@ -729,7 +732,7 @@ function drawBottomLabels(c, plan, plot, entries, drop = 0) {
|
|
|
729
732
|
|
|
730
733
|
// A vertical category axis (labels to the left of horizontal bars and funnels).
|
|
731
734
|
// Labels stay on one line inside the gutter, wrap at spaces onto two lines when
|
|
732
|
-
// their rows are tall enough, else are ellipsized; every n-th row is
|
|
735
|
+
// their rows are tall enough, else are ellipsized; every n-th row is labeled
|
|
733
736
|
// when the rows are shorter than a line of text. LH-120: a row is tall enough for
|
|
734
737
|
// two lines when it holds one line and the glyphs of a second (a line plus one
|
|
735
738
|
// text size): the label then reaches into the gap between bars, and only a label
|
|
@@ -934,7 +937,7 @@ function drawLines(c, spec, series, stacks, { plot, band, at, categorySlot = (i)
|
|
|
934
937
|
run.push([plot.x + (categorySlot(i) + 0.5) * band, at(point.to)]);
|
|
935
938
|
});
|
|
936
939
|
flush();
|
|
937
|
-
// FA-14: with a highlight each point takes its own
|
|
940
|
+
// FA-14: with a highlight each point takes its own color, and a line without markers marks the highlighted categories' points.
|
|
938
941
|
if (spec.markers || c.highlight?.categories.some(Boolean)) stacks[j].forEach((point, i) => {
|
|
939
942
|
if (!point || (!spec.markers && !c.highlight.categories[i])) return;
|
|
940
943
|
const fill = markColor(c, j, i);
|
|
@@ -946,7 +949,7 @@ function drawLines(c, spec, series, stacks, { plot, band, at, categorySlot = (i)
|
|
|
946
949
|
if (point) drawPointLabel(c, labelString(c, { category: c.rows[i][0] === null || c.rows[i][0] === undefined ? "" : String(c.rows[i][0]), value: s.values[i], format: s.format, group: s.group }), [plot.x + (categorySlot(i) + 0.5) * band, at(point.to)], `${c.path}.data.rows.${i}.${s.column}`);
|
|
947
950
|
}));
|
|
948
951
|
// LH-105: each series' last value and name at the end of its line ("61 Enterprise NPS"), in the box core placed it
|
|
949
|
-
// (chart-direct-labels.ts), in its
|
|
952
|
+
// (chart-direct-labels.ts), in its color made legible as text; bold for a series the title names.
|
|
950
953
|
for (const entry of c.endLabels?.entries ?? []) {
|
|
951
954
|
const s = series[entry.series];
|
|
952
955
|
if (!s) continue;
|
|
@@ -1176,7 +1179,7 @@ function renderComboChart(c, spec) {
|
|
|
1176
1179
|
}
|
|
1177
1180
|
|
|
1178
1181
|
// ---------------------------------------------------------------------------
|
|
1179
|
-
// Pie and doughnut: clockwise from 12 o'clock, one
|
|
1182
|
+
// Pie and doughnut: clockwise from 12 o'clock, one color per category; a doughnut of several series draws one ring per series (LH-60).
|
|
1180
1183
|
|
|
1181
1184
|
function renderCircularChart(c, spec) {
|
|
1182
1185
|
const { box, pad } = c;
|
|
@@ -1254,8 +1257,8 @@ function renderCircularChart(c, spec) {
|
|
|
1254
1257
|
if (list) drawValueList(c, list);
|
|
1255
1258
|
}
|
|
1256
1259
|
|
|
1257
|
-
// LH-92: a ring's name,
|
|
1258
|
-
// custom angle), in the
|
|
1260
|
+
// LH-92: a ring's name, centered in its band at the slice's middle and turned along the ring by core's rotation (the PPTX label's
|
|
1261
|
+
// custom angle), in the color that contrasts with the slice.
|
|
1259
1262
|
function drawRingName(c, text, { cx, cy, r, inner, mid }, path, fill, rotation = 0) {
|
|
1260
1263
|
const radius = (r + inner) / 2, x = cx + radius * Math.cos(mid), y = cy + radius * Math.sin(mid);
|
|
1261
1264
|
const width = c.width(text) + c.fontPx * 0.5, height = c.lineHeight;
|
|
@@ -1440,7 +1443,7 @@ function renderRadarChart(c, spec) {
|
|
|
1440
1443
|
// Chartex constructs (FF-22b). opf-pptx writes these as native Office 2016
|
|
1441
1444
|
// chartex parts (cx:series layoutId treemap, clusteredColumn with binning or
|
|
1442
1445
|
// aggregation, paretoLine, boxWhisker, waterfall, funnel, regionMap); the
|
|
1443
|
-
// previews below draw the same data with the same
|
|
1446
|
+
// previews below draw the same data with the same colors and defaults.
|
|
1444
1447
|
|
|
1445
1448
|
/**
|
|
1446
1449
|
* The plotted column of a chartex chart: [Category, Value, ...] plots the first
|
|
@@ -1530,7 +1533,7 @@ function renderHistogramChart(c, spec) {
|
|
|
1530
1533
|
drawBarLabel(c, labelString(c, { category: bar.name, value: bar.value, format, group: labelGroup }), { x: plot.x + i * band + offset, y: Math.min(y, crossing), width, height: Math.abs(crossing - y) }, bar.value >= 0 ? "up" : "down", bar.path, c.colors[0]);
|
|
1531
1534
|
});
|
|
1532
1535
|
if (pareto && bars.length) {
|
|
1533
|
-
// Percentage axis on the right, 0-100%, and the cumulative line through the bar
|
|
1536
|
+
// Percentage axis on the right, 0-100%, and the cumulative line through the bar centers.
|
|
1534
1537
|
// RR-105: the percentage step core composed (layer.histogram.percentUnit), which the PPTX export writes on the secondary axis.
|
|
1535
1538
|
const percent = (c.histogram?.percentUnit > 0 ? composedScale({ min: 0, max: 1, majorUnit: c.histogram.percentUnit }) : undefined) ?? niceScale(0, 1, chartIntervalsFor(plot.height, c.lineHeight * 1.2, c.u), { percent: true });
|
|
1536
1539
|
const right = plot.x + plot.width;
|
|
@@ -1547,9 +1550,9 @@ function renderHistogramChart(c, spec) {
|
|
|
1547
1550
|
}
|
|
1548
1551
|
}
|
|
1549
1552
|
|
|
1550
|
-
// Waterfall: floating bars from the running total, increases and decreases in the first two palette
|
|
1553
|
+
// Waterfall: floating bars from the running total, increases and decreases in the first two palette colors, connector lines between bars.
|
|
1551
1554
|
// LH-59: a last value equal to the running sum of the steps before it is a total (core's waterfallSteps): it stands on zero in the third
|
|
1552
|
-
// palette
|
|
1555
|
+
// palette color, as PowerPoint draws the cx:subtotals point the export writes.
|
|
1553
1556
|
// LH-107: core's roles (layer.waterfall): totals in the strong color, gains in the accent, losses in the context gray (core
|
|
1554
1557
|
// chartWaterfallColors), signed default labels (a total's bold and unsigned), dashed connectors and, with default labels, no value axis.
|
|
1555
1558
|
const waterfallColor = (bar, palette) => palette[(bar.total ? 2 : bar.value < 0 ? 1 : 0) % palette.length];
|
|
@@ -1591,7 +1594,7 @@ function renderWaterfallChart(c) {
|
|
|
1591
1594
|
});
|
|
1592
1595
|
}
|
|
1593
1596
|
|
|
1594
|
-
// Funnel:
|
|
1597
|
+
// Funnel: centered bars from the top, widths proportional to the value, value labels inside and category labels on the left.
|
|
1595
1598
|
function renderFunnelChart(c) {
|
|
1596
1599
|
const { box, pad, fontPx } = c;
|
|
1597
1600
|
const { column, values, categories } = chartexValues(c.rows, c.columns);
|
|
@@ -1665,7 +1668,7 @@ export function squarify(items, x, y, width, height) {
|
|
|
1665
1668
|
return rects;
|
|
1666
1669
|
}
|
|
1667
1670
|
|
|
1668
|
-
// Treemap: one tile per category from the first value column (positive values only), one palette
|
|
1671
|
+
// Treemap: one tile per category from the first value column (positive values only), one palette color per tile, category labels inside.
|
|
1669
1672
|
function renderTreemapChart(c) {
|
|
1670
1673
|
const { box, pad, fontPx } = c;
|
|
1671
1674
|
const { column, values, categories } = chartexValues(c.rows, c.columns);
|
|
@@ -1762,14 +1765,14 @@ function renderBoxWhiskerChart(c) {
|
|
|
1762
1765
|
});
|
|
1763
1766
|
}
|
|
1764
1767
|
|
|
1765
|
-
// LH-56: a label inside a mark (a treemap tile, a funnel bar, a map tile) takes core's markLabelColor for that fill: the full text
|
|
1768
|
+
// LH-56: a label inside a mark (a treemap tile, a funnel bar, a map tile) takes core's markLabelColor for that fill: the full text color
|
|
1766
1769
|
// when it reaches 4.5:1 on the fill, else the slide background, else black or white, as the PPTX export writes the same labels.
|
|
1767
1770
|
function insideText(c, value, rect, path, fill, align = "center") {
|
|
1768
1771
|
const element = c.textElement(value, rect, path, align, markLabelColor(fill, c.labelColor, c.bound.design.colors.background));
|
|
1769
1772
|
if (element) c.children.push(element);
|
|
1770
1773
|
}
|
|
1771
1774
|
|
|
1772
|
-
/** Mix two hex
|
|
1775
|
+
/** Mix two hex colors (#RRGGBB) by `t` in [0, 1], rounded per channel. */
|
|
1773
1776
|
export function mixHex(from, to, t) {
|
|
1774
1777
|
const channel = (hex, i) => parseInt(hex.slice(1 + 2 * i, 3 + 2 * i), 16);
|
|
1775
1778
|
const clamp = Math.min(1, Math.max(0, t));
|
|
@@ -1778,8 +1781,8 @@ export function mixHex(from, to, t) {
|
|
|
1778
1781
|
|
|
1779
1782
|
// Region map: an honest non-geographic preview. PowerPoint draws the map from
|
|
1780
1783
|
// Bing geodata it fetches itself; the preview shows one tile per region, shaded
|
|
1781
|
-
// from a light tint to the series
|
|
1782
|
-
// its value, so labels and
|
|
1784
|
+
// from a light tint to the series color by value, with the region name and
|
|
1785
|
+
// its value, so labels and colors are traceable without shipping geography.
|
|
1783
1786
|
function renderRegionMapChart(c) {
|
|
1784
1787
|
const { box, pad, fontPx } = c;
|
|
1785
1788
|
const { column, values, categories } = chartexValues(c.rows, c.columns);
|
package/dist/color-fonts.js
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
//
|
|
2
|
-
// draw them in
|
|
1
|
+
// Color fonts (FF-45). Noto Color Emoji ships COLRv1 and OT-SVG color glyphs with empty outlines in `glyf`. Browsers
|
|
2
|
+
// draw them in color (Chromium and Firefox from COLRv1, Safari from the SVG table), and fontkit shapes and measures the
|
|
3
3
|
// face, so the SVG names it. resvg (the raster path) draws neither COLRv1 nor OT-SVG glyphs and would paint nothing, so
|
|
4
4
|
// the raster path draws the package's monochrome stand-in (Noto Emoji) instead: measured advances are pinned by
|
|
5
5
|
// textLength where runs are positioned, and the raster shows a black-and-white silhouette, which is a documented limit.
|
|
6
6
|
import { BUNDLED_FONT_MANIFEST } from "./font-manifest.js";
|
|
7
7
|
|
|
8
|
-
/** Every
|
|
8
|
+
/** Every color face of the manifest: its family, package-relative file, color format and the monochrome family the raster path draws. */
|
|
9
9
|
export const COLOR_FONT_FACES = Object.freeze(BUNDLED_FONT_MANIFEST.packages.filter(pkg => pkg.color).flatMap(pkg => pkg.faces.map(face => Object.freeze({
|
|
10
10
|
family: face.family, file: face.file, package: pkg.name, format: pkg.color.format, rasterFamily: pkg.color.rasterFamily,
|
|
11
11
|
}))));
|
|
12
12
|
const rasterFamilyOf = new Map(COLOR_FONT_FACES.map(face => [face.family.toLowerCase(), face.rasterFamily]));
|
|
13
13
|
const colorFiles = COLOR_FONT_FACES.map(face => face.file.replace(/\\/g, "/"));
|
|
14
14
|
|
|
15
|
-
/** `files` without the
|
|
15
|
+
/** `files` without the color faces, which resvg cannot draw (they would also catch its glyph fallback and paint nothing). */
|
|
16
16
|
export function rasterFontFiles(files) {
|
|
17
17
|
return files.filter(file => { const normalized = String(file).replace(/\\/g, "/"); return !colorFiles.some(suffix => normalized.endsWith(`/${suffix}`)); });
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
const fontFamilyAttribute = /(\sfont-family\s*=\s*)(?:"([^"]*)"|'([^']*)')/g;
|
|
21
21
|
const unquote = name => name.trim().replace(/^(["'])(.*)\1$/, "$2");
|
|
22
|
-
/** SVG about to be rasterized only (never the emitted SVG): text in a
|
|
22
|
+
/** SVG about to be rasterized only (never the emitted SVG): text in a color family is drawn with its monochrome stand-in. */
|
|
23
23
|
export function monochromeColorFonts(svg) {
|
|
24
24
|
if (!rasterFamilyOf.size || !/<(?:text|tspan)[\s>]/.test(svg)) return svg;
|
|
25
25
|
return svg.replace(fontFamilyAttribute, (match, prefix, doubleQuoted, singleQuoted) => {
|
package/dist/deck-runtime.js
CHANGED
|
@@ -165,7 +165,7 @@ export function svgDimensions(svg) {
|
|
|
165
165
|
|
|
166
166
|
/**
|
|
167
167
|
* The renderer's SVG made responsive and readable: the fixed `width` and `height` go (the viewBox scales it), and the root's
|
|
168
|
-
*
|
|
168
|
+
* labeled-container attributes (`role="group"`, `aria-roledescription="slide"`, `aria-label`) go too, because the slide section or figure around it
|
|
169
169
|
* carries the one accessible name, so a slide is announced once. The slide's own text nodes reach a screen reader in document order,
|
|
170
170
|
* which is the reading order (tag, title, content, footnotes, then header and footer) the renderer paints; purely decorative drawing
|
|
171
171
|
* keeps its `aria-hidden`.
|
|
@@ -187,7 +187,7 @@ export function prepareSlideSvg(svg, { idPrefix } = {}) {
|
|
|
187
187
|
const UNSAFE_ELEMENTS = new Set(["script", "foreignobject", "iframe", "object", "embed", "animate", "set", "animatetransform", "animatemotion"]);
|
|
188
188
|
|
|
189
189
|
/**
|
|
190
|
-
*
|
|
190
|
+
* Defense in depth for a parsed slide: the renderer escapes everything it writes, but a player may be pointed at a deck
|
|
191
191
|
* nobody reviewed, so scripts, event handlers, foreign content and SMIL animation never reach the page.
|
|
192
192
|
*/
|
|
193
193
|
export function sanitizeSvgTree(root) {
|
package/dist/export-browser.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ export type { PdfDiagnostic, PdfMetadata } from "./index.js";
|
|
|
6
6
|
export interface BrowserToPngOptions extends ToSvgOptions {
|
|
7
7
|
/** Multiplies the SVG's own size (default 1). The result is limited to 40 megapixels. */
|
|
8
8
|
scale?: number;
|
|
9
|
-
/** A CSS
|
|
9
|
+
/** A CSS color painted first (default white); `"transparent"` keeps the alpha channel. */
|
|
10
10
|
background?: string;
|
|
11
11
|
/**
|
|
12
12
|
* How the SVG is handed to the browser's image decoder: a `blob:` URL (default) or a `data:` URL, for a page whose Content-Security-Policy
|
package/dist/export-browser.js
CHANGED
|
@@ -19,7 +19,7 @@ const MAX_PIXELS = 40_000_000;
|
|
|
19
19
|
/**
|
|
20
20
|
* PNG with a canvas (RR-73): a deck drawn with `toSvg` (all slides, a slide number or a selection, as for the Node `toPng`) or SVG
|
|
21
21
|
* the renderer drew; one PNG for a slide number or one SVG, a list otherwise. `scale` multiplies the SVG's own size; `background`
|
|
22
|
-
* is a CSS
|
|
22
|
+
* is a CSS color (default white, `"transparent"` for none).
|
|
23
23
|
*/
|
|
24
24
|
export async function toPng(source, slides, options) {
|
|
25
25
|
({ slides, options } = slideArguments(slides, options));
|
package/dist/font-demand.js
CHANGED
|
@@ -4,6 +4,7 @@ import { FONT_SELECTION_METADATA } from './font-selection-metadata.js';
|
|
|
4
4
|
import { createFontRegistry, pickFace, OPFFontError } from './font-registry.js';
|
|
5
5
|
import { createFontAnalysis } from './lazy-fonts.js';
|
|
6
6
|
import { scriptFontAliases } from './script-fonts.js';
|
|
7
|
+
import { scriptFontNotInstalledMessage } from './script-font-message.js';
|
|
7
8
|
import {
|
|
8
9
|
analyzePresentationScripts,
|
|
9
10
|
createScriptAnalysis,
|
|
@@ -351,7 +352,7 @@ export async function createNodeDemand(
|
|
|
351
352
|
return {request, selected};
|
|
352
353
|
});
|
|
353
354
|
const wanted = new Set([...drawn, ...measured.map(({selected}) => selected)].map(key)), rasterRequired = new Set();
|
|
354
|
-
// A selected manifest
|
|
355
|
+
// A selected manifest color face also needs its effective monochrome raster face.
|
|
355
356
|
// This is a dependency of the drawn face, not another script/pack or a caller-face substitution.
|
|
356
357
|
for (const face of universe) {
|
|
357
358
|
if (!wanted.has(key(face)) || callerFaceKeys.has(key(face)) || !face.pkg.color?.rasterFamily) continue;
|
|
@@ -463,7 +464,7 @@ export async function createNodeDemand(
|
|
|
463
464
|
optional = selected.filter((pkg) => !required(pkg));
|
|
464
465
|
const batches = await Promise.all([
|
|
465
466
|
loadPackages(mandatory, undefined, {
|
|
466
|
-
what: '
|
|
467
|
+
what: 'This presentation',
|
|
467
468
|
}),
|
|
468
469
|
loadPackages(optional, missing),
|
|
469
470
|
]);
|
|
@@ -510,13 +511,11 @@ export async function createNodeDemand(
|
|
|
510
511
|
notify(
|
|
511
512
|
'script-font-not-installed',
|
|
512
513
|
{ package: item.package, version: item.version, scripts: item.scripts },
|
|
513
|
-
|
|
514
|
-
item.package +
|
|
515
|
-
|
|
516
|
-
item.version
|
|
517
|
-
|
|
518
|
-
item.scripts.join(', ') +
|
|
519
|
-
' text with its designated open font.',
|
|
514
|
+
scriptFontNotInstalledMessage(
|
|
515
|
+
'Install ' + item.package + '@' + item.version + ' to preview ' + item.scripts.join(', ') + ' text with its designated open font.',
|
|
516
|
+
item.package,
|
|
517
|
+
item.version,
|
|
518
|
+
),
|
|
520
519
|
onDiagnostic,
|
|
521
520
|
);
|
|
522
521
|
}
|
package/dist/font-manifest.js
CHANGED
|
@@ -2434,15 +2434,15 @@ export const BUNDLED_FONT_MANIFEST=freeze({
|
|
|
2434
2434
|
},
|
|
2435
2435
|
{
|
|
2436
2436
|
"name": "@expo-google-fonts/noto-sans-mongolian",
|
|
2437
|
-
"version": "0.4.
|
|
2437
|
+
"version": "0.4.2",
|
|
2438
2438
|
"pack": "scripts",
|
|
2439
2439
|
"scripts": [
|
|
2440
2440
|
"Mong"
|
|
2441
2441
|
],
|
|
2442
|
-
"source": "https://www.npmjs.com/package/@expo-google-fonts/noto-sans-mongolian/v/0.4.
|
|
2442
|
+
"source": "https://www.npmjs.com/package/@expo-google-fonts/noto-sans-mongolian/v/0.4.2",
|
|
2443
2443
|
"license": "OFL-1.1",
|
|
2444
2444
|
"licenseFile": "LICENSE_FONT",
|
|
2445
|
-
"licenseSha256": "
|
|
2445
|
+
"licenseSha256": "dbaad9386f1579930e60139d1cf36913da6c45f032433798bb8bf2e5912c8467",
|
|
2446
2446
|
"reservedFontNames": [],
|
|
2447
2447
|
"upstream": "https://github.com/notofonts/mongolian",
|
|
2448
2448
|
"copyright": "Copyright 2022 The Noto Project Authors (https://github.com/notofonts/mongolian)",
|
|
@@ -2452,7 +2452,7 @@ export const BUNDLED_FONT_MANIFEST=freeze({
|
|
|
2452
2452
|
"family": "Noto Sans Mongolian",
|
|
2453
2453
|
"weight": 400,
|
|
2454
2454
|
"italic": false,
|
|
2455
|
-
"sha256": "
|
|
2455
|
+
"sha256": "009317e64d43aae7daa08657d1dd0259c5f603faba1ee8f4b4d729b8c462864d"
|
|
2456
2456
|
}
|
|
2457
2457
|
]
|
|
2458
2458
|
},
|
|
@@ -2551,7 +2551,7 @@ export const BUNDLED_FONT_MANIFEST=freeze({
|
|
|
2551
2551
|
},
|
|
2552
2552
|
{
|
|
2553
2553
|
"name": "@expo-google-fonts/noto-color-emoji",
|
|
2554
|
-
"version": "0.4.
|
|
2554
|
+
"version": "0.4.8",
|
|
2555
2555
|
"pack": "scripts",
|
|
2556
2556
|
"scripts": [
|
|
2557
2557
|
"Zsye"
|
|
@@ -2560,7 +2560,7 @@ export const BUNDLED_FONT_MANIFEST=freeze({
|
|
|
2560
2560
|
"format": "COLRv1, SVG",
|
|
2561
2561
|
"rasterFamily": "Noto Emoji"
|
|
2562
2562
|
},
|
|
2563
|
-
"source": "https://www.npmjs.com/package/@expo-google-fonts/noto-color-emoji/v/0.4.
|
|
2563
|
+
"source": "https://www.npmjs.com/package/@expo-google-fonts/noto-color-emoji/v/0.4.8",
|
|
2564
2564
|
"license": "OFL-1.1",
|
|
2565
2565
|
"licenseFile": "LICENSE_FONT",
|
|
2566
2566
|
"licenseSha256": "ac564676d10054a8445923dfc2dfb13c042d97888bd27c1b6ec6dfe89a9d8d62",
|
|
@@ -2573,7 +2573,7 @@ export const BUNDLED_FONT_MANIFEST=freeze({
|
|
|
2573
2573
|
"family": "Noto Color Emoji",
|
|
2574
2574
|
"weight": 400,
|
|
2575
2575
|
"italic": false,
|
|
2576
|
-
"sha256": "
|
|
2576
|
+
"sha256": "d8c8a5e2eaecf93bf46be895640139d344ace174e2cdb6b0d988f7e83fd97844"
|
|
2577
2577
|
}
|
|
2578
2578
|
]
|
|
2579
2579
|
},
|
package/dist/font-registry.js
CHANGED
|
@@ -53,27 +53,6 @@ function unavailableFontError(family, style, policy) {
|
|
|
53
53
|
return new OPFFontError("font-unavailable", `No local font face for '${family}'. ${owner} None of its replacements (${candidates.join(", ")}) is loaded${packs.length ? `; load the ${packs.map(pack=>"'"+pack+"'").join(" or ")} font pack` : ""}, or ${hook}. The PPTX names '${family}' either way.`, details);
|
|
54
54
|
}
|
|
55
55
|
/** Local font files only. The caller explicitly chooses aliases and fallback. */
|
|
56
|
-
// fontkit 2.0.4 cannot decode every OpenType lookup: its GSUB type 8 (reverse chaining contextual single substitution) struct lacks the
|
|
57
|
-
// backtrackGlyphCount field, so the lookup fails with "Not a fixed size" when a feature that references it is applied, and it has no processor
|
|
58
|
-
// for the type anyway. Noto Sans Mongolian 3.x has such a lookup under calt and rclt in every script, so every shaping of the face threw (FF-44).
|
|
59
|
-
// A lookup that cannot be decoded is treated as one that applies nothing (no subtables), so the rest of the feature still runs: advances equal
|
|
60
|
-
// a browser's for the face's Latin and Mongolian samples (test/mongolian-shaping.mjs). Applied only after shaping failed, once per font.
|
|
61
|
-
const lookupsGuarded = new WeakSet();
|
|
62
|
-
export function skipUndecodableLookups(font) {
|
|
63
|
-
if (lookupsGuarded.has(font)) return false;
|
|
64
|
-
lookupsGuarded.add(font);
|
|
65
|
-
let guarded = false;
|
|
66
|
-
for (const tag of ["GSUB", "GPOS"]) {
|
|
67
|
-
let list;
|
|
68
|
-
try { list = font[tag]?.lookupList; } catch { continue; }
|
|
69
|
-
if (typeof list?.get !== "function") continue;
|
|
70
|
-
const get = list.get.bind(list);
|
|
71
|
-
list.get = index => { try { return get(index); } catch { return { lookupType: 1, flags: {}, subTables: [] }; } };
|
|
72
|
-
guarded = true;
|
|
73
|
-
}
|
|
74
|
-
return guarded;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
56
|
// opf-render#125: fontkit 2.0.4 caches one Glyph per glyph id (font._glyphs) with the code points of the call that created it, and
|
|
78
57
|
// its layout reads the input's code points back from that cache (glyphsForString -> getGlyph(id, [codePoint]) -> GlyphInfo). A glyph
|
|
79
58
|
// first reached another way keeps other code points: a composite outline (run.bbox for outlineBounds, glyph.path) reaches its
|
|
@@ -336,7 +315,7 @@ export function createFontRegistry(entries, options = {}, {allowEmpty = false, c
|
|
|
336
315
|
let pen = 0, bounds = null;
|
|
337
316
|
for (const glyph of glyphs) {
|
|
338
317
|
if (includeOutline) {
|
|
339
|
-
//
|
|
318
|
+
// Color/bitmap glyphs may have no fontkit outline (the em-box fallback below still applies).
|
|
340
319
|
let box;
|
|
341
320
|
try { box = face.font.getGlyph(glyph.gid).bbox; } catch { box = null; }
|
|
342
321
|
if (box && [box.minX, box.minY, box.maxX, box.maxY].every(Number.isFinite) && box.width > 0 && box.height > 0) {
|
|
@@ -351,23 +330,13 @@ export function createFontRegistry(entries, options = {}, {allowEmpty = false, c
|
|
|
351
330
|
throw new OPFFontError("font-shaping-failed", `Font '${face.family}' cannot shape this text with HarfBuzz.`, {path:style.path,fontFamily:face.family,cause:error?.message});
|
|
352
331
|
}
|
|
353
332
|
} else try { run=shape(); }
|
|
354
|
-
catch (error) {
|
|
355
|
-
// A lookup fontkit cannot decode (GSUB type 8 in Noto Sans Mongolian) applies nothing; shape again with the rest (FF-44).
|
|
356
|
-
if (skipUndecodableLookups(face.font)) { try { run=shape(); } catch { /* the mark retry below */ } }
|
|
357
|
-
// fontkit rejects some mark-attachment lookups (null anchors, for example
|
|
358
|
-
// Gurmukhi tippi in Noto Sans Gurmukhi). Mark positioning moves marks
|
|
359
|
-
// without changing advances, so measure again without it (FF-19).
|
|
360
|
-
if (!run) {
|
|
361
|
-
try { run=shape({abvm:false,blwm:false,mark:false,mkmk:false}); }
|
|
362
|
-
catch { throw new OPFFontError("font-shaping-failed", `Font '${face.family}' cannot shape this text.`, {path:style.path,fontFamily:face.family,cause:error?.message}); }
|
|
363
|
-
}
|
|
364
|
-
}
|
|
333
|
+
catch (error) { throw new OPFFontError("font-shaping-failed", `Font '${face.family}' cannot shape this text.`, {path:style.path,fontFamily:face.family,cause:error?.message}); }
|
|
365
334
|
value={width:run.positions.reduce((total,position)=>total+position.xAdvance,0)/face.font.unitsPerEm,...value};
|
|
366
335
|
if(includeOutline) {
|
|
367
336
|
const unit=face.font.unitsPerEm;
|
|
368
337
|
let bounds=null;
|
|
369
|
-
// FF-45: fontkit reads COLR v0 layers only; a COLRv1
|
|
370
|
-
// glyf outlines are empty), so its ink box is the face's em box over the run: the
|
|
338
|
+
// FF-45: fontkit reads COLR v0 layers only; a COLRv1 color face (Noto Color Emoji) has no outlines it can bound (its
|
|
339
|
+
// glyf outlines are empty), so its ink box is the face's em box over the run: the color image fills the em square.
|
|
371
340
|
try { bounds=run.bbox; } catch { bounds=null; }
|
|
372
341
|
if(bounds&&[bounds.minX,bounds.minY,bounds.maxX,bounds.maxY].every(Number.isFinite)) value.outline={x:bounds.minX/unit,y:-bounds.maxY/unit,width:bounds.width/unit,height:bounds.height/unit};
|
|
373
342
|
else if(face.font.directory?.tables?.COLR&&value.width>0) { const ascent=face.font.ascent/unit,descent=face.font.descent/unit; value.outline={x:0,y:-ascent,width:value.width,height:ascent-descent}; }
|
package/dist/fonts-node.js
CHANGED
|
@@ -9,6 +9,7 @@ import { textOutlines } from "./text-paths.js";
|
|
|
9
9
|
import { createSubsetter, fontSubsets } from "./font-subset.js";
|
|
10
10
|
import { createShaper } from "./hb-shape.js";
|
|
11
11
|
import { packageRoot, resolveInstalled } from "./node-resolve.js";
|
|
12
|
+
import { scriptFontNotInstalledMessage } from "./script-font-message.js";
|
|
12
13
|
export { BUNDLED_FONT_MANIFEST } from "./font-manifest.js";
|
|
13
14
|
import { analyzePresentationScripts, autoScriptSelection, createScriptAnalysis, nextFallbackPackage, scriptFontPackages, scriptSelectionOf, uncoveredCjkCharacters } from "./script-font-pack.js";
|
|
14
15
|
export { autoScriptSelection, detectPresentationScripts, scriptFontPackages } from "./script-font-pack.js";
|
|
@@ -36,7 +37,12 @@ function requireInstalled(packages, what) {
|
|
|
36
37
|
});
|
|
37
38
|
if (!missing.length) return;
|
|
38
39
|
const install = `npm install ${missing.map(pkg => `${pkg.name}@${pkg.version}`).join(" ")}`;
|
|
39
|
-
|
|
40
|
+
// The families each package serves here (for a presentation: only the faces it selects), so the message says what needs it.
|
|
41
|
+
const familiesOf = pkg => [...new Set((pkg.faces ?? []).map(face => face.family).filter(Boolean))];
|
|
42
|
+
const faces = [...new Set(missing.flatMap(familiesOf))];
|
|
43
|
+
const named = missing.map(pkg => { const families = familiesOf(pkg); return families.length ? `${pkg.name} (${families.join(", ")})` : pkg.name; }).join(", ");
|
|
44
|
+
const one = missing.length === 1;
|
|
45
|
+
throw new OPFFontError("font-resource-unavailable", `${what} needs ${one ? "a font package that is" : "font packages that are"} not installed (${one ? "an optional peer dependency" : "optional peer dependencies"} of @openpresentation/opf-render): ${named}. Run \`${install}\`.`, {packages: missing.map(pkg => pkg.name), faces, install});
|
|
40
46
|
}
|
|
41
47
|
|
|
42
48
|
// `skipped`: an optional npm package that is not installed is recorded there instead of failing (scripts: 'auto').
|
|
@@ -109,7 +115,7 @@ async function withScripts(loaded, scripts, {presentation, onDiagnostic, renderO
|
|
|
109
115
|
const selection = scriptSelectionOf(analyzePresentationScripts(presentation, undefined, renderOptions)), skipped = [];
|
|
110
116
|
const extra = await loadPackages(notLoaded(scriptFontPackages(selection.scripts)), skipped);
|
|
111
117
|
for (const script of selection.unavailable) onDiagnostic?.({code: "script-font-unavailable", script, message: `No pinned open font serves script '${script}'; that text uses the design font.`});
|
|
112
|
-
for (const item of skipped) onDiagnostic?.({code: "script-font-not-installed", package: item.package, version: item.version, scripts: item.scripts, message: `Install ${item.package}@${item.version} to preview ${item.scripts.join(", ")} text with its designated open font
|
|
118
|
+
for (const item of skipped) onDiagnostic?.({code: "script-font-not-installed", package: item.package, version: item.version, scripts: item.scripts, message: scriptFontNotInstalledMessage(`Install ${item.package}@${item.version} to preview ${item.scripts.join(", ")} text with its designated open font.`, item.package, item.version)});
|
|
113
119
|
return {entries:[...loaded.entries, ...embedUsed(extra.entries)], fontFiles:[...loaded.fontFiles, ...extra.fontFiles], packages:[...(loaded.packages ?? []), ...extra.packages],
|
|
114
120
|
selection:{...selection, packages: scriptFontPackages(selection.scripts).map(item => item.name).filter(name => !skipped.some(item => item.package === name)), notInstalled: skipped.map(item => item.package)}};
|
|
115
121
|
}
|
|
@@ -135,7 +141,7 @@ async function completeFallback(registry, presentation, loaded, onDiagnostic, re
|
|
|
135
141
|
const skipped = [], extra = await loadPackages([next], skipped);
|
|
136
142
|
if (skipped.length) {
|
|
137
143
|
selection.notInstalled.push(next.name);
|
|
138
|
-
onDiagnostic?.({code: "script-font-not-installed", package: next.name, version: next.version, scripts: [...next.scripts], message: `Install ${next.name}@${next.version} for glyphs the loaded CJK faces lack
|
|
144
|
+
onDiagnostic?.({code: "script-font-not-installed", package: next.name, version: next.version, scripts: [...next.scripts], message: scriptFontNotInstalledMessage(`Install ${next.name}@${next.version} for glyphs the loaded CJK faces lack.`, next.name, next.version)});
|
|
139
145
|
continue;
|
|
140
146
|
}
|
|
141
147
|
registry.addFaces(embedUsed(extra.entries));
|
|
@@ -238,7 +244,7 @@ async function ensureFonts(registry, loaded, presentation, {onDiagnostic, render
|
|
|
238
244
|
selection.packages.push(...extra.packages);
|
|
239
245
|
for (const item of skipped) {
|
|
240
246
|
selection.notInstalled.push(item.package);
|
|
241
|
-
onDiagnostic?.({code: "script-font-not-installed", package: item.package, version: item.version, scripts: item.scripts, message: `Install ${item.package}@${item.version} to preview ${item.scripts.join(", ")} text with its designated open font
|
|
247
|
+
onDiagnostic?.({code: "script-font-not-installed", package: item.package, version: item.version, scripts: item.scripts, message: scriptFontNotInstalledMessage(`Install ${item.package}@${item.version} to preview ${item.scripts.join(", ")} text with its designated open font.`, item.package, item.version)});
|
|
242
248
|
}
|
|
243
249
|
for (const script of wanted.unavailable) if (!selection.unavailable.includes(script)) {
|
|
244
250
|
selection.unavailable.push(script);
|
package/dist/fonts.d.ts
CHANGED
|
@@ -179,5 +179,5 @@ export declare const EMOJI_FONT_FAMILIES: readonly string[];
|
|
|
179
179
|
export declare function hasEmojiPresentation(text: string): boolean;
|
|
180
180
|
/** True when the text holds mathematical notation that text faces lack (math alphanumerics, letterlike math sets, rarer operator blocks). */
|
|
181
181
|
export declare function hasMathNotation(text: string): boolean;
|
|
182
|
-
/**
|
|
182
|
+
/** Color faces of the manifest: resvg draws their monochrome stand-in (`rasterFamily`); browsers draw them in color. */
|
|
183
183
|
export declare const COLOR_FONT_FACES: readonly { family: string; file: string; package: string; format: string; rasterFamily: string }[];
|
package/dist/index.d.ts
CHANGED
|
@@ -30,7 +30,7 @@ export declare const engineDefaults: Readonly<{
|
|
|
30
30
|
export type RenderDiagnostic = LayoutDiagnostic | {
|
|
31
31
|
/** A generated RTL numbered marker stayed text; this PNG/raster-PDF marker is not direction-qualified. */
|
|
32
32
|
code: "raster-marker-unavailable";
|
|
33
|
-
reason: "unresolved" | "restricted" | "
|
|
33
|
+
reason: "unresolved" | "restricted" | "color-font" | "system-fonts";
|
|
34
34
|
fontFamily?: string;
|
|
35
35
|
message: string;
|
|
36
36
|
} | {
|
|
@@ -41,7 +41,7 @@ export type RenderDiagnostic = LayoutDiagnostic | {
|
|
|
41
41
|
} | {
|
|
42
42
|
/** A run stays text because its face cannot safely be written as outlines. */
|
|
43
43
|
code: "text-as-paths-fallback";
|
|
44
|
-
reason: "
|
|
44
|
+
reason: "color-font" | "restricted";
|
|
45
45
|
fontFamily: string;
|
|
46
46
|
message: string;
|
|
47
47
|
} | {
|
|
@@ -93,9 +93,8 @@ export interface ToSvgOptions {
|
|
|
93
93
|
* cannot be edited in place. The glyphs are shaped by HarfBuzz (the browser's shaper; the Node handle always, a browser handle
|
|
94
94
|
* given `shapeWasm`), are hidden from assistive technology, and each outlined line is also invisible real text pinned to the
|
|
95
95
|
* drawn width, so screen readers, selection, copy and find-in-page get the words. Each element keeps its `data-opf-*` trace.
|
|
96
|
-
* A run stays text, reported as `text-as-paths-fallback` with a `reason`, when its font is a
|
|
97
|
-
* (`"
|
|
98
|
-
* layout's measurement disagree on it (`"shaping"`). Use it for thumbnails, previews and portable SVG files, not for an editing
|
|
96
|
+
* A run stays text, reported as `text-as-paths-fallback` with a `reason`, when its font is a color or bitmap font
|
|
97
|
+
* (`"color-font"`) or its face's fsType restricts embedding (`"restricted"`). Use it for thumbnails, previews and portable SVG files, not for an editing
|
|
99
98
|
* surface or the vector PDF (which keeps real text from `<text>` SVG).
|
|
100
99
|
*/
|
|
101
100
|
text?: "fonts" | "system" | "paths";
|
|
@@ -176,6 +175,8 @@ export interface ToPngOptions extends Omit<ToSvgOptions, "fonts"> {
|
|
|
176
175
|
export type PdfDiagnostic = {
|
|
177
176
|
/** One per embedded font face: what was embedded, how, and under which embedding permissions. */
|
|
178
177
|
code: "pdf-font-embedded";
|
|
178
|
+
/** The face, how it was embedded (a subset or the whole font), its size, and the restriction its fsType sets, in a sentence. */
|
|
179
|
+
message: string;
|
|
179
180
|
family: string; postscriptName: string; weight: number; italic: boolean;
|
|
180
181
|
/** Distinct glyphs kept, and the size of the embedded font program in bytes. */
|
|
181
182
|
glyphs: number; bytes: number;
|
|
@@ -242,7 +243,7 @@ export interface ToPdfOptions extends Omit<ToPngOptions, "onDiagnostic"> {
|
|
|
242
243
|
* the bundled files, the `fonts` handle's `fontFiles` and the font folders you supply, never system fonts.
|
|
243
244
|
*/
|
|
244
245
|
raster?: boolean;
|
|
245
|
-
/** A vector PDF paints the page this
|
|
246
|
+
/** A vector PDF paints the page this color first (default white, as a raster PDF composites on white); `"none"` leaves it unpainted. */
|
|
246
247
|
background?: string;
|
|
247
248
|
/** Vector only. Family drawn for the generic `serif`; default `defaultFontFamily`. */
|
|
248
249
|
serifFamily?: string;
|
|
@@ -300,7 +301,6 @@ export interface RenderBinding {
|
|
|
300
301
|
field?: string;
|
|
301
302
|
value: unknown;
|
|
302
303
|
path: string;
|
|
303
|
-
regionKey?: string;
|
|
304
304
|
}
|
|
305
305
|
|
|
306
306
|
export declare class OPFRenderError extends Error {
|