-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfontise
executable file
·62 lines (54 loc) · 1.95 KB
/
fontise
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
#!/usr/bin/env node
'use strict';
const fs = require('fs');
const path = require('path');
const cp = require('child_process');
const setup = [
{ height: 63, blockWidth: 9, chars: "0123456789:! " },
{ height: 56, blockWidth: 8, chars: "0123456789:! " },
{ height: 49, blockWidth: 7, chars: "0123456789:! " },
{ height: 42, blockWidth: 6, chars: "0123456789:! " },
{ height: 35, blockWidth: 5, chars: "0123456789:! " },
{ height: 28, blockWidth: 4, chars: "0123456789:! " },
{ height: 21, blockWidth: 3, chars: "0123456789:absgdupm! " },
{ height: 14, blockWidth: 2, chars: "0123456789:absgdupm! " },
{ height: 9, blockWidth:1.5, chars: "0123456789:! " },
{ height: 7, blockWidth: 1, chars: "0123456789:! " },
{ height: 9, blockWidth:1.5, chars: "0123456789 ", inverted: true },
{ height: 7, blockWidth: 1, chars: "0123456789 ", inverted: true },
];
const refWidth = {
1: ':!',
5: '1234567890 ',
6: 'bsg',
7: 'a',
8: 'm',
9: 'p',
10: 'ud'
};
const charRef = {};
Object.keys(refWidth).forEach(m => refWidth[m].split('').forEach(l => charRef[l] = m));
const root = ['.', 'resources', 'font'];
let osY = 0;
setup.forEach(setting => {
const fName = path.join.apply(path, root.concat(`hooky_${setting.blockWidth}${setting.inverted? 'i':''}.fnt`));
const out = fs.createWriteStream(fName);
out.write(`common lineHeight=${setting.height} base=${setting.height} pages=1
page id=0 file="hooky9.png"
chars count=${setting.chars.length}
`, () => {
let osX = 0;
const lines = setting.chars.split('').map(c => {
let l = `char id=${c.charCodeAt(0)} `;
l += `x=${osX} y=${osY} `;
l += `width=${charRef[c]*setting.blockWidth|0} `;
l += `height=${setting.height} `;
l += `xoffset=0 yoffset=0 xadvance=${charRef[c]*setting.blockWidth|0} page=0 chnl=1`;
osX += setting.blockWidth * charRef[c] | 0;
return l;
});
lines.push("");
out.end(lines.join("\r\n"));
osY += setting.height;
});
});