pdf-parser.js 5.2.30 → 5.3.1
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-BHD2HZIL.cjs → afm-widths-C6U0SQj9.cjs} +5 -1448
- package/dist/{afm-widths-B_IGbGky.js → afm-widths-p3UfaXme.js} +3 -1398
- package/dist/afm-widths.cjs +1 -1
- package/dist/afm-widths.js +1 -1
- package/dist/annotations.d.cts +3 -3
- package/dist/annotations.d.ts +3 -3
- package/dist/attachments.d.cts +2 -2
- package/dist/attachments.d.ts +2 -2
- package/dist/builtin-encoding.cjs +4 -3
- package/dist/builtin-encoding.js +2 -1
- package/dist/cmap.d.cts +1 -1
- package/dist/cmap.d.ts +1 -1
- package/dist/content-read.d.cts +1 -1
- package/dist/content-read.d.ts +1 -1
- package/dist/content-write.cjs +1 -1
- package/dist/content-write.d.cts +1 -1
- package/dist/content-write.d.ts +1 -1
- package/dist/content-write.js +1 -1
- package/dist/diagnostics-C9FxfZ6H.d.cts +22 -0
- package/dist/diagnostics-C9FxfZ6H.d.ts +22 -0
- package/dist/diagnostics.d.cts +1 -21
- package/dist/diagnostics.d.ts +1 -21
- package/dist/document.d.cts +1 -1
- package/dist/document.d.ts +1 -1
- package/dist/{embedded-font-ByD7ZiQS.d.ts → embedded-font-CQZbTTDM.d.ts} +1 -1
- package/dist/{embedded-font-DgVBedw6.d.cts → embedded-font-CqePfvrl.d.cts} +1 -1
- package/dist/embedded-font-write.d.cts +1 -1
- package/dist/embedded-font-write.d.ts +1 -1
- package/dist/embedded-font.cjs +2 -2
- package/dist/embedded-font.d.cts +1 -1
- package/dist/embedded-font.d.ts +1 -1
- package/dist/embedded-font.js +2 -2
- package/dist/encoding-glyph-unicode.cjs +353 -0
- package/dist/encoding-glyph-unicode.d.cts +4 -0
- package/dist/encoding-glyph-unicode.d.ts +4 -0
- package/dist/encoding-glyph-unicode.js +352 -0
- package/dist/encoding-standard-tables.cjs +531 -0
- package/dist/encoding-standard-tables.d.cts +7 -0
- package/dist/encoding-standard-tables.d.ts +7 -0
- package/dist/encoding-standard-tables.js +527 -0
- package/dist/encoding-symbol-tables.cjs +533 -0
- package/dist/encoding-symbol-tables.d.cts +7 -0
- package/dist/encoding-symbol-tables.d.ts +7 -0
- package/dist/encoding-symbol-tables.js +529 -0
- package/dist/encoding.cjs +1 -9
- package/dist/encoding.d.cts +1 -9
- package/dist/encoding.d.ts +1 -9
- package/dist/encoding.js +2 -2
- package/dist/encrypt.d.cts +1 -1
- package/dist/encrypt.d.ts +1 -1
- package/dist/filters.d.cts +1 -1
- package/dist/filters.d.ts +1 -1
- package/dist/font-read.cjs +4 -3
- package/dist/font-read.d.cts +2 -2
- package/dist/font-read.d.ts +2 -2
- package/dist/font-read.js +2 -1
- package/dist/font-registry.d.cts +1 -1
- package/dist/font-registry.d.ts +1 -1
- package/dist/form.d.cts +2 -2
- package/dist/form.d.ts +2 -2
- package/dist/gdef-table-D0Hzn4KD.d.cts +15 -0
- package/dist/gdef-table-DL0V8wEZ.d.ts +15 -0
- package/dist/gdef-table.d.cts +1 -14
- package/dist/gdef-table.d.ts +1 -14
- package/dist/glyf-contours.d.cts +12 -1
- package/dist/glyf-contours.d.ts +12 -1
- package/dist/gsub-context.cjs +13 -0
- package/dist/gsub-context.d.cts +34 -0
- package/dist/gsub-context.d.ts +34 -0
- package/dist/gsub-context.js +2 -0
- package/dist/gsub-table-BDpJWqpf.d.ts +52 -0
- package/dist/gsub-table-D6niKeLi.js +556 -0
- package/dist/gsub-table-DW7Wmi9V.d.cts +52 -0
- package/dist/gsub-table-hFfYmf1W.cjs +741 -0
- package/dist/gsub-table.cjs +21 -556
- package/dist/gsub-table.d.cts +2 -2
- package/dist/gsub-table.d.ts +2 -2
- package/dist/gsub-table.js +2 -554
- package/dist/images-read.d.cts +2 -2
- package/dist/images-read.d.ts +2 -2
- package/dist/index.cjs +6 -6
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +6 -6
- package/dist/interpret-CqXdXgkY.cjs +712 -0
- package/dist/interpret-aWWhdIzr.js +677 -0
- package/dist/interpret-colors.cjs +6 -0
- package/dist/interpret-colors.d.cts +9 -0
- package/dist/interpret-colors.d.ts +9 -0
- package/dist/interpret-colors.js +2 -0
- package/dist/interpret-marked.cjs +25 -0
- package/dist/interpret-marked.d.cts +11 -0
- package/dist/interpret-marked.d.ts +11 -0
- package/dist/interpret-marked.js +23 -0
- package/dist/interpret-shapes.cjs +212 -0
- package/dist/interpret-shapes.d.cts +32 -0
- package/dist/interpret-shapes.d.ts +32 -0
- package/dist/interpret-shapes.js +199 -0
- package/dist/interpret-types.cjs +0 -0
- package/dist/interpret-types.d.cts +123 -0
- package/dist/interpret-types.d.ts +123 -0
- package/dist/interpret-types.js +0 -0
- package/dist/interpret.cjs +3 -887
- package/dist/interpret.d.cts +5 -116
- package/dist/interpret.d.ts +5 -116
- package/dist/interpret.js +2 -887
- package/dist/math-font.cjs +1 -1
- package/dist/math-font.js +1 -1
- package/dist/measure.cjs +1 -1
- package/dist/measure.js +1 -1
- package/dist/names.d.cts +2 -2
- package/dist/names.d.ts +2 -2
- package/dist/navigation.d.cts +2 -2
- package/dist/navigation.d.ts +2 -2
- package/dist/optional-content.d.cts +2 -2
- package/dist/optional-content.d.ts +2 -2
- package/dist/ot-layout-common-BcsGRFBS.d.cts +10 -0
- package/dist/ot-layout-common-BcsGRFBS.d.ts +10 -0
- package/dist/ot-layout-common.d.cts +1 -9
- package/dist/ot-layout-common.d.ts +1 -9
- package/dist/parse.d.cts +1 -1
- package/dist/parse.d.ts +1 -1
- package/dist/predictors.d.cts +1 -1
- package/dist/predictors.d.ts +1 -1
- package/dist/raster-Cdm3idP_.js +794 -0
- package/dist/raster-EG2KYRZ0.cjs +829 -0
- package/dist/raster-text.cjs +5 -0
- package/dist/raster-text.d.cts +20 -0
- package/dist/raster-text.d.ts +20 -0
- package/dist/raster-text.js +2 -0
- package/dist/raster.cjs +4 -795
- package/dist/raster.d.cts +17 -6
- package/dist/raster.d.ts +17 -6
- package/dist/raster.js +2 -792
- package/dist/read-convert.cjs +310 -0
- package/dist/read-convert.d.cts +58 -0
- package/dist/read-convert.d.ts +58 -0
- package/dist/read-convert.js +295 -0
- package/dist/read.cjs +5 -293
- package/dist/read.d.cts +1 -1
- package/dist/read.d.ts +1 -1
- package/dist/read.js +4 -292
- package/dist/structure.d.cts +2 -2
- package/dist/structure.d.ts +2 -2
- package/dist/winansi.cjs +1 -1
- package/dist/winansi.js +1 -1
- package/dist/write-annotations.cjs +132 -0
- package/dist/write-annotations.d.cts +29 -0
- package/dist/write-annotations.d.ts +29 -0
- package/dist/write-annotations.js +121 -0
- package/dist/write-font-objects.cjs +76 -0
- package/dist/write-font-objects.d.cts +35 -0
- package/dist/write-font-objects.d.ts +35 -0
- package/dist/write-font-objects.js +75 -0
- package/dist/write-form.cjs +91 -0
- package/dist/write-form.d.cts +19 -0
- package/dist/write-form.d.ts +19 -0
- package/dist/write-form.js +89 -0
- package/dist/write-images.cjs +148 -0
- package/dist/write-images.d.cts +25 -0
- package/dist/write-images.d.ts +25 -0
- package/dist/write-images.js +140 -0
- package/dist/write-outline.cjs +46 -0
- package/dist/write-outline.d.cts +18 -0
- package/dist/write-outline.d.ts +18 -0
- package/dist/write-outline.js +45 -0
- package/dist/write-page-emit.cjs +97 -0
- package/dist/write-page-emit.d.cts +63 -0
- package/dist/write-page-emit.d.ts +63 -0
- package/dist/write-page-emit.js +96 -0
- package/dist/write-pages.cjs +37 -0
- package/dist/write-pages.d.cts +21 -0
- package/dist/write-pages.d.ts +21 -0
- package/dist/write-pages.js +36 -0
- package/dist/write-strings.cjs +41 -0
- package/dist/write-strings.d.cts +9 -0
- package/dist/write-strings.d.ts +9 -0
- package/dist/write-strings.js +37 -0
- package/dist/write.cjs +53 -553
- package/dist/write.d.cts +1 -1
- package/dist/write.d.ts +1 -1
- package/dist/write.js +49 -549
- package/dist/xref.d.cts +1 -1
- package/dist/xref.d.ts +1 -1
- package/package.json +1 -1
- package/dist/glyf-contours-B1PsI9oA.d.ts +0 -13
- package/dist/glyf-contours-NHBpgks-.d.cts +0 -13
- package/dist/gsub-table-Bm9kSMzk.d.cts +0 -16
- package/dist/gsub-table-CdfESH2-.d.ts +0 -16
package/dist/gsub-table.js
CHANGED
|
@@ -1,554 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
import { parseGdefTable } from "./gdef-table.js";
|
|
4
|
-
//#region src/gsub-table.ts
|
|
5
|
-
const constantZeroClassDef = () => 0;
|
|
6
|
-
const DEFAULT_GSUB_FEATURE_TAGS = [
|
|
7
|
-
"liga",
|
|
8
|
-
"rlig",
|
|
9
|
-
"calt",
|
|
10
|
-
"clig"
|
|
11
|
-
];
|
|
12
|
-
const GSUB_OPT_IN_FEATURE_TAGS = ["smcp", "dlig"];
|
|
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;
|
|
17
|
-
const SCRIPT_RECORD_SIZE = 6;
|
|
18
|
-
const SCRIPT_RECORD_OFFSET_FIELD_OFFSET = 4;
|
|
19
|
-
const FEATURE_RECORD_SIZE = 6;
|
|
20
|
-
const FEATURE_RECORD_OFFSET_FIELD_OFFSET = 4;
|
|
21
|
-
const LANG_SYS_HEADER_SIZE = 6;
|
|
22
|
-
const LANG_SYS_FEATURE_INDEX_COUNT_OFFSET = 4;
|
|
23
|
-
const FEATURE_HEADER_SIZE = 4;
|
|
24
|
-
const LOOKUP_HEADER_SIZE = 6;
|
|
25
|
-
const LOOKUP_HEADER_SUBTABLE_COUNT_OFFSET = 4;
|
|
26
|
-
const LOOKUP_TYPE_SINGLE_SUBST = 1;
|
|
27
|
-
const LOOKUP_TYPE_LIGATURE_SUBST = 4;
|
|
28
|
-
const LOOKUP_TYPE_CONTEXT_SUBST = 5;
|
|
29
|
-
const LOOKUP_TYPE_CHAIN_CONTEXT_SUBST = 6;
|
|
30
|
-
const LOOKUP_TYPE_EXTENSION_SUBST = 7;
|
|
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;
|
|
36
|
-
const LOOKUP_FLAG_IGNORE_BASE_GLYPHS = 2;
|
|
37
|
-
const LOOKUP_FLAG_IGNORE_LIGATURES = 4;
|
|
38
|
-
const LOOKUP_FLAG_IGNORE_MARKS = 8;
|
|
39
|
-
const LOOKUP_FLAG_USE_MARK_FILTERING_SET = 16;
|
|
40
|
-
const LOOKUP_FLAG_MARK_ATTACHMENT_TYPE = 65280;
|
|
41
|
-
const MAX_LOOKUP_NESTING_DEPTH = 6;
|
|
42
|
-
const PREFERRED_SCRIPT_TAGS = ["latn", "DFLT"];
|
|
43
|
-
function readTag(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);
|
|
45
|
-
}
|
|
46
|
-
function glyphSkipper(lookupFlag, markFilteringSet, gdef) {
|
|
47
|
-
if (gdef === void 0 || lookupFlag === 0) return () => false;
|
|
48
|
-
const ignoreBase = (lookupFlag & LOOKUP_FLAG_IGNORE_BASE_GLYPHS) !== 0;
|
|
49
|
-
const ignoreLigatures = (lookupFlag & LOOKUP_FLAG_IGNORE_LIGATURES) !== 0;
|
|
50
|
-
const ignoreMarks = (lookupFlag & LOOKUP_FLAG_IGNORE_MARKS) !== 0;
|
|
51
|
-
const markAttachmentType = (lookupFlag & LOOKUP_FLAG_MARK_ATTACHMENT_TYPE) >> BITS_PER_BYTE;
|
|
52
|
-
const useMarkFilteringSet = (lookupFlag & LOOKUP_FLAG_USE_MARK_FILTERING_SET) !== 0;
|
|
53
|
-
return (glyphId) => {
|
|
54
|
-
const glyphClass = gdef.glyphClass(glyphId);
|
|
55
|
-
if (ignoreBase && glyphClass === 1) return true;
|
|
56
|
-
if (ignoreLigatures && glyphClass === 2) return true;
|
|
57
|
-
if (glyphClass !== 3) return false;
|
|
58
|
-
if (ignoreMarks) return true;
|
|
59
|
-
if (markAttachmentType !== 0 && gdef.markAttachClass(glyphId) !== markAttachmentType) return true;
|
|
60
|
-
return useMarkFilteringSet && !gdef.markFilteringSetCovers(markFilteringSet, glyphId);
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
function nextVisibleSlot(slots, from, skip) {
|
|
64
|
-
for (let i = Math.max(from, 0); i < slots.length; i++) if (!skip(slots[i].glyphId)) return i;
|
|
65
|
-
}
|
|
66
|
-
function prevVisibleSlot(slots, before, skip) {
|
|
67
|
-
for (let i = Math.min(before, slots.length) - 1; i >= 0; i--) if (!skip(slots[i].glyphId)) return i;
|
|
68
|
-
}
|
|
69
|
-
const SINGLE_SUBST_FORMAT_1_SIZE = 6;
|
|
70
|
-
function parseSingleSubstFormat1(bytes, subtableOffset, skip) {
|
|
71
|
-
if (!hasBytes(bytes, subtableOffset, SINGLE_SUBST_FORMAT_1_SIZE)) return;
|
|
72
|
-
const coverage = parseCoverage(bytes, subtableOffset + u16(bytes, subtableOffset + 2));
|
|
73
|
-
if (coverage === void 0) return;
|
|
74
|
-
const delta = i16(bytes, subtableOffset + SUBST_FORMAT_AND_COVERAGE_SIZE);
|
|
75
|
-
return (slots, index) => {
|
|
76
|
-
const slot = slots[index];
|
|
77
|
-
if (skip(slot.glyphId)) return;
|
|
78
|
-
if (coverage.coverageIndex(slot.glyphId) === void 0) return;
|
|
79
|
-
return {
|
|
80
|
-
consumed: 1,
|
|
81
|
-
replacement: [{
|
|
82
|
-
glyphId: slot.glyphId + delta,
|
|
83
|
-
span: slot.span
|
|
84
|
-
}]
|
|
85
|
-
};
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
const SINGLE_SUBST_FORMAT_2_HEADER_SIZE = 6;
|
|
89
|
-
function parseSingleSubstFormat2(bytes, subtableOffset, skip) {
|
|
90
|
-
if (!hasBytes(bytes, subtableOffset, SINGLE_SUBST_FORMAT_2_HEADER_SIZE)) return;
|
|
91
|
-
const coverage = parseCoverage(bytes, subtableOffset + u16(bytes, subtableOffset + 2));
|
|
92
|
-
if (coverage === void 0) return;
|
|
93
|
-
const glyphCount = u16(bytes, subtableOffset + SUBST_FORMAT_AND_COVERAGE_SIZE);
|
|
94
|
-
const substitutesOffset = subtableOffset + SINGLE_SUBST_FORMAT_2_HEADER_SIZE;
|
|
95
|
-
if (!hasBytes(bytes, substitutesOffset, glyphCount * 2)) return;
|
|
96
|
-
return (slots, index) => {
|
|
97
|
-
const slot = slots[index];
|
|
98
|
-
if (skip(slot.glyphId)) return;
|
|
99
|
-
const coverageIndex = coverage.coverageIndex(slot.glyphId);
|
|
100
|
-
if (coverageIndex === void 0 || coverageIndex >= glyphCount) return;
|
|
101
|
-
return {
|
|
102
|
-
consumed: 1,
|
|
103
|
-
replacement: [{
|
|
104
|
-
glyphId: u16(bytes, substitutesOffset + coverageIndex * 2),
|
|
105
|
-
span: slot.span
|
|
106
|
-
}]
|
|
107
|
-
};
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
|
-
const LIGATURE_SUBST_FORMAT_1_HEADER_SIZE = 6;
|
|
111
|
-
const LIGATURE_SET_HEADER_SIZE = 2;
|
|
112
|
-
const LIGATURE_HEADER_PREFIX_SIZE = 4;
|
|
113
|
-
function parseLigatureSubstFormat1(bytes, subtableOffset, skip) {
|
|
114
|
-
if (!hasBytes(bytes, subtableOffset, LIGATURE_SUBST_FORMAT_1_HEADER_SIZE)) return;
|
|
115
|
-
const coverage = parseCoverage(bytes, subtableOffset + u16(bytes, subtableOffset + 2));
|
|
116
|
-
if (coverage === void 0) return;
|
|
117
|
-
const ligSetCount = u16(bytes, subtableOffset + SUBST_FORMAT_AND_COVERAGE_SIZE);
|
|
118
|
-
const ligSetOffsetsOffset = subtableOffset + LIGATURE_SUBST_FORMAT_1_HEADER_SIZE;
|
|
119
|
-
if (!hasBytes(bytes, ligSetOffsetsOffset, ligSetCount * 2)) return;
|
|
120
|
-
return (slots, index) => {
|
|
121
|
-
const first = slots[index];
|
|
122
|
-
if (skip(first.glyphId)) return;
|
|
123
|
-
const coverageIndex = coverage.coverageIndex(first.glyphId);
|
|
124
|
-
if (coverageIndex === void 0 || coverageIndex >= ligSetCount) return;
|
|
125
|
-
const ligSetOffset = subtableOffset + u16(bytes, ligSetOffsetsOffset + coverageIndex * 2);
|
|
126
|
-
if (!hasBytes(bytes, ligSetOffset, LIGATURE_SET_HEADER_SIZE)) return;
|
|
127
|
-
const ligatureCount = u16(bytes, ligSetOffset);
|
|
128
|
-
const ligatureOffsetsOffset = ligSetOffset + LIGATURE_SET_HEADER_SIZE;
|
|
129
|
-
if (!hasBytes(bytes, ligatureOffsetsOffset, ligatureCount * 2)) return;
|
|
130
|
-
for (let i = 0; i < ligatureCount; i++) {
|
|
131
|
-
const ligatureOffset = ligSetOffset + u16(bytes, ligatureOffsetsOffset + i * 2);
|
|
132
|
-
if (!hasBytes(bytes, ligatureOffset, LIGATURE_HEADER_PREFIX_SIZE)) continue;
|
|
133
|
-
const ligatureGlyph = u16(bytes, ligatureOffset);
|
|
134
|
-
const componentCount = u16(bytes, ligatureOffset + 2);
|
|
135
|
-
if (componentCount === 0) continue;
|
|
136
|
-
const componentsOffset = ligatureOffset + LIGATURE_HEADER_PREFIX_SIZE;
|
|
137
|
-
if (!hasBytes(bytes, componentsOffset, (componentCount - 1) * 2)) continue;
|
|
138
|
-
const matchedSlots = [index];
|
|
139
|
-
let cursor = index;
|
|
140
|
-
let matches = true;
|
|
141
|
-
for (let c = 1; c < componentCount; c++) {
|
|
142
|
-
const next = nextVisibleSlot(slots, cursor + 1, skip);
|
|
143
|
-
if (next === void 0 || slots[next].glyphId !== u16(bytes, componentsOffset + (c - 1) * 2)) {
|
|
144
|
-
matches = false;
|
|
145
|
-
break;
|
|
146
|
-
}
|
|
147
|
-
matchedSlots.push(next);
|
|
148
|
-
cursor = next;
|
|
149
|
-
}
|
|
150
|
-
if (!matches) continue;
|
|
151
|
-
const lastSlot = matchedSlots[matchedSlots.length - 1];
|
|
152
|
-
let windowSpan = 0;
|
|
153
|
-
const retained = [];
|
|
154
|
-
for (let s = index; s <= lastSlot; s++) {
|
|
155
|
-
windowSpan += slots[s].span;
|
|
156
|
-
if (skip(slots[s].glyphId)) retained.push({
|
|
157
|
-
glyphId: slots[s].glyphId,
|
|
158
|
-
span: 0
|
|
159
|
-
});
|
|
160
|
-
}
|
|
161
|
-
return {
|
|
162
|
-
consumed: lastSlot - index + 1,
|
|
163
|
-
replacement: [{
|
|
164
|
-
glyphId: ligatureGlyph,
|
|
165
|
-
span: windowSpan
|
|
166
|
-
}, ...retained]
|
|
167
|
-
};
|
|
168
|
-
}
|
|
169
|
-
};
|
|
170
|
-
}
|
|
171
|
-
function matchContextualRule(slots, index, skip, backtrack, inputTests, lookahead) {
|
|
172
|
-
const inputSlots = [index];
|
|
173
|
-
let cursor = index;
|
|
174
|
-
for (const test of inputTests) {
|
|
175
|
-
const next = nextVisibleSlot(slots, cursor + 1, skip);
|
|
176
|
-
if (next === void 0 || !test(slots[next].glyphId)) return;
|
|
177
|
-
inputSlots.push(next);
|
|
178
|
-
cursor = next;
|
|
179
|
-
}
|
|
180
|
-
let back = index;
|
|
181
|
-
for (let b = backtrack.length - 1; b >= 0; b--) {
|
|
182
|
-
const previous = prevVisibleSlot(slots, back, skip);
|
|
183
|
-
if (previous === void 0 || !backtrack[b](slots[previous].glyphId)) return;
|
|
184
|
-
back = previous;
|
|
185
|
-
}
|
|
186
|
-
let ahead = inputSlots[inputSlots.length - 1];
|
|
187
|
-
for (const test of lookahead) {
|
|
188
|
-
const next = nextVisibleSlot(slots, ahead + 1, skip);
|
|
189
|
-
if (next === void 0 || !test(slots[next].glyphId)) return;
|
|
190
|
-
ahead = next;
|
|
191
|
-
}
|
|
192
|
-
return inputSlots;
|
|
193
|
-
}
|
|
194
|
-
function applyContextualRule(slots, inputSlots, records, lookupOf, skip, depth) {
|
|
195
|
-
const first = inputSlots[0];
|
|
196
|
-
const last = inputSlots[inputSlots.length - 1];
|
|
197
|
-
const window = [];
|
|
198
|
-
for (let s = first; s <= last; s++) window.push({
|
|
199
|
-
glyphId: slots[s].glyphId,
|
|
200
|
-
span: slots[s].span
|
|
201
|
-
});
|
|
202
|
-
for (const record of records) {
|
|
203
|
-
const lookup = lookupOf(record.lookupIndex);
|
|
204
|
-
if (lookup === void 0 || record.sequenceIndex >= inputSlots.length || depth >= MAX_LOOKUP_NESTING_DEPTH) return;
|
|
205
|
-
const target = visibleInputSlot(window, record.sequenceIndex, skip);
|
|
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
|
-
}
|
|
210
|
-
}
|
|
211
|
-
return {
|
|
212
|
-
consumed: last - first + 1,
|
|
213
|
-
replacement: window
|
|
214
|
-
};
|
|
215
|
-
}
|
|
216
|
-
function visibleInputSlot(window, position, skip) {
|
|
217
|
-
let seen = 0;
|
|
218
|
-
for (let i = 0; i < window.length; i++) {
|
|
219
|
-
if (skip(window[i].glyphId)) continue;
|
|
220
|
-
if (seen === position) return i;
|
|
221
|
-
seen += 1;
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
function applyLookupAtSlot(slots, index, lookup, depth) {
|
|
225
|
-
for (const subtable of lookup.subtables) {
|
|
226
|
-
const application = subtable(slots, index, depth);
|
|
227
|
-
if (application !== void 0) return application;
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
const SUBST_LOOKUP_RECORD_SIZE = 4;
|
|
231
|
-
function readSubstLookupRecords(bytes, offset, count) {
|
|
232
|
-
if (!hasBytes(bytes, offset, count * SUBST_LOOKUP_RECORD_SIZE)) return;
|
|
233
|
-
const records = [];
|
|
234
|
-
for (let i = 0; i < count; i++) {
|
|
235
|
-
const recordOffset = offset + i * SUBST_LOOKUP_RECORD_SIZE;
|
|
236
|
-
records.push({
|
|
237
|
-
sequenceIndex: u16(bytes, recordOffset),
|
|
238
|
-
lookupIndex: u16(bytes, recordOffset + 2)
|
|
239
|
-
});
|
|
240
|
-
}
|
|
241
|
-
return records;
|
|
242
|
-
}
|
|
243
|
-
function parseFormat3Rule(bytes, subtableOffset, chained) {
|
|
244
|
-
let offset = subtableOffset + 2;
|
|
245
|
-
const backtrack = [];
|
|
246
|
-
const input = [];
|
|
247
|
-
const lookahead = [];
|
|
248
|
-
const readCoverageArray = () => {
|
|
249
|
-
if (!hasBytes(bytes, offset, 2)) return;
|
|
250
|
-
const count = u16(bytes, offset);
|
|
251
|
-
offset += 2;
|
|
252
|
-
if (!hasBytes(bytes, offset, count * 2)) return;
|
|
253
|
-
const coverages = [];
|
|
254
|
-
for (let i = 0; i < count; i++) {
|
|
255
|
-
const coverageOffset = u16(bytes, offset + i * 2);
|
|
256
|
-
if (coverageOffset === 0) return;
|
|
257
|
-
const coverage = parseCoverage(bytes, subtableOffset + coverageOffset);
|
|
258
|
-
if (coverage === void 0) return;
|
|
259
|
-
coverages.push(coverage);
|
|
260
|
-
}
|
|
261
|
-
offset += count * 2;
|
|
262
|
-
return coverages;
|
|
263
|
-
};
|
|
264
|
-
if (chained) {
|
|
265
|
-
const backtracks = readCoverageArray();
|
|
266
|
-
if (backtracks === void 0) return;
|
|
267
|
-
backtrack.push(...backtracks);
|
|
268
|
-
}
|
|
269
|
-
{
|
|
270
|
-
const inputs = readCoverageArray();
|
|
271
|
-
if (inputs === void 0 || inputs.length === 0) return;
|
|
272
|
-
input.push(...inputs);
|
|
273
|
-
}
|
|
274
|
-
if (chained) {
|
|
275
|
-
const lookaheads = readCoverageArray();
|
|
276
|
-
if (lookaheads === void 0) return;
|
|
277
|
-
lookahead.push(...lookaheads);
|
|
278
|
-
}
|
|
279
|
-
if (!hasBytes(bytes, offset, 2)) return;
|
|
280
|
-
const substCount = u16(bytes, offset);
|
|
281
|
-
const records = readSubstLookupRecords(bytes, offset + 2, substCount);
|
|
282
|
-
if (records === void 0) return;
|
|
283
|
-
return {
|
|
284
|
-
backtrack,
|
|
285
|
-
input,
|
|
286
|
-
lookahead,
|
|
287
|
-
records
|
|
288
|
-
};
|
|
289
|
-
}
|
|
290
|
-
function format3Subtable(rule, skip, lookupOf) {
|
|
291
|
-
const inputRest = [];
|
|
292
|
-
for (let i = 1; i < rule.input.length; i++) {
|
|
293
|
-
const coverage = rule.input[i];
|
|
294
|
-
inputRest.push((glyphId) => coverage.coverageIndex(glyphId) !== void 0);
|
|
295
|
-
}
|
|
296
|
-
const backtrack = rule.backtrack.map((coverage) => (glyphId) => coverage.coverageIndex(glyphId) !== void 0);
|
|
297
|
-
const lookahead = rule.lookahead.map((coverage) => (glyphId) => coverage.coverageIndex(glyphId) !== void 0);
|
|
298
|
-
return (slots, index, depth) => {
|
|
299
|
-
const slot = slots[index];
|
|
300
|
-
if (skip(slot.glyphId)) return;
|
|
301
|
-
if (rule.input[0].coverageIndex(slot.glyphId) === void 0) return;
|
|
302
|
-
const inputSlots = matchContextualRule(slots, index, skip, backtrack, inputRest, lookahead);
|
|
303
|
-
if (inputSlots === void 0) return;
|
|
304
|
-
return applyContextualRule(slots, inputSlots, rule.records, lookupOf, skip, depth);
|
|
305
|
-
};
|
|
306
|
-
}
|
|
307
|
-
function readSequenceRule(bytes, ruleOffset, chained) {
|
|
308
|
-
let offset = ruleOffset;
|
|
309
|
-
const readU16 = () => {
|
|
310
|
-
if (!hasBytes(bytes, offset, 2)) return;
|
|
311
|
-
const value = u16(bytes, offset);
|
|
312
|
-
offset += 2;
|
|
313
|
-
return value;
|
|
314
|
-
};
|
|
315
|
-
const readArray = () => {
|
|
316
|
-
const count = readU16();
|
|
317
|
-
if (count === void 0 || !hasBytes(bytes, offset, count * 2)) return;
|
|
318
|
-
const values = [];
|
|
319
|
-
for (let i = 0; i < count; i++) values.push(u16(bytes, offset + i * 2));
|
|
320
|
-
offset += count * 2;
|
|
321
|
-
return values;
|
|
322
|
-
};
|
|
323
|
-
const backtrack = chained ? readArray() : [];
|
|
324
|
-
const glyphCount = readU16();
|
|
325
|
-
if (backtrack === void 0 || glyphCount === void 0 || glyphCount === 0 || !hasBytes(bytes, offset, (glyphCount - 1) * 2)) return;
|
|
326
|
-
const input = [];
|
|
327
|
-
for (let i = 0; i < glyphCount - 1; i++) input.push(u16(bytes, offset + i * 2));
|
|
328
|
-
offset += (glyphCount - 1) * 2;
|
|
329
|
-
const lookahead = chained ? readArray() : [];
|
|
330
|
-
const substCount = readU16();
|
|
331
|
-
if (lookahead === void 0 || substCount === void 0) return;
|
|
332
|
-
const records = readSubstLookupRecords(bytes, offset, substCount);
|
|
333
|
-
if (records === void 0) return;
|
|
334
|
-
return {
|
|
335
|
-
backtrack,
|
|
336
|
-
input,
|
|
337
|
-
lookahead,
|
|
338
|
-
records
|
|
339
|
-
};
|
|
340
|
-
}
|
|
341
|
-
function sequenceSubtable(bytes, subtableOffset, coverage, setCount, setOffsetsOffset, chained, access, skip, lookupOf) {
|
|
342
|
-
const readSet = (entryGlyphId) => {
|
|
343
|
-
const setIndex = access.setIndexOf(entryGlyphId);
|
|
344
|
-
if (setIndex === void 0 || setIndex >= setCount) return [];
|
|
345
|
-
const setOffset = u16(bytes, setOffsetsOffset + setIndex * 2);
|
|
346
|
-
if (setOffset === 0) return [];
|
|
347
|
-
const ruleSetOffset = subtableOffset + setOffset;
|
|
348
|
-
if (!hasBytes(bytes, ruleSetOffset, 2)) return [];
|
|
349
|
-
const ruleCount = u16(bytes, ruleSetOffset);
|
|
350
|
-
if (!hasBytes(bytes, ruleSetOffset + 2, ruleCount * 2)) return [];
|
|
351
|
-
const rules = [];
|
|
352
|
-
for (let i = 0; i < ruleCount; i++) {
|
|
353
|
-
const rule = readSequenceRule(bytes, ruleSetOffset + u16(bytes, ruleSetOffset + 2 + i * 2), chained);
|
|
354
|
-
if (rule !== void 0) rules.push(rule);
|
|
355
|
-
}
|
|
356
|
-
return rules;
|
|
357
|
-
};
|
|
358
|
-
return (slots, index, depth) => {
|
|
359
|
-
const slot = slots[index];
|
|
360
|
-
if (skip(slot.glyphId)) return;
|
|
361
|
-
if (coverage.coverageIndex(slot.glyphId) === void 0) return;
|
|
362
|
-
for (const rule of readSet(slot.glyphId)) {
|
|
363
|
-
const inputSlots = matchContextualRule(slots, index, skip, rule.backtrack.map(access.backtrackTest), rule.input.map(access.inputTest), rule.lookahead.map(access.lookaheadTest));
|
|
364
|
-
if (inputSlots !== void 0) return applyContextualRule(slots, inputSlots, rule.records, lookupOf, skip, depth);
|
|
365
|
-
}
|
|
366
|
-
};
|
|
367
|
-
}
|
|
368
|
-
function parseSubtable(bytes, lookupType, subtableOffset, skip, lookupOf) {
|
|
369
|
-
if (lookupType === LOOKUP_TYPE_EXTENSION_SUBST) {
|
|
370
|
-
if (!hasBytes(bytes, subtableOffset, EXTENSION_SUBST_HEADER_SIZE) || u16(bytes, subtableOffset) !== 1) return;
|
|
371
|
-
const extensionLookupType = u16(bytes, subtableOffset + 2);
|
|
372
|
-
if (extensionLookupType === LOOKUP_TYPE_EXTENSION_SUBST) return;
|
|
373
|
-
return parseSubtable(bytes, extensionLookupType, subtableOffset + u32(bytes, subtableOffset + EXTENSION_SUBST_OFFSET_FIELD_OFFSET), skip, lookupOf);
|
|
374
|
-
}
|
|
375
|
-
if (lookupType === LOOKUP_TYPE_SINGLE_SUBST) {
|
|
376
|
-
if (!hasBytes(bytes, subtableOffset, 2)) return;
|
|
377
|
-
const substFormat = u16(bytes, subtableOffset);
|
|
378
|
-
if (substFormat === 1) return parseSingleSubstFormat1(bytes, subtableOffset, skip);
|
|
379
|
-
if (substFormat === 2) return parseSingleSubstFormat2(bytes, subtableOffset, skip);
|
|
380
|
-
return;
|
|
381
|
-
}
|
|
382
|
-
if (lookupType === LOOKUP_TYPE_LIGATURE_SUBST) {
|
|
383
|
-
if (!hasBytes(bytes, subtableOffset, 2)) return;
|
|
384
|
-
if (u16(bytes, subtableOffset) !== 1) return;
|
|
385
|
-
return parseLigatureSubstFormat1(bytes, subtableOffset, skip);
|
|
386
|
-
}
|
|
387
|
-
if (lookupType === LOOKUP_TYPE_CONTEXT_SUBST || lookupType === LOOKUP_TYPE_CHAIN_CONTEXT_SUBST) return parseContextualSubtable(bytes, lookupType === LOOKUP_TYPE_CHAIN_CONTEXT_SUBST, subtableOffset, skip, lookupOf);
|
|
388
|
-
}
|
|
389
|
-
function parseContextualSubtable(bytes, chained, subtableOffset, skip, lookupOf) {
|
|
390
|
-
if (!hasBytes(bytes, subtableOffset, 2)) return;
|
|
391
|
-
const substFormat = u16(bytes, subtableOffset);
|
|
392
|
-
if (substFormat === 3) {
|
|
393
|
-
const rule = parseFormat3Rule(bytes, subtableOffset, chained);
|
|
394
|
-
return rule === void 0 ? void 0 : format3Subtable(rule, skip, lookupOf);
|
|
395
|
-
}
|
|
396
|
-
if (substFormat === 1) {
|
|
397
|
-
const prefixSize = 6;
|
|
398
|
-
if (!hasBytes(bytes, subtableOffset, prefixSize)) return;
|
|
399
|
-
const coverage = parseCoverage(bytes, subtableOffset + u16(bytes, subtableOffset + 2));
|
|
400
|
-
if (coverage === void 0) return;
|
|
401
|
-
const setCount = u16(bytes, subtableOffset + SUBST_FORMAT_AND_COVERAGE_SIZE);
|
|
402
|
-
const setOffsetsOffset = subtableOffset + prefixSize;
|
|
403
|
-
if (!hasBytes(bytes, setOffsetsOffset, setCount * 2)) return;
|
|
404
|
-
const glyphEquality = (expected) => (glyphId) => glyphId === expected;
|
|
405
|
-
return sequenceSubtable(bytes, subtableOffset, coverage, setCount, setOffsetsOffset, chained, {
|
|
406
|
-
setIndexOf: (entryGlyphId) => coverage.coverageIndex(entryGlyphId),
|
|
407
|
-
backtrackTest: glyphEquality,
|
|
408
|
-
inputTest: glyphEquality,
|
|
409
|
-
lookaheadTest: glyphEquality
|
|
410
|
-
}, skip, lookupOf);
|
|
411
|
-
}
|
|
412
|
-
if (substFormat === 2) {
|
|
413
|
-
const prefixSize = chained ? 12 : 8;
|
|
414
|
-
if (!hasBytes(bytes, subtableOffset, prefixSize)) return;
|
|
415
|
-
const coverage = parseCoverage(bytes, subtableOffset + u16(bytes, subtableOffset + 2));
|
|
416
|
-
if (coverage === void 0) return;
|
|
417
|
-
const inputClassDefOffset = chained ? u16(bytes, subtableOffset + 6) : u16(bytes, subtableOffset + SUBST_FORMAT_AND_COVERAGE_SIZE);
|
|
418
|
-
const inputClassDef = inputClassDefOffset === 0 ? constantZeroClassDef : parseClassDef(bytes, subtableOffset + inputClassDefOffset);
|
|
419
|
-
const readAuxClassDef = (offset) => offset === 0 ? constantZeroClassDef : parseClassDef(bytes, subtableOffset + offset);
|
|
420
|
-
const backtrackClassDef = chained ? readAuxClassDef(u16(bytes, subtableOffset + SUBST_FORMAT_AND_COVERAGE_SIZE)) : constantZeroClassDef;
|
|
421
|
-
const lookaheadClassDef = chained ? readAuxClassDef(u16(bytes, subtableOffset + 8)) : constantZeroClassDef;
|
|
422
|
-
if (inputClassDef === void 0 || backtrackClassDef === void 0 || lookaheadClassDef === void 0) return;
|
|
423
|
-
const setCount = u16(bytes, subtableOffset + prefixSize - 2);
|
|
424
|
-
const setOffsetsOffset = subtableOffset + prefixSize;
|
|
425
|
-
if (!hasBytes(bytes, setOffsetsOffset, setCount * 2)) return;
|
|
426
|
-
const classEquality = (classDef, expected) => (glyphId) => classDef(glyphId) === expected;
|
|
427
|
-
return sequenceSubtable(bytes, subtableOffset, coverage, setCount, setOffsetsOffset, chained, {
|
|
428
|
-
setIndexOf: (entryGlyphId) => inputClassDef(entryGlyphId),
|
|
429
|
-
backtrackTest: (expected) => classEquality(backtrackClassDef, expected),
|
|
430
|
-
inputTest: (expected) => classEquality(inputClassDef, expected),
|
|
431
|
-
lookaheadTest: (expected) => classEquality(lookaheadClassDef, expected)
|
|
432
|
-
}, skip, lookupOf);
|
|
433
|
-
}
|
|
434
|
-
}
|
|
435
|
-
function findScriptOffset(bytes, scriptListOffset) {
|
|
436
|
-
if (!hasBytes(bytes, scriptListOffset, 2)) return;
|
|
437
|
-
const scriptCount = u16(bytes, scriptListOffset);
|
|
438
|
-
const recordsOffset = scriptListOffset + 2;
|
|
439
|
-
if (!hasBytes(bytes, recordsOffset, scriptCount * SCRIPT_RECORD_SIZE) || scriptCount === 0) return;
|
|
440
|
-
for (const wanted of PREFERRED_SCRIPT_TAGS) for (let i = 0; i < scriptCount; i++) {
|
|
441
|
-
const recordOffset = recordsOffset + i * SCRIPT_RECORD_SIZE;
|
|
442
|
-
if (readTag(bytes, recordOffset) === wanted) return scriptListOffset + u16(bytes, recordOffset + SCRIPT_RECORD_OFFSET_FIELD_OFFSET);
|
|
443
|
-
}
|
|
444
|
-
return scriptListOffset + u16(bytes, recordsOffset + SCRIPT_RECORD_OFFSET_FIELD_OFFSET);
|
|
445
|
-
}
|
|
446
|
-
function parseDefaultLangSysFeatureIndices(bytes, scriptOffset) {
|
|
447
|
-
if (!hasBytes(bytes, scriptOffset, 2)) return [];
|
|
448
|
-
const defaultLangSysOffset = u16(bytes, scriptOffset);
|
|
449
|
-
if (defaultLangSysOffset === 0) return [];
|
|
450
|
-
const langSysOffset = scriptOffset + defaultLangSysOffset;
|
|
451
|
-
if (!hasBytes(bytes, langSysOffset, LANG_SYS_HEADER_SIZE)) return [];
|
|
452
|
-
const featureIndexCount = u16(bytes, langSysOffset + LANG_SYS_FEATURE_INDEX_COUNT_OFFSET);
|
|
453
|
-
const indicesOffset = langSysOffset + LANG_SYS_HEADER_SIZE;
|
|
454
|
-
if (!hasBytes(bytes, indicesOffset, featureIndexCount * 2)) return [];
|
|
455
|
-
const indices = [];
|
|
456
|
-
for (let i = 0; i < featureIndexCount; i++) indices.push(u16(bytes, indicesOffset + i * 2));
|
|
457
|
-
return indices;
|
|
458
|
-
}
|
|
459
|
-
function collectLookupIndices(bytes, featureListOffset, featureIndices, featureTags) {
|
|
460
|
-
if (!hasBytes(bytes, featureListOffset, 2)) return [];
|
|
461
|
-
const featureCount = u16(bytes, featureListOffset);
|
|
462
|
-
const recordsOffset = featureListOffset + 2;
|
|
463
|
-
if (!hasBytes(bytes, recordsOffset, featureCount * FEATURE_RECORD_SIZE)) return [];
|
|
464
|
-
const lookupIndices = [];
|
|
465
|
-
const seen = /* @__PURE__ */ new Set();
|
|
466
|
-
for (const featureIndex of featureIndices) {
|
|
467
|
-
if (featureIndex >= featureCount) continue;
|
|
468
|
-
const recordOffset = recordsOffset + featureIndex * FEATURE_RECORD_SIZE;
|
|
469
|
-
if (!featureTags.includes(readTag(bytes, recordOffset))) continue;
|
|
470
|
-
const featureOffset = featureListOffset + u16(bytes, recordOffset + FEATURE_RECORD_OFFSET_FIELD_OFFSET);
|
|
471
|
-
if (!hasBytes(bytes, featureOffset, FEATURE_HEADER_SIZE)) continue;
|
|
472
|
-
const lookupIndexCount = u16(bytes, featureOffset + 2);
|
|
473
|
-
const indicesOffset = featureOffset + FEATURE_HEADER_SIZE;
|
|
474
|
-
if (!hasBytes(bytes, indicesOffset, lookupIndexCount * 2)) continue;
|
|
475
|
-
for (let i = 0; i < lookupIndexCount; i++) {
|
|
476
|
-
const lookupIndex = u16(bytes, indicesOffset + i * 2);
|
|
477
|
-
if (!seen.has(lookupIndex)) {
|
|
478
|
-
seen.add(lookupIndex);
|
|
479
|
-
lookupIndices.push(lookupIndex);
|
|
480
|
-
}
|
|
481
|
-
}
|
|
482
|
-
}
|
|
483
|
-
return lookupIndices;
|
|
484
|
-
}
|
|
485
|
-
function buildGsubShaper(font, options = {}) {
|
|
486
|
-
const bytes = sfntTableBytes(font, "GSUB");
|
|
487
|
-
if (bytes === void 0 || !hasBytes(bytes, 0, GSUB_HEADER_SIZE) || u16(bytes, 0) !== 1) return;
|
|
488
|
-
const scriptOffset = findScriptOffset(bytes, u16(bytes, GSUB_HEADER_SCRIPT_LIST_OFFSET));
|
|
489
|
-
if (scriptOffset === void 0) return;
|
|
490
|
-
const featureTags = [...DEFAULT_GSUB_FEATURE_TAGS, ...options.optInFeatures ?? []];
|
|
491
|
-
const lookupIndices = collectLookupIndices(bytes, u16(bytes, GSUB_HEADER_FEATURE_LIST_OFFSET), parseDefaultLangSysFeatureIndices(bytes, scriptOffset), featureTags);
|
|
492
|
-
if (lookupIndices.length === 0) return;
|
|
493
|
-
const lookupListOffset = u16(bytes, GSUB_HEADER_LOOKUP_LIST_OFFSET);
|
|
494
|
-
if (!hasBytes(bytes, lookupListOffset, 2)) return;
|
|
495
|
-
const lookupCount = u16(bytes, lookupListOffset);
|
|
496
|
-
const lookupOffsetsOffset = lookupListOffset + 2;
|
|
497
|
-
if (!hasBytes(bytes, lookupOffsetsOffset, lookupCount * 2)) return;
|
|
498
|
-
const gdef = parseGdefTable(font);
|
|
499
|
-
const lookups = [];
|
|
500
|
-
const lookupOf = (lookupIndex) => lookups[lookupIndex];
|
|
501
|
-
for (let i = 0; i < lookupCount; i++) {
|
|
502
|
-
const lookupOffset = lookupListOffset + u16(bytes, lookupOffsetsOffset + i * 2);
|
|
503
|
-
if (!hasBytes(bytes, lookupOffset, LOOKUP_HEADER_SIZE)) {
|
|
504
|
-
lookups.push(void 0);
|
|
505
|
-
continue;
|
|
506
|
-
}
|
|
507
|
-
const lookupFlag = u16(bytes, lookupOffset + 2);
|
|
508
|
-
const lookupType = u16(bytes, lookupOffset);
|
|
509
|
-
const subTableCount = u16(bytes, lookupOffset + LOOKUP_HEADER_SUBTABLE_COUNT_OFFSET);
|
|
510
|
-
const subtableOffsetsOffset = lookupOffset + LOOKUP_HEADER_SIZE;
|
|
511
|
-
const markFilteringSetWidth = (lookupFlag & LOOKUP_FLAG_USE_MARK_FILTERING_SET) !== 0 ? 2 : 0;
|
|
512
|
-
if (!hasBytes(bytes, subtableOffsetsOffset, subTableCount * 2 + markFilteringSetWidth)) {
|
|
513
|
-
lookups.push(void 0);
|
|
514
|
-
continue;
|
|
515
|
-
}
|
|
516
|
-
const skip = glyphSkipper(lookupFlag, markFilteringSetWidth === 0 ? 0 : u16(bytes, subtableOffsetsOffset + subTableCount * 2), gdef);
|
|
517
|
-
const subtables = [];
|
|
518
|
-
for (let s = 0; s < subTableCount; s++) {
|
|
519
|
-
const subtable = parseSubtable(bytes, lookupType, lookupOffset + u16(bytes, subtableOffsetsOffset + s * 2), skip, lookupOf);
|
|
520
|
-
if (subtable !== void 0) subtables.push(subtable);
|
|
521
|
-
}
|
|
522
|
-
lookups.push({ subtables });
|
|
523
|
-
}
|
|
524
|
-
const appliedLookups = [];
|
|
525
|
-
for (const lookupIndex of lookupIndices) {
|
|
526
|
-
const lookup = lookupOf(lookupIndex);
|
|
527
|
-
if (lookup !== void 0) appliedLookups.push(lookup);
|
|
528
|
-
}
|
|
529
|
-
if (appliedLookups.every((lookup) => lookup.subtables.length === 0)) return;
|
|
530
|
-
return (glyphIds) => {
|
|
531
|
-
const slots = glyphIds.map((glyphId) => ({
|
|
532
|
-
glyphId,
|
|
533
|
-
span: 1
|
|
534
|
-
}));
|
|
535
|
-
for (const lookup of appliedLookups) {
|
|
536
|
-
let slotIndex = 0;
|
|
537
|
-
while (slotIndex < slots.length) {
|
|
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;
|
|
545
|
-
}
|
|
546
|
-
}
|
|
547
|
-
return {
|
|
548
|
-
glyphIds: slots.map((slot) => slot.glyphId),
|
|
549
|
-
spans: slots.map((slot) => slot.span)
|
|
550
|
-
};
|
|
551
|
-
};
|
|
552
|
-
}
|
|
553
|
-
//#endregion
|
|
554
|
-
export { DEFAULT_GSUB_FEATURE_TAGS, GSUB_OPT_IN_FEATURE_TAGS, buildGsubShaper };
|
|
1
|
+
import { _ as parseSingleSubstFormat1, a as LOOKUP_TYPE_CHAIN_CONTEXT_SUBST, b as readTag, c as LOOKUP_TYPE_LIGATURE_SUBST, d as SUBST_FORMAT_AND_COVERAGE_SIZE, f as buildGsubShaper, g as parseLigatureSubstFormat1, h as nextVisibleSlot, i as GSUB_OPT_IN_FEATURE_TAGS, l as LOOKUP_TYPE_SINGLE_SUBST, m as glyphSkipper, n as EXTENSION_SUBST_HEADER_SIZE, o as LOOKUP_TYPE_CONTEXT_SUBST, p as constantZeroClassDef, r as EXTENSION_SUBST_OFFSET_FIELD_OFFSET, s as LOOKUP_TYPE_EXTENSION_SUBST, t as DEFAULT_GSUB_FEATURE_TAGS, u as MAX_LOOKUP_NESTING_DEPTH, v as parseSingleSubstFormat2, y as prevVisibleSlot } from "./gsub-table-D6niKeLi.js";
|
|
2
|
+
export { DEFAULT_GSUB_FEATURE_TAGS, EXTENSION_SUBST_HEADER_SIZE, EXTENSION_SUBST_OFFSET_FIELD_OFFSET, GSUB_OPT_IN_FEATURE_TAGS, LOOKUP_TYPE_CHAIN_CONTEXT_SUBST, LOOKUP_TYPE_CONTEXT_SUBST, LOOKUP_TYPE_EXTENSION_SUBST, LOOKUP_TYPE_LIGATURE_SUBST, LOOKUP_TYPE_SINGLE_SUBST, MAX_LOOKUP_NESTING_DEPTH, SUBST_FORMAT_AND_COVERAGE_SIZE, buildGsubShaper, constantZeroClassDef, glyphSkipper, nextVisibleSlot, parseLigatureSubstFormat1, parseSingleSubstFormat1, parseSingleSubstFormat2, prevVisibleSlot, readTag };
|
package/dist/images-read.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { PdfDiagnosticSink } from "./diagnostics.cjs";
|
|
1
|
+
import { i as PdfDiagnosticSink } from "./diagnostics-C9FxfZ6H.cjs";
|
|
2
2
|
import { n as PdfDict } from "./objects-e2RS3-yT.cjs";
|
|
3
|
-
import { PdfObjectResolver } from "./interpret.cjs";
|
|
3
|
+
import { PdfObjectResolver } from "./interpret-types.cjs";
|
|
4
4
|
//#region src/images-read.d.ts
|
|
5
5
|
interface ExtractedPdfImage {
|
|
6
6
|
readonly format: "png" | "jpeg";
|
package/dist/images-read.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { PdfDiagnosticSink } from "./diagnostics.js";
|
|
1
|
+
import { i as PdfDiagnosticSink } from "./diagnostics-C9FxfZ6H.js";
|
|
2
2
|
import { n as PdfDict } from "./objects-e2RS3-yT.js";
|
|
3
|
-
import { PdfObjectResolver } from "./interpret.js";
|
|
3
|
+
import { PdfObjectResolver } from "./interpret-types.js";
|
|
4
4
|
//#region src/images-read.d.ts
|
|
5
5
|
interface ExtractedPdfImage {
|
|
6
6
|
readonly format: "png" | "jpeg";
|
package/dist/index.cjs
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_afm_widths = require("./afm-widths-
|
|
2
|
+
const require_afm_widths = require("./afm-widths-C6U0SQj9.cjs");
|
|
3
3
|
const require_image_ccitt = require("./image/ccitt.cjs");
|
|
4
4
|
const require_image_jbig2_errors = require("./image/jbig2-errors.cjs");
|
|
5
5
|
const require_image_jbig2 = require("./image/jbig2.cjs");
|
|
6
6
|
const require_image_png_filter = require("./image/png-filter.cjs");
|
|
7
|
-
const require_layout = require("./layout.cjs");
|
|
8
|
-
const require_diagnostics = require("./diagnostics.cjs");
|
|
9
|
-
const require_fonts = require("./fonts.cjs");
|
|
10
7
|
const require_image_jpeg2000_errors = require("./image/jpeg2000-errors.cjs");
|
|
11
8
|
const require_image_jp2_boxes = require("./image/jp2-boxes.cjs");
|
|
12
9
|
const require_image_jpeg2000 = require("./image/jpeg2000.cjs");
|
|
10
|
+
const require_layout = require("./layout.cjs");
|
|
11
|
+
const require_diagnostics = require("./diagnostics.cjs");
|
|
12
|
+
const require_fonts = require("./fonts.cjs");
|
|
13
13
|
const require_read = require("./read.cjs");
|
|
14
14
|
const require_encrypt_write = require("./encrypt-write.cjs");
|
|
15
|
-
const require_font_registry = require("./font-registry.cjs");
|
|
16
15
|
const require_math_stretch = require("./math-stretch.cjs");
|
|
17
16
|
const require_math_font = require("./math-font.cjs");
|
|
17
|
+
const require_font_registry = require("./font-registry.cjs");
|
|
18
18
|
const require_measure = require("./measure.cjs");
|
|
19
19
|
const require_write = require("./write.cjs");
|
|
20
20
|
const require_codec = require("./codec.cjs");
|
|
21
21
|
const require_font_face = require("./font-face.cjs");
|
|
22
22
|
const require_text_group = require("./text-group.cjs");
|
|
23
|
-
const require_raster = require("./raster.cjs");
|
|
23
|
+
const require_raster = require("./raster-EG2KYRZ0.cjs");
|
|
24
24
|
exports.DEFAULT_BASELINE_TOLERANCE_EM = require_text_group.DEFAULT_BASELINE_TOLERANCE_EM;
|
|
25
25
|
exports.DEFAULT_COLUMN_GAP_EM = require_text_group.DEFAULT_COLUMN_GAP_EM;
|
|
26
26
|
exports.DEFAULT_VERTICAL_METRIC_POLICY = require_measure.DEFAULT_VERTICAL_METRIC_POLICY;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { n as STANDARD_METRICS, r as StandardFontName, t as FontMetrics } from "./afm-widths-CneRyu5l.cjs";
|
|
2
|
-
import {
|
|
2
|
+
import { a as PdfEncryptedError, i as PdfDiagnosticSink, n as PdfDiagnostic, o as PdfParseError, r as PdfDiagnosticSeverity, s as PdfPasswordRequiredError, t as NOOP_DIAGNOSTIC_SINK } from "./diagnostics-C9FxfZ6H.cjs";
|
|
3
3
|
import { LAYOUT_FORMAT_VERSION, LayoutAnnotation, LayoutAnnotationQuad, LayoutAnnotationQuadSchema, LayoutAnnotationSchema, LayoutAttachment, LayoutAttachmentSchema, LayoutDestination, LayoutDestinationSchema, LayoutDestinationTarget, LayoutDestinationTargetSchema, LayoutDocument, LayoutDocumentSchema, LayoutEllipse, LayoutEllipseSchema, LayoutFormField, LayoutFormFieldSchema, LayoutFormWidget, LayoutFormWidgetSchema, LayoutImage, LayoutImageAsset, LayoutImageAssetSchema, LayoutImageSchema, LayoutInternalLink, LayoutInternalLinkSchema, LayoutItem, LayoutItemSchema, LayoutLayer, LayoutLayerSchema, LayoutLine, LayoutLineSchema, LayoutLink, LayoutLinkSchema, LayoutOutlineItem, LayoutOutlineItemSchema, LayoutPage, LayoutPageSchema, LayoutPath, LayoutPathSchema, LayoutPathSegment, LayoutPathSegmentSchema, LayoutRect, LayoutRectSchema, LayoutStructureElement, LayoutStructureElementSchema, LayoutSubpath, LayoutSubpathSchema, LayoutText, LayoutTextSchema } from "./layout.cjs";
|
|
4
4
|
import { t as GlyphInkBounds } from "./glyph-bounds-BV_Z40KS.cjs";
|
|
5
5
|
import { PdfBytesSchema, pdfCodec } from "./codec.cjs";
|
|
6
|
-
import { n as EmbeddedFaceMetrics, r as EmbeddedFaceSubstitution, t as EmbeddedFace } from "./embedded-font-
|
|
6
|
+
import { n as EmbeddedFaceMetrics, r as EmbeddedFaceSubstitution, t as EmbeddedFace } from "./embedded-font-CqePfvrl.cjs";
|
|
7
7
|
import { WinAnsiSubstitution } from "./winansi.cjs";
|
|
8
8
|
import { PdfEncryptionError, PdfEncryptionOptions, PdfEncryptionPermissions, PdfEncryptionScheme } from "./encrypt-write.cjs";
|
|
9
9
|
import { FontFace, FontFaceParseError, readFontFace } from "./font-face.cjs";
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { n as STANDARD_METRICS, r as StandardFontName, t as FontMetrics } from "./afm-widths-CneRyu5l.js";
|
|
2
|
-
import {
|
|
2
|
+
import { a as PdfEncryptedError, i as PdfDiagnosticSink, n as PdfDiagnostic, o as PdfParseError, r as PdfDiagnosticSeverity, s as PdfPasswordRequiredError, t as NOOP_DIAGNOSTIC_SINK } from "./diagnostics-C9FxfZ6H.js";
|
|
3
3
|
import { LAYOUT_FORMAT_VERSION, LayoutAnnotation, LayoutAnnotationQuad, LayoutAnnotationQuadSchema, LayoutAnnotationSchema, LayoutAttachment, LayoutAttachmentSchema, LayoutDestination, LayoutDestinationSchema, LayoutDestinationTarget, LayoutDestinationTargetSchema, LayoutDocument, LayoutDocumentSchema, LayoutEllipse, LayoutEllipseSchema, LayoutFormField, LayoutFormFieldSchema, LayoutFormWidget, LayoutFormWidgetSchema, LayoutImage, LayoutImageAsset, LayoutImageAssetSchema, LayoutImageSchema, LayoutInternalLink, LayoutInternalLinkSchema, LayoutItem, LayoutItemSchema, LayoutLayer, LayoutLayerSchema, LayoutLine, LayoutLineSchema, LayoutLink, LayoutLinkSchema, LayoutOutlineItem, LayoutOutlineItemSchema, LayoutPage, LayoutPageSchema, LayoutPath, LayoutPathSchema, LayoutPathSegment, LayoutPathSegmentSchema, LayoutRect, LayoutRectSchema, LayoutStructureElement, LayoutStructureElementSchema, LayoutSubpath, LayoutSubpathSchema, LayoutText, LayoutTextSchema } from "./layout.js";
|
|
4
4
|
import { t as GlyphInkBounds } from "./glyph-bounds-BV_Z40KS.js";
|
|
5
5
|
import { PdfBytesSchema, pdfCodec } from "./codec.js";
|
|
6
|
-
import { n as EmbeddedFaceMetrics, r as EmbeddedFaceSubstitution, t as EmbeddedFace } from "./embedded-font-
|
|
6
|
+
import { n as EmbeddedFaceMetrics, r as EmbeddedFaceSubstitution, t as EmbeddedFace } from "./embedded-font-CQZbTTDM.js";
|
|
7
7
|
import { WinAnsiSubstitution } from "./winansi.js";
|
|
8
8
|
import { PdfEncryptionError, PdfEncryptionOptions, PdfEncryptionPermissions, PdfEncryptionScheme } from "./encrypt-write.js";
|
|
9
9
|
import { FontFace, FontFaceParseError, readFontFace } from "./font-face.js";
|