-
Notifications
You must be signed in to change notification settings - Fork 296
Support variable font weight ranges + JS function weights #757
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
Conversation
|
I'm trying to think of a concrete use case for why I would specify a desired range of my variable font other than the entire valid range (1-1000) - it's not validated against when setting explicit weights in font draw styles. One case might be where a user wants to swap out a font in the YAML without changing anything else, but also wants to clamp the allowed weights to an acceptably legible range based on the design of that specific font... LGTM |
|
@bdon that is a good question, and I was about to say maybe we should just drop it entirely and assume the full range. However... I would need to check again, but I think that the font may not report as loaded at all unless a valid weight is provided, e.g. in this syntax, if the first provided value in the range exists in the font. I'm not 100% sure, and the behavior may vary across browsers as well. If we want to add support for this in Tangram ES, we also may need explicit values as it will be using a different font mechanism. We need to care about the font being loaded and with correct settings because if we render too soon then the first tile may render with the wrong font, but |
|
I did some testing across browsers (safari, firefox, chrome) with the 1-1000 range specified. It works fine so far, but I did discover that setting Chromium ticket: Issue 1064756: font-style: italic doesn't activate the ital axis of variable fonts I don't think this a blocker for merging this though. |
|
@bdon that's interesting to know about the italic axis in Chrome. I didn't explicitly point out italic, but it's covered by this comment from the description:
I discovered this while trying to support additional axes beyond |
|
I did some more digging into the italics issue, and it's only Chrome, when using the "100 900" weight specification, that italics stop working. It works fine on Safari and Firefox; it also works fine on Chrome when using the multiple single-weight definitions workaround e.g. |
|
A workaround I discovered: If you only ever use And it will work properly in chrome. So any weight that might be italic needs to be explicitly loaded by FontFace. |
|
@bdon ahhh OK thank you for the further info, I had misunderstood, I only thought that variable italics didn't work, not that all italics on variable fonts are broken (in Chrome)?? Do you still think this makes sense to merge and perhaps just document the Chrome bug? I guess the alternative would be to have Tangram be smart enough to register additional fonts w/FontFace on the fly... right now it relies on parsing all the font definitions once upfront. Some refactoring would be needed to change that, though it would be generally more flexible. Maybe we just create an issue for that work, and proceed with merging this. |
|
I think it does make sense to merge, because I don't see anything wrong with the implementation as-is. (BTW, I tried changing it so that it observes for the '900' weight load event instead of the '100' in case this was some implementation detail about the order in which italics are loaded, but that didn't fix anything) The chrome issue has the workaround I described above, so maybe best to document that. |
|
Thanks. Going to merge this one then and give some thought to adapting font loading to address this, which would bring other performance benefits (deferred loading). |
|
Note, fixed a regression in 28afd16 |
Variable fonts allow multiple variants of a font to be stored in a single file.
Supporting these has several benefits:
In CSS, the syntax for variable font weight looks like:
font-weight: 125 950;.Tangram font syntax is similarly extended to support this as
weight: 125 950for a given font within thefontsblock.Note that while the variable font spec supports variation for other properties including font stretch and even custom, per-typeface-defined properties, Tangram relies on Canvas text rendering for labels, which unfortunately does not support these properties (font stretch cannot be set even for non-variable fonts).
This PR also enables JS function-based font
weight, e.g. an example mapping font weight to building heights: