You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add support for OpenType features in text (e.g. ligatures, smallcaps) (#19020)
# Objective
OpenType features include things like smallcaps, lined vs old-style
numbers, ligatures, stylistic alternate characters, fractional numbers
(numerator placed above the denominator), forced monospacing for
numbers, and more. There are >100 possible OpenType feature tags; see
https://learn.microsoft.com/en-us/typography/opentype/spec/featurelist
for the up-to-date list. This provides a way for Bevy users to use these
features when using .otf fonts that support them.
## Solution
OpenType features are now supported in cosmic-text, so this just
provides a way to pass them through. A few notes:
- I extended the existing "text" example to showcase a few different
OpenType features.
- OpenType features are only available for .otf fonts. Since there
weren't any existing .otf fonts in the asset/ folder, I've added an
SIL-licenced font so that we can showcase this in example code.
- I added a "FontFeatures" struct. cosmic-text does already include its
own FontFeatures struct, but 1) it does not implement Reflect, which is
required by TextFont, and 2) the one I added has a couple ergonomics
improvements for the builder methods compared to cosmic-text's.
- OpenType font features are four characters strings, e.g. "liga". I
considered representing these within an enum, but decided against this
since there are hundreds of possible features, and more get added
frequently, so this would require quite a bit of ongoing maintenance.
Since these features are typically referred to by their four-letter name
in documentation, I think the [u8; 4] representation is appropriate, and
this mirrors what cosmic-text does as well. I added some consts for
commonly used features.
## Testing
I extended the "text" example. Run:
`cargo run --example text`
---
## Showcase
Screenshot:

---------
Co-authored-by: John Hansler <[email protected]>
0 commit comments