#!/usr/bin/node /* 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 var FIXEDWIDTH = false; var FIRSTCHAR = 32; var MAXCHARS = 189; // excludes FIRSTCHAR offset // image width and height, character width and height var W = 128; var H = 72; var CW = 8; var CH = 12; var FILENAME = "charset_8x12.raw"; /* var W = 192; var H = 24; var CW = 6; var CH = 8; var FILENAME = "charset_6x8.raw"; */ pixels = require("fs").readFileSync(FILENAME); var bits = []; var charWidths = []; function genChar(xo,yo) { // work out widths if (FIXEDWIDTH) { xStart = 0; xEnd = CW-1; } else { var xStart = CW; var xEnd = 0; for (var x=0;xxEnd) { xStart=0; xEnd = CW/2; // treat space as half-width } else if (xEnd128; debugText[y] += col?" ":"#"; bits.push(col ? 0 : 1); } } console.log("charcode ",FIRSTCHAR+charWidths.length-1,":",xo,",",yo); console.log(debugText.join("\n")); console.log(); } // get an array of bits var x=0,y=0; while (y < H && charWidths.length=W) { x = 0; y += CH; } } // compact array var bytes = ""; for (var i=0;i