-
Notifications
You must be signed in to change notification settings - Fork 203
/
calt.js
65 lines (60 loc) · 1.42 KB
/
calt.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
const fs = require('fs')
const rules = [
'',
`
lookup 1 {
sub 1 by glyph;
} 1;`,
`
lookup 1_2 {
ignore sub 1 1' 2;
ignore sub 1' 2 2;
sub 1.spacer 2' by glyph;
sub 1' 2 by 1.spacer;
} 1_2;`,
`
lookup 1_2_3 {
ignore sub 1 1' 2 3;
ignore sub 1' 2 3 3;
sub 1.spacer 2.spacer 3' by glyph;
sub 1.spacer 2' 3 by 2.spacer;
sub 1' 2 3 by 1.spacer;
} 1_2_3;`,
`
lookup 1_2_3_4 {
ignore sub 1 1' 2 3 4;
ignore sub 1' 2 3 4 4;
sub 1.spacer 2.spacer 3.spacer 4' by glyph;
sub 1.spacer 2.spacer 3' 4 by 3.spacer;
sub 1.spacer 2' 3 4 by 2.spacer;
sub 1' 2 3 4 by 1.spacer;
} 1_2_3_4;`,
]
const gencalt = ligatures => {
let calt = 'feature calt {\n'
const ligs = {}
ligatures
.filter(l => !!l.name.match(/\.liga$/) || l.name !== l.glyph)
.map(l => l.glyph)
.sort((a, b) => {
const length = b.split('_').length - a.split('_').length
if (length !== 0) return length
return a < b ? -1 : 1
})
.forEach(g => {
g.split('.')
.slice(0, 1)
.forEach(l => {
if (ligs[l]) return
ligs[l] = true
const c = l.split('_')
let rule = rules[c.length]
rule = rule
.replace(/\d/g, m => c[parseInt(m) - 1])
.replace(/glyph/g, g)
calt += rule + '\n'
})
})
return calt + '\n} calt;\n'
}
exports.gencalt = gencalt