ASCII art to glyph bitmaps and back, for hand-drawn fonts.
Glyphs are drawn with # for ink and . for background, one line per pixel row. parse/3 turns the art into the bitstring layout RasterExRatatui.Font expects; call it from module attributes so the work happens at compile time.
A glyph may be drawn smaller than the cell and padded with background on the right and at the bottom, which is how text glyphs get their inter-cell and inter-line spacing without drawing it every time.
Summary
Functions
Parses art into a {width, height} glyph bitstring.
Renders a {width, height} glyph bitstring back to ASCII art, one line per row. Handy when debugging a font or a failing glyph assertion.
Functions
@spec parse(String.t(), {pos_integer(), pos_integer()}, keyword()) :: bitstring()
Parses art into a {width, height} glyph bitstring.
Options
:pad—{right, bottom}background columns and rows added around the art (default{0, 0}). The art must then be exactlywidth - rightcolumns byheight - bottomrows.
Raises ArgumentError when the art does not have that shape or uses a character other than # and ..
Examples
iex> RasterExRatatui.Font.Art.parse("#.\n.#\n", {2, 2})
<<0b1001::4>>
iex> RasterExRatatui.Font.Art.parse("#\n", {2, 2}, pad: {1, 1})
<<0b1000::4>>
@spec render(bitstring(), {pos_integer(), pos_integer()}) :: String.t()
Renders a {width, height} glyph bitstring back to ASCII art, one line per row. Handy when debugging a font or a failing glyph assertion.
Examples
iex> RasterExRatatui.Font.Art.render(<<0b1001::4>>, {2, 2})
"#.\n.#\n"