text

Draw text with the bitmap fonts generated by make_font.

Works on any framebuf-like object that has hline(x, y, w, color), so the same code draws into framebuf.FrameBuffer on the board and into a fake on the host. Only set pixels are drawn; the background stays as it is.

Attributes

Functions

text_width(font, s)

Width of s in pixels.

draw_glyph(fb, font, key, x, y, color)

Draw one glyph (a character, or an icon name) at (x, y).

draw_text(fb, font, s, x, y, color)

Draw s with its top-left corner at (x, y); returns the end x.

wrap(font, text, width[, max_lines])

Break text into lines of at most width pixels.

Module Contents

text.FALLBACK = '?'
text.text_width(font, s)

Width of s in pixels.

text.draw_glyph(fb, font, key, x, y, color)

Draw one glyph (a character, or an icon name) at (x, y).

Unknown keys fall back to “?” if the font has one.

Returns:

The glyph’s width in pixels.

text.draw_text(fb, font, s, x, y, color)

Draw s with its top-left corner at (x, y); returns the end x.

text.ELLIPSIS = '…'
text.wrap(font, text, width, max_lines=None)

Break text into lines of at most width pixels.

Lines break at spaces where possible; explicit newlines are kept. With max_lines, the last line ends with an ellipsis if text was cut off.