Found available Fonts to use with Adafruit_GFX

Hi,

Libraries with display classes that inherit from Adafruit_GFX get FreeFont fonts from Adafruit_GFX.
These fonts are limited in the character set they support, and size. Font converters exist to add fonts.

I am looking for existing fonts that can be used unmodified with Adafruit_GFX.

Are there e.g. libraries that use fonts that are directly compatible with Adafruit_GFX?

Are there libraries with font support that could be easily bridged to other existing libraries, e.g. by overriding the drawPixel() method (which would need to be virtual to do this).

Or are there alternatives to Adafruit_GFX or clones with more fonts?

I just looked for forks of Adafruit_GFX, there are currently 661, so I can't check through all of these.

Any other ideas to achieve this with limited effort?

Thank you

Jean-Marc

Adafruit_GFX comes with a utility to create FreeFont format fonts.
It probably works fine on Linux. I have never been able to compile it on Windoze.

I have written a sketch that will convert some popular microcontroller fonts to FreeFont style.
e.g. MikroElektronika, Codevision, UTFT, ...

My sketch is not suitable for general use. Punters often want enormous digits. Note that the FreeFont format has size limitations. In practice you can't really have fonts that are more than 128 pixels high. The GFX code does not support Unicode.

What font(s) do you want to convert?

You have to apply a certain amount of common sense to these issues.
A 240x320 or 128x160 screen is best served with normal font bitmaps.
If you want a PC sized screen and a font to be rendered in multiple sizes, you would need processing power and memory.

Yes, drawing text with background can be done very efficiently in hardware.
The GFX FreeFont is only rendered transparently i.e. with drawPixel()

David.

Hi David,

I would prefer not to have to convert any fonts, just use existing fonts.

I have been asked for additional fonts for my GxEPD library for e-paper displays, e.g. bigger fonts or Umlauts.

So I am looking for ideas to achieve that with the least effort possible. :slight_smile:

I will look through all TFT libraries I know or have ever loaded.
I would prefer to reference the fonts of such a library over copying them, for update reason.
Most likely I will need to copy the font rendering code; better would be if I can do a bridge pattern class, this may be possible for libraries that inherit from Adafruit_GFX, if it renders through drawPixel().

There is actually extensive font support and development in U8G2, but this code is too complicated for me.

Jean-Marc

The simplest minimal effort approach is to point users to the Adafruit fontconvert utility and let them generate the font styles and sizes they need. Common fonts like Arial are protected by copyright even when encoded in a new font file, hence the use of SIL/GNU free fonts by Adafruit. There are some already generated fonts available but users will not know what they have got unless the font is adequately described. Some look quite poor due to odd pixels at the glyph boundaries but these can usually be eliminated by changing the point size slightly.

There is an online converter here that users could try.

For Windows users the guide here worked for me.

This comment indicates limitations for including the extended character set that includes characters with diacritical marks.

One option is to adapt code from (or use) this library, but that involves some work and forward compatiblity with the evolving Adafruit master will eventually get lost....

The primary limitation of the Adafruit font format is that the character code point is used as an index, so you end up with adding lots of rarely/never used characters to the set. This could be fixed by extending the Glyph struct to include the code point and then search for the code.

@bodmer

I highly appreciate your help! This will get me started on solid ground. Thank you.

I will add a link to your post for a start.

Jean-Marc

ZinggJM:
There is actually extensive font support and development in U8G2, but this code is too complicated for me.

Jean-Marc, you never asked for support here...

The u8g2 font decoding algorithm is independent from the u8g2 library. It breaks down everyrhing to horizontal line draw statements: u8g2/tools/font/bdfconv/fd.c at master · olikraus/u8g2 · GitHub

Complexity is added by some other restrictions which are independent from U8g2 font format: For AVR based Arduino Boards the font decode must support PROGMEM access. For Umlaut and other glyphs UTF-8 support is required (Arduino IDE comes with an UTF-8 code editor).

Oliver

Oliver, thank you very much. At first sight, this code should be understandable for me.

My approach, pulling on one hair, method write() of the library, and following calls downward, failed.
Diving to the bottom, to the buffer(s), and try searching upwards was interesting to see how the buffers are implemented in U8G2, but didn't look like the rope to climb up.

I will look at the details of font decode, to see how I can use it. Thank you.

Jean-Marc

I came across this font editor, so now it is possible to edit the Adafruit style fonts to fix the odd and missing pixels in glyphs or even change a character to another.

