fontdue icon indicating copy to clipboard operation
fontdue copied to clipboard

Rasterize a whole string

Open Inspirateur opened this issue 2 years ago • 3 comments

Hi, I'm making a wordcloud program and I'd like to be able to convert a whole string such as "Hello world" to a bitmap directly, like we can already do with individual chars.
Could this be added to fontdue ?

If this feature is out of scope for the library could you help me in implementing that ?
I'm lost in all the Layout and Metrics parameters and I'm not sure how to interpret them, especially the negative xmin and ymin of Metrics.

Inspirateur avatar Oct 30 '22 10:10 Inspirateur

I ran into the same problem when trying to put text on opencv's Mat. To me, it seems I have to rasterize char by char and it is especially hard considering that advance_width is actually a f32 instead of i32.

I'd appreciate if anyone can share a solution for this, maybe something like rusttype's example to make a image

gwy15 avatar Jan 08 '23 12:01 gwy15

I ran into the same problem when trying to put text on opencv's Mat. To me, it seems I have to rasterize char by char and it is especially hard considering that advance_width is actually a f32 instead of i32.

I'd appreciate if anyone can share a solution for this, maybe something like rusttype's example to make a image

I actually succeeded in rasterizing a string ! Wasn't too complicated, documentation was just somewhat lacking (and my own understanding of the topic is poor too).

Check out this project for a concrete example https://github.com/Inspirateur/wordcloud-rs/blob/main/src/text.rs

Inspirateur avatar Apr 19 '23 16:04 Inspirateur

Rendering a string is tightly coupled to your render pipeline, which isn't something fontdue wants to get involved with.

Ideally it is basically just make a layout, append your text to the layout, then iterate though layout.glyphs() and perform whatever operation you need to do on each glyph. Usually it's rasterizing them, caching them in an atlas, and generating sprites.

I'll leave this issue open, I probably need some kind of example for a whole string if it's not clear in its current state.

mooman219 avatar Apr 23 '23 07:04 mooman219