jrmuizel / raqote

Rust 2D graphics library

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Get width of rendered text

l4l opened this issue · comments

commented

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.

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

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

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

commented

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.

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

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.