Adding TrueType/OpenType font support

Hello.
I wrote htcw_gfx which includes TTF/OTF support.
It is cross platform and works with a small amount of RAM, streaming the font file off of storage.

It is based on some public domain code I found, so I have full control over licensing of it.

I would like to add it to LVGL, but I was told to open an issue on github to move forward. I went to github and the issue template told me to come here.

I’ve used it on ESP32s, ARMs, and SAMDs

The two main things that keep me from doing integrating it, are I am far more versed at C++ than C, and the code is currently (but not heavily) C++ - though that can be ported. The other thing is I cannot find my way around LVGL’s codebase

Here’s what I would need in order to integrate TTF/OTF support:
In order of effectiveness from least effective to most effective:
I need either some sort of comprehensive guide to the source.
I need people I can ask questions of regarding the source for LVGL.
Actually help on this from one seasoned LVGL developer would be ideal.

Is there a way we can make this happen?

1 Like

I would love to see support for this in LVGL :slight_smile:

It’d be amazing to make LVGL support a lightweight TTF library like yours. :slight_smile:

It’s not a problem if it’s mainly in C++, I believe we can hide it behind a C API. Most of the embedded compilers are supporting C++ so it’s fine to have an optional module in C++.

Here you can see how to add a new font engine to LVGL.

Can you point to me to the right place where I can see the API of your font engine?

Absolutely, although it’s messy, and it’s buried under something “clean”

See files at src/stb_*.* for the headers
and src/open_font.cpp for the implementation
Those files are the underlying TTF implementation.
Basically what I did is take a public domain TTF renderer designed for PC game engines, and changed it to stream, and to use low memory environments otherwise. It’s ugly code, even before I got to it, but it works.

It uses a separate library to handle streams, so you won’t see that code in there. It’s the code I’d have to adapt but it’s easy because everything is behind accessor methods.

I found a major problem integrating with LVGL. The issue is that creating bitmaps for truetype fonts doesn’t work. First, they are anti-aliased meaning any bitmap needs to be created with data beneath it - effectively it needs to alpha blend. In addition due to kerning, TTF cannot render bitmaps for glyphs because they would overlap and obscure each other.

I figured all that out - i just needed to familiarize myself with the API

I’ve just replied on GitHub :slight_smile: