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

Rasterize a whole string #128

Open
Inspirateur opened this issue Oct 30, 2022 · 3 comments
Open

Rasterize a whole string #128

Inspirateur opened this issue Oct 30, 2022 · 3 comments
Labels
documentation Improvements or additions to documentation

Comments

@Inspirateur
Copy link

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.

@gwy15
Copy link

gwy15 commented Jan 8, 2023

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

@Inspirateur
Copy link
Author

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

@mooman219 mooman219 added the documentation Improvements or additions to documentation label Apr 23, 2023
@mooman219
Copy link
Owner

mooman219 commented Apr 23, 2023

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.

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

No branches or pull requests

3 participants