pdf-codec 1.4.2 → 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 +56 -15
- 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 +36 -17
- package/dist/content-write.d.cts +9 -2
- package/dist/content-write.d.ts +9 -2
- package/dist/content-write.js +35 -16
- package/dist/crypto/aes.cjs +166 -0
- package/dist/crypto/aes.d.cts +6 -0
- package/dist/crypto/aes.d.ts +6 -0
- package/dist/crypto/aes.js +163 -0
- package/dist/crypto/md5.cjs +215 -0
- package/dist/crypto/md5.d.cts +4 -0
- package/dist/crypto/md5.d.ts +4 -0
- package/dist/crypto/md5.js +214 -0
- package/dist/crypto/rc4.cjs +29 -0
- package/dist/crypto/rc4.d.cts +4 -0
- package/dist/crypto/rc4.d.ts +4 -0
- package/dist/crypto/rc4.js +28 -0
- package/dist/crypto/sha2.cjs +261 -0
- package/dist/crypto/sha2.d.cts +6 -0
- package/dist/crypto/sha2.d.ts +6 -0
- package/dist/crypto/sha2.js +258 -0
- package/dist/diagnostics.cjs +7 -0
- package/dist/diagnostics.d.cts +4 -1
- package/dist/diagnostics.d.ts +4 -1
- package/dist/diagnostics.js +7 -1
- package/dist/document.cjs +38 -2
- package/dist/document.js +38 -2
- 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/encrypt.cjs +264 -0
- package/dist/encrypt.d.cts +11 -0
- package/dist/encrypt.d.ts +11 -0
- package/dist/encrypt.js +263 -0
- package/dist/filters.cjs +19 -1
- package/dist/filters.js +19 -1
- 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/image/ccitt.cjs +488 -0
- package/dist/image/ccitt.d.cts +17 -0
- package/dist/image/ccitt.d.ts +17 -0
- package/dist/image/ccitt.js +487 -0
- package/dist/images-read.cjs +1 -4
- package/dist/images-read.js +2 -5
- package/dist/index.cjs +8 -0
- package/dist/index.d.cts +7 -4
- package/dist/index.d.ts +7 -4
- package/dist/index.js +5 -3
- package/dist/interpret.cjs +173 -38
- package/dist/interpret.d.cts +27 -10
- package/dist/interpret.d.ts +27 -10
- package/dist/interpret.js +174 -39
- package/dist/math-font-write.cjs +3 -32
- package/dist/math-font-write.js +2 -31
- 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/{matrix-B3c2_a2f.d.cts → matrix-BHzJESll.d.cts} +2 -1
- package/dist/{matrix-B3c2_a2f.d.ts → matrix-BHzJESll.d.ts} +2 -1
- package/dist/matrix.cjs +2 -0
- package/dist/matrix.d.cts +2 -2
- package/dist/matrix.d.ts +2 -2
- package/dist/matrix.js +2 -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/objects.cjs +4 -0
- package/dist/objects.d.cts +2 -1
- package/dist/objects.d.ts +2 -1
- package/dist/objects.js +4 -1
- package/dist/read.cjs +43 -4
- package/dist/read.d.cts +1 -1
- package/dist/read.d.ts +1 -1
- package/dist/read.js +43 -4
- 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 +81 -11
- package/dist/write.d.cts +6 -0
- package/dist/write.d.ts +6 -0
- package/dist/write.js +82 -12
- 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/measure.d.cts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { t as FontRegistry } from "./font-registry-yby02snZ.cjs";
|
|
1
2
|
import { LayoutFont } from "document-schema.js";
|
|
2
3
|
//#region src/measure.d.ts
|
|
3
4
|
interface UnderlineMetrics {
|
|
@@ -12,9 +13,15 @@ interface TextMeasurer {
|
|
|
12
13
|
underlineAtSize(font: LayoutFont, sizePt: number): UnderlineMetrics;
|
|
13
14
|
horizontalScaleFor(font: LayoutFont): number;
|
|
14
15
|
}
|
|
16
|
+
type VerticalMetricPolicy = 'hhea' | 'os2Typo' | 'os2Win';
|
|
17
|
+
declare const DEFAULT_VERTICAL_METRIC_POLICY: VerticalMetricPolicy;
|
|
15
18
|
interface StandardFontMeasurerOptions {
|
|
16
19
|
readonly widthCorrectionByFamily?: Readonly<Record<string, number>>;
|
|
17
20
|
}
|
|
21
|
+
interface FontMeasurerOptions extends StandardFontMeasurerOptions {
|
|
22
|
+
readonly verticalMetrics?: VerticalMetricPolicy;
|
|
23
|
+
}
|
|
24
|
+
declare function createFontMeasurer(registry?: FontRegistry, options?: FontMeasurerOptions): TextMeasurer;
|
|
18
25
|
declare function createStandardFontMeasurer(options?: StandardFontMeasurerOptions): TextMeasurer;
|
|
19
26
|
//#endregion
|
|
20
|
-
export { StandardFontMeasurerOptions, TextMeasurer, UnderlineMetrics, createStandardFontMeasurer };
|
|
27
|
+
export { DEFAULT_VERTICAL_METRIC_POLICY, FontMeasurerOptions, StandardFontMeasurerOptions, TextMeasurer, UnderlineMetrics, VerticalMetricPolicy, createFontMeasurer, createStandardFontMeasurer };
|
package/dist/measure.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { t as FontRegistry } from "./font-registry-Cn7P9lAh.js";
|
|
1
2
|
import { LayoutFont } from "document-schema.js";
|
|
2
3
|
//#region src/measure.d.ts
|
|
3
4
|
interface UnderlineMetrics {
|
|
@@ -12,9 +13,15 @@ interface TextMeasurer {
|
|
|
12
13
|
underlineAtSize(font: LayoutFont, sizePt: number): UnderlineMetrics;
|
|
13
14
|
horizontalScaleFor(font: LayoutFont): number;
|
|
14
15
|
}
|
|
16
|
+
type VerticalMetricPolicy = 'hhea' | 'os2Typo' | 'os2Win';
|
|
17
|
+
declare const DEFAULT_VERTICAL_METRIC_POLICY: VerticalMetricPolicy;
|
|
15
18
|
interface StandardFontMeasurerOptions {
|
|
16
19
|
readonly widthCorrectionByFamily?: Readonly<Record<string, number>>;
|
|
17
20
|
}
|
|
21
|
+
interface FontMeasurerOptions extends StandardFontMeasurerOptions {
|
|
22
|
+
readonly verticalMetrics?: VerticalMetricPolicy;
|
|
23
|
+
}
|
|
24
|
+
declare function createFontMeasurer(registry?: FontRegistry, options?: FontMeasurerOptions): TextMeasurer;
|
|
18
25
|
declare function createStandardFontMeasurer(options?: StandardFontMeasurerOptions): TextMeasurer;
|
|
19
26
|
//#endregion
|
|
20
|
-
export { StandardFontMeasurerOptions, TextMeasurer, UnderlineMetrics, createStandardFontMeasurer };
|
|
27
|
+
export { DEFAULT_VERTICAL_METRIC_POLICY, FontMeasurerOptions, StandardFontMeasurerOptions, TextMeasurer, UnderlineMetrics, VerticalMetricPolicy, createFontMeasurer, createStandardFontMeasurer };
|
package/dist/measure.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { o as encodeForShow, t as STANDARD_METRICS } from "./afm-widths-Dxucrg7D.js";
|
|
2
|
-
import {
|
|
2
|
+
import { encodeForShowEmbedded } from "./embedded-font.js";
|
|
3
|
+
import { resolveFaceWithRegistry } from "./font-registry.js";
|
|
3
4
|
//#region src/measure.ts
|
|
5
|
+
const GLYPH_SPACE_UNITS_PER_EM = 1e3;
|
|
4
6
|
const DEFAULT_WIDTH_CORRECTIONS = {
|
|
5
7
|
calibri: .92,
|
|
6
8
|
aptos: .93,
|
|
@@ -12,42 +14,89 @@ const DEFAULT_WIDTH_CORRECTIONS = {
|
|
|
12
14
|
function normalizeFamilyKey(family) {
|
|
13
15
|
return family.toLowerCase().replace(/[^a-z0-9]/g, "");
|
|
14
16
|
}
|
|
15
|
-
|
|
17
|
+
const EMBEDDED_HORIZONTAL_SCALE = 1;
|
|
18
|
+
const DEFAULT_VERTICAL_METRIC_POLICY = "hhea";
|
|
19
|
+
function verticalMetricsFor(face, policy) {
|
|
20
|
+
const m = face.metrics;
|
|
21
|
+
const hhea = {
|
|
22
|
+
ascentGlyphSpace: m.ascentGlyphSpace,
|
|
23
|
+
descentGlyphSpace: m.descentGlyphSpace,
|
|
24
|
+
lineGapGlyphSpace: m.lineGapGlyphSpace
|
|
25
|
+
};
|
|
26
|
+
if (policy === "os2Typo") {
|
|
27
|
+
if (m.typoAscentGlyphSpace === void 0 || m.typoDescentGlyphSpace === void 0 || m.typoLineGapGlyphSpace === void 0) return hhea;
|
|
28
|
+
return {
|
|
29
|
+
ascentGlyphSpace: m.typoAscentGlyphSpace,
|
|
30
|
+
descentGlyphSpace: m.typoDescentGlyphSpace,
|
|
31
|
+
lineGapGlyphSpace: m.typoLineGapGlyphSpace
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
if (policy === "os2Win") {
|
|
35
|
+
if (m.winAscentGlyphSpace === void 0 || m.winDescentGlyphSpace === void 0) return hhea;
|
|
36
|
+
return {
|
|
37
|
+
ascentGlyphSpace: m.winAscentGlyphSpace,
|
|
38
|
+
descentGlyphSpace: m.winDescentGlyphSpace,
|
|
39
|
+
lineGapGlyphSpace: 0
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
return hhea;
|
|
43
|
+
}
|
|
44
|
+
function createFontMeasurer(registry, options = {}) {
|
|
16
45
|
const corrections = {
|
|
17
46
|
...DEFAULT_WIDTH_CORRECTIONS,
|
|
18
47
|
...options.widthCorrectionByFamily
|
|
19
48
|
};
|
|
20
|
-
|
|
49
|
+
const verticalPolicy = options.verticalMetrics ?? "hhea";
|
|
50
|
+
function standardWidthCorrectionFor(family) {
|
|
21
51
|
return corrections[normalizeFamilyKey(family)] ?? 1;
|
|
22
52
|
}
|
|
23
|
-
function
|
|
24
|
-
return
|
|
53
|
+
function resolve(font) {
|
|
54
|
+
return resolveFaceWithRegistry(registry, font);
|
|
25
55
|
}
|
|
26
56
|
return {
|
|
27
57
|
widthOfTextAtSize(text, font, sizePt) {
|
|
28
|
-
const
|
|
29
|
-
return width1000 /
|
|
58
|
+
const face = resolve(font);
|
|
59
|
+
if (face.kind === "embedded") return encodeForShowEmbedded(text, face.face).width1000 / GLYPH_SPACE_UNITS_PER_EM * sizePt;
|
|
60
|
+
const { width1000 } = encodeForShow(text, face.standardName);
|
|
61
|
+
return width1000 / GLYPH_SPACE_UNITS_PER_EM * sizePt * standardWidthCorrectionFor(font.family);
|
|
30
62
|
},
|
|
31
63
|
lineHeightAtSize(font, sizePt) {
|
|
32
|
-
|
|
64
|
+
const face = resolve(font);
|
|
65
|
+
if (face.kind === "embedded") {
|
|
66
|
+
const vertical = verticalMetricsFor(face.face, verticalPolicy);
|
|
67
|
+
return (vertical.ascentGlyphSpace - vertical.descentGlyphSpace + vertical.lineGapGlyphSpace) / GLYPH_SPACE_UNITS_PER_EM * sizePt;
|
|
68
|
+
}
|
|
69
|
+
return STANDARD_METRICS[face.standardName].lineHeightEm * sizePt;
|
|
33
70
|
},
|
|
34
71
|
ascenderAtSize(font, sizePt) {
|
|
35
|
-
|
|
72
|
+
const face = resolve(font);
|
|
73
|
+
if (face.kind === "embedded") return verticalMetricsFor(face.face, verticalPolicy).ascentGlyphSpace / GLYPH_SPACE_UNITS_PER_EM * sizePt;
|
|
74
|
+
return STANDARD_METRICS[face.standardName].ascender / GLYPH_SPACE_UNITS_PER_EM * sizePt;
|
|
36
75
|
},
|
|
37
76
|
descenderAtSize(font, sizePt) {
|
|
38
|
-
|
|
77
|
+
const face = resolve(font);
|
|
78
|
+
if (face.kind === "embedded") return verticalMetricsFor(face.face, verticalPolicy).descentGlyphSpace / GLYPH_SPACE_UNITS_PER_EM * sizePt;
|
|
79
|
+
return STANDARD_METRICS[face.standardName].descender / GLYPH_SPACE_UNITS_PER_EM * sizePt;
|
|
39
80
|
},
|
|
40
81
|
underlineAtSize(font, sizePt) {
|
|
41
|
-
const
|
|
82
|
+
const face = resolve(font);
|
|
83
|
+
if (face.kind === "embedded") return {
|
|
84
|
+
offsetPt: face.face.metrics.underlinePositionGlyphSpace / GLYPH_SPACE_UNITS_PER_EM * sizePt,
|
|
85
|
+
thicknessPt: face.face.metrics.underlineThicknessGlyphSpace / GLYPH_SPACE_UNITS_PER_EM * sizePt
|
|
86
|
+
};
|
|
87
|
+
const metrics = STANDARD_METRICS[face.standardName];
|
|
42
88
|
return {
|
|
43
|
-
offsetPt: metrics.underlinePosition /
|
|
44
|
-
thicknessPt: metrics.underlineThickness /
|
|
89
|
+
offsetPt: metrics.underlinePosition / GLYPH_SPACE_UNITS_PER_EM * sizePt,
|
|
90
|
+
thicknessPt: metrics.underlineThickness / GLYPH_SPACE_UNITS_PER_EM * sizePt
|
|
45
91
|
};
|
|
46
92
|
},
|
|
47
93
|
horizontalScaleFor(font) {
|
|
48
|
-
return
|
|
94
|
+
return resolve(font).kind === "embedded" ? EMBEDDED_HORIZONTAL_SCALE : standardWidthCorrectionFor(font.family);
|
|
49
95
|
}
|
|
50
96
|
};
|
|
51
97
|
}
|
|
98
|
+
function createStandardFontMeasurer(options = {}) {
|
|
99
|
+
return createFontMeasurer(void 0, options);
|
|
100
|
+
}
|
|
52
101
|
//#endregion
|
|
53
|
-
export { createStandardFontMeasurer };
|
|
102
|
+
export { DEFAULT_VERTICAL_METRIC_POLICY, createFontMeasurer, createStandardFontMeasurer };
|
package/dist/objects.cjs
CHANGED
|
@@ -70,6 +70,9 @@ function asNumber(obj) {
|
|
|
70
70
|
function asName(obj) {
|
|
71
71
|
return obj?.kind === "name" ? obj.name : void 0;
|
|
72
72
|
}
|
|
73
|
+
function asBool(obj) {
|
|
74
|
+
return obj?.kind === "bool" ? obj.value : void 0;
|
|
75
|
+
}
|
|
73
76
|
function asArray(obj) {
|
|
74
77
|
return obj?.kind === "array" ? obj.items : void 0;
|
|
75
78
|
}
|
|
@@ -83,6 +86,7 @@ function dictGet(dict, key) {
|
|
|
83
86
|
}
|
|
84
87
|
//#endregion
|
|
85
88
|
exports.asArray = asArray;
|
|
89
|
+
exports.asBool = asBool;
|
|
86
90
|
exports.asDict = asDict;
|
|
87
91
|
exports.asName = asName;
|
|
88
92
|
exports.asNumber = asNumber;
|
package/dist/objects.d.cts
CHANGED
|
@@ -51,8 +51,9 @@ declare function pdfRef(num: number, gen: number): PdfObject;
|
|
|
51
51
|
declare function isName(obj: PdfObject | undefined, name: string): boolean;
|
|
52
52
|
declare function asNumber(obj: PdfObject | undefined): number | undefined;
|
|
53
53
|
declare function asName(obj: PdfObject | undefined): string | undefined;
|
|
54
|
+
declare function asBool(obj: PdfObject | undefined): boolean | undefined;
|
|
54
55
|
declare function asArray(obj: PdfObject | undefined): PdfObject[] | undefined;
|
|
55
56
|
declare function asDict(obj: PdfObject | undefined): PdfDict | undefined;
|
|
56
57
|
declare function dictGet(dict: PdfDict, key: string): PdfObject | undefined;
|
|
57
58
|
//#endregion
|
|
58
|
-
export { PdfArray, PdfDict, PdfObject, PdfStream, asArray, asDict, asName, asNumber, dictGet, isName, pdfArray, pdfBool, pdfDict, pdfHexString, pdfLiteralString, pdfName, pdfNull, pdfNum, pdfRef, pdfStream };
|
|
59
|
+
export { PdfArray, PdfDict, PdfObject, PdfStream, asArray, asBool, asDict, asName, asNumber, dictGet, isName, pdfArray, pdfBool, pdfDict, pdfHexString, pdfLiteralString, pdfName, pdfNull, pdfNum, pdfRef, pdfStream };
|
package/dist/objects.d.ts
CHANGED
|
@@ -51,8 +51,9 @@ declare function pdfRef(num: number, gen: number): PdfObject;
|
|
|
51
51
|
declare function isName(obj: PdfObject | undefined, name: string): boolean;
|
|
52
52
|
declare function asNumber(obj: PdfObject | undefined): number | undefined;
|
|
53
53
|
declare function asName(obj: PdfObject | undefined): string | undefined;
|
|
54
|
+
declare function asBool(obj: PdfObject | undefined): boolean | undefined;
|
|
54
55
|
declare function asArray(obj: PdfObject | undefined): PdfObject[] | undefined;
|
|
55
56
|
declare function asDict(obj: PdfObject | undefined): PdfDict | undefined;
|
|
56
57
|
declare function dictGet(dict: PdfDict, key: string): PdfObject | undefined;
|
|
57
58
|
//#endregion
|
|
58
|
-
export { PdfArray, PdfDict, PdfObject, PdfStream, asArray, asDict, asName, asNumber, dictGet, isName, pdfArray, pdfBool, pdfDict, pdfHexString, pdfLiteralString, pdfName, pdfNull, pdfNum, pdfRef, pdfStream };
|
|
59
|
+
export { PdfArray, PdfDict, PdfObject, PdfStream, asArray, asBool, asDict, asName, asNumber, dictGet, isName, pdfArray, pdfBool, pdfDict, pdfHexString, pdfLiteralString, pdfName, pdfNull, pdfNum, pdfRef, pdfStream };
|
package/dist/objects.js
CHANGED
|
@@ -69,6 +69,9 @@ function asNumber(obj) {
|
|
|
69
69
|
function asName(obj) {
|
|
70
70
|
return obj?.kind === "name" ? obj.name : void 0;
|
|
71
71
|
}
|
|
72
|
+
function asBool(obj) {
|
|
73
|
+
return obj?.kind === "bool" ? obj.value : void 0;
|
|
74
|
+
}
|
|
72
75
|
function asArray(obj) {
|
|
73
76
|
return obj?.kind === "array" ? obj.items : void 0;
|
|
74
77
|
}
|
|
@@ -81,4 +84,4 @@ function dictGet(dict, key) {
|
|
|
81
84
|
return dict.entries.get(key);
|
|
82
85
|
}
|
|
83
86
|
//#endregion
|
|
84
|
-
export { asArray, asDict, asName, asNumber, dictGet, isName, pdfArray, pdfBool, pdfDict, pdfHexString, pdfLiteralString, pdfName, pdfNull, pdfNum, pdfRef, pdfStream };
|
|
87
|
+
export { asArray, asBool, asDict, asName, asNumber, dictGet, isName, pdfArray, pdfBool, pdfDict, pdfHexString, pdfLiteralString, pdfName, pdfNull, pdfNum, pdfRef, pdfStream };
|
package/dist/read.cjs
CHANGED
|
@@ -169,6 +169,8 @@ function readPage(page, resolver, fontResolver, images, imageIdCache, sink) {
|
|
|
169
169
|
function convertExtractedItem(item, pageMatrix, fontResolver, images, imageIdCache, resolver, sink) {
|
|
170
170
|
if (item.kind === "text") return convertText(item, pageMatrix, fontResolver);
|
|
171
171
|
if (item.kind === "rect") return convertRect(item, pageMatrix);
|
|
172
|
+
if (item.kind === "ellipse") return convertEllipse(item, pageMatrix);
|
|
173
|
+
if (item.kind === "line") return convertLine(item, pageMatrix);
|
|
172
174
|
if (item.kind === "path") return convertPath(item, pageMatrix);
|
|
173
175
|
if (item.kind === "image") return convertImage(item, pageMatrix, images, imageIdCache, resolver, sink);
|
|
174
176
|
return convertInlineImage(item, pageMatrix, images, resolver, sink);
|
|
@@ -199,7 +201,13 @@ function convertText(item, pageMatrix, fontResolver) {
|
|
|
199
201
|
rotationDeg: rotationDeg !== 0 ? rotationDeg : void 0
|
|
200
202
|
};
|
|
201
203
|
}
|
|
202
|
-
function
|
|
204
|
+
function paintFields(paint) {
|
|
205
|
+
return {
|
|
206
|
+
...paint.fill !== void 0 ? { fill: paint.fill } : {},
|
|
207
|
+
...paint.stroke !== void 0 ? { stroke: paint.stroke } : {}
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
function transformBox(item, pageMatrix) {
|
|
203
211
|
const p1 = require_matrix.applyMatrix(pageMatrix, {
|
|
204
212
|
x: item.xPt,
|
|
205
213
|
y: item.yPt
|
|
@@ -209,12 +217,43 @@ function convertRect(item, pageMatrix) {
|
|
|
209
217
|
y: item.yPt + item.heightPt
|
|
210
218
|
});
|
|
211
219
|
return {
|
|
212
|
-
kind: "rect",
|
|
213
220
|
xPt: Math.min(p1.x, p2.x),
|
|
214
221
|
yPt: Math.min(p1.y, p2.y),
|
|
215
222
|
widthPt: Math.abs(p2.x - p1.x),
|
|
216
|
-
heightPt: Math.abs(p2.y - p1.y)
|
|
217
|
-
|
|
223
|
+
heightPt: Math.abs(p2.y - p1.y)
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
function convertRect(item, pageMatrix) {
|
|
227
|
+
return {
|
|
228
|
+
kind: "rect",
|
|
229
|
+
...transformBox(item, pageMatrix),
|
|
230
|
+
...paintFields(item)
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
function convertEllipse(item, pageMatrix) {
|
|
234
|
+
return {
|
|
235
|
+
kind: "ellipse",
|
|
236
|
+
...transformBox(item, pageMatrix),
|
|
237
|
+
...paintFields(item)
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
function convertLine(item, pageMatrix) {
|
|
241
|
+
const p1 = require_matrix.applyMatrix(pageMatrix, {
|
|
242
|
+
x: item.x1Pt,
|
|
243
|
+
y: item.y1Pt
|
|
244
|
+
});
|
|
245
|
+
const p2 = require_matrix.applyMatrix(pageMatrix, {
|
|
246
|
+
x: item.x2Pt,
|
|
247
|
+
y: item.y2Pt
|
|
248
|
+
});
|
|
249
|
+
return {
|
|
250
|
+
kind: "line",
|
|
251
|
+
x1Pt: p1.x,
|
|
252
|
+
y1Pt: p1.y,
|
|
253
|
+
x2Pt: p2.x,
|
|
254
|
+
y2Pt: p2.y,
|
|
255
|
+
color: item.color,
|
|
256
|
+
widthPt: item.widthPt
|
|
218
257
|
};
|
|
219
258
|
}
|
|
220
259
|
function transformSubpath(subpath, pageMatrix) {
|
package/dist/read.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { PdfDiagnosticSink } from "./diagnostics.cjs";
|
|
2
|
-
import {
|
|
2
|
+
import { r as Matrix } from "./matrix-BHzJESll.cjs";
|
|
3
3
|
import { LayoutDocument } from "document-schema.js";
|
|
4
4
|
//#region src/read.d.ts
|
|
5
5
|
interface ReadPdfOptions {
|
package/dist/read.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { PdfDiagnosticSink } from "./diagnostics.js";
|
|
2
|
-
import {
|
|
2
|
+
import { r as Matrix } from "./matrix-BHzJESll.js";
|
|
3
3
|
import { LayoutDocument } from "document-schema.js";
|
|
4
4
|
//#region src/read.d.ts
|
|
5
5
|
interface ReadPdfOptions {
|
package/dist/read.js
CHANGED
|
@@ -168,6 +168,8 @@ function readPage(page, resolver, fontResolver, images, imageIdCache, sink) {
|
|
|
168
168
|
function convertExtractedItem(item, pageMatrix, fontResolver, images, imageIdCache, resolver, sink) {
|
|
169
169
|
if (item.kind === "text") return convertText(item, pageMatrix, fontResolver);
|
|
170
170
|
if (item.kind === "rect") return convertRect(item, pageMatrix);
|
|
171
|
+
if (item.kind === "ellipse") return convertEllipse(item, pageMatrix);
|
|
172
|
+
if (item.kind === "line") return convertLine(item, pageMatrix);
|
|
171
173
|
if (item.kind === "path") return convertPath(item, pageMatrix);
|
|
172
174
|
if (item.kind === "image") return convertImage(item, pageMatrix, images, imageIdCache, resolver, sink);
|
|
173
175
|
return convertInlineImage(item, pageMatrix, images, resolver, sink);
|
|
@@ -198,7 +200,13 @@ function convertText(item, pageMatrix, fontResolver) {
|
|
|
198
200
|
rotationDeg: rotationDeg !== 0 ? rotationDeg : void 0
|
|
199
201
|
};
|
|
200
202
|
}
|
|
201
|
-
function
|
|
203
|
+
function paintFields(paint) {
|
|
204
|
+
return {
|
|
205
|
+
...paint.fill !== void 0 ? { fill: paint.fill } : {},
|
|
206
|
+
...paint.stroke !== void 0 ? { stroke: paint.stroke } : {}
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
function transformBox(item, pageMatrix) {
|
|
202
210
|
const p1 = applyMatrix(pageMatrix, {
|
|
203
211
|
x: item.xPt,
|
|
204
212
|
y: item.yPt
|
|
@@ -208,12 +216,43 @@ function convertRect(item, pageMatrix) {
|
|
|
208
216
|
y: item.yPt + item.heightPt
|
|
209
217
|
});
|
|
210
218
|
return {
|
|
211
|
-
kind: "rect",
|
|
212
219
|
xPt: Math.min(p1.x, p2.x),
|
|
213
220
|
yPt: Math.min(p1.y, p2.y),
|
|
214
221
|
widthPt: Math.abs(p2.x - p1.x),
|
|
215
|
-
heightPt: Math.abs(p2.y - p1.y)
|
|
216
|
-
|
|
222
|
+
heightPt: Math.abs(p2.y - p1.y)
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
function convertRect(item, pageMatrix) {
|
|
226
|
+
return {
|
|
227
|
+
kind: "rect",
|
|
228
|
+
...transformBox(item, pageMatrix),
|
|
229
|
+
...paintFields(item)
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
function convertEllipse(item, pageMatrix) {
|
|
233
|
+
return {
|
|
234
|
+
kind: "ellipse",
|
|
235
|
+
...transformBox(item, pageMatrix),
|
|
236
|
+
...paintFields(item)
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
function convertLine(item, pageMatrix) {
|
|
240
|
+
const p1 = applyMatrix(pageMatrix, {
|
|
241
|
+
x: item.x1Pt,
|
|
242
|
+
y: item.y1Pt
|
|
243
|
+
});
|
|
244
|
+
const p2 = applyMatrix(pageMatrix, {
|
|
245
|
+
x: item.x2Pt,
|
|
246
|
+
y: item.y2Pt
|
|
247
|
+
});
|
|
248
|
+
return {
|
|
249
|
+
kind: "line",
|
|
250
|
+
x1Pt: p1.x,
|
|
251
|
+
y1Pt: p1.y,
|
|
252
|
+
x2Pt: p2.x,
|
|
253
|
+
y2Pt: p2.y,
|
|
254
|
+
color: item.color,
|
|
255
|
+
widthPt: item.widthPt
|
|
217
256
|
};
|
|
218
257
|
}
|
|
219
258
|
function transformSubpath(subpath, pageMatrix) {
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
//#region src/sfnt.d.ts
|
|
2
|
+
interface SfntTable {
|
|
3
|
+
readonly offset: number;
|
|
4
|
+
readonly length: number;
|
|
5
|
+
}
|
|
6
|
+
interface SfntFont {
|
|
7
|
+
readonly bytes: Uint8Array<ArrayBuffer>;
|
|
8
|
+
readonly tables: ReadonlyMap<string, SfntTable>;
|
|
9
|
+
}
|
|
10
|
+
declare function hasBytes(bytes: Uint8Array<ArrayBuffer>, offset: number, length: number): boolean;
|
|
11
|
+
declare function parseSfnt(bytes: Uint8Array<ArrayBuffer>): SfntFont | undefined;
|
|
12
|
+
declare function sfntTableBytes(font: SfntFont, tag: string): Uint8Array<ArrayBuffer> | undefined;
|
|
13
|
+
declare function u8(bytes: Uint8Array<ArrayBuffer>, offset: number): number;
|
|
14
|
+
declare function u16(bytes: Uint8Array<ArrayBuffer>, offset: number): number;
|
|
15
|
+
declare function i16(bytes: Uint8Array<ArrayBuffer>, offset: number): number;
|
|
16
|
+
declare function u24(bytes: Uint8Array<ArrayBuffer>, offset: number): number;
|
|
17
|
+
declare function u32(bytes: Uint8Array<ArrayBuffer>, offset: number): number;
|
|
18
|
+
declare function i32(bytes: Uint8Array<ArrayBuffer>, offset: number): number;
|
|
19
|
+
declare function f2dot14(bytes: Uint8Array<ArrayBuffer>, offset: number): number;
|
|
20
|
+
//#endregion
|
|
21
|
+
export { i16 as a, sfntTableBytes as c, u32 as d, u8 as f, hasBytes as i, u16 as l, SfntTable as n, i32 as o, f2dot14 as r, parseSfnt as s, SfntFont as t, u24 as u };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
//#region src/sfnt.d.ts
|
|
2
|
+
interface SfntTable {
|
|
3
|
+
readonly offset: number;
|
|
4
|
+
readonly length: number;
|
|
5
|
+
}
|
|
6
|
+
interface SfntFont {
|
|
7
|
+
readonly bytes: Uint8Array<ArrayBuffer>;
|
|
8
|
+
readonly tables: ReadonlyMap<string, SfntTable>;
|
|
9
|
+
}
|
|
10
|
+
declare function hasBytes(bytes: Uint8Array<ArrayBuffer>, offset: number, length: number): boolean;
|
|
11
|
+
declare function parseSfnt(bytes: Uint8Array<ArrayBuffer>): SfntFont | undefined;
|
|
12
|
+
declare function sfntTableBytes(font: SfntFont, tag: string): Uint8Array<ArrayBuffer> | undefined;
|
|
13
|
+
declare function u8(bytes: Uint8Array<ArrayBuffer>, offset: number): number;
|
|
14
|
+
declare function u16(bytes: Uint8Array<ArrayBuffer>, offset: number): number;
|
|
15
|
+
declare function i16(bytes: Uint8Array<ArrayBuffer>, offset: number): number;
|
|
16
|
+
declare function u24(bytes: Uint8Array<ArrayBuffer>, offset: number): number;
|
|
17
|
+
declare function u32(bytes: Uint8Array<ArrayBuffer>, offset: number): number;
|
|
18
|
+
declare function i32(bytes: Uint8Array<ArrayBuffer>, offset: number): number;
|
|
19
|
+
declare function f2dot14(bytes: Uint8Array<ArrayBuffer>, offset: number): number;
|
|
20
|
+
//#endregion
|
|
21
|
+
export { i16 as a, sfntTableBytes as c, u32 as d, u8 as f, hasBytes as i, u16 as l, SfntTable as n, i32 as o, f2dot14 as r, parseSfnt as s, SfntFont as t, u24 as u };
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_sfnt = require("./sfnt.cjs");
|
|
3
|
+
const require_cmap_table = require("./cmap-table.cjs");
|
|
4
|
+
const require_font_tables = require("./font-tables.cjs");
|
|
5
|
+
const require_glyf = require("./glyf.cjs");
|
|
6
|
+
//#region src/sfnt-subset.ts
|
|
7
|
+
const HEAD_TABLE_SIZE = 54;
|
|
8
|
+
const HEAD_CHECKSUM_ADJUSTMENT_OFFSET = 8;
|
|
9
|
+
const HEAD_INDEX_TO_LOC_FORMAT_OFFSET = 50;
|
|
10
|
+
const INDEX_TO_LOC_FORMAT_LONG = 1;
|
|
11
|
+
const HHEA_TABLE_SIZE = 36;
|
|
12
|
+
const HHEA_NUMBER_OF_HMETRICS_OFFSET = 34;
|
|
13
|
+
const MAXP_MIN_SIZE = 6;
|
|
14
|
+
const MAXP_NUM_GLYPHS_OFFSET = 4;
|
|
15
|
+
const POST_STUB_SIZE = 32;
|
|
16
|
+
const POST_VERSION_3_0 = 196608;
|
|
17
|
+
const POST_METRICS_OFFSET = 4;
|
|
18
|
+
const POST_METRICS_SIZE = 12;
|
|
19
|
+
const LONG_HOR_METRIC_SIZE = 4;
|
|
20
|
+
const LEFT_SIDE_BEARING_SIZE = 2;
|
|
21
|
+
const LOCA_LONG_ENTRY_SIZE = 4;
|
|
22
|
+
const TABLE_DIRECTORY_HEADER_SIZE = 12;
|
|
23
|
+
const TABLE_RECORD_SIZE = 16;
|
|
24
|
+
const SFNT_VERSION_TRUETYPE = 65536;
|
|
25
|
+
const CHECKSUM_ADJUSTMENT_MAGIC = 2981146554;
|
|
26
|
+
const GLYPH_ALIGNMENT = 4;
|
|
27
|
+
const COPIED_TAGS = [
|
|
28
|
+
"cvt ",
|
|
29
|
+
"fpgm",
|
|
30
|
+
"prep"
|
|
31
|
+
];
|
|
32
|
+
function alignUp(value) {
|
|
33
|
+
return Math.ceil(value / GLYPH_ALIGNMENT) * GLYPH_ALIGNMENT;
|
|
34
|
+
}
|
|
35
|
+
function writeU16(bytes, offset, value) {
|
|
36
|
+
bytes[offset] = value >>> 8 & 255;
|
|
37
|
+
bytes[offset + 1] = value & 255;
|
|
38
|
+
}
|
|
39
|
+
function writeU32(bytes, offset, value) {
|
|
40
|
+
bytes[offset] = value >>> 24 & 255;
|
|
41
|
+
bytes[offset + 1] = value >>> 16 & 255;
|
|
42
|
+
bytes[offset + 2] = value >>> 8 & 255;
|
|
43
|
+
bytes[offset + 3] = value & 255;
|
|
44
|
+
}
|
|
45
|
+
function checksum(bytes, offset, length) {
|
|
46
|
+
let sum = 0;
|
|
47
|
+
for (let i = 0; i < length; i += GLYPH_ALIGNMENT) sum = sum + require_sfnt.u32(bytes, offset + i) >>> 0;
|
|
48
|
+
return sum;
|
|
49
|
+
}
|
|
50
|
+
function readHorizontalMetrics(source, glyphId) {
|
|
51
|
+
if (glyphId < source.numberOfHMetrics) {
|
|
52
|
+
const offset = glyphId * LONG_HOR_METRIC_SIZE;
|
|
53
|
+
if (!require_sfnt.hasBytes(source.bytes, offset, LONG_HOR_METRIC_SIZE)) return;
|
|
54
|
+
return {
|
|
55
|
+
advanceWidth: require_sfnt.u16(source.bytes, offset),
|
|
56
|
+
leftSideBearing: require_sfnt.u16(source.bytes, offset + 2)
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
const lastAdvanceOffset = (source.numberOfHMetrics - 1) * LONG_HOR_METRIC_SIZE;
|
|
60
|
+
const bearingOffset = source.numberOfHMetrics * LONG_HOR_METRIC_SIZE + (glyphId - source.numberOfHMetrics) * LEFT_SIDE_BEARING_SIZE;
|
|
61
|
+
if (!require_sfnt.hasBytes(source.bytes, lastAdvanceOffset, LONG_HOR_METRIC_SIZE) || !require_sfnt.hasBytes(source.bytes, bearingOffset, LEFT_SIDE_BEARING_SIZE)) return;
|
|
62
|
+
return {
|
|
63
|
+
advanceWidth: require_sfnt.u16(source.bytes, lastAdvanceOffset),
|
|
64
|
+
leftSideBearing: require_sfnt.u16(source.bytes, bearingOffset)
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
function buildPostStub(font) {
|
|
68
|
+
const post = new Uint8Array(POST_STUB_SIZE);
|
|
69
|
+
writeU32(post, 0, POST_VERSION_3_0);
|
|
70
|
+
const sourcePost = require_sfnt.sfntTableBytes(font, "post");
|
|
71
|
+
if (sourcePost !== void 0 && require_sfnt.hasBytes(sourcePost, POST_METRICS_OFFSET, POST_METRICS_SIZE)) post.set(sourcePost.subarray(POST_METRICS_OFFSET, 16), POST_METRICS_OFFSET);
|
|
72
|
+
return post;
|
|
73
|
+
}
|
|
74
|
+
function collectGlyphIds(glyf, cmap, numGlyphs, codePoints) {
|
|
75
|
+
const used = /* @__PURE__ */ new Set([0]);
|
|
76
|
+
const unmapped = /* @__PURE__ */ new Set();
|
|
77
|
+
const pending = [0];
|
|
78
|
+
for (const codePoint of codePoints) {
|
|
79
|
+
const glyphId = cmap(codePoint);
|
|
80
|
+
if (glyphId === void 0) {
|
|
81
|
+
unmapped.add(codePoint);
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
if (glyphId >= numGlyphs) return;
|
|
85
|
+
if (!used.has(glyphId)) {
|
|
86
|
+
used.add(glyphId);
|
|
87
|
+
pending.push(glyphId);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
while (pending.length > 0) {
|
|
91
|
+
const glyphId = pending.pop();
|
|
92
|
+
if (glyf.glyphBytes(glyphId) === void 0) return;
|
|
93
|
+
const header = glyf.glyphHeader(glyphId);
|
|
94
|
+
if (header === void 0 || header.numberOfContours >= 0) continue;
|
|
95
|
+
const components = glyf.compositeComponents(glyphId);
|
|
96
|
+
if (components === void 0) return;
|
|
97
|
+
for (const component of components) {
|
|
98
|
+
if (component.glyphIndex >= numGlyphs) return;
|
|
99
|
+
if (!used.has(component.glyphIndex)) {
|
|
100
|
+
used.add(component.glyphIndex);
|
|
101
|
+
pending.push(component.glyphIndex);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return {
|
|
106
|
+
used,
|
|
107
|
+
unmapped: [...unmapped].sort((a, b) => a - b)
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
function subsetSfnt(font, codePoints) {
|
|
111
|
+
const head = require_font_tables.parseHead(font);
|
|
112
|
+
const maxp = require_font_tables.parseMaxp(font);
|
|
113
|
+
const sourceHead = require_sfnt.sfntTableBytes(font, "head");
|
|
114
|
+
const sourceHhea = require_sfnt.sfntTableBytes(font, "hhea");
|
|
115
|
+
const sourceMaxp = require_sfnt.sfntTableBytes(font, "maxp");
|
|
116
|
+
const sourceHmtx = require_sfnt.sfntTableBytes(font, "hmtx");
|
|
117
|
+
if (head === void 0 || maxp === void 0 || sourceHead === void 0 || sourceHhea === void 0 || sourceMaxp === void 0 || sourceHmtx === void 0) return;
|
|
118
|
+
if (!require_sfnt.hasBytes(sourceHead, 0, HEAD_TABLE_SIZE) || !require_sfnt.hasBytes(sourceHhea, 0, HHEA_TABLE_SIZE) || !require_sfnt.hasBytes(sourceMaxp, 0, MAXP_MIN_SIZE)) return;
|
|
119
|
+
const numberOfHMetrics = require_sfnt.u16(sourceHhea, HHEA_NUMBER_OF_HMETRICS_OFFSET);
|
|
120
|
+
if (numberOfHMetrics === 0) return;
|
|
121
|
+
const glyf = require_glyf.parseGlyf(font, {
|
|
122
|
+
numGlyphs: maxp.numGlyphs,
|
|
123
|
+
indexToLocFormat: head.indexToLocFormat
|
|
124
|
+
});
|
|
125
|
+
const cmap = require_cmap_table.buildCmapLookup(font);
|
|
126
|
+
if (glyf === void 0 || cmap === void 0) return;
|
|
127
|
+
const collected = collectGlyphIds(glyf, cmap, maxp.numGlyphs, codePoints);
|
|
128
|
+
if (collected === void 0) return;
|
|
129
|
+
const glyphIds = [...collected.used].sort((a, b) => a - b);
|
|
130
|
+
const numGlyphs = glyphIds[glyphIds.length - 1] + 1;
|
|
131
|
+
const outlines = /* @__PURE__ */ new Map();
|
|
132
|
+
let glyfLength = 0;
|
|
133
|
+
for (const glyphId of glyphIds) {
|
|
134
|
+
const bytes = glyf.glyphBytes(glyphId);
|
|
135
|
+
if (bytes === void 0) return;
|
|
136
|
+
outlines.set(glyphId, bytes);
|
|
137
|
+
glyfLength += alignUp(bytes.length);
|
|
138
|
+
}
|
|
139
|
+
const glyfData = new Uint8Array(glyfLength);
|
|
140
|
+
const locaData = new Uint8Array((numGlyphs + 1) * LOCA_LONG_ENTRY_SIZE);
|
|
141
|
+
let glyfOffset = 0;
|
|
142
|
+
for (let glyphId = 0; glyphId < numGlyphs; glyphId++) {
|
|
143
|
+
writeU32(locaData, glyphId * LOCA_LONG_ENTRY_SIZE, glyfOffset);
|
|
144
|
+
const bytes = outlines.get(glyphId);
|
|
145
|
+
if (bytes === void 0) continue;
|
|
146
|
+
glyfData.set(bytes, glyfOffset);
|
|
147
|
+
glyfOffset += alignUp(bytes.length);
|
|
148
|
+
}
|
|
149
|
+
writeU32(locaData, numGlyphs * LOCA_LONG_ENTRY_SIZE, glyfOffset);
|
|
150
|
+
const hmtxData = new Uint8Array(numGlyphs * LONG_HOR_METRIC_SIZE);
|
|
151
|
+
for (let glyphId = 0; glyphId < numGlyphs; glyphId++) {
|
|
152
|
+
const metrics = readHorizontalMetrics({
|
|
153
|
+
bytes: sourceHmtx,
|
|
154
|
+
numberOfHMetrics
|
|
155
|
+
}, glyphId);
|
|
156
|
+
if (metrics === void 0) return;
|
|
157
|
+
writeU16(hmtxData, glyphId * LONG_HOR_METRIC_SIZE, metrics.advanceWidth);
|
|
158
|
+
writeU16(hmtxData, glyphId * LONG_HOR_METRIC_SIZE + 2, metrics.leftSideBearing);
|
|
159
|
+
}
|
|
160
|
+
const headData = new Uint8Array(HEAD_TABLE_SIZE);
|
|
161
|
+
headData.set(sourceHead.subarray(0, HEAD_TABLE_SIZE));
|
|
162
|
+
writeU32(headData, HEAD_CHECKSUM_ADJUSTMENT_OFFSET, 0);
|
|
163
|
+
writeU16(headData, HEAD_INDEX_TO_LOC_FORMAT_OFFSET, INDEX_TO_LOC_FORMAT_LONG);
|
|
164
|
+
const hheaData = new Uint8Array(HHEA_TABLE_SIZE);
|
|
165
|
+
hheaData.set(sourceHhea.subarray(0, HHEA_TABLE_SIZE));
|
|
166
|
+
writeU16(hheaData, HHEA_NUMBER_OF_HMETRICS_OFFSET, numGlyphs);
|
|
167
|
+
const maxpData = new Uint8Array(sourceMaxp.length);
|
|
168
|
+
maxpData.set(sourceMaxp);
|
|
169
|
+
writeU16(maxpData, MAXP_NUM_GLYPHS_OFFSET, numGlyphs);
|
|
170
|
+
const tables = [
|
|
171
|
+
{
|
|
172
|
+
tag: "glyf",
|
|
173
|
+
data: glyfData
|
|
174
|
+
},
|
|
175
|
+
{
|
|
176
|
+
tag: "head",
|
|
177
|
+
data: headData
|
|
178
|
+
},
|
|
179
|
+
{
|
|
180
|
+
tag: "hhea",
|
|
181
|
+
data: hheaData
|
|
182
|
+
},
|
|
183
|
+
{
|
|
184
|
+
tag: "hmtx",
|
|
185
|
+
data: hmtxData
|
|
186
|
+
},
|
|
187
|
+
{
|
|
188
|
+
tag: "loca",
|
|
189
|
+
data: locaData
|
|
190
|
+
},
|
|
191
|
+
{
|
|
192
|
+
tag: "maxp",
|
|
193
|
+
data: maxpData
|
|
194
|
+
},
|
|
195
|
+
{
|
|
196
|
+
tag: "post",
|
|
197
|
+
data: buildPostStub(font)
|
|
198
|
+
}
|
|
199
|
+
];
|
|
200
|
+
for (const tag of COPIED_TAGS) {
|
|
201
|
+
const bytes = require_sfnt.sfntTableBytes(font, tag);
|
|
202
|
+
if (bytes !== void 0) {
|
|
203
|
+
const copy = new Uint8Array(bytes.length);
|
|
204
|
+
copy.set(bytes);
|
|
205
|
+
tables.push({
|
|
206
|
+
tag,
|
|
207
|
+
data: copy
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
tables.sort((a, b) => a.tag < b.tag ? -1 : 1);
|
|
212
|
+
const numTables = tables.length;
|
|
213
|
+
let entrySelector = 0;
|
|
214
|
+
while (1 << entrySelector + 1 <= numTables) entrySelector++;
|
|
215
|
+
const searchRange = (1 << entrySelector) * TABLE_RECORD_SIZE;
|
|
216
|
+
const rangeShift = numTables * TABLE_RECORD_SIZE - searchRange;
|
|
217
|
+
const directorySize = TABLE_DIRECTORY_HEADER_SIZE + numTables * TABLE_RECORD_SIZE;
|
|
218
|
+
const offsets = [];
|
|
219
|
+
let fileLength = alignUp(directorySize);
|
|
220
|
+
for (const table of tables) {
|
|
221
|
+
offsets.push(fileLength);
|
|
222
|
+
fileLength += alignUp(table.data.length);
|
|
223
|
+
}
|
|
224
|
+
const file = new Uint8Array(fileLength);
|
|
225
|
+
writeU32(file, 0, SFNT_VERSION_TRUETYPE);
|
|
226
|
+
writeU16(file, 4, numTables);
|
|
227
|
+
writeU16(file, 6, searchRange);
|
|
228
|
+
writeU16(file, 8, entrySelector);
|
|
229
|
+
writeU16(file, 10, rangeShift);
|
|
230
|
+
for (let i = 0; i < numTables; i++) {
|
|
231
|
+
const table = tables[i];
|
|
232
|
+
const tableOffset = offsets[i];
|
|
233
|
+
file.set(table.data, tableOffset);
|
|
234
|
+
const recordOffset = TABLE_DIRECTORY_HEADER_SIZE + i * TABLE_RECORD_SIZE;
|
|
235
|
+
for (let c = 0; c < table.tag.length; c++) file[recordOffset + c] = table.tag.charCodeAt(c);
|
|
236
|
+
writeU32(file, recordOffset + 4, checksum(file, tableOffset, alignUp(table.data.length)));
|
|
237
|
+
writeU32(file, recordOffset + 8, tableOffset);
|
|
238
|
+
writeU32(file, recordOffset + 12, table.data.length);
|
|
239
|
+
}
|
|
240
|
+
const headOffsetInFile = offsets[tables.findIndex((table) => table.tag === "head")];
|
|
241
|
+
writeU32(file, headOffsetInFile + HEAD_CHECKSUM_ADJUSTMENT_OFFSET, CHECKSUM_ADJUSTMENT_MAGIC - checksum(file, 0, fileLength) >>> 0);
|
|
242
|
+
return {
|
|
243
|
+
bytes: file,
|
|
244
|
+
numGlyphs,
|
|
245
|
+
glyphIds,
|
|
246
|
+
unmappedCodePoints: collected.unmapped
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
//#endregion
|
|
250
|
+
exports.subsetSfnt = subsetSfnt;
|