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

Top of text is slightly clipped in ab-glyph 0.2.12 but not in ab-glyph 0.2.11 #50

Closed
MichaelMMacLeod opened this issue Dec 11, 2021 · 5 comments

Comments

@MichaelMMacLeod
Copy link

MichaelMMacLeod commented Dec 11, 2021

I've got a graphical program that transitively depends on ab-glyph (wgpu_glyph -> glyph-brush -> ab_glyph). I recently ran cargo update and noticed some text clipping I hadn't seen before. The change seems to be caused by upgrading ab-glyph 0.2.11 to ab-glyph 0.2.12.

The text clipping doesn't seem to happen with every font.

I've created a repository with scripts to run example code against the two versions. The example it runs is the hello example from wgpu_glyph, modified to use a font that clips in 0.2.12 but not 0.2.11. It also contains the glyph-brush crate modified to use a specific ab-glyph version (either 0.2.12 or 0.2.11, depending on which script is run). The code requires a unix-like environment with basic utilities (e.g., tar, mv, etc.).

https://github.com/MichaelMMacLeod/debugging-font-weirdness

Running the 0.2.11 example results in the following (which seems correctly displayed):

Screenshot_20211211_145430

Running the 0.2.12 example results in the following (where the top of the text gets slightly clipped):

image

The text also appears a bit bigger in 0.2.12 than it did in 0.2.11 (which might be why it's clipping).

@alexheretic
Copy link
Owner

alexheretic commented Dec 11, 2021 via email

@MichaelMMacLeod
Copy link
Author

I'm using CooperHewitt-OTF-public/CooperHewitt-Book.otf from https://uh8yh30l48rpize52xh0q1o6i-wpengine.netdna-ssl.com/wp-content/uploads/fonts/CooperHewitt-OTF-public.zip. (the download link comes from https://www.cooperhewitt.org/open-source-at-cooper-hewitt/cooper-hewitt-the-typeface-by-chester-jenkins/)

The font is also inside the tarball of crates in https://github.com/MichaelMMacLeod/debugging-font-weirdness. After running one of the scripts you can cd into the directory the script created and then cd wgpu_glyph/examples to find the font there as well.

@alexheretic
Copy link
Owner

I discussed this upstream its caused by the taller glyphs going out of the ascender/descender font metrics. Whereas I expect all glyphs to fit inside the ascender/descender bounds... otherwise I'm not sure what use they are. The values from ttf-parser have changed (0.12 -> -0.13), however they match freetype, so unfortunately can't be simply fixed upstream.

It's possible this is a bug with the font itself, there are some related reports cooperhewitt/cooperhewitt-typeface#11. However, font specs aren't perfect so maybe the font designers don't see this as a bug.

It's not really a bug with ab-glyph either as it is reporting the correct values according to ttf-parser.

It is more related to glyph-brush-layout. I did notice that using the line_gap value as v-padding for the first line essentially fixes the issue. However, I'm not sure if that's the correct behaviour for all fonts in general.

@alexheretic
Copy link
Owner

We can discuss the potential fix here

@MichaelMMacLeod
Copy link
Author

Thanks for the investigation---I appreciate the work you've put in to address this issue. Unfortunately, I don't know much about the implementation of fonts, so I can't really comment about whether or not overflowing of the ascender / descender bounds is a problem with this specific font or just a weird edge-case that font rasterizers aught to handle.

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

No branches or pull requests

2 participants