Upgrade to cosmic-text 0.13 (#18239)

# Objective

Upgrade to `cosmic-text` 0.13

https://github.com/pop-os/cosmic-text/releases

This should include some performance improvements for layout and system
font loading.

## Solution

Bump version, fix the one changed API.

## Testing

Tested some examples locally, will invoke the example runner.

## Layout Perf

||main fps|cosmic-13 fps|
|-|-|-|
|many_buttons --recompute-text --no-borders|6.79|9.42 🟩 +38.7%|
|many_text2d --no-frustum-culling --recompute|3.19|4.28 🟩 +34.0%|
|many_glyphs --recompute-text|7.09|11.17 🟩 +57.6%|
|text_pipeline |140.15|139.90  -0.2%|

## System Font Loading Perf

I tested on macOS somewhat lazily by adding the following system to the
`system_fonts` example from #16365.

<details>
<summary>Expand code</summary>

```rust
fn exit_on_load(
    mut reader: EventReader<bevy::text::SystemFontsAvailable>,
    mut writer: EventWriter<AppExit>,
) {
    for _evt in reader.read() {
        writer.write(AppExit::Success);
    }
}
```
</details>

And running `hyperfine 'cargo run --release --example system_fonts
--features=system_font'`.

The results were nearly identical with and without this PR cherry-picked
there.

Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
This commit is contained in:
Rob Parrett 2025-03-12 11:03:45 -07:00 committed by GitHub
parent 5d80ac3ded
commit 81c0900cf2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 7 deletions

View File

@ -33,7 +33,7 @@ bevy_platform_support = { path = "../bevy_platform_support", version = "0.16.0-d
] }
# other
cosmic-text = { version = "0.12", features = ["shape-run-cache"] }
cosmic-text = { version = "0.13", features = ["shape-run-cache"] }
thiserror = { version = "2", default-features = false }
serde = { version = "1", features = ["derive"] }
smallvec = "1.13"

View File

@ -185,13 +185,14 @@ impl TextPipeline {
},
);
buffer.set_rich_text(font_system, spans_iter, Attrs::new(), Shaping::Advanced);
buffer.set_rich_text(
font_system,
spans_iter,
Attrs::new(),
Shaping::Advanced,
Some(justify.into()),
);
// PERF: https://github.com/pop-os/cosmic-text/issues/166:
// Setting alignment afterwards appears to invalidate some layouting performed by `set_text` which is presumably not free?
for buffer_line in buffer.lines.iter_mut() {
buffer_line.set_align(Some(justify.into()));
}
buffer.shape_until_scroll(font_system, false);
// Workaround for alignment not working for unbounded text.