|
LCDGFX LCD display driver
1.2.0
Lightweight graphics library for SSD1306, SSD1325, SSD1327, SSD1331, SSD1351, SH1106, SH1107, IL9163, ST7735, ST7789, ILI9341, PCD8544 displays over I2C/SPI
|
lcdgfx renders text from font tables stored in PROGMEM. You can use the fonts that ship with the library, or generate your own from any TTF (or a GLCD-exported .c file) with the tools/fontgenerator.py script.
This page covers:
fontgenerator.py needs freetype-py (pip install freetype-py). The generated C array is written to stdout, so redirect it into a header/source file.
-g <first> <count> selects a block of characters. <first> is a symbol, a decimal code, or a 0x.. hex code; <count> is *(number of chars − 1)*. Repeat -g to pack several blocks (e.g. digits + Latin + Cyrillic) into one font while skipping the gaps in between:
Use the font in your sketch:
The generated array name encodes the size, e.g.
free_consola6x13. Look at theextern const uint8_t ...line at the top of the output for the exact symbol to pass tosetFreeFont().
*(New format only — the recommended fix for uneven spacing.)*
A variable-width font keeps every glyph at its natural width, which is usually what you want — but some characters are drawn very narrow. A space or colon may be only 1–2 px wide, so a string like Cookies 325 12 mins looks cramped even with getFont().setSpacing(1). Forcing the whole font to fixed width (-fw) over-corrects: now every glyph is as wide as W, wasting space.
The optional 3rd argument of -g solves this per block:
It forces every char in that group to an exact pixel width, keeping the glyph centered — narrow chars are padded with blank columns on both sides, wider chars are cropped equally from both sides. The width is stored per char in the jump table, so it costs nothing at runtime and combines cleanly with setSpacing().
Notes:
char U+XXXX cropped ...) — the glyph may lose pixels.-fw. -fw forces one global width onto every char and would override the per-group values. | Option | Meaning |
|---|---|
--ttf <file> | Use a TTF file as the source. |
--glcd <file> | Use a GLCD-exported .c file as the source. |
-s <N> | Font size (point size, not pixels). |
-SB <N> | Limit glyph height to N pixels (bottom pixels are cut). |
-fh | Fixed height (pad all glyphs to the tallest). |
-fw | Fixed width (pad all glyphs to the widest). |
-g <S> <E> [W] | Add a char block: first char S, count-minus-1 E, optional exact width W (new format only). |
-f old | Old fixed format (1.7.6 and below). |
-f new | New free/variable format (1.7.8 and above). |
-d | Print demo text to the console. |
-t <text> | Text to use for the -d demo. |
--demo-only | Print demo text and exit (no font emitted). |
--output-file <file> | Write the font to a file directly (instead of stdout). |
For people writing tools that emit or parse lcdgfx fonts. Every field is one byte unless noted.
TYPE 0 or 1)TYPE 2)WIDTH / HEIGHT — the per-char dimensions. This is where a per-group exact width ends up, which is why it is free at render time.