pdf-codec 1.5.0 → 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +36 -3
- package/dist/assets/caladea-bold.cjs +5 -0
- package/dist/assets/caladea-bold.d.cts +4 -0
- package/dist/assets/caladea-bold.d.ts +4 -0
- package/dist/assets/caladea-bold.js +4 -0
- package/dist/assets/caladea-bolditalic.cjs +5 -0
- package/dist/assets/caladea-bolditalic.d.cts +4 -0
- package/dist/assets/caladea-bolditalic.d.ts +4 -0
- package/dist/assets/caladea-bolditalic.js +4 -0
- package/dist/assets/caladea-italic.cjs +5 -0
- package/dist/assets/caladea-italic.d.cts +4 -0
- package/dist/assets/caladea-italic.d.ts +4 -0
- package/dist/assets/caladea-italic.js +4 -0
- package/dist/assets/caladea-regular.cjs +5 -0
- package/dist/assets/caladea-regular.d.cts +4 -0
- package/dist/assets/caladea-regular.d.ts +4 -0
- package/dist/assets/caladea-regular.js +4 -0
- package/dist/assets/carlito-bold.cjs +5 -0
- package/dist/assets/carlito-bold.d.cts +4 -0
- package/dist/assets/carlito-bold.d.ts +4 -0
- package/dist/assets/carlito-bold.js +4 -0
- package/dist/assets/carlito-bolditalic.cjs +5 -0
- package/dist/assets/carlito-bolditalic.d.cts +4 -0
- package/dist/assets/carlito-bolditalic.d.ts +4 -0
- package/dist/assets/carlito-bolditalic.js +4 -0
- package/dist/assets/carlito-italic.cjs +5 -0
- package/dist/assets/carlito-italic.d.cts +4 -0
- package/dist/assets/carlito-italic.d.ts +4 -0
- package/dist/assets/carlito-italic.js +4 -0
- package/dist/assets/carlito-regular.cjs +5 -0
- package/dist/assets/carlito-regular.d.cts +4 -0
- package/dist/assets/carlito-regular.d.ts +4 -0
- package/dist/assets/carlito-regular.js +4 -0
- package/dist/cff-probe.cjs +133 -0
- package/dist/cff-probe.d.cts +10 -0
- package/dist/cff-probe.d.ts +10 -0
- package/dist/cff-probe.js +132 -0
- package/dist/cmap-table.cjs +108 -0
- package/dist/cmap-table.d.cts +6 -0
- package/dist/cmap-table.d.ts +6 -0
- package/dist/cmap-table.js +107 -0
- package/dist/content-write.cjs +34 -14
- package/dist/content-write.d.cts +9 -2
- package/dist/content-write.d.ts +9 -2
- package/dist/content-write.js +34 -14
- package/dist/embedded-font-CLedn-mT.d.cts +42 -0
- package/dist/embedded-font-CbqkKgBl.d.ts +42 -0
- package/dist/embedded-font-write.cjs +92 -0
- package/dist/embedded-font-write.d.cts +22 -0
- package/dist/embedded-font-write.d.ts +22 -0
- package/dist/embedded-font-write.js +90 -0
- package/dist/embedded-font.cjs +142 -0
- package/dist/embedded-font.d.cts +2 -0
- package/dist/embedded-font.d.ts +2 -0
- package/dist/embedded-font.js +138 -0
- package/dist/font-registry-Cn7P9lAh.d.ts +38 -0
- package/dist/font-registry-yby02snZ.d.cts +38 -0
- package/dist/font-registry.cjs +152 -0
- package/dist/font-registry.d.cts +2 -0
- package/dist/font-registry.d.ts +2 -0
- package/dist/font-registry.js +150 -0
- package/dist/font-substitutes.cjs +13 -0
- package/dist/font-substitutes.d.cts +5 -0
- package/dist/font-substitutes.d.ts +5 -0
- package/dist/font-substitutes.js +12 -0
- package/dist/font-tables.cjs +127 -0
- package/dist/font-tables.d.cts +43 -0
- package/dist/font-tables.d.ts +43 -0
- package/dist/font-tables.js +122 -0
- package/dist/fonts.cjs +1 -0
- package/dist/fonts.d.cts +2 -1
- package/dist/fonts.d.ts +2 -1
- package/dist/fonts.js +1 -1
- package/dist/glyf.cjs +127 -0
- package/dist/glyf.d.cts +31 -0
- package/dist/glyf.d.ts +31 -0
- package/dist/glyf.js +125 -0
- package/dist/{math-hmtx.cjs → hmtx-table.cjs} +3 -3
- package/dist/{math-hmtx.d.ts → hmtx-table.d.cts} +2 -2
- package/dist/{math-hmtx.d.cts → hmtx-table.d.ts} +2 -2
- package/dist/{math-hmtx.js → hmtx-table.js} +3 -3
- package/dist/index.cjs +5 -0
- package/dist/index.d.cts +4 -2
- package/dist/index.d.ts +4 -2
- package/dist/index.js +3 -2
- package/dist/math-font-write.cjs +2 -31
- package/dist/math-font-write.js +1 -30
- package/dist/math-font.cjs +7 -5
- package/dist/math-font.js +5 -3
- package/dist/math-table.d.cts +1 -1
- package/dist/math-table.d.ts +1 -1
- package/dist/measure.cjs +65 -14
- package/dist/measure.d.cts +8 -1
- package/dist/measure.d.ts +8 -1
- package/dist/measure.js +64 -15
- package/dist/sfnt-V08bb5ut.d.cts +21 -0
- package/dist/sfnt-V08bb5ut.d.ts +21 -0
- package/dist/sfnt-subset.cjs +250 -0
- package/dist/sfnt-subset.d.cts +11 -0
- package/dist/sfnt-subset.d.ts +11 -0
- package/dist/sfnt-subset.js +249 -0
- package/dist/sfnt.cjs +50 -4
- package/dist/sfnt.d.cts +2 -17
- package/dist/sfnt.d.ts +2 -17
- package/dist/sfnt.js +47 -5
- package/dist/tounicode.cjs +34 -0
- package/dist/tounicode.d.cts +5 -0
- package/dist/tounicode.d.ts +5 -0
- package/dist/tounicode.js +33 -0
- package/dist/write.cjs +80 -10
- package/dist/write.d.cts +6 -0
- package/dist/write.d.ts +6 -0
- package/dist/write.js +81 -11
- package/package.json +1 -1
- package/dist/math-cmap.cjs +0 -81
- package/dist/math-cmap.d.cts +0 -6
- package/dist/math-cmap.d.ts +0 -6
- package/dist/math-cmap.js +0 -80
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { hasBytes, i16, sfntTableBytes, u16 } from "./sfnt.js";
|
|
2
|
+
import { buildCmapLookup } from "./cmap-table.js";
|
|
3
|
+
import { parseHead, parseMaxp, parseName, parseOs2, parsePost } from "./font-tables.js";
|
|
4
|
+
import { parseGlyf } from "./glyf.js";
|
|
5
|
+
import { parseHmtx } from "./hmtx-table.js";
|
|
6
|
+
//#region src/embedded-font.ts
|
|
7
|
+
const GLYPH_SPACE_UNITS_PER_EM = 1e3;
|
|
8
|
+
const NOTDEF_GLYPH_ID = 0;
|
|
9
|
+
const CAP_HEIGHT_REFERENCE_CODE_POINT = 72;
|
|
10
|
+
const PANOSE_FAMILY_KIND_OFFSET = 0;
|
|
11
|
+
const PANOSE_SERIF_STYLE_OFFSET = 1;
|
|
12
|
+
const PANOSE_FAMILY_KIND_LATIN_TEXT = 2;
|
|
13
|
+
const PANOSE_FIRST_SERIF_STYLE = 2;
|
|
14
|
+
const PANOSE_LAST_SERIF_STYLE = 10;
|
|
15
|
+
const cache = /* @__PURE__ */ new WeakMap();
|
|
16
|
+
function scaleToGlyphSpace(designUnits, unitsPerEm) {
|
|
17
|
+
return designUnits * GLYPH_SPACE_UNITS_PER_EM / unitsPerEm;
|
|
18
|
+
}
|
|
19
|
+
function resolveCapHeight(font, cmap, declared, ascent) {
|
|
20
|
+
if (declared !== void 0) return declared;
|
|
21
|
+
const head = parseHead(font);
|
|
22
|
+
const maxp = parseMaxp(font);
|
|
23
|
+
const glyphId = cmap(CAP_HEIGHT_REFERENCE_CODE_POINT);
|
|
24
|
+
if (head === void 0 || maxp === void 0 || glyphId === void 0) return ascent;
|
|
25
|
+
return parseGlyf(font, {
|
|
26
|
+
numGlyphs: maxp.numGlyphs,
|
|
27
|
+
indexToLocFormat: head.indexToLocFormat
|
|
28
|
+
})?.glyphHeader(glyphId)?.yMax ?? ascent;
|
|
29
|
+
}
|
|
30
|
+
function isSerifByPanose(panose) {
|
|
31
|
+
if (panose?.[PANOSE_FAMILY_KIND_OFFSET] !== PANOSE_FAMILY_KIND_LATIN_TEXT) return false;
|
|
32
|
+
const serifStyle = panose[PANOSE_SERIF_STYLE_OFFSET];
|
|
33
|
+
return serifStyle !== void 0 && serifStyle >= PANOSE_FIRST_SERIF_STYLE && serifStyle <= PANOSE_LAST_SERIF_STYLE;
|
|
34
|
+
}
|
|
35
|
+
function loadEmbeddedFace(font) {
|
|
36
|
+
const cached = cache.get(font.bytes);
|
|
37
|
+
if (cached !== void 0 || cache.has(font.bytes)) return cached;
|
|
38
|
+
const face = readEmbeddedFace(font);
|
|
39
|
+
cache.set(font.bytes, face);
|
|
40
|
+
return face;
|
|
41
|
+
}
|
|
42
|
+
function readEmbeddedFace(font) {
|
|
43
|
+
const head = parseHead(font);
|
|
44
|
+
const maxp = parseMaxp(font);
|
|
45
|
+
const name = parseName(font);
|
|
46
|
+
const cmap = buildCmapLookup(font);
|
|
47
|
+
if (head === void 0 || maxp === void 0 || cmap === void 0 || name?.postScriptName === void 0) return;
|
|
48
|
+
const hhea = parseHhea(font);
|
|
49
|
+
const hmtxBytes = sfntTableBytes(font, "hmtx");
|
|
50
|
+
if (hhea === void 0 || hmtxBytes === void 0 || !hasBytes(hmtxBytes, 0, hhea.numberOfHMetrics * LONG_HOR_METRIC_SIZE)) return;
|
|
51
|
+
const hmtx = parseHmtx(font);
|
|
52
|
+
const os2 = parseOs2(font);
|
|
53
|
+
const post = parsePost(font);
|
|
54
|
+
const { unitsPerEm } = head;
|
|
55
|
+
const scale = (designUnits) => scaleToGlyphSpace(designUnits, unitsPerEm);
|
|
56
|
+
const capHeight = resolveCapHeight(font, cmap, os2?.sCapHeight, hhea.ascent);
|
|
57
|
+
return {
|
|
58
|
+
font,
|
|
59
|
+
postScriptName: name.postScriptName,
|
|
60
|
+
numGlyphs: maxp.numGlyphs,
|
|
61
|
+
metrics: {
|
|
62
|
+
unitsPerEm,
|
|
63
|
+
ascentGlyphSpace: scale(hhea.ascent),
|
|
64
|
+
descentGlyphSpace: scale(hhea.descent),
|
|
65
|
+
lineGapGlyphSpace: scale(hhea.lineGap),
|
|
66
|
+
typoAscentGlyphSpace: os2 === void 0 ? void 0 : scale(os2.sTypoAscender),
|
|
67
|
+
typoDescentGlyphSpace: os2 === void 0 ? void 0 : scale(os2.sTypoDescender),
|
|
68
|
+
typoLineGapGlyphSpace: os2 === void 0 ? void 0 : scale(os2.sTypoLineGap),
|
|
69
|
+
winAscentGlyphSpace: os2 === void 0 ? void 0 : scale(os2.usWinAscent),
|
|
70
|
+
winDescentGlyphSpace: os2 === void 0 ? void 0 : -scale(os2.usWinDescent),
|
|
71
|
+
capHeightGlyphSpace: scale(capHeight),
|
|
72
|
+
xHeightGlyphSpace: os2?.sxHeight === void 0 ? void 0 : scale(os2.sxHeight),
|
|
73
|
+
bboxGlyphSpace: [
|
|
74
|
+
scale(head.xMin),
|
|
75
|
+
scale(head.yMin),
|
|
76
|
+
scale(head.xMax),
|
|
77
|
+
scale(head.yMax)
|
|
78
|
+
],
|
|
79
|
+
italicAngleDegrees: post?.italicAngle ?? 0,
|
|
80
|
+
underlinePositionGlyphSpace: scale(post?.underlinePosition ?? 0),
|
|
81
|
+
underlineThicknessGlyphSpace: scale(post?.underlineThickness ?? 0),
|
|
82
|
+
serif: isSerifByPanose(os2?.panose)
|
|
83
|
+
},
|
|
84
|
+
glyphId: (codePoint) => cmap(codePoint),
|
|
85
|
+
glyphSpaceWidth: (glyphId) => scale(hmtx.advanceWidth(glyphId))
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
const HHEA_TABLE_SIZE = 36;
|
|
89
|
+
const HHEA_ASCENDER_OFFSET = 4;
|
|
90
|
+
const HHEA_DESCENDER_OFFSET = 6;
|
|
91
|
+
const HHEA_LINE_GAP_OFFSET = 8;
|
|
92
|
+
const HHEA_NUMBER_OF_HMETRICS_OFFSET = 34;
|
|
93
|
+
const LONG_HOR_METRIC_SIZE = 4;
|
|
94
|
+
function parseHhea(font) {
|
|
95
|
+
const bytes = sfntTableBytes(font, "hhea");
|
|
96
|
+
if (bytes === void 0 || !hasBytes(bytes, 0, HHEA_TABLE_SIZE)) return;
|
|
97
|
+
const numberOfHMetrics = u16(bytes, HHEA_NUMBER_OF_HMETRICS_OFFSET);
|
|
98
|
+
if (numberOfHMetrics === 0) return;
|
|
99
|
+
return {
|
|
100
|
+
ascent: i16(bytes, HHEA_ASCENDER_OFFSET),
|
|
101
|
+
descent: i16(bytes, HHEA_DESCENDER_OFFSET),
|
|
102
|
+
lineGap: i16(bytes, HHEA_LINE_GAP_OFFSET),
|
|
103
|
+
numberOfHMetrics
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
function encodeForShowEmbedded(text, face) {
|
|
107
|
+
const glyphIds = [];
|
|
108
|
+
const substitutions = [];
|
|
109
|
+
let width1000 = 0;
|
|
110
|
+
for (const character of text) {
|
|
111
|
+
const glyphId = face.glyphId(character.codePointAt(0));
|
|
112
|
+
if (glyphId === void 0) substitutions.push({ from: character });
|
|
113
|
+
const shown = glyphId ?? 0;
|
|
114
|
+
glyphIds.push(shown);
|
|
115
|
+
width1000 += face.glyphSpaceWidth(shown);
|
|
116
|
+
}
|
|
117
|
+
const codes = new Uint8Array(glyphIds.length * 2);
|
|
118
|
+
glyphIds.forEach((glyphId, index) => {
|
|
119
|
+
codes[index * 2] = glyphId >> 8 & 255;
|
|
120
|
+
codes[index * 2 + 1] = glyphId & 255;
|
|
121
|
+
});
|
|
122
|
+
return {
|
|
123
|
+
codes,
|
|
124
|
+
width1000,
|
|
125
|
+
substitutions
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
function collectEmbeddedGlyphs(texts, face) {
|
|
129
|
+
const used = /* @__PURE__ */ new Map();
|
|
130
|
+
for (const text of texts) for (const character of text) {
|
|
131
|
+
const codePoint = character.codePointAt(0);
|
|
132
|
+
const glyphId = face.glyphId(codePoint);
|
|
133
|
+
if (glyphId !== void 0 && !used.has(glyphId)) used.set(glyphId, codePoint);
|
|
134
|
+
}
|
|
135
|
+
return used;
|
|
136
|
+
}
|
|
137
|
+
//#endregion
|
|
138
|
+
export { NOTDEF_GLYPH_ID, collectEmbeddedGlyphs, encodeForShowEmbedded, loadEmbeddedFace };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { r as StandardFontName } from "./afm-widths-DyDq56Ph.js";
|
|
2
|
+
import { t as EmbeddedFace } from "./embedded-font-CbqkKgBl.js";
|
|
3
|
+
import { LayoutFont } from "document-schema.js";
|
|
4
|
+
//#region src/font-registry.d.ts
|
|
5
|
+
interface ProvidedFont {
|
|
6
|
+
readonly family: string;
|
|
7
|
+
readonly bold: boolean;
|
|
8
|
+
readonly italic: boolean;
|
|
9
|
+
readonly bytes: Uint8Array<ArrayBuffer>;
|
|
10
|
+
}
|
|
11
|
+
type ResolvedFace = {
|
|
12
|
+
readonly kind: 'embedded';
|
|
13
|
+
readonly face: EmbeddedFace;
|
|
14
|
+
} | {
|
|
15
|
+
readonly kind: 'standard';
|
|
16
|
+
readonly standardName: StandardFontName;
|
|
17
|
+
readonly matched: boolean;
|
|
18
|
+
};
|
|
19
|
+
interface FontSubstitution {
|
|
20
|
+
readonly requestedFamily: string;
|
|
21
|
+
readonly requestedBold: boolean;
|
|
22
|
+
readonly requestedItalic: boolean;
|
|
23
|
+
readonly reason: 'missing-face' | 'vendored-substitute';
|
|
24
|
+
readonly resolvedFamily: string;
|
|
25
|
+
}
|
|
26
|
+
interface FontRegistryOptions {
|
|
27
|
+
readonly sourceFonts?: readonly ProvidedFont[];
|
|
28
|
+
readonly fonts?: readonly ProvidedFont[];
|
|
29
|
+
readonly substitutes?: 'vendored' | 'none';
|
|
30
|
+
readonly onSubstitution?: (substitution: FontSubstitution) => void;
|
|
31
|
+
}
|
|
32
|
+
interface FontRegistry {
|
|
33
|
+
resolve(font: LayoutFont): ResolvedFace;
|
|
34
|
+
}
|
|
35
|
+
declare function createFontRegistry(options?: FontRegistryOptions): FontRegistry;
|
|
36
|
+
declare function resolveFaceWithRegistry(registry: FontRegistry | undefined, font: LayoutFont): ResolvedFace;
|
|
37
|
+
//#endregion
|
|
38
|
+
export { ResolvedFace as a, ProvidedFont as i, FontRegistryOptions as n, createFontRegistry as o, FontSubstitution as r, resolveFaceWithRegistry as s, FontRegistry as t };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { r as StandardFontName } from "./afm-widths-DyDq56Ph.cjs";
|
|
2
|
+
import { t as EmbeddedFace } from "./embedded-font-CLedn-mT.cjs";
|
|
3
|
+
import { LayoutFont } from "document-schema.js";
|
|
4
|
+
//#region src/font-registry.d.ts
|
|
5
|
+
interface ProvidedFont {
|
|
6
|
+
readonly family: string;
|
|
7
|
+
readonly bold: boolean;
|
|
8
|
+
readonly italic: boolean;
|
|
9
|
+
readonly bytes: Uint8Array<ArrayBuffer>;
|
|
10
|
+
}
|
|
11
|
+
type ResolvedFace = {
|
|
12
|
+
readonly kind: 'embedded';
|
|
13
|
+
readonly face: EmbeddedFace;
|
|
14
|
+
} | {
|
|
15
|
+
readonly kind: 'standard';
|
|
16
|
+
readonly standardName: StandardFontName;
|
|
17
|
+
readonly matched: boolean;
|
|
18
|
+
};
|
|
19
|
+
interface FontSubstitution {
|
|
20
|
+
readonly requestedFamily: string;
|
|
21
|
+
readonly requestedBold: boolean;
|
|
22
|
+
readonly requestedItalic: boolean;
|
|
23
|
+
readonly reason: 'missing-face' | 'vendored-substitute';
|
|
24
|
+
readonly resolvedFamily: string;
|
|
25
|
+
}
|
|
26
|
+
interface FontRegistryOptions {
|
|
27
|
+
readonly sourceFonts?: readonly ProvidedFont[];
|
|
28
|
+
readonly fonts?: readonly ProvidedFont[];
|
|
29
|
+
readonly substitutes?: 'vendored' | 'none';
|
|
30
|
+
readonly onSubstitution?: (substitution: FontSubstitution) => void;
|
|
31
|
+
}
|
|
32
|
+
interface FontRegistry {
|
|
33
|
+
resolve(font: LayoutFont): ResolvedFace;
|
|
34
|
+
}
|
|
35
|
+
declare function createFontRegistry(options?: FontRegistryOptions): FontRegistry;
|
|
36
|
+
declare function resolveFaceWithRegistry(registry: FontRegistry | undefined, font: LayoutFont): ResolvedFace;
|
|
37
|
+
//#endregion
|
|
38
|
+
export { ResolvedFace as a, ProvidedFont as i, FontRegistryOptions as n, createFontRegistry as o, FontSubstitution as r, resolveFaceWithRegistry as s, FontRegistry as t };
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_sfnt = require("./sfnt.cjs");
|
|
3
|
+
const require_util_base64 = require("./util/base64.cjs");
|
|
4
|
+
const require_fonts = require("./fonts.cjs");
|
|
5
|
+
const require_embedded_font = require("./embedded-font.cjs");
|
|
6
|
+
const require_assets_caladea_bold = require("./assets/caladea-bold.cjs");
|
|
7
|
+
const require_assets_caladea_bolditalic = require("./assets/caladea-bolditalic.cjs");
|
|
8
|
+
const require_assets_caladea_italic = require("./assets/caladea-italic.cjs");
|
|
9
|
+
const require_assets_caladea_regular = require("./assets/caladea-regular.cjs");
|
|
10
|
+
const require_assets_carlito_bold = require("./assets/carlito-bold.cjs");
|
|
11
|
+
const require_assets_carlito_bolditalic = require("./assets/carlito-bolditalic.cjs");
|
|
12
|
+
const require_assets_carlito_italic = require("./assets/carlito-italic.cjs");
|
|
13
|
+
const require_assets_carlito_regular = require("./assets/carlito-regular.cjs");
|
|
14
|
+
const require_font_substitutes = require("./font-substitutes.cjs");
|
|
15
|
+
let fflate = require("fflate");
|
|
16
|
+
//#region src/font-registry.ts
|
|
17
|
+
function faceCacheKey(family, bold, italic) {
|
|
18
|
+
return `${require_fonts.normalizeFamilyName(family)}|${bold ? 1 : 0}|${italic ? 1 : 0}`;
|
|
19
|
+
}
|
|
20
|
+
function embedFace(bytes) {
|
|
21
|
+
const sfnt = require_sfnt.parseSfnt(bytes);
|
|
22
|
+
if (sfnt === void 0) return;
|
|
23
|
+
return require_embedded_font.loadEmbeddedFace(sfnt);
|
|
24
|
+
}
|
|
25
|
+
function findExactFace(list, family, bold, italic) {
|
|
26
|
+
const normalized = require_fonts.normalizeFamilyName(family);
|
|
27
|
+
return list.find((candidate) => require_fonts.normalizeFamilyName(candidate.family) === normalized && candidate.bold === bold && candidate.italic === italic);
|
|
28
|
+
}
|
|
29
|
+
function findFamilyRegular(list, family) {
|
|
30
|
+
const normalized = require_fonts.normalizeFamilyName(family);
|
|
31
|
+
const familyFaces = list.filter((candidate) => require_fonts.normalizeFamilyName(candidate.family) === normalized);
|
|
32
|
+
if (familyFaces.length === 0) return;
|
|
33
|
+
return familyFaces.find((candidate) => !candidate.bold && !candidate.italic) ?? familyFaces[0];
|
|
34
|
+
}
|
|
35
|
+
const vendoredFaceBytesCache = /* @__PURE__ */ new Map();
|
|
36
|
+
const VENDORED_FACE_BASE64 = {
|
|
37
|
+
carlito: {
|
|
38
|
+
regular: require_assets_carlito_regular.CARLITO_REGULAR_FONT_DEFLATED_BASE64,
|
|
39
|
+
bold: require_assets_carlito_bold.CARLITO_BOLD_FONT_DEFLATED_BASE64,
|
|
40
|
+
italic: require_assets_carlito_italic.CARLITO_ITALIC_FONT_DEFLATED_BASE64,
|
|
41
|
+
boldItalic: require_assets_carlito_bolditalic.CARLITO_BOLDITALIC_FONT_DEFLATED_BASE64
|
|
42
|
+
},
|
|
43
|
+
caladea: {
|
|
44
|
+
regular: require_assets_caladea_regular.CALADEA_REGULAR_FONT_DEFLATED_BASE64,
|
|
45
|
+
bold: require_assets_caladea_bold.CALADEA_BOLD_FONT_DEFLATED_BASE64,
|
|
46
|
+
italic: require_assets_caladea_italic.CALADEA_ITALIC_FONT_DEFLATED_BASE64,
|
|
47
|
+
boldItalic: require_assets_caladea_bolditalic.CALADEA_BOLDITALIC_FONT_DEFLATED_BASE64
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
function loadVendoredFaceBytes(family, bold, italic) {
|
|
51
|
+
const faceKey = bold && italic ? "boldItalic" : bold ? "bold" : italic ? "italic" : "regular";
|
|
52
|
+
const cacheKey = `${family}-${faceKey}`;
|
|
53
|
+
const cached = vendoredFaceBytesCache.get(cacheKey);
|
|
54
|
+
if (cached !== void 0) return cached;
|
|
55
|
+
const deflatedBase64 = VENDORED_FACE_BASE64[family][faceKey];
|
|
56
|
+
const inflated = (0, fflate.inflateSync)(require_util_base64.base64ToBytes(deflatedBase64));
|
|
57
|
+
const bytes = new Uint8Array(inflated.length);
|
|
58
|
+
bytes.set(inflated);
|
|
59
|
+
vendoredFaceBytesCache.set(cacheKey, bytes);
|
|
60
|
+
return bytes;
|
|
61
|
+
}
|
|
62
|
+
function createFontRegistry(options = {}) {
|
|
63
|
+
const sourceFonts = options.sourceFonts ?? [];
|
|
64
|
+
const fonts = options.fonts ?? [];
|
|
65
|
+
const substitutesEnabled = (options.substitutes ?? "vendored") === "vendored";
|
|
66
|
+
const onSubstitution = options.onSubstitution;
|
|
67
|
+
const cache = /* @__PURE__ */ new Map();
|
|
68
|
+
function resolveUncached(family, bold, italic) {
|
|
69
|
+
const sourceExact = findExactFace(sourceFonts, family, bold, italic);
|
|
70
|
+
if (sourceExact !== void 0) {
|
|
71
|
+
const face = embedFace(sourceExact.bytes);
|
|
72
|
+
if (face !== void 0) return {
|
|
73
|
+
kind: "embedded",
|
|
74
|
+
face
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
const callerExact = findExactFace(fonts, family, bold, italic);
|
|
78
|
+
if (callerExact !== void 0) {
|
|
79
|
+
const face = embedFace(callerExact.bytes);
|
|
80
|
+
if (face !== void 0) return {
|
|
81
|
+
kind: "embedded",
|
|
82
|
+
face
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
const sourceFamilyRegular = findFamilyRegular(sourceFonts, family);
|
|
86
|
+
const callerFamilyRegular = sourceFamilyRegular === void 0 ? findFamilyRegular(fonts, family) : void 0;
|
|
87
|
+
const familyRegular = sourceFamilyRegular ?? callerFamilyRegular;
|
|
88
|
+
if (familyRegular !== void 0) {
|
|
89
|
+
const face = embedFace(familyRegular.bytes);
|
|
90
|
+
if (face !== void 0) {
|
|
91
|
+
onSubstitution?.({
|
|
92
|
+
requestedFamily: family,
|
|
93
|
+
requestedBold: bold,
|
|
94
|
+
requestedItalic: italic,
|
|
95
|
+
reason: "missing-face",
|
|
96
|
+
resolvedFamily: family
|
|
97
|
+
});
|
|
98
|
+
return {
|
|
99
|
+
kind: "embedded",
|
|
100
|
+
face
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
if (substitutesEnabled) {
|
|
105
|
+
const vendoredFamily = require_font_substitutes.resolveVendoredSubstituteFamily(family);
|
|
106
|
+
if (vendoredFamily !== void 0) {
|
|
107
|
+
const face = embedFace(loadVendoredFaceBytes(vendoredFamily, bold, italic));
|
|
108
|
+
if (face !== void 0) {
|
|
109
|
+
onSubstitution?.({
|
|
110
|
+
requestedFamily: family,
|
|
111
|
+
requestedBold: bold,
|
|
112
|
+
requestedItalic: italic,
|
|
113
|
+
reason: "vendored-substitute",
|
|
114
|
+
resolvedFamily: vendoredFamily
|
|
115
|
+
});
|
|
116
|
+
return {
|
|
117
|
+
kind: "embedded",
|
|
118
|
+
face
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
const standard = require_fonts.resolveStandardFont(family, bold, italic);
|
|
124
|
+
return {
|
|
125
|
+
kind: "standard",
|
|
126
|
+
standardName: standard.standardName,
|
|
127
|
+
matched: standard.matched
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
return { resolve(font) {
|
|
131
|
+
const bold = font.weight === "bold";
|
|
132
|
+
const italic = font.style === "italic";
|
|
133
|
+
const key = faceCacheKey(font.family, bold, italic);
|
|
134
|
+
const cached = cache.get(key);
|
|
135
|
+
if (cached !== void 0) return cached;
|
|
136
|
+
const resolved = resolveUncached(font.family, bold, italic);
|
|
137
|
+
cache.set(key, resolved);
|
|
138
|
+
return resolved;
|
|
139
|
+
} };
|
|
140
|
+
}
|
|
141
|
+
function resolveFaceWithRegistry(registry, font) {
|
|
142
|
+
if (registry !== void 0) return registry.resolve(font);
|
|
143
|
+
const standard = require_fonts.resolveStandardFont(font.family, font.weight === "bold", font.style === "italic");
|
|
144
|
+
return {
|
|
145
|
+
kind: "standard",
|
|
146
|
+
standardName: standard.standardName,
|
|
147
|
+
matched: standard.matched
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
//#endregion
|
|
151
|
+
exports.createFontRegistry = createFontRegistry;
|
|
152
|
+
exports.resolveFaceWithRegistry = resolveFaceWithRegistry;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as ResolvedFace, i as ProvidedFont, n as FontRegistryOptions, o as createFontRegistry, r as FontSubstitution, s as resolveFaceWithRegistry, t as FontRegistry } from "./font-registry-yby02snZ.cjs";
|
|
2
|
+
export { FontRegistry, FontRegistryOptions, FontSubstitution, ProvidedFont, ResolvedFace, createFontRegistry, resolveFaceWithRegistry };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as ResolvedFace, i as ProvidedFont, n as FontRegistryOptions, o as createFontRegistry, r as FontSubstitution, s as resolveFaceWithRegistry, t as FontRegistry } from "./font-registry-Cn7P9lAh.js";
|
|
2
|
+
export { FontRegistry, FontRegistryOptions, FontSubstitution, ProvidedFont, ResolvedFace, createFontRegistry, resolveFaceWithRegistry };
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { parseSfnt } from "./sfnt.js";
|
|
2
|
+
import { base64ToBytes } from "./util/base64.js";
|
|
3
|
+
import { normalizeFamilyName, resolveStandardFont } from "./fonts.js";
|
|
4
|
+
import { loadEmbeddedFace } from "./embedded-font.js";
|
|
5
|
+
import { CALADEA_BOLD_FONT_DEFLATED_BASE64 } from "./assets/caladea-bold.js";
|
|
6
|
+
import { CALADEA_BOLDITALIC_FONT_DEFLATED_BASE64 } from "./assets/caladea-bolditalic.js";
|
|
7
|
+
import { CALADEA_ITALIC_FONT_DEFLATED_BASE64 } from "./assets/caladea-italic.js";
|
|
8
|
+
import { CALADEA_REGULAR_FONT_DEFLATED_BASE64 } from "./assets/caladea-regular.js";
|
|
9
|
+
import { CARLITO_BOLD_FONT_DEFLATED_BASE64 } from "./assets/carlito-bold.js";
|
|
10
|
+
import { CARLITO_BOLDITALIC_FONT_DEFLATED_BASE64 } from "./assets/carlito-bolditalic.js";
|
|
11
|
+
import { CARLITO_ITALIC_FONT_DEFLATED_BASE64 } from "./assets/carlito-italic.js";
|
|
12
|
+
import { CARLITO_REGULAR_FONT_DEFLATED_BASE64 } from "./assets/carlito-regular.js";
|
|
13
|
+
import { resolveVendoredSubstituteFamily } from "./font-substitutes.js";
|
|
14
|
+
import { inflateSync } from "fflate";
|
|
15
|
+
//#region src/font-registry.ts
|
|
16
|
+
function faceCacheKey(family, bold, italic) {
|
|
17
|
+
return `${normalizeFamilyName(family)}|${bold ? 1 : 0}|${italic ? 1 : 0}`;
|
|
18
|
+
}
|
|
19
|
+
function embedFace(bytes) {
|
|
20
|
+
const sfnt = parseSfnt(bytes);
|
|
21
|
+
if (sfnt === void 0) return;
|
|
22
|
+
return loadEmbeddedFace(sfnt);
|
|
23
|
+
}
|
|
24
|
+
function findExactFace(list, family, bold, italic) {
|
|
25
|
+
const normalized = normalizeFamilyName(family);
|
|
26
|
+
return list.find((candidate) => normalizeFamilyName(candidate.family) === normalized && candidate.bold === bold && candidate.italic === italic);
|
|
27
|
+
}
|
|
28
|
+
function findFamilyRegular(list, family) {
|
|
29
|
+
const normalized = normalizeFamilyName(family);
|
|
30
|
+
const familyFaces = list.filter((candidate) => normalizeFamilyName(candidate.family) === normalized);
|
|
31
|
+
if (familyFaces.length === 0) return;
|
|
32
|
+
return familyFaces.find((candidate) => !candidate.bold && !candidate.italic) ?? familyFaces[0];
|
|
33
|
+
}
|
|
34
|
+
const vendoredFaceBytesCache = /* @__PURE__ */ new Map();
|
|
35
|
+
const VENDORED_FACE_BASE64 = {
|
|
36
|
+
carlito: {
|
|
37
|
+
regular: CARLITO_REGULAR_FONT_DEFLATED_BASE64,
|
|
38
|
+
bold: CARLITO_BOLD_FONT_DEFLATED_BASE64,
|
|
39
|
+
italic: CARLITO_ITALIC_FONT_DEFLATED_BASE64,
|
|
40
|
+
boldItalic: CARLITO_BOLDITALIC_FONT_DEFLATED_BASE64
|
|
41
|
+
},
|
|
42
|
+
caladea: {
|
|
43
|
+
regular: CALADEA_REGULAR_FONT_DEFLATED_BASE64,
|
|
44
|
+
bold: CALADEA_BOLD_FONT_DEFLATED_BASE64,
|
|
45
|
+
italic: CALADEA_ITALIC_FONT_DEFLATED_BASE64,
|
|
46
|
+
boldItalic: CALADEA_BOLDITALIC_FONT_DEFLATED_BASE64
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
function loadVendoredFaceBytes(family, bold, italic) {
|
|
50
|
+
const faceKey = bold && italic ? "boldItalic" : bold ? "bold" : italic ? "italic" : "regular";
|
|
51
|
+
const cacheKey = `${family}-${faceKey}`;
|
|
52
|
+
const cached = vendoredFaceBytesCache.get(cacheKey);
|
|
53
|
+
if (cached !== void 0) return cached;
|
|
54
|
+
const deflatedBase64 = VENDORED_FACE_BASE64[family][faceKey];
|
|
55
|
+
const inflated = inflateSync(base64ToBytes(deflatedBase64));
|
|
56
|
+
const bytes = new Uint8Array(inflated.length);
|
|
57
|
+
bytes.set(inflated);
|
|
58
|
+
vendoredFaceBytesCache.set(cacheKey, bytes);
|
|
59
|
+
return bytes;
|
|
60
|
+
}
|
|
61
|
+
function createFontRegistry(options = {}) {
|
|
62
|
+
const sourceFonts = options.sourceFonts ?? [];
|
|
63
|
+
const fonts = options.fonts ?? [];
|
|
64
|
+
const substitutesEnabled = (options.substitutes ?? "vendored") === "vendored";
|
|
65
|
+
const onSubstitution = options.onSubstitution;
|
|
66
|
+
const cache = /* @__PURE__ */ new Map();
|
|
67
|
+
function resolveUncached(family, bold, italic) {
|
|
68
|
+
const sourceExact = findExactFace(sourceFonts, family, bold, italic);
|
|
69
|
+
if (sourceExact !== void 0) {
|
|
70
|
+
const face = embedFace(sourceExact.bytes);
|
|
71
|
+
if (face !== void 0) return {
|
|
72
|
+
kind: "embedded",
|
|
73
|
+
face
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
const callerExact = findExactFace(fonts, family, bold, italic);
|
|
77
|
+
if (callerExact !== void 0) {
|
|
78
|
+
const face = embedFace(callerExact.bytes);
|
|
79
|
+
if (face !== void 0) return {
|
|
80
|
+
kind: "embedded",
|
|
81
|
+
face
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
const sourceFamilyRegular = findFamilyRegular(sourceFonts, family);
|
|
85
|
+
const callerFamilyRegular = sourceFamilyRegular === void 0 ? findFamilyRegular(fonts, family) : void 0;
|
|
86
|
+
const familyRegular = sourceFamilyRegular ?? callerFamilyRegular;
|
|
87
|
+
if (familyRegular !== void 0) {
|
|
88
|
+
const face = embedFace(familyRegular.bytes);
|
|
89
|
+
if (face !== void 0) {
|
|
90
|
+
onSubstitution?.({
|
|
91
|
+
requestedFamily: family,
|
|
92
|
+
requestedBold: bold,
|
|
93
|
+
requestedItalic: italic,
|
|
94
|
+
reason: "missing-face",
|
|
95
|
+
resolvedFamily: family
|
|
96
|
+
});
|
|
97
|
+
return {
|
|
98
|
+
kind: "embedded",
|
|
99
|
+
face
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
if (substitutesEnabled) {
|
|
104
|
+
const vendoredFamily = resolveVendoredSubstituteFamily(family);
|
|
105
|
+
if (vendoredFamily !== void 0) {
|
|
106
|
+
const face = embedFace(loadVendoredFaceBytes(vendoredFamily, bold, italic));
|
|
107
|
+
if (face !== void 0) {
|
|
108
|
+
onSubstitution?.({
|
|
109
|
+
requestedFamily: family,
|
|
110
|
+
requestedBold: bold,
|
|
111
|
+
requestedItalic: italic,
|
|
112
|
+
reason: "vendored-substitute",
|
|
113
|
+
resolvedFamily: vendoredFamily
|
|
114
|
+
});
|
|
115
|
+
return {
|
|
116
|
+
kind: "embedded",
|
|
117
|
+
face
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
const standard = resolveStandardFont(family, bold, italic);
|
|
123
|
+
return {
|
|
124
|
+
kind: "standard",
|
|
125
|
+
standardName: standard.standardName,
|
|
126
|
+
matched: standard.matched
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
return { resolve(font) {
|
|
130
|
+
const bold = font.weight === "bold";
|
|
131
|
+
const italic = font.style === "italic";
|
|
132
|
+
const key = faceCacheKey(font.family, bold, italic);
|
|
133
|
+
const cached = cache.get(key);
|
|
134
|
+
if (cached !== void 0) return cached;
|
|
135
|
+
const resolved = resolveUncached(font.family, bold, italic);
|
|
136
|
+
cache.set(key, resolved);
|
|
137
|
+
return resolved;
|
|
138
|
+
} };
|
|
139
|
+
}
|
|
140
|
+
function resolveFaceWithRegistry(registry, font) {
|
|
141
|
+
if (registry !== void 0) return registry.resolve(font);
|
|
142
|
+
const standard = resolveStandardFont(font.family, font.weight === "bold", font.style === "italic");
|
|
143
|
+
return {
|
|
144
|
+
kind: "standard",
|
|
145
|
+
standardName: standard.standardName,
|
|
146
|
+
matched: standard.matched
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
//#endregion
|
|
150
|
+
export { createFontRegistry, resolveFaceWithRegistry };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_fonts = require("./fonts.cjs");
|
|
3
|
+
//#region src/font-substitutes.ts
|
|
4
|
+
const SUBSTITUTE_FAMILY_BY_NORMALIZED_NAME = /* @__PURE__ */ new Map([
|
|
5
|
+
["calibri", "carlito"],
|
|
6
|
+
["calibrilight", "carlito"],
|
|
7
|
+
["cambria", "caladea"]
|
|
8
|
+
]);
|
|
9
|
+
function resolveVendoredSubstituteFamily(rawFamily) {
|
|
10
|
+
return SUBSTITUTE_FAMILY_BY_NORMALIZED_NAME.get(require_fonts.normalizeFamilyName(rawFamily));
|
|
11
|
+
}
|
|
12
|
+
//#endregion
|
|
13
|
+
exports.resolveVendoredSubstituteFamily = resolveVendoredSubstituteFamily;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { normalizeFamilyName } from "./fonts.js";
|
|
2
|
+
//#region src/font-substitutes.ts
|
|
3
|
+
const SUBSTITUTE_FAMILY_BY_NORMALIZED_NAME = /* @__PURE__ */ new Map([
|
|
4
|
+
["calibri", "carlito"],
|
|
5
|
+
["calibrilight", "carlito"],
|
|
6
|
+
["cambria", "caladea"]
|
|
7
|
+
]);
|
|
8
|
+
function resolveVendoredSubstituteFamily(rawFamily) {
|
|
9
|
+
return SUBSTITUTE_FAMILY_BY_NORMALIZED_NAME.get(normalizeFamilyName(rawFamily));
|
|
10
|
+
}
|
|
11
|
+
//#endregion
|
|
12
|
+
export { resolveVendoredSubstituteFamily };
|