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/glyf.cjs
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_sfnt = require("./sfnt.cjs");
|
|
3
|
+
//#region src/glyf.ts
|
|
4
|
+
const LOCA_SHORT_ENTRY_SIZE = 2;
|
|
5
|
+
const LOCA_LONG_ENTRY_SIZE = 4;
|
|
6
|
+
const LOCA_SHORT_OFFSET_SCALE = 2;
|
|
7
|
+
function parseLoca(font, options) {
|
|
8
|
+
const bytes = require_sfnt.sfntTableBytes(font, "loca");
|
|
9
|
+
if (bytes === void 0) return;
|
|
10
|
+
const entryCount = options.numGlyphs + 1;
|
|
11
|
+
const entrySize = options.indexToLocFormat === 0 ? LOCA_SHORT_ENTRY_SIZE : LOCA_LONG_ENTRY_SIZE;
|
|
12
|
+
if (!require_sfnt.hasBytes(bytes, 0, entryCount * entrySize)) return;
|
|
13
|
+
const offsets = [];
|
|
14
|
+
for (let i = 0; i < entryCount; i++) offsets.push(options.indexToLocFormat === 0 ? require_sfnt.u16(bytes, i * LOCA_SHORT_ENTRY_SIZE) * LOCA_SHORT_OFFSET_SCALE : require_sfnt.u32(bytes, i * LOCA_LONG_ENTRY_SIZE));
|
|
15
|
+
return offsets;
|
|
16
|
+
}
|
|
17
|
+
const GLYPH_HEADER_SIZE = 10;
|
|
18
|
+
const ARG_1_AND_2_ARE_WORDS = 1;
|
|
19
|
+
const ARGS_ARE_XY_VALUES = 2;
|
|
20
|
+
const WE_HAVE_A_SCALE = 8;
|
|
21
|
+
const MORE_COMPONENTS = 32;
|
|
22
|
+
const WE_HAVE_AN_X_AND_Y_SCALE = 64;
|
|
23
|
+
const WE_HAVE_A_TWO_BY_TWO = 128;
|
|
24
|
+
const COMPONENT_RECORD_HEADER_SIZE = 4;
|
|
25
|
+
function signedByte(value) {
|
|
26
|
+
return value >= 128 ? value - 256 : value;
|
|
27
|
+
}
|
|
28
|
+
function readComponents(glyph) {
|
|
29
|
+
const components = [];
|
|
30
|
+
let offset = GLYPH_HEADER_SIZE;
|
|
31
|
+
for (;;) {
|
|
32
|
+
if (!require_sfnt.hasBytes(glyph, offset, COMPONENT_RECORD_HEADER_SIZE)) return;
|
|
33
|
+
const flags = require_sfnt.u16(glyph, offset);
|
|
34
|
+
const glyphIndex = require_sfnt.u16(glyph, offset + 2);
|
|
35
|
+
offset += COMPONENT_RECORD_HEADER_SIZE;
|
|
36
|
+
const argsAreWords = (flags & ARG_1_AND_2_ARE_WORDS) !== 0;
|
|
37
|
+
const argsAreXyValues = (flags & ARGS_ARE_XY_VALUES) !== 0;
|
|
38
|
+
const argsSize = argsAreWords ? 4 : 2;
|
|
39
|
+
if (!require_sfnt.hasBytes(glyph, offset, argsSize)) return;
|
|
40
|
+
let argument1;
|
|
41
|
+
let argument2;
|
|
42
|
+
if (argsAreWords) {
|
|
43
|
+
argument1 = argsAreXyValues ? require_sfnt.i16(glyph, offset) : require_sfnt.u16(glyph, offset);
|
|
44
|
+
argument2 = argsAreXyValues ? require_sfnt.i16(glyph, offset + 2) : require_sfnt.u16(glyph, offset + 2);
|
|
45
|
+
} else {
|
|
46
|
+
argument1 = argsAreXyValues ? signedByte(require_sfnt.u8(glyph, offset)) : require_sfnt.u8(glyph, offset);
|
|
47
|
+
argument2 = argsAreXyValues ? signedByte(require_sfnt.u8(glyph, offset + 1)) : require_sfnt.u8(glyph, offset + 1);
|
|
48
|
+
}
|
|
49
|
+
offset += argsSize;
|
|
50
|
+
let transform;
|
|
51
|
+
if ((flags & WE_HAVE_A_SCALE) !== 0) {
|
|
52
|
+
if (!require_sfnt.hasBytes(glyph, offset, 2)) return;
|
|
53
|
+
const scale = require_sfnt.f2dot14(glyph, offset);
|
|
54
|
+
transform = [
|
|
55
|
+
scale,
|
|
56
|
+
0,
|
|
57
|
+
0,
|
|
58
|
+
scale
|
|
59
|
+
];
|
|
60
|
+
offset += 2;
|
|
61
|
+
} else if ((flags & WE_HAVE_AN_X_AND_Y_SCALE) !== 0) {
|
|
62
|
+
if (!require_sfnt.hasBytes(glyph, offset, 4)) return;
|
|
63
|
+
transform = [
|
|
64
|
+
require_sfnt.f2dot14(glyph, offset),
|
|
65
|
+
0,
|
|
66
|
+
0,
|
|
67
|
+
require_sfnt.f2dot14(glyph, offset + 2)
|
|
68
|
+
];
|
|
69
|
+
offset += 4;
|
|
70
|
+
} else if ((flags & WE_HAVE_A_TWO_BY_TWO) !== 0) {
|
|
71
|
+
if (!require_sfnt.hasBytes(glyph, offset, 8)) return;
|
|
72
|
+
transform = [
|
|
73
|
+
require_sfnt.f2dot14(glyph, offset),
|
|
74
|
+
require_sfnt.f2dot14(glyph, offset + 2),
|
|
75
|
+
require_sfnt.f2dot14(glyph, offset + 4),
|
|
76
|
+
require_sfnt.f2dot14(glyph, offset + 6)
|
|
77
|
+
];
|
|
78
|
+
offset += 8;
|
|
79
|
+
}
|
|
80
|
+
components.push({
|
|
81
|
+
flags,
|
|
82
|
+
glyphIndex,
|
|
83
|
+
argument1,
|
|
84
|
+
argument2,
|
|
85
|
+
argsAreXyValues,
|
|
86
|
+
transform
|
|
87
|
+
});
|
|
88
|
+
if ((flags & MORE_COMPONENTS) === 0) return components;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
function parseGlyf(font, options) {
|
|
92
|
+
const glyfBytes = require_sfnt.sfntTableBytes(font, "glyf");
|
|
93
|
+
const loca = parseLoca(font, options);
|
|
94
|
+
if (glyfBytes === void 0 || loca === void 0) return;
|
|
95
|
+
const glyphBytes = (glyphId) => {
|
|
96
|
+
if (!Number.isInteger(glyphId) || glyphId < 0 || glyphId >= options.numGlyphs) return;
|
|
97
|
+
const start = loca[glyphId];
|
|
98
|
+
const end = loca[glyphId + 1];
|
|
99
|
+
if (end < start || !require_sfnt.hasBytes(glyfBytes, start, end - start)) return;
|
|
100
|
+
return glyfBytes.subarray(start, end);
|
|
101
|
+
};
|
|
102
|
+
const glyphHeader = (glyphId) => {
|
|
103
|
+
const glyph = glyphBytes(glyphId);
|
|
104
|
+
if (glyph === void 0 || !require_sfnt.hasBytes(glyph, 0, GLYPH_HEADER_SIZE)) return;
|
|
105
|
+
return {
|
|
106
|
+
numberOfContours: require_sfnt.i16(glyph, 0),
|
|
107
|
+
xMin: require_sfnt.i16(glyph, 2),
|
|
108
|
+
yMin: require_sfnt.i16(glyph, 4),
|
|
109
|
+
xMax: require_sfnt.i16(glyph, 6),
|
|
110
|
+
yMax: require_sfnt.i16(glyph, 8)
|
|
111
|
+
};
|
|
112
|
+
};
|
|
113
|
+
return {
|
|
114
|
+
numGlyphs: options.numGlyphs,
|
|
115
|
+
glyphBytes,
|
|
116
|
+
glyphHeader,
|
|
117
|
+
compositeComponents(glyphId) {
|
|
118
|
+
const header = glyphHeader(glyphId);
|
|
119
|
+
if (header === void 0 || header.numberOfContours >= 0) return;
|
|
120
|
+
const glyph = glyphBytes(glyphId);
|
|
121
|
+
return glyph === void 0 ? void 0 : readComponents(glyph);
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
//#endregion
|
|
126
|
+
exports.parseGlyf = parseGlyf;
|
|
127
|
+
exports.parseLoca = parseLoca;
|
package/dist/glyf.d.cts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { t as SfntFont } from "./sfnt-V08bb5ut.cjs";
|
|
2
|
+
//#region src/glyf.d.ts
|
|
3
|
+
interface GlyphHeader {
|
|
4
|
+
readonly numberOfContours: number;
|
|
5
|
+
readonly xMin: number;
|
|
6
|
+
readonly yMin: number;
|
|
7
|
+
readonly xMax: number;
|
|
8
|
+
readonly yMax: number;
|
|
9
|
+
}
|
|
10
|
+
interface CompositeComponent {
|
|
11
|
+
readonly flags: number;
|
|
12
|
+
readonly glyphIndex: number;
|
|
13
|
+
readonly argument1: number;
|
|
14
|
+
readonly argument2: number;
|
|
15
|
+
readonly argsAreXyValues: boolean;
|
|
16
|
+
readonly transform: readonly [number, number, number, number] | undefined;
|
|
17
|
+
}
|
|
18
|
+
interface GlyfTable {
|
|
19
|
+
readonly numGlyphs: number;
|
|
20
|
+
glyphBytes(glyphId: number): Uint8Array<ArrayBuffer> | undefined;
|
|
21
|
+
glyphHeader(glyphId: number): GlyphHeader | undefined;
|
|
22
|
+
compositeComponents(glyphId: number): readonly CompositeComponent[] | undefined;
|
|
23
|
+
}
|
|
24
|
+
interface GlyfOptions {
|
|
25
|
+
readonly numGlyphs: number;
|
|
26
|
+
readonly indexToLocFormat: 0 | 1;
|
|
27
|
+
}
|
|
28
|
+
declare function parseLoca(font: SfntFont, options: GlyfOptions): readonly number[] | undefined;
|
|
29
|
+
declare function parseGlyf(font: SfntFont, options: GlyfOptions): GlyfTable | undefined;
|
|
30
|
+
//#endregion
|
|
31
|
+
export { CompositeComponent, GlyfOptions, GlyfTable, GlyphHeader, parseGlyf, parseLoca };
|
package/dist/glyf.d.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { t as SfntFont } from "./sfnt-V08bb5ut.js";
|
|
2
|
+
//#region src/glyf.d.ts
|
|
3
|
+
interface GlyphHeader {
|
|
4
|
+
readonly numberOfContours: number;
|
|
5
|
+
readonly xMin: number;
|
|
6
|
+
readonly yMin: number;
|
|
7
|
+
readonly xMax: number;
|
|
8
|
+
readonly yMax: number;
|
|
9
|
+
}
|
|
10
|
+
interface CompositeComponent {
|
|
11
|
+
readonly flags: number;
|
|
12
|
+
readonly glyphIndex: number;
|
|
13
|
+
readonly argument1: number;
|
|
14
|
+
readonly argument2: number;
|
|
15
|
+
readonly argsAreXyValues: boolean;
|
|
16
|
+
readonly transform: readonly [number, number, number, number] | undefined;
|
|
17
|
+
}
|
|
18
|
+
interface GlyfTable {
|
|
19
|
+
readonly numGlyphs: number;
|
|
20
|
+
glyphBytes(glyphId: number): Uint8Array<ArrayBuffer> | undefined;
|
|
21
|
+
glyphHeader(glyphId: number): GlyphHeader | undefined;
|
|
22
|
+
compositeComponents(glyphId: number): readonly CompositeComponent[] | undefined;
|
|
23
|
+
}
|
|
24
|
+
interface GlyfOptions {
|
|
25
|
+
readonly numGlyphs: number;
|
|
26
|
+
readonly indexToLocFormat: 0 | 1;
|
|
27
|
+
}
|
|
28
|
+
declare function parseLoca(font: SfntFont, options: GlyfOptions): readonly number[] | undefined;
|
|
29
|
+
declare function parseGlyf(font: SfntFont, options: GlyfOptions): GlyfTable | undefined;
|
|
30
|
+
//#endregion
|
|
31
|
+
export { CompositeComponent, GlyfOptions, GlyfTable, GlyphHeader, parseGlyf, parseLoca };
|
package/dist/glyf.js
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { f2dot14, hasBytes, i16, sfntTableBytes, u16, u32, u8 } from "./sfnt.js";
|
|
2
|
+
//#region src/glyf.ts
|
|
3
|
+
const LOCA_SHORT_ENTRY_SIZE = 2;
|
|
4
|
+
const LOCA_LONG_ENTRY_SIZE = 4;
|
|
5
|
+
const LOCA_SHORT_OFFSET_SCALE = 2;
|
|
6
|
+
function parseLoca(font, options) {
|
|
7
|
+
const bytes = sfntTableBytes(font, "loca");
|
|
8
|
+
if (bytes === void 0) return;
|
|
9
|
+
const entryCount = options.numGlyphs + 1;
|
|
10
|
+
const entrySize = options.indexToLocFormat === 0 ? LOCA_SHORT_ENTRY_SIZE : LOCA_LONG_ENTRY_SIZE;
|
|
11
|
+
if (!hasBytes(bytes, 0, entryCount * entrySize)) return;
|
|
12
|
+
const offsets = [];
|
|
13
|
+
for (let i = 0; i < entryCount; i++) offsets.push(options.indexToLocFormat === 0 ? u16(bytes, i * LOCA_SHORT_ENTRY_SIZE) * LOCA_SHORT_OFFSET_SCALE : u32(bytes, i * LOCA_LONG_ENTRY_SIZE));
|
|
14
|
+
return offsets;
|
|
15
|
+
}
|
|
16
|
+
const GLYPH_HEADER_SIZE = 10;
|
|
17
|
+
const ARG_1_AND_2_ARE_WORDS = 1;
|
|
18
|
+
const ARGS_ARE_XY_VALUES = 2;
|
|
19
|
+
const WE_HAVE_A_SCALE = 8;
|
|
20
|
+
const MORE_COMPONENTS = 32;
|
|
21
|
+
const WE_HAVE_AN_X_AND_Y_SCALE = 64;
|
|
22
|
+
const WE_HAVE_A_TWO_BY_TWO = 128;
|
|
23
|
+
const COMPONENT_RECORD_HEADER_SIZE = 4;
|
|
24
|
+
function signedByte(value) {
|
|
25
|
+
return value >= 128 ? value - 256 : value;
|
|
26
|
+
}
|
|
27
|
+
function readComponents(glyph) {
|
|
28
|
+
const components = [];
|
|
29
|
+
let offset = GLYPH_HEADER_SIZE;
|
|
30
|
+
for (;;) {
|
|
31
|
+
if (!hasBytes(glyph, offset, COMPONENT_RECORD_HEADER_SIZE)) return;
|
|
32
|
+
const flags = u16(glyph, offset);
|
|
33
|
+
const glyphIndex = u16(glyph, offset + 2);
|
|
34
|
+
offset += COMPONENT_RECORD_HEADER_SIZE;
|
|
35
|
+
const argsAreWords = (flags & ARG_1_AND_2_ARE_WORDS) !== 0;
|
|
36
|
+
const argsAreXyValues = (flags & ARGS_ARE_XY_VALUES) !== 0;
|
|
37
|
+
const argsSize = argsAreWords ? 4 : 2;
|
|
38
|
+
if (!hasBytes(glyph, offset, argsSize)) return;
|
|
39
|
+
let argument1;
|
|
40
|
+
let argument2;
|
|
41
|
+
if (argsAreWords) {
|
|
42
|
+
argument1 = argsAreXyValues ? i16(glyph, offset) : u16(glyph, offset);
|
|
43
|
+
argument2 = argsAreXyValues ? i16(glyph, offset + 2) : u16(glyph, offset + 2);
|
|
44
|
+
} else {
|
|
45
|
+
argument1 = argsAreXyValues ? signedByte(u8(glyph, offset)) : u8(glyph, offset);
|
|
46
|
+
argument2 = argsAreXyValues ? signedByte(u8(glyph, offset + 1)) : u8(glyph, offset + 1);
|
|
47
|
+
}
|
|
48
|
+
offset += argsSize;
|
|
49
|
+
let transform;
|
|
50
|
+
if ((flags & WE_HAVE_A_SCALE) !== 0) {
|
|
51
|
+
if (!hasBytes(glyph, offset, 2)) return;
|
|
52
|
+
const scale = f2dot14(glyph, offset);
|
|
53
|
+
transform = [
|
|
54
|
+
scale,
|
|
55
|
+
0,
|
|
56
|
+
0,
|
|
57
|
+
scale
|
|
58
|
+
];
|
|
59
|
+
offset += 2;
|
|
60
|
+
} else if ((flags & WE_HAVE_AN_X_AND_Y_SCALE) !== 0) {
|
|
61
|
+
if (!hasBytes(glyph, offset, 4)) return;
|
|
62
|
+
transform = [
|
|
63
|
+
f2dot14(glyph, offset),
|
|
64
|
+
0,
|
|
65
|
+
0,
|
|
66
|
+
f2dot14(glyph, offset + 2)
|
|
67
|
+
];
|
|
68
|
+
offset += 4;
|
|
69
|
+
} else if ((flags & WE_HAVE_A_TWO_BY_TWO) !== 0) {
|
|
70
|
+
if (!hasBytes(glyph, offset, 8)) return;
|
|
71
|
+
transform = [
|
|
72
|
+
f2dot14(glyph, offset),
|
|
73
|
+
f2dot14(glyph, offset + 2),
|
|
74
|
+
f2dot14(glyph, offset + 4),
|
|
75
|
+
f2dot14(glyph, offset + 6)
|
|
76
|
+
];
|
|
77
|
+
offset += 8;
|
|
78
|
+
}
|
|
79
|
+
components.push({
|
|
80
|
+
flags,
|
|
81
|
+
glyphIndex,
|
|
82
|
+
argument1,
|
|
83
|
+
argument2,
|
|
84
|
+
argsAreXyValues,
|
|
85
|
+
transform
|
|
86
|
+
});
|
|
87
|
+
if ((flags & MORE_COMPONENTS) === 0) return components;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
function parseGlyf(font, options) {
|
|
91
|
+
const glyfBytes = sfntTableBytes(font, "glyf");
|
|
92
|
+
const loca = parseLoca(font, options);
|
|
93
|
+
if (glyfBytes === void 0 || loca === void 0) return;
|
|
94
|
+
const glyphBytes = (glyphId) => {
|
|
95
|
+
if (!Number.isInteger(glyphId) || glyphId < 0 || glyphId >= options.numGlyphs) return;
|
|
96
|
+
const start = loca[glyphId];
|
|
97
|
+
const end = loca[glyphId + 1];
|
|
98
|
+
if (end < start || !hasBytes(glyfBytes, start, end - start)) return;
|
|
99
|
+
return glyfBytes.subarray(start, end);
|
|
100
|
+
};
|
|
101
|
+
const glyphHeader = (glyphId) => {
|
|
102
|
+
const glyph = glyphBytes(glyphId);
|
|
103
|
+
if (glyph === void 0 || !hasBytes(glyph, 0, GLYPH_HEADER_SIZE)) return;
|
|
104
|
+
return {
|
|
105
|
+
numberOfContours: i16(glyph, 0),
|
|
106
|
+
xMin: i16(glyph, 2),
|
|
107
|
+
yMin: i16(glyph, 4),
|
|
108
|
+
xMax: i16(glyph, 6),
|
|
109
|
+
yMax: i16(glyph, 8)
|
|
110
|
+
};
|
|
111
|
+
};
|
|
112
|
+
return {
|
|
113
|
+
numGlyphs: options.numGlyphs,
|
|
114
|
+
glyphBytes,
|
|
115
|
+
glyphHeader,
|
|
116
|
+
compositeComponents(glyphId) {
|
|
117
|
+
const header = glyphHeader(glyphId);
|
|
118
|
+
if (header === void 0 || header.numberOfContours >= 0) return;
|
|
119
|
+
const glyph = glyphBytes(glyphId);
|
|
120
|
+
return glyph === void 0 ? void 0 : readComponents(glyph);
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
//#endregion
|
|
125
|
+
export { parseGlyf, parseLoca };
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_sfnt = require("./sfnt.cjs");
|
|
3
|
-
//#region src/
|
|
3
|
+
//#region src/hmtx-table.ts
|
|
4
4
|
function parseHmtx(font) {
|
|
5
5
|
const hheaBytes = require_sfnt.sfntTableBytes(font, "hhea");
|
|
6
6
|
const hmtxBytes = require_sfnt.sfntTableBytes(font, "hmtx");
|
|
7
|
-
if (hheaBytes === void 0 || hmtxBytes === void 0) throw new Error("
|
|
7
|
+
if (hheaBytes === void 0 || hmtxBytes === void 0) throw new Error("font has no hhea/hmtx table");
|
|
8
8
|
const numberOfHMetrics = require_sfnt.u16(hheaBytes, 34);
|
|
9
|
-
if (numberOfHMetrics === 0) throw new Error("
|
|
9
|
+
if (numberOfHMetrics === 0) throw new Error("font hhea numberOfHMetrics is zero");
|
|
10
10
|
const lastWidth = require_sfnt.u16(hmtxBytes, (numberOfHMetrics - 1) * 4);
|
|
11
11
|
return { advanceWidth(glyphId) {
|
|
12
12
|
if (glyphId < numberOfHMetrics) return require_sfnt.u16(hmtxBytes, glyphId * 4);
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { sfntTableBytes, u16 } from "./sfnt.js";
|
|
2
|
-
//#region src/
|
|
2
|
+
//#region src/hmtx-table.ts
|
|
3
3
|
function parseHmtx(font) {
|
|
4
4
|
const hheaBytes = sfntTableBytes(font, "hhea");
|
|
5
5
|
const hmtxBytes = sfntTableBytes(font, "hmtx");
|
|
6
|
-
if (hheaBytes === void 0 || hmtxBytes === void 0) throw new Error("
|
|
6
|
+
if (hheaBytes === void 0 || hmtxBytes === void 0) throw new Error("font has no hhea/hmtx table");
|
|
7
7
|
const numberOfHMetrics = u16(hheaBytes, 34);
|
|
8
|
-
if (numberOfHMetrics === 0) throw new Error("
|
|
8
|
+
if (numberOfHMetrics === 0) throw new Error("font hhea numberOfHMetrics is zero");
|
|
9
9
|
const lastWidth = u16(hmtxBytes, (numberOfHMetrics - 1) * 4);
|
|
10
10
|
return { advanceWidth(glyphId) {
|
|
11
11
|
if (glyphId < numberOfHMetrics) return u16(hmtxBytes, glyphId * 4);
|