Drafter.Widget.Digits.Raster (drafter v0.3.2)

Copy Markdown View Source

Rasterises Drafter.Widget.Digits.Bitmap glyphs into terminal cells.

Three packings put multiple pixels in one cell: :braille (2×4), :quadrant (2×2), and :half (1×2). The chart pixel packer supplies the cell characters. See the large text guide for how the packings compare.

Examples

iex> Drafter.Widget.Digits.Raster.cell_pixels(:braille)
{2, 4}

iex> Drafter.Widget.Digits.Raster.shrink(:quadrant)
{1, 2}

iex> font = Drafter.Widget.Digits.Raster.font(:braille)
iex> {font.width, font.height}
{4, 4}

Summary

Functions

Pixels a cell holds, as {across, down}, for a packing.

Rasterise every bitmap into a font map for Drafter.Widget.Digits.Font.

Rasterise one set of lit pixels into rows strings of columns cells.

Divisors applied to the bitmap before rasterising, as {x, y}.

Types

packing()

@type packing() :: :braille | :quadrant | :half

Functions

cell_pixels(atom)

@spec cell_pixels(packing()) :: {pos_integer(), pos_integer()}

Pixels a cell holds, as {across, down}, for a packing.

font(packing)

@spec font(packing()) :: %{height: pos_integer(), width: pos_integer(), glyphs: map()}

Rasterise every bitmap into a font map for Drafter.Widget.Digits.Font.

Returns %{height: rows, width: columns, glyphs: %{character => [row, ...]}}.

glyph(packing, lit, columns, rows)

@spec glyph(packing(), MapSet.t(), pos_integer(), pos_integer()) :: [String.t()]

Rasterise one set of lit pixels into rows strings of columns cells.

shrink(atom)

@spec shrink(packing()) :: {pos_integer(), pos_integer()}

Divisors applied to the bitmap before rasterising, as {x, y}.

:braille reads the bitmap at full resolution. The coarser packings halve the rows; a shrunk pixel is lit when any pixel it covers was lit.