/* This file is part of Espruino, a JavaScript interpreter for Microcontrollers Copyright (C) 2013 Gordon Williams This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. ---------------------------------------------------------------------------------------- Bitmap font creator for Graphics custom fonts This is pretty rough-and-ready, and in order to easily get bitmap data out of an image it requires the image to already be in RAW format. For this, use ImageMagick as follows: `convert charset_8x12.png -depth 8 gray:charset_8x12.raw` ---------------------------------------------------------------------------------------- */ // npm install btoa pixels = require("fs").readFileSync("charset_8x12.raw"); // image width and height var W = 128; var H = 72; // character width and height var CW = 8; var CH = 12; /* pixels = require("fs").readFileSync("charset_6x8.raw"); var W = 192; var H = 24; var CW = 6; var CH = 8;*/ var bits = []; var charWidths = []; function genChar(xo,yo) { // work out widths var xStart = CW; var xEnd = 0; for (var x=0;xxEnd) { xStart=0; xEnd = CW/2; // treat space as half-width } else if (xEnd128) ? 0 : 1); } } } // get an array of bits var x=0,y=0; while (y < H) { genChar(x,y); x += CW; if (x>=W) { x = 0; y += CH; } } // compact array var bytes = ""; for (var i=0;i