Minimal Font Families, Font Queries, Collections, System Fonts, Stretch, and Slant support - #22156
Conversation
Added a `weight: Weight` field to `TextFont`.
`clamp` is called on `Weight` in the `From` impl for `cosmic_text::Weight`
Co-authored-by: Thierry Berger <contact@thierryberger.com>
|
Your PR caused a change in the graphical output of an example or rendering test. This might be intentional, but it could also mean that something broke! If it's expected, please add the M-Deliberate-Rendering-Change label. If this change seems unrelated to your PR, you can consider updating your PR to target the latest main branch, either by rebasing or merging main into it. |
|
Your PR caused a change in the graphical output of an example or rendering test. This might be intentional, but it could also mean that something broke! If it's expected, please add the M-Deliberate-Rendering-Change label. If this change seems unrelated to your PR, you can consider updating your PR to target the latest main branch, either by rebasing or merging main into it. |
1 similar comment
|
Your PR caused a change in the graphical output of an example or rendering test. This might be intentional, but it could also mean that something broke! If it's expected, please add the M-Deliberate-Rendering-Change label. If this change seems unrelated to your PR, you can consider updating your PR to target the latest main branch, either by rebasing or merging main into it. |
|
@alice-i-cecile this should be more or less ready now. I'm too sleepy to wait and see if the CI passes though. |
|
CI is failing sadly :) |
The markdown CI isn't giving any errors either, just failing. Maybe I've found the problem now. |
|
@alice-i-cecile ready now |
# Objective Included some naive test code for system fonts in the `text` example in #22156 by mistake. ## Solution Revert the changes to the example.
# Objective #22156 introduced a leak 😓 . Every time a text section with a font handle font source is updated in `TextPipeLine::update_buffer`, a new font with a new font ID is added to cosmic text's FontDb. Fixes #22419 ## Solution Remove font loading and asset-ID association from TextPipeline. Instead, add the font family name to the `Font` asset after loading. Then `update_buffer` can just use the family name from the asset. ## Testing Add this system to the `text` example (or any bevy app with updating text): ```rust .add_systems(Update, |font_system: Res<CosmicFontSystem>| { println!("fonts: {}", font_system.db().len()); }) ``` You should observe the count increasing with every text update on main. The count should be stable with this PR.
Objective
Implement support for the remaining missing text features with minimal changes.
Solution
TextFonthas been expanded to include new fields:FontSource has two variants: Handle, which identifies a font by asset handle, and Family, which selects a font by its family name.
FontWidthis a newtype struct representing OpenType font stretch classifications ranging from ULTRA_CONDENSED (50%) to ULTRA_EXPANDED (200%).FontStyleis an enum used to set the slant style of a font, eitherNormal,Italic, orOblique.The system font support is very barebones. You load them using the
CosmicFontSystemresource:Then they are available to be selected by family name using
FontSource::Family.Other changes
TextPipelines'sglyph_infofield has been removed. There is no need to collect the section infos or perform any querys during text layout updates, so that code has been removed as well.update_text_layout_infoused sometry_for_eachwith some nested closures which was unnecessarily complicated again. They've been replaced with a regular for loop.After font assets are loaded there's a new system
load_font_assets_into_fontdb_systemthat automatically adds them to cosmic text's font database. Then they are available to be looked up by family name as well as by asset handle.There aren't are performance motivated changes but layout updates seem to be overall significantly more efficient now, with a slight regression for very large numbers of short, single section text entities.
Font texture atlases are no longer automatically cleared when the font asset they were generated from is removed. There is no way to remove individual fonts from cosmic text's
FontSystem, so the font is still accessible using the family name withFontSource::familyand removing the text atlases naively could cause a panic since rendering expects them to be present.Testing
Showcase