-
Notifications
You must be signed in to change notification settings - Fork 29
/
index.js
executable file
·57 lines (49 loc) · 1.57 KB
/
index.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
#!/usr/bin/env node
var fs = require('fs');
var path = require('path');
var fontnik = require('fontnik');
var d3 = require('d3-queue');
try {
var fname = process.argv[2];
var fontstack = fs.readFileSync(fname);
console.log('Process '+fname);
var rex = /([A-Z])([A-Z])([a-z])|([a-z])([A-Z])/g;
var folder = path.basename(fname).slice(0, -4).replace('-','').replace(rex, '$1$4 $2$3$5');
if (process.argv[3]) {
if (fs.existsSync(process.argv[3])) {
folder = path.join(process.argv[3], folder);
} else {
console.error('Path ' + process.argv[3] + ' does not exist. Using default.');
}
}
} catch (e) {
console.error('error: could not read font '+e)
return;
}
if(!fs.existsSync(folder)){
fs.mkdirSync(folder, 0766, function(err){
if(err){
console.log(err);
response.send("ERROR! Can't make the directory! \n");
}
});
}
var q = d3.queue(Math.max(4, require('os').cpus().length));
var queue = [];
for (var i = 0; i < 65536; (i = i + 256)) {
q.defer(writeGlyphs, {
font: fontstack,
start: i,
end: Math.min(i + 255, 65535)
});
}
function writeGlyphs(opts, done) {
fontnik.range(opts, function(err, zdata) {
if (err) {
console.warn(err.toString());
process.exit(1);
}
fs.writeFileSync(folder + '/' + opts.start + '-' + opts.end + '.pbf', zdata);
done();
});
}