Pixel-art text: strings drawn as scaled bitmap glyphs on a canvas.
A glyph is a monochrome bitmap with a fixed cell size. Each glyph is drawn
once per scale into a white gfx.sprite art mask and cached. Drawing blits
the mask with the text colour as a tint, so one mask serves every colour.
| Name | Signature |
|---|---|
| font | font(spec) -> font |
font(
spec) ->font
Create a pixel-art font
| spec field | default | description |
|---|---|---|
glyphs | the 5x7 ASCII font | map of character to rows of # and . |
cell_w, cell_h | 5, 7 | glyph cell size in pixels |
default_color | {252,252,252,255} | text colour |
fallback | " " | character drawn for a missing glyph |
spacing | 1 | gap between glyphs, in cell pixels |
line_spacing | 1 | gap between lines, in cell pixels |
A lowercase letter with no glyph draws its uppercase glyph.
font:draw(canvas, text, x, y, opts) draws text with its top-left at
x, y and returns the pen x after the last glyph. A newline starts a line
at x.
font:measure(text, opts) returns the width and height draw would cover,
in pixels.
| opts field | description |
|---|---|
scale | integer pixels per cell pixel, default 1 |
color | text colour, default default_color; draw only |
blend | passed to canvas:blit; draw only |
spacing, line_spacing | override the font's gaps |