FontGen - PathogenDavid/Periodic GitHub Wiki

Because of our use of the FB32 graphics mode, we had to write our own tools for converting graphics assets. FontGen is a tool written in C# that can take in a palette image and a font image and generate a .cpp/h file combo that contains the raw data for the palette and font.

Usage

It is unlikely that you will ever need to invoke FontGen directly. It is automatically invoked by our build system when necessary. That being said, the usage of the tool is very simple:

FontGen input.png

Where input.png is the font image to use. It is assumed to only use colors from the palette, and

The file palette.png must be present in the current working directory. It is expected to be contain the same number of pixels present in the FB32 graphics mode (16 pixels.) Pallet colors will be numbered left-to-right, top-to-bottom.

The Output

The output files will be named fontname.gen.cpp and fontname.gen.h, where fontname is the name of your font file excluding the file extension. The output files shall define the following literal constants and matching memory constants.

  • PALETTE_COUNT - The number of colors in the palette
  • PALETTE_SIZE - The number of bytes consumed by the palette
  • palette - An array of unsigned chars that is PALETTE_SIZE long. The data is list of R, G, and B bytes for all PALETTE_COUNT colors in the palette.
  • FONTNAME_SIZE - The number of bytes consumed by the font data.
  • FONTNAME_GLYPH_WIDTH - The number of horizontal pixels that each glyph in the font needs.
  • FONTNAME_GLYPH_HEIGHT - The number of vertical pixels that each glyph in the font needs.
  • FONTNAME_GLYPH_SIZE - The number of pixels in total that each glyph in the font needs.
  • fontName - The data for the font, a series of index values for the corresponding pallet. Every FONTNAME_GLYPH_SIZE bytes defines a different glyph.

Where fontName is your font's file name without the extension and FONTNAME is fontName, but all uppercase.

Limitations

There are some limitations in the tool simply because we don't need certain features right now.

  • Right now the name of palette.png is hard-coded
  • The pallet data is always emitted (which would be a problem if we had more than one font or emitted something besides fonts in a separate tool.)
  • The tool only works for FB32 mode (not FB64 or FB128.)
  • The tool doesn't support transparency (and neither does our font rendering for that matter.)
  • The tool requires a font image that was manually prepared in another tool, rather than by using a font directly.
  • The tool only works for alphabetic characters, upper and lower-case.