lib-font 2.6.0 → 3.0.1
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/.github/workflows/ci.yml +29 -0
- package/.prettierrc +6 -0
- package/LICENSE +1 -1
- package/lib-font.browser.js +1 -1
- package/lib-font.js +176 -162
- package/package.json +8 -11
- package/src/opentype/tables/advanced/lookups/gpos/gpos-lookup.js +15 -2
- package/src/opentype/tables/advanced/lookups/gpos/lookup-type-1.js +1 -0
- package/src/opentype/tables/advanced/lookups/gpos/lookup-type-2.js +1 -0
- package/src/opentype/tables/advanced/lookups/gpos/lookup-type-3.js +1 -0
- package/src/opentype/tables/advanced/lookups/gpos/lookup-type-4.js +3 -1
- package/src/opentype/tables/advanced/lookups/gpos/lookup-type-5.js +3 -1
- package/src/opentype/tables/advanced/lookups/gpos/lookup-type-6.js +3 -1
- package/src/opentype/tables/advanced/lookups/gpos/lookup-type-7.js +1 -0
- package/src/opentype/tables/advanced/lookups/gpos/lookup-type-8.js +5 -1
- package/src/opentype/tables/advanced/lookups/gpos/lookup-type-9.js +3 -1
- package/src/opentype/tables/advanced/lookups/gsub/gsub-lookup.js +3 -1
- package/src/opentype/tables/advanced/lookups/gsub/lookup-type-1.js +12 -1
- package/src/opentype/tables/advanced/lookups/gsub/lookup-type-2.js +1 -0
- package/src/opentype/tables/advanced/lookups/gsub/lookup-type-3.js +1 -0
- package/src/opentype/tables/advanced/lookups/gsub/lookup-type-4.js +1 -0
- package/src/opentype/tables/advanced/lookups/gsub/lookup-type-5.js +10 -11
- package/src/opentype/tables/advanced/lookups/gsub/lookup-type-6.js +51 -24
- package/src/opentype/tables/advanced/lookups/gsub/lookup-type-7.js +46 -5
- package/src/opentype/tables/advanced/lookups/gsub/lookup-type-8.js +1 -0
- package/src/opentype/tables/advanced/shared/lookup.js +3 -1
- package/src/opentype/tables/simple/name.js +27 -1
|
@@ -7,19 +7,20 @@ import {
|
|
|
7
7
|
import { CoverageTable } from "../../shared/coverage.js";
|
|
8
8
|
|
|
9
9
|
class LookupType5 extends LookupType {
|
|
10
|
+
type = 5;
|
|
10
11
|
constructor(p) {
|
|
11
12
|
super(p);
|
|
12
13
|
|
|
13
14
|
// There are three possible subtable formats
|
|
14
15
|
|
|
15
|
-
if (this.
|
|
16
|
+
if (this.format === 1) {
|
|
16
17
|
this.subRuleSetCount = p.uint16;
|
|
17
18
|
this.subRuleSetOffsets = [...new Array(this.subRuleSetCount)].map(
|
|
18
19
|
(_) => p.Offset16
|
|
19
20
|
);
|
|
20
21
|
}
|
|
21
22
|
|
|
22
|
-
if (this.
|
|
23
|
+
if (this.format === 2) {
|
|
23
24
|
this.classDefOffset = p.Offset16;
|
|
24
25
|
this.subClassSetCount = p.uint16;
|
|
25
26
|
this.subClassSetOffsets = [...new Array(this.subClassSetCount)].map(
|
|
@@ -27,7 +28,7 @@ class LookupType5 extends LookupType {
|
|
|
27
28
|
);
|
|
28
29
|
}
|
|
29
30
|
|
|
30
|
-
if (this.
|
|
31
|
+
if (this.format === 3) {
|
|
31
32
|
// undo the coverageOffset parsing, because this format uses an
|
|
32
33
|
// entire *array* of coverage offsets instead, like 6.3
|
|
33
34
|
undoCoverageOffsetParsing(this);
|
|
@@ -44,29 +45,27 @@ class LookupType5 extends LookupType {
|
|
|
44
45
|
}
|
|
45
46
|
|
|
46
47
|
getSubRuleSet(index) {
|
|
47
|
-
if (this.
|
|
48
|
-
throw new Error(`lookup type 5.${this.
|
|
48
|
+
if (this.format !== 1)
|
|
49
|
+
throw new Error(`lookup type 5.${this.format} has no subrule sets.`);
|
|
49
50
|
let p = this.parser;
|
|
50
51
|
p.currentPosition = this.start + this.subRuleSetOffsets[index];
|
|
51
52
|
return new SubRuleSetTable(p);
|
|
52
53
|
}
|
|
53
54
|
|
|
54
55
|
getSubClassSet(index) {
|
|
55
|
-
if (this.
|
|
56
|
-
throw new Error(
|
|
57
|
-
`lookup type 5.${this.substFormat} has no subclass sets.`
|
|
58
|
-
);
|
|
56
|
+
if (this.format !== 2)
|
|
57
|
+
throw new Error(`lookup type 5.${this.format} has no subclass sets.`);
|
|
59
58
|
let p = this.parser;
|
|
60
59
|
p.currentPosition = this.start + this.subClassSetOffsets[index];
|
|
61
60
|
return new SubClassSetTable(p);
|
|
62
61
|
}
|
|
63
62
|
|
|
64
63
|
getCoverageTable(index) {
|
|
65
|
-
if (this.
|
|
64
|
+
if (this.format !== 3 && !index) return super.getCoverageTable();
|
|
66
65
|
|
|
67
66
|
if (!index)
|
|
68
67
|
throw new Error(
|
|
69
|
-
`lookup type 5.${this.
|
|
68
|
+
`lookup type 5.${this.format} requires an coverage table index.`
|
|
70
69
|
);
|
|
71
70
|
|
|
72
71
|
let p = this.parser;
|
|
@@ -5,21 +5,23 @@ import {
|
|
|
5
5
|
SubstLookupRecord,
|
|
6
6
|
} from "./gsub-lookup.js";
|
|
7
7
|
import { CoverageTable } from "../../shared/coverage.js";
|
|
8
|
+
import { ClassDefinition } from "../../shared/class.js";
|
|
8
9
|
|
|
9
10
|
class LookupType6 extends LookupType {
|
|
11
|
+
type = 6;
|
|
10
12
|
constructor(p) {
|
|
11
13
|
super(p);
|
|
12
14
|
|
|
13
15
|
// There are three possible subtable formats
|
|
14
16
|
|
|
15
|
-
if (this.
|
|
17
|
+
if (this.format === 1) {
|
|
16
18
|
this.chainSubRuleSetCount = p.uint16;
|
|
17
19
|
this.chainSubRuleSetOffsets = [
|
|
18
20
|
...new Array(this.chainSubRuleSetCount),
|
|
19
21
|
].map((_) => p.Offset16);
|
|
20
22
|
}
|
|
21
23
|
|
|
22
|
-
if (this.
|
|
24
|
+
if (this.format === 2) {
|
|
23
25
|
this.backtrackClassDefOffset = p.Offset16;
|
|
24
26
|
this.inputClassDefOffset = p.Offset16;
|
|
25
27
|
this.lookaheadClassDefOffset = p.Offset16;
|
|
@@ -29,7 +31,7 @@ class LookupType6 extends LookupType {
|
|
|
29
31
|
].map((_) => p.Offset16);
|
|
30
32
|
}
|
|
31
33
|
|
|
32
|
-
if (this.
|
|
34
|
+
if (this.format === 3) {
|
|
33
35
|
// undo the coverageOffset parsing, because this format uses an
|
|
34
36
|
// entire *array* of coverage offsets instead, like 5.3
|
|
35
37
|
undoCoverageOffsetParsing(this);
|
|
@@ -46,27 +48,25 @@ class LookupType6 extends LookupType {
|
|
|
46
48
|
this.lookaheadCoverageOffsets = [
|
|
47
49
|
...new Array(this.lookaheadGlyphCount),
|
|
48
50
|
].map((_) => p.Offset16);
|
|
49
|
-
this.
|
|
50
|
-
this.
|
|
51
|
-
(_) => new
|
|
51
|
+
this.substitutionCount = p.uint16;
|
|
52
|
+
this.substLookupRecords = [...new Array(this.substitutionCount)].map(
|
|
53
|
+
(_) => new SubstLookupRecord(p)
|
|
52
54
|
);
|
|
53
55
|
}
|
|
54
56
|
}
|
|
55
57
|
|
|
56
58
|
getChainSubRuleSet(index) {
|
|
57
|
-
if (this.
|
|
58
|
-
throw new Error(
|
|
59
|
-
`lookup type 6.${this.substFormat} has no chainsubrule sets.`
|
|
60
|
-
);
|
|
59
|
+
if (this.format !== 1)
|
|
60
|
+
throw new Error(`lookup type 6.${this.format} has no chainsubrule sets.`);
|
|
61
61
|
let p = this.parser;
|
|
62
62
|
p.currentPosition = this.start + this.chainSubRuleSetOffsets[index];
|
|
63
63
|
return new ChainSubRuleSetTable(p);
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
getChainSubClassSet(index) {
|
|
67
|
-
if (this.
|
|
67
|
+
if (this.format !== 2)
|
|
68
68
|
throw new Error(
|
|
69
|
-
`lookup type 6.${this.
|
|
69
|
+
`lookup type 6.${this.format} has no chainsubclass sets.`
|
|
70
70
|
);
|
|
71
71
|
let p = this.parser;
|
|
72
72
|
p.currentPosition = this.start + this.chainSubClassSetOffsets[index];
|
|
@@ -74,14 +74,48 @@ class LookupType6 extends LookupType {
|
|
|
74
74
|
}
|
|
75
75
|
|
|
76
76
|
getCoverageFromOffset(offset) {
|
|
77
|
-
if (this.
|
|
77
|
+
if (this.format !== 3)
|
|
78
78
|
throw new Error(
|
|
79
|
-
`lookup type 6.${this.
|
|
79
|
+
`lookup type 6.${this.format} does not use contextual coverage offsets.`
|
|
80
80
|
);
|
|
81
81
|
let p = this.parser;
|
|
82
82
|
p.currentPosition = this.start + offset;
|
|
83
83
|
return new CoverageTable(p);
|
|
84
84
|
}
|
|
85
|
+
|
|
86
|
+
getBacktrackClassDef() {
|
|
87
|
+
if (this.format !== 2)
|
|
88
|
+
throw new Error(
|
|
89
|
+
`lookup type 6.${this.format} does not use class definitions.`
|
|
90
|
+
);
|
|
91
|
+
let p = this.parser;
|
|
92
|
+
p.currentPosition = this.start + this.backtrackClassDefOffset;
|
|
93
|
+
return new ClassDefinition(p);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
getInputClassDef() {
|
|
97
|
+
if (this.format !== 2)
|
|
98
|
+
throw new Error(
|
|
99
|
+
`lookup type 6.${this.format} does not use class definitions.`
|
|
100
|
+
);
|
|
101
|
+
let p = this.parser;
|
|
102
|
+
p.currentPosition = this.start + this.inputClassDefOffset;
|
|
103
|
+
return new ClassDefinition(p);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
getLookaheadClassDef() {
|
|
107
|
+
if (this.format !== 2)
|
|
108
|
+
throw new Error(
|
|
109
|
+
`lookup type 6.${this.format} does not use class definitions.`
|
|
110
|
+
);
|
|
111
|
+
let p = this.parser;
|
|
112
|
+
p.currentPosition = this.start + this.lookaheadClassDefOffset;
|
|
113
|
+
return new ClassDefinition(p);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
getSubstLookupRecord(index) {
|
|
117
|
+
return this.substLookupRecords?.[index];
|
|
118
|
+
}
|
|
85
119
|
}
|
|
86
120
|
|
|
87
121
|
// 6.1
|
|
@@ -155,18 +189,11 @@ class ChainSubClassRuleTable {
|
|
|
155
189
|
);
|
|
156
190
|
this.substitutionCount = p.uint16;
|
|
157
191
|
this.substLookupRecords = [...new Array(this.substitutionCount)].map(
|
|
158
|
-
(_) => new
|
|
192
|
+
(_) => new SubstLookupRecord(p)
|
|
159
193
|
);
|
|
160
194
|
}
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
// 6.3
|
|
164
|
-
|
|
165
|
-
class SequenceLookupRecord extends ParsedData {
|
|
166
|
-
constructor(p) {
|
|
167
|
-
super(p);
|
|
168
|
-
this.sequenceIndex = p.uint16;
|
|
169
|
-
this.lookupListIndex = p.uint16;
|
|
195
|
+
getSubstLookupRecord(index) {
|
|
196
|
+
return this.substLookupRecords[index];
|
|
170
197
|
}
|
|
171
198
|
}
|
|
172
199
|
|
|
@@ -1,12 +1,53 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { LookupType, undoCoverageOffsetParsing } from "./gsub-lookup.js";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
import { LookupType1 } from "./lookup-type-1.js";
|
|
4
|
+
import { LookupType2 } from "./lookup-type-2.js";
|
|
5
|
+
import { LookupType3 } from "./lookup-type-3.js";
|
|
6
|
+
import { LookupType4 } from "./lookup-type-4.js";
|
|
7
|
+
import { LookupType5 } from "./lookup-type-5.js";
|
|
8
|
+
import { LookupType6 } from "./lookup-type-6.js";
|
|
9
|
+
import { LookupType8 } from "./lookup-type-8.js";
|
|
10
|
+
|
|
11
|
+
const Lookups = [
|
|
12
|
+
null,
|
|
13
|
+
LookupType1,
|
|
14
|
+
LookupType2,
|
|
15
|
+
LookupType3,
|
|
16
|
+
LookupType4,
|
|
17
|
+
LookupType5,
|
|
18
|
+
LookupType6,
|
|
19
|
+
null,
|
|
20
|
+
LookupType8,
|
|
21
|
+
];
|
|
22
|
+
|
|
23
|
+
// This subtable is the "I actually need a 32 bit
|
|
24
|
+
// offset" hack table that is used as a pointer to
|
|
25
|
+
// any of the other subtables that can't be pointed
|
|
26
|
+
// to using a 16 bit offset value.
|
|
27
|
+
class LookupType7 extends LookupType {
|
|
28
|
+
type = 7;
|
|
5
29
|
constructor(p) {
|
|
6
30
|
super(p);
|
|
7
|
-
this
|
|
31
|
+
// undo the coverageOffset parsing, because this subtable
|
|
32
|
+
// "isn't a table", it's just a pointer to another table.
|
|
33
|
+
undoCoverageOffsetParsing(this);
|
|
8
34
|
this.extensionLookupType = p.uint16;
|
|
9
|
-
this.extensionOffset = p.Offset32;
|
|
35
|
+
this.extensionOffset = p.Offset32; // from beginning of subtable
|
|
36
|
+
}
|
|
37
|
+
getSubstTable() {
|
|
38
|
+
if (this._lookup === undefined) {
|
|
39
|
+
const p = this.parser;
|
|
40
|
+
const type = this.extensionLookupType;
|
|
41
|
+
let LookupType = Lookups[type];
|
|
42
|
+
if (LookupType) {
|
|
43
|
+
p.currentPosition = this.start + this.extensionOffset;
|
|
44
|
+
this._lookup = new LookupType(p);
|
|
45
|
+
} else {
|
|
46
|
+
this._lookup = false;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return this._lookup;
|
|
10
51
|
}
|
|
11
52
|
}
|
|
12
53
|
|
|
@@ -50,7 +50,9 @@ class LookupTable extends ParsedData {
|
|
|
50
50
|
getSubTable(index) {
|
|
51
51
|
const builder = this.ctType === `GSUB` ? GSUBtables : GPOStables;
|
|
52
52
|
this.parser.currentPosition = this.start + this.subtableOffsets[index];
|
|
53
|
-
|
|
53
|
+
let subtable = builder.buildSubtable(this.lookupType, this.parser);
|
|
54
|
+
if (this.lookupType === 7) subtable = subtable.getSubstTable();
|
|
55
|
+
return subtable;
|
|
54
56
|
}
|
|
55
57
|
}
|
|
56
58
|
|
|
@@ -2,6 +2,12 @@ import { Parser } from "../../../parser.js";
|
|
|
2
2
|
import { SimpleTable } from "../simple-table.js";
|
|
3
3
|
import lazy from "../../../lazy.js";
|
|
4
4
|
|
|
5
|
+
const decoders = {
|
|
6
|
+
mac: new TextDecoder(`macintosh`),
|
|
7
|
+
shiftJIS: new TextDecoder(`shift-jis`),
|
|
8
|
+
big5: new TextDecoder(`big5`),
|
|
9
|
+
};
|
|
10
|
+
|
|
5
11
|
/**
|
|
6
12
|
* The OpenType `name` table.
|
|
7
13
|
*
|
|
@@ -38,7 +44,27 @@ class name extends SimpleTable {
|
|
|
38
44
|
*/
|
|
39
45
|
get(nameID) {
|
|
40
46
|
let record = this.nameRecords.find((record) => record.nameID === nameID);
|
|
41
|
-
if (record) return
|
|
47
|
+
if (!record) return;
|
|
48
|
+
|
|
49
|
+
const { platformID, encodingID, string } = record;
|
|
50
|
+
const bytes = new Uint8Array(
|
|
51
|
+
Array.from(string).map((s) => s.codePointAt(0))
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
if (platformID === 1) {
|
|
55
|
+
return decoders.mac.decode(bytes);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (platformID === 3) {
|
|
59
|
+
if (encodingID === 2) {
|
|
60
|
+
return decoders.shiftJIS.decode(bytes);
|
|
61
|
+
}
|
|
62
|
+
if (encodingID === 4) {
|
|
63
|
+
return decoders.big5.decode(bytes);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return string;
|
|
42
68
|
}
|
|
43
69
|
}
|
|
44
70
|
|