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

Get width of rendered text #169

Open
l4l opened this issue Dec 13, 2020 · 6 comments · May be fixed by #171
Open

Get width of rendered text #169

l4l opened this issue Dec 13, 2020 · 6 comments · May be fixed by #171

Comments

@l4l
Copy link
Contributor

l4l commented Dec 13, 2020

Is it possible to get a width of rendered text (i.e. draw_text). This particularly useful if there's a need to draw a text with mixing different colors (or perhaps there's an easier way?) so the offset for drawing a block of differently colored text is known.

@jrmuizel
Copy link
Owner

It shouldn't be too hard to add something like this, a la measureText() from HTML canvas.

@l4l l4l linked a pull request Dec 20, 2020 that will close this issue
@tiye
Copy link

tiye commented Sep 10, 2021

noticed we don't have align: center for text yet, can we rely on this to center?

@J-Cake
Copy link

J-Cake commented Oct 13, 2022

I ended up using my own text rendering system using rusttype. It works well and it's decently fast

@l4l
Copy link
Contributor Author

l4l commented Oct 15, 2022

I encountered quite poor performance with rusttype but probably it was due tofill_rect (versus draw_image) and didn't spend much time figuring out why. So I ended up with fontdue crate instead. Here is all that you need to draw text with it.

@J-Cake
Copy link

J-Cake commented Oct 18, 2022

I ran into a few quality issues as well, but I found that to be the font face I was using. I tested mine with Raleway, Rasa, Lora, Inconsolata and DejaVu from Google Fonts, and they all worked well. Only NotoSans didn't really work that well

@ion232
Copy link

ion232 commented Mar 23, 2023

I tried both methods and found that the fontdue crate worked best in my case. The font I was using (PokemonGB) was crashing due to a negative min bounding box in the rusttype method.

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

Successfully merging a pull request may close this issue.

5 participants