pptx-glimpse 1.1.2 → 3.0.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/dist/browser.cjs +14329 -0
- package/dist/browser.d.cts +131 -0
- package/dist/browser.d.ts +131 -0
- package/dist/browser.js +3180 -0
- package/dist/chunk-2AYNMYMC.js +1554 -0
- package/dist/chunk-KMSN55AE.js +9629 -0
- package/dist/chunk-MWMHSSAD.js +124 -0
- package/dist/chunk-QPT6BMN5.js +25 -0
- package/dist/font-collector-DYooJP6L.d.cts +1345 -0
- package/dist/font-collector-DYooJP6L.d.ts +1345 -0
- package/dist/index.cjs +9224 -10957
- package/dist/index.d.cts +4 -204
- package/dist/index.d.ts +4 -204
- package/dist/index.js +66 -12682
- package/dist/node-6KTAWUIB.js +9 -0
- package/dist/node-font-loader-274G445U.js +45 -0
- package/dist/png-IONMVVDQ.js +53 -0
- package/package.json +8 -1
|
@@ -0,0 +1,1554 @@
|
|
|
1
|
+
// ../renderer/src/warning-logger.ts
|
|
2
|
+
var PREFIX = "[pptx-glimpse]";
|
|
3
|
+
var currentLevel = "off";
|
|
4
|
+
var entries = [];
|
|
5
|
+
var featureCounts = /* @__PURE__ */ new Map();
|
|
6
|
+
function initWarningLogger(level) {
|
|
7
|
+
currentLevel = level;
|
|
8
|
+
entries = [];
|
|
9
|
+
featureCounts.clear();
|
|
10
|
+
}
|
|
11
|
+
function warn(feature, message, context) {
|
|
12
|
+
if (currentLevel === "off") return;
|
|
13
|
+
entries.push({ feature, message, ...context !== void 0 && { context } });
|
|
14
|
+
const existing = featureCounts.get(feature);
|
|
15
|
+
if (existing) {
|
|
16
|
+
existing.count++;
|
|
17
|
+
} else {
|
|
18
|
+
featureCounts.set(feature, { message, count: 1 });
|
|
19
|
+
}
|
|
20
|
+
if (currentLevel === "debug") {
|
|
21
|
+
const ctx = context ? ` (${context})` : "";
|
|
22
|
+
console.warn(`${PREFIX} SKIP: ${feature} - ${message}${ctx}`);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
function debug(feature, message, context) {
|
|
26
|
+
if (currentLevel !== "debug") return;
|
|
27
|
+
entries.push({ feature, message, ...context !== void 0 && { context } });
|
|
28
|
+
const existing = featureCounts.get(feature);
|
|
29
|
+
if (existing) {
|
|
30
|
+
existing.count++;
|
|
31
|
+
} else {
|
|
32
|
+
featureCounts.set(feature, { message, count: 1 });
|
|
33
|
+
}
|
|
34
|
+
const ctx = context ? ` (${context})` : "";
|
|
35
|
+
console.warn(`${PREFIX} DEBUG: ${feature} - ${message}${ctx}`);
|
|
36
|
+
}
|
|
37
|
+
function getWarningSummary() {
|
|
38
|
+
const features = [];
|
|
39
|
+
for (const [feature, { message, count }] of featureCounts) {
|
|
40
|
+
features.push({ feature, message, count });
|
|
41
|
+
}
|
|
42
|
+
return { totalCount: entries.length, features };
|
|
43
|
+
}
|
|
44
|
+
function flushWarnings() {
|
|
45
|
+
const summary = getWarningSummary();
|
|
46
|
+
if (currentLevel !== "off" && summary.features.length > 0) {
|
|
47
|
+
console.warn(`${PREFIX} Summary: ${summary.features.length} unsupported feature(s) detected`);
|
|
48
|
+
for (const { feature, count } of summary.features) {
|
|
49
|
+
console.warn(` - ${feature}: ${count} occurrence(s)`);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
entries = [];
|
|
53
|
+
featureCounts.clear();
|
|
54
|
+
return summary;
|
|
55
|
+
}
|
|
56
|
+
function getWarningEntries() {
|
|
57
|
+
return entries;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// ../renderer/src/font/font-mapping.ts
|
|
61
|
+
var DEFAULT_FONT_MAPPING = {
|
|
62
|
+
// Latin fonts
|
|
63
|
+
Calibri: "Carlito",
|
|
64
|
+
"Calibri Light": "Carlito",
|
|
65
|
+
Arial: "Arimo",
|
|
66
|
+
"Times New Roman": "Tinos",
|
|
67
|
+
"Courier New": "Cousine",
|
|
68
|
+
Cambria: "Caladea",
|
|
69
|
+
// Japanese Gothic fonts -> Noto Sans JP
|
|
70
|
+
// Use "Noto Sans JP" instead of "Noto Sans CJK JP".
|
|
71
|
+
// NotoSansCJK TTC extracts only the first font, so it may not always be possible to obtain the JP variant.
|
|
72
|
+
// The font name matches the standalone NotoSansJP.ttf downloaded in the Docker environment.
|
|
73
|
+
\u30E1\u30A4\u30EA\u30AA: "Noto Sans JP",
|
|
74
|
+
Meiryo: "Noto Sans JP",
|
|
75
|
+
\u6E38\u30B4\u30B7\u30C3\u30AF: "Noto Sans JP",
|
|
76
|
+
"Yu Gothic": "Noto Sans JP",
|
|
77
|
+
"MS \u30B4\u30B7\u30C3\u30AF": "Noto Sans JP",
|
|
78
|
+
"MS Gothic": "Noto Sans JP",
|
|
79
|
+
"MS P\u30B4\u30B7\u30C3\u30AF": "Noto Sans JP",
|
|
80
|
+
"MS PGothic": "Noto Sans JP",
|
|
81
|
+
// Japanese Mincho fonts -> Noto Serif CJK JP
|
|
82
|
+
"MS \u660E\u671D": "Noto Serif CJK JP",
|
|
83
|
+
"MS Mincho": "Noto Serif CJK JP",
|
|
84
|
+
"MS P\u660E\u671D": "Noto Serif CJK JP",
|
|
85
|
+
"MS PMincho": "Noto Serif CJK JP",
|
|
86
|
+
\u6E38\u660E\u671D: "Noto Serif CJK JP",
|
|
87
|
+
"Yu Mincho": "Noto Serif CJK JP"
|
|
88
|
+
};
|
|
89
|
+
function createFontMapping(userMapping) {
|
|
90
|
+
if (!userMapping) return { ...DEFAULT_FONT_MAPPING };
|
|
91
|
+
return { ...DEFAULT_FONT_MAPPING, ...userMapping };
|
|
92
|
+
}
|
|
93
|
+
function normalizeFullWidth(s) {
|
|
94
|
+
return s.replace(/[\uff01-\uff5e]/g, (ch) => String.fromCharCode(ch.charCodeAt(0) - 65248)).replace(/\u3000/g, " ");
|
|
95
|
+
}
|
|
96
|
+
function getMappedFont(fontFamily, mapping) {
|
|
97
|
+
if (!fontFamily) return null;
|
|
98
|
+
const direct = mapping[fontFamily];
|
|
99
|
+
if (direct !== void 0) return direct;
|
|
100
|
+
const normalized = normalizeFullWidth(fontFamily);
|
|
101
|
+
if (normalized !== fontFamily) {
|
|
102
|
+
const directNormalized = mapping[normalized];
|
|
103
|
+
if (directNormalized !== void 0) return directNormalized;
|
|
104
|
+
}
|
|
105
|
+
const lower = normalized.toLowerCase();
|
|
106
|
+
for (const key of Object.keys(mapping)) {
|
|
107
|
+
if (normalizeFullWidth(key).toLowerCase() === lower) {
|
|
108
|
+
return mapping[key];
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return null;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// ../renderer/src/unsafe-type-assertion.ts
|
|
115
|
+
function unsafeExternalInteropAssertion(value) {
|
|
116
|
+
return value;
|
|
117
|
+
}
|
|
118
|
+
function unsafeBrandAssertion(value) {
|
|
119
|
+
return value;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// ../renderer/src/data/font-metrics.ts
|
|
123
|
+
var metricsData = {
|
|
124
|
+
Carlito: {
|
|
125
|
+
unitsPerEm: 2048,
|
|
126
|
+
ascender: 1950,
|
|
127
|
+
descender: -550,
|
|
128
|
+
defaultWidth: 991,
|
|
129
|
+
cjkWidth: 2048,
|
|
130
|
+
widths: {
|
|
131
|
+
" ": 463,
|
|
132
|
+
"!": 667,
|
|
133
|
+
'"': 821,
|
|
134
|
+
"#": 1020,
|
|
135
|
+
"$": 1038,
|
|
136
|
+
"%": 1464,
|
|
137
|
+
"&": 1397,
|
|
138
|
+
"'": 452,
|
|
139
|
+
"(": 621,
|
|
140
|
+
")": 621,
|
|
141
|
+
"*": 1020,
|
|
142
|
+
"+": 1020,
|
|
143
|
+
",": 511,
|
|
144
|
+
"-": 627,
|
|
145
|
+
".": 517,
|
|
146
|
+
"/": 791,
|
|
147
|
+
"0": 1038,
|
|
148
|
+
"1": 1038,
|
|
149
|
+
"2": 1038,
|
|
150
|
+
"3": 1038,
|
|
151
|
+
"4": 1038,
|
|
152
|
+
"5": 1038,
|
|
153
|
+
"6": 1038,
|
|
154
|
+
"7": 1038,
|
|
155
|
+
"8": 1038,
|
|
156
|
+
"9": 1038,
|
|
157
|
+
":": 548,
|
|
158
|
+
";": 548,
|
|
159
|
+
"<": 1020,
|
|
160
|
+
"=": 1020,
|
|
161
|
+
">": 1020,
|
|
162
|
+
"?": 949,
|
|
163
|
+
"@": 1831,
|
|
164
|
+
"A": 1185,
|
|
165
|
+
"B": 1114,
|
|
166
|
+
"C": 1092,
|
|
167
|
+
"D": 1260,
|
|
168
|
+
"E": 1e3,
|
|
169
|
+
"F": 941,
|
|
170
|
+
"G": 1292,
|
|
171
|
+
"H": 1276,
|
|
172
|
+
"I": 516,
|
|
173
|
+
"J": 653,
|
|
174
|
+
"K": 1064,
|
|
175
|
+
"L": 861,
|
|
176
|
+
"M": 1751,
|
|
177
|
+
"N": 1322,
|
|
178
|
+
"O": 1356,
|
|
179
|
+
"P": 1058,
|
|
180
|
+
"Q": 1378,
|
|
181
|
+
"R": 1112,
|
|
182
|
+
"S": 941,
|
|
183
|
+
"T": 998,
|
|
184
|
+
"U": 1314,
|
|
185
|
+
"V": 1162,
|
|
186
|
+
"W": 1822,
|
|
187
|
+
"X": 1063,
|
|
188
|
+
"Y": 998,
|
|
189
|
+
"Z": 959,
|
|
190
|
+
"[": 628,
|
|
191
|
+
"\\": 791,
|
|
192
|
+
"]": 628,
|
|
193
|
+
"^": 1020,
|
|
194
|
+
"_": 1020,
|
|
195
|
+
"`": 596,
|
|
196
|
+
"a": 981,
|
|
197
|
+
"b": 1076,
|
|
198
|
+
"c": 866,
|
|
199
|
+
"d": 1076,
|
|
200
|
+
"e": 1019,
|
|
201
|
+
"f": 625,
|
|
202
|
+
"g": 964,
|
|
203
|
+
"h": 1076,
|
|
204
|
+
"i": 470,
|
|
205
|
+
"j": 490,
|
|
206
|
+
"k": 931,
|
|
207
|
+
"l": 470,
|
|
208
|
+
"m": 1636,
|
|
209
|
+
"n": 1076,
|
|
210
|
+
"o": 1080,
|
|
211
|
+
"p": 1076,
|
|
212
|
+
"q": 1076,
|
|
213
|
+
"r": 714,
|
|
214
|
+
"s": 801,
|
|
215
|
+
"t": 686,
|
|
216
|
+
"u": 1076,
|
|
217
|
+
"v": 925,
|
|
218
|
+
"w": 1464,
|
|
219
|
+
"x": 887,
|
|
220
|
+
"y": 927,
|
|
221
|
+
"z": 809,
|
|
222
|
+
"{": 644,
|
|
223
|
+
"|": 943,
|
|
224
|
+
"}": 644,
|
|
225
|
+
"~": 1020,
|
|
226
|
+
"\xA0": 463,
|
|
227
|
+
"\xA1": 667,
|
|
228
|
+
"\xA2": 1020,
|
|
229
|
+
"\xA3": 1038,
|
|
230
|
+
"\xA4": 1020,
|
|
231
|
+
"\xA5": 1038,
|
|
232
|
+
"\xA6": 1020,
|
|
233
|
+
"\xA7": 1020,
|
|
234
|
+
"\xA8": 804,
|
|
235
|
+
"\xA9": 1709,
|
|
236
|
+
"\xAA": 824,
|
|
237
|
+
"\xAB": 1049,
|
|
238
|
+
"\xAC": 1020,
|
|
239
|
+
"\xAE": 1038,
|
|
240
|
+
"\xAF": 807,
|
|
241
|
+
"\xB0": 694,
|
|
242
|
+
"\xB1": 1020,
|
|
243
|
+
"\xB2": 688,
|
|
244
|
+
"\xB3": 685,
|
|
245
|
+
"\xB4": 598,
|
|
246
|
+
"\xB5": 1126,
|
|
247
|
+
"\xB6": 1200,
|
|
248
|
+
"\xB7": 517,
|
|
249
|
+
"\xB8": 629,
|
|
250
|
+
"\xB9": 504,
|
|
251
|
+
"\xBA": 865,
|
|
252
|
+
"\xBB": 1049,
|
|
253
|
+
"\xBC": 1303,
|
|
254
|
+
"\xBD": 1375,
|
|
255
|
+
"\xBE": 1383,
|
|
256
|
+
"\xBF": 949,
|
|
257
|
+
"\xC0": 1185,
|
|
258
|
+
"\xC1": 1185,
|
|
259
|
+
"\xC2": 1185,
|
|
260
|
+
"\xC3": 1185,
|
|
261
|
+
"\xC4": 1185,
|
|
262
|
+
"\xC5": 1185,
|
|
263
|
+
"\xC6": 1563,
|
|
264
|
+
"\xC7": 1092,
|
|
265
|
+
"\xC8": 1e3,
|
|
266
|
+
"\xC9": 1e3,
|
|
267
|
+
"\xCA": 1e3,
|
|
268
|
+
"\xCB": 1e3,
|
|
269
|
+
"\xCC": 516,
|
|
270
|
+
"\xCD": 516,
|
|
271
|
+
"\xCE": 516,
|
|
272
|
+
"\xCF": 516,
|
|
273
|
+
"\xD0": 1279,
|
|
274
|
+
"\xD1": 1322,
|
|
275
|
+
"\xD2": 1356,
|
|
276
|
+
"\xD3": 1356,
|
|
277
|
+
"\xD4": 1356,
|
|
278
|
+
"\xD5": 1356,
|
|
279
|
+
"\xD6": 1356,
|
|
280
|
+
"\xD7": 1020,
|
|
281
|
+
"\xD8": 1359,
|
|
282
|
+
"\xD9": 1314,
|
|
283
|
+
"\xDA": 1314,
|
|
284
|
+
"\xDB": 1314,
|
|
285
|
+
"\xDC": 1314,
|
|
286
|
+
"\xDD": 998,
|
|
287
|
+
"\xDE": 1058,
|
|
288
|
+
"\xDF": 1080,
|
|
289
|
+
"\xE0": 981,
|
|
290
|
+
"\xE1": 981,
|
|
291
|
+
"\xE2": 981,
|
|
292
|
+
"\xE3": 981,
|
|
293
|
+
"\xE4": 981,
|
|
294
|
+
"\xE5": 981,
|
|
295
|
+
"\xE6": 1583,
|
|
296
|
+
"\xE7": 866,
|
|
297
|
+
"\xE8": 1019,
|
|
298
|
+
"\xE9": 1019,
|
|
299
|
+
"\xEA": 1019,
|
|
300
|
+
"\xEB": 1019,
|
|
301
|
+
"\xEC": 470,
|
|
302
|
+
"\xED": 470,
|
|
303
|
+
"\xEE": 470,
|
|
304
|
+
"\xEF": 470,
|
|
305
|
+
"\xF0": 1076,
|
|
306
|
+
"\xF1": 1076,
|
|
307
|
+
"\xF2": 1080,
|
|
308
|
+
"\xF3": 1080,
|
|
309
|
+
"\xF4": 1080,
|
|
310
|
+
"\xF5": 1080,
|
|
311
|
+
"\xF6": 1080,
|
|
312
|
+
"\xF7": 1020,
|
|
313
|
+
"\xF8": 1084,
|
|
314
|
+
"\xF9": 1076,
|
|
315
|
+
"\xFA": 1076,
|
|
316
|
+
"\xFB": 1076,
|
|
317
|
+
"\xFC": 1076,
|
|
318
|
+
"\xFD": 927,
|
|
319
|
+
"\xFE": 1076,
|
|
320
|
+
"\xFF": 927
|
|
321
|
+
}
|
|
322
|
+
},
|
|
323
|
+
LiberationSans: {
|
|
324
|
+
unitsPerEm: 2048,
|
|
325
|
+
ascender: 1854,
|
|
326
|
+
descender: -434,
|
|
327
|
+
defaultWidth: 1114,
|
|
328
|
+
cjkWidth: 2048,
|
|
329
|
+
widths: {
|
|
330
|
+
" ": 569,
|
|
331
|
+
"!": 569,
|
|
332
|
+
'"': 727,
|
|
333
|
+
"#": 1139,
|
|
334
|
+
"$": 1139,
|
|
335
|
+
"%": 1821,
|
|
336
|
+
"&": 1366,
|
|
337
|
+
"'": 391,
|
|
338
|
+
"(": 682,
|
|
339
|
+
")": 682,
|
|
340
|
+
"*": 797,
|
|
341
|
+
"+": 1196,
|
|
342
|
+
",": 569,
|
|
343
|
+
"-": 682,
|
|
344
|
+
".": 569,
|
|
345
|
+
"/": 569,
|
|
346
|
+
"0": 1139,
|
|
347
|
+
"1": 1139,
|
|
348
|
+
"2": 1139,
|
|
349
|
+
"3": 1139,
|
|
350
|
+
"4": 1139,
|
|
351
|
+
"5": 1139,
|
|
352
|
+
"6": 1139,
|
|
353
|
+
"7": 1139,
|
|
354
|
+
"8": 1139,
|
|
355
|
+
"9": 1139,
|
|
356
|
+
":": 569,
|
|
357
|
+
";": 569,
|
|
358
|
+
"<": 1196,
|
|
359
|
+
"=": 1196,
|
|
360
|
+
">": 1196,
|
|
361
|
+
"?": 1139,
|
|
362
|
+
"@": 2079,
|
|
363
|
+
"A": 1366,
|
|
364
|
+
"B": 1366,
|
|
365
|
+
"C": 1479,
|
|
366
|
+
"D": 1479,
|
|
367
|
+
"E": 1366,
|
|
368
|
+
"F": 1251,
|
|
369
|
+
"G": 1593,
|
|
370
|
+
"H": 1479,
|
|
371
|
+
"I": 569,
|
|
372
|
+
"J": 1024,
|
|
373
|
+
"K": 1366,
|
|
374
|
+
"L": 1139,
|
|
375
|
+
"M": 1706,
|
|
376
|
+
"N": 1479,
|
|
377
|
+
"O": 1593,
|
|
378
|
+
"P": 1366,
|
|
379
|
+
"Q": 1593,
|
|
380
|
+
"R": 1479,
|
|
381
|
+
"S": 1366,
|
|
382
|
+
"T": 1251,
|
|
383
|
+
"U": 1479,
|
|
384
|
+
"V": 1366,
|
|
385
|
+
"W": 1933,
|
|
386
|
+
"X": 1366,
|
|
387
|
+
"Y": 1366,
|
|
388
|
+
"Z": 1251,
|
|
389
|
+
"[": 569,
|
|
390
|
+
"\\": 569,
|
|
391
|
+
"]": 569,
|
|
392
|
+
"^": 961,
|
|
393
|
+
"_": 1139,
|
|
394
|
+
"`": 682,
|
|
395
|
+
"a": 1139,
|
|
396
|
+
"b": 1139,
|
|
397
|
+
"c": 1024,
|
|
398
|
+
"d": 1139,
|
|
399
|
+
"e": 1139,
|
|
400
|
+
"f": 569,
|
|
401
|
+
"g": 1139,
|
|
402
|
+
"h": 1139,
|
|
403
|
+
"i": 455,
|
|
404
|
+
"j": 455,
|
|
405
|
+
"k": 1024,
|
|
406
|
+
"l": 455,
|
|
407
|
+
"m": 1706,
|
|
408
|
+
"n": 1139,
|
|
409
|
+
"o": 1139,
|
|
410
|
+
"p": 1139,
|
|
411
|
+
"q": 1139,
|
|
412
|
+
"r": 682,
|
|
413
|
+
"s": 1024,
|
|
414
|
+
"t": 569,
|
|
415
|
+
"u": 1139,
|
|
416
|
+
"v": 1024,
|
|
417
|
+
"w": 1479,
|
|
418
|
+
"x": 1024,
|
|
419
|
+
"y": 1024,
|
|
420
|
+
"z": 1024,
|
|
421
|
+
"{": 684,
|
|
422
|
+
"|": 532,
|
|
423
|
+
"}": 684,
|
|
424
|
+
"~": 1196,
|
|
425
|
+
"\xA0": 569,
|
|
426
|
+
"\xA1": 682,
|
|
427
|
+
"\xA2": 1139,
|
|
428
|
+
"\xA3": 1139,
|
|
429
|
+
"\xA4": 1139,
|
|
430
|
+
"\xA5": 1139,
|
|
431
|
+
"\xA6": 532,
|
|
432
|
+
"\xA7": 1139,
|
|
433
|
+
"\xA8": 682,
|
|
434
|
+
"\xA9": 1509,
|
|
435
|
+
"\xAA": 758,
|
|
436
|
+
"\xAB": 1139,
|
|
437
|
+
"\xAC": 1196,
|
|
438
|
+
"\xAD": 682,
|
|
439
|
+
"\xAE": 1509,
|
|
440
|
+
"\xAF": 1131,
|
|
441
|
+
"\xB0": 819,
|
|
442
|
+
"\xB1": 1124,
|
|
443
|
+
"\xB2": 682,
|
|
444
|
+
"\xB3": 682,
|
|
445
|
+
"\xB4": 682,
|
|
446
|
+
"\xB5": 1180,
|
|
447
|
+
"\xB6": 1100,
|
|
448
|
+
"\xB7": 682,
|
|
449
|
+
"\xB8": 682,
|
|
450
|
+
"\xB9": 682,
|
|
451
|
+
"\xBA": 748,
|
|
452
|
+
"\xBB": 1139,
|
|
453
|
+
"\xBC": 1708,
|
|
454
|
+
"\xBD": 1708,
|
|
455
|
+
"\xBE": 1708,
|
|
456
|
+
"\xBF": 1251,
|
|
457
|
+
"\xC0": 1366,
|
|
458
|
+
"\xC1": 1366,
|
|
459
|
+
"\xC2": 1366,
|
|
460
|
+
"\xC3": 1366,
|
|
461
|
+
"\xC4": 1366,
|
|
462
|
+
"\xC5": 1366,
|
|
463
|
+
"\xC6": 2048,
|
|
464
|
+
"\xC7": 1479,
|
|
465
|
+
"\xC8": 1366,
|
|
466
|
+
"\xC9": 1366,
|
|
467
|
+
"\xCA": 1366,
|
|
468
|
+
"\xCB": 1366,
|
|
469
|
+
"\xCC": 569,
|
|
470
|
+
"\xCD": 569,
|
|
471
|
+
"\xCE": 569,
|
|
472
|
+
"\xCF": 569,
|
|
473
|
+
"\xD0": 1479,
|
|
474
|
+
"\xD1": 1479,
|
|
475
|
+
"\xD2": 1593,
|
|
476
|
+
"\xD3": 1593,
|
|
477
|
+
"\xD4": 1593,
|
|
478
|
+
"\xD5": 1593,
|
|
479
|
+
"\xD6": 1593,
|
|
480
|
+
"\xD7": 1196,
|
|
481
|
+
"\xD8": 1593,
|
|
482
|
+
"\xD9": 1479,
|
|
483
|
+
"\xDA": 1479,
|
|
484
|
+
"\xDB": 1479,
|
|
485
|
+
"\xDC": 1479,
|
|
486
|
+
"\xDD": 1366,
|
|
487
|
+
"\xDE": 1366,
|
|
488
|
+
"\xDF": 1251,
|
|
489
|
+
"\xE0": 1139,
|
|
490
|
+
"\xE1": 1139,
|
|
491
|
+
"\xE2": 1139,
|
|
492
|
+
"\xE3": 1139,
|
|
493
|
+
"\xE4": 1139,
|
|
494
|
+
"\xE5": 1139,
|
|
495
|
+
"\xE6": 1821,
|
|
496
|
+
"\xE7": 1024,
|
|
497
|
+
"\xE8": 1139,
|
|
498
|
+
"\xE9": 1139,
|
|
499
|
+
"\xEA": 1139,
|
|
500
|
+
"\xEB": 1139,
|
|
501
|
+
"\xEC": 569,
|
|
502
|
+
"\xED": 569,
|
|
503
|
+
"\xEE": 569,
|
|
504
|
+
"\xEF": 569,
|
|
505
|
+
"\xF0": 1139,
|
|
506
|
+
"\xF1": 1139,
|
|
507
|
+
"\xF2": 1139,
|
|
508
|
+
"\xF3": 1139,
|
|
509
|
+
"\xF4": 1139,
|
|
510
|
+
"\xF5": 1139,
|
|
511
|
+
"\xF6": 1139,
|
|
512
|
+
"\xF7": 1124,
|
|
513
|
+
"\xF8": 1251,
|
|
514
|
+
"\xF9": 1139,
|
|
515
|
+
"\xFA": 1139,
|
|
516
|
+
"\xFB": 1139,
|
|
517
|
+
"\xFC": 1139,
|
|
518
|
+
"\xFD": 1024,
|
|
519
|
+
"\xFE": 1139,
|
|
520
|
+
"\xFF": 1024
|
|
521
|
+
}
|
|
522
|
+
},
|
|
523
|
+
LiberationSerif: {
|
|
524
|
+
unitsPerEm: 2048,
|
|
525
|
+
ascender: 1825,
|
|
526
|
+
descender: -443,
|
|
527
|
+
defaultWidth: 1056,
|
|
528
|
+
cjkWidth: 2048,
|
|
529
|
+
widths: {
|
|
530
|
+
" ": 512,
|
|
531
|
+
"!": 682,
|
|
532
|
+
'"': 836,
|
|
533
|
+
"#": 1024,
|
|
534
|
+
"$": 1024,
|
|
535
|
+
"%": 1706,
|
|
536
|
+
"&": 1593,
|
|
537
|
+
"'": 369,
|
|
538
|
+
"(": 682,
|
|
539
|
+
")": 682,
|
|
540
|
+
"*": 1024,
|
|
541
|
+
"+": 1155,
|
|
542
|
+
",": 512,
|
|
543
|
+
"-": 682,
|
|
544
|
+
".": 512,
|
|
545
|
+
"/": 569,
|
|
546
|
+
"0": 1024,
|
|
547
|
+
"1": 1024,
|
|
548
|
+
"2": 1024,
|
|
549
|
+
"3": 1024,
|
|
550
|
+
"4": 1024,
|
|
551
|
+
"5": 1024,
|
|
552
|
+
"6": 1024,
|
|
553
|
+
"7": 1024,
|
|
554
|
+
"8": 1024,
|
|
555
|
+
"9": 1024,
|
|
556
|
+
":": 569,
|
|
557
|
+
";": 569,
|
|
558
|
+
"<": 1155,
|
|
559
|
+
"=": 1155,
|
|
560
|
+
">": 1155,
|
|
561
|
+
"?": 909,
|
|
562
|
+
"@": 1886,
|
|
563
|
+
"A": 1479,
|
|
564
|
+
"B": 1366,
|
|
565
|
+
"C": 1366,
|
|
566
|
+
"D": 1479,
|
|
567
|
+
"E": 1251,
|
|
568
|
+
"F": 1139,
|
|
569
|
+
"G": 1479,
|
|
570
|
+
"H": 1479,
|
|
571
|
+
"I": 682,
|
|
572
|
+
"J": 797,
|
|
573
|
+
"K": 1479,
|
|
574
|
+
"L": 1251,
|
|
575
|
+
"M": 1821,
|
|
576
|
+
"N": 1479,
|
|
577
|
+
"O": 1479,
|
|
578
|
+
"P": 1139,
|
|
579
|
+
"Q": 1479,
|
|
580
|
+
"R": 1366,
|
|
581
|
+
"S": 1139,
|
|
582
|
+
"T": 1251,
|
|
583
|
+
"U": 1479,
|
|
584
|
+
"V": 1479,
|
|
585
|
+
"W": 1933,
|
|
586
|
+
"X": 1479,
|
|
587
|
+
"Y": 1479,
|
|
588
|
+
"Z": 1251,
|
|
589
|
+
"[": 682,
|
|
590
|
+
"\\": 569,
|
|
591
|
+
"]": 682,
|
|
592
|
+
"^": 961,
|
|
593
|
+
"_": 1024,
|
|
594
|
+
"`": 682,
|
|
595
|
+
"a": 909,
|
|
596
|
+
"b": 1024,
|
|
597
|
+
"c": 909,
|
|
598
|
+
"d": 1024,
|
|
599
|
+
"e": 909,
|
|
600
|
+
"f": 682,
|
|
601
|
+
"g": 1024,
|
|
602
|
+
"h": 1024,
|
|
603
|
+
"i": 569,
|
|
604
|
+
"j": 569,
|
|
605
|
+
"k": 1024,
|
|
606
|
+
"l": 569,
|
|
607
|
+
"m": 1593,
|
|
608
|
+
"n": 1024,
|
|
609
|
+
"o": 1024,
|
|
610
|
+
"p": 1024,
|
|
611
|
+
"q": 1024,
|
|
612
|
+
"r": 682,
|
|
613
|
+
"s": 797,
|
|
614
|
+
"t": 569,
|
|
615
|
+
"u": 1024,
|
|
616
|
+
"v": 1024,
|
|
617
|
+
"w": 1479,
|
|
618
|
+
"x": 1024,
|
|
619
|
+
"y": 1024,
|
|
620
|
+
"z": 909,
|
|
621
|
+
"{": 983,
|
|
622
|
+
"|": 410,
|
|
623
|
+
"}": 983,
|
|
624
|
+
"~": 1108,
|
|
625
|
+
"\xA0": 512,
|
|
626
|
+
"\xA1": 682,
|
|
627
|
+
"\xA2": 1024,
|
|
628
|
+
"\xA3": 1024,
|
|
629
|
+
"\xA4": 1024,
|
|
630
|
+
"\xA5": 1024,
|
|
631
|
+
"\xA6": 410,
|
|
632
|
+
"\xA7": 1024,
|
|
633
|
+
"\xA8": 682,
|
|
634
|
+
"\xA9": 1556,
|
|
635
|
+
"\xAA": 565,
|
|
636
|
+
"\xAB": 1024,
|
|
637
|
+
"\xAC": 1155,
|
|
638
|
+
"\xAD": 682,
|
|
639
|
+
"\xAE": 1556,
|
|
640
|
+
"\xAF": 1024,
|
|
641
|
+
"\xB0": 819,
|
|
642
|
+
"\xB1": 1124,
|
|
643
|
+
"\xB2": 614,
|
|
644
|
+
"\xB3": 614,
|
|
645
|
+
"\xB4": 682,
|
|
646
|
+
"\xB5": 1180,
|
|
647
|
+
"\xB6": 928,
|
|
648
|
+
"\xB7": 682,
|
|
649
|
+
"\xB8": 682,
|
|
650
|
+
"\xB9": 614,
|
|
651
|
+
"\xBA": 635,
|
|
652
|
+
"\xBB": 1024,
|
|
653
|
+
"\xBC": 1536,
|
|
654
|
+
"\xBD": 1536,
|
|
655
|
+
"\xBE": 1536,
|
|
656
|
+
"\xBF": 909,
|
|
657
|
+
"\xC0": 1479,
|
|
658
|
+
"\xC1": 1479,
|
|
659
|
+
"\xC2": 1479,
|
|
660
|
+
"\xC3": 1479,
|
|
661
|
+
"\xC4": 1479,
|
|
662
|
+
"\xC5": 1479,
|
|
663
|
+
"\xC6": 1821,
|
|
664
|
+
"\xC7": 1366,
|
|
665
|
+
"\xC8": 1251,
|
|
666
|
+
"\xC9": 1251,
|
|
667
|
+
"\xCA": 1251,
|
|
668
|
+
"\xCB": 1251,
|
|
669
|
+
"\xCC": 682,
|
|
670
|
+
"\xCD": 682,
|
|
671
|
+
"\xCE": 682,
|
|
672
|
+
"\xCF": 682,
|
|
673
|
+
"\xD0": 1479,
|
|
674
|
+
"\xD1": 1479,
|
|
675
|
+
"\xD2": 1479,
|
|
676
|
+
"\xD3": 1479,
|
|
677
|
+
"\xD4": 1479,
|
|
678
|
+
"\xD5": 1479,
|
|
679
|
+
"\xD6": 1479,
|
|
680
|
+
"\xD7": 1155,
|
|
681
|
+
"\xD8": 1479,
|
|
682
|
+
"\xD9": 1479,
|
|
683
|
+
"\xDA": 1479,
|
|
684
|
+
"\xDB": 1479,
|
|
685
|
+
"\xDC": 1479,
|
|
686
|
+
"\xDD": 1479,
|
|
687
|
+
"\xDE": 1139,
|
|
688
|
+
"\xDF": 1024,
|
|
689
|
+
"\xE0": 909,
|
|
690
|
+
"\xE1": 909,
|
|
691
|
+
"\xE2": 909,
|
|
692
|
+
"\xE3": 909,
|
|
693
|
+
"\xE4": 909,
|
|
694
|
+
"\xE5": 909,
|
|
695
|
+
"\xE6": 1366,
|
|
696
|
+
"\xE7": 909,
|
|
697
|
+
"\xE8": 909,
|
|
698
|
+
"\xE9": 909,
|
|
699
|
+
"\xEA": 909,
|
|
700
|
+
"\xEB": 909,
|
|
701
|
+
"\xEC": 569,
|
|
702
|
+
"\xED": 569,
|
|
703
|
+
"\xEE": 569,
|
|
704
|
+
"\xEF": 569,
|
|
705
|
+
"\xF0": 1024,
|
|
706
|
+
"\xF1": 1024,
|
|
707
|
+
"\xF2": 1024,
|
|
708
|
+
"\xF3": 1024,
|
|
709
|
+
"\xF4": 1024,
|
|
710
|
+
"\xF5": 1024,
|
|
711
|
+
"\xF6": 1024,
|
|
712
|
+
"\xF7": 1124,
|
|
713
|
+
"\xF8": 1024,
|
|
714
|
+
"\xF9": 1024,
|
|
715
|
+
"\xFA": 1024,
|
|
716
|
+
"\xFB": 1024,
|
|
717
|
+
"\xFC": 1024,
|
|
718
|
+
"\xFD": 1024,
|
|
719
|
+
"\xFE": 1024,
|
|
720
|
+
"\xFF": 1024
|
|
721
|
+
}
|
|
722
|
+
},
|
|
723
|
+
NotoSansJP: {
|
|
724
|
+
unitsPerEm: 1e3,
|
|
725
|
+
ascender: 1160,
|
|
726
|
+
descender: -288,
|
|
727
|
+
defaultWidth: 563,
|
|
728
|
+
cjkWidth: 1e3,
|
|
729
|
+
widths: {
|
|
730
|
+
" ": 224,
|
|
731
|
+
"!": 323,
|
|
732
|
+
'"': 474,
|
|
733
|
+
"#": 555,
|
|
734
|
+
"$": 555,
|
|
735
|
+
"%": 921,
|
|
736
|
+
"&": 680,
|
|
737
|
+
"'": 278,
|
|
738
|
+
"(": 338,
|
|
739
|
+
")": 338,
|
|
740
|
+
"*": 467,
|
|
741
|
+
"+": 555,
|
|
742
|
+
",": 278,
|
|
743
|
+
"-": 347,
|
|
744
|
+
".": 278,
|
|
745
|
+
"/": 392,
|
|
746
|
+
"0": 555,
|
|
747
|
+
"1": 555,
|
|
748
|
+
"2": 555,
|
|
749
|
+
"3": 555,
|
|
750
|
+
"4": 555,
|
|
751
|
+
"5": 555,
|
|
752
|
+
"6": 555,
|
|
753
|
+
"7": 555,
|
|
754
|
+
"8": 555,
|
|
755
|
+
"9": 555,
|
|
756
|
+
":": 278,
|
|
757
|
+
";": 278,
|
|
758
|
+
"<": 555,
|
|
759
|
+
"=": 555,
|
|
760
|
+
">": 555,
|
|
761
|
+
"?": 474,
|
|
762
|
+
"@": 946,
|
|
763
|
+
"A": 608,
|
|
764
|
+
"B": 657,
|
|
765
|
+
"C": 638,
|
|
766
|
+
"D": 688,
|
|
767
|
+
"E": 589,
|
|
768
|
+
"F": 552,
|
|
769
|
+
"G": 689,
|
|
770
|
+
"H": 728,
|
|
771
|
+
"I": 293,
|
|
772
|
+
"J": 535,
|
|
773
|
+
"K": 646,
|
|
774
|
+
"L": 543,
|
|
775
|
+
"M": 812,
|
|
776
|
+
"N": 723,
|
|
777
|
+
"O": 742,
|
|
778
|
+
"P": 633,
|
|
779
|
+
"Q": 742,
|
|
780
|
+
"R": 635,
|
|
781
|
+
"S": 596,
|
|
782
|
+
"T": 599,
|
|
783
|
+
"U": 721,
|
|
784
|
+
"V": 575,
|
|
785
|
+
"W": 878,
|
|
786
|
+
"X": 573,
|
|
787
|
+
"Y": 531,
|
|
788
|
+
"Z": 603,
|
|
789
|
+
"[": 338,
|
|
790
|
+
"\\": 392,
|
|
791
|
+
"]": 338,
|
|
792
|
+
"^": 555,
|
|
793
|
+
"_": 559,
|
|
794
|
+
"`": 606,
|
|
795
|
+
"a": 563,
|
|
796
|
+
"b": 618,
|
|
797
|
+
"c": 510,
|
|
798
|
+
"d": 620,
|
|
799
|
+
"e": 554,
|
|
800
|
+
"f": 325,
|
|
801
|
+
"g": 564,
|
|
802
|
+
"h": 607,
|
|
803
|
+
"i": 275,
|
|
804
|
+
"j": 275,
|
|
805
|
+
"k": 552,
|
|
806
|
+
"l": 284,
|
|
807
|
+
"m": 926,
|
|
808
|
+
"n": 610,
|
|
809
|
+
"o": 606,
|
|
810
|
+
"p": 620,
|
|
811
|
+
"q": 620,
|
|
812
|
+
"r": 388,
|
|
813
|
+
"s": 468,
|
|
814
|
+
"t": 377,
|
|
815
|
+
"u": 607,
|
|
816
|
+
"v": 521,
|
|
817
|
+
"w": 802,
|
|
818
|
+
"x": 498,
|
|
819
|
+
"y": 521,
|
|
820
|
+
"z": 475,
|
|
821
|
+
"{": 338,
|
|
822
|
+
"|": 270,
|
|
823
|
+
"}": 338,
|
|
824
|
+
"~": 555,
|
|
825
|
+
"\xA0": 224,
|
|
826
|
+
"\xA1": 323,
|
|
827
|
+
"\xA2": 555,
|
|
828
|
+
"\xA3": 555,
|
|
829
|
+
"\xA4": 555,
|
|
830
|
+
"\xA5": 555,
|
|
831
|
+
"\xA6": 270,
|
|
832
|
+
"\xA7": 1e3,
|
|
833
|
+
"\xA8": 606,
|
|
834
|
+
"\xA9": 832,
|
|
835
|
+
"\xAA": 386,
|
|
836
|
+
"\xAB": 479,
|
|
837
|
+
"\xAC": 555,
|
|
838
|
+
"\xAD": 347,
|
|
839
|
+
"\xAE": 473,
|
|
840
|
+
"\xAF": 606,
|
|
841
|
+
"\xB0": 370,
|
|
842
|
+
"\xB1": 1e3,
|
|
843
|
+
"\xB2": 411,
|
|
844
|
+
"\xB3": 411,
|
|
845
|
+
"\xB4": 606,
|
|
846
|
+
"\xB5": 628,
|
|
847
|
+
"\xB6": 1e3,
|
|
848
|
+
"\xB7": 561,
|
|
849
|
+
"\xB8": 606,
|
|
850
|
+
"\xB9": 411,
|
|
851
|
+
"\xBA": 407,
|
|
852
|
+
"\xBB": 479,
|
|
853
|
+
"\xBC": 873,
|
|
854
|
+
"\xBD": 903,
|
|
855
|
+
"\xBE": 889,
|
|
856
|
+
"\xBF": 474,
|
|
857
|
+
"\xC0": 608,
|
|
858
|
+
"\xC1": 608,
|
|
859
|
+
"\xC2": 608,
|
|
860
|
+
"\xC3": 608,
|
|
861
|
+
"\xC4": 608,
|
|
862
|
+
"\xC5": 608,
|
|
863
|
+
"\xC6": 918,
|
|
864
|
+
"\xC7": 638,
|
|
865
|
+
"\xC8": 589,
|
|
866
|
+
"\xC9": 589,
|
|
867
|
+
"\xCA": 589,
|
|
868
|
+
"\xCB": 589,
|
|
869
|
+
"\xCC": 293,
|
|
870
|
+
"\xCD": 293,
|
|
871
|
+
"\xCE": 293,
|
|
872
|
+
"\xCF": 293,
|
|
873
|
+
"\xD0": 712,
|
|
874
|
+
"\xD1": 723,
|
|
875
|
+
"\xD2": 742,
|
|
876
|
+
"\xD3": 742,
|
|
877
|
+
"\xD4": 742,
|
|
878
|
+
"\xD5": 742,
|
|
879
|
+
"\xD6": 742,
|
|
880
|
+
"\xD7": 1e3,
|
|
881
|
+
"\xD8": 742,
|
|
882
|
+
"\xD9": 721,
|
|
883
|
+
"\xDA": 721,
|
|
884
|
+
"\xDB": 721,
|
|
885
|
+
"\xDC": 721,
|
|
886
|
+
"\xDD": 531,
|
|
887
|
+
"\xDE": 652,
|
|
888
|
+
"\xDF": 643,
|
|
889
|
+
"\xE0": 563,
|
|
890
|
+
"\xE1": 563,
|
|
891
|
+
"\xE2": 563,
|
|
892
|
+
"\xE3": 563,
|
|
893
|
+
"\xE4": 563,
|
|
894
|
+
"\xE5": 563,
|
|
895
|
+
"\xE6": 877,
|
|
896
|
+
"\xE7": 510,
|
|
897
|
+
"\xE8": 554,
|
|
898
|
+
"\xE9": 554,
|
|
899
|
+
"\xEA": 554,
|
|
900
|
+
"\xEB": 554,
|
|
901
|
+
"\xEC": 275,
|
|
902
|
+
"\xED": 275,
|
|
903
|
+
"\xEE": 275,
|
|
904
|
+
"\xEF": 275,
|
|
905
|
+
"\xF0": 608,
|
|
906
|
+
"\xF1": 610,
|
|
907
|
+
"\xF2": 606,
|
|
908
|
+
"\xF3": 606,
|
|
909
|
+
"\xF4": 606,
|
|
910
|
+
"\xF5": 606,
|
|
911
|
+
"\xF6": 606,
|
|
912
|
+
"\xF7": 1e3,
|
|
913
|
+
"\xF8": 606,
|
|
914
|
+
"\xF9": 607,
|
|
915
|
+
"\xFA": 607,
|
|
916
|
+
"\xFB": 607,
|
|
917
|
+
"\xFC": 607,
|
|
918
|
+
"\xFD": 521,
|
|
919
|
+
"\xFE": 620,
|
|
920
|
+
"\xFF": 521
|
|
921
|
+
}
|
|
922
|
+
}
|
|
923
|
+
};
|
|
924
|
+
var fontNameMap = {
|
|
925
|
+
// Calibri -> Carlito
|
|
926
|
+
Calibri: "Carlito",
|
|
927
|
+
calibri: "Carlito",
|
|
928
|
+
// Arial / Helvetica -> Liberation Sans
|
|
929
|
+
Arial: "LiberationSans",
|
|
930
|
+
arial: "LiberationSans",
|
|
931
|
+
Helvetica: "LiberationSans",
|
|
932
|
+
helvetica: "LiberationSans",
|
|
933
|
+
// Times New Roman -> Liberation Serif
|
|
934
|
+
"Times New Roman": "LiberationSerif",
|
|
935
|
+
"times new roman": "LiberationSerif",
|
|
936
|
+
// Japanese fonts -> Noto Sans JP
|
|
937
|
+
"MS PGothic": "NotoSansJP",
|
|
938
|
+
"MS P\u30B4\u30B7\u30C3\u30AF": "NotoSansJP",
|
|
939
|
+
"MS Gothic": "NotoSansJP",
|
|
940
|
+
"MS \u30B4\u30B7\u30C3\u30AF": "NotoSansJP",
|
|
941
|
+
Meiryo: "NotoSansJP",
|
|
942
|
+
\u30E1\u30A4\u30EA\u30AA: "NotoSansJP",
|
|
943
|
+
"Yu Gothic": "NotoSansJP",
|
|
944
|
+
\u6E38\u30B4\u30B7\u30C3\u30AF: "NotoSansJP",
|
|
945
|
+
"Yu Mincho": "NotoSansJP",
|
|
946
|
+
\u6E38\u660E\u671D: "NotoSansJP",
|
|
947
|
+
"Hiragino Sans": "NotoSansJP",
|
|
948
|
+
"Hiragino Kaku Gothic ProN": "NotoSansJP",
|
|
949
|
+
"Noto Sans JP": "NotoSansJP",
|
|
950
|
+
"Noto Sans CJK JP": "NotoSansJP"
|
|
951
|
+
};
|
|
952
|
+
var metricsKeyToFontName = {
|
|
953
|
+
Carlito: "Carlito",
|
|
954
|
+
LiberationSans: "Liberation Sans",
|
|
955
|
+
LiberationSerif: "Liberation Serif",
|
|
956
|
+
NotoSansJP: "Noto Sans JP"
|
|
957
|
+
};
|
|
958
|
+
function getFontMetrics(fontFamily) {
|
|
959
|
+
if (!fontFamily) return null;
|
|
960
|
+
const key = fontNameMap[fontFamily] ?? fontNameMap[fontFamily.toLowerCase()];
|
|
961
|
+
if (!key) return null;
|
|
962
|
+
return metricsData[key] ?? null;
|
|
963
|
+
}
|
|
964
|
+
function getMetricsFallbackFont(fontFamily) {
|
|
965
|
+
if (!fontFamily) return null;
|
|
966
|
+
const key = fontNameMap[fontFamily] ?? fontNameMap[fontFamily.toLowerCase()];
|
|
967
|
+
if (!key) return null;
|
|
968
|
+
return metricsKeyToFontName[key] ?? null;
|
|
969
|
+
}
|
|
970
|
+
|
|
971
|
+
// ../renderer/src/utils/text-measure.ts
|
|
972
|
+
var WIDTH_RATIO = {
|
|
973
|
+
narrow: 0.3,
|
|
974
|
+
// i, l, 1, punctuation, etc.
|
|
975
|
+
normal: 0.6,
|
|
976
|
+
// average width of latin letters
|
|
977
|
+
wide: 1
|
|
978
|
+
// CJK characters (full-width)
|
|
979
|
+
};
|
|
980
|
+
var BOLD_FACTOR = 1.05;
|
|
981
|
+
var PX_PER_PT = 96 / 72;
|
|
982
|
+
var DEFAULT_LINE_HEIGHT_RATIO = 1.2;
|
|
983
|
+
var DEFAULT_ASCENDER_RATIO = 1;
|
|
984
|
+
function getLineHeightRatio(fontFamily, fontFamilyEa) {
|
|
985
|
+
const metrics = getFontMetrics(fontFamily) ?? getFontMetrics(fontFamilyEa);
|
|
986
|
+
if (!metrics) return DEFAULT_LINE_HEIGHT_RATIO;
|
|
987
|
+
return (metrics.ascender + Math.abs(metrics.descender)) / metrics.unitsPerEm;
|
|
988
|
+
}
|
|
989
|
+
function getAscenderRatio(fontFamily, fontFamilyEa) {
|
|
990
|
+
const metrics = getFontMetrics(fontFamily) ?? getFontMetrics(fontFamilyEa);
|
|
991
|
+
if (!metrics) return DEFAULT_ASCENDER_RATIO;
|
|
992
|
+
return metrics.ascender / metrics.unitsPerEm;
|
|
993
|
+
}
|
|
994
|
+
function isCjkCodePoint(codePoint) {
|
|
995
|
+
return codePoint >= 12288 && codePoint <= 40959 || // CJK symbols, hiragana, katakana, integrated kanji
|
|
996
|
+
codePoint >= 63744 && codePoint <= 64255 || // CJK compatible kanji
|
|
997
|
+
codePoint >= 65281 && codePoint <= 65376 || // Full-width alphanumeric characters/symbols
|
|
998
|
+
codePoint >= 131072 && codePoint <= 173791;
|
|
999
|
+
}
|
|
1000
|
+
function categorizeChar(codePoint) {
|
|
1001
|
+
if (isCjkCodePoint(codePoint)) {
|
|
1002
|
+
return "wide";
|
|
1003
|
+
}
|
|
1004
|
+
if (codePoint === 32 || // space
|
|
1005
|
+
codePoint === 33 || // !
|
|
1006
|
+
codePoint === 44 || // ,
|
|
1007
|
+
codePoint === 46 || // .
|
|
1008
|
+
codePoint === 58 || // :
|
|
1009
|
+
codePoint === 59 || // ;
|
|
1010
|
+
codePoint === 105 || // i
|
|
1011
|
+
codePoint === 106 || // j
|
|
1012
|
+
codePoint === 108 || // l
|
|
1013
|
+
codePoint === 49 || // 1
|
|
1014
|
+
codePoint === 124 || // |
|
|
1015
|
+
codePoint === 39 || // '
|
|
1016
|
+
codePoint === 40 || // (
|
|
1017
|
+
codePoint === 41 || // )
|
|
1018
|
+
codePoint === 91 || // [
|
|
1019
|
+
codePoint === 93 || // ]
|
|
1020
|
+
codePoint === 123 || // {
|
|
1021
|
+
codePoint === 125) {
|
|
1022
|
+
return "narrow";
|
|
1023
|
+
}
|
|
1024
|
+
return "normal";
|
|
1025
|
+
}
|
|
1026
|
+
function measureCharHeuristic(codePoint, baseSizePx) {
|
|
1027
|
+
return baseSizePx * WIDTH_RATIO[categorizeChar(codePoint)];
|
|
1028
|
+
}
|
|
1029
|
+
function measureCharMetrics(char, codePoint, baseSizePx, metrics) {
|
|
1030
|
+
const charWidth = metrics.widths[char];
|
|
1031
|
+
if (charWidth !== void 0) {
|
|
1032
|
+
return charWidth / metrics.unitsPerEm * baseSizePx;
|
|
1033
|
+
}
|
|
1034
|
+
if (isCjkCodePoint(codePoint)) {
|
|
1035
|
+
return metrics.cjkWidth / metrics.unitsPerEm * baseSizePx;
|
|
1036
|
+
}
|
|
1037
|
+
return metrics.defaultWidth / metrics.unitsPerEm * baseSizePx;
|
|
1038
|
+
}
|
|
1039
|
+
function measureTextWidth(text, fontSizePt, bold, fontFamily, fontFamilyEa) {
|
|
1040
|
+
const baseSizePx = fontSizePt * PX_PER_PT;
|
|
1041
|
+
const latinMetrics = getFontMetrics(fontFamily);
|
|
1042
|
+
const eaMetrics = getFontMetrics(fontFamilyEa);
|
|
1043
|
+
let totalWidth = 0;
|
|
1044
|
+
for (const char of text) {
|
|
1045
|
+
const codePoint = char.codePointAt(0);
|
|
1046
|
+
const isEa = isCjkCodePoint(codePoint);
|
|
1047
|
+
const metrics = isEa && eaMetrics ? eaMetrics : latinMetrics;
|
|
1048
|
+
let charWidth;
|
|
1049
|
+
if (metrics) {
|
|
1050
|
+
charWidth = measureCharMetrics(char, codePoint, baseSizePx, metrics);
|
|
1051
|
+
} else {
|
|
1052
|
+
charWidth = measureCharHeuristic(codePoint, baseSizePx);
|
|
1053
|
+
}
|
|
1054
|
+
if (bold && !isEa) {
|
|
1055
|
+
charWidth *= BOLD_FACTOR;
|
|
1056
|
+
}
|
|
1057
|
+
totalWidth += charWidth;
|
|
1058
|
+
}
|
|
1059
|
+
return totalWidth;
|
|
1060
|
+
}
|
|
1061
|
+
|
|
1062
|
+
// ../renderer/src/font/cjk-font-fallback.ts
|
|
1063
|
+
var MACOS_FALLBACKS = {
|
|
1064
|
+
// Gothic family
|
|
1065
|
+
"Noto Sans JP": ["Hiragino Sans", "Hiragino Kaku Gothic ProN"],
|
|
1066
|
+
"Noto Sans CJK JP": ["Hiragino Sans", "Hiragino Kaku Gothic ProN"],
|
|
1067
|
+
// Mincho family
|
|
1068
|
+
"Noto Serif CJK JP": ["Hiragino Mincho ProN"]
|
|
1069
|
+
};
|
|
1070
|
+
var WINDOWS_FALLBACKS = {
|
|
1071
|
+
// Gothic family
|
|
1072
|
+
"Noto Sans JP": ["Yu Gothic", "Meiryo", "MS Gothic"],
|
|
1073
|
+
"Noto Sans CJK JP": ["Yu Gothic", "Meiryo", "MS Gothic"],
|
|
1074
|
+
// Mincho family
|
|
1075
|
+
"Noto Serif CJK JP": ["Yu Mincho", "MS Mincho"]
|
|
1076
|
+
};
|
|
1077
|
+
var EMPTY = [];
|
|
1078
|
+
var cachedFallbacks = null;
|
|
1079
|
+
var platformOverrideForTest = null;
|
|
1080
|
+
function getRuntimePlatform() {
|
|
1081
|
+
if (platformOverrideForTest !== null) return platformOverrideForTest;
|
|
1082
|
+
return typeof process !== "undefined" ? process.platform : "";
|
|
1083
|
+
}
|
|
1084
|
+
function getFallbackMap() {
|
|
1085
|
+
if (cachedFallbacks) return cachedFallbacks;
|
|
1086
|
+
const os = getRuntimePlatform();
|
|
1087
|
+
if (os === "darwin") {
|
|
1088
|
+
cachedFallbacks = MACOS_FALLBACKS;
|
|
1089
|
+
} else if (os === "win32") {
|
|
1090
|
+
cachedFallbacks = WINDOWS_FALLBACKS;
|
|
1091
|
+
} else {
|
|
1092
|
+
cachedFallbacks = {};
|
|
1093
|
+
}
|
|
1094
|
+
return cachedFallbacks;
|
|
1095
|
+
}
|
|
1096
|
+
function getCjkFallbackFonts(mappedFontName) {
|
|
1097
|
+
return getFallbackMap()[mappedFontName] ?? EMPTY;
|
|
1098
|
+
}
|
|
1099
|
+
|
|
1100
|
+
// ../renderer/src/font/font-mapping-context.ts
|
|
1101
|
+
var currentMapping = { ...DEFAULT_FONT_MAPPING };
|
|
1102
|
+
function setFontMapping(mapping) {
|
|
1103
|
+
currentMapping = mapping;
|
|
1104
|
+
}
|
|
1105
|
+
function resetFontMapping() {
|
|
1106
|
+
currentMapping = { ...DEFAULT_FONT_MAPPING };
|
|
1107
|
+
}
|
|
1108
|
+
function getCurrentMappedFont(fontFamily) {
|
|
1109
|
+
return getMappedFont(fontFamily, currentMapping);
|
|
1110
|
+
}
|
|
1111
|
+
|
|
1112
|
+
// ../renderer/src/font/opentype-text-measurer.ts
|
|
1113
|
+
var PX_PER_PT2 = 96 / 72;
|
|
1114
|
+
var BOLD_FACTOR2 = 1.05;
|
|
1115
|
+
var OpentypeTextMeasurer = class {
|
|
1116
|
+
fonts;
|
|
1117
|
+
defaultFont;
|
|
1118
|
+
warnedFonts = /* @__PURE__ */ new Set();
|
|
1119
|
+
/**
|
|
1120
|
+
* @param fonts - font name -> opentype.js Map of Font objects
|
|
1121
|
+
* @param defaultFont - fallback font (optional)
|
|
1122
|
+
*/
|
|
1123
|
+
constructor(fonts, defaultFont) {
|
|
1124
|
+
this.fonts = fonts;
|
|
1125
|
+
this.defaultFont = defaultFont ?? null;
|
|
1126
|
+
}
|
|
1127
|
+
measureTextWidth(text, fontSizePt, bold, fontFamily, fontFamilyEa) {
|
|
1128
|
+
const latinFont = this.resolveFont(fontFamily);
|
|
1129
|
+
const eaFont = this.resolveFont(fontFamilyEa);
|
|
1130
|
+
const fallbackFont = latinFont ?? eaFont ?? this.defaultFont;
|
|
1131
|
+
if (!fallbackFont) {
|
|
1132
|
+
return measureTextWidth(text, fontSizePt, bold, fontFamily, fontFamilyEa);
|
|
1133
|
+
}
|
|
1134
|
+
const fontSizePx = fontSizePt * PX_PER_PT2;
|
|
1135
|
+
const latinFontResolved = latinFont ?? fallbackFont;
|
|
1136
|
+
const eaFontResolved = eaFont ?? fallbackFont;
|
|
1137
|
+
const boldLatinFont = bold ? this.resolveBoldFont(fontFamily) : null;
|
|
1138
|
+
const latinGlyphCache = /* @__PURE__ */ new Map();
|
|
1139
|
+
const eaGlyphCache = eaFontResolved !== latinFontResolved ? /* @__PURE__ */ new Map() : latinGlyphCache;
|
|
1140
|
+
const boldGlyphCache = /* @__PURE__ */ new Map();
|
|
1141
|
+
let totalWidth = 0;
|
|
1142
|
+
for (const char of text) {
|
|
1143
|
+
const codePoint = char.codePointAt(0);
|
|
1144
|
+
const isEa = isCjkCodePoint(codePoint);
|
|
1145
|
+
const font = isEa ? eaFontResolved : latinFontResolved;
|
|
1146
|
+
const cache = isEa ? eaGlyphCache : latinGlyphCache;
|
|
1147
|
+
if (!cache.has(char)) {
|
|
1148
|
+
cache.set(char, font.stringToGlyphs(char)[0]);
|
|
1149
|
+
}
|
|
1150
|
+
const scale = fontSizePx / font.unitsPerEm;
|
|
1151
|
+
const glyph = cache.get(char);
|
|
1152
|
+
let charWidth = (glyph?.advanceWidth ?? font.unitsPerEm * 0.6) * scale;
|
|
1153
|
+
if (bold && !isEa) {
|
|
1154
|
+
if (boldLatinFont) {
|
|
1155
|
+
if (!boldGlyphCache.has(char)) {
|
|
1156
|
+
boldGlyphCache.set(char, boldLatinFont.stringToGlyphs(char)[0]);
|
|
1157
|
+
}
|
|
1158
|
+
const boldGlyph = boldGlyphCache.get(char);
|
|
1159
|
+
const boldScale = fontSizePx / boldLatinFont.unitsPerEm;
|
|
1160
|
+
charWidth = (boldGlyph?.advanceWidth ?? boldLatinFont.unitsPerEm * 0.6) * boldScale;
|
|
1161
|
+
} else {
|
|
1162
|
+
charWidth *= BOLD_FACTOR2;
|
|
1163
|
+
}
|
|
1164
|
+
}
|
|
1165
|
+
totalWidth += charWidth;
|
|
1166
|
+
}
|
|
1167
|
+
return totalWidth;
|
|
1168
|
+
}
|
|
1169
|
+
getLineHeightRatio(fontFamily, fontFamilyEa) {
|
|
1170
|
+
const font = this.resolveFont(fontFamily) ?? this.resolveFont(fontFamilyEa) ?? this.defaultFont;
|
|
1171
|
+
if (!font) return 1.2;
|
|
1172
|
+
return (font.ascender + Math.abs(font.descender)) / font.unitsPerEm;
|
|
1173
|
+
}
|
|
1174
|
+
getAscenderRatio(fontFamily, fontFamilyEa) {
|
|
1175
|
+
const font = this.resolveFont(fontFamily) ?? this.resolveFont(fontFamilyEa) ?? this.defaultFont;
|
|
1176
|
+
if (!font) return 1;
|
|
1177
|
+
return font.ascender / font.unitsPerEm;
|
|
1178
|
+
}
|
|
1179
|
+
resolveBoldFont(name) {
|
|
1180
|
+
if (!name) return null;
|
|
1181
|
+
const bases = [name];
|
|
1182
|
+
const mappedBase = getCurrentMappedFont(name);
|
|
1183
|
+
if (mappedBase && mappedBase !== name) bases.push(mappedBase);
|
|
1184
|
+
for (const base of bases) {
|
|
1185
|
+
for (const boldName of [`${base} Bold`, `${base}-Bold`]) {
|
|
1186
|
+
const direct = this.fonts.get(boldName);
|
|
1187
|
+
if (direct) return direct;
|
|
1188
|
+
const mapped = getCurrentMappedFont(boldName);
|
|
1189
|
+
if (mapped) {
|
|
1190
|
+
const mappedFont = this.fonts.get(mapped);
|
|
1191
|
+
if (mappedFont) return mappedFont;
|
|
1192
|
+
}
|
|
1193
|
+
}
|
|
1194
|
+
}
|
|
1195
|
+
return null;
|
|
1196
|
+
}
|
|
1197
|
+
resolveFont(name) {
|
|
1198
|
+
if (!name) return null;
|
|
1199
|
+
const direct = this.fonts.get(name);
|
|
1200
|
+
if (direct) return direct;
|
|
1201
|
+
const mapped = getCurrentMappedFont(name);
|
|
1202
|
+
if (mapped) {
|
|
1203
|
+
const mappedFont = this.fonts.get(mapped);
|
|
1204
|
+
if (mappedFont) return mappedFont;
|
|
1205
|
+
for (const fallback of getCjkFallbackFonts(mapped)) {
|
|
1206
|
+
const fallbackFont = this.fonts.get(fallback);
|
|
1207
|
+
if (fallbackFont) return fallbackFont;
|
|
1208
|
+
}
|
|
1209
|
+
}
|
|
1210
|
+
if (!this.warnedFonts.has(name)) {
|
|
1211
|
+
this.warnedFonts.add(name);
|
|
1212
|
+
warn("font.notFound", `Font not found: "${name}"`);
|
|
1213
|
+
}
|
|
1214
|
+
return null;
|
|
1215
|
+
}
|
|
1216
|
+
};
|
|
1217
|
+
|
|
1218
|
+
// ../renderer/src/font/text-path-context.ts
|
|
1219
|
+
var DefaultTextPathFontResolver = class {
|
|
1220
|
+
fonts;
|
|
1221
|
+
defaultFont;
|
|
1222
|
+
warnedFonts = /* @__PURE__ */ new Set();
|
|
1223
|
+
constructor(fonts, defaultFont) {
|
|
1224
|
+
this.fonts = fonts;
|
|
1225
|
+
this.defaultFont = defaultFont ?? null;
|
|
1226
|
+
}
|
|
1227
|
+
resolveFont(fontFamily, fontFamilyEa, jpanFallback) {
|
|
1228
|
+
if (fontFamily) {
|
|
1229
|
+
const font = this.findFont(fontFamily);
|
|
1230
|
+
if (font) return font;
|
|
1231
|
+
}
|
|
1232
|
+
if (fontFamilyEa) {
|
|
1233
|
+
const font = this.findFont(fontFamilyEa);
|
|
1234
|
+
if (font) return font;
|
|
1235
|
+
}
|
|
1236
|
+
if (jpanFallback) {
|
|
1237
|
+
const font = this.findFont(jpanFallback);
|
|
1238
|
+
if (font) return font;
|
|
1239
|
+
}
|
|
1240
|
+
for (const name of [fontFamily, fontFamilyEa, jpanFallback]) {
|
|
1241
|
+
if (name && !this.warnedFonts.has(name)) {
|
|
1242
|
+
this.warnedFonts.add(name);
|
|
1243
|
+
warn("font.notFound", `Font not found: "${name}"`);
|
|
1244
|
+
}
|
|
1245
|
+
}
|
|
1246
|
+
return this.defaultFont;
|
|
1247
|
+
}
|
|
1248
|
+
findFont(name) {
|
|
1249
|
+
const direct = this.fonts.get(name);
|
|
1250
|
+
if (direct) return direct;
|
|
1251
|
+
const mapped = getCurrentMappedFont(name);
|
|
1252
|
+
if (mapped) {
|
|
1253
|
+
const mappedFont = this.fonts.get(mapped);
|
|
1254
|
+
if (mappedFont) return mappedFont;
|
|
1255
|
+
for (const fallback of getCjkFallbackFonts(mapped)) {
|
|
1256
|
+
const fallbackFont = this.fonts.get(fallback);
|
|
1257
|
+
if (fallbackFont) return fallbackFont;
|
|
1258
|
+
}
|
|
1259
|
+
}
|
|
1260
|
+
return null;
|
|
1261
|
+
}
|
|
1262
|
+
};
|
|
1263
|
+
var currentResolver = null;
|
|
1264
|
+
function setTextPathFontResolver(resolver) {
|
|
1265
|
+
currentResolver = resolver;
|
|
1266
|
+
}
|
|
1267
|
+
function getTextPathFontResolver() {
|
|
1268
|
+
return currentResolver;
|
|
1269
|
+
}
|
|
1270
|
+
function resetTextPathFontResolver() {
|
|
1271
|
+
currentResolver = null;
|
|
1272
|
+
}
|
|
1273
|
+
|
|
1274
|
+
// ../renderer/src/font/ttc-parser.ts
|
|
1275
|
+
var TTC_TAG = 1953784678;
|
|
1276
|
+
function isTtcBuffer(data) {
|
|
1277
|
+
const view = toDataView(data);
|
|
1278
|
+
if (view.byteLength < 4) return false;
|
|
1279
|
+
return view.getUint32(0) === TTC_TAG;
|
|
1280
|
+
}
|
|
1281
|
+
function extractTtcFonts(data) {
|
|
1282
|
+
const view = toDataView(data);
|
|
1283
|
+
const bytes = toUint8Array(data);
|
|
1284
|
+
if (view.byteLength < 12) return [];
|
|
1285
|
+
if (view.getUint32(0) !== TTC_TAG) return [];
|
|
1286
|
+
const numFonts = view.getUint32(8);
|
|
1287
|
+
if (numFonts === 0) return [];
|
|
1288
|
+
const headerEnd = 12 + numFonts * 4;
|
|
1289
|
+
if (view.byteLength < headerEnd) return [];
|
|
1290
|
+
const results = [];
|
|
1291
|
+
for (let i = 0; i < numFonts; i++) {
|
|
1292
|
+
try {
|
|
1293
|
+
const fontOffset = view.getUint32(12 + i * 4);
|
|
1294
|
+
const extracted = extractSingleFont(view, bytes, fontOffset);
|
|
1295
|
+
if (extracted) results.push(extracted);
|
|
1296
|
+
} catch {
|
|
1297
|
+
}
|
|
1298
|
+
}
|
|
1299
|
+
return results;
|
|
1300
|
+
}
|
|
1301
|
+
function extractSingleFont(view, bytes, fontOffset) {
|
|
1302
|
+
if (fontOffset + 12 > view.byteLength) return null;
|
|
1303
|
+
const sfVersion = view.getUint32(fontOffset);
|
|
1304
|
+
const numTables = view.getUint16(fontOffset + 4);
|
|
1305
|
+
if (numTables === 0) return null;
|
|
1306
|
+
const tableRecordsStart = fontOffset + 12;
|
|
1307
|
+
const tableRecordsEnd = tableRecordsStart + numTables * 16;
|
|
1308
|
+
if (tableRecordsEnd > view.byteLength) return null;
|
|
1309
|
+
const tables = [];
|
|
1310
|
+
for (let i = 0; i < numTables; i++) {
|
|
1311
|
+
const recOffset = tableRecordsStart + i * 16;
|
|
1312
|
+
const tableOffset = view.getUint32(recOffset + 8);
|
|
1313
|
+
const tableLength = view.getUint32(recOffset + 12);
|
|
1314
|
+
if (tableOffset > view.byteLength || tableLength > view.byteLength - tableOffset) {
|
|
1315
|
+
return null;
|
|
1316
|
+
}
|
|
1317
|
+
tables.push({
|
|
1318
|
+
tag: view.getUint32(recOffset),
|
|
1319
|
+
checkSum: view.getUint32(recOffset + 4),
|
|
1320
|
+
offset: tableOffset,
|
|
1321
|
+
length: tableLength
|
|
1322
|
+
});
|
|
1323
|
+
}
|
|
1324
|
+
const headerSize = 12 + numTables * 16;
|
|
1325
|
+
let dataSize = 0;
|
|
1326
|
+
for (const table of tables) {
|
|
1327
|
+
dataSize += alignTo4(table.length);
|
|
1328
|
+
}
|
|
1329
|
+
const totalSize = headerSize + dataSize;
|
|
1330
|
+
const output = new ArrayBuffer(totalSize);
|
|
1331
|
+
const outView = new DataView(output);
|
|
1332
|
+
const outBytes = new Uint8Array(output);
|
|
1333
|
+
outView.setUint32(0, sfVersion);
|
|
1334
|
+
outView.setUint16(4, numTables);
|
|
1335
|
+
const { searchRange, entrySelector, rangeShift } = calcOffsetTableFields(numTables);
|
|
1336
|
+
outView.setUint16(6, searchRange);
|
|
1337
|
+
outView.setUint16(8, entrySelector);
|
|
1338
|
+
outView.setUint16(10, rangeShift);
|
|
1339
|
+
let currentDataOffset = headerSize;
|
|
1340
|
+
for (let i = 0; i < numTables; i++) {
|
|
1341
|
+
const table = tables[i];
|
|
1342
|
+
const recOffset = 12 + i * 16;
|
|
1343
|
+
outView.setUint32(recOffset, table.tag);
|
|
1344
|
+
outView.setUint32(recOffset + 4, table.checkSum);
|
|
1345
|
+
outView.setUint32(recOffset + 8, currentDataOffset);
|
|
1346
|
+
outView.setUint32(recOffset + 12, table.length);
|
|
1347
|
+
outBytes.set(bytes.subarray(table.offset, table.offset + table.length), currentDataOffset);
|
|
1348
|
+
currentDataOffset += alignTo4(table.length);
|
|
1349
|
+
}
|
|
1350
|
+
return output;
|
|
1351
|
+
}
|
|
1352
|
+
function alignTo4(n) {
|
|
1353
|
+
return n + 3 & ~3;
|
|
1354
|
+
}
|
|
1355
|
+
function calcOffsetTableFields(numTables) {
|
|
1356
|
+
let searchRange = 16;
|
|
1357
|
+
let entrySelector = 0;
|
|
1358
|
+
while (searchRange * 2 <= numTables * 16) {
|
|
1359
|
+
searchRange *= 2;
|
|
1360
|
+
entrySelector++;
|
|
1361
|
+
}
|
|
1362
|
+
const rangeShift = numTables * 16 - searchRange;
|
|
1363
|
+
return { searchRange, entrySelector, rangeShift };
|
|
1364
|
+
}
|
|
1365
|
+
function toDataView(data) {
|
|
1366
|
+
if (data instanceof Uint8Array) {
|
|
1367
|
+
return new DataView(data.buffer, data.byteOffset, data.byteLength);
|
|
1368
|
+
}
|
|
1369
|
+
return new DataView(data);
|
|
1370
|
+
}
|
|
1371
|
+
function toUint8Array(data) {
|
|
1372
|
+
if (data instanceof Uint8Array) return data;
|
|
1373
|
+
return new Uint8Array(data);
|
|
1374
|
+
}
|
|
1375
|
+
|
|
1376
|
+
// ../renderer/src/font/opentype-buffer-helpers.ts
|
|
1377
|
+
async function tryLoadOpentype() {
|
|
1378
|
+
try {
|
|
1379
|
+
const mod = await import("opentype.js");
|
|
1380
|
+
return {
|
|
1381
|
+
parse: (buffer) => unsafeExternalInteropAssertion(mod.parse(buffer))
|
|
1382
|
+
};
|
|
1383
|
+
} catch {
|
|
1384
|
+
return null;
|
|
1385
|
+
}
|
|
1386
|
+
}
|
|
1387
|
+
function buildReverseMapping(mapping) {
|
|
1388
|
+
const reverse = /* @__PURE__ */ new Map();
|
|
1389
|
+
for (const [pptxName, ossName] of Object.entries(mapping)) {
|
|
1390
|
+
const existing = reverse.get(ossName) ?? [];
|
|
1391
|
+
existing.push(pptxName);
|
|
1392
|
+
reverse.set(ossName, existing);
|
|
1393
|
+
}
|
|
1394
|
+
return reverse;
|
|
1395
|
+
}
|
|
1396
|
+
function toArrayBuffer(data) {
|
|
1397
|
+
if (data instanceof ArrayBuffer) return data;
|
|
1398
|
+
return unsafeExternalInteropAssertion(
|
|
1399
|
+
data.buffer.slice(data.byteOffset, data.byteOffset + data.byteLength)
|
|
1400
|
+
);
|
|
1401
|
+
}
|
|
1402
|
+
function parseFontBuffer(arrayBuffer, opentype) {
|
|
1403
|
+
if (isTtcBuffer(arrayBuffer)) {
|
|
1404
|
+
const fonts = extractTtcFonts(arrayBuffer);
|
|
1405
|
+
if (fonts.length > 0) {
|
|
1406
|
+
try {
|
|
1407
|
+
return [opentype.parse(fonts[0])];
|
|
1408
|
+
} catch {
|
|
1409
|
+
}
|
|
1410
|
+
}
|
|
1411
|
+
return [];
|
|
1412
|
+
}
|
|
1413
|
+
return [opentype.parse(arrayBuffer)];
|
|
1414
|
+
}
|
|
1415
|
+
function createOpentypeSetupState() {
|
|
1416
|
+
return {
|
|
1417
|
+
measurerFonts: /* @__PURE__ */ new Map(),
|
|
1418
|
+
resolverFonts: /* @__PURE__ */ new Map(),
|
|
1419
|
+
firstMeasurerFont: null,
|
|
1420
|
+
firstResolverFont: null
|
|
1421
|
+
};
|
|
1422
|
+
}
|
|
1423
|
+
function registerParsedFont(font, reverseMap, state, explicitName) {
|
|
1424
|
+
if (!state.firstMeasurerFont) state.firstMeasurerFont = font;
|
|
1425
|
+
if (!state.firstResolverFont)
|
|
1426
|
+
state.firstResolverFont = unsafeExternalInteropAssertion(font);
|
|
1427
|
+
if (explicitName) {
|
|
1428
|
+
registerFont(explicitName, font, reverseMap, state.measurerFonts, state.resolverFonts);
|
|
1429
|
+
}
|
|
1430
|
+
for (const name of collectFontNames(font)) {
|
|
1431
|
+
registerFont(name, font, reverseMap, state.measurerFonts, state.resolverFonts);
|
|
1432
|
+
}
|
|
1433
|
+
}
|
|
1434
|
+
function registerFont(name, font, reverseMap, measurerFonts, resolverFonts) {
|
|
1435
|
+
const fullFont = unsafeExternalInteropAssertion(font);
|
|
1436
|
+
if (!measurerFonts.has(name)) {
|
|
1437
|
+
measurerFonts.set(name, font);
|
|
1438
|
+
resolverFonts.set(name, fullFont);
|
|
1439
|
+
}
|
|
1440
|
+
const pptxNames = reverseMap.get(name);
|
|
1441
|
+
if (pptxNames) {
|
|
1442
|
+
for (const pptxName of pptxNames) {
|
|
1443
|
+
if (!measurerFonts.has(pptxName)) {
|
|
1444
|
+
measurerFonts.set(pptxName, font);
|
|
1445
|
+
resolverFonts.set(pptxName, fullFont);
|
|
1446
|
+
}
|
|
1447
|
+
}
|
|
1448
|
+
}
|
|
1449
|
+
}
|
|
1450
|
+
function collectFontNames(font) {
|
|
1451
|
+
const names = /* @__PURE__ */ new Set();
|
|
1452
|
+
if (font.names.fontFamily) {
|
|
1453
|
+
for (const name of Object.values(font.names.fontFamily)) {
|
|
1454
|
+
names.add(name);
|
|
1455
|
+
}
|
|
1456
|
+
}
|
|
1457
|
+
if (font.names.preferredFamily) {
|
|
1458
|
+
for (const name of Object.values(font.names.preferredFamily)) {
|
|
1459
|
+
names.add(name);
|
|
1460
|
+
}
|
|
1461
|
+
}
|
|
1462
|
+
return names;
|
|
1463
|
+
}
|
|
1464
|
+
function buildOpentypeSetupFromState(state) {
|
|
1465
|
+
if (state.measurerFonts.size === 0 && !state.firstMeasurerFont) return null;
|
|
1466
|
+
const measurer = new OpentypeTextMeasurer(
|
|
1467
|
+
state.measurerFonts,
|
|
1468
|
+
state.firstMeasurerFont ?? void 0
|
|
1469
|
+
);
|
|
1470
|
+
const fontResolver = new DefaultTextPathFontResolver(
|
|
1471
|
+
state.resolverFonts,
|
|
1472
|
+
state.firstResolverFont ?? void 0
|
|
1473
|
+
);
|
|
1474
|
+
return { measurer, fontResolver };
|
|
1475
|
+
}
|
|
1476
|
+
async function createOpentypeTextMeasurerFromBuffers(fontBuffers, fontMapping) {
|
|
1477
|
+
const setup = await createOpentypeSetupFromBuffers(fontBuffers, fontMapping);
|
|
1478
|
+
return setup?.measurer ?? null;
|
|
1479
|
+
}
|
|
1480
|
+
async function createOpentypeSetupFromBuffers(fontBuffers, fontMapping) {
|
|
1481
|
+
if (fontBuffers.length === 0) return null;
|
|
1482
|
+
const opentype = await tryLoadOpentype();
|
|
1483
|
+
if (!opentype) return null;
|
|
1484
|
+
const mapping = createFontMapping(fontMapping);
|
|
1485
|
+
const reverseMap = buildReverseMapping(mapping);
|
|
1486
|
+
const state = createOpentypeSetupState();
|
|
1487
|
+
for (const buffer of fontBuffers) {
|
|
1488
|
+
try {
|
|
1489
|
+
const arrayBuffer = toArrayBuffer(buffer.data);
|
|
1490
|
+
const fonts = parseFontBuffer(arrayBuffer, opentype);
|
|
1491
|
+
for (const font of fonts) {
|
|
1492
|
+
registerParsedFont(font, reverseMap, state, buffer.name);
|
|
1493
|
+
}
|
|
1494
|
+
} catch {
|
|
1495
|
+
}
|
|
1496
|
+
}
|
|
1497
|
+
return buildOpentypeSetupFromState(state);
|
|
1498
|
+
}
|
|
1499
|
+
var SYSTEM_FONT_CACHE_KEY = "__pptxGlimpseSystemFontCache__";
|
|
1500
|
+
function getSystemFontCacheStore() {
|
|
1501
|
+
const globalObject = globalThis;
|
|
1502
|
+
globalObject[SYSTEM_FONT_CACHE_KEY] ??= { setup: null, key: null };
|
|
1503
|
+
return globalObject[SYSTEM_FONT_CACHE_KEY];
|
|
1504
|
+
}
|
|
1505
|
+
function getCachedSystemOpentypeSetup(key) {
|
|
1506
|
+
const cache = getSystemFontCacheStore();
|
|
1507
|
+
return cache.key === key ? cache.setup : void 0;
|
|
1508
|
+
}
|
|
1509
|
+
function setCachedSystemOpentypeSetup(key, setup) {
|
|
1510
|
+
const cache = getSystemFontCacheStore();
|
|
1511
|
+
cache.setup = setup;
|
|
1512
|
+
cache.key = key;
|
|
1513
|
+
}
|
|
1514
|
+
function clearFontCache() {
|
|
1515
|
+
const cache = getSystemFontCacheStore();
|
|
1516
|
+
cache.setup = null;
|
|
1517
|
+
cache.key = null;
|
|
1518
|
+
}
|
|
1519
|
+
|
|
1520
|
+
export {
|
|
1521
|
+
getMetricsFallbackFont,
|
|
1522
|
+
unsafeExternalInteropAssertion,
|
|
1523
|
+
unsafeBrandAssertion,
|
|
1524
|
+
initWarningLogger,
|
|
1525
|
+
warn,
|
|
1526
|
+
debug,
|
|
1527
|
+
getWarningSummary,
|
|
1528
|
+
flushWarnings,
|
|
1529
|
+
getWarningEntries,
|
|
1530
|
+
DEFAULT_FONT_MAPPING,
|
|
1531
|
+
createFontMapping,
|
|
1532
|
+
getMappedFont,
|
|
1533
|
+
setFontMapping,
|
|
1534
|
+
resetFontMapping,
|
|
1535
|
+
getCurrentMappedFont,
|
|
1536
|
+
getLineHeightRatio,
|
|
1537
|
+
getAscenderRatio,
|
|
1538
|
+
measureTextWidth,
|
|
1539
|
+
setTextPathFontResolver,
|
|
1540
|
+
getTextPathFontResolver,
|
|
1541
|
+
resetTextPathFontResolver,
|
|
1542
|
+
tryLoadOpentype,
|
|
1543
|
+
buildReverseMapping,
|
|
1544
|
+
toArrayBuffer,
|
|
1545
|
+
parseFontBuffer,
|
|
1546
|
+
createOpentypeSetupState,
|
|
1547
|
+
registerParsedFont,
|
|
1548
|
+
buildOpentypeSetupFromState,
|
|
1549
|
+
createOpentypeTextMeasurerFromBuffers,
|
|
1550
|
+
createOpentypeSetupFromBuffers,
|
|
1551
|
+
getCachedSystemOpentypeSetup,
|
|
1552
|
+
setCachedSystemOpentypeSetup,
|
|
1553
|
+
clearFontCache
|
|
1554
|
+
};
|