@cantoo/fontkit 2.0.5 → 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 (140) hide show
  1. package/dist/browser-module.mjs +4423 -1117
  2. package/dist/browser-module.mjs.map +1 -1
  3. package/dist/browser.cjs +4424 -1117
  4. package/dist/browser.cjs.map +1 -1
  5. package/dist/main.cjs +4424 -1117
  6. package/dist/main.cjs.map +1 -1
  7. package/dist/module.mjs +4423 -1117
  8. package/dist/module.mjs.map +1 -1
  9. package/package.json +3 -1
  10. package/src/CmapProcessor.js +59 -20
  11. package/src/DFont.js +114 -14
  12. package/src/TTFFont.js +259 -57
  13. package/src/TrueTypeCollection.js +54 -10
  14. package/src/WOFF2Font.js +128 -16
  15. package/src/WOFFFont.js +45 -8
  16. package/src/aat/AATFeatureMap.js +62 -18
  17. package/src/aat/AATLayoutEngine.js +33 -1
  18. package/src/aat/AATLookupTable.js +22 -4
  19. package/src/aat/AATMorxProcessor.js +189 -52
  20. package/src/aat/AATStateMachine.js +32 -0
  21. package/src/base.js +19 -0
  22. package/src/cff/CFFCharsets.js +3 -0
  23. package/src/cff/CFFDict.js +79 -9
  24. package/src/cff/CFFEncodings.js +2 -0
  25. package/src/cff/CFFFont.js +119 -23
  26. package/src/cff/CFFIndex.js +62 -5
  27. package/src/cff/CFFOperand.js +52 -17
  28. package/src/cff/CFFPointer.js +41 -2
  29. package/src/cff/CFFPrivateDict.js +14 -4
  30. package/src/cff/CFFStandardStrings.js +1 -0
  31. package/src/cff/CFFTop.js +103 -10
  32. package/src/decorators.js +32 -13
  33. package/src/encodings.js +22 -5
  34. package/src/fs.js +10 -0
  35. package/src/glyph/BBox.js +14 -0
  36. package/src/glyph/CFFGlyph.js +290 -148
  37. package/src/glyph/COLRGlyph.js +38 -3
  38. package/src/glyph/Glyph.js +68 -9
  39. package/src/glyph/GlyphVariationProcessor.js +135 -34
  40. package/src/glyph/Path.js +107 -20
  41. package/src/glyph/SBIXGlyph.js +57 -8
  42. package/src/glyph/StandardNames.js +1 -0
  43. package/src/glyph/TTFGlyph.js +176 -29
  44. package/src/glyph/TTFGlyphEncoder.js +32 -0
  45. package/src/glyph/WOFF2Glyph.js +23 -4
  46. package/src/layout/GlyphPosition.js +6 -0
  47. package/src/layout/GlyphRun.js +25 -7
  48. package/src/layout/KernProcessor.js +62 -3
  49. package/src/layout/LayoutEngine.js +86 -12
  50. package/src/layout/Script.js +27 -1
  51. package/src/layout/UnicodeLayoutEngine.js +29 -4
  52. package/src/opentype/GPOSProcessor.js +156 -45
  53. package/src/opentype/GSUBProcessor.js +92 -33
  54. package/src/opentype/GlyphInfo.js +52 -4
  55. package/src/opentype/GlyphIterator.js +51 -2
  56. package/src/opentype/OTLayoutEngine.js +66 -8
  57. package/src/opentype/OTProcessor.js +283 -70
  58. package/src/opentype/ShapingPlan.js +51 -3
  59. package/src/opentype/shapers/ArabicShaper.js +19 -0
  60. package/src/opentype/shapers/DefaultShaper.js +51 -7
  61. package/src/opentype/shapers/HangulShaper.js +85 -7
  62. package/src/opentype/shapers/HebrewShaper.js +45 -11
  63. package/src/opentype/shapers/IndicShaper.js +141 -26
  64. package/src/opentype/shapers/ThaiShaper.js +35 -4
  65. package/src/opentype/shapers/UniversalShaper.js +83 -17
  66. package/src/opentype/shapers/index.js +15 -2
  67. package/src/packages/unicode-properties/data-trie.js +1 -0
  68. package/src/packages/unicode-properties/data.js +12 -0
  69. package/src/packages/unicode-properties/dist/index.cjs +22 -9
  70. package/src/packages/unicode-properties/dist/index.cjs.map +2 -2
  71. package/src/packages/unicode-properties/dist/index.mjs +21 -9
  72. package/src/packages/unicode-properties/dist/index.mjs.map +2 -2
  73. package/src/packages/unicode-properties/index.js +65 -0
  74. package/src/packages/unicode-properties/package.json +1 -1
  75. package/src/packages/unicode-trie/builder.js +128 -7
  76. package/src/packages/unicode-trie/dist/builder.cjs +129 -16
  77. package/src/packages/unicode-trie/dist/builder.cjs.map +2 -2
  78. package/src/packages/unicode-trie/dist/builder.mjs +128 -16
  79. package/src/packages/unicode-trie/dist/builder.mjs.map +2 -2
  80. package/src/packages/unicode-trie/dist/index.cjs +22 -9
  81. package/src/packages/unicode-trie/dist/index.cjs.map +2 -2
  82. package/src/packages/unicode-trie/dist/index.mjs +21 -9
  83. package/src/packages/unicode-trie/dist/index.mjs.map +2 -2
  84. package/src/packages/unicode-trie/index.js +62 -10
  85. package/src/packages/unicode-trie/package.json +1 -1
  86. package/src/packages/unicode-trie/swap.js +13 -0
  87. package/src/subset/CFFSubset.js +112 -22
  88. package/src/subset/Subset.js +21 -1
  89. package/src/subset/TTFSubset.js +79 -36
  90. package/src/tables/BASE.js +1 -0
  91. package/src/tables/COLR.js +1 -0
  92. package/src/tables/CPAL.js +1 -0
  93. package/src/tables/DSIG.js +1 -0
  94. package/src/tables/EBDT.js +10 -3
  95. package/src/tables/EBLC.js +67 -7
  96. package/src/tables/GDEF.js +1 -0
  97. package/src/tables/GPOS.js +79 -16
  98. package/src/tables/GSUB.js +14 -3
  99. package/src/tables/HVAR.js +51 -5
  100. package/src/tables/JSTF.js +3 -2
  101. package/src/tables/LTSH.js +1 -0
  102. package/src/tables/OS2.js +1 -0
  103. package/src/tables/PCLT.js +1 -0
  104. package/src/tables/STAT.js +46 -6
  105. package/src/tables/VDMX.js +1 -0
  106. package/src/tables/VORG.js +1 -0
  107. package/src/tables/WOFF2Directory.js +56 -8
  108. package/src/tables/WOFFDirectory.js +14 -2
  109. package/src/tables/aat.js +160 -35
  110. package/src/tables/avar.js +1 -0
  111. package/src/tables/bsln.js +3 -2
  112. package/src/tables/cmap.js +26 -6
  113. package/src/tables/cvt.js +1 -0
  114. package/src/tables/directory.js +44 -16
  115. package/src/tables/feat.js +24 -2
  116. package/src/tables/fpgm.js +1 -0
  117. package/src/tables/fvar.js +32 -4
  118. package/src/tables/gasp.js +1 -0
  119. package/src/tables/glyf.js +1 -0
  120. package/src/tables/gvar.js +29 -2
  121. package/src/tables/hdmx.js +12 -1
  122. package/src/tables/head.js +1 -0
  123. package/src/tables/hhea.js +1 -0
  124. package/src/tables/hmtx.js +18 -2
  125. package/src/tables/index.js +1 -0
  126. package/src/tables/just.js +15 -4
  127. package/src/tables/kern.js +43 -6
  128. package/src/tables/loca.js +21 -8
  129. package/src/tables/maxp.js +1 -0
  130. package/src/tables/morx.js +14 -7
  131. package/src/tables/name.js +104 -23
  132. package/src/tables/opbd.js +2 -1
  133. package/src/tables/opentype.js +39 -4
  134. package/src/tables/post.js +8 -1
  135. package/src/tables/prep.js +1 -0
  136. package/src/tables/sbix.js +12 -1
  137. package/src/tables/variations.js +23 -3
  138. package/src/tables/vhea.js +1 -0
  139. package/src/tables/vmtx.js +18 -2
  140. package/src/utils.js +15 -0
