Skip to main content

Custom font

What this example shows​

Print one line in the default font and one in FreeSerif 24 px, one of the extra fonts in the repository's fonts/ folder. The fonts are not installed with the board modules, so install the one you want first:

mpremote mip install github:SolderedElectronics/Inkplate-micropython/fonts/free_serif_24px.py

Any other file in fonts/ works the same way: FreeMono, FreeSans and FreeSerif in regular, bold, oblique and italic styles, 12 to 48 px.

Example code​

"""Swap in one of the extra typefaces shipped under fonts/ instead of the default font.

fonts/ isn't installed by default -- fetch the one file you want directly:

mpremote mip install github:SolderedElectronics/Inkplate-micropython/fonts/free_serif_24px.py

Any other file under fonts/ works the same way; see that directory for the full
family/size list (FreeMono/FreeSans/FreeSerif, regular/bold/oblique/italic, 12-48px).
"""

from inkplate7spectra import Inkplate
import free_serif_24px

inkplate = Inkplate()
inkplate.begin()

inkplate.set_text_size(1)
inkplate.set_cursor(180, 180)
inkplate.print("Default font")

inkplate.set_font(free_serif_24px)
inkplate.set_cursor(180, 230)
inkplate.print("Custom font!")

inkplate.display()

Functions used​

Inkplate()returns Inkplate

Creates the display object from the inkplate7spectra module.

ReturnsThe display object.

inkplate.begin()returns bool

Sets up the board and a white frame buffer, with the default font selected. Call it once.

ReturnsTrue.

inkplate.set_text_size(s)returns None

Sets the text scale factor, here 1.

ReturnsNothing.

inkplate.set_cursor(x, y)returns None

Sets where print() starts.

ReturnsNothing.

inkplate.print(text)returns None

Draws text at the cursor in the current font, size and color.

ReturnsNothing.

inkplate.set_font(f)returns None

Switches the font used by print() to the imported font module.

ReturnsNothing.

inkplate.display(leave_on=False)returns None

Sends the frame buffer to the panel and refreshes it.

ReturnsNothing.

What to expect​

"Default font" appears at (180, 180) and "Custom font!" in FreeSerif below it, at (180, 230), both in black. Nothing is printed in the shell.

🔗Open the complete example

examples/inkplate7spectra/custom_font.py

→