Drafter.Widget.Digits.Figlet (drafter v0.3.1)

Copy Markdown View Source

Reads FIGlet fonts (.flf) into the glyph maps Drafter.Widget.Digits.Font serves.

A parsed font behaves like a built-in one once registered:

{:ok, font} = Figlet.load("/usr/share/figlet/slant.flf")
Font.register(:slant, font)
digits("Vellum", font: :slant)

Glyphs are laid out full width — characters placed side by side with no kerning or smushing. Hardblanks are rendered as plain spaces.

Format

The header names a hardblank character, the glyph height, and how many comment lines follow. Glyphs for the printable ASCII range then appear in code order, each one height lines long, every line closed by a repeated endmark character.

See the large text guide for the layout rules Drafter applies.

Summary

Functions

Parse every bundled font, keyed by name.

The directory of FIGlet fonts shipped with Drafter.

Reads and parses a .flf file.

Same as load/1, but raises ArgumentError if the font cannot be loaded.

Every .flf file in a directory, parsed and keyed by its basename.

Parse the contents of a .flf file.

Parses every bundled font and registers it under its own name.

Functions

bundled()

@spec bundled() :: %{required(atom()) => Drafter.Widget.Digits.Font.font()}

Parse every bundled font, keyed by name.

bundled_directory()

@spec bundled_directory() :: Path.t()

The directory of FIGlet fonts shipped with Drafter.

load(path)

@spec load(Path.t()) :: {:ok, Drafter.Widget.Digits.Font.font()} | {:error, term()}

Reads and parses a .flf file.

Returns {:ok, font}, {:error, {:unreadable, reason}} when the file cannot be read, or {:error, {:malformed, detail}} when its header or glyph data is not FIGlet.

load!(path)

Same as load/1, but raises ArgumentError if the font cannot be loaded.

load_directory(directory)

@spec load_directory(Path.t()) :: %{
  required(atom()) => Drafter.Widget.Digits.Font.font()
}

Every .flf file in a directory, parsed and keyed by its basename.

Files that fail to parse are omitted.

parse(contents)

@spec parse(binary()) :: {:ok, Drafter.Widget.Digits.Font.font()} | {:error, term()}

Parse the contents of a .flf file.

register_bundled()

@spec register_bundled() :: [atom()]

Parses every bundled font and registers it under its own name.

Returns the sorted list of names registered, each then usable as digits(text, font: name).