-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Font weight support #22038
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
base: main
Are you sure you want to change the base?
Font weight support #22038
Conversation
Added a `weight: Weight` field to `TextFont`.
`clamp` is called on `Weight` in the `From` impl for `cosmic_text::Weight`
ThierryBerger
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! But the noto font should probably be removed indeed ; Is there any reason not to use fira font ? or another one already present ?
| section_info.5 = (metrics.underline_offset * scalar).round(); | ||
| } | ||
| if let Some((id, _)) = self.map_handle_to_font_id.get(§ion_info.0) | ||
| && let Some(font) = font_system.get_font(*id, cosmic_text::Weight(section_info.6)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let chain 🎉 👍
All the fonts we include atm are static, so they won't show any changes. |
|
Maybe there is some light weight minimalistic variable font we can include instead, I'll have a look. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approving ; if font size is a problem we may:
- look into bringing a smaller font, maybe inter being 875kb (~half noto?)
- or choose a more "powerful"/"featureful" font to anticipate further needs (but I doubt that makes sense, anticipating unclear goals is usually a no-no)
But it quickly gets into bikeshed territory, and assets management is a wild topic which I wouldn't want to block on here.
|
Switched to MonaSans variable font. It's only 384kb, which seems reasonable. If the extra size is a problem, we could remove the static EBGaramond font. |
|
So if I understand correctly, this new font weight attribute only affects variable fonts, it has no affect on non-variable fonts? If so, this should be made clear in the documentation. |
Sort of. To use this with static fonts, you need to load multiple fonts with different weights, so that it can choose the one with the nearest font-weight. |
How does that work? Because we are still assigning a font handle to each individual text span, how can it choose between different handles? I mean, obviously this is how we want it to work, but it's not clear that this PR works that way now. In any case, my point stands: if there are limitations then they should be called out in the docs. |
Objective
Add font weight support.
Solution
FontWeightstruct that newtypes au16.font: FontWeightfield onTextFont.TextPipelineduring text updates.MonSans-VariableFont.ttf. This needs a variable font for testing.Doesn't support
lighterandbolderas that would require text style inheritance, which we don't support yet.I added stretch and slant as well, but split them off from this PR. Swash only has limited variable-font support and there's no way to demonstrate that they work without other changes.
Testing
Added a basic example:
cargo run --example font_weightsShowcase