@@ -1,9 +1,29 @@
1
1
  import * as r from 'restructure';
2
2
 
3
+ /** @typedef {import('restructure').StructValue} StructValue */
4
+
5
+ /**
6
+ * @param {StructValue} t
7
+ * @param {number} depth
8
+ * @param {number} nameIndex
9
+ * @returns {unknown}
10
+ */
11
+ function featureNameAt(t, depth, nameIndex) {
12
+ let cur = t;
13
+ for (let i = 0; i < depth; i++) {
14
+ cur = /** @type {StructValue} */ (cur.parent);
15
+ }
16
+ let name = /** @type {StructValue} */ (cur.name);
17
+ let records = /** @type {StructValue} */ (name.records);
18
+ let fontFeatures = /** @type {Record<number, unknown>} */ (records.fontFeatures);
19
+ return fontFeatures[nameIndex];
20
+ }
21
+
3
22
  let Setting = new r.Struct({
4
23
  setting: r.uint16,
5
24
  nameIndex: r.int16,
6
- name: t => t.parent.parent.parent.name.records.fontFeatures[t.nameIndex]
25
+ /** @param {StructValue} t @returns {unknown} */
26
+ name: t => featureNameAt(t, 3, /** @type {number} */ (t.nameIndex))
7
27
  });
8
28
 
9
29
  let FeatureName = new r.Struct({
@@ -16,9 +36,11 @@ let FeatureName = new r.Struct({
16
36
  ]),
17
37
  defaultSetting: r.uint8,
18
38
  nameIndex: r.int16,
19
- name: t => t.parent.parent.name.records.fontFeatures[t.nameIndex]
39
+ /** @param {StructValue} t @returns {unknown} */
40
+ name: t => featureNameAt(t, 2, /** @type {number} */ (t.nameIndex))
20
41
  });
21
42
 
43
+ /** @type {import('restructure').Struct} */
22
44
  export default new r.Struct({
23
45
  version: r.fixed32,
24
46
  featureNameCount: r.uint16,
@@ -3,6 +3,7 @@ import * as r from 'restructure';
3
3
  // A list of instructions that are executed once when a font is first used.
4
4
  // These instructions are known as the font program. The main use of this table
5
5
  // is for the definition of functions that are used in many different glyph programs.
6
+ /** @type {import('restructure').Struct} */
6
7
  export default new r.Struct({
7
8
  instructions: new r.Array(r.uint8)
8
9
  });
@@ -1,5 +1,21 @@
1
1
  import * as r from 'restructure';
2
2
 
3
+ /** @typedef {import('restructure').StructValue} StructValue */
4
+
5
+ /**
6
+ * @param {StructValue} t
7
+ * @param {number} nameID
8
+ * @returns {unknown}
9
+ */
10
+ function featureName(t, nameID) {
11
+ let parent = /** @type {StructValue} */ (t.parent);
12
+ let grand = /** @type {StructValue} */ (parent.parent);
13
+ let name = /** @type {StructValue} */ (grand.name);
14
+ let records = /** @type {StructValue} */ (name.records);
15
+ let fontFeatures = /** @type {Record<number, unknown>} */ (records.fontFeatures);
16
+ return fontFeatures[nameID];
17
+ }
18
+
3
19
  let Axis = new r.Struct({
4
20
  axisTag: new r.String(4),
5
21
  minValue: r.fixed32,
@@ -7,17 +23,29 @@ let Axis = new r.Struct({
7
23
  maxValue: r.fixed32,
8
24
  flags: r.uint16,
9
25
  nameID: r.uint16,
10
- name: t => t.parent.parent.name.records.fontFeatures[t.nameID]
26
+ /** @param {StructValue} t @returns {unknown} */
27
+ name: t => featureName(t, /** @type {number} */ (t.nameID))
11
28
  });
12
29
 
13
30
  let Instance = new r.Struct({
14
31
  nameID: r.uint16,
15
- name: t => t.parent.parent.name.records.fontFeatures[t.nameID],
32
+ /** @param {StructValue} t @returns {unknown} */
33
+ name: t => featureName(t, /** @type {number} */ (t.nameID)),
16
34
  flags: r.uint16,
17
- coord: new r.Array(r.fixed32, t => t.parent.axisCount),
18
- postscriptNameID: new r.Optional(r.uint16, t => t.parent.instanceSize - t._currentOffset > 0)
35
+ coord: new r.Array(
36
+ r.fixed32,
37
+ /** @param {StructValue} t @returns {number} */
38
+ t => /** @type {number} */ (/** @type {StructValue} */ (t.parent).axisCount)
39
+ ),
40
+ postscriptNameID: new r.Optional(
41
+ r.uint16,
42
+ /** @param {StructValue} t @returns {boolean} */
43
+ t => /** @type {number} */ (/** @type {StructValue} */ (t.parent).instanceSize)
44
+ - /** @type {number} */ (t._currentOffset) > 0
45
+ )
19
46
  });
20
47
 
48
+ /** @type {import('restructure').Struct} */
21
49
  export default new r.Struct({
22
50
  version: r.fixed32,
23
51
  offsetToData: r.uint16,
@@ -8,6 +8,7 @@ let GaspRange = new r.Struct({
8
8
  ])
9
9
  });
10
10
 
11
+ /** @type {import('restructure').Struct} */
11
12
  export default new r.Struct({
12
13
  version: r.uint16, // set to 0
13
14
  numRanges: r.uint16,
@@ -1,4 +1,5 @@
1
1
  import * as r from 'restructure';
2
2
 
3
3
  // only used for encoding
4
+ /** @type {import('restructure').ArrayT} */
4
5
  export default new r.Array(new r.Buffer());
@@ -1,17 +1,32 @@
1
1
  import * as r from 'restructure';
2
2
 
3
+ /** @typedef {import('restructure').BaseType} BaseType */
4
+ /** @typedef {import('restructure').DecodeStream} DecodeStream */
5
+ /** @typedef {import('restructure').StructValue} StructValue */
6
+
3
7
  let shortFrac = new r.Fixed(16, 'BE', 14);
8
+
9
+ /**
10
+ * Offset whose width depends on gvar.flags (Apple short/long format).
11
+ * @implements {BaseType}
12
+ */
4
13
  class Offset {
14
+ /**
15
+ * @param {DecodeStream} stream
16
+ * @param {StructValue | null | undefined} parent
17
+ * @returns {number}
18
+ */
5
19
  static decode(stream, parent) {
6
20
  // In short format, offsets are multiplied by 2.
7
21
  // This doesn't seem to be documented by Apple, but it
8
22
  // is implemented this way in Freetype.
9
- return parent.flags
23
+ return parent && parent.flags
10
24
  ? stream.readUInt32BE()
11
25
  : stream.readUInt16BE() * 2;
12
26
  }
13
27
  }
14
28
 
29
+ /** @type {import('restructure').Struct} */
15
30
  let gvar = new r.Struct({
16
31
  version: r.uint16,
17
32
  reserved: new r.Reserved(r.uint16),
@@ -21,7 +36,19 @@ let gvar = new r.Struct({
21
36
  glyphCount: r.uint16,
22
37
  flags: r.uint16,
23
38
  offsetToData: r.uint32,
24
- offsets: new r.Array(new r.Pointer(Offset, 'void', { relativeTo: ctx => ctx.offsetToData, allowNull: false }), t => t.glyphCount + 1)
39
+ offsets: new r.Array(
40
+ new r.Pointer(
41
+ /** @type {BaseType} */ (Offset),
42
+ 'void',
43
+ {
44
+ /** @param {StructValue} ctx @returns {number} */
45
+ relativeTo: ctx => /** @type {number} */ (ctx.offsetToData),
46
+ allowNull: false
47
+ }
48
+ ),
49
+ /** @param {StructValue} t @returns {number} */
50
+ t => /** @type {number} */ (t.glyphCount) + 1
51
+ )
25
52
  });
26
53
 
27
54
  export default gvar;
@@ -1,12 +1,23 @@
1
1
  import * as r from 'restructure';
2
2
 
3
+ /** @typedef {import('restructure').StructValue} StructValue */
4
+
3
5
  let DeviceRecord = new r.Struct({
4
6
  pixelSize: r.uint8,
5
7
  maximumWidth: r.uint8,
6
- widths: new r.Array(r.uint8, t => t.parent.parent.maxp.numGlyphs)
8
+ widths: new r.Array(
9
+ r.uint8,
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);
15
+ }
16
+ )
7
17
  });
8
18
 
9
19
  // The Horizontal Device Metrics table stores integer advance widths scaled to particular pixel sizes
20
+ /** @type {import('restructure').Struct} */
10
21
  export default new r.Struct({
11
22
  version: r.uint16,
12
23
  numRecords: r.int16,
@@ -1,6 +1,7 @@
1
1
  import * as r from 'restructure';
2
2
 
3
3
  // font header
4
+ /** @type {import('restructure').Struct} */
4
5
  export default new r.Struct({
5
6
  version: r.int32, // 0x00010000 (version 1.0)
6
7
  revision: r.int32, // set by font manufacturer
@@ -1,6 +1,7 @@
1
1
  import * as r from 'restructure';
2
2
 
3
3
  // horizontal header
4
+ /** @type {import('restructure').Struct} */
4
5
  export default new r.Struct({
5
6
  version: r.int32,
6
7
  ascent: r.int16, // Distance from baseline of highest ascender
@@ -1,11 +1,27 @@
1
1
  import * as r from 'restructure';
2
2
 
3
+ /** @typedef {import('restructure').StructValue} StructValue */
4
+
3
5
  let HmtxEntry = new r.Struct({
4
6
  advance: r.uint16,
5
7
  bearing: r.int16
6
8
  });
7
9
 
10
+ /** @type {import('restructure').Struct} */
8
11
  export default new r.Struct({
9
- metrics: new r.LazyArray(HmtxEntry, t => t.parent.hhea.numberOfMetrics),
10
- bearings: new r.LazyArray(r.int16, t => t.parent.maxp.numGlyphs - t.parent.hhea.numberOfMetrics)
12
+ metrics: new r.LazyArray(
13
+ HmtxEntry,
14
+ /** @param {StructValue} t @returns {number} */
15
+ t => /** @type {number} */ (/** @type {StructValue} */ (/** @type {StructValue} */ (t.parent).hhea).numberOfMetrics)
16
+ ),
17
+ bearings: new r.LazyArray(
18
+ r.int16,
19
+ /** @param {StructValue} t @returns {number} */
20
+ (t) => {
21
+ let parent = /** @type {StructValue} */ (t.parent);
22
+ let maxp = /** @type {StructValue} */ (parent.maxp);
23
+ let hhea = /** @type {StructValue} */ (parent.hhea);
24
+ return /** @type {number} */ (maxp.numGlyphs) - /** @type {number} */ (hhea.numberOfMetrics);
25
+ }
26
+ )
11
27
  });
@@ -1,3 +1,4 @@
1
+ /** @type {Record<string, import('../../types/fontkit').TableCodec>} */
1
2
  let tables = {};
2
3
  export default tables;
3
4
 
@@ -1,11 +1,13 @@
1
1
  import * as r from 'restructure';
2
2
  import { LookupTable, StateTable1 } from './aat';
3
3
 
4
+ /** @typedef {import('restructure').StructValue} StructValue */
5
+
4
6
  let ClassTable = new r.Struct({
5
7
  length: r.uint16,
6
8
  coverage: r.uint16,
7
9
  subFeatureFlags: r.uint32,
8
- stateTable: new StateTable1()
10
+ stateTable: StateTable1()
9
11
  });
10
12
 
11
13
  let WidthDeltaRecord = new r.Struct({
@@ -58,21 +60,30 @@ let Action = new r.Struct({
58
60
  actionType: r.uint16,
59
61
  actionLength: r.uint32,
60
62
  actionData: ActionData,
61
- padding: new r.Reserved(r.uint8, t => t.actionLength - t._currentOffset)
63
+ padding: new r.Reserved(
64
+ r.uint8,
65
+ /** @param {StructValue} t @returns {number} */
66
+ t => /** @type {number} */ (t.actionLength) - /** @type {number} */ (t._currentOffset)
67
+ )
62
68
  });
63
69
 
64
70
  let PostcompensationAction = new r.Array(Action, r.uint32);
65
71
  let PostCompensationTable = new r.Struct({
66
- lookupTable: new LookupTable(new r.Pointer(r.uint16, PostcompensationAction))
72
+ lookupTable: LookupTable(new r.Pointer(r.uint16, PostcompensationAction))
67
73
  });
68
74
 
69
75
  let JustificationTable = new r.Struct({
70
76
  classTable: new r.Pointer(r.uint16, ClassTable, { type: 'parent' }),
71
77
  wdcOffset: r.uint16,
72
78
  postCompensationTable: new r.Pointer(r.uint16, PostCompensationTable, { type: 'parent' }),
73
- widthDeltaClusters: new LookupTable(new r.Pointer(r.uint16, WidthDeltaCluster, { type: 'parent', relativeTo: ctx => ctx.wdcOffset }))
79
+ widthDeltaClusters: LookupTable(new r.Pointer(r.uint16, WidthDeltaCluster, {
80
+ type: 'parent',
81
+ /** @param {StructValue} ctx @returns {number} */
82
+ relativeTo: ctx => /** @type {number} */ (ctx.wdcOffset)
83
+ }))
74
84
  });
75
85
 
86
+ /** @type {import('restructure').Struct} */
76
87
  export default new r.Struct({
77
88
  version: r.uint32,
78
89
  format: r.uint16,
@@ -1,5 +1,7 @@
1
1
  import * as r from 'restructure';
2
2
 
3
+ /** @typedef {import('restructure').StructValue} StructValue */
4
+
3
5
  let KernPair = new r.Struct({
4
6
  left: r.uint16,
5
7
  right: r.uint16,
@@ -10,12 +12,34 @@ let ClassTable = new r.Struct({
10
12
  firstGlyph: r.uint16,
11
13
  nGlyphs: r.uint16,
12
14
  offsets: new r.Array(r.uint16, 'nGlyphs'),
13
- max: t => t.offsets.length && Math.max.apply(Math, t.offsets)
15
+ /**
16
+ * @param {StructValue} t
17
+ * @returns {number}
18
+ */
19
+ max: (t) => {
20
+ let offsets = /** @type {number[]} */ (t.offsets);
21
+ return offsets.length ? Math.max.apply(Math, offsets) : 0;
22
+ }
14
23
  });
15
24
 
16
25
  let Kern2Array = new r.Struct({
17
- off: t => t._startOffset - t.parent.parent._startOffset,
18
- len: t => (((t.parent.leftTable.max - t.off) / t.parent.rowWidth) + 1) * (t.parent.rowWidth / 2),
26
+ /**
27
+ * @param {StructValue} t
28
+ * @returns {number}
29
+ */
30
+ off: t => /** @type {number} */ (t._startOffset)
31
+ - /** @type {number} */ (/** @type {StructValue} */ (/** @type {StructValue} */ (t.parent).parent)._startOffset),
32
+ /**
33
+ * @param {StructValue} t
34
+ * @returns {number}
35
+ */
36
+ len: (t) => {
37
+ let parent = /** @type {StructValue} */ (t.parent);
38
+ let leftTable = /** @type {StructValue} */ (parent.leftTable);
39
+ let rowWidth = /** @type {number} */ (parent.rowWidth);
40
+ let off = /** @type {number} */ (t.off);
41
+ return (((/** @type {number} */ (leftTable.max) - off) / rowWidth) + 1) * (rowWidth / 2);
42
+ },
19
43
  values: new r.LazyArray(r.int16, 'len')
20
44
  });
21
45
 
@@ -44,7 +68,11 @@ let KernSubtable = new r.VersionedStruct('format', {
44
68
  kernValue: new r.Array(r.int16, 'kernValueCount'),
45
69
  leftClass: new r.Array(r.uint8, 'glyphCount'),
46
70
  rightClass: new r.Array(r.uint8, 'glyphCount'),
47
- kernIndex: new r.Array(r.uint8, t => t.leftClassCount * t.rightClassCount)
71
+ kernIndex: new r.Array(
72
+ r.uint8,
73
+ /** @param {StructValue} t @returns {number} */
74
+ t => /** @type {number} */ (t.leftClassCount) * /** @type {number} */ (t.rightClassCount)
75
+ )
48
76
  }
49
77
  });
50
78
 
@@ -60,7 +88,11 @@ let KernTable = new r.VersionedStruct('version', {
60
88
  'override' // If set to 1 the value in this table replaces the accumulated value
61
89
  ]),
62
90
  subtable: KernSubtable,
63
- padding: new r.Reserved(r.uint8, t => t.length - t._currentOffset)
91
+ padding: new r.Reserved(
92
+ r.uint8,
93
+ /** @param {StructValue} t @returns {number} */
94
+ t => /** @type {number} */ (t.length) - /** @type {number} */ (t._currentOffset)
95
+ )
64
96
  },
65
97
  1: { // Apple uses this format
66
98
  length: r.uint32,
@@ -73,10 +105,15 @@ let KernTable = new r.VersionedStruct('version', {
73
105
  format: r.uint8,
74
106
  tupleIndex: r.uint16,
75
107
  subtable: KernSubtable,
76
- padding: new r.Reserved(r.uint8, t => t.length - t._currentOffset)
108
+ padding: new r.Reserved(
109
+ r.uint8,
110
+ /** @param {StructValue} t @returns {number} */
111
+ t => /** @type {number} */ (t.length) - /** @type {number} */ (t._currentOffset)
112
+ )
77
113
  }
78
114
  });
79
115
 
116
+ /** @type {import('restructure').VersionedStruct} */
80
117
  export default new r.VersionedStruct(r.uint16, {
81
118
  0: { // Microsoft Version
82
119
  nTables: r.uint16,
@@ -1,5 +1,16 @@
1
1
  import * as r from 'restructure';
2
2
 
3
+ /** @typedef {import('restructure').StructValue} StructValue */
4
+
5
+ /**
6
+ * @typedef {StructValue & {
7
+ * version: number,
8
+ * offsets: number[],
9
+ * _processed?: boolean
10
+ * }} LocaValue
11
+ */
12
+
13
+ /** @type {import('restructure').VersionedStruct} */
3
14
  let loca = new r.VersionedStruct('head.indexToLocFormat', {
4
15
  0: {
5
16
  offsets: new r.Array(r.uint16)
@@ -10,20 +21,22 @@ let loca = new r.VersionedStruct('head.indexToLocFormat', {
10
21
  });
11
22
 
12
23
  loca.process = function () {
13
- if (this.version === 0 && !this._processed) {
14
- for (let i = 0; i < this.offsets.length; i++) {
15
- this.offsets[i] <<= 1;
24
+ let self = /** @type {LocaValue} */ (this);
25
+ if (self.version === 0 && !self._processed) {
26
+ for (let i = 0; i < self.offsets.length; i++) {
27
+ self.offsets[i] <<= 1;
16
28
  }
17
- this._processed = true;
29
+ self._processed = true;
18
30
  }
19
31
  };
20
32
 
21
33
  loca.preEncode = function () {
22
- if (this.version === 0 && this._processed !== false) {
23
- for (let i = 0; i < this.offsets.length; i++) {
24
- this.offsets[i] >>>= 1;
34
+ let self = /** @type {LocaValue} */ (this);
35
+ if (self.version === 0 && self._processed !== false) {
36
+ for (let i = 0; i < self.offsets.length; i++) {
37
+ self.offsets[i] >>>= 1;
25
38
  }
26
- this._processed = false;
39
+ self._processed = false;
27
40
  }
28
41
  };
29
42
 
@@ -1,6 +1,7 @@
1
1
  import * as r from 'restructure';
2
2
 
3
3
  // maxiumum profile
4
+ /** @type {import('restructure').Struct} */
4
5
  export default new r.Struct({
5
6
  version: r.int32,
6
7
  numGlyphs: r.uint16, // The number of glyphs in the font
@@ -1,6 +1,8 @@
1
1
  import * as r from 'restructure';
2
2
  import { UnboundedArray, LookupTable, StateTable } from './aat';
3
3
 
4
+ /** @typedef {import('restructure').StructValue} StructValue */
5
+
4
6
  let LigatureData = {
5
7
  action: r.uint16
6
8
  };
@@ -16,32 +18,32 @@ let InsertionData = {
16
18
  };
17
19
 
18
20
  let SubstitutionTable = new r.Struct({
19
- items: new UnboundedArray(new r.Pointer(r.uint32, new LookupTable()))
21
+ items: new UnboundedArray(new r.Pointer(r.uint32, LookupTable()))
20
22
  });
21
23
 
22
24
  let SubtableData = new r.VersionedStruct('type', {
23
25
  0: { // Indic Rearrangement Subtable
24
- stateTable: new StateTable()
26
+ stateTable: StateTable()
25
27
  },
26
28
 
27
29
  1: { // Contextual Glyph Substitution Subtable
28
- stateTable: new StateTable(ContextualData),
30
+ stateTable: StateTable(ContextualData),
29
31
  substitutionTable: new r.Pointer(r.uint32, SubstitutionTable)
30
32
  },
31
33
 
32
34
  2: { // Ligature subtable
33
- stateTable: new StateTable(LigatureData),
35
+ stateTable: StateTable(LigatureData),
34
36
  ligatureActions: new r.Pointer(r.uint32, new UnboundedArray(r.uint32)),
35
37
  components: new r.Pointer(r.uint32, new UnboundedArray(r.uint16)),
36
38
  ligatureList: new r.Pointer(r.uint32, new UnboundedArray(r.uint16))
37
39
  },
38
40
 
39
41
  4: { // Non-contextual Glyph Substitution Subtable
40
- lookupTable: new LookupTable()
42
+ lookupTable: LookupTable()
41
43
  },
42
44
 
43
45
  5: { // Glyph Insertion Subtable
44
- stateTable: new StateTable(InsertionData),
46
+ stateTable: StateTable(InsertionData),
45
47
  insertionActions: new r.Pointer(r.uint32, new UnboundedArray(r.uint16))
46
48
  }
47
49
  });
@@ -52,7 +54,11 @@ let Subtable = new r.Struct({
52
54
  type: r.uint8,
53
55
  subFeatureFlags: r.uint32,
54
56
  table: SubtableData,
55
- padding: new r.Reserved(r.uint8, t => t.length - t._currentOffset)
57
+ padding: new r.Reserved(
58
+ r.uint8,
59
+ /** @param {StructValue} t @returns {number} */
60
+ t => /** @type {number} */ (t.length) - /** @type {number} */ (t._currentOffset)
61
+ )
56
62
  });
57
63
 
58
64
  let FeatureEntry = new r.Struct({
@@ -71,6 +77,7 @@ let MorxChain = new r.Struct({
71
77
  subtables: new r.Array(Subtable, 'nSubtables')
72
78
  });
73
79
 
80
+ /** @type {import('restructure').Struct} */
74
81
  export default new r.Struct({
75
82
  version: r.uint16,
76
83
  unused: new r.Reserved(r.uint16),