Add OpenType font variations#24088
Conversation
| font: font.clone(), | ||
| font_size: FontSize::Px(32.0), | ||
| font_variations: FontVariations::builder() | ||
| .set(FontVariationTag::WEIGHT, weight as f32) |
There was a problem hiding this comment.
This feels like a code smell that we should just be unifying the APIs here somehow.
There was a problem hiding this comment.
I can totally do that.
The question is what would we call the unified struct and builder. I was thinking
struct FontVariables {
features: Vec<...>,
variations: Vec<...>
}and a corresponding builder.
However, this is less discoverable than FontVariations and FontFeatures, which match the OpenType names.
There was a problem hiding this comment.
I'm not so sure about unifying the APIs. I agree it would be more user friendly, but parley maintains separate lists and it might complicate font inheritance and change detection. So personally I think it would be better to leave it like this for now.
There was a problem hiding this comment.
It might be okay though, I'm not certain.
|
|
||
| impl FontVariationTag { | ||
| /// Defines the stroke thickness. | ||
| pub const WEIGHT: FontVariationTag = FontVariationTag::new(b"wght"); |
There was a problem hiding this comment.
It feels a bit empty just to have the wght tag, it would be nice to have a few more here.
And the doc comment for weight could mention the values will be clamped to some subrange inside 1..1000.
There was a problem hiding this comment.
Otherwise, no complaints.
|
@alice-i-cecile seems like this got forgotten after the merge problems a few days ago |
Objective
Bevy currently supports OpenType
FontFeatures, but it doesn't supportFontVariations, althoughparleyhas support for them.Font features are mainly on/off values to vary the font (
u32), while font variations are a continuous range of values that can be set to vary the font (f32).I personally need it for setting
FILLon the material design icon font.Solution
I implemented
FontVariationsas a separate struct fromFontFeaturesfor now and copied it's api.However, since both are so similar it's worth considering to merge them into something like a
FontVariableswith a builder that hasset_featureandset_variationmethods.Testing
Added a new example demonstrating how to set the font weight using
FontVariationsinstead ofFontWeight.(Setting font weight using
FontFeaturesdoes not work, although the documentation suggests it should. I'm not sure if this depends on the variable font used or whether this is an error in the documentation.)Showcase