-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtableName.js
37 lines (26 loc) · 1.23 KB
/
tableName.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 table = require('./table');
module.exports = function(data) {
var ntOffset = table.offset(data, 'name'),
offsetStorage = data.readUInt16BE(ntOffset+4),
numberNameRecords = data.readUInt16BE(ntOffset+2);
var storage = offsetStorage + ntOffset;
var info = {};
for (var j = 0; j < numberNameRecords; j++) {
var o = ntOffset + 6 + j*12;
var platformId = data.readUInt16BE(o),
nameId = data.readUInt16BE(o+6),
stringLength = data.readUInt16BE(o+8),
stringOffset = data.readUInt16BE(o+10);
var fieldNames = ['copyright','fontFamily','fontSubFamily','fontIdentifier','fontName','fontVersion','postscriptName','trademark','manufacturer','designer','description','vendorURL','designerURL','license','licenseURL','reserved','preferredFamily','preferredSubFamily','compatibleFullName','sampleText','postScriptCIDfindfontName','WWSFamilyName','WWSSubFamilyName'];
nameId = fieldNames[nameId]?fieldNames[nameId]:nameId;
if (!info[nameId]) {
info[nameId] = '';
for (var k = 0; k < stringLength; k++) {
var charCode = data[storage+stringOffset+k];
if (charCode === 0) continue;
info[nameId] += String.fromCharCode(charCode);
}
}
}
return info;
};