-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathworker.js
114 lines (95 loc) · 4.75 KB
/
worker.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
DataView.prototype.getHex = function (offset, length) {
let end = typeof length == 'number' ? offset + length : this.byteLength;
let text = '';
let val = -1;
while (offset < this.byteLength && offset < end) {
val = this.getUint8(offset++);
text += val.toString(16).toUpperCase().padStart(2, '0');
}
return text;
};
onmessage = function (buffer) {
const view = new DataView(buffer.data);
const version = view.getUint32(4, true);
if (version == 68101 || version == 68614) {
var charCount = view.getUint32(28, true),
floatCount = view.getUint32(32, true),
fileNameLength = view.getUint32(44 + floatCount * 4, true),
glphs = new String;
} else if (version == 69382 || version == 69639 || version == 69895) {
var charCount = view.getUint32(28, true),
floatCount = view.getUint32(36, true),
fileNameLength = view.getUint32(56 + floatCount * 4, true),
glphs = new String;
}
for (let i = 0; i < charCount; i++) {
if (version == 68101 || version == 68614) {
var char = new DataView(buffer.data.slice((49 + floatCount * 4 + fileNameLength) + 16 * i, (49 + floatCount * 4 + fileNameLength) + 16 * i + 16)),
code = char.getUint32(0, true),
unicode = code.toString(16).toUpperCase().padStart(4, '0');
if (code == 32) {
var type = ' ';
} else {
var type = String.fromCodePoint(parseInt(code));
}
var teId = char.getHex(4, 1),
pos = char.getHex(5, 3),
posi1 = parseInt('0x' + pos.substr(3, 1) + pos.substr(0, 2)),
posi2 = ', ' + parseInt('0x' + pos.substr(4, 2) + pos.substr(2, 1)),
siz = char.getHex(9, 3),
size1 = parseInt('0x' + siz.substr(3, 1) + siz.substr(0, 2)),
size2 = ', ' + parseInt('0x' + siz.substr(4, 2) + siz.substr(2, 1)),
adv = '',
advn1 = char.getInt8(12),
advn2 = '',
offs1 = '',
offs2 = '',
spac = char.getHex(13, 1) + ', ' + char.getHex(14, 1) + ', ' + char.getHex(15, 1);
} else if (version == 69382) {
var char = new DataView(buffer.data.slice((61 + floatCount * 4 + fileNameLength) + 20 * i, (61 + floatCount * 4 + fileNameLength) + 20 * i + 20)),
code = char.getUint32(0, true),
unicode = code.toString(16).toUpperCase().padStart(4, '0');
if (code == 32) {
var type = ' ';
} else {
var type = String.fromCodePoint(parseInt(code));
}
var teId = char.getHex(4, 1),
pos = char.getHex(5, 3),
posi1 = parseInt('0x' + pos.substr(3, 1) + pos.substr(0, 2)),
posi2 = ', ' + parseInt('0x' + pos.substr(4, 2) + pos.substr(2, 1)),
siz = char.getHex(8, 3),
size1 = parseInt('0x' + siz.substr(3, 1) + siz.substr(0, 2)),
size2 = ', ' + parseInt('0x' + siz.substr(4, 2) + siz.substr(2, 1)),
spac = char.getHex(11, 1),
adv = char.getHex(12, 3),
advn1 = parseInt('0x' + adv.substr(3, 1) + adv.substr(0, 2)),
advn2 = ', ' + parseInt('0x' + adv.substr(4, 2) + adv.substr(2, 1)),
offs1 = char.getInt8(16),
offs2 = ', ' + char.getInt8(17);
} else if (version == 69639 || version == 69895) {
var char = new DataView(buffer.data.slice((61 + floatCount * 4 + fileNameLength) + 36 * i, (61 + floatCount * 4 + fileNameLength) + 36 * i + 36)),
code = char.getUint32(0, true),
unicode = code.toString(16).toUpperCase().padStart(4, '0');
if (code == 32) {
var type = ' ';
} else {
var type = String.fromCodePoint(parseInt(code));
}
var size1 = char.getFloat32(4, true),
size2 = ', ' + char.getFloat32(8, true),
offs1 = char.getFloat32(12, true),
offs2 = ', ' + char.getFloat32(16, true),
advn1 = char.getFloat32(20, true),
advn2 = ', ' + char.getFloat32(24, true),
teId = char.getHex(28, 1),
pos = char.getHex(29, 3),
posi1 = parseInt('0x' + pos.substr(3, 1) + pos.substr(0, 2)),
posi2 = ', ' + parseInt('0x' + pos.substr(4, 2) + pos.substr(2, 1)),
spac = char.getHex(32, 1);
}
let glph = '<tr><td class="TableObject-item"><code lang="ja" class="color-bg-subtle">' + type + '</code> U+' + unicode + '</td><td class="TableObject-item">' + teId + '</td><td class="TableObject-item">' + posi1 + posi2 + '</td><td class="TableObject-item">' + size1 + size2 + '</td><td class="TableObject-item">' + advn1 + advn2 + '</td><td class="TableObject-item">' + offs1 + offs2 + '</td><td class="TableObject-item">' + spac + '</td></tr>';
glphs += glph;
}
postMessage(glphs);
}