@cantoo/fontkit 2.0.4 → 2.0.6
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/browser-module.mjs +4448 -1142
- package/dist/browser-module.mjs.map +1 -1
- package/dist/browser.cjs +4449 -1142
- package/dist/browser.cjs.map +1 -1
- package/dist/main.cjs +4449 -1142
- package/dist/main.cjs.map +1 -1
- package/dist/module.mjs +4448 -1142
- package/dist/module.mjs.map +1 -1
- package/package.json +4 -1
- package/src/CmapProcessor.js +60 -21
- package/src/DFont.js +114 -14
- package/src/TTFFont.js +260 -62
- package/src/TrueTypeCollection.js +59 -15
- package/src/WOFF2Font.js +128 -22
- package/src/WOFFFont.js +45 -8
- package/src/aat/AATFeatureMap.js +83 -40
- package/src/aat/AATLayoutEngine.js +34 -2
- package/src/aat/AATLookupTable.js +24 -6
- package/src/aat/AATMorxProcessor.js +202 -65
- package/src/aat/AATStateMachine.js +35 -3
- package/src/base.js +20 -1
- package/src/cff/CFFCharsets.js +3 -0
- package/src/cff/CFFDict.js +81 -11
- package/src/cff/CFFEncodings.js +2 -0
- package/src/cff/CFFFont.js +120 -24
- package/src/cff/CFFIndex.js +66 -9
- package/src/cff/CFFOperand.js +53 -28
- package/src/cff/CFFPointer.js +41 -2
- package/src/cff/CFFPrivateDict.js +34 -24
- package/src/cff/CFFStandardStrings.js +68 -67
- package/src/cff/CFFTop.js +161 -68
- package/src/decorators.js +34 -15
- package/src/encodings.js +133 -116
- package/src/fs.js +10 -0
- package/src/glyph/BBox.js +14 -0
- package/src/glyph/CFFGlyph.js +293 -152
- package/src/glyph/COLRGlyph.js +40 -5
- package/src/glyph/Glyph.js +72 -13
- package/src/glyph/GlyphVariationProcessor.js +158 -62
- package/src/glyph/Path.js +119 -32
- package/src/glyph/SBIXGlyph.js +57 -8
- package/src/glyph/StandardNames.js +1 -0
- package/src/glyph/TTFGlyph.js +203 -63
- package/src/glyph/TTFGlyphEncoder.js +58 -26
- package/src/glyph/WOFF2Glyph.js +25 -6
- package/src/layout/GlyphPosition.js +6 -0
- package/src/layout/GlyphRun.js +28 -10
- package/src/layout/KernProcessor.js +63 -4
- package/src/layout/LayoutEngine.js +99 -26
- package/src/layout/Script.js +52 -26
- package/src/layout/UnicodeLayoutEngine.js +34 -10
- package/src/opentype/GPOSProcessor.js +156 -45
- package/src/opentype/GSUBProcessor.js +92 -33
- package/src/opentype/GlyphInfo.js +53 -5
- package/src/opentype/GlyphIterator.js +51 -2
- package/src/opentype/OTLayoutEngine.js +66 -8
- package/src/opentype/OTProcessor.js +284 -71
- package/src/opentype/ShapingPlan.js +52 -5
- package/src/opentype/shapers/ArabicShaper.js +27 -8
- package/src/opentype/shapers/DefaultShaper.js +54 -10
- package/src/opentype/shapers/HangulShaper.js +120 -42
- package/src/opentype/shapers/HebrewShaper.js +50 -16
- package/src/opentype/shapers/IndicShaper.js +159 -44
- package/src/opentype/shapers/ThaiShaper.js +50 -19
- package/src/opentype/shapers/UniversalShaper.js +83 -17
- package/src/opentype/shapers/index.js +48 -35
- package/src/opentype/shapers/indic-data.js +2 -2
- package/src/packages/unicode-properties/data-trie.js +2 -1
- package/src/packages/unicode-properties/data.js +13 -1
- package/src/packages/unicode-properties/dist/index.cjs +23 -10
- package/src/packages/unicode-properties/dist/index.cjs.map +2 -2
- package/src/packages/unicode-properties/dist/index.mjs +22 -10
- package/src/packages/unicode-properties/dist/index.mjs.map +2 -2
- package/src/packages/unicode-properties/generate.js +3 -4
- package/src/packages/unicode-properties/index.js +95 -30
- package/src/packages/unicode-properties/package.json +1 -1
- package/src/packages/unicode-trie/builder.js +146 -29
- package/src/packages/unicode-trie/dist/builder.cjs +135 -25
- package/src/packages/unicode-trie/dist/builder.cjs.map +2 -2
- package/src/packages/unicode-trie/dist/builder.mjs +134 -25
- package/src/packages/unicode-trie/dist/builder.mjs.map +2 -2
- package/src/packages/unicode-trie/dist/index.cjs +22 -9
- package/src/packages/unicode-trie/dist/index.cjs.map +2 -2
- package/src/packages/unicode-trie/dist/index.mjs +21 -9
- package/src/packages/unicode-trie/dist/index.mjs.map +2 -2
- package/src/packages/unicode-trie/index.js +63 -12
- package/src/packages/unicode-trie/package.json +1 -1
- package/src/packages/unicode-trie/swap.js +15 -2
- package/src/subset/CFFSubset.js +112 -22
- package/src/subset/Subset.js +23 -3
- package/src/subset/TTFSubset.js +84 -41
- package/src/tables/BASE.js +28 -27
- package/src/tables/COLR.js +10 -9
- package/src/tables/CPAL.js +2 -1
- package/src/tables/DSIG.js +8 -7
- package/src/tables/EBDT.js +10 -4
- package/src/tables/EBLC.js +70 -10
- package/src/tables/GDEF.js +18 -17
- package/src/tables/GPOS.js +153 -90
- package/src/tables/GSUB.js +50 -39
- package/src/tables/HVAR.js +51 -5
- package/src/tables/JSTF.js +17 -16
- package/src/tables/LTSH.js +4 -3
- package/src/tables/OS2.js +50 -49
- package/src/tables/PCLT.js +16 -15
- package/src/tables/STAT.js +46 -6
- package/src/tables/VDMX.js +18 -17
- package/src/tables/VORG.js +8 -7
- package/src/tables/WOFF2Directory.js +57 -9
- package/src/tables/WOFFDirectory.js +32 -20
- package/src/tables/aat.js +160 -35
- package/src/tables/avar.js +1 -0
- package/src/tables/bsln.js +3 -2
- package/src/tables/cmap.js +83 -63
- package/src/tables/cvt.js +1 -0
- package/src/tables/directory.js +56 -28
- package/src/tables/feat.js +24 -2
- package/src/tables/fpgm.js +1 -0
- package/src/tables/fvar.js +32 -4
- package/src/tables/gasp.js +6 -5
- package/src/tables/glyf.js +2 -1
- package/src/tables/gvar.js +29 -2
- package/src/tables/hdmx.js +18 -7
- package/src/tables/head.js +17 -16
- package/src/tables/hhea.js +15 -14
- package/src/tables/hmtx.js +18 -2
- package/src/tables/index.js +1 -5
- package/src/tables/just.js +15 -4
- package/src/tables/kern.js +84 -47
- package/src/tables/loca.js +23 -10
- package/src/tables/maxp.js +16 -15
- package/src/tables/morx.js +27 -20
- package/src/tables/name.js +120 -39
- package/src/tables/opbd.js +2 -1
- package/src/tables/opentype.js +126 -91
- package/src/tables/post.js +18 -11
- package/src/tables/prep.js +1 -0
- package/src/tables/sbix.js +12 -1
- package/src/tables/variations.js +29 -9
- package/src/tables/vhea.js +15 -14
- package/src/tables/vmtx.js +20 -4
- package/src/utils.js +15 -0
package/src/tables/opentype.js
CHANGED
|
@@ -1,54 +1,60 @@
|
|
|
1
1
|
import * as r from 'restructure';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
/** @typedef {import('restructure').BaseType} BaseType */
|
|
4
|
+
/** @typedef {import('restructure').StructValue} StructValue */
|
|
5
|
+
|
|
6
|
+
// ########################
|
|
4
7
|
// Scripts and Languages #
|
|
5
|
-
|
|
8
|
+
// ########################
|
|
6
9
|
|
|
7
10
|
let LangSysTable = new r.Struct({
|
|
8
|
-
reserved:
|
|
9
|
-
reqFeatureIndex:
|
|
10
|
-
featureCount:
|
|
11
|
-
featureIndexes:
|
|
11
|
+
reserved: new r.Reserved(r.uint16),
|
|
12
|
+
reqFeatureIndex: r.uint16,
|
|
13
|
+
featureCount: r.uint16,
|
|
14
|
+
featureIndexes: new r.Array(r.uint16, 'featureCount')
|
|
12
15
|
});
|
|
13
16
|
|
|
14
17
|
let LangSysRecord = new r.Struct({
|
|
15
|
-
tag:
|
|
16
|
-
langSys:
|
|
18
|
+
tag: new r.String(4),
|
|
19
|
+
langSys: new r.Pointer(r.uint16, LangSysTable, { type: 'parent' })
|
|
17
20
|
});
|
|
18
21
|
|
|
19
22
|
let Script = new r.Struct({
|
|
20
23
|
defaultLangSys: new r.Pointer(r.uint16, LangSysTable),
|
|
21
|
-
count:
|
|
24
|
+
count: r.uint16,
|
|
22
25
|
langSysRecords: new r.Array(LangSysRecord, 'count')
|
|
23
26
|
});
|
|
24
27
|
|
|
25
28
|
let ScriptRecord = new r.Struct({
|
|
26
|
-
tag:
|
|
29
|
+
tag: new r.String(4),
|
|
27
30
|
script: new r.Pointer(r.uint16, Script, { type: 'parent' })
|
|
28
31
|
});
|
|
29
32
|
|
|
33
|
+
/** @type {import('restructure').ArrayT} */
|
|
30
34
|
export let ScriptList = new r.Array(ScriptRecord, r.uint16);
|
|
31
35
|
|
|
32
|
-
|
|
36
|
+
// #######################
|
|
33
37
|
// Features and Lookups #
|
|
34
|
-
|
|
38
|
+
// #######################
|
|
35
39
|
|
|
36
40
|
let FeatureParams = new r.Struct({
|
|
37
|
-
version:
|
|
38
|
-
nameID:
|
|
41
|
+
version: r.uint16, // should be set to 0 according OT spec
|
|
42
|
+
nameID: r.uint16 // OT spec: UI Name ID or uiLabelNameId
|
|
39
43
|
});
|
|
40
44
|
|
|
45
|
+
/** @type {import('restructure').Struct} */
|
|
41
46
|
export let Feature = new r.Struct({
|
|
42
|
-
featureParams:
|
|
43
|
-
lookupCount:
|
|
44
|
-
lookupListIndexes:
|
|
47
|
+
featureParams: new r.Pointer(r.uint16, FeatureParams),
|
|
48
|
+
lookupCount: r.uint16,
|
|
49
|
+
lookupListIndexes: new r.Array(r.uint16, 'lookupCount')
|
|
45
50
|
});
|
|
46
51
|
|
|
47
52
|
let FeatureRecord = new r.Struct({
|
|
48
|
-
tag:
|
|
49
|
-
feature:
|
|
53
|
+
tag: new r.String(4),
|
|
54
|
+
feature: new r.Pointer(r.uint16, Feature, { type: 'parent' })
|
|
50
55
|
});
|
|
51
56
|
|
|
57
|
+
/** @type {import('restructure').ArrayT} */
|
|
52
58
|
export let FeatureList = new r.Array(FeatureRecord, r.uint16);
|
|
53
59
|
|
|
54
60
|
let LookupFlags = new r.Struct({
|
|
@@ -59,159 +65,188 @@ let LookupFlags = new r.Struct({
|
|
|
59
65
|
])
|
|
60
66
|
});
|
|
61
67
|
|
|
68
|
+
/**
|
|
69
|
+
* @param {BaseType} SubTable
|
|
70
|
+
* @returns {import('restructure').LazyArray}
|
|
71
|
+
*/
|
|
62
72
|
export function LookupList(SubTable) {
|
|
63
73
|
let Lookup = new r.Struct({
|
|
64
|
-
lookupType:
|
|
65
|
-
flags:
|
|
66
|
-
subTableCount:
|
|
67
|
-
subTables:
|
|
68
|
-
markFilteringSet:
|
|
74
|
+
lookupType: r.uint16,
|
|
75
|
+
flags: LookupFlags,
|
|
76
|
+
subTableCount: r.uint16,
|
|
77
|
+
subTables: new r.Array(new r.Pointer(r.uint16, SubTable), 'subTableCount'),
|
|
78
|
+
markFilteringSet: new r.Optional(
|
|
79
|
+
r.uint16,
|
|
80
|
+
/** @param {StructValue} t @returns {boolean} */
|
|
81
|
+
(t) => {
|
|
82
|
+
let flags = /** @type {StructValue} */ (t.flags);
|
|
83
|
+
let bits = /** @type {Record<string, boolean>} */ (flags.flags);
|
|
84
|
+
return !!bits.useMarkFilteringSet;
|
|
85
|
+
}
|
|
86
|
+
)
|
|
69
87
|
});
|
|
70
88
|
|
|
71
89
|
return new r.LazyArray(new r.Pointer(r.uint16, Lookup), r.uint16);
|
|
72
90
|
}
|
|
73
91
|
|
|
74
|
-
|
|
92
|
+
// #################
|
|
75
93
|
// Coverage Table #
|
|
76
|
-
|
|
94
|
+
// #################
|
|
77
95
|
|
|
78
96
|
let RangeRecord = new r.Struct({
|
|
79
|
-
start:
|
|
80
|
-
end:
|
|
97
|
+
start: r.uint16,
|
|
98
|
+
end: r.uint16,
|
|
81
99
|
startCoverageIndex: r.uint16
|
|
82
100
|
});
|
|
83
101
|
|
|
102
|
+
/** @type {import('restructure').VersionedStruct} */
|
|
84
103
|
export let Coverage = new r.VersionedStruct(r.uint16, {
|
|
85
104
|
1: {
|
|
86
|
-
glyphCount:
|
|
87
|
-
glyphs:
|
|
105
|
+
glyphCount: r.uint16,
|
|
106
|
+
glyphs: new r.Array(r.uint16, 'glyphCount')
|
|
88
107
|
},
|
|
89
108
|
2: {
|
|
90
|
-
rangeCount:
|
|
109
|
+
rangeCount: r.uint16,
|
|
91
110
|
rangeRecords: new r.Array(RangeRecord, 'rangeCount')
|
|
92
111
|
}
|
|
93
112
|
});
|
|
94
113
|
|
|
95
|
-
|
|
114
|
+
// #########################
|
|
96
115
|
// Class Definition Table #
|
|
97
|
-
|
|
116
|
+
// #########################
|
|
98
117
|
|
|
99
118
|
let ClassRangeRecord = new r.Struct({
|
|
100
|
-
start:
|
|
101
|
-
end:
|
|
102
|
-
class:
|
|
119
|
+
start: r.uint16,
|
|
120
|
+
end: r.uint16,
|
|
121
|
+
class: r.uint16
|
|
103
122
|
});
|
|
104
123
|
|
|
124
|
+
/** @type {import('restructure').VersionedStruct} */
|
|
105
125
|
export let ClassDef = new r.VersionedStruct(r.uint16, {
|
|
106
126
|
1: { // Class array
|
|
107
|
-
startGlyph:
|
|
108
|
-
glyphCount:
|
|
109
|
-
classValueArray:
|
|
127
|
+
startGlyph: r.uint16,
|
|
128
|
+
glyphCount: r.uint16,
|
|
129
|
+
classValueArray: new r.Array(r.uint16, 'glyphCount')
|
|
110
130
|
},
|
|
111
131
|
2: { // Class ranges
|
|
112
|
-
classRangeCount:
|
|
132
|
+
classRangeCount: r.uint16,
|
|
113
133
|
classRangeRecord: new r.Array(ClassRangeRecord, 'classRangeCount')
|
|
114
134
|
}
|
|
115
135
|
});
|
|
116
136
|
|
|
117
|
-
|
|
137
|
+
// ###############
|
|
118
138
|
// Device Table #
|
|
119
|
-
|
|
139
|
+
// ###############
|
|
120
140
|
|
|
141
|
+
/** @type {import('restructure').Struct} */
|
|
121
142
|
export let Device = new r.Struct({
|
|
122
143
|
a: r.uint16, // startSize for hinting Device, outerIndex for VariationIndex
|
|
123
144
|
b: r.uint16, // endSize for Device, innerIndex for VariationIndex
|
|
124
145
|
deltaFormat: r.uint16
|
|
125
146
|
});
|
|
126
147
|
|
|
127
|
-
|
|
148
|
+
// #############################################
|
|
128
149
|
// Contextual Substitution/Positioning Tables #
|
|
129
|
-
|
|
150
|
+
// #############################################
|
|
130
151
|
|
|
131
152
|
let LookupRecord = new r.Struct({
|
|
132
|
-
sequenceIndex:
|
|
133
|
-
lookupListIndex:
|
|
153
|
+
sequenceIndex: r.uint16,
|
|
154
|
+
lookupListIndex: r.uint16
|
|
134
155
|
});
|
|
135
156
|
|
|
136
157
|
let Rule = new r.Struct({
|
|
137
|
-
glyphCount:
|
|
138
|
-
lookupCount:
|
|
139
|
-
input:
|
|
140
|
-
|
|
158
|
+
glyphCount: r.uint16,
|
|
159
|
+
lookupCount: r.uint16,
|
|
160
|
+
input: new r.Array(
|
|
161
|
+
r.uint16,
|
|
162
|
+
/** @param {StructValue} t @returns {number} */
|
|
163
|
+
t => /** @type {number} */ (t.glyphCount) - 1
|
|
164
|
+
),
|
|
165
|
+
lookupRecords: new r.Array(LookupRecord, 'lookupCount')
|
|
141
166
|
});
|
|
142
167
|
|
|
143
168
|
let RuleSet = new r.Array(new r.Pointer(r.uint16, Rule), r.uint16);
|
|
144
169
|
|
|
145
170
|
let ClassRule = new r.Struct({
|
|
146
|
-
glyphCount:
|
|
147
|
-
lookupCount:
|
|
148
|
-
classes:
|
|
149
|
-
|
|
171
|
+
glyphCount: r.uint16,
|
|
172
|
+
lookupCount: r.uint16,
|
|
173
|
+
classes: new r.Array(
|
|
174
|
+
r.uint16,
|
|
175
|
+
/** @param {StructValue} t @returns {number} */
|
|
176
|
+
t => /** @type {number} */ (t.glyphCount) - 1
|
|
177
|
+
),
|
|
178
|
+
lookupRecords: new r.Array(LookupRecord, 'lookupCount')
|
|
150
179
|
});
|
|
151
180
|
|
|
152
181
|
let ClassSet = new r.Array(new r.Pointer(r.uint16, ClassRule), r.uint16);
|
|
153
182
|
|
|
183
|
+
/** @type {import('restructure').VersionedStruct} */
|
|
154
184
|
export let Context = new r.VersionedStruct(r.uint16, {
|
|
155
185
|
1: { // Simple context
|
|
156
|
-
coverage:
|
|
157
|
-
ruleSetCount:
|
|
158
|
-
ruleSets:
|
|
186
|
+
coverage: new r.Pointer(r.uint16, Coverage),
|
|
187
|
+
ruleSetCount: r.uint16,
|
|
188
|
+
ruleSets: new r.Array(new r.Pointer(r.uint16, RuleSet), 'ruleSetCount')
|
|
159
189
|
},
|
|
160
190
|
2: { // Class-based context
|
|
161
|
-
coverage:
|
|
162
|
-
classDef:
|
|
163
|
-
classSetCnt:
|
|
164
|
-
classSet:
|
|
191
|
+
coverage: new r.Pointer(r.uint16, Coverage),
|
|
192
|
+
classDef: new r.Pointer(r.uint16, ClassDef),
|
|
193
|
+
classSetCnt: r.uint16,
|
|
194
|
+
classSet: new r.Array(new r.Pointer(r.uint16, ClassSet), 'classSetCnt')
|
|
165
195
|
},
|
|
166
196
|
3: {
|
|
167
|
-
glyphCount:
|
|
168
|
-
lookupCount:
|
|
169
|
-
coverages:
|
|
197
|
+
glyphCount: r.uint16,
|
|
198
|
+
lookupCount: r.uint16,
|
|
199
|
+
coverages: new r.Array(new r.Pointer(r.uint16, Coverage), 'glyphCount'),
|
|
170
200
|
lookupRecords: new r.Array(LookupRecord, 'lookupCount')
|
|
171
201
|
}
|
|
172
202
|
});
|
|
173
203
|
|
|
174
|
-
|
|
204
|
+
// ######################################################
|
|
175
205
|
// Chaining Contextual Substitution/Positioning Tables #
|
|
176
|
-
|
|
206
|
+
// ######################################################
|
|
177
207
|
|
|
178
208
|
let ChainRule = new r.Struct({
|
|
179
|
-
backtrackGlyphCount:
|
|
180
|
-
backtrack:
|
|
181
|
-
inputGlyphCount:
|
|
182
|
-
input:
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
209
|
+
backtrackGlyphCount: r.uint16,
|
|
210
|
+
backtrack: new r.Array(r.uint16, 'backtrackGlyphCount'),
|
|
211
|
+
inputGlyphCount: r.uint16,
|
|
212
|
+
input: new r.Array(
|
|
213
|
+
r.uint16,
|
|
214
|
+
/** @param {StructValue} t @returns {number} */
|
|
215
|
+
t => /** @type {number} */ (t.inputGlyphCount) - 1
|
|
216
|
+
),
|
|
217
|
+
lookaheadGlyphCount: r.uint16,
|
|
218
|
+
lookahead: new r.Array(r.uint16, 'lookaheadGlyphCount'),
|
|
219
|
+
lookupCount: r.uint16,
|
|
220
|
+
lookupRecords: new r.Array(LookupRecord, 'lookupCount')
|
|
187
221
|
});
|
|
188
222
|
|
|
189
223
|
let ChainRuleSet = new r.Array(new r.Pointer(r.uint16, ChainRule), r.uint16);
|
|
190
224
|
|
|
225
|
+
/** @type {import('restructure').VersionedStruct} */
|
|
191
226
|
export let ChainingContext = new r.VersionedStruct(r.uint16, {
|
|
192
227
|
1: { // Simple context glyph substitution
|
|
193
|
-
coverage:
|
|
194
|
-
chainCount:
|
|
195
|
-
chainRuleSets:
|
|
228
|
+
coverage: new r.Pointer(r.uint16, Coverage),
|
|
229
|
+
chainCount: r.uint16,
|
|
230
|
+
chainRuleSets: new r.Array(new r.Pointer(r.uint16, ChainRuleSet), 'chainCount')
|
|
196
231
|
},
|
|
197
232
|
|
|
198
233
|
2: { // Class-based chaining context
|
|
199
|
-
coverage:
|
|
200
|
-
backtrackClassDef:
|
|
201
|
-
inputClassDef:
|
|
202
|
-
lookaheadClassDef:
|
|
203
|
-
chainCount:
|
|
204
|
-
chainClassSet:
|
|
234
|
+
coverage: new r.Pointer(r.uint16, Coverage),
|
|
235
|
+
backtrackClassDef: new r.Pointer(r.uint16, ClassDef),
|
|
236
|
+
inputClassDef: new r.Pointer(r.uint16, ClassDef),
|
|
237
|
+
lookaheadClassDef: new r.Pointer(r.uint16, ClassDef),
|
|
238
|
+
chainCount: r.uint16,
|
|
239
|
+
chainClassSet: new r.Array(new r.Pointer(r.uint16, ChainRuleSet), 'chainCount')
|
|
205
240
|
},
|
|
206
241
|
|
|
207
242
|
3: { // Coverage-based chaining context
|
|
208
|
-
backtrackGlyphCount:
|
|
209
|
-
backtrackCoverage:
|
|
210
|
-
inputGlyphCount:
|
|
211
|
-
inputCoverage:
|
|
212
|
-
lookaheadGlyphCount:
|
|
213
|
-
lookaheadCoverage:
|
|
214
|
-
lookupCount:
|
|
215
|
-
lookupRecords:
|
|
243
|
+
backtrackGlyphCount: r.uint16,
|
|
244
|
+
backtrackCoverage: new r.Array(new r.Pointer(r.uint16, Coverage), 'backtrackGlyphCount'),
|
|
245
|
+
inputGlyphCount: r.uint16,
|
|
246
|
+
inputCoverage: new r.Array(new r.Pointer(r.uint16, Coverage), 'inputGlyphCount'),
|
|
247
|
+
lookaheadGlyphCount: r.uint16,
|
|
248
|
+
lookaheadCoverage: new r.Array(new r.Pointer(r.uint16, Coverage), 'lookaheadGlyphCount'),
|
|
249
|
+
lookupCount: r.uint16,
|
|
250
|
+
lookupRecords: new r.Array(LookupRecord, 'lookupCount')
|
|
216
251
|
}
|
|
217
252
|
});
|
package/src/tables/post.js
CHANGED
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
import * as r from 'restructure';
|
|
2
2
|
|
|
3
|
+
/** @typedef {import('restructure').StructValue} StructValue */
|
|
4
|
+
|
|
3
5
|
// PostScript information
|
|
6
|
+
/** @type {import('restructure').VersionedStruct} */
|
|
4
7
|
export default new r.VersionedStruct(r.fixed32, {
|
|
5
8
|
header: { // these fields exist at the top of all versions
|
|
6
|
-
italicAngle:
|
|
7
|
-
underlinePosition:
|
|
8
|
-
underlineThickness: r.int16,
|
|
9
|
-
isFixedPitch:
|
|
10
|
-
minMemType42:
|
|
11
|
-
maxMemType42:
|
|
12
|
-
minMemType1:
|
|
13
|
-
maxMemType1:
|
|
9
|
+
italicAngle: r.fixed32, // Italic angle in counter-clockwise degrees from the vertical.
|
|
10
|
+
underlinePosition: r.int16, // Suggested distance of the top of the underline from the baseline
|
|
11
|
+
underlineThickness: r.int16, // Suggested values for the underline thickness
|
|
12
|
+
isFixedPitch: r.uint32, // Whether the font is monospaced
|
|
13
|
+
minMemType42: r.uint32, // Minimum memory usage when a TrueType font is downloaded as a Type 42 font
|
|
14
|
+
maxMemType42: r.uint32, // Maximum memory usage when a TrueType font is downloaded as a Type 42 font
|
|
15
|
+
minMemType1: r.uint32, // Minimum memory usage when a TrueType font is downloaded as a Type 1 font
|
|
16
|
+
maxMemType1: r.uint32 // Maximum memory usage when a TrueType font is downloaded as a Type 1 font
|
|
14
17
|
},
|
|
15
18
|
|
|
16
19
|
1: {}, // version 1 has no additional fields
|
|
@@ -18,17 +21,21 @@ export default new r.VersionedStruct(r.fixed32, {
|
|
|
18
21
|
2: {
|
|
19
22
|
numberOfGlyphs: r.uint16,
|
|
20
23
|
glyphNameIndex: new r.Array(r.uint16, 'numberOfGlyphs'),
|
|
21
|
-
names:
|
|
24
|
+
names: new r.Array(new r.String(r.uint8))
|
|
22
25
|
},
|
|
23
26
|
|
|
24
27
|
2.5: {
|
|
25
28
|
numberOfGlyphs: r.uint16,
|
|
26
|
-
offsets:
|
|
29
|
+
offsets: new r.Array(r.uint8, 'numberOfGlyphs')
|
|
27
30
|
},
|
|
28
31
|
|
|
29
32
|
3: {}, // version 3 has no additional fields
|
|
30
33
|
|
|
31
34
|
4: {
|
|
32
|
-
map: new r.Array(
|
|
35
|
+
map: new r.Array(
|
|
36
|
+
r.uint32,
|
|
37
|
+
/** @param {StructValue} t @returns {number} */
|
|
38
|
+
t => /** @type {number} */ (/** @type {StructValue} */ (/** @type {StructValue} */ (t.parent).maxp).numGlyphs)
|
|
39
|
+
)
|
|
33
40
|
}
|
|
34
41
|
});
|
package/src/tables/prep.js
CHANGED
package/src/tables/sbix.js
CHANGED
|
@@ -1,14 +1,25 @@
|
|
|
1
1
|
import * as r from 'restructure';
|
|
2
2
|
|
|
3
|
+
/** @typedef {import('restructure').StructValue} StructValue */
|
|
4
|
+
|
|
3
5
|
let ImageTable = new r.Struct({
|
|
4
6
|
ppem: r.uint16,
|
|
5
7
|
resolution: r.uint16,
|
|
6
|
-
imageOffsets: new r.Array(
|
|
8
|
+
imageOffsets: new r.Array(
|
|
9
|
+
new r.Pointer(r.uint32, 'void'),
|
|
10
|
+
/** @param {StructValue} t @returns {number} */
|
|
11
|
+
(t) => {
|
|
12
|
+
let parent = /** @type {StructValue} */ (t.parent);
|
|
13
|
+
let grand = /** @type {StructValue} */ (parent.parent);
|
|
14
|
+
return /** @type {number} */ (/** @type {StructValue} */ (grand.maxp).numGlyphs) + 1;
|
|
15
|
+
}
|
|
16
|
+
)
|
|
7
17
|
});
|
|
8
18
|
|
|
9
19
|
// This is the Apple sbix table, used by the "Apple Color Emoji" font.
|
|
10
20
|
// It includes several image tables with images for each bitmap glyph
|
|
11
21
|
// of several different sizes.
|
|
22
|
+
/** @type {import('restructure').Struct} */
|
|
12
23
|
export default new r.Struct({
|
|
13
24
|
version: r.uint16,
|
|
14
25
|
flags: new r.Bitfield(r.uint16, ['renderOutlines']),
|
package/src/tables/variations.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import {Feature} from './opentype';
|
|
1
|
+
import { Feature } from './opentype';
|
|
2
2
|
import * as r from 'restructure';
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
/** @typedef {import('restructure').StructValue} StructValue */
|
|
5
|
+
|
|
6
|
+
/** *****************
|
|
5
7
|
* Variation Store *
|
|
6
8
|
*******************/
|
|
7
9
|
|
|
@@ -19,9 +21,25 @@ let VariationRegionList = new r.Struct({
|
|
|
19
21
|
});
|
|
20
22
|
|
|
21
23
|
let DeltaSet = new r.Struct({
|
|
22
|
-
shortDeltas: new r.Array(
|
|
23
|
-
|
|
24
|
-
|
|
24
|
+
shortDeltas: new r.Array(
|
|
25
|
+
r.int16,
|
|
26
|
+
/** @param {StructValue} t @returns {number} */
|
|
27
|
+
t => /** @type {number} */ (/** @type {StructValue} */ (t.parent).shortDeltaCount)
|
|
28
|
+
),
|
|
29
|
+
regionDeltas: new r.Array(
|
|
30
|
+
r.int8,
|
|
31
|
+
/** @param {StructValue} t @returns {number} */
|
|
32
|
+
(t) => {
|
|
33
|
+
let parent = /** @type {StructValue} */ (t.parent);
|
|
34
|
+
return /** @type {number} */ (parent.regionIndexCount)
|
|
35
|
+
- /** @type {number} */ (parent.shortDeltaCount);
|
|
36
|
+
}
|
|
37
|
+
),
|
|
38
|
+
/**
|
|
39
|
+
* @param {StructValue} t
|
|
40
|
+
* @returns {number[]}
|
|
41
|
+
*/
|
|
42
|
+
deltas: t => /** @type {number[]} */ (t.shortDeltas).concat(/** @type {number[]} */ (t.regionDeltas))
|
|
25
43
|
});
|
|
26
44
|
|
|
27
45
|
let ItemVariationData = new r.Struct({
|
|
@@ -32,6 +50,7 @@ let ItemVariationData = new r.Struct({
|
|
|
32
50
|
deltaSets: new r.Array(DeltaSet, 'itemCount')
|
|
33
51
|
});
|
|
34
52
|
|
|
53
|
+
/** @type {import('restructure').Struct} */
|
|
35
54
|
export let ItemVariationStore = new r.Struct({
|
|
36
55
|
format: r.uint16,
|
|
37
56
|
variationRegionList: new r.Pointer(r.uint32, VariationRegionList),
|
|
@@ -39,7 +58,7 @@ export let ItemVariationStore = new r.Struct({
|
|
|
39
58
|
itemVariationData: new r.Array(new r.Pointer(r.uint32, ItemVariationData), 'variationDataCount')
|
|
40
59
|
});
|
|
41
60
|
|
|
42
|
-
|
|
61
|
+
/** ********************
|
|
43
62
|
* Feature Variations *
|
|
44
63
|
**********************/
|
|
45
64
|
|
|
@@ -58,7 +77,7 @@ let ConditionSet = new r.Struct({
|
|
|
58
77
|
|
|
59
78
|
let FeatureTableSubstitutionRecord = new r.Struct({
|
|
60
79
|
featureIndex: r.uint16,
|
|
61
|
-
alternateFeatureTable: new r.Pointer(r.uint32, Feature, {type: 'parent'})
|
|
80
|
+
alternateFeatureTable: new r.Pointer(r.uint32, Feature, { type: 'parent' })
|
|
62
81
|
});
|
|
63
82
|
|
|
64
83
|
let FeatureTableSubstitution = new r.Struct({
|
|
@@ -68,10 +87,11 @@ let FeatureTableSubstitution = new r.Struct({
|
|
|
68
87
|
});
|
|
69
88
|
|
|
70
89
|
let FeatureVariationRecord = new r.Struct({
|
|
71
|
-
conditionSet: new r.Pointer(r.uint32, ConditionSet, {type: 'parent'}),
|
|
72
|
-
featureTableSubstitution: new r.Pointer(r.uint32, FeatureTableSubstitution, {type: 'parent'})
|
|
90
|
+
conditionSet: new r.Pointer(r.uint32, ConditionSet, { type: 'parent' }),
|
|
91
|
+
featureTableSubstitution: new r.Pointer(r.uint32, FeatureTableSubstitution, { type: 'parent' })
|
|
73
92
|
});
|
|
74
93
|
|
|
94
|
+
/** @type {import('restructure').Struct} */
|
|
75
95
|
export let FeatureVariations = new r.Struct({
|
|
76
96
|
majorVersion: r.uint16,
|
|
77
97
|
minorVersion: r.uint16,
|
package/src/tables/vhea.js
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
import * as r from 'restructure';
|
|
2
2
|
|
|
3
3
|
// Vertical Header Table
|
|
4
|
+
/** @type {import('restructure').Struct} */
|
|
4
5
|
export default new r.Struct({
|
|
5
|
-
version:
|
|
6
|
-
ascent:
|
|
7
|
-
descent:
|
|
8
|
-
lineGap:
|
|
9
|
-
advanceHeightMax:
|
|
10
|
-
minTopSideBearing:
|
|
11
|
-
minBottomSideBearing:
|
|
12
|
-
yMaxExtent:
|
|
13
|
-
caretSlopeRise:
|
|
14
|
-
caretSlopeRun:
|
|
15
|
-
caretOffset:
|
|
16
|
-
reserved:
|
|
17
|
-
metricDataFormat:
|
|
18
|
-
numberOfMetrics:
|
|
6
|
+
version: r.fixed32, // Version number of the Vertical Header Table
|
|
7
|
+
ascent: r.int16, // The vertical typographic ascender for this font
|
|
8
|
+
descent: r.int16, // The vertical typographic descender for this font
|
|
9
|
+
lineGap: r.int16, // The vertical typographic line gap for this font
|
|
10
|
+
advanceHeightMax: r.uint16, // The maximum advance height measurement found in the font
|
|
11
|
+
minTopSideBearing: r.int16, // The minimum top side bearing measurement found in the font
|
|
12
|
+
minBottomSideBearing: r.int16, // The minimum bottom side bearing measurement found in the font
|
|
13
|
+
yMaxExtent: r.int16,
|
|
14
|
+
caretSlopeRise: r.int16, // Caret slope (rise/run)
|
|
15
|
+
caretSlopeRun: r.int16,
|
|
16
|
+
caretOffset: r.int16, // Set value equal to 0 for nonslanted fonts
|
|
17
|
+
reserved: new r.Reserved(r.int16, 4),
|
|
18
|
+
metricDataFormat: r.int16, // Set to 0
|
|
19
|
+
numberOfMetrics: r.uint16 // Number of advance heights in the Vertical Metrics table
|
|
19
20
|
});
|
package/src/tables/vmtx.js
CHANGED
|
@@ -1,12 +1,28 @@
|
|
|
1
1
|
import * as r from 'restructure';
|
|
2
2
|
|
|
3
|
+
/** @typedef {import('restructure').StructValue} StructValue */
|
|
4
|
+
|
|
3
5
|
let VmtxEntry = new r.Struct({
|
|
4
|
-
advance: r.uint16,
|
|
5
|
-
bearing: r.int16
|
|
6
|
+
advance: r.uint16, // The advance height of the glyph
|
|
7
|
+
bearing: r.int16 // The top sidebearing of the glyph
|
|
6
8
|
});
|
|
7
9
|
|
|
8
10
|
// Vertical Metrics Table
|
|
11
|
+
/** @type {import('restructure').Struct} */
|
|
9
12
|
export default new r.Struct({
|
|
10
|
-
metrics:
|
|
11
|
-
|
|
13
|
+
metrics: new r.LazyArray(
|
|
14
|
+
VmtxEntry,
|
|
15
|
+
/** @param {StructValue} t @returns {number} */
|
|
16
|
+
t => /** @type {number} */ (/** @type {StructValue} */ (/** @type {StructValue} */ (t.parent).vhea).numberOfMetrics)
|
|
17
|
+
),
|
|
18
|
+
bearings: new r.LazyArray(
|
|
19
|
+
r.int16,
|
|
20
|
+
/** @param {StructValue} t @returns {number} */
|
|
21
|
+
(t) => {
|
|
22
|
+
let parent = /** @type {StructValue} */ (t.parent);
|
|
23
|
+
let maxp = /** @type {StructValue} */ (parent.maxp);
|
|
24
|
+
let vhea = /** @type {StructValue} */ (parent.vhea);
|
|
25
|
+
return /** @type {number} */ (maxp.numGlyphs) - /** @type {number} */ (vhea.numberOfMetrics);
|
|
26
|
+
}
|
|
27
|
+
)
|
|
12
28
|
});
|
package/src/utils.js
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @template T
|
|
3
|
+
* @param {T[]} arr
|
|
4
|
+
* @param {(item: T) => number} cmp
|
|
5
|
+
* @returns {number}
|
|
6
|
+
*/
|
|
1
7
|
export function binarySearch(arr, cmp) {
|
|
2
8
|
let min = 0;
|
|
3
9
|
let max = arr.length - 1;
|
|
@@ -17,6 +23,11 @@ export function binarySearch(arr, cmp) {
|
|
|
17
23
|
return -1;
|
|
18
24
|
}
|
|
19
25
|
|
|
26
|
+
/**
|
|
27
|
+
* @param {number} index
|
|
28
|
+
* @param {number} end
|
|
29
|
+
* @returns {number[]}
|
|
30
|
+
*/
|
|
20
31
|
export function range(index, end) {
|
|
21
32
|
let range = [];
|
|
22
33
|
while (index < end) {
|
|
@@ -34,6 +45,10 @@ for (let i = 0; i < CHARS.length; i++) {
|
|
|
34
45
|
LOOKUP[CHARS.charCodeAt(i)] = i;
|
|
35
46
|
}
|
|
36
47
|
|
|
48
|
+
/**
|
|
49
|
+
* @param {string} base64
|
|
50
|
+
* @returns {Uint8Array}
|
|
51
|
+
*/
|
|
37
52
|
export function decodeBase64(base64) {
|
|
38
53
|
let bufferLength = base64.length * 0.75;
|
|
39
54
|
|