OpenFontRender icon indicating copy to clipboard operation
OpenFontRender copied to clipboard

Adding a getTextWidth(char* text_buffer) function

Open martinberlin opened this issue 2 years ago • 3 comments

To design stuff sometimes is great to know how much is the text width (Using font size) that you will draw. Lovyan has a function like this:

uint16_t getTextWidth(char* text_buffer);

@takkaO if you give me some pointers on how to do it I can add it myself. On another question: Is possible to speed up just a little bit the drawing? Tried with ESP32 at 80Mhz and also at 160Mhz, the difference is not noticeable, but still I like a lot to see how it draws the font from the binary TTF. Amazing work!

martinberlin avatar Oct 12 '22 14:10 martinberlin

I have issued a pull request that speeds up rendering. This should work with any Adafruit_GFX API compatible library (drawFastHLine fn).

Bodmer avatar Nov 11 '22 12:11 Bodmer

ESP32 renders example "load from binary" now reports 54ms (8 bit parallel interface). If the cache is valid for a repeat render then this reduces to 27ms, which is circa 1ms per character.

Bodmer avatar Nov 11 '22 12:11 Bodmer

That's awesome. I'm using this primarily in some IT8951 (parallel epaper displays) but I'm sending data from ESP32S3 as fast I can per SPI. Will try and see if I can get more speed with your fix. But I'm using @lovyan03 Lovyan GFX as a controller library and they don't use Adafruit but their own GFX.

martinberlin avatar Nov 11 '22 12:11 martinberlin

@martinberlin

getTextWidth and getTextHeight methods have been added. However, if you need both width and height, it is recommended that you use the calculateBoundingBox or calculateBoundingBoxFmt method and get the bounding box instead. You can calculate width and height from bounding box and it is less computationally intensive that way.

takkaO avatar Nov 23 '22 13:11 takkaO

Awesome work will try it before closing the ticket to give you feedback. Thanks a lot!

martinberlin avatar Nov 24 '22 03:11 martinberlin

Thanks TakkaO working as expected. Still didn't try the calculateBoundingBox but I will soon!

martinberlin avatar Jan 13 '23 13:01 martinberlin