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

Best way to make a text fill a rectangle? #81

Open
Kerollmops opened this issue Aug 2, 2021 · 3 comments
Open

Best way to make a text fill a rectangle? #81

Kerollmops opened this issue Aug 2, 2021 · 3 comments
Labels
question Further information is requested

Comments

@Kerollmops
Copy link

Hey,

I was trying your library, it seems to be very complete, thank you. I am trying to find the biggest scale of a text to make it fill a rectangle.

I found the Layout struct that outputs the list of glyphs positions, problem is that appending text to this layout requires a px parameter.

What I har in mind was that I could use the Font and my text to know the max ascent and max descent of the glyphs of my text, also using those glyphs to know the width it takes. Then, by using a simple calculus I could compute the scale my text needs to be to fit in height and width in my rectangle.

What do you think? I am not even sure I can rely on a simple multiplication to compute the ideal scale.

@mooman219 mooman219 added the question Further information is requested label Jan 29, 2022
@tasogare3710
Copy link

Hi,

To use unscaled metrics, You can pass Font::units_per_em() to the px parameter, but I couldn't find a way to get side bearing.

In my opinion, we cannot get the other values we need. For instance, the outline rectangle(a.k.a bounding box)*1 is (xMin,xMax,yMin,yMax) in the glyf table.


  1. (advanceWidth, ascender - descender + lineGap) is the outside of bounding box.

@mooman219
Copy link
Owner

mooman219 commented Mar 2, 2022

In my opinion, we cannot get the other values we need. For instance, the outline rectangle(a.k.a bounding box)*1 is (xMin,xMax,yMin,yMax) in the glyf table.

@tasogare3710 This exists and is well documented https://docs.rs/fontdue/latest/fontdue/struct.Metrics.html

@mooman219
Copy link
Owner

@Kerollmops What you want to do is achievable in the API, but you would need to provide your own layout. I don't have any intentions currently to add variably sized layouts, but it's definitely neat. Scale factoring is also well documented.

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

No branches or pull requests

3 participants