Go Down

Topic: Creating your own fonts for Adafruit TFT (Read 224 times) previous topic - next topic

carguy

Hello,

so I've installed GLCD Font Creator and I have generated the uint8_t code for a font that I want to use in my project (using a 7-segment "digital" font to imitate a classic seven-segment LCD display). It looks something like this_


Code: [Select]


//Font Generated by MikroElektronika GLCD Font Creator 1.2.0.0
//MikroElektrnika 2011
//http://www.mikroe.com

//GLCD FontName : Digital7
//GLCD FontSize : 16 x 27

const unsigned short Digital7[] PROGMEM = {
   0x00,
   0x00,
   0x20,0x00,
   0x7F,0x00,
   0x1B,
   0x00,
   0x01,0x88,0x01,0x00,
 

// yadayadayada...

        };



So now what do I actually do with it? I've tried simply saving this file as "Digital7.h" in the fonts folder in the Adafruit GFX library, but when I try to incorporate this font into my sketches, I get error messages.

What is the correct code syntax within your own "myOwnFont.h"-type files that the Arduino IDE needs in order to compile a sketch?

Sorry, really still kinda new at using fonts and displays.

bodmer

The official Adafruit GFX library only handles two font formats. A basic 7x5 character in file "glcdfont.c" file and specially encoded fonts in the "Fonts" folder.

Adafruit provide a utility in the fontconvert folder to make you own from the FreeFonts library or TrueType fonts which are available on the internet. However you will need to be a bit of a Linux Guru to get the fontconvert program running and I have not seen a tutorial on this.

If you want to create fonts in another format and use them, then you will have to write your own code to render them to the screen.
Formerly Rowboteer (now a broken user profile!)

WillCut

bodmer,

I need to get a custom font as well... The sizes for the ones included wont work, I  need something a smidgen smaller. Who do we have to start nagging to get a solution other than that fontconverter nightmare. not all of us are linux weenies.

carguy

yeah, sadly, I don't know the first thing about Linux.

Maybe I will try another approach - I've seen pictures online of displays hooked up to an Arduino where somebody actually had seven-segment LCD font on their TFT.

Is there a ready to use, Adafruit compatible font like that?

david_prentice

#4
Aug 16, 2016, 09:00 pm Last Edit: Aug 16, 2016, 11:05 pm by david_prentice
Adafruit_GFX supports the historic 7x5 font.   And the FreeFonts style.

I have converted the default UTFT Fonts to the Free format.  i.e. Small, Big, SevenSegment.
Just copy FreeDefaultFonts.c  from my GitHub site.

I have a sketch somewhere that converts the UTFT font style.
And can convert the Codevision's style of font.
It does not convert MikroElektronika fonts.    I suppose I could support them if people genuinely wanted them.

Note that the GFX rendering is a bit of a pain.  i.e. it is always transparent.  It draws from a baseline and not from the top.

Someone said they wanted something smaller than 7x5.   I think I did a 5x3 into Free style.    Heaven knows why anyone would want 5x3.  It looks horrible.

David.

bodmer

Someone said they wanted something smaller than 7x5.   I think I did a 5x3 into Free style.    Heaven knows why anyone would want 5x3.  It looks horrible.

The new Adafruit_GFX library has a TomThumb 3x5 font in the Fonts folder but it is not one I have used.

Your convert utilities sound promising  :)
Formerly Rowboteer (now a broken user profile!)

WillCut

I finally got that font converter working. Installed VMware Player, created a ubuntu VM and then made sure the two dependencies were installed. After that the program complied and started working like a charm.

sudo apt-get install libfreetype6-dev was the key in my case.

I know the GFX rendering is a pain in the arse for fonts and I prefer how bodmer's works with the background color of the font but sadly his renders a LOT slower on my ST7735R.

bodmer

