@cantoo/fontkit 2.0.4 → 2.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser-module.mjs +4448 -1142
- package/dist/browser-module.mjs.map +1 -1
- package/dist/browser.cjs +4449 -1142
- package/dist/browser.cjs.map +1 -1
- package/dist/main.cjs +4449 -1142
- package/dist/main.cjs.map +1 -1
- package/dist/module.mjs +4448 -1142
- package/dist/module.mjs.map +1 -1
- package/package.json +4 -1
- package/src/CmapProcessor.js +60 -21
- package/src/DFont.js +114 -14
- package/src/TTFFont.js +260 -62
- package/src/TrueTypeCollection.js +59 -15
- package/src/WOFF2Font.js +128 -22
- package/src/WOFFFont.js +45 -8
- package/src/aat/AATFeatureMap.js +83 -40
- package/src/aat/AATLayoutEngine.js +34 -2
- package/src/aat/AATLookupTable.js +24 -6
- package/src/aat/AATMorxProcessor.js +202 -65
- package/src/aat/AATStateMachine.js +35 -3
- package/src/base.js +20 -1
- package/src/cff/CFFCharsets.js +3 -0
- package/src/cff/CFFDict.js +81 -11
- package/src/cff/CFFEncodings.js +2 -0
- package/src/cff/CFFFont.js +120 -24
- package/src/cff/CFFIndex.js +66 -9
- package/src/cff/CFFOperand.js +53 -28
- package/src/cff/CFFPointer.js +41 -2
- package/src/cff/CFFPrivateDict.js +34 -24
- package/src/cff/CFFStandardStrings.js +68 -67
- package/src/cff/CFFTop.js +161 -68
- package/src/decorators.js +34 -15
- package/src/encodings.js +133 -116
- package/src/fs.js +10 -0
- package/src/glyph/BBox.js +14 -0
- package/src/glyph/CFFGlyph.js +293 -152
- package/src/glyph/COLRGlyph.js +40 -5
- package/src/glyph/Glyph.js +72 -13
- package/src/glyph/GlyphVariationProcessor.js +158 -62
- package/src/glyph/Path.js +119 -32
- package/src/glyph/SBIXGlyph.js +57 -8
- package/src/glyph/StandardNames.js +1 -0
- package/src/glyph/TTFGlyph.js +203 -63
- package/src/glyph/TTFGlyphEncoder.js +58 -26
- package/src/glyph/WOFF2Glyph.js +25 -6
- package/src/layout/GlyphPosition.js +6 -0
- package/src/layout/GlyphRun.js +28 -10
- package/src/layout/KernProcessor.js +63 -4
- package/src/layout/LayoutEngine.js +99 -26
- package/src/layout/Script.js +52 -26
- package/src/layout/UnicodeLayoutEngine.js +34 -10
- package/src/opentype/GPOSProcessor.js +156 -45
- package/src/opentype/GSUBProcessor.js +92 -33
- package/src/opentype/GlyphInfo.js +53 -5
- package/src/opentype/GlyphIterator.js +51 -2
- package/src/opentype/OTLayoutEngine.js +66 -8
- package/src/opentype/OTProcessor.js +284 -71
- package/src/opentype/ShapingPlan.js +52 -5
- package/src/opentype/shapers/ArabicShaper.js +27 -8
- package/src/opentype/shapers/DefaultShaper.js +54 -10
- package/src/opentype/shapers/HangulShaper.js +120 -42
- package/src/opentype/shapers/HebrewShaper.js +50 -16
- package/src/opentype/shapers/IndicShaper.js +159 -44
- package/src/opentype/shapers/ThaiShaper.js +50 -19
- package/src/opentype/shapers/UniversalShaper.js +83 -17
- package/src/opentype/shapers/index.js +48 -35
- package/src/opentype/shapers/indic-data.js +2 -2
- package/src/packages/unicode-properties/data-trie.js +2 -1
- package/src/packages/unicode-properties/data.js +13 -1
- package/src/packages/unicode-properties/dist/index.cjs +23 -10
- package/src/packages/unicode-properties/dist/index.cjs.map +2 -2
- package/src/packages/unicode-properties/dist/index.mjs +22 -10
- package/src/packages/unicode-properties/dist/index.mjs.map +2 -2
- package/src/packages/unicode-properties/generate.js +3 -4
- package/src/packages/unicode-properties/index.js +95 -30
- package/src/packages/unicode-properties/package.json +1 -1
- package/src/packages/unicode-trie/builder.js +146 -29
- package/src/packages/unicode-trie/dist/builder.cjs +135 -25
- package/src/packages/unicode-trie/dist/builder.cjs.map +2 -2
- package/src/packages/unicode-trie/dist/builder.mjs +134 -25
- package/src/packages/unicode-trie/dist/builder.mjs.map +2 -2
- package/src/packages/unicode-trie/dist/index.cjs +22 -9
- package/src/packages/unicode-trie/dist/index.cjs.map +2 -2
- package/src/packages/unicode-trie/dist/index.mjs +21 -9
- package/src/packages/unicode-trie/dist/index.mjs.map +2 -2
- package/src/packages/unicode-trie/index.js +63 -12
- package/src/packages/unicode-trie/package.json +1 -1
- package/src/packages/unicode-trie/swap.js +15 -2
- package/src/subset/CFFSubset.js +112 -22
- package/src/subset/Subset.js +23 -3
- package/src/subset/TTFSubset.js +84 -41
- package/src/tables/BASE.js +28 -27
- package/src/tables/COLR.js +10 -9
- package/src/tables/CPAL.js +2 -1
- package/src/tables/DSIG.js +8 -7
- package/src/tables/EBDT.js +10 -4
- package/src/tables/EBLC.js +70 -10
- package/src/tables/GDEF.js +18 -17
- package/src/tables/GPOS.js +153 -90
- package/src/tables/GSUB.js +50 -39
- package/src/tables/HVAR.js +51 -5
- package/src/tables/JSTF.js +17 -16
- package/src/tables/LTSH.js +4 -3
- package/src/tables/OS2.js +50 -49
- package/src/tables/PCLT.js +16 -15
- package/src/tables/STAT.js +46 -6
- package/src/tables/VDMX.js +18 -17
- package/src/tables/VORG.js +8 -7
- package/src/tables/WOFF2Directory.js +57 -9
- package/src/tables/WOFFDirectory.js +32 -20
- package/src/tables/aat.js +160 -35
- package/src/tables/avar.js +1 -0
- package/src/tables/bsln.js +3 -2
- package/src/tables/cmap.js +83 -63
- package/src/tables/cvt.js +1 -0
- package/src/tables/directory.js +56 -28
- package/src/tables/feat.js +24 -2
- package/src/tables/fpgm.js +1 -0
- package/src/tables/fvar.js +32 -4
- package/src/tables/gasp.js +6 -5
- package/src/tables/glyf.js +2 -1
- package/src/tables/gvar.js +29 -2
- package/src/tables/hdmx.js +18 -7
- package/src/tables/head.js +17 -16
- package/src/tables/hhea.js +15 -14
- package/src/tables/hmtx.js +18 -2
- package/src/tables/index.js +1 -5
- package/src/tables/just.js +15 -4
- package/src/tables/kern.js +84 -47
- package/src/tables/loca.js +23 -10
- package/src/tables/maxp.js +16 -15
- package/src/tables/morx.js +27 -20
- package/src/tables/name.js +120 -39
- package/src/tables/opbd.js +2 -1
- package/src/tables/opentype.js +126 -91
- package/src/tables/post.js +18 -11
- package/src/tables/prep.js +1 -0
- package/src/tables/sbix.js +12 -1
- package/src/tables/variations.js +29 -9
- package/src/tables/vhea.js +15 -14
- package/src/tables/vmtx.js +20 -4
- package/src/utils.js +15 -0
package/src/tables/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
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import * as r from 'restructure';
|
|
2
2
|
|
|
3
3
|
let GaspRange = new r.Struct({
|
|
4
|
-
rangeMaxPPEM:
|
|
5
|
-
rangeGaspBehavior:
|
|
4
|
+
rangeMaxPPEM: r.uint16, // Upper limit of range, in ppem
|
|
5
|
+
rangeGaspBehavior: new r.Bitfield(r.uint16, [ // Flags describing desired rasterizer behavior
|
|
6
6
|
'grayscale', 'gridfit',
|
|
7
|
-
'symmetricSmoothing', 'symmetricGridfit'
|
|
7
|
+
'symmetricSmoothing', 'symmetricGridfit' // only in version 1, for ClearType
|
|
8
8
|
])
|
|
9
9
|
});
|
|
10
10
|
|
|
11
|
+
/** @type {import('restructure').Struct} */
|
|
11
12
|
export default new r.Struct({
|
|
12
|
-
version:
|
|
13
|
-
numRanges:
|
|
13
|
+
version: r.uint16, // set to 0
|
|
14
|
+
numRanges: r.uint16,
|
|
14
15
|
gaspRanges: new r.Array(GaspRange, 'numRanges') // Sorted by ppem
|
|
15
16
|
});
|
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,15 +1,26 @@
|
|
|
1
1
|
import * as r from 'restructure';
|
|
2
2
|
|
|
3
|
+
/** @typedef {import('restructure').StructValue} StructValue */
|
|
4
|
+
|
|
3
5
|
let DeviceRecord = new r.Struct({
|
|
4
|
-
pixelSize:
|
|
5
|
-
maximumWidth:
|
|
6
|
-
widths:
|
|
6
|
+
pixelSize: r.uint8,
|
|
7
|
+
maximumWidth: r.uint8,
|
|
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
|
-
version:
|
|
12
|
-
numRecords:
|
|
13
|
-
sizeDeviceRecord:
|
|
14
|
-
records:
|
|
22
|
+
version: r.uint16,
|
|
23
|
+
numRecords: r.int16,
|
|
24
|
+
sizeDeviceRecord: r.int32,
|
|
25
|
+
records: new r.Array(DeviceRecord, 'numRecords')
|
|
15
26
|
});
|
package/src/tables/head.js
CHANGED
|
@@ -1,25 +1,26 @@
|
|
|
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
|
-
version:
|
|
6
|
-
revision:
|
|
6
|
+
version: r.int32, // 0x00010000 (version 1.0)
|
|
7
|
+
revision: r.int32, // set by font manufacturer
|
|
7
8
|
checkSumAdjustment: r.uint32,
|
|
8
|
-
magicNumber:
|
|
9
|
-
flags:
|
|
10
|
-
unitsPerEm:
|
|
11
|
-
created:
|
|
12
|
-
modified:
|
|
13
|
-
xMin:
|
|
14
|
-
yMin:
|
|
15
|
-
xMax:
|
|
16
|
-
yMax:
|
|
17
|
-
macStyle:
|
|
9
|
+
magicNumber: r.uint32, // set to 0x5F0F3CF5
|
|
10
|
+
flags: r.uint16,
|
|
11
|
+
unitsPerEm: r.uint16, // range from 64 to 16384
|
|
12
|
+
created: new r.Array(r.int32, 2),
|
|
13
|
+
modified: new r.Array(r.int32, 2),
|
|
14
|
+
xMin: r.int16, // for all glyph bounding boxes
|
|
15
|
+
yMin: r.int16, // for all glyph bounding boxes
|
|
16
|
+
xMax: r.int16, // for all glyph bounding boxes
|
|
17
|
+
yMax: r.int16, // for all glyph bounding boxes
|
|
18
|
+
macStyle: new r.Bitfield(r.uint16, [
|
|
18
19
|
'bold', 'italic', 'underline', 'outline',
|
|
19
20
|
'shadow', 'condensed', 'extended'
|
|
20
21
|
]),
|
|
21
|
-
lowestRecPPEM:
|
|
22
|
-
fontDirectionHint:
|
|
23
|
-
indexToLocFormat:
|
|
24
|
-
glyphDataFormat:
|
|
22
|
+
lowestRecPPEM: r.uint16, // smallest readable size in pixels
|
|
23
|
+
fontDirectionHint: r.int16,
|
|
24
|
+
indexToLocFormat: r.int16, // 0 for short offsets, 1 for long
|
|
25
|
+
glyphDataFormat: r.int16 // 0 for current format
|
|
25
26
|
});
|
package/src/tables/hhea.js
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
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
|
-
version:
|
|
6
|
-
ascent:
|
|
7
|
-
descent:
|
|
8
|
-
lineGap:
|
|
9
|
-
advanceWidthMax:
|
|
10
|
-
minLeftSideBearing:
|
|
11
|
-
minRightSideBearing:
|
|
12
|
-
xMaxExtent:
|
|
13
|
-
caretSlopeRise:
|
|
14
|
-
caretSlopeRun:
|
|
15
|
-
caretOffset:
|
|
16
|
-
reserved:
|
|
17
|
-
metricDataFormat:
|
|
18
|
-
numberOfMetrics:
|
|
6
|
+
version: r.int32,
|
|
7
|
+
ascent: r.int16, // Distance from baseline of highest ascender
|
|
8
|
+
descent: r.int16, // Distance from baseline of lowest descender
|
|
9
|
+
lineGap: r.int16, // Typographic line gap
|
|
10
|
+
advanceWidthMax: r.uint16, // Maximum advance width value in 'hmtx' table
|
|
11
|
+
minLeftSideBearing: r.int16, // Maximum advance width value in 'hmtx' table
|
|
12
|
+
minRightSideBearing: r.int16, // Minimum right sidebearing value
|
|
13
|
+
xMaxExtent: r.int16,
|
|
14
|
+
caretSlopeRise: r.int16, // Used to calculate the slope of the cursor (rise/run); 1 for vertical
|
|
15
|
+
caretSlopeRun: r.int16, // 0 for vertical
|
|
16
|
+
caretOffset: r.int16, // Set to 0 for non-slanted fonts
|
|
17
|
+
reserved: new r.Reserved(r.int16, 4),
|
|
18
|
+
metricDataFormat: r.int16, // 0 for current format
|
|
19
|
+
numberOfMetrics: r.uint16 // Number of advance widths in 'hmtx' table
|
|
19
20
|
});
|
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:
|
|
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
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/** @type {Record<string, import('../../types/fontkit').TableCodec>} */
|
|
1
2
|
let tables = {};
|
|
2
3
|
export default tables;
|
|
3
4
|
|
|
@@ -20,7 +21,6 @@ tables.name = name;
|
|
|
20
21
|
tables['OS/2'] = OS2;
|
|
21
22
|
tables.post = post;
|
|
22
23
|
|
|
23
|
-
|
|
24
24
|
// TrueType Outlines
|
|
25
25
|
import cvt from './cvt';
|
|
26
26
|
import fpgm from './fpgm';
|
|
@@ -34,7 +34,6 @@ tables.prep = prep;
|
|
|
34
34
|
tables['cvt '] = cvt;
|
|
35
35
|
tables.glyf = glyf;
|
|
36
36
|
|
|
37
|
-
|
|
38
37
|
// PostScript Outlines
|
|
39
38
|
import CFFFont from '../cff/CFFFont';
|
|
40
39
|
import VORG from './VORG';
|
|
@@ -43,7 +42,6 @@ tables['CFF '] = CFFFont;
|
|
|
43
42
|
tables['CFF2'] = CFFFont;
|
|
44
43
|
tables.VORG = VORG;
|
|
45
44
|
|
|
46
|
-
|
|
47
45
|
// Bitmap Glyphs
|
|
48
46
|
import EBLC from './EBLC';
|
|
49
47
|
import sbix from './sbix';
|
|
@@ -56,7 +54,6 @@ tables.sbix = sbix;
|
|
|
56
54
|
tables.COLR = COLR;
|
|
57
55
|
tables.CPAL = CPAL;
|
|
58
56
|
|
|
59
|
-
|
|
60
57
|
// Advanced OpenType Tables
|
|
61
58
|
import BASE from './BASE';
|
|
62
59
|
import GDEF from './GDEF';
|
|
@@ -98,7 +95,6 @@ tables.VDMX = VDMX;
|
|
|
98
95
|
tables.vhea = vhea;
|
|
99
96
|
tables.vmtx = vmtx;
|
|
100
97
|
|
|
101
|
-
|
|
102
98
|
// Apple Advanced Typography Tables
|
|
103
99
|
import avar from './avar';
|
|
104
100
|
import bsln from './bsln';
|
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,91 +1,128 @@
|
|
|
1
1
|
import * as r from 'restructure';
|
|
2
2
|
|
|
3
|
+
/** @typedef {import('restructure').StructValue} StructValue */
|
|
4
|
+
|
|
3
5
|
let KernPair = new r.Struct({
|
|
4
|
-
left:
|
|
5
|
-
right:
|
|
6
|
-
value:
|
|
6
|
+
left: r.uint16,
|
|
7
|
+
right: r.uint16,
|
|
8
|
+
value: r.int16
|
|
7
9
|
});
|
|
8
10
|
|
|
9
11
|
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
|
|
|
22
46
|
let KernSubtable = new r.VersionedStruct('format', {
|
|
23
47
|
0: {
|
|
24
|
-
nPairs:
|
|
25
|
-
searchRange:
|
|
26
|
-
entrySelector:
|
|
27
|
-
rangeShift:
|
|
28
|
-
pairs:
|
|
48
|
+
nPairs: r.uint16,
|
|
49
|
+
searchRange: r.uint16,
|
|
50
|
+
entrySelector: r.uint16,
|
|
51
|
+
rangeShift: r.uint16,
|
|
52
|
+
pairs: new r.Array(KernPair, 'nPairs')
|
|
29
53
|
},
|
|
30
54
|
|
|
31
55
|
2: {
|
|
32
|
-
rowWidth:
|
|
33
|
-
leftTable:
|
|
34
|
-
rightTable: new r.Pointer(r.uint16, ClassTable, {type: 'parent'}),
|
|
35
|
-
array:
|
|
56
|
+
rowWidth: r.uint16,
|
|
57
|
+
leftTable: new r.Pointer(r.uint16, ClassTable, { type: 'parent' }),
|
|
58
|
+
rightTable: new r.Pointer(r.uint16, ClassTable, { type: 'parent' }),
|
|
59
|
+
array: new r.Pointer(r.uint16, Kern2Array, { type: 'parent' })
|
|
36
60
|
},
|
|
37
61
|
|
|
38
62
|
3: {
|
|
39
|
-
glyphCount:
|
|
40
|
-
kernValueCount:
|
|
41
|
-
leftClassCount:
|
|
42
|
-
rightClassCount:
|
|
43
|
-
flags:
|
|
44
|
-
kernValue:
|
|
45
|
-
leftClass:
|
|
46
|
-
rightClass:
|
|
47
|
-
kernIndex:
|
|
63
|
+
glyphCount: r.uint16,
|
|
64
|
+
kernValueCount: r.uint8,
|
|
65
|
+
leftClassCount: r.uint8,
|
|
66
|
+
rightClassCount: r.uint8,
|
|
67
|
+
flags: r.uint8,
|
|
68
|
+
kernValue: new r.Array(r.int16, 'kernValueCount'),
|
|
69
|
+
leftClass: new r.Array(r.uint8, 'glyphCount'),
|
|
70
|
+
rightClass: new r.Array(r.uint8, 'glyphCount'),
|
|
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
|
|
|
51
79
|
let KernTable = new r.VersionedStruct('version', {
|
|
52
80
|
0: { // Microsoft uses this format
|
|
53
|
-
subVersion: r.uint16,
|
|
54
|
-
length:
|
|
55
|
-
format:
|
|
56
|
-
coverage:
|
|
57
|
-
'horizontal',
|
|
58
|
-
'minimum',
|
|
59
|
-
'crossStream',
|
|
60
|
-
'override'
|
|
81
|
+
subVersion: r.uint16, // Microsoft has an extra sub-table version number
|
|
82
|
+
length: r.uint16, // Length of the subtable, in bytes
|
|
83
|
+
format: r.uint8, // Format of subtable
|
|
84
|
+
coverage: new r.Bitfield(r.uint8, [
|
|
85
|
+
'horizontal', // 1 if table has horizontal data, 0 if vertical
|
|
86
|
+
'minimum', // If set to 1, the table has minimum values. If set to 0, the table has kerning values.
|
|
87
|
+
'crossStream', // If set to 1, kerning is perpendicular to the flow of the text
|
|
88
|
+
'override' // If set to 1 the value in this table replaces the accumulated value
|
|
61
89
|
]),
|
|
62
|
-
subtable:
|
|
63
|
-
padding: new r.Reserved(
|
|
90
|
+
subtable: KernSubtable,
|
|
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
|
-
length:
|
|
67
|
-
coverage:
|
|
98
|
+
length: r.uint32,
|
|
99
|
+
coverage: new r.Bitfield(r.uint8, [
|
|
68
100
|
null, null, null, null, null,
|
|
69
|
-
'variation',
|
|
70
|
-
'crossStream',
|
|
71
|
-
'vertical'
|
|
101
|
+
'variation', // Set if table has variation kerning values
|
|
102
|
+
'crossStream', // Set if table has cross-stream kerning values
|
|
103
|
+
'vertical' // Set if table has vertical kerning values
|
|
72
104
|
]),
|
|
73
|
-
format:
|
|
105
|
+
format: r.uint8,
|
|
74
106
|
tupleIndex: r.uint16,
|
|
75
|
-
subtable:
|
|
76
|
-
padding: new r.Reserved(
|
|
107
|
+
subtable: KernSubtable,
|
|
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
|
-
nTables:
|
|
83
|
-
tables:
|
|
119
|
+
nTables: r.uint16,
|
|
120
|
+
tables: new r.Array(KernTable, 'nTables')
|
|
84
121
|
},
|
|
85
122
|
|
|
86
123
|
1: { // Apple Version
|
|
87
|
-
reserved:
|
|
88
|
-
nTables:
|
|
89
|
-
tables:
|
|
124
|
+
reserved: new r.Reserved(r.uint16), // the other half of the version number
|
|
125
|
+
nTables: r.uint32,
|
|
126
|
+
tables: new r.Array(KernTable, 'nTables')
|
|
90
127
|
}
|
|
91
128
|
});
|
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)
|
|
@@ -9,21 +20,23 @@ let loca = new r.VersionedStruct('head.indexToLocFormat', {
|
|
|
9
20
|
}
|
|
10
21
|
});
|
|
11
22
|
|
|
12
|
-
loca.process = function() {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
23
|
+
loca.process = function () {
|
|
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
|
-
loca.preEncode = function() {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
33
|
+
loca.preEncode = function () {
|
|
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
|
|