-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
36 lines (32 loc) · 794 Bytes
/
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
const Parser = require('./src/parser.js'),
fs = require('fs.promisify');
const parse = (path) => {
return new Parser(path).toObject();
};
const toBitmap = (res) => {
let char = {}, list = res.FONT.CHARS;
for (let i in list) {
char[i] = {
offset: {x: list[i].BBX[2] || 0, y: list[i].BBX[3] || 0},
width: list[i].BBX[0] || 0,
height: list[i].BBX[1] || 0,
bitmap: []
};
for (let x in list[i].BITMAP) {
char[i].bitmap.push(list[i].BITMAP[x].toString(2).padStart(10, '0').split('').map((a) => Number(a)));
}
}
return char;
};
module.exports = {
parse: parse,
bitmap: (p) => {
return parse(p).then((res) => toBitmap(res));
},
bitmapSync: (p) => {
if (Buffer.isBuffer(p)) {
return toBitmap(parse(p));
}
return toBitmap(parse(fs.readFileSync(p)));
}
};