forked from fontello/svg2ttf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ttfinfo.js
executable file
·91 lines (72 loc) · 1.87 KB
/
ttfinfo.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/usr/bin/env node
/*
* Internal utility qu quickly check ttf tables size
*/
/*eslint-disable no-console*/
'use strict';
var fs = require('fs');
var _ = require('lodash');
var format = require('util').format;
var ArgumentParser = require('argparse').ArgumentParser;
var parser = new ArgumentParser({
version: require('./package.json').version,
addHelp: true,
description: 'Dupm TTF tables info'
});
parser.addArgument(
[ 'infile' ],
{
nargs: 1,
help: 'Input file'
}
);
parser.addArgument(
[ '-d', '--details' ],
{
help: 'Show table dump',
action: 'storeTrue',
required: false
}
);
var args = parser.parseArgs();
var ttf;
try {
ttf = fs.readFileSync(args.infile[0]);
} catch (e) {
console.error("Can't open input file (%s)", args.infile[0]);
process.exit(1);
}
var tablesCount = ttf.readUInt16BE(4);
var i, offset, headers = [];
for (i = 0; i < tablesCount; i++) {
offset = 12 + i * 16;
headers.push({
name: String.fromCharCode(
ttf.readUInt8(offset),
ttf.readUInt8(offset + 1),
ttf.readUInt8(offset + 2),
ttf.readUInt8(offset + 3)
),
offset: ttf.readUInt32BE(offset + 8),
length: ttf.readUInt32BE(offset + 12)
});
}
console.log(format('Tables count: %d'), tablesCount);
_.forEach(_.sortBy(headers, 'offset'), function (info) {
console.log('- %s: %d bytes (%d offset)', info.name, info.length, info.offset);
if (args.details) {
var bufTable = ttf.slice(info.offset, info.offset + info.length);
var count = Math.floor(bufTable.length / 32);
var offset = 0;
//split buffer to the small chunks to fit the screen
for (var i = 0; i < count; i++) {
console.log(bufTable.slice(offset, offset + 32));
offset += 32;
}
//output the rest
if (offset < (info.length)) {
console.log(bufTable.slice(offset, info.length));
}
console.log('');
}
});