-
Notifications
You must be signed in to change notification settings - Fork 20
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
scale height to (ascender-descender), preserve aspect, center width #255
Conversation
f6dea44
to
9c34b3f
Compare
A great improvement, with PR #256, the generated color icons have almost the same effect as the black and white icons in iconfont. |
ty for sharing that example! |
Yeyh for fixing #2, big thanks! |
@drott Next is waiting for you to fix Chrome's COLR font blurring problem. |
Let's stay on topic on this PR. If you are referring to https://bugs.chromium.org/p/chromium/issues/detail?id=1112051 - please comment there (and optionally attach screenshots) if you observe this issue for COLRv1 as well. |
looks like I'm only using the default --width when parsing gradients, and not taking into account a potentially scaled glyph advance widths (by aspect ratio) that we apply for the outlines when the viewbox is non-square. I'll fix that in a follow-up commit.
Fixes the previously failing test
I deliberately did not use absl.flags validators because those would not check if an invalid value was passed via config file, as opposed to CLI flags. There's probably a cleverer way, but at least this works for both.
Previously, I was simply scaling the FontConfig.width by the aspect ratio. But that can produce unintended consequences if the default width != font height (ascender-descender): e.g. if one wanted to pad glyphs on both sides (like we do with noto-emoji) by setting a wider default width than the font height, the impact of non-square viewbox on that padding would be even greater as the viewbox gets wider. It's better to do this: given the font height and the viewbox aspect ratio, scale font heigth by aspect ratio to obtain the scaled advance width; ise the latter if it's larger than the default width, otherwise use the default width (and place things centered). A user can play with the default --width (even set it to 0) until they like it. This effectively becomes the minimum default advance width, to be used only used when the proportional advance width that is computed from the viewbox width (relative to its height which is fixed to ascender-descender) is smaller. Yeah, I think I like that.
Two new notable changes:
def _color_glyph_advance_width(view_box: Rect, config: FontConfig) -> int:
# Scale advance width proportionally to viewbox aspect ratio.
# Use the default advance width if it's larger than the proportional one.
font_height = config.ascent - config.descent # descent <= 0
return max(config.width, round(font_height * view_box.w / view_box.h)) |
LGTM |
The ascender/descender forms are more common in typography. Also UFO and the Oxford English Dictionary agree with me.
b5d45be
to
40fff1b
Compare
Fixes #2 (comment) and #230
Previously we were mapping the SVG viewBox to UPEM square (0, 0, upem, upem), stretching it when the aspect ratio was not square, and setting the advance width to the same monospaced value.
After this PR: