@officedk/pptxdk 0.0.0-stage → 0.2.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/LICENSE +21 -0
- package/dist/build-zrZuX4fK.d.ts +3 -0
- package/dist/build.d.ts +35 -0
- package/dist/build.js +128 -0
- package/dist/capabilities/dist/all.js +34 -0
- package/dist/capabilities/dist/box/box-codegen.js +84 -0
- package/dist/capabilities/dist/box/box-declaration.js +32 -0
- package/dist/capabilities/dist/box/box-elements.js +17 -0
- package/dist/capabilities/dist/box/box.js +142 -0
- package/dist/capabilities/dist/chart/chart-codegen.js +79 -0
- package/dist/capabilities/dist/chart/chart-declaration.js +7 -0
- package/dist/capabilities/dist/chart/chart-elements.js +12 -0
- package/dist/capabilities/dist/chart/chart-import.js +2403 -0
- package/dist/capabilities/dist/chart/chart-labels.js +86 -0
- package/dist/capabilities/dist/chart/chart-model.js +9 -0
- package/dist/capabilities/dist/chart/chart-schemas.js +1088 -0
- package/dist/capabilities/dist/chart/chart-xml.js +788 -0
- package/dist/capabilities/dist/chart/chart.js +1119 -0
- package/dist/capabilities/dist/chart/preview/axes-and-grid.js +311 -0
- package/dist/capabilities/dist/chart/preview/bar-column.js +143 -0
- package/dist/capabilities/dist/chart/preview/data-labels.js +334 -0
- package/dist/capabilities/dist/chart/preview/error-bars.js +213 -0
- package/dist/capabilities/dist/chart/preview/index.js +192 -0
- package/dist/capabilities/dist/chart/preview/layout.js +592 -0
- package/dist/capabilities/dist/chart/preview/legend.js +273 -0
- package/dist/capabilities/dist/chart/preview/line-area.js +404 -0
- package/dist/capabilities/dist/chart/preview/markers.js +100 -0
- package/dist/capabilities/dist/chart/preview/number-format.js +247 -0
- package/dist/capabilities/dist/chart/preview/pie-doughnut.js +159 -0
- package/dist/capabilities/dist/chart/preview/scales.js +365 -0
- package/dist/capabilities/dist/chart/preview/scatter.js +131 -0
- package/dist/capabilities/dist/chart/preview/style.js +60 -0
- package/dist/capabilities/dist/chart/preview/text-render.js +116 -0
- package/dist/capabilities/dist/chart/preview/trendlines.js +537 -0
- package/dist/capabilities/dist/chart/preview/types.js +5 -0
- package/dist/capabilities/dist/document.js +168 -0
- package/dist/capabilities/dist/font/font-embedding.js +119 -0
- package/dist/capabilities/dist/font/font-engine.js +834 -0
- package/dist/capabilities/dist/font/font-import.js +766 -0
- package/dist/capabilities/dist/font/font-subset.js +55 -0
- package/dist/capabilities/dist/font/font.js +72 -0
- package/dist/capabilities/dist/group/group-codegen.js +74 -0
- package/dist/capabilities/dist/group/group-declaration.js +41 -0
- package/dist/capabilities/dist/group/group-elements.js +12 -0
- package/dist/capabilities/dist/group/group-import.js +649 -0
- package/dist/capabilities/dist/group/group-xml.js +8 -0
- package/dist/capabilities/dist/group/group.js +260 -0
- package/dist/capabilities/dist/image/gif-decoder.js +244 -0
- package/dist/capabilities/dist/image/image-codegen.js +164 -0
- package/dist/capabilities/dist/image/image-declaration.js +8 -0
- package/dist/capabilities/dist/image/image-decode.js +244 -0
- package/dist/capabilities/dist/image/image-elements.js +12 -0
- package/dist/capabilities/dist/image/image-import.js +984 -0
- package/dist/capabilities/dist/image/image-schemas.js +147 -0
- package/dist/capabilities/dist/image/image-xml.js +12 -0
- package/dist/capabilities/dist/image/image.js +552 -0
- package/dist/capabilities/dist/line/line-codegen.js +89 -0
- package/dist/capabilities/dist/line/line-declaration.js +72 -0
- package/dist/capabilities/dist/line/line-elements.js +12 -0
- package/dist/capabilities/dist/line/line-import.js +504 -0
- package/dist/capabilities/dist/line/line-xml.js +9 -0
- package/dist/capabilities/dist/line/line.js +331 -0
- package/dist/capabilities/dist/masters/footer-placeholder.js +683 -0
- package/dist/capabilities/dist/masters/masters-codegen.js +69 -0
- package/dist/capabilities/dist/masters/masters.js +250 -0
- package/dist/capabilities/dist/motion/motion-api.js +757 -0
- package/dist/capabilities/dist/motion/motion-codegen.js +406 -0
- package/dist/capabilities/dist/motion/motion-elements.js +43 -0
- package/dist/capabilities/dist/motion/motion-import.js +1568 -0
- package/dist/capabilities/dist/motion/motion-plan.js +2340 -0
- package/dist/capabilities/dist/motion/motion-query.js +423 -0
- package/dist/capabilities/dist/motion/motion-schemas.js +339 -0
- package/dist/capabilities/dist/motion/motion.js +1617 -0
- package/dist/capabilities/dist/notes/notes-codegen.js +19 -0
- package/dist/capabilities/dist/notes/notes-declaration.js +8 -0
- package/dist/capabilities/dist/notes/notes-elements.js +12 -0
- package/dist/capabilities/dist/notes/notes-import.js +292 -0
- package/dist/capabilities/dist/notes/notes-schemas.js +38 -0
- package/dist/capabilities/dist/notes/notes-xml.js +38 -0
- package/dist/capabilities/dist/notes/notes.js +194 -0
- package/dist/capabilities/dist/placeholder/placeholder-codegen.js +54 -0
- package/dist/capabilities/dist/placeholder/placeholder-elements.js +13 -0
- package/dist/capabilities/dist/placeholder/placeholder-schemas.js +33 -0
- package/dist/capabilities/dist/placeholder/placeholder.js +451 -0
- package/dist/capabilities/dist/shape/shape-codegen.js +236 -0
- package/dist/capabilities/dist/shape/shape-declaration.js +45 -0
- package/dist/capabilities/dist/shape/shape-elements.js +12 -0
- package/dist/capabilities/dist/shape/shape-import.js +628 -0
- package/dist/capabilities/dist/shape/shape-xml.js +6 -0
- package/dist/capabilities/dist/shape/shape.js +320 -0
- package/dist/capabilities/dist/shared/geometry.js +1681 -0
- package/dist/capabilities/dist/shared/identity.js +205 -0
- package/dist/capabilities/dist/shared/morph-api.js +11 -0
- package/dist/capabilities/dist/shared/placeholder-import.js +238 -0
- package/dist/capabilities/dist/shared/preset-definitions.js +22423 -0
- package/dist/capabilities/dist/shared/style-inheritance.js +161 -0
- package/dist/capabilities/dist/shared/text-schemas.js +241 -0
- package/dist/capabilities/dist/shared/text-service.js +2252 -0
- package/dist/capabilities/dist/shared/visual.js +1197 -0
- package/dist/capabilities/dist/slide-background/slide-background-codegen.js +44 -0
- package/dist/capabilities/dist/slide-background/slide-background-import.js +166 -0
- package/dist/capabilities/dist/slide-background/slide-background-xml.js +34 -0
- package/dist/capabilities/dist/slide-background/slide-background.js +238 -0
- package/dist/capabilities/dist/table/table-codegen.js +125 -0
- package/dist/capabilities/dist/table/table-declaration.js +15 -0
- package/dist/capabilities/dist/table/table-elements.js +27 -0
- package/dist/capabilities/dist/table/table-import.js +606 -0
- package/dist/capabilities/dist/table/table-schemas.js +334 -0
- package/dist/capabilities/dist/table/table-xml.js +30 -0
- package/dist/capabilities/dist/table/table.js +739 -0
- package/dist/capabilities/dist/text/text-codegen.js +198 -0
- package/dist/capabilities/dist/text/text-declaration.js +27 -0
- package/dist/capabilities/dist/text/text-elements.js +54 -0
- package/dist/capabilities/dist/text/text-import.js +1224 -0
- package/dist/capabilities/dist/text/text-xml.js +9 -0
- package/dist/capabilities/dist/text/text.js +320 -0
- package/dist/capabilities/dist/transition/transition-api.js +136 -0
- package/dist/capabilities/dist/transition/transition-codegen.js +45 -0
- package/dist/capabilities/dist/transition/transition-import.js +477 -0
- package/dist/capabilities/dist/transition/transition.js +260 -0
- package/dist/capability-BbKW9w4O.d.ts +2131 -0
- package/dist/cli.js +20 -0
- package/dist/codegen/dist/assets.js +79 -0
- package/dist/codegen/dist/codegen.js +691 -0
- package/dist/codegen/dist/identifiers.js +203 -0
- package/dist/codegen/dist/index.js +3 -0
- package/dist/codegen/dist/printer.js +143 -0
- package/dist/codegen/dist/types.js +77 -0
- package/dist/core/dist/author-ids.js +51 -0
- package/dist/core/dist/author-schemas.js +330 -0
- package/dist/core/dist/block-flex-layout.js +801 -0
- package/dist/core/dist/build.js +4 -0
- package/dist/core/dist/capability.js +15 -0
- package/dist/core/dist/declaration.js +16 -0
- package/dist/core/dist/diagnostics.js +353 -0
- package/dist/core/dist/document-internals.js +26 -0
- package/dist/core/dist/document.js +417 -0
- package/dist/core/dist/font-seal.js +204 -0
- package/dist/core/dist/geometry-schemas.js +256 -0
- package/dist/core/dist/grid-layout.js +449 -0
- package/dist/core/dist/host.js +40 -0
- package/dist/core/dist/index.js +15 -0
- package/dist/core/dist/input-values.js +61 -0
- package/dist/core/dist/layout-protocol.js +61 -0
- package/dist/core/dist/layout-schemas.js +201 -0
- package/dist/core/dist/layout.js +340 -0
- package/dist/core/dist/masters.js +194 -0
- package/dist/core/dist/morph.js +30 -0
- package/dist/core/dist/placeholders.js +275 -0
- package/dist/core/dist/query.js +190 -0
- package/dist/core/dist/resolution.js +12 -0
- package/dist/core/dist/resolve.js +2246 -0
- package/dist/core/dist/stage-options.js +300 -0
- package/dist/core/dist/theme.js +1023 -0
- package/dist/core/dist/transform-geometry.js +72 -0
- package/dist/document-41spD7bq.d.ts +1350 -0
- package/dist/emit/dist/emit.js +957 -0
- package/dist/emit/dist/index.js +5 -0
- package/dist/emit/dist/ooxml.js +661 -0
- package/dist/emit/dist/shape-tree.js +12 -0
- package/dist/import/dist/alternate-content.js +54 -0
- package/dist/import/dist/diagnostics.js +157 -0
- package/dist/import/dist/fonts.js +309 -0
- package/dist/import/dist/import.js +513 -0
- package/dist/import/dist/index.js +16 -0
- package/dist/import/dist/masters.js +1293 -0
- package/dist/import/dist/mechanism.js +10 -0
- package/dist/import/dist/namespaces.js +61 -0
- package/dist/import/dist/notes-masters.js +300 -0
- package/dist/import/dist/opc.js +233 -0
- package/dist/import/dist/resources.js +166 -0
- package/dist/import/dist/sections.js +139 -0
- package/dist/import/dist/themes.js +777 -0
- package/dist/import/dist/visual.js +821 -0
- package/dist/import/dist/xml-fragments.js +277 -0
- package/dist/import/dist/xml-reader.js +267 -0
- package/dist/index-1ag7U9Jt.d.ts +63 -0
- package/dist/index-BEwhk7c8.d.ts +72 -0
- package/dist/index-cK2KtukZ.d.ts +161 -0
- package/dist/index-v77CTJev.d.ts +55 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +82 -0
- package/dist/node.d.ts +53 -0
- package/dist/node.js +225 -0
- package/dist/pptxdk/src/cli-commands.js +907 -0
- package/dist/pptxdk/src/compose.js +53 -0
- package/dist/pptxdk/src/slide.js +9 -0
- package/dist/preview/dist/index.js +342 -0
- package/dist/preview/dist/options.js +40 -0
- package/dist/preview/dist/svg-guard.js +1089 -0
- package/dist/preview.d.ts +12 -0
- package/dist/preview.js +29 -0
- package/dist/react/dist/append.js +66 -0
- package/dist/react/dist/document-adapter.js +404 -0
- package/dist/react/dist/elements.js +82 -0
- package/dist/react/dist/from-vanilla.js +57 -0
- package/dist/react/dist/index.js +89 -0
- package/dist/react/dist/mount.js +34 -0
- package/dist/react/dist/reconciler.js +290 -0
- package/dist/react.d.ts +235 -0
- package/dist/react.js +31 -0
- package/dist/transition-6n8GZxSg.d.ts +9 -0
- package/dist/vanilla.d.ts +4 -0
- package/dist/vanilla.js +15 -0
- package/package.json +79 -3
- package/README.md +0 -3
|
@@ -0,0 +1,834 @@
|
|
|
1
|
+
import { CapabilityError } from "../../../core/dist/diagnostics.js";
|
|
2
|
+
import { bytesSha256, computePitchFamilyFromPanose, formatPanoseHex, peekFontFaceResource } from "../../../core/dist/font-seal.js";
|
|
3
|
+
import "../../../core/dist/capability.js";
|
|
4
|
+
import { subsetFont } from "./font-subset.js";
|
|
5
|
+
import * as fontkit from "fontkit";
|
|
6
|
+
import * as hb from "harfbuzzjs";
|
|
7
|
+
// ../capabilities/dist/font/font-engine.js
|
|
8
|
+
/** Normalizes a font family name for case-insensitive, whitespace-collapsed lookup. */
|
|
9
|
+
function fontFamilyKey(value) {
|
|
10
|
+
return value.trim().replace(/\s+/gu, " ").toLowerCase();
|
|
11
|
+
}
|
|
12
|
+
const unsupportedColorFontTables = [
|
|
13
|
+
"CBDT",
|
|
14
|
+
"CBLC",
|
|
15
|
+
"COLR",
|
|
16
|
+
"CPAL",
|
|
17
|
+
"SVG ",
|
|
18
|
+
"sbix"
|
|
19
|
+
];
|
|
20
|
+
const parsedFontCache = /* @__PURE__ */ new Map();
|
|
21
|
+
const measureFaceCache = /* @__PURE__ */ new WeakMap();
|
|
22
|
+
let sharedHbBuffer;
|
|
23
|
+
let sharedHbBufferBusy = false;
|
|
24
|
+
function withHbBuffer(fn) {
|
|
25
|
+
if (!sharedHbBufferBusy) {
|
|
26
|
+
sharedHbBufferBusy = true;
|
|
27
|
+
sharedHbBuffer ??= new hb.Buffer();
|
|
28
|
+
try {
|
|
29
|
+
return fn(sharedHbBuffer);
|
|
30
|
+
} finally {
|
|
31
|
+
sharedHbBuffer.reset();
|
|
32
|
+
sharedHbBufferBusy = false;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
const buffer = new hb.Buffer();
|
|
36
|
+
try {
|
|
37
|
+
return fn(buffer);
|
|
38
|
+
} finally {
|
|
39
|
+
buffer.reset();
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
function readSfntDirectoryAt(bytes, headerOffset) {
|
|
43
|
+
if (headerOffset < 0 || headerOffset + 12 > bytes.byteLength) throw new Error("Font data is shorter than the 12-byte SFNT header");
|
|
44
|
+
const signature = String.fromCharCode(...bytes.subarray(headerOffset, headerOffset + 4));
|
|
45
|
+
if (signature !== "\0\0\0" && signature !== "true" && signature !== "OTTO") throw new Error("Font data is not a valid SFNT file");
|
|
46
|
+
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
47
|
+
const count = view.getUint16(headerOffset + 4);
|
|
48
|
+
if (headerOffset + 12 + count * 16 > bytes.byteLength) throw new Error("Font SFNT table directory is incomplete");
|
|
49
|
+
const tables = /* @__PURE__ */ new Map();
|
|
50
|
+
for (let index = 0; index < count; index += 1) {
|
|
51
|
+
const record = headerOffset + 12 + index * 16;
|
|
52
|
+
const tag = String.fromCharCode(...bytes.subarray(record, record + 4));
|
|
53
|
+
const offset = view.getUint32(record + 8);
|
|
54
|
+
const length = view.getUint32(record + 12);
|
|
55
|
+
if (offset > bytes.byteLength || length > bytes.byteLength - offset) throw new Error(`Font table ${tag} exceeds file boundaries`);
|
|
56
|
+
tables.set(tag, {
|
|
57
|
+
offset,
|
|
58
|
+
length
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
return {
|
|
62
|
+
signature,
|
|
63
|
+
tables
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
function readSfntDirectory(bytes) {
|
|
67
|
+
return readSfntDirectoryAt(bytes, 0);
|
|
68
|
+
}
|
|
69
|
+
function tryReadSfntDirectory(bytes) {
|
|
70
|
+
if (bytes.byteLength < 12) return void 0;
|
|
71
|
+
const signature = String.fromCharCode(...bytes.subarray(0, 4));
|
|
72
|
+
if (signature !== "\0\0\0" && signature !== "true" && signature !== "OTTO") return;
|
|
73
|
+
return readSfntDirectory(bytes);
|
|
74
|
+
}
|
|
75
|
+
function isItalicFontkit(font) {
|
|
76
|
+
const os2 = font["OS/2"];
|
|
77
|
+
return Boolean(os2?.fsSelection?.italic) || Boolean(os2?.fsSelection?.oblique) || font.italicAngle !== 0;
|
|
78
|
+
}
|
|
79
|
+
const utf16BeDecoder = new TextDecoder("utf-16be");
|
|
80
|
+
const eotRequiredNameIds = /* @__PURE__ */ new Set([
|
|
81
|
+
1,
|
|
82
|
+
2,
|
|
83
|
+
4,
|
|
84
|
+
5
|
|
85
|
+
]);
|
|
86
|
+
function unicodeNamePriority(platformID, languageID) {
|
|
87
|
+
if (platformID === 3 && languageID === 1033) return 0;
|
|
88
|
+
if (platformID === 0) return 1;
|
|
89
|
+
return 2;
|
|
90
|
+
}
|
|
91
|
+
function emptyUnicodeFontNames(nameTableError) {
|
|
92
|
+
return {
|
|
93
|
+
legacyFamilies: /* @__PURE__ */ new Set(),
|
|
94
|
+
legacyFamilyKeys: /* @__PURE__ */ new Set(),
|
|
95
|
+
preferredFamilies: /* @__PURE__ */ new Set(),
|
|
96
|
+
preferredFamilyKeys: /* @__PURE__ */ new Set(),
|
|
97
|
+
primaryLegacyFamily: void 0,
|
|
98
|
+
eotUtf16LeFields: /* @__PURE__ */ new Map(),
|
|
99
|
+
nameTableError
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Extracts all Unicode `Name ID 1` / `Name ID 16` family names and EOT UTF-16LE fields
|
|
104
|
+
* from an SFNT `name` table in a single pass (`platformID === 0` or `platformID === 3`
|
|
105
|
+
* with `encodingID === 1 || 10`, across all language IDs).
|
|
106
|
+
*/
|
|
107
|
+
function parseSfntUnicodeNames(bytes, table) {
|
|
108
|
+
if (table === void 0) return emptyUnicodeFontNames("Font name table is missing");
|
|
109
|
+
if (table.length < 6) return emptyUnicodeFontNames("Font name table is incomplete");
|
|
110
|
+
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
111
|
+
const count = view.getUint16(table.offset + 2);
|
|
112
|
+
const stringsOffset = view.getUint16(table.offset + 4);
|
|
113
|
+
if (6 + count * 12 > table.length || stringsOffset > table.length) return emptyUnicodeFontNames("Font name table record out of bounds");
|
|
114
|
+
const legacyFamilies = /* @__PURE__ */ new Set();
|
|
115
|
+
const legacyFamilyKeys = /* @__PURE__ */ new Set();
|
|
116
|
+
const preferredFamilies = /* @__PURE__ */ new Set();
|
|
117
|
+
const preferredFamilyKeys = /* @__PURE__ */ new Set();
|
|
118
|
+
let primaryLegacyFamily;
|
|
119
|
+
let primaryLegacyPriority = Number.POSITIVE_INFINITY;
|
|
120
|
+
const eotUtf16LeFields = /* @__PURE__ */ new Map();
|
|
121
|
+
const eotPriorities = /* @__PURE__ */ new Map();
|
|
122
|
+
let nameTableError;
|
|
123
|
+
for (let index = 0; index < count; index += 1) {
|
|
124
|
+
const record = table.offset + 6 + index * 12;
|
|
125
|
+
const platformID = view.getUint16(record);
|
|
126
|
+
const encodingID = view.getUint16(record + 2);
|
|
127
|
+
const languageID = view.getUint16(record + 4);
|
|
128
|
+
const nameID = view.getUint16(record + 6);
|
|
129
|
+
const length = view.getUint16(record + 8);
|
|
130
|
+
const offset = stringsOffset + view.getUint16(record + 10);
|
|
131
|
+
if (offset > table.length || length > table.length - offset) {
|
|
132
|
+
nameTableError ??= "Font name string out of bounds";
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
if (!(platformID === 0 || platformID === 3 && (encodingID === 1 || encodingID === 10))) continue;
|
|
136
|
+
const raw = bytes.subarray(table.offset + offset, table.offset + offset + length);
|
|
137
|
+
if (raw.byteLength % 2 !== 0) {
|
|
138
|
+
nameTableError ??= "Font name string is not UTF-16 encoded";
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
141
|
+
const priority = unicodeNamePriority(platformID, languageID);
|
|
142
|
+
if (eotRequiredNameIds.has(nameID)) {
|
|
143
|
+
if (priority < (eotPriorities.get(nameID) ?? Number.POSITIVE_INFINITY)) {
|
|
144
|
+
const littleEndian = new Uint8Array(raw.byteLength);
|
|
145
|
+
for (let at = 0; at < raw.byteLength; at += 2) {
|
|
146
|
+
littleEndian[at] = raw[at + 1];
|
|
147
|
+
littleEndian[at + 1] = raw[at];
|
|
148
|
+
}
|
|
149
|
+
eotUtf16LeFields.set(nameID, littleEndian);
|
|
150
|
+
eotPriorities.set(nameID, priority);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
if (nameID !== 1 && nameID !== 16) continue;
|
|
154
|
+
const decoded = utf16BeDecoder.decode(raw);
|
|
155
|
+
if (decoded.trim() === "") continue;
|
|
156
|
+
if (nameID === 1) {
|
|
157
|
+
legacyFamilies.add(decoded);
|
|
158
|
+
legacyFamilyKeys.add(fontFamilyKey(decoded));
|
|
159
|
+
if (priority < primaryLegacyPriority) {
|
|
160
|
+
primaryLegacyFamily = decoded;
|
|
161
|
+
primaryLegacyPriority = priority;
|
|
162
|
+
}
|
|
163
|
+
} else {
|
|
164
|
+
preferredFamilies.add(decoded);
|
|
165
|
+
preferredFamilyKeys.add(fontFamilyKey(decoded));
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
return {
|
|
169
|
+
legacyFamilies,
|
|
170
|
+
legacyFamilyKeys,
|
|
171
|
+
preferredFamilies,
|
|
172
|
+
preferredFamilyKeys,
|
|
173
|
+
primaryLegacyFamily,
|
|
174
|
+
eotUtf16LeFields,
|
|
175
|
+
nameTableError
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Fallback Unicode family extraction for WOFF/WOFF2 containers via `fontkit`'s
|
|
180
|
+
* decompressed `name.records` across all language entries.
|
|
181
|
+
*/
|
|
182
|
+
function extractWoffUnicodeNames(font) {
|
|
183
|
+
const records = font.name?.records;
|
|
184
|
+
const legacyFamilies = /* @__PURE__ */ new Set();
|
|
185
|
+
const legacyFamilyKeys = /* @__PURE__ */ new Set();
|
|
186
|
+
const preferredFamilies = /* @__PURE__ */ new Set();
|
|
187
|
+
const preferredFamilyKeys = /* @__PURE__ */ new Set();
|
|
188
|
+
const fontFamilyRecords = records?.fontFamily ?? {};
|
|
189
|
+
for (const value of Object.values(fontFamilyRecords)) if (typeof value === "string" && value.trim() !== "") {
|
|
190
|
+
legacyFamilies.add(value);
|
|
191
|
+
legacyFamilyKeys.add(fontFamilyKey(value));
|
|
192
|
+
}
|
|
193
|
+
const preferredFamilyRecords = records?.preferredFamily ?? {};
|
|
194
|
+
for (const value of Object.values(preferredFamilyRecords)) if (typeof value === "string" && value.trim() !== "") {
|
|
195
|
+
preferredFamilies.add(value);
|
|
196
|
+
preferredFamilyKeys.add(fontFamilyKey(value));
|
|
197
|
+
}
|
|
198
|
+
const englishLegacy = fontFamilyRecords["en"];
|
|
199
|
+
const firstLegacy = [...legacyFamilies][0];
|
|
200
|
+
const fallbackFamily = typeof font.familyName === "string" && font.familyName.trim() !== "" ? font.familyName : void 0;
|
|
201
|
+
const primaryLegacyFamily = typeof englishLegacy === "string" && englishLegacy.trim() !== "" ? englishLegacy : firstLegacy ?? fallbackFamily;
|
|
202
|
+
if (primaryLegacyFamily !== void 0 && legacyFamilies.size === 0) {
|
|
203
|
+
legacyFamilies.add(primaryLegacyFamily);
|
|
204
|
+
legacyFamilyKeys.add(fontFamilyKey(primaryLegacyFamily));
|
|
205
|
+
}
|
|
206
|
+
return {
|
|
207
|
+
legacyFamilies,
|
|
208
|
+
legacyFamilyKeys,
|
|
209
|
+
preferredFamilies,
|
|
210
|
+
preferredFamilyKeys,
|
|
211
|
+
primaryLegacyFamily,
|
|
212
|
+
eotUtf16LeFields: /* @__PURE__ */ new Map(),
|
|
213
|
+
nameTableError: void 0
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
function matchesAnyUnicodeFamily(parsed, family) {
|
|
217
|
+
const targetKey = fontFamilyKey(family);
|
|
218
|
+
return parsed.names.legacyFamilyKeys.has(targetKey) || parsed.names.preferredFamilyKeys.has(targetKey);
|
|
219
|
+
}
|
|
220
|
+
function matchesLegacyUnicodeFamily(parsed, family) {
|
|
221
|
+
return parsed.names.legacyFamilyKeys.has(fontFamilyKey(family));
|
|
222
|
+
}
|
|
223
|
+
function computeFontCategory(font) {
|
|
224
|
+
const panose = font["OS/2"]?.panose ?? [];
|
|
225
|
+
const isFixedPitch = font.post?.isFixedPitch ?? 0;
|
|
226
|
+
return {
|
|
227
|
+
pitchFamily: computePitchFamilyFromPanose(panose, isFixedPitch),
|
|
228
|
+
charset: 0
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
function isValidWeightClass(value) {
|
|
232
|
+
return typeof value === "number" && Number.isInteger(value) && value >= 1 && value <= 1e3;
|
|
233
|
+
}
|
|
234
|
+
function parseFontBinaryUncached(bytes, identity) {
|
|
235
|
+
if (bytes.byteLength < 12) throw new Error("Font data is empty or truncated");
|
|
236
|
+
if (String.fromCharCode(...bytes.subarray(0, 4)) === "ttcf") throw new Error("Font collections (TTC/OTC) are not supported");
|
|
237
|
+
const safeBytes = new Uint8Array(bytes);
|
|
238
|
+
const sfnt = tryReadSfntDirectory(safeBytes);
|
|
239
|
+
const opened = fontkit.create(Buffer.from(safeBytes.buffer, safeBytes.byteOffset, safeBytes.byteLength));
|
|
240
|
+
if (!("unitsPerEm" in opened) || typeof opened.hasGlyphForCodePoint !== "function") throw new Error("Font collection is not a single font file");
|
|
241
|
+
let format;
|
|
242
|
+
if (opened.type === "WOFF") format = "WOFF";
|
|
243
|
+
else if (opened.type === "WOFF2") format = "WOFF2";
|
|
244
|
+
else if (opened.type === "TTF") {
|
|
245
|
+
if (sfnt === void 0) throw new Error("SFNT header is invalid for uncompressed font");
|
|
246
|
+
format = sfnt.signature === "OTTO" || sfnt.tables.has("CFF ") || sfnt.tables.has("CFF2") ? "CFF" : "TTF";
|
|
247
|
+
} else throw new Error(`Unsupported font container type: ${String(opened.type)}`);
|
|
248
|
+
const directoryTables = opened.directory?.tables;
|
|
249
|
+
const hasTable = (tag) => Boolean(sfnt?.tables.has(tag)) || directoryTables !== void 0 && tag in directoryTables || tag in opened;
|
|
250
|
+
const hasFvar = hasTable("fvar") || opened.variationAxes !== void 0 && Object.keys(opened.variationAxes).length > 0;
|
|
251
|
+
const hasColorOrBitmapTable = unsupportedColorFontTables.some((tag) => hasTable(tag));
|
|
252
|
+
const hasGlyf = format === "TTF" && Boolean(sfnt?.tables.has("glyf")) && !hasTable("CFF ") && !hasTable("CFF2");
|
|
253
|
+
const os2 = opened["OS/2"];
|
|
254
|
+
const hasOs2 = os2 !== void 0;
|
|
255
|
+
let weightClass;
|
|
256
|
+
let fsType;
|
|
257
|
+
const rawOs2 = sfnt?.tables.get("OS/2");
|
|
258
|
+
if (rawOs2 !== void 0 && rawOs2.length >= 10) {
|
|
259
|
+
const view = new DataView(safeBytes.buffer, safeBytes.byteOffset, safeBytes.byteLength);
|
|
260
|
+
const rawWeight = view.getUint16(rawOs2.offset + 4);
|
|
261
|
+
weightClass = isValidWeightClass(rawWeight) ? rawWeight : void 0;
|
|
262
|
+
fsType = view.getUint16(rawOs2.offset + 8);
|
|
263
|
+
} else if (hasOs2 && isValidWeightClass(os2.usWeightClass)) weightClass = os2.usWeightClass;
|
|
264
|
+
const isItalic = isItalicFontkit(opened);
|
|
265
|
+
const os2Bold = Boolean(os2?.fsSelection?.bold);
|
|
266
|
+
const { pitchFamily, charset } = computeFontCategory(opened);
|
|
267
|
+
const panose = rawOs2 !== void 0 && rawOs2.length >= 42 ? formatPanoseHex(safeBytes.subarray(rawOs2.offset + 32, rawOs2.offset + 42)) : Array.isArray(os2?.panose) && os2.panose.length === 10 ? formatPanoseHex(os2.panose) : void 0;
|
|
268
|
+
const names = sfnt !== void 0 ? parseSfntUnicodeNames(safeBytes, sfnt.tables.get("name")) : extractWoffUnicodeNames(opened);
|
|
269
|
+
return {
|
|
270
|
+
identity,
|
|
271
|
+
bytes: safeBytes,
|
|
272
|
+
format,
|
|
273
|
+
font: opened,
|
|
274
|
+
sfnt,
|
|
275
|
+
names,
|
|
276
|
+
hasGlyf,
|
|
277
|
+
hasFvar,
|
|
278
|
+
hasColorOrBitmapTable,
|
|
279
|
+
hasOs2,
|
|
280
|
+
weightClass,
|
|
281
|
+
style: isItalic ? "italic" : "normal",
|
|
282
|
+
os2Bold,
|
|
283
|
+
isItalic,
|
|
284
|
+
fsType,
|
|
285
|
+
unitsPerEm: opened.unitsPerEm,
|
|
286
|
+
ascent: opened.ascent,
|
|
287
|
+
descent: opened.descent,
|
|
288
|
+
lineGap: opened.lineGap,
|
|
289
|
+
underlineThickness: opened.underlineThickness,
|
|
290
|
+
underlinePosition: opened.underlinePosition,
|
|
291
|
+
yStrikeoutSize: os2?.yStrikeoutSize ?? 0,
|
|
292
|
+
yStrikeoutPosition: os2?.yStrikeoutPosition ?? 0,
|
|
293
|
+
...panose === void 0 ? {} : { panose },
|
|
294
|
+
pitchFamily,
|
|
295
|
+
charset,
|
|
296
|
+
hbEntry: void 0
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
function getOrParseFontBinary(bytes, knownIdentity) {
|
|
300
|
+
const identity = knownIdentity ?? bytesSha256(bytes);
|
|
301
|
+
let parsed = parsedFontCache.get(identity);
|
|
302
|
+
if (parsed === void 0) {
|
|
303
|
+
parsed = parseFontBinaryUncached(bytes, identity);
|
|
304
|
+
parsedFontCache.set(identity, parsed);
|
|
305
|
+
}
|
|
306
|
+
return parsed;
|
|
307
|
+
}
|
|
308
|
+
function tryGetOrParseFontBinary(bytes, knownIdentity) {
|
|
309
|
+
try {
|
|
310
|
+
return getOrParseFontBinary(bytes, knownIdentity);
|
|
311
|
+
} catch {
|
|
312
|
+
return;
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
function ensureHarfBuzzFont(parsed) {
|
|
316
|
+
if (parsed.format !== "TTF" && parsed.format !== "CFF") return;
|
|
317
|
+
if (parsed.hbEntry === void 0) {
|
|
318
|
+
const blob = new hb.Blob(parsed.bytes);
|
|
319
|
+
const face = new hb.Face(blob, 0);
|
|
320
|
+
const font = new hb.Font(face);
|
|
321
|
+
font.setScale(parsed.unitsPerEm, parsed.unitsPerEm);
|
|
322
|
+
parsed.hbEntry = {
|
|
323
|
+
blob,
|
|
324
|
+
face,
|
|
325
|
+
font
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
return parsed.hbEntry.font;
|
|
329
|
+
}
|
|
330
|
+
function toMeasureFace(parsed) {
|
|
331
|
+
const face = {
|
|
332
|
+
identity: parsed.identity,
|
|
333
|
+
unitsPerEm: parsed.unitsPerEm,
|
|
334
|
+
ascent: parsed.ascent,
|
|
335
|
+
descent: parsed.descent,
|
|
336
|
+
lineGap: parsed.lineGap,
|
|
337
|
+
underlineThickness: parsed.underlineThickness,
|
|
338
|
+
underlinePosition: parsed.underlinePosition,
|
|
339
|
+
yStrikeoutSize: parsed.yStrikeoutSize,
|
|
340
|
+
yStrikeoutPosition: parsed.yStrikeoutPosition,
|
|
341
|
+
os2Bold: parsed.os2Bold,
|
|
342
|
+
hasColorOrBitmapTable: parsed.hasColorOrBitmapTable
|
|
343
|
+
};
|
|
344
|
+
measureFaceCache.set(face, parsed);
|
|
345
|
+
return face;
|
|
346
|
+
}
|
|
347
|
+
function parsedOfMeasureFace(face) {
|
|
348
|
+
const cached = measureFaceCache.get(face) ?? parsedFontCache.get(face.identity);
|
|
349
|
+
if (cached === void 0) throw new Error(`Missing parsed font binary for ${face.identity}`);
|
|
350
|
+
return cached;
|
|
351
|
+
}
|
|
352
|
+
function fontErrorDetails(source, extra) {
|
|
353
|
+
return {
|
|
354
|
+
font: {
|
|
355
|
+
family: source.family,
|
|
356
|
+
weight: source.weight,
|
|
357
|
+
style: source.style
|
|
358
|
+
},
|
|
359
|
+
...extra
|
|
360
|
+
};
|
|
361
|
+
}
|
|
362
|
+
function failFont(source, code, message, extra) {
|
|
363
|
+
throw new CapabilityError(code, message, source.path, fontErrorDetails(source, extra));
|
|
364
|
+
}
|
|
365
|
+
/**
|
|
366
|
+
* Attempts to read static single-font weight (`OS/2.usWeightClass`) and glyph style
|
|
367
|
+
* (`italic || oblique || italicAngle !== 0`) for `font()` construction.
|
|
368
|
+
* Returns `undefined` for corrupt bytes, font collections, or variable (`fvar`) fonts
|
|
369
|
+
* so `resolve`/`emit` can report a node-path-attributed `BuildError`.
|
|
370
|
+
*/
|
|
371
|
+
function tryInferStaticFontFaceMetadata(bytes, knownIdentity) {
|
|
372
|
+
const parsed = tryGetOrParseFontBinary(bytes, knownIdentity);
|
|
373
|
+
if (parsed === void 0 || parsed.hasFvar || parsed.weightClass === void 0) return;
|
|
374
|
+
return {
|
|
375
|
+
weight: parsed.weightClass,
|
|
376
|
+
style: parsed.style,
|
|
377
|
+
...parsed.panose === void 0 ? {} : { panose: parsed.panose },
|
|
378
|
+
pitchFamily: parsed.pitchFamily
|
|
379
|
+
};
|
|
380
|
+
}
|
|
381
|
+
/**
|
|
382
|
+
* Resolves the effective `(weight, style)` slot of a declared `FontFace` for style matching.
|
|
383
|
+
* Supports unconstructed literal `{ data }` faces and ensures `fvar`/corrupt omitted-weight
|
|
384
|
+
* faces are still selected so `resolve` rejects them with full path context.
|
|
385
|
+
*/
|
|
386
|
+
function resolveDeclaredFaceSlot(face) {
|
|
387
|
+
if (face.weight !== void 0 && face.style !== void 0) return {
|
|
388
|
+
weight: face.weight,
|
|
389
|
+
style: face.style,
|
|
390
|
+
matchAnyWeightOnFvarOrCorrupt: false
|
|
391
|
+
};
|
|
392
|
+
const resource = peekFontFaceResource(face);
|
|
393
|
+
if (resource === void 0) return {
|
|
394
|
+
weight: face.weight ?? 400,
|
|
395
|
+
style: face.style ?? "normal",
|
|
396
|
+
matchAnyWeightOnFvarOrCorrupt: false
|
|
397
|
+
};
|
|
398
|
+
const parsed = tryGetOrParseFontBinary(resource.bytes, resource.sha256);
|
|
399
|
+
if (parsed === void 0 || parsed.hasFvar) return {
|
|
400
|
+
weight: face.weight ?? parsed?.weightClass ?? 400,
|
|
401
|
+
style: face.style ?? parsed?.style ?? "normal",
|
|
402
|
+
matchAnyWeightOnFvarOrCorrupt: face.weight === void 0
|
|
403
|
+
};
|
|
404
|
+
return {
|
|
405
|
+
weight: face.weight ?? parsed.weightClass ?? 400,
|
|
406
|
+
style: face.style ?? parsed.style,
|
|
407
|
+
matchAnyWeightOnFvarOrCorrupt: false
|
|
408
|
+
};
|
|
409
|
+
}
|
|
410
|
+
/**
|
|
411
|
+
* Validates that a font face resource is a single non-variable font whose actual `OS/2`
|
|
412
|
+
* weight and italic metadata match the declared `weight` and `style`.
|
|
413
|
+
*/
|
|
414
|
+
function validateFontFaceResource(source) {
|
|
415
|
+
let parsed;
|
|
416
|
+
try {
|
|
417
|
+
parsed = getOrParseFontBinary(source.data, source.identity);
|
|
418
|
+
} catch (error) {
|
|
419
|
+
return failFont(source, "unsupported-font-format", `Cannot parse font file for ${source.family}: ${error instanceof Error ? error.message : String(error)}`);
|
|
420
|
+
}
|
|
421
|
+
if (parsed.hasFvar) return failFont(source, "unsupported-font-format", `Variable font "${source.family}" contains an OpenType "fvar" axis table and is not supported; supply static per-weight font files instead`);
|
|
422
|
+
if (parsed.weightClass === void 0) return failFont(source, "unsupported-font-format", `Font file for ${source.family} is missing a valid OS/2 usWeightClass (1..1000)`);
|
|
423
|
+
if (parsed.weightClass !== source.weight) return failFont(source, "font-weight-mismatch", `Font value for ${source.family} declared weight ${source.weight}, but file OS/2 usWeightClass is ${parsed.weightClass}`);
|
|
424
|
+
if (parsed.style !== source.style) return failFont(source, "font-style-mismatch", `Font value for ${source.family} declared style "${source.style}", but file metadata indicates "${parsed.style}"`);
|
|
425
|
+
return toMeasureFace(parsed);
|
|
426
|
+
}
|
|
427
|
+
/**
|
|
428
|
+
* Opens a validated font face for text measurement and preview outline extraction,
|
|
429
|
+
* verifying family match (unless `substitute` is true), line metrics, and initializing
|
|
430
|
+
* HarfBuzz shaping for static `.ttf` and static CFF `.otf` fonts.
|
|
431
|
+
*/
|
|
432
|
+
function openMeasureFontFace(source) {
|
|
433
|
+
const face = validateFontFaceResource(source);
|
|
434
|
+
const parsed = parsedOfMeasureFace(face);
|
|
435
|
+
if (!source.substitute && !matchesAnyUnicodeFamily(parsed, source.family)) return failFont(source, "font-substitution-required", `Metrics file declares ${parsed.names.primaryLegacyFamily ?? [...parsed.names.preferredFamilies][0] ?? parsed.font.familyName}; retaining output font name ${source.family} requires setting Font.substitute explicitly`, { reason: "font-substitution-required" });
|
|
436
|
+
if (!Number.isFinite(parsed.unitsPerEm) || parsed.unitsPerEm <= 0 || !Number.isFinite(parsed.ascent) || !Number.isFinite(parsed.descent) || !Number.isFinite(parsed.lineGap)) return failFont(source, "font-metrics-invalid", `Font line metrics for ${source.family} are invalid`, { reason: "font-metrics-invalid" });
|
|
437
|
+
ensureHarfBuzzFont(parsed);
|
|
438
|
+
return face;
|
|
439
|
+
}
|
|
440
|
+
/** Returns unique visible characters in `text` that lack a non-.notdef glyph in `face`. */
|
|
441
|
+
function findMissingFontGlyphs(face, text, requiresVisibleGlyph) {
|
|
442
|
+
const parsed = parsedOfMeasureFace(face);
|
|
443
|
+
const missing = /* @__PURE__ */ new Set();
|
|
444
|
+
for (const character of text) {
|
|
445
|
+
if (!requiresVisibleGlyph(character)) continue;
|
|
446
|
+
const codePoint = character.codePointAt(0);
|
|
447
|
+
if (codePoint !== void 0 && (!parsed.font.hasGlyphForCodePoint(codePoint) || parsed.font.glyphForCodePoint(codePoint).id === 0)) missing.add(character);
|
|
448
|
+
}
|
|
449
|
+
return [...missing];
|
|
450
|
+
}
|
|
451
|
+
/** Shapes `visibleText` and returns per-glyph horizontal advances in font design units. */
|
|
452
|
+
function shapeFontAdvances(face, visibleText) {
|
|
453
|
+
if (visibleText === "") return [];
|
|
454
|
+
const parsed = parsedOfMeasureFace(face);
|
|
455
|
+
const hbFont = ensureHarfBuzzFont(parsed);
|
|
456
|
+
if (hbFont !== void 0) return withHbBuffer((buffer) => {
|
|
457
|
+
buffer.addText(visibleText);
|
|
458
|
+
buffer.guessSegmentProperties();
|
|
459
|
+
hb.shape(hbFont, buffer);
|
|
460
|
+
return buffer.getGlyphInfosAndPositions().map((item) => item.xAdvance ?? 0);
|
|
461
|
+
});
|
|
462
|
+
return parsed.font.layout(visibleText).positions.map((position) => position.xAdvance);
|
|
463
|
+
}
|
|
464
|
+
/** Shapes `visibleText` with direction/language and returns SVG glyph outline paths and offsets. */
|
|
465
|
+
function shapeFontOutlines(face, visibleText, isRtl, lang) {
|
|
466
|
+
if (visibleText === "") return [];
|
|
467
|
+
const parsed = parsedOfMeasureFace(face);
|
|
468
|
+
const hbFont = ensureHarfBuzzFont(parsed);
|
|
469
|
+
if (hbFont !== void 0) return withHbBuffer((buffer) => {
|
|
470
|
+
buffer.addText(visibleText);
|
|
471
|
+
buffer.guessSegmentProperties();
|
|
472
|
+
buffer.setDirection(isRtl ? hb.Direction.RTL : hb.Direction.LTR);
|
|
473
|
+
if (lang !== void 0) buffer.setLanguage(lang);
|
|
474
|
+
hb.shape(hbFont, buffer);
|
|
475
|
+
return buffer.getGlyphInfosAndPositions().map((item) => ({
|
|
476
|
+
path: hbFont.glyphToPath(item.codepoint),
|
|
477
|
+
xAdvance: item.xAdvance ?? 0,
|
|
478
|
+
xOffset: item.xOffset ?? 0,
|
|
479
|
+
yOffset: item.yOffset ?? 0,
|
|
480
|
+
cluster: item.cluster,
|
|
481
|
+
isSpace: /\p{White_Space}/u.test(visibleText[item.cluster] ?? "")
|
|
482
|
+
}));
|
|
483
|
+
});
|
|
484
|
+
const fkRun = parsed.font.layout(visibleText, void 0, void 0, void 0, isRtl ? "rtl" : "ltr");
|
|
485
|
+
return fkRun.glyphs.map((glyph, index) => {
|
|
486
|
+
const pos = fkRun.positions[index];
|
|
487
|
+
const isSpace = glyph.codePoints.some((cp) => /\p{White_Space}/u.test(String.fromCodePoint(cp)));
|
|
488
|
+
return {
|
|
489
|
+
path: glyph.path.toSVG(),
|
|
490
|
+
xAdvance: pos.xAdvance,
|
|
491
|
+
xOffset: pos.xOffset,
|
|
492
|
+
yOffset: pos.yOffset,
|
|
493
|
+
cluster: index,
|
|
494
|
+
isSpace
|
|
495
|
+
};
|
|
496
|
+
});
|
|
497
|
+
}
|
|
498
|
+
function checkFsTypeEmbeddability(fsType) {
|
|
499
|
+
const usagePermission = fsType & 15;
|
|
500
|
+
if (![
|
|
501
|
+
0,
|
|
502
|
+
2,
|
|
503
|
+
4,
|
|
504
|
+
8
|
|
505
|
+
].includes(usagePermission) || (fsType & -784) !== 0) return false;
|
|
506
|
+
if (usagePermission === 2 || usagePermission === 4 || (fsType & 512) !== 0) return false;
|
|
507
|
+
return true;
|
|
508
|
+
}
|
|
509
|
+
/**
|
|
510
|
+
* Checks whether raw font bytes, declared `family` (`Name ID 1`), and author policy allow full
|
|
511
|
+
* TrueType font embedding.
|
|
512
|
+
*/
|
|
513
|
+
function isTrueTypeFontEmbeddable(bytes, family, substitute, declaredEmbeddable, knownIdentity) {
|
|
514
|
+
if (substitute || !declaredEmbeddable) return false;
|
|
515
|
+
const parsed = tryGetOrParseFontBinary(bytes, knownIdentity);
|
|
516
|
+
if (parsed === void 0 || !parsed.hasGlyf || parsed.hasFvar || parsed.hasColorOrBitmapTable || parsed.sfnt === void 0 || !parsed.sfnt.tables.has("head") || !parsed.sfnt.tables.has("name") || parsed.fsType === void 0) return false;
|
|
517
|
+
if (!matchesLegacyUnicodeFamily(parsed, family)) return false;
|
|
518
|
+
const os2 = parsed.sfnt.tables.get("OS/2");
|
|
519
|
+
if (os2 === void 0 || os2.length < 64) return false;
|
|
520
|
+
return checkFsTypeEmbeddability(parsed.fsType);
|
|
521
|
+
}
|
|
522
|
+
/** Validates that a font face satisfies OOXML static TrueType EOT embedding requirements. */
|
|
523
|
+
function validateEmbeddableTrueTypeFont(input, mode) {
|
|
524
|
+
if (!input.embeddable) return failFont(input, "font-not-embeddable", `${input.family} explicitly declares embeddable: false and cannot satisfy font embedding request`);
|
|
525
|
+
if (input.substitute) {
|
|
526
|
+
const parsed = input.bytes !== void 0 ? tryGetOrParseFontBinary(input.bytes, input.identity) : void 0;
|
|
527
|
+
const nativeLegacy = parsed?.names.primaryLegacyFamily;
|
|
528
|
+
if (parsed !== void 0 && matchesLegacyUnicodeFamily(parsed, input.family)) {
|
|
529
|
+
const nativeName = nativeLegacy ?? input.family;
|
|
530
|
+
return failFont(input, "font-substitute-not-embeddable", `Font "${input.family}" sets substitute: true, but the font file's native Name ID 1 ("${nativeName}") already matches "${input.family}"; remove redundant substitute: true to enable embedding.`);
|
|
531
|
+
}
|
|
532
|
+
if (nativeLegacy !== void 0) return failFont(input, "font-substitute-not-embeddable", `Font "${input.family}" sets substitute: true with a font file whose native Name ID 1 is "${nativeLegacy}"; substitute fonts cannot be embedded under another family name.`);
|
|
533
|
+
return failFont(input, "font-substitute-not-embeddable", `Font "${input.family}" uses substitute font metrics and cannot satisfy embedding request for the declared family`);
|
|
534
|
+
}
|
|
535
|
+
if (input.bytes === void 0 || input.identity === "missing") return failFont(input, "font-embedding-resource-missing", `${input.family} ${input.weight} ${input.style} is missing embeddable font resource`);
|
|
536
|
+
const actualIdentity = bytesSha256(input.bytes);
|
|
537
|
+
if (actualIdentity !== input.identity) return failFont(input, "invalid-font-face", `Font resource identity for ${input.family} does not match actual bytes`);
|
|
538
|
+
let parsed;
|
|
539
|
+
try {
|
|
540
|
+
parsed = getOrParseFontBinary(input.bytes, actualIdentity);
|
|
541
|
+
} catch (error) {
|
|
542
|
+
return failFont(input, "unsupported-font-format", `Failed to parse TrueType font tables for ${input.family}: ${error instanceof Error ? error.message : String(error)}`);
|
|
543
|
+
}
|
|
544
|
+
if (parsed.hasFvar) return failFont(input, "unsupported-font-format", `Variable font "${input.family}" contains an OpenType "fvar" axis table and cannot be embedded; supply static per-weight TrueType font files instead`);
|
|
545
|
+
if (parsed.hasColorOrBitmapTable) return failFont(input, "unsupported-font-format", `Font embedding only supports monochrome static TrueType outlines; color or bitmap font "${input.family}" is not supported`);
|
|
546
|
+
if (parsed.format !== "TTF" || !parsed.hasGlyf || parsed.sfnt === void 0 || !parsed.sfnt.tables.has("OS/2") || !parsed.sfnt.tables.has("head") || !parsed.sfnt.tables.has("name")) return failFont(input, "unsupported-font-format", "Font embedding only supports static TrueType (glyf) outlines; CFF OpenType (.otf), WOFF, WOFF2, and font collections are not supported");
|
|
547
|
+
if (parsed.sfnt.tables.get("OS/2").length < 64 || parsed.fsType === void 0 || parsed.weightClass === void 0) return failFont(input, "unsupported-font-format", "Font OS/2 table is missing weight, fsType, or style selection fields");
|
|
548
|
+
const fsType = parsed.fsType;
|
|
549
|
+
const usagePermission = fsType & 15;
|
|
550
|
+
if (![
|
|
551
|
+
0,
|
|
552
|
+
2,
|
|
553
|
+
4,
|
|
554
|
+
8
|
|
555
|
+
].includes(usagePermission) || (fsType & -784) !== 0) return failFont(input, "invalid-font-permissions", `OS/2 fsType of ${input.family} contains invalid or reserved permission flags`);
|
|
556
|
+
if (usagePermission === 2) return failFont(input, "font-embedding-restricted", `OS/2 fsType of ${input.family} restricts embedding`);
|
|
557
|
+
if (usagePermission === 4) return failFont(input, "font-embedding-preview-print", `OS/2 fsType of ${input.family} permits only preview and print, which cannot satisfy font embedding for editable presentations`);
|
|
558
|
+
if (mode === "subset" && (fsType & 256) !== 0) return failFont(input, "font-subsetting-forbidden", `OS/2 fsType of ${input.family} forbids subsetting; switch to full embedding or omit embedding request`);
|
|
559
|
+
if ((fsType & 512) !== 0) return failFont(input, "font-embedding-bitmap-only", `OS/2 fsType of ${input.family} allows bitmap embedding only and cannot embed TrueType outlines`);
|
|
560
|
+
if (!matchesLegacyUnicodeFamily(parsed, input.family)) {
|
|
561
|
+
const nativeLegacy = parsed.names.primaryLegacyFamily;
|
|
562
|
+
if (parsed.names.preferredFamilyKeys.has(fontFamilyKey(input.family))) {
|
|
563
|
+
const nativeLabel = nativeLegacy ?? "an unspecified Name ID 1 legacy family";
|
|
564
|
+
return failFont(input, "font-family-mismatch", `Font "${input.family}" matches typographic Name ID 16 only, whereas embedding requires matching the font file's native Name ID 1 legacy family "${nativeLabel}". Register an independent font("${nativeLabel}", ...) for embedding, or disable embedFonts.`);
|
|
565
|
+
}
|
|
566
|
+
const nativeLabel = nativeLegacy ?? [...parsed.names.preferredFamilies][0] ?? parsed.font.familyName ?? "unknown";
|
|
567
|
+
return failFont(input, "font-family-mismatch", `Font file's native Name ID 1 family "${nativeLabel}" does not match declared family "${input.family}". Register font("${nativeLabel}", ...) for embedding, or set substitute: true for unembedded measurement only.`);
|
|
568
|
+
}
|
|
569
|
+
if (parsed.weightClass !== input.weight) return failFont(input, "font-weight-mismatch", `${input.family} requested ${input.weight} weight, but OS/2 usWeightClass is ${parsed.weightClass}`);
|
|
570
|
+
if (parsed.os2Bold !== input.bold || parsed.isItalic !== input.italic || parsed.isItalic !== (input.style === "italic")) return failFont(input, "font-style-mismatch", `OS/2 fsSelection of ${input.family} does not match bold or italic styles emitted for text`);
|
|
571
|
+
return {
|
|
572
|
+
identity: parsed.identity,
|
|
573
|
+
primaryLegacyFamily: parsed.names.primaryLegacyFamily,
|
|
574
|
+
weightClass: parsed.weightClass,
|
|
575
|
+
fsType,
|
|
576
|
+
os2Bold: parsed.os2Bold,
|
|
577
|
+
isItalic: parsed.isItalic,
|
|
578
|
+
...parsed.panose === void 0 ? {} : { panose: parsed.panose },
|
|
579
|
+
pitchFamily: parsed.pitchFamily,
|
|
580
|
+
charset: parsed.charset
|
|
581
|
+
};
|
|
582
|
+
}
|
|
583
|
+
function getEotNameUtf16Le(names, id, context) {
|
|
584
|
+
if (names.nameTableError !== void 0) return failFont(context, "unsupported-font-format", names.nameTableError);
|
|
585
|
+
const field = names.eotUtf16LeFields.get(id);
|
|
586
|
+
if (field === void 0) return failFont(context, "unsupported-font-format", `Font name table is missing Unicode name field ${id} required for EOT`);
|
|
587
|
+
return field;
|
|
588
|
+
}
|
|
589
|
+
function subsetTrueTypeAndVerify(parsed, checked, characters, context, requiresVisibleGlyph) {
|
|
590
|
+
const requiredCharacters = [...new Set(characters)];
|
|
591
|
+
const missingCharacters = requiredCharacters.filter((character) => {
|
|
592
|
+
const codePoint = character.codePointAt(0);
|
|
593
|
+
return codePoint !== void 0 && requiresVisibleGlyph(character) && (!parsed.font.hasGlyphForCodePoint(codePoint) || parsed.font.glyphForCodePoint(codePoint).id === 0);
|
|
594
|
+
});
|
|
595
|
+
if (missingCharacters.length > 0) return failFont(context, "font-missing-glyph", `${context.family} ${context.weight} ${context.style} font is missing glyph for emitted character ${missingCharacters[0]}`, { characters: missingCharacters });
|
|
596
|
+
let subsetBytes;
|
|
597
|
+
try {
|
|
598
|
+
subsetBytes = subsetFont(parsed.bytes, characters);
|
|
599
|
+
} catch (error) {
|
|
600
|
+
return failFont(context, "font-subsetting-failed", `Failed to generate character subset for ${context.family}: ${error instanceof Error ? error.message : String(error)}`);
|
|
601
|
+
}
|
|
602
|
+
let subsetParsed;
|
|
603
|
+
try {
|
|
604
|
+
subsetParsed = parseFontBinaryUncached(subsetBytes, bytesSha256(subsetBytes));
|
|
605
|
+
if (subsetParsed.format !== "TTF" || !subsetParsed.hasGlyf || subsetParsed.hasFvar || subsetParsed.sfnt === void 0 || !subsetParsed.sfnt.tables.has("OS/2") || !subsetParsed.sfnt.tables.has("head") || !subsetParsed.sfnt.tables.has("name")) throw new Error("Subset is not a static TrueType font");
|
|
606
|
+
} catch (error) {
|
|
607
|
+
return failFont(context, "font-subsetting-failed", `Failed to parse character subset for ${context.family} independently: ${error instanceof Error ? error.message : String(error)}`);
|
|
608
|
+
}
|
|
609
|
+
if (subsetParsed.weightClass !== checked.weightClass || subsetParsed.font["OS/2"].fsType.editable !== parsed.font["OS/2"].fsType.editable || subsetParsed.font["OS/2"].fsType.noSubsetting !== parsed.font["OS/2"].fsType.noSubsetting || subsetParsed.os2Bold !== parsed.os2Bold || subsetParsed.isItalic !== checked.isItalic) return failFont(context, "font-subsetting-failed", `Character subset for ${context.family} did not retain embedding permissions and styles of the original font`);
|
|
610
|
+
for (const character of requiredCharacters) {
|
|
611
|
+
const codePoint = character.codePointAt(0);
|
|
612
|
+
if (codePoint !== void 0 && requiresVisibleGlyph(character) && !subsetParsed.font.hasGlyphForCodePoint(codePoint)) return failFont(context, "font-subsetting-failed", `Character subset for ${context.family} did not retain emitted character ${character}`);
|
|
613
|
+
}
|
|
614
|
+
return subsetBytes;
|
|
615
|
+
}
|
|
616
|
+
function packUncompressedEot(parsed, checked, payloadBytes, context) {
|
|
617
|
+
const sourceBytes = parsed.bytes;
|
|
618
|
+
const os2 = parsed.sfnt.tables.get("OS/2");
|
|
619
|
+
const view = new DataView(sourceBytes.buffer, sourceBytes.byteOffset, sourceBytes.byteLength);
|
|
620
|
+
let payloadSfnt;
|
|
621
|
+
try {
|
|
622
|
+
payloadSfnt = readSfntDirectory(payloadBytes);
|
|
623
|
+
} catch (error) {
|
|
624
|
+
return failFont(context, "unsupported-font-format", error instanceof Error ? error.message : String(error));
|
|
625
|
+
}
|
|
626
|
+
const payloadHead = payloadSfnt.tables.get("head");
|
|
627
|
+
if (payloadHead === void 0) return failFont(context, "unsupported-font-format", "Font payload is missing head table");
|
|
628
|
+
const payloadView = new DataView(payloadBytes.buffer, payloadBytes.byteOffset, payloadBytes.byteLength);
|
|
629
|
+
const os2Version = view.getUint16(os2.offset);
|
|
630
|
+
const field32 = (offset) => offset + 4 <= os2.length ? view.getUint32(os2.offset + offset) : 0;
|
|
631
|
+
const panose = sourceBytes.slice(os2.offset + 32, os2.offset + 42);
|
|
632
|
+
const chunks = [];
|
|
633
|
+
const u8 = (value) => chunks.push(Uint8Array.of(value));
|
|
634
|
+
const u16 = (value) => {
|
|
635
|
+
const chunk = /* @__PURE__ */ new Uint8Array(2);
|
|
636
|
+
new DataView(chunk.buffer).setUint16(0, value, true);
|
|
637
|
+
chunks.push(chunk);
|
|
638
|
+
};
|
|
639
|
+
const u32 = (value) => {
|
|
640
|
+
const chunk = /* @__PURE__ */ new Uint8Array(4);
|
|
641
|
+
new DataView(chunk.buffer).setUint32(0, value >>> 0, true);
|
|
642
|
+
chunks.push(chunk);
|
|
643
|
+
};
|
|
644
|
+
u32(0);
|
|
645
|
+
u32(payloadBytes.byteLength);
|
|
646
|
+
u32(131074);
|
|
647
|
+
u32(0);
|
|
648
|
+
chunks.push(panose);
|
|
649
|
+
u8(1);
|
|
650
|
+
u8(checked.isItalic ? 1 : 0);
|
|
651
|
+
u32(checked.weightClass);
|
|
652
|
+
u16(checked.fsType);
|
|
653
|
+
u16(20556);
|
|
654
|
+
for (const offset of [
|
|
655
|
+
42,
|
|
656
|
+
46,
|
|
657
|
+
50,
|
|
658
|
+
54
|
|
659
|
+
]) u32(field32(offset));
|
|
660
|
+
for (const offset of [78, 82]) u32(os2Version >= 1 && os2.length >= offset + 4 ? field32(offset) : 0);
|
|
661
|
+
u32(payloadView.getUint32(payloadHead.offset + 8));
|
|
662
|
+
for (let index = 0; index < 4; index += 1) u32(0);
|
|
663
|
+
for (const id of [
|
|
664
|
+
1,
|
|
665
|
+
2,
|
|
666
|
+
5,
|
|
667
|
+
4
|
|
668
|
+
]) {
|
|
669
|
+
const name = getEotNameUtf16Le(parsed.names, id, context);
|
|
670
|
+
u16(0);
|
|
671
|
+
u16(name.byteLength);
|
|
672
|
+
chunks.push(name);
|
|
673
|
+
}
|
|
674
|
+
u16(0);
|
|
675
|
+
u16(0);
|
|
676
|
+
u32(1346851650);
|
|
677
|
+
u32(0);
|
|
678
|
+
u16(0);
|
|
679
|
+
u16(0);
|
|
680
|
+
u32(0);
|
|
681
|
+
u32(0);
|
|
682
|
+
chunks.push(payloadBytes);
|
|
683
|
+
const size = chunks.reduce((sum, chunk) => sum + chunk.byteLength, 0);
|
|
684
|
+
const output = new Uint8Array(size);
|
|
685
|
+
let offset = 0;
|
|
686
|
+
for (const chunk of chunks) {
|
|
687
|
+
output.set(chunk, offset);
|
|
688
|
+
offset += chunk.byteLength;
|
|
689
|
+
}
|
|
690
|
+
new DataView(output.buffer).setUint32(0, size, true);
|
|
691
|
+
return output;
|
|
692
|
+
}
|
|
693
|
+
/**
|
|
694
|
+
* Generates an uncompressed EOT (`.fntdata`) container for an already-validated
|
|
695
|
+
* static TrueType font in either `"full"` or `"subset"` embedding mode.
|
|
696
|
+
*/
|
|
697
|
+
function buildEmbeddedEotPayload(sourceBytes, checked, mode, characters, context, requiresVisibleGlyph) {
|
|
698
|
+
const parsed = getOrParseFontBinary(sourceBytes, checked.identity);
|
|
699
|
+
if (parsed.sfnt === void 0) return failFont(context, "unsupported-font-format", `Font data for ${context.family} is not a valid SFNT file`);
|
|
700
|
+
return packUncompressedEot(parsed, checked, mode === "subset" ? subsetTrueTypeAndVerify(parsed, checked, characters ?? "", context, requiresVisibleGlyph) : parsed.bytes, context);
|
|
701
|
+
}
|
|
702
|
+
/**
|
|
703
|
+
* Inspects unpacked SFNT bytes from an imported PPTX embedded font part, returning
|
|
704
|
+
* family match status and `1..1000` weight / unified italic metadata if valid TrueType.
|
|
705
|
+
*/
|
|
706
|
+
function inspectImportedEmbeddedFont(ttfBytes, declaredTypeface) {
|
|
707
|
+
const parsed = tryGetOrParseFontBinary(ttfBytes);
|
|
708
|
+
if (parsed === void 0 || parsed.format !== "TTF" || parsed.hasFvar) return;
|
|
709
|
+
return {
|
|
710
|
+
familyMatches: matchesAnyUnicodeFamily(parsed, declaredTypeface),
|
|
711
|
+
weight: parsed.weightClass,
|
|
712
|
+
style: parsed.hasOs2 ? parsed.style : void 0
|
|
713
|
+
};
|
|
714
|
+
}
|
|
715
|
+
function sfntTableChecksum(bytes) {
|
|
716
|
+
const paddedLength = Math.ceil(bytes.byteLength / 4) * 4;
|
|
717
|
+
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
718
|
+
let sum = 0;
|
|
719
|
+
for (let offset = 0; offset < paddedLength; offset += 4) if (offset + 4 <= bytes.byteLength) sum = sum + view.getUint32(offset) >>> 0;
|
|
720
|
+
else {
|
|
721
|
+
let word = 0;
|
|
722
|
+
for (let byte = 0; byte < 4; byte += 1) {
|
|
723
|
+
const value = offset + byte < bytes.byteLength ? bytes[offset + byte] : 0;
|
|
724
|
+
word = word << 8 | value;
|
|
725
|
+
}
|
|
726
|
+
sum = sum + (word >>> 0) >>> 0;
|
|
727
|
+
}
|
|
728
|
+
return sum >>> 0;
|
|
729
|
+
}
|
|
730
|
+
function packStandaloneSfnt(signature, tables, sourceBytes) {
|
|
731
|
+
const sorted = [...tables.entries()].toSorted(([a], [b]) => a < b ? -1 : a > b ? 1 : 0);
|
|
732
|
+
const numTables = sorted.length;
|
|
733
|
+
const headerSize = 12 + numTables * 16;
|
|
734
|
+
let totalSize = headerSize;
|
|
735
|
+
for (const [, record] of sorted) totalSize += Math.ceil(record.length / 4) * 4;
|
|
736
|
+
const output = new Uint8Array(totalSize);
|
|
737
|
+
const view = new DataView(output.buffer);
|
|
738
|
+
for (let i = 0; i < 4; i += 1) output[i] = signature.charCodeAt(i);
|
|
739
|
+
view.setUint16(4, numTables);
|
|
740
|
+
const entrySelector = Math.floor(Math.log2(Math.max(1, numTables)));
|
|
741
|
+
const searchRange = (1 << entrySelector) * 16;
|
|
742
|
+
view.setUint16(6, searchRange);
|
|
743
|
+
view.setUint16(8, entrySelector);
|
|
744
|
+
view.setUint16(10, numTables * 16 - searchRange);
|
|
745
|
+
let dataOffset = headerSize;
|
|
746
|
+
let headOffset;
|
|
747
|
+
for (let index = 0; index < sorted.length; index += 1) {
|
|
748
|
+
const [tag, record] = sorted[index];
|
|
749
|
+
const slice = sourceBytes.subarray(record.offset, record.offset + record.length);
|
|
750
|
+
const tableBytes = tag === "head" && slice.byteLength >= 12 ? new Uint8Array(slice) : slice;
|
|
751
|
+
if (tag === "head" && tableBytes.byteLength >= 12) {
|
|
752
|
+
new DataView(tableBytes.buffer).setUint32(8, 0);
|
|
753
|
+
headOffset = dataOffset;
|
|
754
|
+
}
|
|
755
|
+
output.set(tableBytes, dataOffset);
|
|
756
|
+
const recordOffset = 12 + index * 16;
|
|
757
|
+
for (let i = 0; i < 4; i += 1) output[recordOffset + i] = tag.charCodeAt(i);
|
|
758
|
+
view.setUint32(recordOffset + 4, sfntTableChecksum(tableBytes));
|
|
759
|
+
view.setUint32(recordOffset + 8, dataOffset);
|
|
760
|
+
view.setUint32(recordOffset + 12, tableBytes.byteLength);
|
|
761
|
+
dataOffset += Math.ceil(tableBytes.byteLength / 4) * 4;
|
|
762
|
+
}
|
|
763
|
+
if (headOffset !== void 0) {
|
|
764
|
+
const adjustment = 2981146554 - sfntTableChecksum(output) >>> 0;
|
|
765
|
+
view.setUint32(headOffset + 8, adjustment);
|
|
766
|
+
}
|
|
767
|
+
return output;
|
|
768
|
+
}
|
|
769
|
+
/**
|
|
770
|
+
* Parses a TrueType/OpenType Collection (`ttcf` v1/v2) binary buffer and reconstructs standalone
|
|
771
|
+
* static SFNT faces for members matching `family` (or the sole family when `substitute: true`).
|
|
772
|
+
*/
|
|
773
|
+
function unpackFontCollectionFaces(bytes, family, options = {}) {
|
|
774
|
+
const failCollection = (code, message) => {
|
|
775
|
+
throw new CapabilityError(code, message, void 0, { font: { family } });
|
|
776
|
+
};
|
|
777
|
+
if (bytes.byteLength < 12) return failCollection("unsupported-font-format", "Font collection data is empty or truncated");
|
|
778
|
+
if (String.fromCharCode(...bytes.subarray(0, 4)) !== "ttcf") return failCollection("unsupported-font-format", "Font collection data must begin with a valid 'ttcf' header");
|
|
779
|
+
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
780
|
+
const majorVersion = view.getUint16(4);
|
|
781
|
+
const minorVersion = view.getUint16(6);
|
|
782
|
+
if (majorVersion !== 1 && majorVersion !== 2 || minorVersion !== 0) return failCollection("unsupported-font-format", `Unsupported font collection version ${majorVersion}.${minorVersion}`);
|
|
783
|
+
const numFonts = view.getUint32(8);
|
|
784
|
+
if (numFonts === 0 || (bytes.byteLength - 12) / 4 < numFonts) return failCollection("unsupported-font-format", "Font collection header has invalid or truncated member offset table");
|
|
785
|
+
const members = [];
|
|
786
|
+
for (let index = 0; index < numFonts; index += 1) {
|
|
787
|
+
const dirOffset = view.getUint32(12 + index * 4);
|
|
788
|
+
let sfnt;
|
|
789
|
+
try {
|
|
790
|
+
sfnt = readSfntDirectoryAt(bytes, dirOffset);
|
|
791
|
+
} catch (error) {
|
|
792
|
+
return failCollection("unsupported-font-format", `Corrupt member font at index ${index} in font collection: ${error instanceof Error ? error.message : String(error)}`);
|
|
793
|
+
}
|
|
794
|
+
const names = parseSfntUnicodeNames(bytes, sfnt.tables.get("name"));
|
|
795
|
+
const allFamilyKeys = /* @__PURE__ */ new Set([...names.legacyFamilyKeys, ...names.preferredFamilyKeys]);
|
|
796
|
+
const displayFamily = names.primaryLegacyFamily ?? [...names.preferredFamilies][0] ?? [...names.legacyFamilies][0];
|
|
797
|
+
members.push({
|
|
798
|
+
sfnt,
|
|
799
|
+
names,
|
|
800
|
+
allFamilyKeys,
|
|
801
|
+
displayFamily
|
|
802
|
+
});
|
|
803
|
+
}
|
|
804
|
+
const targetKey = fontFamilyKey(family);
|
|
805
|
+
let matched = members.filter((member) => member.allFamilyKeys.has(targetKey));
|
|
806
|
+
if (matched.length === 0 && options.substitute === true) {
|
|
807
|
+
const commonKeys = new Set(members[0].allFamilyKeys);
|
|
808
|
+
for (let index = 1; index < members.length; index += 1) for (const key of commonKeys) if (!members[index].allFamilyKeys.has(key)) commonKeys.delete(key);
|
|
809
|
+
if (commonKeys.size > 0) matched = members;
|
|
810
|
+
}
|
|
811
|
+
if (matched.length === 0) {
|
|
812
|
+
const available = [...new Set(members.map((m) => m.displayFamily).filter((name) => name !== void 0))];
|
|
813
|
+
return failCollection("font-family-mismatch", `Font collection does not contain family "${family}"${available.length > 0 ? `; available families: ${available.join(", ")}` : ""}`);
|
|
814
|
+
}
|
|
815
|
+
const unpacked = [];
|
|
816
|
+
for (const member of matched) {
|
|
817
|
+
if (member.sfnt.tables.has("fvar")) return failCollection("unsupported-font-format", `Variable font "${family}" inside font collection contains an OpenType "fvar" axis table and is not supported; supply static per-weight font files instead`);
|
|
818
|
+
if (!member.sfnt.tables.has("OS/2") || !member.sfnt.tables.has("head") || !member.sfnt.tables.has("name")) return failCollection("unsupported-font-format", `Member font for "${family}" in font collection is missing required SFNT tables`);
|
|
819
|
+
const standaloneBytes = packStandaloneSfnt(member.sfnt.signature, member.sfnt.tables, bytes);
|
|
820
|
+
const parsed = tryGetOrParseFontBinary(standaloneBytes, bytesSha256(standaloneBytes));
|
|
821
|
+
if (parsed === void 0) return failCollection("unsupported-font-format", `Failed to parse reconstructed SFNT face for "${family}" from font collection`);
|
|
822
|
+
if (parsed.hasFvar) return failCollection("unsupported-font-format", `Variable font "${family}" inside font collection contains an OpenType "fvar" axis table and is not supported; supply static per-weight font files instead`);
|
|
823
|
+
if (parsed.weightClass === void 0) return failCollection("unsupported-font-format", `Member font for "${family}" in font collection is missing a valid OS/2 usWeightClass (1..1000)`);
|
|
824
|
+
unpacked.push({
|
|
825
|
+
bytes: standaloneBytes,
|
|
826
|
+
weight: parsed.weightClass,
|
|
827
|
+
style: parsed.style,
|
|
828
|
+
...parsed.panose === void 0 ? {} : { panose: parsed.panose },
|
|
829
|
+
pitchFamily: parsed.pitchFamily
|
|
830
|
+
});
|
|
831
|
+
}
|
|
832
|
+
return unpacked;
|
|
833
|
+
}
|
|
834
|
+
export { buildEmbeddedEotPayload, findMissingFontGlyphs, fontFamilyKey, inspectImportedEmbeddedFont, isTrueTypeFontEmbeddable, openMeasureFontFace, resolveDeclaredFaceSlot, shapeFontAdvances, shapeFontOutlines, tryInferStaticFontFaceMetadata, unpackFontCollectionFaces, validateEmbeddableTrueTypeFont, validateFontFaceResource };
|