#7
Aug 19, 2016, 02:26 am Last Edit: Aug 19, 2016, 02:29 am by bodmer
I know the GFX rendering is a pain in the arse for fonts and I prefer how bodmer's works with the background color of the font but sadly his renders a LOT slower on my ST7735R.
Something must be wrong with your setup if this library is running slow. As a performance comparison if all the delays are taken out the graphicstest example that is built into the Adafruit_ST7735 library it completes the test in 8.62s, if you run the same test on the TFT_ST7735 library (called graphicstest_small) it runs in 1.707s which is a remarkable 5x faster.

Running the TFT_Char_Time example in the TFT_ST7735 library should give figures in the range 0.2ms per character for a numeral the small adafruit GLCD font, up to 10.1ms for the extra large custom Font 8 which has 72 pixel high characters.

At the moment the TFT_ST7735 library does not support the FreeFonts format, however the Mega and Due 16 bit libraries do.

The Adafruit FreeFont format does something no other TFT library does and that is handle characters that overlap, ie in an italic font the tail of a "y" tucks under the previous character. This makes rendering background too a pain but this is achieved in the 16bit libraries mentioned above by determining the string length in pixels then doing a block erase.
Formerly Rowboteer (now a broken user profile!)

WillCut

#8
Aug 20, 2016, 12:09 am Last Edit: Aug 20, 2016, 12:15 am by WillCut
I'm using a teensy, I assumed that had something to do with it being slower. I guess its not optimized for it.  Also, was getting some font corruption if my sketch hit a certain size.

bodmer

I'm using a teensy, I assumed that had something to do with it being slower. I guess its not optimized for it.  Also, was getting some font corruption if my sketch hit a certain size.
Ah! I am amazed it worked at all on a Teensy!

The library is written purely for 8 bit AVR processors (UNO, Mega or Leonardo and variants).

I guess the IDE you are using ignored the avr architecture constraint in the library.properties file.
Formerly Rowboteer (now a broken user profile!)

carguy

#10
Aug 20, 2016, 03:28 pm Last Edit: Aug 20, 2016, 06:43 pm by carguy
@david_prentice:

Somehow, I couldn't get your font library to work... and I have to say the font rendering of Adafruit's own free fonts that come with this display looks very disappointing, even taking into consideration the obvious limitations of a stamp-sized TFT display (I used to be a web site programmer and graphics designer, so it jumps out at me when fonts are poorly rendered or displayed).

And I've thought of another approach that would be slightly more flexible and reusable... a slightly crazy idea; what if I write a function that converts an integer into a series of small bmp files that show the numbers from 0 to 9?

That function would then convert an integer or float into a character string, and go down the string, array member by array member, and load the corresponding .bmp file to display that digit on the screen.

The advantage would be that if well written, such a function would also make it possible to use various different fonts.

Or would this slow down display refresh times by too much?

This is all for a CarDuino, and I plan to update the display every three seconds with new data.

david_prentice

@carguy,

Which Arduino model?
Which Adafruit_GFX version?
Which MCUFRIEND_kbv version?

Note that the Library Manager does not seem to install the current GFX Master branch from GitHub.

The FreeFonts render just fine with the current GFX library.
I am not sure how the Manger chooses what to install.

I would expect a Manager to install a Release (if available)
Or the current "master" branch which is likely to be Beta in progress.

David.

bodmer

... and I have to say the font rendering of Adafruit's own free fonts that come with this display looks very disappointing, even taking into consideration the obvious limitations of a stamp-sized TFT display (I used to be a web site programmer and graphics designer, so it jumps out at me when fonts are poorly rendered or displayed).

The small size freefonts do look a bit ugly due to the way they are automatically digitised by software. The larger ones render quite well.

Your quality expectations are high so look at this library which supports anti-aliased fonts, but you won't match the high end graphics performance seen in Web pages.   There is a PC display design GUI too.  I have not used either myself.
Formerly Rowboteer (now a broken user profile!)

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy