Proposal: Multi-file font family
Proposal: Multi-file font family
Summary
It is possible to specify and use a custom font family in WinUI apps by pointing to a font file (like .ttf) bundled with the application. However, when the font has multiple files for different styles and weights, multiple font families have to be created and then referenced, which is incovenient.
For example let's take the Open Sans font. It comes in multiple weights and each weight has regular and italic style. So in total 10 font files are available, which would result in 10 font family declarations in XAML - even though in fact this is just one "real" font-family.

<TextBlock Text="Test" FontFamily="ms-appx:///Assets/Fonts/OpenSans-Regular-Bold.ttf#Open Sans" />
<TextBlock Text="Test" FontFamily="ms-appx:///Assets/Fonts/OpenSans-Italic-Bold.ttf#Open Sans" />
...
Interestingly, when user manually installs the font family into the system (into Windows/Fonts), it is then possible to use the whole font family easily:
<TextBlock Text="Test" FontFamily="Open Sans" />
Rationale
- Simpler usage of custom font families with multiple variants
- Same behavior for custom fonts as for installed fonts
- Ability to replace the default font with a custom font family (e.g.
ContentControlThemeFontFamilyreplacing Segoe UI with Open Sans)
Scope
| Capability | Priority |
|---|---|
This proposal will allow developers to bundle a custom font family and reference all its variations with a single FontFamily declaration |
Must |
This proposal will allow developers to replace the default font in ContentControlThemeFontFamily with a custom font family bundled with the app |
Must |
Important Notes
API proposal
If all font files for a given font family are in a single folder, it could be possible to do something like:
<TextBlock Text="Test" FontFamily="ms-appx:///Assets/Fonts/OpenSans/" />
Where the framework would automatically discover that there are multiple font files in the folder and could use similar approach as resource qualifiers to sort them:
OpenSans.weight-bold_style-regular.ttf
OpenSans.weight-black_style-italic.ttf
OpenSans.weight-semilight_style-italic.ttf
...