Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding a getTextWidth(char* text_buffer) function #5

Closed
martinberlin opened this issue Oct 12, 2022 · 6 comments
Closed

Adding a getTextWidth(char* text_buffer) function #5

martinberlin opened this issue Oct 12, 2022 · 6 comments

Comments

@martinberlin
Copy link

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 martinberlin changed the title How easy is to add a getTextWidth(char* text_buffer) function? Adding a getTextWidth(char* text_buffer) function Oct 12, 2022
@Bodmer
Copy link
Contributor

Bodmer commented Nov 11, 2022

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

@Bodmer
Copy link
Contributor

Bodmer commented Nov 11, 2022

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.

@martinberlin
Copy link
Author

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.

@takkaO
Copy link
Owner

takkaO commented Nov 23, 2022

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

@martinberlin
Copy link
Author

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

@takkaO takkaO added the progress: waiting for confirmation and close Waiting for confirmation and close label Dec 2, 2022
@martinberlin
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants