@cantoo/fontkit 2.0.4
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/LICENSE +21 -0
- package/README.md +274 -0
- package/dist/browser-module.mjs +13660 -0
- package/dist/browser-module.mjs.map +1 -0
- package/dist/browser.cjs +13689 -0
- package/dist/browser.cjs.map +1 -0
- package/dist/main.cjs +13712 -0
- package/dist/main.cjs.map +1 -0
- package/dist/module.mjs +13673 -0
- package/dist/module.mjs.map +1 -0
- package/package.json +99 -0
- package/src/CmapProcessor.js +285 -0
- package/src/DFont.js +113 -0
- package/src/TTFFont.js +621 -0
- package/src/TrueTypeCollection.js +65 -0
- package/src/WOFF2Font.js +222 -0
- package/src/WOFFFont.js +56 -0
- package/src/aat/AATFeatureMap.js +545 -0
- package/src/aat/AATLayoutEngine.js +48 -0
- package/src/aat/AATLookupTable.js +125 -0
- package/src/aat/AATMorxProcessor.js +429 -0
- package/src/aat/AATStateMachine.js +96 -0
- package/src/base.js +29 -0
- package/src/cff/CFFCharsets.js +99 -0
- package/src/cff/CFFDict.js +166 -0
- package/src/cff/CFFEncodings.js +48 -0
- package/src/cff/CFFFont.js +158 -0
- package/src/cff/CFFIndex.js +150 -0
- package/src/cff/CFFOperand.js +135 -0
- package/src/cff/CFFPointer.js +50 -0
- package/src/cff/CFFPrivateDict.js +39 -0
- package/src/cff/CFFStandardStrings.js +71 -0
- package/src/cff/CFFTop.js +236 -0
- package/src/decorators.js +36 -0
- package/src/encodings.js +219 -0
- package/src/fs.js +12 -0
- package/src/glyph/BBox.js +72 -0
- package/src/glyph/CBDTGlyph.js +9 -0
- package/src/glyph/CFFGlyph.js +635 -0
- package/src/glyph/COLRGlyph.js +108 -0
- package/src/glyph/Glyph.js +270 -0
- package/src/glyph/GlyphVariationProcessor.js +487 -0
- package/src/glyph/Path.js +257 -0
- package/src/glyph/SBIXGlyph.js +54 -0
- package/src/glyph/StandardNames.js +27 -0
- package/src/glyph/TTFGlyph.js +408 -0
- package/src/glyph/TTFGlyphEncoder.js +158 -0
- package/src/glyph/WOFF2Glyph.js +70 -0
- package/src/index.js +15 -0
- package/src/layout/GlyphPosition.js +30 -0
- package/src/layout/GlyphRun.js +108 -0
- package/src/layout/KernProcessor.js +97 -0
- package/src/layout/LayoutEngine.js +190 -0
- package/src/layout/Script.js +231 -0
- package/src/layout/UnicodeLayoutEngine.js +250 -0
- package/src/node.js +16 -0
- package/src/opentype/GPOSProcessor.js +311 -0
- package/src/opentype/GSUBProcessor.js +208 -0
- package/src/opentype/GlyphInfo.js +57 -0
- package/src/opentype/GlyphIterator.js +82 -0
- package/src/opentype/OTLayoutEngine.js +117 -0
- package/src/opentype/OTProcessor.js +472 -0
- package/src/opentype/ShapingPlan.js +121 -0
- package/src/opentype/shapers/ArabicShaper.js +124 -0
- package/src/opentype/shapers/DefaultShaper.js +116 -0
- package/src/opentype/shapers/HangulShaper.js +285 -0
- package/src/opentype/shapers/HebrewShaper.js +105 -0
- package/src/opentype/shapers/IndicShaper.js +914 -0
- package/src/opentype/shapers/ThaiShaper.js +238 -0
- package/src/opentype/shapers/UniversalShaper.js +186 -0
- package/src/opentype/shapers/data.trie +0 -0
- package/src/opentype/shapers/gen-indic.js +208 -0
- package/src/opentype/shapers/gen-use.js +287 -0
- package/src/opentype/shapers/generate-data.js +33 -0
- package/src/opentype/shapers/index.js +109 -0
- package/src/opentype/shapers/indic-data.js +175 -0
- package/src/opentype/shapers/indic.json +1 -0
- package/src/opentype/shapers/indic.machine +31 -0
- package/src/opentype/shapers/indic.trie +0 -0
- package/src/opentype/shapers/use.json +1 -0
- package/src/opentype/shapers/use.machine +44 -0
- package/src/opentype/shapers/use.trie +0 -0
- package/src/packages/unicode-properties/LICENSE +8 -0
- package/src/packages/unicode-properties/README.md +12 -0
- package/src/packages/unicode-properties/data-trie.js +1 -0
- package/src/packages/unicode-properties/data.js +1 -0
- package/src/packages/unicode-properties/data.json +1 -0
- package/src/packages/unicode-properties/data.trie +0 -0
- package/src/packages/unicode-properties/dist/index.cjs +257 -0
- package/src/packages/unicode-properties/dist/index.cjs.map +7 -0
- package/src/packages/unicode-properties/dist/index.mjs +234 -0
- package/src/packages/unicode-properties/dist/index.mjs.map +7 -0
- package/src/packages/unicode-properties/generate.js +107 -0
- package/src/packages/unicode-properties/index.js +184 -0
- package/src/packages/unicode-properties/package.json +50 -0
- package/src/packages/unicode-trie/LICENSE +8 -0
- package/src/packages/unicode-trie/README.md +13 -0
- package/src/packages/unicode-trie/builder.js +965 -0
- package/src/packages/unicode-trie/dist/builder.cjs +711 -0
- package/src/packages/unicode-trie/dist/builder.cjs.map +7 -0
- package/src/packages/unicode-trie/dist/builder.mjs +690 -0
- package/src/packages/unicode-trie/dist/builder.mjs.map +7 -0
- package/src/packages/unicode-trie/dist/index.cjs +112 -0
- package/src/packages/unicode-trie/dist/index.cjs.map +7 -0
- package/src/packages/unicode-trie/dist/index.mjs +91 -0
- package/src/packages/unicode-trie/dist/index.mjs.map +7 -0
- package/src/packages/unicode-trie/index.js +135 -0
- package/src/packages/unicode-trie/package.json +49 -0
- package/src/packages/unicode-trie/swap.js +21 -0
- package/src/subset/CFFSubset.js +176 -0
- package/src/subset/Subset.js +63 -0
- package/src/subset/TTFSubset.js +130 -0
- package/src/tables/BASE.js +78 -0
- package/src/tables/COLR.js +25 -0
- package/src/tables/CPAL.js +24 -0
- package/src/tables/DSIG.js +21 -0
- package/src/tables/EBDT.js +91 -0
- package/src/tables/EBLC.js +80 -0
- package/src/tables/GDEF.js +57 -0
- package/src/tables/GPOS.js +209 -0
- package/src/tables/GSUB.js +85 -0
- package/src/tables/HVAR.js +44 -0
- package/src/tables/JSTF.js +43 -0
- package/src/tables/LTSH.js +10 -0
- package/src/tables/OS2.js +84 -0
- package/src/tables/PCLT.js +21 -0
- package/src/tables/STAT.js +99 -0
- package/src/tables/VDMX.js +33 -0
- package/src/tables/VORG.js +14 -0
- package/src/tables/WOFF2Directory.js +73 -0
- package/src/tables/WOFFDirectory.js +37 -0
- package/src/tables/aat.js +157 -0
- package/src/tables/avar.js +19 -0
- package/src/tables/bsln.js +31 -0
- package/src/tables/cmap.js +127 -0
- package/src/tables/cvt.js +6 -0
- package/src/tables/directory.js +58 -0
- package/src/tables/feat.js +28 -0
- package/src/tables/fpgm.js +8 -0
- package/src/tables/fvar.js +31 -0
- package/src/tables/gasp.js +15 -0
- package/src/tables/glyf.js +4 -0
- package/src/tables/gvar.js +27 -0
- package/src/tables/hdmx.js +15 -0
- package/src/tables/head.js +25 -0
- package/src/tables/hhea.js +19 -0
- package/src/tables/hmtx.js +11 -0
- package/src/tables/index.js +119 -0
- package/src/tables/just.js +81 -0
- package/src/tables/kern.js +91 -0
- package/src/tables/loca.js +30 -0
- package/src/tables/maxp.js +20 -0
- package/src/tables/morx.js +79 -0
- package/src/tables/name.js +157 -0
- package/src/tables/opbd.js +15 -0
- package/src/tables/opentype.js +217 -0
- package/src/tables/post.js +34 -0
- package/src/tables/prep.js +6 -0
- package/src/tables/sbix.js +17 -0
- package/src/tables/variations.js +80 -0
- package/src/tables/vhea.js +19 -0
- package/src/tables/vmtx.js +12 -0
- package/src/utils.js +62 -0
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
import codepoints from 'codepoints';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import UnicodeTrieBuilder from '../../packages/unicode-trie/builder.js';
|
|
4
|
+
import dfa from 'dfa/compile.js';
|
|
5
|
+
|
|
6
|
+
const compile = dfa.default;
|
|
7
|
+
|
|
8
|
+
const CATEGORIES = {
|
|
9
|
+
B: [
|
|
10
|
+
{UISC: 'Number'},
|
|
11
|
+
{UISC: 'Avagraha', UGC: 'Lo'},
|
|
12
|
+
{UISC: 'Bindu', UGC: 'Lo'},
|
|
13
|
+
{UISC: 'Consonant'},
|
|
14
|
+
{UISC: 'Consonant_Final', UGC: 'Lo'},
|
|
15
|
+
{UISC: 'Consonant_Head_Letter'},
|
|
16
|
+
{UISC: 'Consonant_Medial', UGC: 'Lo'},
|
|
17
|
+
{UISC: 'Consonant_Subjoined', UGC: 'Lo'},
|
|
18
|
+
{UISC: 'Tone_Letter'},
|
|
19
|
+
{UISC: 'Vowel', UGC: 'Lo'},
|
|
20
|
+
{UISC: 'Vowel_Independent'},
|
|
21
|
+
{UISC: 'Vowel_Dependent', UGC: 'Lo'}
|
|
22
|
+
],
|
|
23
|
+
CGJ: [0x034f],
|
|
24
|
+
CM: [
|
|
25
|
+
'Nukta',
|
|
26
|
+
'Gemination_Mark',
|
|
27
|
+
'Consonant_Killer'
|
|
28
|
+
],
|
|
29
|
+
CS: [
|
|
30
|
+
'Consonant_With_Stacker'
|
|
31
|
+
],
|
|
32
|
+
F: [
|
|
33
|
+
{UISC: 'Consonant_Final', UGC: {not: 'Lo'}},
|
|
34
|
+
{UISC: 'Consonant_Succeeding_Repha'}
|
|
35
|
+
],
|
|
36
|
+
FM: [
|
|
37
|
+
'Syllable_Modifier'
|
|
38
|
+
],
|
|
39
|
+
GB: [
|
|
40
|
+
'Consonant_Placeholder',
|
|
41
|
+
0x2015,
|
|
42
|
+
0x2022,
|
|
43
|
+
0x25fb,
|
|
44
|
+
0x25fc,
|
|
45
|
+
0x25fd,
|
|
46
|
+
0x25fe
|
|
47
|
+
],
|
|
48
|
+
H: [
|
|
49
|
+
'Virama',
|
|
50
|
+
'Invisible_Stacker'
|
|
51
|
+
],
|
|
52
|
+
HN: [
|
|
53
|
+
'Number_Joiner'
|
|
54
|
+
],
|
|
55
|
+
IND: [
|
|
56
|
+
'Consonant_Dead',
|
|
57
|
+
'Modifying_Letter',
|
|
58
|
+
{UGC: 'Po', U: {not: [0x104e, 0x2022]}}
|
|
59
|
+
],
|
|
60
|
+
M: [
|
|
61
|
+
{UISC: 'Consonant_Medial', UGC: {not: 'Lo'}}
|
|
62
|
+
],
|
|
63
|
+
N: [
|
|
64
|
+
'Brahmi_Joining_Number'
|
|
65
|
+
],
|
|
66
|
+
R: [
|
|
67
|
+
'Consonant_Preceding_Repha',
|
|
68
|
+
'Consonant_Prefixed'
|
|
69
|
+
],
|
|
70
|
+
Rsv: [
|
|
71
|
+
{UGC: 'Cn'} // TODO
|
|
72
|
+
],
|
|
73
|
+
S: [
|
|
74
|
+
{UGC: 'So', U: {not: 0x25cc}},
|
|
75
|
+
{UGC: 'Sc'}
|
|
76
|
+
],
|
|
77
|
+
SM: [
|
|
78
|
+
0x1b6b,
|
|
79
|
+
0x1b6c,
|
|
80
|
+
0x1b6d,
|
|
81
|
+
0x1b6e,
|
|
82
|
+
0x1b6f,
|
|
83
|
+
0x1b70,
|
|
84
|
+
0x1b71,
|
|
85
|
+
0x1b72,
|
|
86
|
+
0x1b73
|
|
87
|
+
],
|
|
88
|
+
SUB: [
|
|
89
|
+
{UISC: 'Consonant_Subjoined', UGC: {not: 'Lo'}}
|
|
90
|
+
],
|
|
91
|
+
V: [
|
|
92
|
+
{UISC: 'Vowel', UGC: {not: 'Lo'}},
|
|
93
|
+
{UISC: 'Vowel_Dependent', UGC: {not: 'Lo'}},
|
|
94
|
+
{UISC: 'Pure_Killer'}
|
|
95
|
+
],
|
|
96
|
+
VM: [
|
|
97
|
+
{UISC: 'Bindu', UGC: {not: 'Lo'}},
|
|
98
|
+
'Tone_Mark',
|
|
99
|
+
'Cantillation_Mark',
|
|
100
|
+
'Register_Shifter',
|
|
101
|
+
'Visarga'
|
|
102
|
+
],
|
|
103
|
+
VS: [
|
|
104
|
+
0xfe00, 0xfe01, 0xfe02, 0xfe03, 0xfe04, 0xfe05, 0xfe06, 0xfe07,
|
|
105
|
+
0xfe08, 0xfe09, 0xfe0a, 0xfe0b, 0xfe0c, 0xfe0d, 0xfe0e, 0xfe0f
|
|
106
|
+
],
|
|
107
|
+
WJ: [0x2060],
|
|
108
|
+
ZWJ: [
|
|
109
|
+
'Joiner'
|
|
110
|
+
],
|
|
111
|
+
ZWNJ: [
|
|
112
|
+
'Non_Joiner'
|
|
113
|
+
],
|
|
114
|
+
O: [
|
|
115
|
+
'Other'
|
|
116
|
+
]
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
const USE_POSITIONS = {
|
|
120
|
+
F: {
|
|
121
|
+
Abv: ['Top'],
|
|
122
|
+
Blw: ['Bottom'],
|
|
123
|
+
Pst: ['Right'],
|
|
124
|
+
},
|
|
125
|
+
M: {
|
|
126
|
+
Abv: ['Top'],
|
|
127
|
+
Blw: ['Bottom'],
|
|
128
|
+
Pst: ['Right'],
|
|
129
|
+
Pre: ['Left'],
|
|
130
|
+
},
|
|
131
|
+
CM: {
|
|
132
|
+
Abv: ['Top'],
|
|
133
|
+
Blw: ['Bottom'],
|
|
134
|
+
},
|
|
135
|
+
V: {
|
|
136
|
+
Abv: ['Top', 'Top_And_Bottom', 'Top_And_Bottom_And_Right', 'Top_And_Right'],
|
|
137
|
+
Blw: ['Bottom', 'Overstruck', 'Bottom_And_Right'],
|
|
138
|
+
Pst: ['Right'],
|
|
139
|
+
Pre: ['Left', 'Top_And_Left', 'Top_And_Left_And_Right', 'Left_And_Right'],
|
|
140
|
+
},
|
|
141
|
+
VM: {
|
|
142
|
+
Abv: ['Top'],
|
|
143
|
+
Blw: ['Bottom', 'Overstruck'],
|
|
144
|
+
Pst: ['Right'],
|
|
145
|
+
Pre: ['Left'],
|
|
146
|
+
},
|
|
147
|
+
SM: {
|
|
148
|
+
Abv: ['Top'],
|
|
149
|
+
Blw: ['Bottom'],
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
const UISC_OVERRIDE = {
|
|
154
|
+
0x17dd: 'Vowel_Dependent',
|
|
155
|
+
0x1ce2: 'Cantillation_Mark',
|
|
156
|
+
0x1ce3: 'Cantillation_Mark',
|
|
157
|
+
0x1ce4: 'Cantillation_Mark',
|
|
158
|
+
0x1ce5: 'Cantillation_Mark',
|
|
159
|
+
0x1ce6: 'Cantillation_Mark',
|
|
160
|
+
0x1ce7: 'Cantillation_Mark',
|
|
161
|
+
0x1ce8: 'Cantillation_Mark',
|
|
162
|
+
0x1ced: 'Tone_Mark'
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
const UIPC_OVERRIDE = {
|
|
166
|
+
0x1b6c: 'Bottom',
|
|
167
|
+
0x953: 'Not_Applicable',
|
|
168
|
+
0x954: 'Not_Applicable',
|
|
169
|
+
0x103c: 'Left',
|
|
170
|
+
0xa926: 'Top',
|
|
171
|
+
0xa927: 'Top',
|
|
172
|
+
0xa928: 'Top',
|
|
173
|
+
0xa929: 'Top',
|
|
174
|
+
0xa92a: 'Top',
|
|
175
|
+
0x111ca: 'Bottom',
|
|
176
|
+
0x11300: 'Top',
|
|
177
|
+
0x1133c: 'Bottom',
|
|
178
|
+
0x1171e: 'Left',
|
|
179
|
+
0x1cf2: 'Right',
|
|
180
|
+
0x1cf3: 'Right',
|
|
181
|
+
0x1cf8: 'Top',
|
|
182
|
+
0x1cf9: 'Top'
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
function check(pattern, value) {
|
|
186
|
+
if (typeof pattern === 'object' && pattern.not) {
|
|
187
|
+
if (Array.isArray(pattern.not)) {
|
|
188
|
+
return pattern.not.indexOf(value) === -1;
|
|
189
|
+
} else {
|
|
190
|
+
return value !== pattern.not;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
return value === pattern;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
function matches(pattern, code) {
|
|
198
|
+
if (typeof pattern === 'number') {
|
|
199
|
+
pattern = {U: pattern};
|
|
200
|
+
} else if (typeof pattern === 'string') {
|
|
201
|
+
pattern = {UISC: pattern};
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
for (let key in pattern) {
|
|
205
|
+
if (!check(pattern[key], code[key])) {
|
|
206
|
+
return false;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
return true;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
function getUISC(code) {
|
|
214
|
+
return UISC_OVERRIDE[code.code] || code.indicSyllabicCategory || 'Other';
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
function getUIPC(code) {
|
|
218
|
+
return UIPC_OVERRIDE[code.code] || code.indicPositionalCategory;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
function getPositionalCategory(code, USE) {
|
|
222
|
+
let UIPC = getUIPC(code);
|
|
223
|
+
let pos = USE_POSITIONS[USE];
|
|
224
|
+
if (pos) {
|
|
225
|
+
for (let key in pos) {
|
|
226
|
+
if (pos[key].indexOf(UIPC) !== -1) {
|
|
227
|
+
return USE + key;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
return USE;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
function getCategory(code) {
|
|
236
|
+
for (let category in CATEGORIES) {
|
|
237
|
+
for (let pattern of CATEGORIES[category]) {
|
|
238
|
+
if (matches(pattern, {UISC: getUISC(code), UGC: code.category, U: code.code})) {
|
|
239
|
+
return getPositionalCategory(code, category);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
return null;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
let trie = new UnicodeTrieBuilder;
|
|
248
|
+
let symbols = {};
|
|
249
|
+
let numSymbols = 0;
|
|
250
|
+
let decompositions = {};
|
|
251
|
+
for (let i = 0; i < codepoints.length; i++) {
|
|
252
|
+
let codepoint = codepoints[i];
|
|
253
|
+
if (codepoint) {
|
|
254
|
+
let category = getCategory(codepoint);
|
|
255
|
+
if (!(category in symbols)) {
|
|
256
|
+
symbols[category] = numSymbols++;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
trie.set(codepoint.code, symbols[category]);
|
|
260
|
+
|
|
261
|
+
if (codepoint.indicSyllabicCategory === 'Vowel_Dependent' && codepoint.decomposition.length > 0) {
|
|
262
|
+
decompositions[codepoint.code] = decompose(codepoint.code);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
function decompose(code) {
|
|
268
|
+
let decomposition = [];
|
|
269
|
+
let codepoint = codepoints[code];
|
|
270
|
+
for (let c of codepoint.decomposition) {
|
|
271
|
+
let codes = decompose(c);
|
|
272
|
+
codes = codes.length > 0 ? codes : [c];
|
|
273
|
+
decomposition.push(...codes);
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
return decomposition;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
fs.writeFileSync(new URL('use.trie', import.meta.url), trie.toBuffer());
|
|
280
|
+
|
|
281
|
+
let stateMachine = compile(fs.readFileSync(new URL('use.machine', import.meta.url), 'utf8'), symbols);
|
|
282
|
+
let json = Object.assign({
|
|
283
|
+
categories: Object.keys(symbols),
|
|
284
|
+
decompositions: decompositions
|
|
285
|
+
}, stateMachine);
|
|
286
|
+
|
|
287
|
+
fs.writeFileSync(new URL('use.json', import.meta.url), JSON.stringify(json));
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
//
|
|
2
|
+
// This script generates a UnicodeTrie containing shaping data derived
|
|
3
|
+
// from Unicode properties (currently just for the Arabic shaper).
|
|
4
|
+
//
|
|
5
|
+
import codepoints from 'codepoints';
|
|
6
|
+
import fs from 'fs';
|
|
7
|
+
import UnicodeTrieBuilder from '../../packages/unicode-trie/builder.js';
|
|
8
|
+
|
|
9
|
+
let ShapingClasses = {
|
|
10
|
+
Non_Joining: 0,
|
|
11
|
+
Left_Joining: 1,
|
|
12
|
+
Right_Joining: 2,
|
|
13
|
+
Dual_Joining: 3,
|
|
14
|
+
Join_Causing: 3,
|
|
15
|
+
ALAPH: 4,
|
|
16
|
+
'DALATH RISH': 5,
|
|
17
|
+
Transparent: 6
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
let trie = new UnicodeTrieBuilder;
|
|
21
|
+
for (let i = 0; i < codepoints.length; i++) {
|
|
22
|
+
let codepoint = codepoints[i];
|
|
23
|
+
if (codepoint) {
|
|
24
|
+
if (codepoint.joiningGroup === 'ALAPH' || codepoint.joiningGroup === 'DALATH RISH') {
|
|
25
|
+
trie.set(codepoint.code, ShapingClasses[codepoint.joiningGroup] + 1);
|
|
26
|
+
|
|
27
|
+
} else if (codepoint.joiningType) {
|
|
28
|
+
trie.set(codepoint.code, ShapingClasses[codepoint.joiningType] + 1);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
fs.writeFileSync(new URL('data.trie', import.meta.url), trie.toBuffer());
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import DefaultShaper from './DefaultShaper';
|
|
2
|
+
import ArabicShaper from './ArabicShaper';
|
|
3
|
+
import HangulShaper from './HangulShaper';
|
|
4
|
+
import HebrewShaper from './HebrewShaper';
|
|
5
|
+
import IndicShaper from './IndicShaper';
|
|
6
|
+
import ThaiShaper from './ThaiShaper';
|
|
7
|
+
import UniversalShaper from './UniversalShaper';
|
|
8
|
+
|
|
9
|
+
const SHAPERS = {
|
|
10
|
+
arab: ArabicShaper, // Arabic
|
|
11
|
+
mong: ArabicShaper, // Mongolian
|
|
12
|
+
syrc: ArabicShaper, // Syriac
|
|
13
|
+
'nko ': ArabicShaper, // N'Ko
|
|
14
|
+
phag: ArabicShaper, // Phags Pa
|
|
15
|
+
mand: ArabicShaper, // Mandaic
|
|
16
|
+
mani: ArabicShaper, // Manichaean
|
|
17
|
+
phlp: ArabicShaper, // Psalter Pahlavi
|
|
18
|
+
|
|
19
|
+
hang: HangulShaper, // Hangul
|
|
20
|
+
|
|
21
|
+
hebr: HebrewShaper, // Hebrew
|
|
22
|
+
|
|
23
|
+
bng2: IndicShaper, // Bengali
|
|
24
|
+
beng: IndicShaper, // Bengali
|
|
25
|
+
dev2: IndicShaper, // Devanagari
|
|
26
|
+
deva: IndicShaper, // Devanagari
|
|
27
|
+
gjr2: IndicShaper, // Gujarati
|
|
28
|
+
gujr: IndicShaper, // Gujarati
|
|
29
|
+
guru: IndicShaper, // Gurmukhi
|
|
30
|
+
gur2: IndicShaper, // Gurmukhi
|
|
31
|
+
knda: IndicShaper, // Kannada
|
|
32
|
+
knd2: IndicShaper, // Kannada
|
|
33
|
+
mlm2: IndicShaper, // Malayalam
|
|
34
|
+
mlym: IndicShaper, // Malayalam
|
|
35
|
+
ory2: IndicShaper, // Oriya
|
|
36
|
+
orya: IndicShaper, // Oriya
|
|
37
|
+
taml: IndicShaper, // Tamil
|
|
38
|
+
tml2: IndicShaper, // Tamil
|
|
39
|
+
telu: IndicShaper, // Telugu
|
|
40
|
+
tel2: IndicShaper, // Telugu
|
|
41
|
+
khmr: IndicShaper, // Khmer
|
|
42
|
+
|
|
43
|
+
thai: ThaiShaper, // Thai
|
|
44
|
+
'lao ': ThaiShaper, // Lao (4-char OT tag with trailing space)
|
|
45
|
+
|
|
46
|
+
bali: UniversalShaper, // Balinese
|
|
47
|
+
batk: UniversalShaper, // Batak
|
|
48
|
+
brah: UniversalShaper, // Brahmi
|
|
49
|
+
bugi: UniversalShaper, // Buginese
|
|
50
|
+
buhd: UniversalShaper, // Buhid
|
|
51
|
+
cakm: UniversalShaper, // Chakma
|
|
52
|
+
cham: UniversalShaper, // Cham
|
|
53
|
+
dupl: UniversalShaper, // Duployan
|
|
54
|
+
egyp: UniversalShaper, // Egyptian Hieroglyphs
|
|
55
|
+
gran: UniversalShaper, // Grantha
|
|
56
|
+
hano: UniversalShaper, // Hanunoo
|
|
57
|
+
java: UniversalShaper, // Javanese
|
|
58
|
+
kthi: UniversalShaper, // Kaithi
|
|
59
|
+
kali: UniversalShaper, // Kayah Li
|
|
60
|
+
khar: UniversalShaper, // Kharoshthi
|
|
61
|
+
khoj: UniversalShaper, // Khojki
|
|
62
|
+
sind: UniversalShaper, // Khudawadi
|
|
63
|
+
lepc: UniversalShaper, // Lepcha
|
|
64
|
+
limb: UniversalShaper, // Limbu
|
|
65
|
+
mahj: UniversalShaper, // Mahajani
|
|
66
|
+
// mand: UniversalShaper, // Mandaic
|
|
67
|
+
// mani: UniversalShaper, // Manichaean
|
|
68
|
+
mtei: UniversalShaper, // Meitei Mayek
|
|
69
|
+
modi: UniversalShaper, // Modi
|
|
70
|
+
// mong: UniversalShaper, // Mongolian
|
|
71
|
+
// 'nko ': UniversalShaper, // N’Ko
|
|
72
|
+
hmng: UniversalShaper, // Pahawh Hmong
|
|
73
|
+
// phag: UniversalShaper, // Phags-pa
|
|
74
|
+
// phlp: UniversalShaper, // Psalter Pahlavi
|
|
75
|
+
rjng: UniversalShaper, // Rejang
|
|
76
|
+
saur: UniversalShaper, // Saurashtra
|
|
77
|
+
shrd: UniversalShaper, // Sharada
|
|
78
|
+
sidd: UniversalShaper, // Siddham
|
|
79
|
+
sinh: IndicShaper, // Sinhala
|
|
80
|
+
sund: UniversalShaper, // Sundanese
|
|
81
|
+
sylo: UniversalShaper, // Syloti Nagri
|
|
82
|
+
tglg: UniversalShaper, // Tagalog
|
|
83
|
+
tagb: UniversalShaper, // Tagbanwa
|
|
84
|
+
tale: UniversalShaper, // Tai Le
|
|
85
|
+
lana: UniversalShaper, // Tai Tham
|
|
86
|
+
tavt: UniversalShaper, // Tai Viet
|
|
87
|
+
takr: UniversalShaper, // Takri
|
|
88
|
+
tibt: UniversalShaper, // Tibetan
|
|
89
|
+
tfng: UniversalShaper, // Tifinagh
|
|
90
|
+
tirh: UniversalShaper, // Tirhuta
|
|
91
|
+
|
|
92
|
+
latn: DefaultShaper, // Latin
|
|
93
|
+
DFLT: DefaultShaper // Default
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
export function choose(script) {
|
|
97
|
+
if (!Array.isArray(script)) {
|
|
98
|
+
script = [script];
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
for (let s of script) {
|
|
102
|
+
let shaper = SHAPERS[s];
|
|
103
|
+
if (shaper) {
|
|
104
|
+
return shaper;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
return DefaultShaper;
|
|
109
|
+
}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
// Cateories used in the OpenType spec:
|
|
2
|
+
// https://www.microsoft.com/typography/otfntdev/devanot/shaping.aspx
|
|
3
|
+
export const CATEGORIES = {
|
|
4
|
+
X: 1 << 0,
|
|
5
|
+
C: 1 << 1,
|
|
6
|
+
V: 1 << 2,
|
|
7
|
+
N: 1 << 3,
|
|
8
|
+
H: 1 << 4,
|
|
9
|
+
ZWNJ: 1 << 5,
|
|
10
|
+
ZWJ: 1 << 6,
|
|
11
|
+
M: 1 << 7,
|
|
12
|
+
SM: 1 << 8,
|
|
13
|
+
VD: 1 << 9,
|
|
14
|
+
A: 1 << 10,
|
|
15
|
+
Placeholder: 1 << 11,
|
|
16
|
+
Dotted_Circle: 1 << 12,
|
|
17
|
+
RS: 1 << 13, // Register Shifter, used in Khmer OT spec.
|
|
18
|
+
Coeng: 1 << 14, // Khmer-style Virama.
|
|
19
|
+
Repha: 1 << 15, // Atomically-encoded logical or visual repha.
|
|
20
|
+
Ra: 1 << 16,
|
|
21
|
+
CM: 1 << 17, // Consonant-Medial.
|
|
22
|
+
Symbol: 1 << 18 // Avagraha, etc that take marks (SM,A,VD).
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
// Visual positions in a syllable from left to right.
|
|
26
|
+
export const POSITIONS = {
|
|
27
|
+
Start: 1 << 0,
|
|
28
|
+
|
|
29
|
+
Ra_To_Become_Reph: 1 << 1,
|
|
30
|
+
Pre_M: 1 << 2,
|
|
31
|
+
Pre_C: 1 << 3,
|
|
32
|
+
|
|
33
|
+
Base_C: 1 << 4,
|
|
34
|
+
After_Main: 1 << 5,
|
|
35
|
+
|
|
36
|
+
Above_C: 1 << 6,
|
|
37
|
+
|
|
38
|
+
Before_Sub: 1 << 7,
|
|
39
|
+
Below_C: 1 << 8,
|
|
40
|
+
After_Sub: 1 << 9,
|
|
41
|
+
|
|
42
|
+
Before_Post: 1 << 10,
|
|
43
|
+
Post_C: 1 << 11,
|
|
44
|
+
After_Post: 1 << 12,
|
|
45
|
+
|
|
46
|
+
Final_C: 1 << 13,
|
|
47
|
+
SMVD: 1 << 14,
|
|
48
|
+
|
|
49
|
+
End: 1 << 15
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export const CONSONANT_FLAGS = CATEGORIES.C | CATEGORIES.Ra | CATEGORIES.CM | CATEGORIES.V | CATEGORIES.Placeholder | CATEGORIES.Dotted_Circle;
|
|
53
|
+
export const JOINER_FLAGS = CATEGORIES.ZWJ | CATEGORIES.ZWNJ;
|
|
54
|
+
export const HALANT_OR_COENG_FLAGS = CATEGORIES.H | CATEGORIES.Coeng;
|
|
55
|
+
|
|
56
|
+
export const INDIC_CONFIGS = {
|
|
57
|
+
Default: {
|
|
58
|
+
hasOldSpec: false,
|
|
59
|
+
virama: 0,
|
|
60
|
+
basePos: 'Last',
|
|
61
|
+
rephPos: POSITIONS.Before_Post,
|
|
62
|
+
rephMode: 'Implicit',
|
|
63
|
+
blwfMode: 'Pre_And_Post'
|
|
64
|
+
},
|
|
65
|
+
|
|
66
|
+
Devanagari: {
|
|
67
|
+
hasOldSpec: true,
|
|
68
|
+
virama: 0x094D,
|
|
69
|
+
basePos: 'Last',
|
|
70
|
+
rephPos: POSITIONS.Before_Post,
|
|
71
|
+
rephMode: 'Implicit',
|
|
72
|
+
blwfMode: 'Pre_And_Post'
|
|
73
|
+
},
|
|
74
|
+
|
|
75
|
+
Bengali: {
|
|
76
|
+
hasOldSpec: true,
|
|
77
|
+
virama: 0x09CD,
|
|
78
|
+
basePos: 'Last',
|
|
79
|
+
rephPos: POSITIONS.After_Sub,
|
|
80
|
+
rephMode: 'Implicit',
|
|
81
|
+
blwfMode: 'Pre_And_Post'
|
|
82
|
+
},
|
|
83
|
+
|
|
84
|
+
Gurmukhi: {
|
|
85
|
+
hasOldSpec: true,
|
|
86
|
+
virama: 0x0A4D,
|
|
87
|
+
basePos: 'Last',
|
|
88
|
+
rephPos: POSITIONS.Before_Sub,
|
|
89
|
+
rephMode: 'Implicit',
|
|
90
|
+
blwfMode: 'Pre_And_Post'
|
|
91
|
+
},
|
|
92
|
+
|
|
93
|
+
Gujarati: {
|
|
94
|
+
hasOldSpec: true,
|
|
95
|
+
virama: 0x0ACD,
|
|
96
|
+
basePos: 'Last',
|
|
97
|
+
rephPos: POSITIONS.Before_Post,
|
|
98
|
+
rephMode: 'Implicit',
|
|
99
|
+
blwfMode: 'Pre_And_Post'
|
|
100
|
+
},
|
|
101
|
+
|
|
102
|
+
Oriya: {
|
|
103
|
+
hasOldSpec: true,
|
|
104
|
+
virama: 0x0B4D,
|
|
105
|
+
basePos: 'Last',
|
|
106
|
+
rephPos: POSITIONS.After_Main,
|
|
107
|
+
rephMode: 'Implicit',
|
|
108
|
+
blwfMode: 'Pre_And_Post'
|
|
109
|
+
},
|
|
110
|
+
|
|
111
|
+
Tamil: {
|
|
112
|
+
hasOldSpec: true,
|
|
113
|
+
virama: 0x0BCD,
|
|
114
|
+
basePos: 'Last',
|
|
115
|
+
rephPos: POSITIONS.After_Post,
|
|
116
|
+
rephMode: 'Implicit',
|
|
117
|
+
blwfMode: 'Pre_And_Post'
|
|
118
|
+
},
|
|
119
|
+
|
|
120
|
+
Telugu: {
|
|
121
|
+
hasOldSpec: true,
|
|
122
|
+
virama: 0x0C4D,
|
|
123
|
+
basePos: 'Last',
|
|
124
|
+
rephPos: POSITIONS.After_Post,
|
|
125
|
+
rephMode: 'Explicit',
|
|
126
|
+
blwfMode: 'Post_Only'
|
|
127
|
+
},
|
|
128
|
+
|
|
129
|
+
Kannada: {
|
|
130
|
+
hasOldSpec: true,
|
|
131
|
+
virama: 0x0CCD,
|
|
132
|
+
basePos: 'Last',
|
|
133
|
+
rephPos: POSITIONS.After_Post,
|
|
134
|
+
rephMode: 'Implicit',
|
|
135
|
+
blwfMode: 'Post_Only'
|
|
136
|
+
},
|
|
137
|
+
|
|
138
|
+
Malayalam: {
|
|
139
|
+
hasOldSpec: true,
|
|
140
|
+
virama: 0x0D4D,
|
|
141
|
+
basePos: 'Last',
|
|
142
|
+
rephPos: POSITIONS.After_Main,
|
|
143
|
+
rephMode: 'Log_Repha',
|
|
144
|
+
blwfMode: 'Pre_And_Post'
|
|
145
|
+
},
|
|
146
|
+
|
|
147
|
+
// Handled by UniversalShaper
|
|
148
|
+
// Sinhala: {
|
|
149
|
+
// hasOldSpec: false,
|
|
150
|
+
// virama: 0x0DCA,
|
|
151
|
+
// basePos: 'Last_Sinhala',
|
|
152
|
+
// rephPos: POSITIONS.After_Main,
|
|
153
|
+
// rephMode: 'Explicit',
|
|
154
|
+
// blwfMode: 'Pre_And_Post'
|
|
155
|
+
// },
|
|
156
|
+
|
|
157
|
+
Khmer: {
|
|
158
|
+
hasOldSpec: false,
|
|
159
|
+
virama: 0x17D2,
|
|
160
|
+
basePos: 'First',
|
|
161
|
+
rephPos: POSITIONS.Ra_To_Become_Reph,
|
|
162
|
+
rephMode: 'Vis_Repha',
|
|
163
|
+
blwfMode: 'Pre_And_Post'
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
// Additional decompositions that aren't in Unicode
|
|
168
|
+
export const INDIC_DECOMPOSITIONS = {
|
|
169
|
+
// Khmer
|
|
170
|
+
0x17BE: [0x17C1, 0x17BE],
|
|
171
|
+
0x17BF: [0x17C1, 0x17BF],
|
|
172
|
+
0x17C0: [0x17C1, 0x17C0],
|
|
173
|
+
0x17C4: [0x17C1, 0x17C4],
|
|
174
|
+
0x17C5: [0x17C1, 0x17C5]
|
|
175
|
+
};
|