ZinggJM:
Oliver, thank you very much. At first sight, this code should be understandable for me.

My approach, pulling on one hair, method write() of the library, and following calls downward, failed.
Diving to the bottom, to the buffer(s), and try searching upwards was interesting to see how the buffers are implemented in U8G2, but didn't look like the rope to climb up.

I will look at the details of font decode, to see how I can use it. Thank you.

Jean-Marc

I have created an extension for the Adafruit GFX library, which makes all U8g2 fonts available to all Adafruit GFX based libraries:

Simply connect U8g2-for-Adafruit-GFX library to an existing graphics library and output text with U8g2 fonts.
I hope it will also work with your libraries (like https://github.com/ZinggJM/GxEPD2_AVR).

U8g2-for-Adafruit-GFX is not yet available in the library manager, but I will raise a ticket for it soon. Meanwhile just download the zip file and install it via the Arduino "Add Zip Library" menu entry.

Let me know if there are any issues.

Oliver

Example code:

#include <Adafruit_SSD1306.h>
#include <U8g2_for_Adafruit_GFX.h>

Adafruit_SSD1306 display(/*MOSI*/ 11, /*CLK*/ 13, /*DC*/ 9, /*RESET*/ 8, /*CS*/ 10);
U8G2_FOR_ADAFRUIT_GFX u8g2_for_adafruit_gfx;  // connector object

void setup() {
  display.begin(SSD1306_SWITCHCAPVCC);
  u8g2_for_adafruit_gfx.begin(display);                 // connect u8g2 procedures to Adafruit GFX
}

void loop() {  
  display.clearDisplay();                               // clear the graphcis buffer  
  u8g2_for_adafruit_gfx.setFontMode(1);                 // use u8g2 transparent mode (this is default)
  u8g2_for_adafruit_gfx.setFontDirection(0);            // left to right (this is default)
  u8g2_for_adafruit_gfx.setForegroundColor(WHITE);      // apply Adafruit GFX color
  u8g2_for_adafruit_gfx.setFont(u8g2_font_helvR14_tf);  // select u8g2 font from here: https://github.com/olikraus/u8g2/wiki/fntlistall
  u8g2_for_adafruit_gfx.setCursor(0,20);                // start writing at this position
  u8g2_for_adafruit_gfx.print("Hello World!");
  u8g2_for_adafruit_gfx.setCursor(0,40);                // start writing at this position
  u8g2_for_adafruit_gfx.print("Umlaut ÄÖÜ");            // UTF-8 string with german umlaut chars
  display.display();                                    // make everything visible
  delay(2000);
}

This is exactly what I was looking for (and didn't dare to propose or ask for).
I will look at it tomorrow.

Thank you very much.

Jean-Marc

Yes, this should work "out-of-the-box". All GxEPD and GxEPD2 classes are (inherit from) Adafruit_GFX.

The example will be slightly different: display.display() is display.update() in GxEPD, and in GxEPD2 the drawing calls go into a picture loop (paged display). For GxEPD this works only for full buffered display. I will make it available also through the GxFont_GFX switch-bridge class, to make it available with the GxEPD drawPaged() methods.

I will check tomorrow and create examples for my libraries.

Oliver, thank you very much!

I have added GxEPD2_32_U8T2_Fonts_Example to the library GxEPD2_32 for experimental use.

I encountered the following issues:

library.properties might be architectures=*

println does not start a new line

void setForegroundColor(uint8_t fg); should take uint16_t to use with 3-color EPD
or a hint for which value to use to produce 16bit red color to drawPixel.

the 2 fonts I tried so far have some artefacts (additional pixel points).

a method returning the font height would be nice.
a method returning the width for a string would be nice.

I have added GxFont_GFX_Example to GxEPD

To enable use of U8g2_for_Adafruit_GFX it needs to be enabled in GxFont_GFX.h

Jean-Marc

Hi Jean-Marc

It would be too cool, if you could create issues at Issues · olikraus/U8g2_for_Adafruit_GFX · GitHub

library.properties might be architectures=*

U8g2_for_Adafruit_GFX will not work on ESP8266 at the moment (ESP32 however should be supported).

the 2 fonts I tried so far have some artefacts (additional pixel points).

U8g2_for_Adafruit_GFX calls the hline and vline procedures. Both function might be on, partly on or off the screen. So both procedures must do proper clipping. Did you have some chars being partly outside the screen?

Oliver

Hi Oliver

I did not know if you prefer feedback here or by issues, and I did not test enough to confirm issues.

I did my experiments on ESP8266; I was not sure about pgmspace use, as I didn't see it, but it looks like it works on Wemos D1 mini.

I can do tests with other platforms, e.g. Arduino Due, ESP32, STM32 or Arduino Pro mini.
I wonder if code space will be an issue on AVR.

Clipping is done in the drawPixel methods of the GxEPD and GxEPD2 classes, so I would not notice.
But I can add diagnostic output to check. I don't expect any foldback effects.

I have just started to use this formidable new feature; I may report more details or analysis.

Thank you

Jean-Marc

ZinggJM:
I did not know if you prefer feedback here or by issues, and I did not test enough to confirm issues.

It is better for tracking. I do not always look at forum entries. I also have more control with github issues. I can assign issues to the next milestone and can close them.

ZinggJM:
I did my experiments on ESP8266; I was not sure about pgmspace use, as I didn't see it, but it looks like it works on Wemos D1 mini.

PROGMEM is not an issue (although there are some tricks because of the sections), but the problem is, that ESP8266 does not have byte access (at least in history). Anyway if ESP8266 works, then we can set architecture to *.

ZinggJM:
I can do tests with other platforms, e.g. Arduino Due, ESP32, STM32 or Arduino Pro mini.
I wonder if code space will be an issue on AVR.

Full chinese font requires more than 200K. Other fonts require less space. It works, but it depends on the fonts.

ZinggJM:
Clipping is done in the drawPixel methods of the GxEPD and GxEPD2 classes, so I would not notice.
But I can add diagnostic output to check. I don't expect any foldback effects.

I can just guess. For example I call "drawFastHLine(x,y,len,color);". It should do nothing if len is zero and should do proper clipping for calls like "drawFastHLine(-2,4,5,1);"

Oliver

I use

#if defined(ESP8266) || defined(ESP32)
#include <pgmspace.h>
#else
#include <avr/pgmspace.h>
#endif

Then byte array can go into program space with PROGMEM. Otherwise the compiler reserves RAM and copy-initializes the byte array there. The ESP8266 creates exceptions if program space bytes are accessed without pgm_read_byte().

All drawing methods except drawPixel() (and some drawBitmap()) are handled by Adafruit_GFX in GxEPD.

Jean-Marc

I do not now of any pgmspace.h include on the ESP8266. Instead there was a discussion and solution here:

The other problem is the byte access. More specific I talk about this code: u8g2/csrc/u8x8_8x8.c at master · olikraus/u8g2 · GitHub
Exactly this code is not there for U8g2_for_Adafruit_GFX and this is why I wonder why it still works.

All drawing methods except drawPixel() (and some drawBitmap()) are handled by Adafruit_GFX in GxEPD.

I need more information on your problem. At least code and a picture of the extra (wrong) pixel would be great.

Meanwhile I have created several issues on the project page for U8g2_for_Adafruit_GFX page.

Oliver

I have a tool to ensure the compatibility of the fonts from the various libraries of Arduino - a converter that reads C files. no difficulties, just open the file and save in a new format. there are plans to continue the project and add supported formats. taking this opportunity to ask you, Oliver, to give a description of the U8glib and U8g2 fonts. hard to parse yourself)

DenSyo:
I have a tool to ensure the compatibility of the fonts from the various libraries of Arduino - a converter that reads C files. no difficulties, just open the file and save in a new format. there are plans to continue the project and add supported formats. taking this opportunity to ask you, Oliver, to give a description of the U8glib and U8g2 fonts. hard to parse yourself)

There is no description as such. Some description is in the decoder:

and the encoder:

There is also a independent c decoder:

Hope this helps,
Oliver

Good Morning Oliver

const char array in code space on 32bit processor, e.g. ESP8266

const uint8_t BitmapExample1[] = {...}; consumes RAM with compiler for ESP8266

After having asked these questions and looking at the processor spec I knew to use pgmspace with ESP8266 on Arduino IDE. Asking why pgmspace.h resides in different locations cause some "political" answers.

I get the same results on Arduino Due.

Maybe I should check also with a monochrome pixel LCD, but I think I used it with U8G2, think I even reported successful use.

Jean-Marc

ok, it somehow looks like, that len=0 does not work with the Adafruit GFX

Oliver