Found available Fonts to use with Adafruit_GFX

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

Yes, indeed:

void Adafruit_GFX::drawFastHLine(int16_t x, int16_t y,
        int16_t w, uint16_t color) {
    // Update in subclasses if desired!
    startWrite();
    writeLine(x, y, x+w-1, y, color);
    endWrite();
}

drawFastHLine does not work with w=0. I did my tests with the SSD1306 library which probably did overload (changed) the drawFastHLine() to a better version which does not do something for w=0.

Well, I can fix this, but I would call this a bug in the Adafruit GFX library.

Oliver

@Oliver

I just have verified this with my newly modified UC1701 clone:

class UC1701: public Adafruit_GFX
{
  public:
    UC1701(uint8_t cs, uint8_t dc, uint8_t rst);
    void drawPixel(int16_t x, int16_t y, uint16_t color);
    void drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color)
    {
      if (w > 0) Adafruit_GFX::drawFastHLine(x, y, w, color);
    }
    // display the buffer content
    void display();
    void begin();

the artifacts have disappeared.

Thank you!

Jean-Marc

Yes, I fixed it also: Do not call Adafruit GFX hline/vline procedures for len=0 · Issue #4 · olikraus/U8g2_for_Adafruit_GFX · GitHub

Oliver

I have created a new release for download:

All discussed points should be fixed from my perspective.

Oliver

olikraus:
I have created a new release for download:
Release 1.1.0 · olikraus/U8g2_for_Adafruit_GFX · GitHub

All discussed points should be fixed from my perspective.

Oliver

Hello Oliver,

I am testing U8g2_for_Adafruit_GFX on an ESP32 with an RGB matrix, and it works pretty well. I am delighted to finally be able to display French accents on dynamic texts that scroll. Congratulations for your work.

I would like to ask you two questions:
Question 1:
With the original font and graphics drawn by Adafruit GFX, I can display all the colors. But if I select a U8g2 font, it can not be displayed in blue, or in colors that contain blue. I guess there must be a little oversight somewhere in the code. Do you have an idea ?

Question 2:
I would also like to know if it is possible to load 2 or 3 fonts (or more) into the memory of the ESP32 and select them dynamically?

Thank you very much.

[EDIT]
For my second question, I think that by creating individual functions with different fonts, he has to load them all into memory. To check...

Question 1:
With the original font and graphics drawn by Adafruit GFX, I can display all the colors. But if I select a U8g2 font, it can not be displayed in blue, or in colors that contain blue. I guess there must be a little oversight somewhere in the code. Do you have an idea ?

Can you provide your code? Did you use setForegroundColor() function here?

Question 2:
I would also like to know if it is possible to load 2 or 3 fonts (or more) into the memory of the ESP32 and select them dynamically?

Just assign the font to setFont() function. There is no limit for the number of the fonts except for the flash memory size.

Oliver

An old but relevant thread...

I have forked the Adafruit_GFX library here and added UTF-8 encoded string support to the print stream handler which is an essential need for adding extended range font characters.

The tweaked library now supports 16 bit point codes so the characters/glyphs/graphemes in the entire Unicode Basic Multilingual Plane are now available to the library users. I tested this with the stock Adafruit_ILI9341 library.

The example attached to this post demos the extended capability for the Japanese Hiragana glyphs:

See the comments in the example for the link to the YouTube video and fontconvert utility I used in a Windows environment. Note that most online converters only generate character codes in the range 32-127, so unfortunately the command line utility is the only way to generate the extended range character set fonts at the moment.

Here is another screenshot with characters from the 32-255 code point range showing some of the extended ASCII accented characters.

I have generated a "pull request" to encourage Adafruit to incorporate this enhancement but I suspect they may need some further encouragement :wink: from users.

hiragana_example.zip (19.2 KB)