How can I use the PROGMEM to load *.ttf font file for selected characters only?

Hi

I am converting a ttf font file to hex array code, then using it on a display connected to ESP32. All works fine.
Since I am using only numbers (0..9, . , ,) , how can I convert the numeric characters only instead all characters from the particular font file?

My last solution will be edit the font file and remove all characters except the numbers, But is there any easier way to achieve this?

Thanks.

doesn't seem like the thread title matches you're problem and should be edited

1 Like

Be more specific

1 Like

I am not following what you are saying. I will take a swag and say you should do a range check on the variable before printing and decide what to do with it if you do not want to print it. You can just ignore it if you like.

Okay. I have updated my question.

But My idea is for, avoid loading other unnecessary characters to save memory.

How are you converting the font, to what format?
If it ends up in flash, is it an actual problem? Are you short on storage space?

Test them before loading and do not load the invalid ones. You will have to read the characters to test or display them so that function does not go away. The other thing is modify the source so it does the filtering.

Depends a lot on what display library you are using. The U8g2 library, as well as the libraries based on Adafruit_GFX, have ways of limiting the range of characters in the font.

The ESP32 does not have PROGMEM as such, that is only applicable to some AVR processors. The ESP32 has flash memory that serves the same purpose, but since it is in the same address space as the ram the PROGMEM methods are unnecessary.

You can extract only the numeric characters from the TTF font file by using a font editing tool like FontForge. Instead of editing the file manually, you can select only the numeric characters (0-9, comma, and period) and export them. This way, you avoid converting the entire font to a hex array and can streamline the process for your ESP32 display. It's definitely easier than manually removing all other characters. I’ve done something similar when designing gym accessories like a Lifting Belt, and it really simplifies the process.

The ESP8266 too but you are right for the ESP32. The PROGMEM macro does nothing.

I am using the #include <TFT_eSPI.h> bodmar library.
ESP32with display: Lilygo ESP32 S3 amoled

I am converting the font to .vlw format using the tool called Processing.

Then using another tool: File to hex converter
to convert it to hex format. Then use the converted hex array data in a PROGMEM command.

So the font will be called using sprite function for smooth operation.

Yes. Editing the font is an option.

You need to understand the target font format to make sure you provide a consistent hex structure defining the characters.

@J-M-L Yes. It is difficult to understand the hex structure for removing unnecessary fonts.
So I am going to export the numeric characters only and make a new font for this purpose. it will only contain 12 characters.

Yes. I had this on my mind. But thought easier to remove some characters in the hex file. But now, I will export the characters needed only to make a new font and use it. will contain 12 char.

OK - sure that’s one way

Are you using the tools included with the TFT_eSPI library? The Create_font.pde file has options for only converting specific characters. There is already a commented out example for the characters needed for a clock (0123456789+-.:apm only), that can easily be changed to what you need.

The tools I am using is from a you tube video mentioned in their video. Did not know there are any tools included with the library . But I will take a look.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.