# Hexafonter

A command-line tool that will convert a PNG file with a fixed-width pixel font
for small LCD displays, like this:

![(sample font image)](./font.png)

to a C file with a sideways preview and a character code legend, like this:

![(sample output screenshot)](./output-screenshot.png)

See [`sample-output.c`](./sample-output.c) for the full thing -- but note that
you need a relatively modern monospace font for this to look good.


## Installation

You need Python 3.6+ and the [`png` module](https://pypng.readthedocs.io/en/latest/index.html).

In a Python virtual environent, you can install the tool as:

    python -m pip install hexafonter


## Usage

To convert a PNG to a C font file:

    python -m hexafonter font.png > output-font.c

By default, the tool expects characters to be 8 pixels tall 6 pixels wide.
The height is hard-coded, but you can change the width by adding a number:

    python -m hexafonter arcade-font.png 8 > output-font.c

Several options:

* `-p preamble-file`: Use a custom preamble (`#include` and variable
  declaration)
* `-p -`: Use *no* preamble (useful if you prepend it some other way)
* `-o outfile.c`: Output to the given file, rather than stdout (i.e. don't
  combine this with the `> outfile` part shown above)
* `-r`: Reverse mode -- convert a C file to a PNG instead.
  (May not work with files generated by other tools.
  Details not present in the C file will be lost.
  On the other hand, the resulting PNG will be relatively small.)
* `-h`: Get help


## Details of operation

The tool looks at the *red* channel of each pixel and does a very basic
treshold operation. That means:

- Don't use (semi-)transparent images.
  (The tool does not “see” what you see in the transparent regions.)
- Dark colors, especially green/cyan/blue, are treated as black (on).
- Light colors, especially red/yellow/magenta, and all are treated as
  white (off).

The preview in the C file uses Unicode `BLOCK SEXTANT` characters.


## License

The tool is provided under the MIT license. May it serve you well.
