Go Down

Topic: Found available Fonts to use with Adafruit_GFX (Read 1 time) previous topic - next topic

ZinggJM

Mar 14, 2018, 06:48 am Last Edit: Mar 22, 2018, 07:27 am by ZinggJM
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
No personal message please; any question may be useful for other users. Use code tags for code. Make links clickable with URL tags. Provide links to the product in question.

david_prentice

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.

ZinggJM

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. :)

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
No personal message please; any question may be useful for other users. Use code tags for code. Make links clickable with URL tags. Provide links to the product in question.

bodmer

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.
Formerly Rowboteer (now a broken user profile!)

ZinggJM

@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
No personal message please; any question may be useful for other users. Use code tags for code. Make links clickable with URL tags. Provide links to the product in question.

olikraus

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: https://github.com/olikraus/u8g2/blob/master/tools/font/bdfconv/fd.c#L122

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




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

No personal message please; any question may be useful for other users. Use code tags for code. Make links clickable with URL tags. Provide links to the product in question.

bodmer

#7
Mar 17, 2018, 12:17 pm Last Edit: Mar 17, 2018, 12:19 pm by bodmer Reason: Correct link
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.
Formerly Rowboteer (now a broken user profile!)

olikraus

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:

https://github.com/olikraus/U8g2_for_Adafruit_GFX

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](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:
Code: [Select]

#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);
}

ZinggJM

#9
Mar 18, 2018, 06:49 pm Last Edit: Mar 18, 2018, 08:16 pm by ZinggJM
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.
No personal message please; any question may be useful for other users. Use code tags for code. Make links clickable with URL tags. Provide links to the product in question.

ZinggJM

#10
Mar 19, 2018, 02:45 pm Last Edit: Mar 19, 2018, 05:06 pm by ZinggJM
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

No personal message please; any question may be useful for other users. Use code tags for code. Make links clickable with URL tags. Provide links to the product in question.

olikraus

#11
Mar 19, 2018, 07:21 pm Last Edit: Mar 19, 2018, 08:13 pm by olikraus
Hi Jean-Marc

It would be too cool, if you could create issues at https://github.com/olikraus/U8g2_for_Adafruit_GFX/issues

Quote
library.properties might be architectures=*
U8g2_for_Adafruit_GFX will not work on ESP8266 at the moment (ESP32 however should be supported).

Quote
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

ZinggJM

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
No personal message please; any question may be useful for other users. Use code tags for code. Make links clickable with URL tags. Provide links to the product in question.

olikraus



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.


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 *.


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.


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

ZinggJM

#14
Mar 19, 2018, 09:53 pm Last Edit: Mar 19, 2018, 09:55 pm by ZinggJM
I use

Code: [Select]
#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
No personal message please; any question may be useful for other users. Use code tags for code. Make links clickable with URL tags. Provide links to the product in question.

Go Up