Vivid.BDF.Glyph (vivid v1.0.0)

Copy Markdown View Source

A single glyph from a bitmap font: how far the pen advances, and which pixels are lit.

Pixels are {x, y} pairs relative to the glyph's origin, with Y pointing up like everything else in this library, so a descender has negative coordinates. Unlike an outline glyph there's nothing to parse on demand - a bitmap is already as decoded as it gets - so they're expanded when the font is read.

Summary

Functions

Returns how far the pen advances after drawing glyph, in pixels.

Initialize a glyph from its advance width and lit pixels.

Returns the lit pixels of glyph as {x, y} pairs.

Types

t()

@type t() :: %Vivid.BDF.Glyph{advance: number(), pixels: [{integer(), integer()}]}

Functions

advance(glyph)

@spec advance(t()) :: number()

Returns how far the pen advances after drawing glyph, in pixels.

Example

iex> Path.join(:code.priv_dir(:vivid), "fonts/misc-fixed-4x6.bdf")
...> |> Vivid.BDF.load!()
...> |> Vivid.Font.glyph(?W)
...> |> Vivid.BDF.Glyph.advance()
4

init(advance, pixels)

@spec init(number(), [{integer(), integer()}]) :: t()

Initialize a glyph from its advance width and lit pixels.

pixels(glyph)

@spec pixels(t()) :: [{integer(), integer()}]

Returns the lit pixels of glyph as {x, y} pairs.

Example

A full stop is a single pixel, sitting on the baseline.

iex> Path.join(:code.priv_dir(:vivid), "fonts/misc-fixed-4x6.bdf")
...> |> Vivid.BDF.load!()
...> |> Vivid.Font.glyph(?.)
...> |> Vivid.BDF.Glyph.pixels()
[{1, 0}]