editor/codepage.js
function codepageGenerator(retina, palette) {
"use strict";
var BASE64_CHARS, FONT_80X25, FONT_80X25_SMALL, bigFontBuffer, smallFontBuffer, NULL, SPACE, UPPER_HALF_BLOCK, LOWER_HALF_BLOCK, LEFT_HALF_BLOCK, RIGHT_HALF_BLOCK, LIGHT_SHADE, MEDIUM_SHADE, DARK_SHADE, FULL_BLOCK, BULLET_OPERATOR, MIDDLE_DOT, NO_BREAK_SPACE;
NULL = 0;
SPACE = 32;
UPPER_HALF_BLOCK = 223;
LOWER_HALF_BLOCK = 220;
LEFT_HALF_BLOCK = 221;
RIGHT_HALF_BLOCK = 222;
LIGHT_SHADE = 176;
MEDIUM_SHADE = 177;
DARK_SHADE = 178;
FULL_BLOCK = 219;
BULLET_OPERATOR = 249;
MIDDLE_DOT = 250;
NO_BREAK_SPACE = 255;
BASE64_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
bigFontBuffer = [];
smallFontBuffer = [];
function base64ToBits(text) {
var i, j, k, bytes16, bytes8, bits;
bytes16 = new Uint32Array(1);
bytes8 = new Uint8Array(text.length / 4 * 3);
for (i = j = 0; i < text.length; bytes16[0] = 0) {
bytes16[0] += (BASE64_CHARS.indexOf(text.charAt(i++)) & 63) << 18;
bytes16[0] += (BASE64_CHARS.indexOf(text.charAt(i++)) & 63) << 12;
bytes16[0] += (BASE64_CHARS.indexOf(text.charAt(i++)) & 63) << 6;
bytes16[0] += BASE64_CHARS.indexOf(text.charAt(i++)) & 63;
bytes8[j++] = (bytes16[0] >> 16) & 255;
bytes8[j++] = (bytes16[0] >> 8) & 255;
bytes8[j++] = bytes16[0] & 255;
}
bits = new Uint8Array(9 * 16 * 256);
for (i = 0, k = 0; i < 9 * 16 * 256 / 8; ++i) {
for (j = 7; j >= 0; --j) {
bits[k++] = (bytes8[i] >> j) & 1;
}
}
return bits;
}
FONT_80X25 = base64ToBits("AAAAAAAAAAAAAAAAAAAAAAAAAAAfkC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A7gAE5OTgBOREQATkREAALyAAAE9AAAAI8AAAb2AAAE7gAADuQAAAAAAABEQEAAqgAAAE5OQARoQsQACSSQAE5JpQBIAAAAJERCAEIiJACk5KAABOQAAAAASAAA4AAAAABAAAJEgABKqkAAxETgAMJI4ADCQsAAiORAAOhCwABIykAA4kRAAEpKQABqYiAABAQAAAQEgAAkhCAADw8AAIQkgASiQEAATuhgAErqoADKysAASopAAMqqwADoyOAA6MiAAEqOQACq6qAA5ETgAOIqQACqyqAAiIjgAK7qoACu7qAASqpAAMrIgABKqmAAysqgAGhCwADkREAAqqpAAKqkQACq7kAAqkqgAKpEQADiSOAAZERgAAhEIABiImAEoAAAAAAADwCEAAAABqpgAIyqwAAGiGAAJqpgAAToYAAkZEAABKpiQIyqoABAREAAQERIAIrKoABEREAADuqgAAyqoAAEqkAADKyAAAamIAAMqIAABoLAAE5EQAAKqmAACqpAAAqu4AAKRKAACqRAAA4s4AAkxCAARERAAIRkgAbAAAAABKrgAEqKSACgqmACQk6OBKBuYACgbmAEIG5gAEBuYAAAaGSEoE6OAKBOjghATo4AoERABKBEQAhAREAKBK6gBASuoAJA6MjgBv5wAHr6sASgSqQKAEqkCEBKpASgqkAIQKpACgqkQAoEqqQKCqqkAARoZASoyOAKpORADKyrohJU5EgCQG5gAkBEQAJASqQCQKpABsDKoAbAru6gbmDgAEpA4AQEikAAAOiAAADiIARA4EjkQOCOQEBO5AAFhQAAChoAAUFBQUWlpaWtfX19dERERERExERETMRERVXVVVAA9VVQDMRERV3VVVVVVVVQD9VVVV3wAAVV8AAETMAAAADEREREcAAERPAAAAD0REREdERAAPAABET0RERHdERFVXVVVVdwAAAHdVVVX/AAAA/1VVVXdVVQD/AABV/1VVRP8AAFVfAAAA/0REAA9VVVVXAABEdwAAAHdERAAHVVVVX1VVRP9ERERMAAAAB0RE/////wAA///MzMzMMzMzM///AAAFqqUAaamSAA6oiAAA6qoA+EJI8AB6qkAAVVZIAKREQOSqpOBKrqpAaZZmkGQmmWAA+Z8AEmlkgAaOhgAGmZkADg4OAABOQOAAQkBgACQgYAJUREREREzABA4EAAWgWgBKQAAAAAZgAAAGAAADIqYgDKoAAEJGAAAAZmYAAAAAAA==");
function doubleScale(rgbaSource, fontWidth) {
var byteWidth, doubledByteWidth, rgba, rgbaDoubled, startOfRow, i, k;
byteWidth = fontWidth * 4;
doubledByteWidth = byteWidth * 2;
rgbaDoubled = new Uint8Array(rgbaSource.length * 4);
for (i = 0, k = 0; i < rgbaSource.length; i += 4) {
rgba = rgbaSource.subarray(i, i + 4);
rgbaDoubled.set(rgba, k);
k += 4;
rgbaDoubled.set(rgba, k);
k += 4;
if ((i + 4) % byteWidth === 0) {
startOfRow = k - doubledByteWidth;
rgbaDoubled.set(rgbaDoubled.subarray(startOfRow, startOfRow + doubledByteWidth), k);
k += doubledByteWidth;
}
}
return rgbaDoubled;
}
function scaleCanvas(sourceData, width, height, chunkWidth, chunkHeight) {
var destWidth, destHeight, destData, rgba, pixelRowOffset, chunkSize, i, j, k, x, y, r, g, b, a;
rgba = new Uint8Array(4);
destWidth = width / chunkWidth;
destHeight = height / chunkHeight;
destData = new Uint8Array(destWidth * destHeight * 4);
pixelRowOffset = (width - chunkWidth) * 4;
chunkSize = chunkWidth * chunkHeight;
for (i = x = y = 0; i < destData.length; i += 4) {
for (j = r = g = b = a = 0, k = (y * width * chunkHeight + x * chunkWidth) * 4; j < chunkSize; ++j) {
r += sourceData[k++];
g += sourceData[k++];
b += sourceData[k++];
a += sourceData[k++];
if ((j + 1) % chunkWidth === 0) {
k += pixelRowOffset;
}
}
rgba[0] = Math.round(r / chunkSize);
rgba[1] = Math.round(g / chunkSize);
rgba[2] = Math.round(b / chunkSize);
rgba[3] = Math.round(a / chunkSize);
destData.set(rgba, i);
if (++x === destWidth) {
x = 0;
++y;
}
}
return destData;
}
function getData(charCode, fg, bg, width, height, data, excludeNinthBit) {
var fontBitWidth, rgbaOutput, i, j, k;
fontBitWidth = width * height;
rgbaOutput = new Uint8Array((excludeNinthBit ? width - 1 : width) * height * 4);
for (i = 0, j = charCode * fontBitWidth, k = 0; i < fontBitWidth; ++i, ++j) {
if (!excludeNinthBit || (i + 1) % 9 !== 0) {
if (data[j]) {
rgbaOutput.set(palette.COLORS[fg], k);
} else {
rgbaOutput.set(palette.COLORS[bg], k);
}
k += 4;
}
}
return rgbaOutput;
}
function bigFont(charCode, fg, bg) {
var bufferIndex;
bufferIndex = charCode + (fg << 8) + (bg << 12);
if (!bigFontBuffer[bufferIndex]) {
bigFontBuffer[bufferIndex] = getData(charCode, fg, bg, 9, 16, FONT_80X25, true);
if (retina) {
bigFontBuffer[bufferIndex] = doubleScale(bigFontBuffer[bufferIndex], 8);
}
}
return bigFontBuffer[bufferIndex];
}
function smallFont(charCode, fg, bg) {
var bufferIndex;
bufferIndex = charCode + (fg << 8) + (bg << 12);
if (!smallFontBuffer[bufferIndex]) {
smallFontBuffer[bufferIndex] = getData(charCode, fg, bg, 4, 8, FONT_80X25_SMALL, false);
if (!retina) {
smallFontBuffer[bufferIndex] = scaleCanvas(smallFontBuffer[bufferIndex], 4, 8, 2, 2);
}
}
return smallFontBuffer[bufferIndex];
}
return {
"bigFont": bigFont,
"smallFont": smallFont,
"NULL": NULL,
"SPACE": SPACE,
"UPPER_HALF_BLOCK": UPPER_HALF_BLOCK,
"LOWER_HALF_BLOCK": LOWER_HALF_BLOCK,
"LEFT_HALF_BLOCK": LEFT_HALF_BLOCK,
"RIGHT_HALF_BLOCK": RIGHT_HALF_BLOCK,
"LIGHT_SHADE": LIGHT_SHADE,
"MEDIUM_SHADE": MEDIUM_SHADE,
"DARK_SHADE": DARK_SHADE,
"FULL_BLOCK": FULL_BLOCK,
"BULLET_OPERATOR": BULLET_OPERATOR,
"MIDDLE_DOT": MIDDLE_DOT,
"NO_BREAK_SPACE": NO_BREAK_SPACE,
"fontWidth": retina ? 16 : 8,
"fontHeight": retina ? 32 : 16
};
}