Skip to content

Minimal Font Families, Font Queries, Collections, System Fonts, Stretch, and Slant support - #22156

Merged
alice-i-cecile merged 90 commits into
bevyengine:mainfrom
ickshonpe:minimal-font-families
Jan 3, 2026
Merged

alice-i-cecile merged 90 commits into
bevyengine:mainfrom
ickshonpe:minimal-font-families

Conversation

@ickshonpe

@ickshonpe ickshonpe commented Dec 16, 2025 •

Copy link
Copy Markdown
Contributor

Objective

Implement support for the remaining missing text features with minimal changes.

Solution

TextFont has been expanded to include new fields:

pub struct TextFont {
    pub font: FontSource,
    pub font_size: f32,
    pub weight: FontWeight,
    pub width: FontWidth,
    pub style: FontStyle,
    pub font_smoothing: FontSmoothing,
    pub font_features: FontFeatures,
}

FontSource has two variants: Handle, which identifies a font by asset handle, and Family, which selects a font by its family name.

FontWidth is a newtype struct representing OpenType font stretch classifications ranging from ULTRA_CONDENSED (50%) to ULTRA_EXPANDED (200%).

FontStyle is an enum used to set the slant style of a font, either Normal, Italic, or Oblique.

The system font support is very barebones. You load them using the CosmicFontSystem resource:

font_system.db_mut().load_system_fonts()

Then they are available to be selected by family name using FontSource::Family.

Other changes

  • TextPipelines's glyph_info field 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_info used some try_for_each with 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_system that 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 with FontSource::family and removing the text atlases naively could cause a panic since rendering expects them to be present.

Testing

cargo run --example font_query

Showcase

font-query

ickshonpe and others added 30 commits December 5, 2025 09:38
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>
@github-actions

github-actions Bot commented Jan 2, 2026

Copy link
Copy Markdown
Contributor

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!
You can review it at https://pixel-eagle.com/project/B04F67C0-C054-4A6F-92EC-F599FEC2FD1D?filter=PR-22156

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.

@github-actions

github-actions Bot commented Jan 2, 2026

Copy link
Copy Markdown
Contributor

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!
You can review it at https://pixel-eagle.com/project/B04F67C0-C054-4A6F-92EC-F599FEC2FD1D?filter=PR-22156

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
@github-actions

github-actions Bot commented Jan 2, 2026

Copy link
Copy Markdown
Contributor

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!
You can review it at https://pixel-eagle.com/project/B04F67C0-C054-4A6F-92EC-F599FEC2FD1D?filter=PR-22156

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.

@ickshonpe

Copy link
Copy Markdown
Contributor Author

@alice-i-cecile this should be more or less ready now. I'm too sleepy to wait and see if the CI passes though.

@alice-i-cecile

Copy link
Copy Markdown
Member

CI is failing sadly :)

@ickshonpe

ickshonpe commented Jan 3, 2026 •

Copy link
Copy Markdown
Contributor Author

CI is failing sadly :)

The markdown CI isn't giving any errors either, just failing. Maybe I've found the problem now.

@ickshonpe

Copy link
Copy Markdown
Contributor Author

@alice-i-cecile ready now

@ickshonpe ickshonpe added S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it and removed S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged labels Jan 3, 2026
@alice-i-cecile
alice-i-cecile added this pull request to the merge queue Jan 3, 2026
Merged via the queue into bevyengine:main with commit e5d4dfd Jan 3, 2026
44 checks passed
github-merge-queue Bot pushed a commit that referenced this pull request Jan 5, 2026
# Objective

Included some naive test code for system fonts in the `text` example in
#22156 by mistake.

## Solution

Revert the changes to the example.
@ickshonpe ickshonpe mentioned this pull request Jan 7, 2026
github-merge-queue Bot pushed a commit that referenced this pull request Jan 7, 2026
# 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Text Rendering and layout for characters C-Feature A new feature, making something new possible M-Migration-Guide A breaking change to Bevy's public API that needs to be noted in a migration guide M-Release-Note Work that should be called out in the blog due to impact S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants