@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.
Files changed (142) hide show
  1. package/dist/browser-module.mjs +4448 -1142
  2. package/dist/browser-module.mjs.map +1 -1
  3. package/dist/browser.cjs +4449 -1142
  4. package/dist/browser.cjs.map +1 -1
  5. package/dist/main.cjs +4449 -1142
  6. package/dist/main.cjs.map +1 -1
  7. package/dist/module.mjs +4448 -1142
  8. package/dist/module.mjs.map +1 -1
  9. package/package.json +4 -1
  10. package/src/CmapProcessor.js +60 -21
  11. package/src/DFont.js +114 -14
  12. package/src/TTFFont.js +260 -62
  13. package/src/TrueTypeCollection.js +59 -15
  14. package/src/WOFF2Font.js +128 -22
  15. package/src/WOFFFont.js +45 -8
  16. package/src/aat/AATFeatureMap.js +83 -40
  17. package/src/aat/AATLayoutEngine.js +34 -2
  18. package/src/aat/AATLookupTable.js +24 -6
  19. package/src/aat/AATMorxProcessor.js +202 -65
  20. package/src/aat/AATStateMachine.js +35 -3
  21. package/src/base.js +20 -1
  22. package/src/cff/CFFCharsets.js +3 -0
  23. package/src/cff/CFFDict.js +81 -11
  24. package/src/cff/CFFEncodings.js +2 -0
  25. package/src/cff/CFFFont.js +120 -24
  26. package/src/cff/CFFIndex.js +66 -9
  27. package/src/cff/CFFOperand.js +53 -28
  28. package/src/cff/CFFPointer.js +41 -2
  29. package/src/cff/CFFPrivateDict.js +34 -24
  30. package/src/cff/CFFStandardStrings.js +68 -67
  31. package/src/cff/CFFTop.js +161 -68
  32. package/src/decorators.js +34 -15
  33. package/src/encodings.js +133 -116
  34. package/src/fs.js +10 -0
  35. package/src/glyph/BBox.js +14 -0
  36. package/src/glyph/CFFGlyph.js +293 -152
  37. package/src/glyph/COLRGlyph.js +40 -5
  38. package/src/glyph/Glyph.js +72 -13
  39. package/src/glyph/GlyphVariationProcessor.js +158 -62
  40. package/src/glyph/Path.js +119 -32
  41. package/src/glyph/SBIXGlyph.js +57 -8
  42. package/src/glyph/StandardNames.js +1 -0
  43. package/src/glyph/TTFGlyph.js +203 -63
  44. package/src/glyph/TTFGlyphEncoder.js +58 -26
  45. package/src/glyph/WOFF2Glyph.js +25 -6
  46. package/src/layout/GlyphPosition.js +6 -0
  47. package/src/layout/GlyphRun.js +28 -10
  48. package/src/layout/KernProcessor.js +63 -4
  49. package/src/layout/LayoutEngine.js +99 -26
  50. package/src/layout/Script.js +52 -26
  51. package/src/layout/UnicodeLayoutEngine.js +34 -10
  52. package/src/opentype/GPOSProcessor.js +156 -45
  53. package/src/opentype/GSUBProcessor.js +92 -33
  54. package/src/opentype/GlyphInfo.js +53 -5
  55. package/src/opentype/GlyphIterator.js +51 -2
  56. package/src/opentype/OTLayoutEngine.js +66 -8
  57. package/src/opentype/OTProcessor.js +284 -71
  58. package/src/opentype/ShapingPlan.js +52 -5
  59. package/src/opentype/shapers/ArabicShaper.js +27 -8
  60. package/src/opentype/shapers/DefaultShaper.js +54 -10
  61. package/src/opentype/shapers/HangulShaper.js +120 -42
  62. package/src/opentype/shapers/HebrewShaper.js +50 -16
  63. package/src/opentype/shapers/IndicShaper.js +159 -44
  64. package/src/opentype/shapers/ThaiShaper.js +50 -19
  65. package/src/opentype/shapers/UniversalShaper.js +83 -17
  66. package/src/opentype/shapers/index.js +48 -35
  67. package/src/opentype/shapers/indic-data.js +2 -2
  68. package/src/packages/unicode-properties/data-trie.js +2 -1
  69. package/src/packages/unicode-properties/data.js +13 -1
  70. package/src/packages/unicode-properties/dist/index.cjs +23 -10
  71. package/src/packages/unicode-properties/dist/index.cjs.map +2 -2
  72. package/src/packages/unicode-properties/dist/index.mjs +22 -10
  73. package/src/packages/unicode-properties/dist/index.mjs.map +2 -2
  74. package/src/packages/unicode-properties/generate.js +3 -4
  75. package/src/packages/unicode-properties/index.js +95 -30
  76. package/src/packages/unicode-properties/package.json +1 -1
  77. package/src/packages/unicode-trie/builder.js +146 -29
  78. package/src/packages/unicode-trie/dist/builder.cjs +135 -25
  79. package/src/packages/unicode-trie/dist/builder.cjs.map +2 -2
  80. package/src/packages/unicode-trie/dist/builder.mjs +134 -25
  81. package/src/packages/unicode-trie/dist/builder.mjs.map +2 -2
  82. package/src/packages/unicode-trie/dist/index.cjs +22 -9
  83. package/src/packages/unicode-trie/dist/index.cjs.map +2 -2
  84. package/src/packages/unicode-trie/dist/index.mjs +21 -9
  85. package/src/packages/unicode-trie/dist/index.mjs.map +2 -2
  86. package/src/packages/unicode-trie/index.js +63 -12
  87. package/src/packages/unicode-trie/package.json +1 -1
  88. package/src/packages/unicode-trie/swap.js +15 -2
  89. package/src/subset/CFFSubset.js +112 -22
  90. package/src/subset/Subset.js +23 -3
  91. package/src/subset/TTFSubset.js +84 -41
  92. package/src/tables/BASE.js +28 -27
  93. package/src/tables/COLR.js +10 -9
  94. package/src/tables/CPAL.js +2 -1
  95. package/src/tables/DSIG.js +8 -7
  96. package/src/tables/EBDT.js +10 -4
  97. package/src/tables/EBLC.js +70 -10
  98. package/src/tables/GDEF.js +18 -17
  99. package/src/tables/GPOS.js +153 -90
  100. package/src/tables/GSUB.js +50 -39
  101. package/src/tables/HVAR.js +51 -5
  102. package/src/tables/JSTF.js +17 -16
  103. package/src/tables/LTSH.js +4 -3
  104. package/src/tables/OS2.js +50 -49
  105. package/src/tables/PCLT.js +16 -15
  106. package/src/tables/STAT.js +46 -6
  107. package/src/tables/VDMX.js +18 -17
  108. package/src/tables/VORG.js +8 -7
  109. package/src/tables/WOFF2Directory.js +57 -9
  110. package/src/tables/WOFFDirectory.js +32 -20
  111. package/src/tables/aat.js +160 -35
  112. package/src/tables/avar.js +1 -0
  113. package/src/tables/bsln.js +3 -2
  114. package/src/tables/cmap.js +83 -63
  115. package/src/tables/cvt.js +1 -0
  116. package/src/tables/directory.js +56 -28
  117. package/src/tables/feat.js +24 -2
  118. package/src/tables/fpgm.js +1 -0
  119. package/src/tables/fvar.js +32 -4
  120. package/src/tables/gasp.js +6 -5
  121. package/src/tables/glyf.js +2 -1
  122. package/src/tables/gvar.js +29 -2
  123. package/src/tables/hdmx.js +18 -7
  124. package/src/tables/head.js +17 -16
  125. package/src/tables/hhea.js +15 -14
  126. package/src/tables/hmtx.js +18 -2
  127. package/src/tables/index.js +1 -5
  128. package/src/tables/just.js +15 -4
  129. package/src/tables/kern.js +84 -47
  130. package/src/tables/loca.js +23 -10
  131. package/src/tables/maxp.js +16 -15
  132. package/src/tables/morx.js +27 -20
  133. package/src/tables/name.js +120 -39
  134. package/src/tables/opbd.js +2 -1
  135. package/src/tables/opentype.js +126 -91
  136. package/src/tables/post.js +18 -11
  137. package/src/tables/prep.js +1 -0
  138. package/src/tables/sbix.js +12 -1
  139. package/src/tables/variations.js +29 -9
  140. package/src/tables/vhea.js +15 -14
  141. package/src/tables/vmtx.js +20 -4
  142. package/src/utils.js +15 -0
@@ -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: new r.Reserved(r.uint16),
9
- reqFeatureIndex: r.uint16,
10
- featureCount: r.uint16,
11
- featureIndexes: new r.Array(r.uint16, 'featureCount')
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: new r.String(4),
16
- langSys: new r.Pointer(r.uint16, LangSysTable, { type: 'parent' })
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: r.uint16,
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: new r.String(4),
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: r.uint16, // should be set to 0 according OT spec
38
- nameID: r.uint16, //OT spec: UI Name ID or uiLabelNameId
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: new r.Pointer(r.uint16, FeatureParams),
43
- lookupCount: r.uint16,
44
- lookupListIndexes: new r.Array(r.uint16, 'lookupCount')
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: new r.String(4),
49
- feature: new r.Pointer(r.uint16, Feature, { type: 'parent' })
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: 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)
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: r.uint16,
80
- end: r.uint16,
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: r.uint16,
87
- glyphs: new r.Array(r.uint16, 'glyphCount')
105
+ glyphCount: r.uint16,
106
+ glyphs: new r.Array(r.uint16, 'glyphCount')
88
107
  },
89
108
  2: {
90
- rangeCount: r.uint16,
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: r.uint16,
101
- end: r.uint16,
102
- class: r.uint16
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: r.uint16,
108
- glyphCount: r.uint16,
109
- classValueArray: new r.Array(r.uint16, 'glyphCount')
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: r.uint16,
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: r.uint16,
133
- lookupListIndex: r.uint16
153
+ sequenceIndex: r.uint16,
154
+ lookupListIndex: r.uint16
134
155
  });
135
156
 
136
157
  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')
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: r.uint16,
147
- lookupCount: r.uint16,
148
- classes: new r.Array(r.uint16, t => t.glyphCount - 1),
149
- lookupRecords: new r.Array(LookupRecord, 'lookupCount')
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: new r.Pointer(r.uint16, Coverage),
157
- ruleSetCount: r.uint16,
158
- ruleSets: new r.Array(new r.Pointer(r.uint16, RuleSet), 'ruleSetCount')
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: 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')
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: r.uint16,
168
- lookupCount: r.uint16,
169
- coverages: new r.Array(new r.Pointer(r.uint16, Coverage), 'glyphCount'),
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: 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')
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: new r.Pointer(r.uint16, Coverage),
194
- chainCount: r.uint16,
195
- chainRuleSets: new r.Array(new r.Pointer(r.uint16, ChainRuleSet), 'chainCount')
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: 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')
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: 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')
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
  });
@@ -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: 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
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: new r.Array(new r.String(r.uint8))
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: new r.Array(r.uint8, 'numberOfGlyphs')
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(r.uint32, t => t.parent.maxp.numGlyphs)
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
  });
@@ -1,6 +1,7 @@
1
1
  import * as r from 'restructure';
2
2
 
3
3
  // Set of instructions executed whenever the point size or font transformation change
4
+ /** @type {import('restructure').Struct} */
4
5
  export default new r.Struct({
5
6
  controlValueProgram: new r.Array(r.uint8)
6
7
  });
@@ -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(new r.Pointer(r.uint32, 'void'), t => t.parent.parent.maxp.numGlyphs + 1)
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']),
@@ -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(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)
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,
@@ -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: 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
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
  });
@@ -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, // The advance height of the glyph
5
- bearing: r.int16 // The top sidebearing of the glyph
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: 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)
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