Python script to create new fonts for WaveShare epaper / e-ink [EPS32 module]
I am super happy of my e-ink display from Waveshare, but their library only offers basic fonts types, and only 5 fonts sizes (font8, font12, font16, font20 and font24). This is unfortunately very limiting :(
This python script is inspired by the waveshare blogpost this. But they do not provide any code to use...
On the other hand the font2bytes from Dominik Kapusta is available but requires C++ compilers.
This is my version made in python. At this moment it only recreates ASCII caracters, but you can use any font and specify any size. (just make sure that it will fit your epaper display)
- Python 3
- Pillow library (NOTE: Pillow and PIL cannot co-exist in the same environment. Before installing Pillow, please uninstall PIL.)
- numpy library
- drop any font you want to use (.tff) within the ./fonts folder
withn the font2bytes.py
-
specify a new name for the font to create
-
specify the font name that you want to use (default is roboto-Regular)
-
specify the height and the width of the new font.
-
run the python script
The python script will generate the new .cpp file within the ./output folder with the desired name
within the waveshare lkibrary source folder (Arduino\libraries\esp32-waveshare-epd\src)
-
add the new .cpp font file
-
open the fonts.h and
-
add a new "extern" line with the name of the new font
E.g.: extern sFONT FontBold40;
-
[OPTIONAL] make sure that the defined MAX_HEIGHT_FONT and MAX_WIDTH_FONT are equal or smaller that the new font size. Update the values if required
-
Use the new font in your script and enjoy!
E.g. Paint_DrawString_EN(5, 0, "waveshare Electronics", &FontBold40, BLACK, WHITE);
within the ./output folder there are already a couple of .cpp files that can be used without running the oython code. Just follow the instructions from the 6th step
TheHeXstyle
LGPL v3.0, see LICENSE for details.