Pixel fonts in pure JS
NOTE: this is a browser-targeted fork of @hgcummings' node.js library. It does not include the PNG rendering function.
npm install barthy-koeln/pixel-fonts --save
yarn add barthy-koeln/pixel-fonts
Render as an array of pixels, for using elsewhere (e.g. drawing to canvas, controlling LEDs):
import { renderPixels } from 'js-pixel-fonts'
import sevenPlus from 'js-pixel-fonts/data/seven-plus.js'
const pixels = renderPixels("Hi!", sevenPlus);
/**
* pixels === [
* [
* [ 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1 ],
* [ 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1 ],
* [ 1, 0, 0, 0, 1, 0, 1, 1, 0, 0, 1 ],
* [ 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 1 ],
* [ 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1 ],
* [ 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0 ],
* [ 1, 0, 0, 0, 1, 0, 1, 1, 1, 0, 1 ]
* ]
* ]
*/
Renders the supplied text
string in the specified font
.
Structure of the returned array:
array[lineIndex] // text line, one per \n in the input string
array[lineIndex][rowindex] // row, one of several per text line
array[lineIndex][rowindex][columnIndex] // column in row, either 1 or 0