class

AsciiArt::FlfFont

Inherits Reference < Object

Parsed representation of a FIGlet font (.flf file).

The .flf format (FIGfont version 2) is a plain-text container specifying a header line, a multi-line comment, and one block of height lines per glyph. Glyphs are stored in this fixed order:

  1. printable ASCII 32..126 (95 glyphs, in code-point order)
  2. seven Latin-1 extras (U+00C4 Ä, U+00D6 Ö, U+00DC Ü, U+00E4 ä, U+00F6 ö, U+00FC ü, U+00DF ß) — required by spec
  3. zero or more "code-tagged" glyphs prefixed by their codepoint

Each glyph line ends with a "endmark" character (typically @) which is repeated twice on the last line. The "hardblank" character declared in the header (often $) is rendered as an actual space at draw time but stops adjacent glyphs from being smushed together.

This v0.1 parser supports the printable ASCII range; Latin-1 extras are read but optional, code-tagged glyphs are skipped (used only by exotic fonts for non-Latin scripts).

Constructors

load(path : String) : FlfFont

Convenience: reads the .flf from path and parses it.

Source
new(hardblank : Char, height : Int32, baseline : Int32, max_length : Int32, print_direction : Int32, comment : String, glyphs : Hash(Int32, Array(String)))
Source
parse(content : String) : FlfFont

Parses the content of a .flf file and returns a FlfFont. Raises ArgumentError on malformed input rather than silently returning a half-initialised font.

Source

Instance methods

baseline

Distance from the top of the glyph to the baseline (the line most letters sit on). Exposed for callers that want to align multiple fonts vertically.

Source
comment

Comment block from the .flf header, joined by "\n". Useful for --show-credits style output.

Source
glyph_for(char : Char) : Array(String) | Nil

Returns the glyph for char, or nil when the font has no rendering for that character. Callers typically substitute a blank glyph (or a ?) when a character is missing.

Source
glyphs

Map from codepoint to glyph (each glyph = height strings of equal width). Built lazily during parsing.

Source
hardblank

Character used to pad short lines inside a glyph; rendered as a real space at draw time. Distinct from a regular space so the font can encode "intentional blank columns" inside a glyph.

Source
height

Vertical size of every glyph, in lines.

Source
max_length

Maximum width of any line in the font.

Source
soften_hardblanks(line : String) : String

Replace every hardblank in line by a literal space — meant to be applied just before printing, never on the raw glyph data (otherwise smushing would lose its anchor).

Source