parent
76d40a7450
commit
0d6dfca317
|
|
@ -63,27 +63,27 @@ const prepFont = (name, data) => {
|
||||||
if (m = /^(<*)(=)([*\d]*)(=*)(>*)$/.exec(line) || /^(<*)(-)(.)(-*)(>*)$/.exec(line)) {
|
if (m = /^(<*)(=)([*\d]*)(=*)(>*)$/.exec(line) || /^(<*)(-)(.)(-*)(>*)$/.exec(line)) {
|
||||||
const h = m[2] == '=';
|
const h = m[2] == '=';
|
||||||
if (m[1].length > desc || h && m[1].length != desc)
|
if (m[1].length > desc || h && m[1].length != desc)
|
||||||
throw new Error('Invalid descender height at ' + l);
|
throw new Error('Invalid descender height at ' + l);
|
||||||
if (m[2].length + m[3].length + m[4].length != body)
|
if (m[2].length + m[3].length + m[4].length != body)
|
||||||
throw new Error('Invalid body height at ' + l);
|
throw new Error('Invalid body height at ' + l);
|
||||||
if (m[5].length > asc || h && m[5].length != asc)
|
if (m[5].length > asc || h && m[5].length != asc)
|
||||||
throw new Error('Invalid ascender height at ' + l);
|
throw new Error('Invalid ascender height at ' + l);
|
||||||
if (c != null) {
|
if (c != null) {
|
||||||
lengths[c] = l - o;
|
lengths[c] = l - o;
|
||||||
if (width !== null && width !== lengths[c])
|
if (width !== null && width !== lengths[c])
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Character has width ${lengths[c]} != ${width} at ${offsets[c]}`
|
`Character has width ${lengths[c]} != ${width} at ${offsets[c]}`
|
||||||
);
|
);
|
||||||
c = null
|
c = null
|
||||||
}
|
}
|
||||||
if (!h) {
|
if (!h) {
|
||||||
c = m[3].charCodeAt(0);
|
c = m[3].charCodeAt(0);
|
||||||
if (c < min) min = c;
|
if (c < min) min = c;
|
||||||
if (c > max) max = c;
|
if (c > max) max = c;
|
||||||
o = l + 1;
|
o = l + 1;
|
||||||
offsets[c] = l;
|
offsets[c] = l;
|
||||||
adjustments[c] = m[1].length
|
adjustments[c] = m[1].length
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
const xoffs = Uint8Array(lines.length);
|
const xoffs = Uint8Array(lines.length);
|
||||||
|
|
@ -92,16 +92,16 @@ const prepFont = (name, data) => {
|
||||||
const w0 = lengths[min];
|
const w0 = lengths[min];
|
||||||
let widths = '';
|
let widths = '';
|
||||||
for (c = min, o = 0; c <= max; c++) {
|
for (c = min, o = 0; c <= max; c++) {
|
||||||
for (i = 0, j = offsets[c]; i < lengths[c]; i++) {
|
for (i = 0, j = offsets[c]; i < lengths[c]; i++) {
|
||||||
xoffs[j] = asc + body + adjustments[c] - 1;
|
xoffs[j] = asc + body + adjustments[c] - 1;
|
||||||
ypos[j++] = o++;
|
ypos[j++] = o++;
|
||||||
}
|
}
|
||||||
widths += String.fromCharCode(lengths[c]);
|
widths += String.fromCharCode(lengths[c]);
|
||||||
}
|
}
|
||||||
const raster = Graphics.createArrayBuffer(h, o, 1, {msb: true});
|
const raster = Graphics.createArrayBuffer(h, o, 1, {msb: true});
|
||||||
const writer = Graphics.createCallback(
|
const writer = Graphics.createCallback(
|
||||||
image.width, image.height, 1,
|
image.width, image.height, 1,
|
||||||
(x, y, col) => raster.setPixel(xoffs[y] - x, ypos[y], col)
|
(x, y, col) => raster.setPixel(xoffs[y] - x, ypos[y], col)
|
||||||
);
|
);
|
||||||
writer.drawImage(image);
|
writer.drawImage(image);
|
||||||
if (width === null) width = `dec(${enc(widths)})`;
|
if (width === null) width = `dec(${enc(widths)})`;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue