@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.
- package/dist/browser-module.mjs +4423 -1117
- package/dist/browser-module.mjs.map +1 -1
- package/dist/browser.cjs +4424 -1117
- package/dist/browser.cjs.map +1 -1
- package/dist/main.cjs +4424 -1117
- package/dist/main.cjs.map +1 -1
- package/dist/module.mjs +4423 -1117
- package/dist/module.mjs.map +1 -1
- package/package.json +3 -1
- package/src/CmapProcessor.js +59 -20
- package/src/DFont.js +114 -14
- package/src/TTFFont.js +259 -57
- package/src/TrueTypeCollection.js +54 -10
- package/src/WOFF2Font.js +128 -16
- package/src/WOFFFont.js +45 -8
- package/src/aat/AATFeatureMap.js +62 -18
- package/src/aat/AATLayoutEngine.js +33 -1
- package/src/aat/AATLookupTable.js +22 -4
- package/src/aat/AATMorxProcessor.js +189 -52
- package/src/aat/AATStateMachine.js +32 -0
- package/src/base.js +19 -0
- package/src/cff/CFFCharsets.js +3 -0
- package/src/cff/CFFDict.js +79 -9
- package/src/cff/CFFEncodings.js +2 -0
- package/src/cff/CFFFont.js +119 -23
- package/src/cff/CFFIndex.js +62 -5
- package/src/cff/CFFOperand.js +52 -17
- package/src/cff/CFFPointer.js +41 -2
- package/src/cff/CFFPrivateDict.js +14 -4
- package/src/cff/CFFStandardStrings.js +1 -0
- package/src/cff/CFFTop.js +103 -10
- package/src/decorators.js +32 -13
- package/src/encodings.js +22 -5
- package/src/fs.js +10 -0
- package/src/glyph/BBox.js +14 -0
- package/src/glyph/CFFGlyph.js +290 -148
- package/src/glyph/COLRGlyph.js +38 -3
- package/src/glyph/Glyph.js +68 -9
- package/src/glyph/GlyphVariationProcessor.js +135 -34
- package/src/glyph/Path.js +107 -20
- package/src/glyph/SBIXGlyph.js +57 -8
- package/src/glyph/StandardNames.js +1 -0
- package/src/glyph/TTFGlyph.js +176 -29
- package/src/glyph/TTFGlyphEncoder.js +32 -0
- package/src/glyph/WOFF2Glyph.js +23 -4
- package/src/layout/GlyphPosition.js +6 -0
- package/src/layout/GlyphRun.js +25 -7
- package/src/layout/KernProcessor.js +62 -3
- package/src/layout/LayoutEngine.js +86 -12
- package/src/layout/Script.js +27 -1
- package/src/layout/UnicodeLayoutEngine.js +29 -4
- package/src/opentype/GPOSProcessor.js +156 -45
- package/src/opentype/GSUBProcessor.js +92 -33
- package/src/opentype/GlyphInfo.js +52 -4
- package/src/opentype/GlyphIterator.js +51 -2
- package/src/opentype/OTLayoutEngine.js +66 -8
- package/src/opentype/OTProcessor.js +283 -70
- package/src/opentype/ShapingPlan.js +51 -3
- package/src/opentype/shapers/ArabicShaper.js +19 -0
- package/src/opentype/shapers/DefaultShaper.js +51 -7
- package/src/opentype/shapers/HangulShaper.js +85 -7
- package/src/opentype/shapers/HebrewShaper.js +45 -11
- package/src/opentype/shapers/IndicShaper.js +141 -26
- package/src/opentype/shapers/ThaiShaper.js +35 -4
- package/src/opentype/shapers/UniversalShaper.js +83 -17
- package/src/opentype/shapers/index.js +15 -2
- package/src/packages/unicode-properties/data-trie.js +1 -0
- package/src/packages/unicode-properties/data.js +12 -0
- package/src/packages/unicode-properties/dist/index.cjs +22 -9
- package/src/packages/unicode-properties/dist/index.cjs.map +2 -2
- package/src/packages/unicode-properties/dist/index.mjs +21 -9
- package/src/packages/unicode-properties/dist/index.mjs.map +2 -2
- package/src/packages/unicode-properties/index.js +65 -0
- package/src/packages/unicode-properties/package.json +1 -1
- package/src/packages/unicode-trie/builder.js +128 -7
- package/src/packages/unicode-trie/dist/builder.cjs +129 -16
- package/src/packages/unicode-trie/dist/builder.cjs.map +2 -2
- package/src/packages/unicode-trie/dist/builder.mjs +128 -16
- 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 +62 -10
- package/src/packages/unicode-trie/package.json +1 -1
- package/src/packages/unicode-trie/swap.js +13 -0
- package/src/subset/CFFSubset.js +112 -22
- package/src/subset/Subset.js +21 -1
- package/src/subset/TTFSubset.js +79 -36
- package/src/tables/BASE.js +1 -0
- package/src/tables/COLR.js +1 -0
- package/src/tables/CPAL.js +1 -0
- package/src/tables/DSIG.js +1 -0
- package/src/tables/EBDT.js +10 -3
- package/src/tables/EBLC.js +67 -7
- package/src/tables/GDEF.js +1 -0
- package/src/tables/GPOS.js +79 -16
- package/src/tables/GSUB.js +14 -3
- package/src/tables/HVAR.js +51 -5
- package/src/tables/JSTF.js +3 -2
- package/src/tables/LTSH.js +1 -0
- package/src/tables/OS2.js +1 -0
- package/src/tables/PCLT.js +1 -0
- package/src/tables/STAT.js +46 -6
- package/src/tables/VDMX.js +1 -0
- package/src/tables/VORG.js +1 -0
- package/src/tables/WOFF2Directory.js +56 -8
- package/src/tables/WOFFDirectory.js +14 -2
- 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 +26 -6
- package/src/tables/cvt.js +1 -0
- package/src/tables/directory.js +44 -16
- 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 +1 -0
- package/src/tables/glyf.js +1 -0
- package/src/tables/gvar.js +29 -2
- package/src/tables/hdmx.js +12 -1
- package/src/tables/head.js +1 -0
- package/src/tables/hhea.js +1 -0
- package/src/tables/hmtx.js +18 -2
- package/src/tables/index.js +1 -0
- package/src/tables/just.js +15 -4
- package/src/tables/kern.js +43 -6
- package/src/tables/loca.js +21 -8
- package/src/tables/maxp.js +1 -0
- package/src/tables/morx.js +14 -7
- package/src/tables/name.js +104 -23
- package/src/tables/opbd.js +2 -1
- package/src/tables/opentype.js +39 -4
- package/src/tables/post.js +8 -1
- package/src/tables/prep.js +1 -0
- package/src/tables/sbix.js +12 -1
- package/src/tables/variations.js +23 -3
- package/src/tables/vhea.js +1 -0
- package/src/tables/vmtx.js +18 -2
- package/src/utils.js +15 -0
package/src/tables/feat.js
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
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,
|
package/src/tables/fpgm.js
CHANGED
|
@@ -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
|
});
|
package/src/tables/fvar.js
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
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(
|
|
18
|
-
|
|
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,
|
package/src/tables/gasp.js
CHANGED
package/src/tables/glyf.js
CHANGED
package/src/tables/gvar.js
CHANGED
|
@@ -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(
|
|
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;
|
package/src/tables/hdmx.js
CHANGED
|
@@ -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(
|
|
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,
|
package/src/tables/head.js
CHANGED
package/src/tables/hhea.js
CHANGED
package/src/tables/hmtx.js
CHANGED
|
@@ -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(
|
|
10
|
-
|
|
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
|
});
|
package/src/tables/index.js
CHANGED
package/src/tables/just.js
CHANGED
|
@@ -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:
|
|
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(
|
|
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:
|
|
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:
|
|
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,
|
package/src/tables/kern.js
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
18
|
-
|
|
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(
|
|
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(
|
|
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(
|
|
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,
|
package/src/tables/loca.js
CHANGED
|
@@ -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
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
-
|
|
29
|
+
self._processed = true;
|
|
18
30
|
}
|
|
19
31
|
};
|
|
20
32
|
|
|
21
33
|
loca.preEncode = function () {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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
|
-
|
|
39
|
+
self._processed = false;
|
|
27
40
|
}
|
|
28
41
|
};
|
|
29
42
|
|
package/src/tables/maxp.js
CHANGED
package/src/tables/morx.js
CHANGED
|
@@ -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,
|
|
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:
|
|
26
|
+
stateTable: StateTable()
|
|
25
27
|
},
|
|
26
28
|
|
|
27
29
|
1: { // Contextual Glyph Substitution Subtable
|
|
28
|
-
stateTable:
|
|
30
|
+
stateTable: StateTable(ContextualData),
|
|
29
31
|
substitutionTable: new r.Pointer(r.uint32, SubstitutionTable)
|
|
30
32
|
},
|
|
31
33
|
|
|
32
34
|
2: { // Ligature subtable
|
|
33
|
-
stateTable:
|
|
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:
|
|
42
|
+
lookupTable: LookupTable()
|
|
41
43
|
},
|
|
42
44
|
|
|
43
45
|
5: { // Glyph Insertion Subtable
|
|
44
|
-
stateTable:
|
|
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(
|
|
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),
|