pdf-parser.js 5.2.26 → 5.2.28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{afm-widths-BYiX2L9D.cjs → afm-widths-BHD2HZIL.cjs} +553 -642
- package/dist/{afm-widths-blUDDjlI.js → afm-widths-B_IGbGky.js} +553 -642
- package/dist/afm-widths.cjs +1 -1
- package/dist/afm-widths.js +1 -1
- package/dist/annotations.cjs +5 -3
- package/dist/annotations.d.cts +2 -2
- package/dist/annotations.d.ts +2 -2
- package/dist/annotations.js +5 -3
- package/dist/attachments.d.cts +2 -2
- package/dist/attachments.d.ts +2 -2
- package/dist/builtin-encoding.cjs +17 -6
- package/dist/builtin-encoding.js +17 -6
- package/dist/bytes/crc32.cjs +5 -3
- package/dist/bytes/crc32.js +5 -3
- package/dist/bytes/flate.cjs +0 -1
- package/dist/bytes/flate.js +0 -1
- package/dist/cff-bounds.cjs +73 -45
- package/dist/cff-bounds.js +73 -45
- package/dist/cff.cjs +13 -6
- package/dist/cff.js +13 -6
- package/dist/cmap-table.cjs +54 -26
- package/dist/cmap-table.js +54 -26
- package/dist/cmap.cjs +5 -3
- package/dist/cmap.js +5 -3
- package/dist/content-read.d.cts +1 -1
- package/dist/content-read.d.ts +1 -1
- package/dist/content-write.cjs +21 -14
- package/dist/content-write.d.cts +2 -2
- package/dist/content-write.d.ts +2 -2
- package/dist/content-write.js +21 -14
- package/dist/crypto/aes.cjs +76 -55
- package/dist/crypto/aes.js +76 -55
- package/dist/crypto/md5.cjs +345 -149
- package/dist/crypto/md5.js +345 -149
- package/dist/crypto/rc4.cjs +5 -4
- package/dist/crypto/rc4.js +5 -4
- package/dist/crypto/sha2.cjs +92 -43
- package/dist/crypto/sha2.js +92 -43
- package/dist/document.cjs +17 -11
- package/dist/document.d.cts +1 -1
- package/dist/document.d.ts +1 -1
- package/dist/document.js +17 -11
- package/dist/{embedded-font-Bnhh4juV.d.ts → embedded-font-ByD7ZiQS.d.ts} +1 -1
- package/dist/{embedded-font-CEf-zBCA.d.cts → embedded-font-DgVBedw6.d.cts} +1 -1
- package/dist/embedded-font-write.d.cts +2 -2
- package/dist/embedded-font-write.d.ts +2 -2
- package/dist/embedded-font.cjs +4 -2
- package/dist/embedded-font.d.cts +1 -1
- package/dist/embedded-font.d.ts +1 -1
- package/dist/embedded-font.js +4 -2
- package/dist/encoding.cjs +1 -1
- package/dist/encoding.js +1 -1
- package/dist/encrypt-write.cjs +25 -21
- package/dist/encrypt-write.d.cts +1 -1
- package/dist/encrypt-write.d.ts +1 -1
- package/dist/encrypt-write.js +25 -21
- package/dist/encrypt.cjs +43 -64
- package/dist/encrypt.d.cts +1 -1
- package/dist/encrypt.d.ts +1 -1
- package/dist/encrypt.js +43 -64
- package/dist/filters.cjs +46 -26
- package/dist/filters.d.cts +1 -1
- package/dist/filters.d.ts +1 -1
- package/dist/filters.js +46 -26
- package/dist/font-face.cjs +2 -1
- package/dist/font-face.js +2 -1
- package/dist/font-read.cjs +12 -6
- package/dist/font-read.d.cts +1 -1
- package/dist/font-read.d.ts +1 -1
- package/dist/font-read.js +12 -6
- package/dist/font-registry.d.cts +3 -3
- package/dist/font-registry.d.ts +3 -3
- package/dist/font-tables.cjs +55 -28
- package/dist/font-tables.js +55 -28
- package/dist/form.cjs +13 -8
- package/dist/form.d.cts +2 -2
- package/dist/form.d.ts +2 -2
- package/dist/form.js +13 -8
- package/dist/gdef-table.cjs +6 -3
- package/dist/gdef-table.js +6 -3
- package/dist/{glyf-contours-C0epBNqP.d.ts → glyf-contours-B1PsI9oA.d.ts} +1 -1
- package/dist/{glyf-contours-BRpvd0rt.d.cts → glyf-contours-NHBpgks-.d.cts} +1 -1
- package/dist/glyf-contours.cjs +3 -1
- package/dist/glyf-contours.d.cts +1 -1
- package/dist/glyf-contours.d.ts +1 -1
- package/dist/glyf-contours.js +3 -1
- package/dist/glyf.cjs +22 -11
- package/dist/glyf.js +22 -11
- package/dist/gpos-table.cjs +37 -19
- package/dist/gpos-table.js +37 -19
- package/dist/gsub-table.cjs +40 -25
- package/dist/gsub-table.js +40 -25
- package/dist/hmtx-table.cjs +5 -3
- package/dist/hmtx-table.js +5 -3
- package/dist/image/ccitt-encode.cjs +8 -5
- package/dist/image/ccitt-encode.js +8 -5
- package/dist/image/ccitt.cjs +801 -209
- package/dist/image/ccitt.js +801 -209
- package/dist/image/jbig2-arith.cjs +340 -306
- package/dist/image/jbig2-arith.js +340 -306
- package/dist/image/jbig2-bitmap.cjs +8 -5
- package/dist/image/jbig2-bitmap.js +8 -5
- package/dist/image/jbig2-generic.cjs +240 -69
- package/dist/image/jbig2-generic.js +240 -69
- package/dist/image/jbig2-text.cjs +4 -2
- package/dist/image/jbig2-text.js +4 -2
- package/dist/image/jbig2.cjs +69 -31
- package/dist/image/jbig2.js +69 -31
- package/dist/image/jp2-boxes.cjs +52 -27
- package/dist/image/jp2-boxes.js +52 -27
- package/dist/image/jpeg-info.cjs +29 -24
- package/dist/image/jpeg-info.js +29 -24
- package/dist/image/jpeg2000-codestream.cjs +61 -32
- package/dist/image/jpeg2000-codestream.js +61 -32
- package/dist/image/jpeg2000-dwt.cjs +2 -1
- package/dist/image/jpeg2000-dwt.js +2 -1
- package/dist/image/jpeg2000-t1.cjs +21 -11
- package/dist/image/jpeg2000-t1.js +21 -11
- package/dist/image/jpeg2000-t2.cjs +12 -5
- package/dist/image/jpeg2000-t2.js +12 -5
- package/dist/image/jpeg2000-tagtree.cjs +8 -4
- package/dist/image/jpeg2000-tagtree.js +8 -4
- package/dist/image/jpeg2000.cjs +11 -6
- package/dist/image/jpeg2000.js +11 -6
- package/dist/image/png-decode.cjs +62 -39
- package/dist/image/png-decode.d.cts +3 -2
- package/dist/image/png-decode.d.ts +3 -2
- package/dist/image/png-decode.js +62 -39
- package/dist/image/png-filter.cjs +23 -15
- package/dist/image/png-filter.js +23 -15
- package/dist/images-read.cjs +41 -36
- package/dist/images-read.d.cts +2 -2
- package/dist/images-read.d.ts +2 -2
- package/dist/images-read.js +41 -36
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/interpret.cjs +68 -40
- package/dist/interpret.d.cts +1 -1
- package/dist/interpret.d.ts +1 -1
- package/dist/interpret.js +68 -40
- package/dist/lexer.cjs +86 -51
- package/dist/lexer.js +86 -51
- package/dist/math-content-write.cjs +9 -5
- package/dist/math-content-write.js +9 -5
- package/dist/math-font-write.cjs +2 -1
- package/dist/math-font-write.d.cts +1 -1
- package/dist/math-font-write.d.ts +1 -1
- package/dist/math-font-write.js +2 -1
- package/dist/math-font.cjs +16 -7
- package/dist/math-font.js +16 -7
- package/dist/math-table.cjs +25 -13
- package/dist/math-table.js +25 -13
- package/dist/matrix.cjs +3 -2
- package/dist/matrix.js +3 -2
- package/dist/measure.cjs +1 -1
- package/dist/measure.js +1 -1
- package/dist/names.cjs +7 -7
- package/dist/names.d.cts +2 -2
- package/dist/names.d.ts +2 -2
- package/dist/names.js +7 -7
- package/dist/navigation.cjs +16 -12
- package/dist/navigation.d.cts +4 -4
- package/dist/navigation.d.ts +4 -4
- package/dist/navigation.js +16 -12
- package/dist/{objects-B7HdMeWS.d.cts → objects-e2RS3-yT.d.cts} +3 -3
- package/dist/{objects-B7HdMeWS.d.ts → objects-e2RS3-yT.d.ts} +3 -3
- package/dist/objects.d.cts +1 -1
- package/dist/objects.d.ts +1 -1
- package/dist/optional-content.d.cts +2 -2
- package/dist/optional-content.d.ts +2 -2
- package/dist/ot-layout-common.cjs +22 -15
- package/dist/ot-layout-common.js +22 -15
- package/dist/parse.cjs +7 -5
- package/dist/parse.d.cts +1 -1
- package/dist/parse.d.ts +1 -1
- package/dist/parse.js +7 -5
- package/dist/pdf-text.cjs +5 -2
- package/dist/pdf-text.js +5 -2
- package/dist/predictors.cjs +14 -9
- package/dist/predictors.d.cts +1 -1
- package/dist/predictors.d.ts +1 -1
- package/dist/predictors.js +14 -9
- package/dist/raster.cjs +30 -19
- package/dist/raster.d.cts +8 -8
- package/dist/raster.d.ts +8 -8
- package/dist/raster.js +30 -19
- package/dist/read.cjs +29 -16
- package/dist/read.js +29 -16
- package/dist/serialize.cjs +6 -2
- package/dist/serialize.d.cts +1 -1
- package/dist/serialize.d.ts +1 -1
- package/dist/serialize.js +6 -2
- package/dist/sfnt-subset.cjs +25 -13
- package/dist/sfnt-subset.d.cts +1 -1
- package/dist/sfnt-subset.d.ts +1 -1
- package/dist/sfnt-subset.js +25 -13
- package/dist/sfnt.cjs +20 -10
- package/dist/sfnt.js +20 -10
- package/dist/structure.d.cts +2 -2
- package/dist/structure.d.ts +2 -2
- package/dist/text-group.cjs +0 -1
- package/dist/text-group.js +0 -1
- package/dist/text-layout.d.cts +1 -1
- package/dist/text-layout.d.ts +1 -1
- package/dist/tounicode.cjs +4 -2
- package/dist/tounicode.d.cts +1 -1
- package/dist/tounicode.d.ts +1 -1
- package/dist/tounicode.js +4 -2
- package/dist/winansi.cjs +1 -1
- package/dist/winansi.js +1 -1
- package/dist/write.cjs +20 -12
- package/dist/write.d.cts +1 -1
- package/dist/write.d.ts +1 -1
- package/dist/write.js +20 -12
- package/dist/xref.cjs +5 -2
- package/dist/xref.d.cts +1 -1
- package/dist/xref.d.ts +1 -1
- package/dist/xref.js +5 -2
- package/package.json +1 -1
package/dist/gsub-table.js
CHANGED
|
@@ -11,17 +11,28 @@ const DEFAULT_GSUB_FEATURE_TAGS = [
|
|
|
11
11
|
];
|
|
12
12
|
const GSUB_OPT_IN_FEATURE_TAGS = ["smcp", "dlig"];
|
|
13
13
|
const GSUB_HEADER_SIZE = 10;
|
|
14
|
+
const GSUB_HEADER_SCRIPT_LIST_OFFSET = 4;
|
|
15
|
+
const GSUB_HEADER_FEATURE_LIST_OFFSET = 6;
|
|
16
|
+
const GSUB_HEADER_LOOKUP_LIST_OFFSET = 8;
|
|
14
17
|
const SCRIPT_RECORD_SIZE = 6;
|
|
18
|
+
const SCRIPT_RECORD_OFFSET_FIELD_OFFSET = 4;
|
|
15
19
|
const FEATURE_RECORD_SIZE = 6;
|
|
20
|
+
const FEATURE_RECORD_OFFSET_FIELD_OFFSET = 4;
|
|
16
21
|
const LANG_SYS_HEADER_SIZE = 6;
|
|
22
|
+
const LANG_SYS_FEATURE_INDEX_COUNT_OFFSET = 4;
|
|
17
23
|
const FEATURE_HEADER_SIZE = 4;
|
|
18
24
|
const LOOKUP_HEADER_SIZE = 6;
|
|
25
|
+
const LOOKUP_HEADER_SUBTABLE_COUNT_OFFSET = 4;
|
|
19
26
|
const LOOKUP_TYPE_SINGLE_SUBST = 1;
|
|
20
27
|
const LOOKUP_TYPE_LIGATURE_SUBST = 4;
|
|
21
28
|
const LOOKUP_TYPE_CONTEXT_SUBST = 5;
|
|
22
29
|
const LOOKUP_TYPE_CHAIN_CONTEXT_SUBST = 6;
|
|
23
30
|
const LOOKUP_TYPE_EXTENSION_SUBST = 7;
|
|
24
31
|
const EXTENSION_SUBST_HEADER_SIZE = 8;
|
|
32
|
+
const EXTENSION_SUBST_OFFSET_FIELD_OFFSET = 4;
|
|
33
|
+
const BITS_PER_BYTE = 8;
|
|
34
|
+
const BYTE_MASK = 255;
|
|
35
|
+
const SUBST_FORMAT_AND_COVERAGE_SIZE = 4;
|
|
25
36
|
const LOOKUP_FLAG_IGNORE_BASE_GLYPHS = 2;
|
|
26
37
|
const LOOKUP_FLAG_IGNORE_LIGATURES = 4;
|
|
27
38
|
const LOOKUP_FLAG_IGNORE_MARKS = 8;
|
|
@@ -30,14 +41,14 @@ const LOOKUP_FLAG_MARK_ATTACHMENT_TYPE = 65280;
|
|
|
30
41
|
const MAX_LOOKUP_NESTING_DEPTH = 6;
|
|
31
42
|
const PREFERRED_SCRIPT_TAGS = ["latn", "DFLT"];
|
|
32
43
|
function readTag(bytes, offset) {
|
|
33
|
-
return String.fromCharCode(u16(bytes, offset) >>
|
|
44
|
+
return String.fromCharCode(u16(bytes, offset) >> BITS_PER_BYTE, u16(bytes, offset) & BYTE_MASK, u16(bytes, offset + 2) >> BITS_PER_BYTE, u16(bytes, offset + 2) & BYTE_MASK);
|
|
34
45
|
}
|
|
35
46
|
function glyphSkipper(lookupFlag, markFilteringSet, gdef) {
|
|
36
47
|
if (gdef === void 0 || lookupFlag === 0) return () => false;
|
|
37
48
|
const ignoreBase = (lookupFlag & LOOKUP_FLAG_IGNORE_BASE_GLYPHS) !== 0;
|
|
38
49
|
const ignoreLigatures = (lookupFlag & LOOKUP_FLAG_IGNORE_LIGATURES) !== 0;
|
|
39
50
|
const ignoreMarks = (lookupFlag & LOOKUP_FLAG_IGNORE_MARKS) !== 0;
|
|
40
|
-
const markAttachmentType = (lookupFlag & LOOKUP_FLAG_MARK_ATTACHMENT_TYPE) >>
|
|
51
|
+
const markAttachmentType = (lookupFlag & LOOKUP_FLAG_MARK_ATTACHMENT_TYPE) >> BITS_PER_BYTE;
|
|
41
52
|
const useMarkFilteringSet = (lookupFlag & LOOKUP_FLAG_USE_MARK_FILTERING_SET) !== 0;
|
|
42
53
|
return (glyphId) => {
|
|
43
54
|
const glyphClass = gdef.glyphClass(glyphId);
|
|
@@ -60,7 +71,7 @@ function parseSingleSubstFormat1(bytes, subtableOffset, skip) {
|
|
|
60
71
|
if (!hasBytes(bytes, subtableOffset, SINGLE_SUBST_FORMAT_1_SIZE)) return;
|
|
61
72
|
const coverage = parseCoverage(bytes, subtableOffset + u16(bytes, subtableOffset + 2));
|
|
62
73
|
if (coverage === void 0) return;
|
|
63
|
-
const delta = i16(bytes, subtableOffset +
|
|
74
|
+
const delta = i16(bytes, subtableOffset + SUBST_FORMAT_AND_COVERAGE_SIZE);
|
|
64
75
|
return (slots, index) => {
|
|
65
76
|
const slot = slots[index];
|
|
66
77
|
if (skip(slot.glyphId)) return;
|
|
@@ -79,7 +90,7 @@ function parseSingleSubstFormat2(bytes, subtableOffset, skip) {
|
|
|
79
90
|
if (!hasBytes(bytes, subtableOffset, SINGLE_SUBST_FORMAT_2_HEADER_SIZE)) return;
|
|
80
91
|
const coverage = parseCoverage(bytes, subtableOffset + u16(bytes, subtableOffset + 2));
|
|
81
92
|
if (coverage === void 0) return;
|
|
82
|
-
const glyphCount = u16(bytes, subtableOffset +
|
|
93
|
+
const glyphCount = u16(bytes, subtableOffset + SUBST_FORMAT_AND_COVERAGE_SIZE);
|
|
83
94
|
const substitutesOffset = subtableOffset + SINGLE_SUBST_FORMAT_2_HEADER_SIZE;
|
|
84
95
|
if (!hasBytes(bytes, substitutesOffset, glyphCount * 2)) return;
|
|
85
96
|
return (slots, index) => {
|
|
@@ -103,7 +114,7 @@ function parseLigatureSubstFormat1(bytes, subtableOffset, skip) {
|
|
|
103
114
|
if (!hasBytes(bytes, subtableOffset, LIGATURE_SUBST_FORMAT_1_HEADER_SIZE)) return;
|
|
104
115
|
const coverage = parseCoverage(bytes, subtableOffset + u16(bytes, subtableOffset + 2));
|
|
105
116
|
if (coverage === void 0) return;
|
|
106
|
-
const ligSetCount = u16(bytes, subtableOffset +
|
|
117
|
+
const ligSetCount = u16(bytes, subtableOffset + SUBST_FORMAT_AND_COVERAGE_SIZE);
|
|
107
118
|
const ligSetOffsetsOffset = subtableOffset + LIGATURE_SUBST_FORMAT_1_HEADER_SIZE;
|
|
108
119
|
if (!hasBytes(bytes, ligSetOffsetsOffset, ligSetCount * 2)) return;
|
|
109
120
|
return (slots, index) => {
|
|
@@ -192,7 +203,10 @@ function applyContextualRule(slots, inputSlots, records, lookupOf, skip, depth)
|
|
|
192
203
|
const lookup = lookupOf(record.lookupIndex);
|
|
193
204
|
if (lookup === void 0 || record.sequenceIndex >= inputSlots.length || depth >= MAX_LOOKUP_NESTING_DEPTH) return;
|
|
194
205
|
const target = visibleInputSlot(window, record.sequenceIndex, skip);
|
|
195
|
-
if (target !== void 0)
|
|
206
|
+
if (target !== void 0) {
|
|
207
|
+
const application = applyLookupAtSlot(window, target, lookup, depth + 1);
|
|
208
|
+
if (application !== void 0) window.splice(target, application.consumed, ...application.replacement);
|
|
209
|
+
}
|
|
196
210
|
}
|
|
197
211
|
return {
|
|
198
212
|
consumed: last - first + 1,
|
|
@@ -210,12 +224,8 @@ function visibleInputSlot(window, position, skip) {
|
|
|
210
224
|
function applyLookupAtSlot(slots, index, lookup, depth) {
|
|
211
225
|
for (const subtable of lookup.subtables) {
|
|
212
226
|
const application = subtable(slots, index, depth);
|
|
213
|
-
if (application !== void 0)
|
|
214
|
-
slots.splice(index, application.consumed, ...application.replacement);
|
|
215
|
-
return application.replacement.length;
|
|
216
|
-
}
|
|
227
|
+
if (application !== void 0) return application;
|
|
217
228
|
}
|
|
218
|
-
return 0;
|
|
219
229
|
}
|
|
220
230
|
const SUBST_LOOKUP_RECORD_SIZE = 4;
|
|
221
231
|
function readSubstLookupRecords(bytes, offset, count) {
|
|
@@ -360,7 +370,7 @@ function parseSubtable(bytes, lookupType, subtableOffset, skip, lookupOf) {
|
|
|
360
370
|
if (!hasBytes(bytes, subtableOffset, EXTENSION_SUBST_HEADER_SIZE) || u16(bytes, subtableOffset) !== 1) return;
|
|
361
371
|
const extensionLookupType = u16(bytes, subtableOffset + 2);
|
|
362
372
|
if (extensionLookupType === LOOKUP_TYPE_EXTENSION_SUBST) return;
|
|
363
|
-
return parseSubtable(bytes, extensionLookupType, subtableOffset + u32(bytes, subtableOffset +
|
|
373
|
+
return parseSubtable(bytes, extensionLookupType, subtableOffset + u32(bytes, subtableOffset + EXTENSION_SUBST_OFFSET_FIELD_OFFSET), skip, lookupOf);
|
|
364
374
|
}
|
|
365
375
|
if (lookupType === LOOKUP_TYPE_SINGLE_SUBST) {
|
|
366
376
|
if (!hasBytes(bytes, subtableOffset, 2)) return;
|
|
@@ -388,7 +398,7 @@ function parseContextualSubtable(bytes, chained, subtableOffset, skip, lookupOf)
|
|
|
388
398
|
if (!hasBytes(bytes, subtableOffset, prefixSize)) return;
|
|
389
399
|
const coverage = parseCoverage(bytes, subtableOffset + u16(bytes, subtableOffset + 2));
|
|
390
400
|
if (coverage === void 0) return;
|
|
391
|
-
const setCount = u16(bytes, subtableOffset +
|
|
401
|
+
const setCount = u16(bytes, subtableOffset + SUBST_FORMAT_AND_COVERAGE_SIZE);
|
|
392
402
|
const setOffsetsOffset = subtableOffset + prefixSize;
|
|
393
403
|
if (!hasBytes(bytes, setOffsetsOffset, setCount * 2)) return;
|
|
394
404
|
const glyphEquality = (expected) => (glyphId) => glyphId === expected;
|
|
@@ -404,10 +414,10 @@ function parseContextualSubtable(bytes, chained, subtableOffset, skip, lookupOf)
|
|
|
404
414
|
if (!hasBytes(bytes, subtableOffset, prefixSize)) return;
|
|
405
415
|
const coverage = parseCoverage(bytes, subtableOffset + u16(bytes, subtableOffset + 2));
|
|
406
416
|
if (coverage === void 0) return;
|
|
407
|
-
const inputClassDefOffset = chained ? u16(bytes, subtableOffset + 6) : u16(bytes, subtableOffset +
|
|
417
|
+
const inputClassDefOffset = chained ? u16(bytes, subtableOffset + 6) : u16(bytes, subtableOffset + SUBST_FORMAT_AND_COVERAGE_SIZE);
|
|
408
418
|
const inputClassDef = inputClassDefOffset === 0 ? constantZeroClassDef : parseClassDef(bytes, subtableOffset + inputClassDefOffset);
|
|
409
419
|
const readAuxClassDef = (offset) => offset === 0 ? constantZeroClassDef : parseClassDef(bytes, subtableOffset + offset);
|
|
410
|
-
const backtrackClassDef = chained ? readAuxClassDef(u16(bytes, subtableOffset +
|
|
420
|
+
const backtrackClassDef = chained ? readAuxClassDef(u16(bytes, subtableOffset + SUBST_FORMAT_AND_COVERAGE_SIZE)) : constantZeroClassDef;
|
|
411
421
|
const lookaheadClassDef = chained ? readAuxClassDef(u16(bytes, subtableOffset + 8)) : constantZeroClassDef;
|
|
412
422
|
if (inputClassDef === void 0 || backtrackClassDef === void 0 || lookaheadClassDef === void 0) return;
|
|
413
423
|
const setCount = u16(bytes, subtableOffset + prefixSize - 2);
|
|
@@ -429,9 +439,9 @@ function findScriptOffset(bytes, scriptListOffset) {
|
|
|
429
439
|
if (!hasBytes(bytes, recordsOffset, scriptCount * SCRIPT_RECORD_SIZE) || scriptCount === 0) return;
|
|
430
440
|
for (const wanted of PREFERRED_SCRIPT_TAGS) for (let i = 0; i < scriptCount; i++) {
|
|
431
441
|
const recordOffset = recordsOffset + i * SCRIPT_RECORD_SIZE;
|
|
432
|
-
if (readTag(bytes, recordOffset) === wanted) return scriptListOffset + u16(bytes, recordOffset +
|
|
442
|
+
if (readTag(bytes, recordOffset) === wanted) return scriptListOffset + u16(bytes, recordOffset + SCRIPT_RECORD_OFFSET_FIELD_OFFSET);
|
|
433
443
|
}
|
|
434
|
-
return scriptListOffset + u16(bytes, recordsOffset +
|
|
444
|
+
return scriptListOffset + u16(bytes, recordsOffset + SCRIPT_RECORD_OFFSET_FIELD_OFFSET);
|
|
435
445
|
}
|
|
436
446
|
function parseDefaultLangSysFeatureIndices(bytes, scriptOffset) {
|
|
437
447
|
if (!hasBytes(bytes, scriptOffset, 2)) return [];
|
|
@@ -439,7 +449,7 @@ function parseDefaultLangSysFeatureIndices(bytes, scriptOffset) {
|
|
|
439
449
|
if (defaultLangSysOffset === 0) return [];
|
|
440
450
|
const langSysOffset = scriptOffset + defaultLangSysOffset;
|
|
441
451
|
if (!hasBytes(bytes, langSysOffset, LANG_SYS_HEADER_SIZE)) return [];
|
|
442
|
-
const featureIndexCount = u16(bytes, langSysOffset +
|
|
452
|
+
const featureIndexCount = u16(bytes, langSysOffset + LANG_SYS_FEATURE_INDEX_COUNT_OFFSET);
|
|
443
453
|
const indicesOffset = langSysOffset + LANG_SYS_HEADER_SIZE;
|
|
444
454
|
if (!hasBytes(bytes, indicesOffset, featureIndexCount * 2)) return [];
|
|
445
455
|
const indices = [];
|
|
@@ -457,7 +467,7 @@ function collectLookupIndices(bytes, featureListOffset, featureIndices, featureT
|
|
|
457
467
|
if (featureIndex >= featureCount) continue;
|
|
458
468
|
const recordOffset = recordsOffset + featureIndex * FEATURE_RECORD_SIZE;
|
|
459
469
|
if (!featureTags.includes(readTag(bytes, recordOffset))) continue;
|
|
460
|
-
const featureOffset = featureListOffset + u16(bytes, recordOffset +
|
|
470
|
+
const featureOffset = featureListOffset + u16(bytes, recordOffset + FEATURE_RECORD_OFFSET_FIELD_OFFSET);
|
|
461
471
|
if (!hasBytes(bytes, featureOffset, FEATURE_HEADER_SIZE)) continue;
|
|
462
472
|
const lookupIndexCount = u16(bytes, featureOffset + 2);
|
|
463
473
|
const indicesOffset = featureOffset + FEATURE_HEADER_SIZE;
|
|
@@ -475,12 +485,12 @@ function collectLookupIndices(bytes, featureListOffset, featureIndices, featureT
|
|
|
475
485
|
function buildGsubShaper(font, options = {}) {
|
|
476
486
|
const bytes = sfntTableBytes(font, "GSUB");
|
|
477
487
|
if (bytes === void 0 || !hasBytes(bytes, 0, GSUB_HEADER_SIZE) || u16(bytes, 0) !== 1) return;
|
|
478
|
-
const scriptOffset = findScriptOffset(bytes, u16(bytes,
|
|
488
|
+
const scriptOffset = findScriptOffset(bytes, u16(bytes, GSUB_HEADER_SCRIPT_LIST_OFFSET));
|
|
479
489
|
if (scriptOffset === void 0) return;
|
|
480
490
|
const featureTags = [...DEFAULT_GSUB_FEATURE_TAGS, ...options.optInFeatures ?? []];
|
|
481
|
-
const lookupIndices = collectLookupIndices(bytes, u16(bytes,
|
|
491
|
+
const lookupIndices = collectLookupIndices(bytes, u16(bytes, GSUB_HEADER_FEATURE_LIST_OFFSET), parseDefaultLangSysFeatureIndices(bytes, scriptOffset), featureTags);
|
|
482
492
|
if (lookupIndices.length === 0) return;
|
|
483
|
-
const lookupListOffset = u16(bytes,
|
|
493
|
+
const lookupListOffset = u16(bytes, GSUB_HEADER_LOOKUP_LIST_OFFSET);
|
|
484
494
|
if (!hasBytes(bytes, lookupListOffset, 2)) return;
|
|
485
495
|
const lookupCount = u16(bytes, lookupListOffset);
|
|
486
496
|
const lookupOffsetsOffset = lookupListOffset + 2;
|
|
@@ -496,7 +506,7 @@ function buildGsubShaper(font, options = {}) {
|
|
|
496
506
|
}
|
|
497
507
|
const lookupFlag = u16(bytes, lookupOffset + 2);
|
|
498
508
|
const lookupType = u16(bytes, lookupOffset);
|
|
499
|
-
const subTableCount = u16(bytes, lookupOffset +
|
|
509
|
+
const subTableCount = u16(bytes, lookupOffset + LOOKUP_HEADER_SUBTABLE_COUNT_OFFSET);
|
|
500
510
|
const subtableOffsetsOffset = lookupOffset + LOOKUP_HEADER_SIZE;
|
|
501
511
|
const markFilteringSetWidth = (lookupFlag & LOOKUP_FLAG_USE_MARK_FILTERING_SET) !== 0 ? 2 : 0;
|
|
502
512
|
if (!hasBytes(bytes, subtableOffsetsOffset, subTableCount * 2 + markFilteringSetWidth)) {
|
|
@@ -525,8 +535,13 @@ function buildGsubShaper(font, options = {}) {
|
|
|
525
535
|
for (const lookup of appliedLookups) {
|
|
526
536
|
let slotIndex = 0;
|
|
527
537
|
while (slotIndex < slots.length) {
|
|
528
|
-
const
|
|
529
|
-
|
|
538
|
+
const application = applyLookupAtSlot(slots, slotIndex, lookup, 0);
|
|
539
|
+
if (application === void 0) {
|
|
540
|
+
slotIndex += 1;
|
|
541
|
+
continue;
|
|
542
|
+
}
|
|
543
|
+
slots.splice(slotIndex, application.consumed, ...application.replacement);
|
|
544
|
+
slotIndex += application.replacement.length !== 0 ? application.replacement.length : 1;
|
|
530
545
|
}
|
|
531
546
|
}
|
|
532
547
|
return {
|
package/dist/hmtx-table.cjs
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_sfnt = require("./sfnt.cjs");
|
|
3
3
|
//#region src/hmtx-table.ts
|
|
4
|
+
const HHEA_NUMBER_OF_H_METRICS_OFFSET = 34;
|
|
5
|
+
const HMTX_LONG_HOR_METRIC_SIZE_BYTES = 4;
|
|
4
6
|
function parseHmtx(font) {
|
|
5
7
|
const hheaBytes = require_sfnt.sfntTableBytes(font, "hhea");
|
|
6
8
|
const hmtxBytes = require_sfnt.sfntTableBytes(font, "hmtx");
|
|
7
9
|
if (hheaBytes === void 0 || hmtxBytes === void 0) throw new Error("font has no hhea/hmtx table");
|
|
8
|
-
const numberOfHMetrics = require_sfnt.u16(hheaBytes,
|
|
10
|
+
const numberOfHMetrics = require_sfnt.u16(hheaBytes, HHEA_NUMBER_OF_H_METRICS_OFFSET);
|
|
9
11
|
if (numberOfHMetrics === 0) throw new Error("font hhea numberOfHMetrics is zero");
|
|
10
|
-
const lastWidth = require_sfnt.u16(hmtxBytes, (numberOfHMetrics - 1) *
|
|
12
|
+
const lastWidth = require_sfnt.u16(hmtxBytes, (numberOfHMetrics - 1) * HMTX_LONG_HOR_METRIC_SIZE_BYTES);
|
|
11
13
|
return { advanceWidth(glyphId) {
|
|
12
|
-
if (glyphId < numberOfHMetrics) return require_sfnt.u16(hmtxBytes, glyphId *
|
|
14
|
+
if (glyphId < numberOfHMetrics) return require_sfnt.u16(hmtxBytes, glyphId * HMTX_LONG_HOR_METRIC_SIZE_BYTES);
|
|
13
15
|
return lastWidth;
|
|
14
16
|
} };
|
|
15
17
|
}
|
package/dist/hmtx-table.js
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import { sfntTableBytes, u16 } from "./sfnt.js";
|
|
2
2
|
//#region src/hmtx-table.ts
|
|
3
|
+
const HHEA_NUMBER_OF_H_METRICS_OFFSET = 34;
|
|
4
|
+
const HMTX_LONG_HOR_METRIC_SIZE_BYTES = 4;
|
|
3
5
|
function parseHmtx(font) {
|
|
4
6
|
const hheaBytes = sfntTableBytes(font, "hhea");
|
|
5
7
|
const hmtxBytes = sfntTableBytes(font, "hmtx");
|
|
6
8
|
if (hheaBytes === void 0 || hmtxBytes === void 0) throw new Error("font has no hhea/hmtx table");
|
|
7
|
-
const numberOfHMetrics = u16(hheaBytes,
|
|
9
|
+
const numberOfHMetrics = u16(hheaBytes, HHEA_NUMBER_OF_H_METRICS_OFFSET);
|
|
8
10
|
if (numberOfHMetrics === 0) throw new Error("font hhea numberOfHMetrics is zero");
|
|
9
|
-
const lastWidth = u16(hmtxBytes, (numberOfHMetrics - 1) *
|
|
11
|
+
const lastWidth = u16(hmtxBytes, (numberOfHMetrics - 1) * HMTX_LONG_HOR_METRIC_SIZE_BYTES);
|
|
10
12
|
return { advanceWidth(glyphId) {
|
|
11
|
-
if (glyphId < numberOfHMetrics) return u16(hmtxBytes, glyphId *
|
|
13
|
+
if (glyphId < numberOfHMetrics) return u16(hmtxBytes, glyphId * HMTX_LONG_HOR_METRIC_SIZE_BYTES);
|
|
12
14
|
return lastWidth;
|
|
13
15
|
} };
|
|
14
16
|
}
|
|
@@ -22,6 +22,9 @@ const VERTICAL_MODES = /* @__PURE__ */ new Map([
|
|
|
22
22
|
]);
|
|
23
23
|
const LARGEST_MAKEUP_RUN = 2560;
|
|
24
24
|
const MAKEUP_GRANULARITY = 64;
|
|
25
|
+
const BITS_PER_BYTE = 8;
|
|
26
|
+
const BYTE_INDEX_SHIFT = 3;
|
|
27
|
+
const BYTE_BIT_MASK = 7;
|
|
25
28
|
var BitWriter = class {
|
|
26
29
|
bytes = [];
|
|
27
30
|
current = 0;
|
|
@@ -33,7 +36,7 @@ var BitWriter = class {
|
|
|
33
36
|
for (const char of bits) {
|
|
34
37
|
this.current = this.current << 1 | (char === "1" ? 1 : 0);
|
|
35
38
|
this.used++;
|
|
36
|
-
if (this.used ===
|
|
39
|
+
if (this.used === BITS_PER_BYTE) {
|
|
37
40
|
this.bytes.push(this.current);
|
|
38
41
|
this.current = 0;
|
|
39
42
|
this.used = 0;
|
|
@@ -41,7 +44,7 @@ var BitWriter = class {
|
|
|
41
44
|
}
|
|
42
45
|
}
|
|
43
46
|
finish() {
|
|
44
|
-
if (this.used > 0) this.bytes.push(this.current <<
|
|
47
|
+
if (this.used > 0) this.bytes.push(this.current << BITS_PER_BYTE - this.used);
|
|
45
48
|
return new Uint8Array(this.bytes);
|
|
46
49
|
}
|
|
47
50
|
};
|
|
@@ -59,7 +62,7 @@ function changingElements(bitmap, rowByteOffset, columns) {
|
|
|
59
62
|
const changes = [];
|
|
60
63
|
let previous = 1;
|
|
61
64
|
for (let x = 0; x < columns; x++) {
|
|
62
|
-
const pixel = (bitmap[rowByteOffset + (x >>
|
|
65
|
+
const pixel = (bitmap[rowByteOffset + (x >> BYTE_INDEX_SHIFT)] ?? 0) >> BYTE_BIT_MASK - (x & BYTE_BIT_MASK) & 1;
|
|
63
66
|
if (pixel !== previous) {
|
|
64
67
|
changes.push(x);
|
|
65
68
|
previous = pixel;
|
|
@@ -70,7 +73,7 @@ function changingElements(bitmap, rowByteOffset, columns) {
|
|
|
70
73
|
function encodeCcittFax(bitmap, options) {
|
|
71
74
|
const { columns, rows, maxBytes } = options;
|
|
72
75
|
if (columns <= 0 || rows <= 0) return /* @__PURE__ */ new Uint8Array(0);
|
|
73
|
-
const rowBytes = columns +
|
|
76
|
+
const rowBytes = columns + BYTE_BIT_MASK >> BYTE_INDEX_SHIFT;
|
|
74
77
|
const writer = new BitWriter();
|
|
75
78
|
let reference = [];
|
|
76
79
|
for (let y = 0; y < rows; y++) {
|
|
@@ -109,7 +112,7 @@ function encodeCcittFax(bitmap, options) {
|
|
|
109
112
|
ci += 2;
|
|
110
113
|
}
|
|
111
114
|
}
|
|
112
|
-
if (a0 < columns) white = ((bitmap[offset + (a0 >>
|
|
115
|
+
if (a0 < columns) white = ((bitmap[offset + (a0 >> BYTE_INDEX_SHIFT)] ?? 0) >> BYTE_BIT_MASK - (a0 & BYTE_BIT_MASK) & 1) === 1;
|
|
113
116
|
}
|
|
114
117
|
reference = current;
|
|
115
118
|
}
|
|
@@ -21,6 +21,9 @@ const VERTICAL_MODES = /* @__PURE__ */ new Map([
|
|
|
21
21
|
]);
|
|
22
22
|
const LARGEST_MAKEUP_RUN = 2560;
|
|
23
23
|
const MAKEUP_GRANULARITY = 64;
|
|
24
|
+
const BITS_PER_BYTE = 8;
|
|
25
|
+
const BYTE_INDEX_SHIFT = 3;
|
|
26
|
+
const BYTE_BIT_MASK = 7;
|
|
24
27
|
var BitWriter = class {
|
|
25
28
|
bytes = [];
|
|
26
29
|
current = 0;
|
|
@@ -32,7 +35,7 @@ var BitWriter = class {
|
|
|
32
35
|
for (const char of bits) {
|
|
33
36
|
this.current = this.current << 1 | (char === "1" ? 1 : 0);
|
|
34
37
|
this.used++;
|
|
35
|
-
if (this.used ===
|
|
38
|
+
if (this.used === BITS_PER_BYTE) {
|
|
36
39
|
this.bytes.push(this.current);
|
|
37
40
|
this.current = 0;
|
|
38
41
|
this.used = 0;
|
|
@@ -40,7 +43,7 @@ var BitWriter = class {
|
|
|
40
43
|
}
|
|
41
44
|
}
|
|
42
45
|
finish() {
|
|
43
|
-
if (this.used > 0) this.bytes.push(this.current <<
|
|
46
|
+
if (this.used > 0) this.bytes.push(this.current << BITS_PER_BYTE - this.used);
|
|
44
47
|
return new Uint8Array(this.bytes);
|
|
45
48
|
}
|
|
46
49
|
};
|
|
@@ -58,7 +61,7 @@ function changingElements(bitmap, rowByteOffset, columns) {
|
|
|
58
61
|
const changes = [];
|
|
59
62
|
let previous = 1;
|
|
60
63
|
for (let x = 0; x < columns; x++) {
|
|
61
|
-
const pixel = (bitmap[rowByteOffset + (x >>
|
|
64
|
+
const pixel = (bitmap[rowByteOffset + (x >> BYTE_INDEX_SHIFT)] ?? 0) >> BYTE_BIT_MASK - (x & BYTE_BIT_MASK) & 1;
|
|
62
65
|
if (pixel !== previous) {
|
|
63
66
|
changes.push(x);
|
|
64
67
|
previous = pixel;
|
|
@@ -69,7 +72,7 @@ function changingElements(bitmap, rowByteOffset, columns) {
|
|
|
69
72
|
function encodeCcittFax(bitmap, options) {
|
|
70
73
|
const { columns, rows, maxBytes } = options;
|
|
71
74
|
if (columns <= 0 || rows <= 0) return /* @__PURE__ */ new Uint8Array(0);
|
|
72
|
-
const rowBytes = columns +
|
|
75
|
+
const rowBytes = columns + BYTE_BIT_MASK >> BYTE_INDEX_SHIFT;
|
|
73
76
|
const writer = new BitWriter();
|
|
74
77
|
let reference = [];
|
|
75
78
|
for (let y = 0; y < rows; y++) {
|
|
@@ -108,7 +111,7 @@ function encodeCcittFax(bitmap, options) {
|
|
|
108
111
|
ci += 2;
|
|
109
112
|
}
|
|
110
113
|
}
|
|
111
|
-
if (a0 < columns) white = ((bitmap[offset + (a0 >>
|
|
114
|
+
if (a0 < columns) white = ((bitmap[offset + (a0 >> BYTE_INDEX_SHIFT)] ?? 0) >> BYTE_BIT_MASK - (a0 & BYTE_BIT_MASK) & 1) === 1;
|
|
112
115
|
}
|
|
113
116
|
reference = current;
|
|
114
117
|
}
|