Close

Adding custom fonts as libraries

A project log for using uGFX in Arduino

uGFX was written for use with makefiles. Using it in arduino is possible with minimal effort, though. Here's how.

christophChristoph 11/25/2015 at 16:050 Comments

Yes, that works, too!

Here's a sample font library:

~/Arduino/libraries/ugfx-arduino-font-had-logos-98/
.
├── bdf
│   └── had-logos-98.bdf
├── fontdata
│   └── had-logos-98.c
├── readme.md
└── ugfx-arduino-font-had-logos.h

The font is just the hackaday prize logo (wrenched skull with helmet) from 2014 with 98 pixels height, converted from svg (I don't remember where that came from) to bmp to bdf and then to uGFX's font format using their online converter. I might add more later.

You can use just about any font you like, as long as

The header (ugfx-arduino-font-had-logos.h) directly includes the font source:
#include "fontdata/had-logos-98.c"
The font source must not be in the root directory or in src/, because arduino would try to compile it out of context and spit out errors. That's why it's in fontdata/.

In the uGFX config file (gfxconf.h) you'd have

#define GDISP_NEED_TEXT             TRUE
#define GDISP_INCLUDE_USER_FONTS    TRUE
and in userfonts.h:
#include "ugfx-arduino-font-had-logos.h"
More can be added here, and arduino will look up the library with that header and include it. Font collections can be created by having the font header include multiple font source files.

github: ugfx-arduino-font-had-logos

Discussions