Skip to content

How to create new font for the library

Aleksei edited this page Aug 29, 2020 · 3 revisions

How to create new font for the library

The library supports different font formats. To get exact information on font formats supported, please refer to API.

Creating new font using GLCD Font Creator (fixed width fonts)

You can easily add new fonts to your application, using GLCD Font Creator application.

  1. Download and install GLCD Font Creator
  2. Download and install Python 2.7
    • Download and install pip: sudo apt-get install python-pip
    • Download and install freetype_py: sudo pip install freetype-py or pip install freetype-py
  3. Generate the font, you need, in GLCD Font Creator application.
  4. Export created font by pressing "Export to GLCD" button to some file glcdfont.c Export font
  5. Run python script fontgenerator.py from lcdgfx/tools directory

python fontgenerator.py --glcd glcdfont.c -f old > ssd1306font.h

  1. Copy generated font code to your application or include ssd1306font.h file and use the font:
    display.setFixedFont(YOUR_FONT_NAME);
    display.printFixed(0,  8, "Hello", STYLE_NORMAL);
    // OR
    canvas.setFixedFont(YOUR_FONT_NAME);
    canvas.printFixed(0,  8, "Hello", STYLE_NORMAL);

Creating new font from BDF format

Please, use this useful tool developed by mayopan: Link to font converter with instructions

Creating new font directly from ttf font file (fixed width and variable size fonts)

You can easily add new fonts to your application, generating font directly from TTF font file.

Fixed width fonts

  1. Download and install Python 2.7 (if you don't have it)
    • Download and install pip: sudo apt-get install python-pip
    • Download and install freetype_py: sudo pip install freetype-py or pip install freetype-py

sudo pip install freetype-py

  1. Generate the font, you need, directly from ttf file by running python script fontgenerator.py from lcdgfx/tools directory

python fontgenerator.py --ttf FreeMono.ttf -f old > ssd1306font.h

  1. Copy generated font code to your application or include ssd1306font.h file and use the font:
    display.setFixedFont(YOUR_FONT_NAME);
    display.printFixed(0,  8, "Hello", STYLE_NORMAL);
    // OR
    canvas.setFixedFont(YOUR_FONT_NAME);
    canvas.printFixed(0,  8, "Hello", STYLE_NORMAL);

Variable width fonts

  1. Download and install Python 2.7 (if you don't have it)
    • Download and install pip
    • Download and install freetype_py

sudo pip install freetype-py

  1. Generate the font, you need, directly from ttf file by running python script fontgenerator.py from lcdgfx/tools directory

python fontgenerator.py --ttf FreeMono.ttf -f new > ssd1306font.h

  1. Copy generated font code to your application or include ssd1306font.h file and use the font:
    display.setFreeFont(YOUR_FONT_NAME);
    display.printFixed(0,  8, "Hello", STYLE_NORMAL);
    // OR
    canvas.setFreeFont(YOUR_FONT_NAME);
    canvas.printFixed(0,  8, "Hello", STYLE_NORMAL);

check YOUR_FONT_NAME in generated header file.

Use online font creator for the library.

Online font creator by RoboDurden