MaxMatrix
Drive chained 8x8 LED dot matrix modules with MAX7219.
Loading...
Searching...
No Matches
max_matrix::Font Class Reference

The format of a font, and the way from a char of a string to its glyph. More...

#include <Font.h>

Static Public Member Functions

static MAXMATRIX_NODISCARD Status CheckFont (span< uint8_t const > font)
 Returns whether font is a font that fills its bytes exactly.
static MAXMATRIX_NODISCARD Result< Glyph > GetGlyph (span< uint8_t const > font, char c)
 Finds the glyph of a char in a font.
static DecodedChar DecodeChar (span< char const > text)
 Decodes the next char of a string.

Detailed Description

The format of a font, and the way from a char of a string to its glyph.

A font is the font format of the MD_MAX72XX library, so that its fonts and its font builder serve here as well: an array of bytes in flash, PROGMEM, that starts with 'F', the version, the code of the first char, that of the last, and the height in rows, and then holds every char from the first to the last as its width and that many columns, bit 0 the top row. A char of width 0 is not in the font. Version 1 gives each code in one byte; version 2, which lets a font go past 255, in two, high byte first.

The format holds no length of its own, so a font is checked against the length of its array, which the span it is handed brings: every char from the first to the last has to fit into it, and the last has to end it. A font that CheckFont() took cannot lead GetGlyph() past its end.

constexpr auto kDigits PROGMEM{max_matrix::make_array<uint8_t>(
'F', 1, '0', '1', 7, // version 1, the chars 0 to 1, 7 rows high
3, B00111110, B01000001, B00111110, // 0
2, B01000010, B01111111)}; // 1
constexpr array< T, sizeof...(Values)> make_array(Values... values)
Returns an array of T of its values, with the size taken from them.
Definition array.h:185

A char is found by walking from the first char to it, as MD_MAX72XX does: in the default font 34 us for an A and 211 us for a u umlaut, 220 chars on, on the Uno (measured in simavr), against an index that would take two bytes of flash per char. A shifting text looks a char up once.

It keeps no font of its own: every function is handed the font, and internal::Text keeps which one is set.

Member Function Documentation

◆ CheckFont()

MAXMATRIX_NODISCARD Status max_matrix::Font::CheckFont ( span< uint8_t const > font)
static

Returns whether font is a font that fills its bytes exactly.

A font in RAM fails as well, almost always, as it is read from flash: the bytes found there at its address would have to add up to its length exactly.

Parameters
[in]fontThe font, in flash.
Returns
Error::kOk, or Error::kNotAFont if font is too short for its header, does not start with 'F', version 1 or 2, a first char no later than the last and a height of 1 to 8, or its chars do not fill it exactly.

◆ DecodeChar()

DecodedChar max_matrix::Font::DecodeChar ( span< char const > text)
static

Decodes the next char of a string.

A UTF-8 sequence of a latin-1 char, such as an umlaut, becomes that one latin-1 char; every other byte comes back as it is.

Parameters
[in]textThe text from the char to decode on; not at its end, as internal::IsEndOfText() tells it.
Returns
The char, and the number of bytes it took in text.

◆ GetGlyph()

MAXMATRIX_NODISCARD Result< Glyph > max_matrix::Font::GetGlyph ( span< uint8_t const > font,
char c )
static

Finds the glyph of a char in a font.

Parameters
[in]fontThe font, in flash, one that CheckFont() took.
[in]cThe char, latin-1, as DecodeChar() gives it.
Returns
The glyph, or Error::kUnknownChar if the font has no char for it.

The documentation for this class was generated from the following file: