Skip to content

Fonts

The basic edition provides the Terminal font. The font is stored on the internal Flash of the MCU.

The advanced and commercial editions feature the DejaVu font, with three variants: fixed Mono, proportional Serif and proportional Sans Serif, on the internal Flash of the MCU.

The commercial edition brings an additional storage option on an external SPI Flash.

All the fonts include an extended set of characters with the European accented letters.

Configure

uint8_t myFont = 0;

#if (FONT_MODE == USE_FONT_TERMINAL)

    myFont = Font_Terminal12x16;

#elif (FONT_MODE == USE_FONT_FLASH)

    myFont = Font_DejaVuSans16;

#elif (FONT_MODE == USE_FONT_HEADER)

    myFont = myScreen.addFont(Font_DejaVuSans16);
    myFont -= (myFont > 0) ? 1 : 0;

#else

#error Non valid FONT_MODE

#end

addFont() adds a font and returns the number of fonts, or 0 in case of an error.

The number of the font added is addFont() - 1.

This function is only available for the option USE_FONT_HEADER, where header fonts are stored in the internal Flash memory of the MCU.

fontMax() returns the number of fonts.

The available fonts are in the range 0..fontMax() - 1.

Use

selectFont() selects the font based on its index, from range 0 ..fontMax() - 1.

getFont() returns the current font number on the range 0..fontMax() - 1.

getFontDetails() returns a font object with different details such as kind, number of the first character, number of characters, general height and maximum width in pixels.

setFontSolid() prints the text with a transparent background for false or an opaque background for true.

setFontSpaceX() sets additional spaces between two characters on the x-axis.

setFontSpaceY() sets additional spaces between two characters on the y-axis.

uint16_t sizeI = myScreen.characterSizeX('I');
uint16_t sizeM = myScreen.characterSizeX('M');

characterSizeX() returns the size of the character on the x-axis.

As some fonts are proportional, a character is required as parameter.

characterSizeY() returns the size of the font on the y-axis.

uint16_t sizeI = myScreen.stringSizeX("Text");
uint16_t sizeM = myScreen.stringLengthToFitX("Text", 40);

stringSizeX() returns the size of the string on the x-axis.

stringLengthToFitX() returns the number of characters to fit a given number of pixels on the x-axis.

Example

This is the core of the code from example Common_Fonts.ino.

void displayCharacters()
{
    myScreen.setOrientation(myOrientation);
    uint16_t x, y;
    x = myScreen.screenSizeX();
    y = myScreen.screenSizeY();

    myScreen.selectFont(myFont);

    String text;
    uint16_t dx;

    for (uint8_t i = 1; i < 17; i++)
    {
        myScreen.gText(i * x / 17, 0, formatString(".%x", (i - 1)), myColours.red);
    }
    for (uint8_t j = 2; j < 16; j++)
    {
        myScreen.gText(0, (j - 1) * y / 15, formatString("%x.", (j)), myColours.red);
    }

    for (uint16_t i = 1; i < 17; i++)
    {
        for (uint8_t j = 2; j < 16; j++)
        {
            text = (String)char((i - 1) + j * 16);
            dx = i * x / 17 + (x / 17 - myScreen.stringSizeX(text)) / 2;
            myScreen.gText(dx, (j - 1) * y / 15, text, myColours.black);
        }
    }

    myScreen.flush();
}