By dave | May 28, 2021

In the theme plugin properties you can often select the font to use. However, there are a few points to bear in mind when using fonts. Here are the key points:

  • Each plugin will use a different style of fonts, mainly based on how the underlying library itself draws fonts. You must use a compatible font.
  • Some libraries such as U8G2 and TFT_eSPI generally include the fonts in the package, and it is up to you to know which ones are available.
  • For Adafruit_GFX the fonts are generally included as needed from the Fonts directory, either in the package itself, or from your local project. They will be included once only in the C++ menu file and the variable for the font will be exported.
  • With themes, the designer will NOT overwrite any theme header file that has already been created in case you have manually modified it, to make the changes you must delete the file yourself so that it is recreated.
Font dialog showing default selection

Font definition dialog

We’ll now discuss each option in turn, and what it means in terms of generated code.

Using the default font

Nearly all display plugins support the default option. This means use whatever font is the default for the library, or if there is not a default, we pick a sensible one that would fit most displays. Only the font size field is relevant and is used as the magnification if supported.

Adafruit Library font

For Adafruit_GFX and LTDC/BSP libraries Adafruit fonts are used.

For this option you provide a font that will be found in the global Adafruit_GFX Fonts directory, you also provide the magnification factor for this. During code generation we will turn this into a C++ file global include, export the font name for use elsewhere, and set the font definition up.

Adafruit local font

For Adafruit_GFX and LTDC/BSP libraries Adafruit fonts are used.

For this option you provide a font that will be found within your project in a Fonts directory, you also provide the magnification factor for this. During code generation we will turn this into a C++ file project local include, export the font name for use elsewhere, and set the font definition up.

Static Font

In U8G2 the fonts are all included in the library directly, all that is needed is to refer to the variable. This option is suitable when the font is already available and can be referenced by name. It will create a font definition only. For this option provide the name only.

Numbered font

Some displays such as TFT_eSPI keep available fonts in an array, and you refer to them by number. For this option provide the number only. The definition will be created for that font number.

Fonts being passed to rendering functions

Within the core graphics functions, fonts are pased around as a MenuFontDef, this structure has the fontData which is a pointer to the font, and also the fontMag parameter, which is either the size or font number, depending on the device in use.

To construct a font definition manually:

MenuFontDefinition def(fontDataPtr, fontMagOrSize);

It is a struct, so has trivially simple copy characteristics.

Notes for specific implementations

Other pages within this category

comments powered by Disqus

This site uses cookies to analyse traffic, serve ads by Google AdSense (non-personalized in EEA/UK), and to record consent. We also embed Twitter, Youtube and Disqus content on some pages, these companies have their own privacy policies.

Our privacy policy applies to all pages on our site

Should you need further guidance on how to proceed: External link for information about cookie management.