font-problems

1.7.1 • Public • Published

font-problems

font-problems is a command-line tool for reading and writing console bitmap fonts. These are fonts described by a rectangular pixel matrix, used for small hardware projects like light-up signs or low-resolution terminals.

In particular, it can convert between "standard" formats like PSF and BDF, as well as import and export BMP images (for easy editing), GFX headers, or compact C or rust source files.

Building

Building and running requires node.js.

$ npm install
$ ./bin/font-problems --help

Formats

Supported formats are:

.bmp    grid of glyphs
.psf    portable screen font (used by Linux and PC DOS)
.bdf    bitmap distribution format (popular in the 1990s)
.h      C header ("raw" and GFX)
.rs     Rust header ("raw" only)

BMP files

A font in BMP format is a regular grid of glyphs. You can specify the glyph dimensions manually, though it can usually detect the borders automatically by noticing the empty pixels between letters. The glyphs are assumed to be drawn in a dark color (like black) on a light color (like white), though they can be read from a white-on-black file using --reversed.

Glyphs that aren't as wide as the cell should be pushed up against the left edge. For proportional fonts, font-problems will detect the whitespace on the right edge, and remove it.

Header files

"Raw header file" output format is a C or Rust header file with one constant each for the glyph width (monospace only) and height, and an array of cell data. You can use these to directly include a bitmap font in the source for your project.

For proportional fonts, there's also an array of offsets for indexing. The cell data for character n starts at offset[n] (inclusive) and goes through offset[n + 1] (exclusive).

Each int is a single row or column of pixels, in LSB or MSB order. LSB (the default) means the left or top pixel is in the least-significant bit.

Some "raw" header files can be imported, as well, if you provide the cell width and height on the command line. You may have to massage the file a bit to remove extra lines that confuse the parser.

GFX files

GFX is just a variant of a C header file, described here: https://glenviewsoftware.com/projects/products/adafonteditor/adafruit-gfx-font-format/

GFX fonts may be monospace or proportional, and usually cover just the ASCII range.

PSF files

PSF file format is described here: http://www.win.tue.nl/~aeb/linux/kbd/font-formats-1.html

Each glyph must be the same width and height in a PSF file (monospace), and exactly 256 or 512 characters must be defined. BIOS only supports a glyph width of 8, so only framebuffers can use other widths.

Font-problems will generate a simple unicode mapping table for PSF files, which you can specify with "--map". This is a text file in a particular format, described here: PSF map files

BDF files

BDF file format is documented by Adobe and X11, and is still in popular use because it's really just a text file with a simple format. Font-problems should be able to read and write these files, though it hasn't had as much testing as the other formats.

Sample fonts

Three sample fonts are included, in the fonts/ folder:

  • "Tom Thumb" is from my blog, with some line-drawing and block characters added, for console tools like Midnight Commander. Each cell is 4x6, which I believe is the smallest a bitmap font can be while still having any legibility.

  • "Lola" is a simple proportional font, ranging from 4x8 to 6x8, in ASCII only. It was designed to work on LED matrix displays like this one.

  • "Oranj" is a 6x8 monospace font inspired by the Apple II, with support for most Latin glyphs.

  • "Bizcat" is an 8x16 monospace font suitable for 1980s home computers and 640x480 displays, with support for most Latin glyphs, inspired by wanting to replace the stuffy IBM PC default console font.

All of these fonts are licensed as Creative Commons "share & adapt": http://creativecommons.org/licenses/by/4.0/

License

Apache 2 (open-source) license, included in LICENSE.txt.

Authors

@robey - Robey Pointer robeypointer@gmail.com

Readme

Keywords

none

Package Sidebar

Install

npm i font-problems

Weekly Downloads

1

Version

1.7.1

License

Apache-2.0

Unpacked Size

4.35 MB

Total Files

117

Last publish

Collaborators

  • robey