pdf-codec 1.5.0 → 1.7.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 +100 -9
- 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-bounds.cjs +432 -0
- package/dist/cff-bounds.d.cts +9 -0
- package/dist/cff-bounds.d.ts +9 -0
- package/dist/cff-bounds.js +431 -0
- package/dist/cff-probe.cjs +35 -0
- package/dist/cff-probe.d.cts +10 -0
- package/dist/cff-probe.d.ts +10 -0
- package/dist/cff-probe.js +34 -0
- package/dist/cff.cjs +158 -0
- package/dist/cff.d.cts +17 -0
- package/dist/cff.d.ts +17 -0
- package/dist/cff.js +150 -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/filters.cjs +45 -2
- package/dist/filters.d.cts +4 -3
- package/dist/filters.d.ts +4 -3
- package/dist/filters.js +45 -2
- 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/formula.d.cts +1 -1
- package/dist/formula.d.ts +1 -1
- package/dist/glyf.cjs +183 -0
- package/dist/glyf.d.cts +33 -0
- package/dist/glyf.d.ts +33 -0
- package/dist/glyf.js +181 -0
- package/dist/glyph-bounds-BV_Z40KS.d.cts +10 -0
- package/dist/glyph-bounds-BV_Z40KS.d.ts +10 -0
- package/dist/glyph-bounds.cjs +12 -0
- package/dist/glyph-bounds.d.cts +2 -0
- package/dist/glyph-bounds.d.ts +2 -0
- package/dist/glyph-bounds.js +11 -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/image/jbig2-arith.cjs +432 -0
- package/dist/image/jbig2-arith.d.cts +23 -0
- package/dist/image/jbig2-arith.d.ts +23 -0
- package/dist/image/jbig2-arith.js +426 -0
- package/dist/image/jbig2-bitmap.cjs +80 -0
- package/dist/image/jbig2-bitmap.d.cts +20 -0
- package/dist/image/jbig2-bitmap.d.ts +20 -0
- package/dist/image/jbig2-bitmap.js +72 -0
- package/dist/image/jbig2-errors.cjs +17 -0
- package/dist/image/jbig2-errors.d.cts +2 -0
- package/dist/image/jbig2-errors.d.ts +2 -0
- package/dist/image/jbig2-errors.js +15 -0
- package/dist/image/jbig2-generic.cjs +242 -0
- package/dist/image/jbig2-generic.d.cts +27 -0
- package/dist/image/jbig2-generic.d.ts +27 -0
- package/dist/image/jbig2-generic.js +237 -0
- package/dist/image/jbig2-text.cjs +175 -0
- package/dist/image/jbig2-text.d.cts +58 -0
- package/dist/image/jbig2-text.d.ts +58 -0
- package/dist/image/jbig2-text.js +170 -0
- package/dist/image/jbig2.cjs +333 -0
- package/dist/image/jbig2.d.cts +15 -0
- package/dist/image/jbig2.d.ts +15 -0
- package/dist/image/jbig2.js +332 -0
- package/dist/image/jp2-boxes.cjs +148 -0
- package/dist/image/jp2-boxes.d.cts +26 -0
- package/dist/image/jp2-boxes.d.ts +26 -0
- package/dist/image/jp2-boxes.js +146 -0
- package/dist/image/jpeg2000-codestream.cjs +309 -0
- package/dist/image/jpeg2000-codestream.d.cts +78 -0
- package/dist/image/jpeg2000-codestream.d.ts +78 -0
- package/dist/image/jpeg2000-codestream.js +308 -0
- package/dist/image/jpeg2000-dwt.cjs +148 -0
- package/dist/image/jpeg2000-dwt.d.cts +34 -0
- package/dist/image/jpeg2000-dwt.d.ts +34 -0
- package/dist/image/jpeg2000-dwt.js +145 -0
- package/dist/image/jpeg2000-errors.cjs +17 -0
- package/dist/image/jpeg2000-errors.d.cts +9 -0
- package/dist/image/jpeg2000-errors.d.ts +9 -0
- package/dist/image/jpeg2000-errors.js +15 -0
- package/dist/image/jpeg2000-t1.cjs +254 -0
- package/dist/image/jpeg2000-t1.d.cts +18 -0
- package/dist/image/jpeg2000-t1.d.ts +18 -0
- package/dist/image/jpeg2000-t1.js +253 -0
- package/dist/image/jpeg2000-t2.cjs +316 -0
- package/dist/image/jpeg2000-t2.d.cts +79 -0
- package/dist/image/jpeg2000-t2.d.ts +79 -0
- package/dist/image/jpeg2000-t2.js +311 -0
- package/dist/image/jpeg2000-tagtree.cjs +105 -0
- package/dist/image/jpeg2000-tagtree.d.cts +29 -0
- package/dist/image/jpeg2000-tagtree.d.ts +29 -0
- package/dist/image/jpeg2000-tagtree.js +103 -0
- package/dist/image/jpeg2000.cjs +322 -0
- package/dist/image/jpeg2000.d.cts +54 -0
- package/dist/image/jpeg2000.d.ts +54 -0
- package/dist/image/jpeg2000.js +320 -0
- package/dist/images-read.cjs +78 -1
- package/dist/images-read.js +78 -1
- package/dist/index.cjs +22 -0
- package/dist/index.d.cts +14 -3
- package/dist/index.d.ts +14 -3
- package/dist/index.js +9 -2
- package/dist/jbig2-errors-Bj6MPxrx.d.cts +9 -0
- package/dist/jbig2-errors-Bj6MPxrx.d.ts +9 -0
- package/dist/math-font-write.cjs +2 -31
- package/dist/math-font-write.js +1 -30
- package/dist/math-font.cjs +50 -23
- package/dist/math-font.d.cts +8 -1
- package/dist/math-font.d.ts +8 -1
- package/dist/math-font.js +48 -21
- package/dist/math-stretch-Bwk_bxh1.d.ts +24 -0
- package/dist/math-stretch-DXWjs8gL.d.cts +24 -0
- package/dist/math-stretch.cjs +96 -0
- package/dist/math-stretch.d.cts +2 -0
- package/dist/math-stretch.d.ts +2 -0
- package/dist/math-stretch.js +94 -0
- package/dist/math-table-DhPrNoPa.d.ts +70 -0
- package/dist/math-table-gFNB8DmQ.d.cts +70 -0
- package/dist/math-table.cjs +69 -1
- package/dist/math-table.d.cts +2 -45
- package/dist/math-table.d.ts +2 -45
- package/dist/math-table.js +69 -1
- package/dist/{math-types-Ba8qAf1p.d.cts → math-types-YSQUTviw.d.cts} +2 -0
- package/dist/{math-types-Ba8qAf1p.d.ts → math-types-YSQUTviw.d.ts} +2 -0
- package/dist/math-types.d.cts +1 -1
- package/dist/math-types.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
package/dist/filters.d.cts
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { PdfDiagnosticSink } from "./diagnostics.cjs";
|
|
2
|
-
import { PdfDict } from "./objects.cjs";
|
|
2
|
+
import { PdfDict, PdfObject } from "./objects.cjs";
|
|
3
3
|
//#region src/filters.d.ts
|
|
4
4
|
interface DecodedStream {
|
|
5
5
|
readonly bytes: Uint8Array<ArrayBuffer>;
|
|
6
6
|
readonly remainingFilter?: string;
|
|
7
7
|
}
|
|
8
|
-
|
|
8
|
+
type PdfIndirectResolver = (obj: PdfObject | undefined) => PdfObject | undefined;
|
|
9
|
+
declare function decodeStream(raw: Uint8Array<ArrayBuffer>, dict: PdfDict, sink: PdfDiagnosticSink, resolve?: PdfIndirectResolver): DecodedStream;
|
|
9
10
|
declare function lzwDecode(data: Uint8Array<ArrayBuffer>, earlyChange: boolean, sink: PdfDiagnosticSink): Uint8Array<ArrayBuffer>;
|
|
10
11
|
declare function ascii85Decode(data: Uint8Array<ArrayBuffer>): Uint8Array<ArrayBuffer>;
|
|
11
12
|
declare function asciiHexDecode(data: Uint8Array<ArrayBuffer>): Uint8Array<ArrayBuffer>;
|
|
12
13
|
declare function runLengthDecode(data: Uint8Array<ArrayBuffer>): Uint8Array<ArrayBuffer>;
|
|
13
14
|
//#endregion
|
|
14
|
-
export { DecodedStream, ascii85Decode, asciiHexDecode, decodeStream, lzwDecode, runLengthDecode };
|
|
15
|
+
export { DecodedStream, PdfIndirectResolver, ascii85Decode, asciiHexDecode, decodeStream, lzwDecode, runLengthDecode };
|
package/dist/filters.d.ts
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { PdfDiagnosticSink } from "./diagnostics.js";
|
|
2
|
-
import { PdfDict } from "./objects.js";
|
|
2
|
+
import { PdfDict, PdfObject } from "./objects.js";
|
|
3
3
|
//#region src/filters.d.ts
|
|
4
4
|
interface DecodedStream {
|
|
5
5
|
readonly bytes: Uint8Array<ArrayBuffer>;
|
|
6
6
|
readonly remainingFilter?: string;
|
|
7
7
|
}
|
|
8
|
-
|
|
8
|
+
type PdfIndirectResolver = (obj: PdfObject | undefined) => PdfObject | undefined;
|
|
9
|
+
declare function decodeStream(raw: Uint8Array<ArrayBuffer>, dict: PdfDict, sink: PdfDiagnosticSink, resolve?: PdfIndirectResolver): DecodedStream;
|
|
9
10
|
declare function lzwDecode(data: Uint8Array<ArrayBuffer>, earlyChange: boolean, sink: PdfDiagnosticSink): Uint8Array<ArrayBuffer>;
|
|
10
11
|
declare function ascii85Decode(data: Uint8Array<ArrayBuffer>): Uint8Array<ArrayBuffer>;
|
|
11
12
|
declare function asciiHexDecode(data: Uint8Array<ArrayBuffer>): Uint8Array<ArrayBuffer>;
|
|
12
13
|
declare function runLengthDecode(data: Uint8Array<ArrayBuffer>): Uint8Array<ArrayBuffer>;
|
|
13
14
|
//#endregion
|
|
14
|
-
export { DecodedStream, ascii85Decode, asciiHexDecode, decodeStream, lzwDecode, runLengthDecode };
|
|
15
|
+
export { DecodedStream, PdfIndirectResolver, ascii85Decode, asciiHexDecode, decodeStream, lzwDecode, runLengthDecode };
|
package/dist/filters.js
CHANGED
|
@@ -2,9 +2,10 @@ import { isAsciiWhitespace } from "./bytes/reader.js";
|
|
|
2
2
|
import { asArray, asBool, asDict, asName, asNumber, dictGet } from "./objects.js";
|
|
3
3
|
import { inflateTolerant } from "./bytes/flate.js";
|
|
4
4
|
import { decodeCcittFax } from "./image/ccitt.js";
|
|
5
|
+
import { decodeJbig2Embedded } from "./image/jbig2.js";
|
|
5
6
|
import { applyPredictor, readPredictorParams } from "./predictors.js";
|
|
6
7
|
//#region src/filters.ts
|
|
7
|
-
function decodeStream(raw, dict, sink) {
|
|
8
|
+
function decodeStream(raw, dict, sink, resolve) {
|
|
8
9
|
const filters = filterNames(dict);
|
|
9
10
|
const parms = decodeParmsList(dict, filters.length);
|
|
10
11
|
let bytes = raw;
|
|
@@ -19,10 +20,21 @@ function decodeStream(raw, dict, sink) {
|
|
|
19
20
|
else if (filter === "ASCIIHexDecode" || filter === "AHx") bytes = asciiHexDecode(bytes);
|
|
20
21
|
else if (filter === "RunLengthDecode" || filter === "RL") bytes = runLengthDecode(bytes);
|
|
21
22
|
else if (filter === "CCITTFaxDecode" || filter === "CCF") bytes = ccittFaxDecode(bytes, parm, dict, sink);
|
|
22
|
-
else if (filter === "
|
|
23
|
+
else if (filter === "JBIG2Decode") {
|
|
24
|
+
const decoded = jbig2Decode(bytes, parm, dict, sink, resolve);
|
|
25
|
+
if (decoded === void 0) return {
|
|
26
|
+
bytes,
|
|
27
|
+
remainingFilter: "JBIG2Decode"
|
|
28
|
+
};
|
|
29
|
+
bytes = decoded;
|
|
30
|
+
} else if (filter === "DCTDecode" || filter === "DCT") return {
|
|
23
31
|
bytes,
|
|
24
32
|
remainingFilter: "DCTDecode"
|
|
25
33
|
};
|
|
34
|
+
else if (filter === "JPXDecode") return {
|
|
35
|
+
bytes,
|
|
36
|
+
remainingFilter: "JPXDecode"
|
|
37
|
+
};
|
|
26
38
|
else {
|
|
27
39
|
sink({
|
|
28
40
|
code: "pdf/unsupported-filter",
|
|
@@ -56,6 +68,37 @@ function ccittFaxDecode(data, parm, dict, sink) {
|
|
|
56
68
|
})
|
|
57
69
|
}).bytes;
|
|
58
70
|
}
|
|
71
|
+
function jbig2Decode(data, parm, dict, sink, resolve) {
|
|
72
|
+
const globalsObj = parm !== void 0 ? dictGet(parm, "JBIG2Globals") : void 0;
|
|
73
|
+
const resolvedGlobals = resolve !== void 0 ? resolve(globalsObj) : globalsObj;
|
|
74
|
+
let globals;
|
|
75
|
+
if (resolvedGlobals?.kind === "stream") globals = decodeStream(resolvedGlobals.raw, resolvedGlobals.dict, sink, resolve).bytes;
|
|
76
|
+
else if (globalsObj !== void 0) sink({
|
|
77
|
+
code: "pdf/jbig2-degraded",
|
|
78
|
+
severity: "warning",
|
|
79
|
+
message: "a JBIG2Decode stream declares /JBIG2Globals but it could not be resolved to a stream; decoding without it, which will fail if the page refers to a shared symbol dictionary"
|
|
80
|
+
});
|
|
81
|
+
try {
|
|
82
|
+
const image = decodeJbig2Embedded(data, {
|
|
83
|
+
globals,
|
|
84
|
+
width: asNumber(dictGet(dict, "Width") ?? dictGet(dict, "W")),
|
|
85
|
+
height: asNumber(dictGet(dict, "Height") ?? dictGet(dict, "H")),
|
|
86
|
+
onWarning: (message) => sink({
|
|
87
|
+
code: "pdf/jbig2-degraded",
|
|
88
|
+
severity: "warning",
|
|
89
|
+
message
|
|
90
|
+
})
|
|
91
|
+
});
|
|
92
|
+
return Uint8Array.from(image.bytes, (byte) => byte ^ 255);
|
|
93
|
+
} catch (error) {
|
|
94
|
+
sink({
|
|
95
|
+
code: "pdf/jbig2-undecodable",
|
|
96
|
+
severity: "warning",
|
|
97
|
+
message: `JBIG2Decode stream could not be decoded (${error instanceof Error ? error.message : String(error)}); leaving its bytes undecoded`
|
|
98
|
+
});
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
59
102
|
function filterNames(dict) {
|
|
60
103
|
const filterObj = dictGet(dict, "Filter") ?? dictGet(dict, "F");
|
|
61
104
|
if (filterObj === void 0) return [];
|
|
@@ -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 };
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_sfnt = require("./sfnt.cjs");
|
|
3
|
+
//#region src/font-tables.ts
|
|
4
|
+
const HEAD_TABLE_SIZE = 54;
|
|
5
|
+
const HEAD_MAGIC_NUMBER = 1594834165;
|
|
6
|
+
const MIN_UNITS_PER_EM = 16;
|
|
7
|
+
const MAX_UNITS_PER_EM = 16384;
|
|
8
|
+
function parseHead(font) {
|
|
9
|
+
const bytes = require_sfnt.sfntTableBytes(font, "head");
|
|
10
|
+
if (bytes === void 0 || !require_sfnt.hasBytes(bytes, 0, HEAD_TABLE_SIZE)) return;
|
|
11
|
+
if (require_sfnt.u32(bytes, 12) !== HEAD_MAGIC_NUMBER) return;
|
|
12
|
+
const unitsPerEm = require_sfnt.u16(bytes, 18);
|
|
13
|
+
if (unitsPerEm < MIN_UNITS_PER_EM || unitsPerEm > MAX_UNITS_PER_EM) return;
|
|
14
|
+
const indexToLocFormat = require_sfnt.i16(bytes, 50);
|
|
15
|
+
if (indexToLocFormat !== 0 && indexToLocFormat !== 1) return;
|
|
16
|
+
return {
|
|
17
|
+
unitsPerEm,
|
|
18
|
+
checkSumAdjustment: require_sfnt.u32(bytes, 8),
|
|
19
|
+
xMin: require_sfnt.i16(bytes, 36),
|
|
20
|
+
yMin: require_sfnt.i16(bytes, 38),
|
|
21
|
+
xMax: require_sfnt.i16(bytes, 40),
|
|
22
|
+
yMax: require_sfnt.i16(bytes, 42),
|
|
23
|
+
indexToLocFormat
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
const MAXP_HEADER_SIZE = 6;
|
|
27
|
+
function parseMaxp(font) {
|
|
28
|
+
const bytes = require_sfnt.sfntTableBytes(font, "maxp");
|
|
29
|
+
if (bytes === void 0 || !require_sfnt.hasBytes(bytes, 0, MAXP_HEADER_SIZE)) return;
|
|
30
|
+
return { numGlyphs: require_sfnt.u16(bytes, 4) };
|
|
31
|
+
}
|
|
32
|
+
const OS2_VERSION_0_SIZE = 78;
|
|
33
|
+
const OS2_VERSION_2_SIZE = 96;
|
|
34
|
+
const OS2_VERSION_WITH_HEIGHTS = 2;
|
|
35
|
+
const OS2_PANOSE_OFFSET = 32;
|
|
36
|
+
function parseOs2(font) {
|
|
37
|
+
const bytes = require_sfnt.sfntTableBytes(font, "OS/2");
|
|
38
|
+
if (bytes === void 0 || !require_sfnt.hasBytes(bytes, 0, OS2_VERSION_0_SIZE)) return;
|
|
39
|
+
const version = require_sfnt.u16(bytes, 0);
|
|
40
|
+
const hasHeights = version >= OS2_VERSION_WITH_HEIGHTS && require_sfnt.hasBytes(bytes, 0, OS2_VERSION_2_SIZE);
|
|
41
|
+
return {
|
|
42
|
+
version,
|
|
43
|
+
fsSelection: require_sfnt.u16(bytes, 62),
|
|
44
|
+
panose: [...bytes.subarray(OS2_PANOSE_OFFSET, 42)],
|
|
45
|
+
sTypoAscender: require_sfnt.i16(bytes, 68),
|
|
46
|
+
sTypoDescender: require_sfnt.i16(bytes, 70),
|
|
47
|
+
sTypoLineGap: require_sfnt.i16(bytes, 72),
|
|
48
|
+
usWinAscent: require_sfnt.u16(bytes, 74),
|
|
49
|
+
usWinDescent: require_sfnt.u16(bytes, 76),
|
|
50
|
+
sxHeight: hasHeights ? require_sfnt.i16(bytes, 86) : void 0,
|
|
51
|
+
sCapHeight: hasHeights ? require_sfnt.i16(bytes, 88) : void 0
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
const POST_HEADER_SIZE = 32;
|
|
55
|
+
const FIXED_16_16_SCALE = 65536;
|
|
56
|
+
function parsePost(font) {
|
|
57
|
+
const bytes = require_sfnt.sfntTableBytes(font, "post");
|
|
58
|
+
if (bytes === void 0 || !require_sfnt.hasBytes(bytes, 0, POST_HEADER_SIZE)) return;
|
|
59
|
+
return {
|
|
60
|
+
version: require_sfnt.u32(bytes, 0),
|
|
61
|
+
italicAngle: require_sfnt.i32(bytes, 4) / FIXED_16_16_SCALE,
|
|
62
|
+
underlinePosition: require_sfnt.i16(bytes, 8),
|
|
63
|
+
underlineThickness: require_sfnt.i16(bytes, 10)
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
const NAME_HEADER_SIZE = 6;
|
|
67
|
+
const NAME_RECORD_SIZE = 12;
|
|
68
|
+
const NAME_ID_FAMILY = 1;
|
|
69
|
+
const NAME_ID_POSTSCRIPT = 6;
|
|
70
|
+
const NAME_ID_TYPOGRAPHIC_FAMILY = 16;
|
|
71
|
+
const PLATFORM_UNICODE = 0;
|
|
72
|
+
const PLATFORM_MACINTOSH = 1;
|
|
73
|
+
const PLATFORM_WINDOWS = 3;
|
|
74
|
+
const WINDOWS_ENCODING_UNICODE_BMP = 1;
|
|
75
|
+
const MACINTOSH_ENCODING_ROMAN = 0;
|
|
76
|
+
function decodeUtf16Be(bytes, offset, length) {
|
|
77
|
+
let text = "";
|
|
78
|
+
for (let i = 0; i + 1 < length; i += 2) text += String.fromCharCode(bytes[offset + i] << 8 | bytes[offset + i + 1]);
|
|
79
|
+
return text;
|
|
80
|
+
}
|
|
81
|
+
function decodeMacRoman(bytes, offset, length) {
|
|
82
|
+
let text = "";
|
|
83
|
+
for (let i = 0; i < length; i++) text += String.fromCharCode(bytes[offset + i]);
|
|
84
|
+
return text;
|
|
85
|
+
}
|
|
86
|
+
function platformRank(record) {
|
|
87
|
+
if (record.platformId === PLATFORM_WINDOWS && record.encodingId === WINDOWS_ENCODING_UNICODE_BMP) return 0;
|
|
88
|
+
if (record.platformId === PLATFORM_UNICODE) return 1;
|
|
89
|
+
if (record.platformId === PLATFORM_MACINTOSH && record.encodingId === MACINTOSH_ENCODING_ROMAN) return 2;
|
|
90
|
+
return 3;
|
|
91
|
+
}
|
|
92
|
+
function readName(bytes, records, nameId) {
|
|
93
|
+
const matches = records.filter((record) => record.nameId === nameId && platformRank(record) < 3).sort((a, b) => platformRank(a) - platformRank(b));
|
|
94
|
+
for (const record of matches) {
|
|
95
|
+
if (!require_sfnt.hasBytes(bytes, record.stringOffset, record.length)) continue;
|
|
96
|
+
const text = record.platformId === PLATFORM_MACINTOSH ? decodeMacRoman(bytes, record.stringOffset, record.length) : decodeUtf16Be(bytes, record.stringOffset, record.length);
|
|
97
|
+
if (text.length > 0) return text;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
function parseName(font) {
|
|
101
|
+
const bytes = require_sfnt.sfntTableBytes(font, "name");
|
|
102
|
+
if (bytes === void 0 || !require_sfnt.hasBytes(bytes, 0, NAME_HEADER_SIZE)) return;
|
|
103
|
+
const count = require_sfnt.u16(bytes, 2);
|
|
104
|
+
const storageOffset = require_sfnt.u16(bytes, 4);
|
|
105
|
+
if (!require_sfnt.hasBytes(bytes, NAME_HEADER_SIZE, count * NAME_RECORD_SIZE)) return;
|
|
106
|
+
const records = [];
|
|
107
|
+
for (let i = 0; i < count; i++) {
|
|
108
|
+
const recordOffset = NAME_HEADER_SIZE + i * NAME_RECORD_SIZE;
|
|
109
|
+
records.push({
|
|
110
|
+
platformId: require_sfnt.u16(bytes, recordOffset),
|
|
111
|
+
encodingId: require_sfnt.u16(bytes, recordOffset + 2),
|
|
112
|
+
nameId: require_sfnt.u16(bytes, recordOffset + 6),
|
|
113
|
+
length: require_sfnt.u16(bytes, recordOffset + 8),
|
|
114
|
+
stringOffset: storageOffset + require_sfnt.u16(bytes, recordOffset + 10)
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
return {
|
|
118
|
+
postScriptName: readName(bytes, records, NAME_ID_POSTSCRIPT),
|
|
119
|
+
familyName: readName(bytes, records, NAME_ID_TYPOGRAPHIC_FAMILY) ?? readName(bytes, records, NAME_ID_FAMILY)
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
//#endregion
|
|
123
|
+
exports.parseHead = parseHead;
|
|
124
|
+
exports.parseMaxp = parseMaxp;
|
|
125
|
+
exports.parseName = parseName;
|
|
126
|
+
exports.parseOs2 = parseOs2;
|
|
127
|
+
exports.parsePost = parsePost;
|