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