bevy icon indicating copy to clipboard operation
bevy copied to clipboard

`bevy_text` parley migration

Open ickshonpe opened this issue 1 month ago • 5 comments

Objective

Minimal-ish bevy_text migration from cosmic-text to parley 0.7.

Solution

Internally the bevy_text::pipeline module has been completely rewritten.

  • shape_text shapes the text.
  • update_text_layout_info updates the glyph geometry for rendering and handles strikethrough and underline.

The fields of TextNodeFlags have been renamed:

  • needs_measure_fn -> needs_shaping
  • needs_recompute -> needs_relayout

The public builder API is unchanged, but internally FontFeatures now keeps a list of parley FontFeatures. The From<&FontFeatures> for cosmic_text::FontFeatures implementation has been removed. In its place FontFeatures now has an as_slice method that returns a &[FontFeature] slice that can be passed directly to parley.

Most of the other APIs and behaviours are unchanged.


Todo

  • ~I forgot about text anti-aliasing, support for bevy_text::FontSmoothing::None still needs to be implemented.~
  • A couple of tests have been removed and need to replaced.
  • The text layout for testbed_ui's text scene shows changes, need to look into why.

Been a couple of weeks since I last worked on bevy_text, so I probably forgot other things well.

Testing

The tests and examples all seem to work correctly. Things to check out first would be change detection, malformed text hierarchies, empty text sections, default fonts, and the new-ish features like FontFeatures (@hansler) and Underline and Strikethrough.

Performance

cargo run --example many_glyphs --features trace_tracy,debug --release -- --recompute-text

yellow - this PR, red - main

For UI text layout is a three stage process

  1. shaping in shape_text_system
  2. measurement in ui_layout_system
  3. glyph layout in layout_text_system
many-glyphs-shaping many-glyphs-ui_layout_system many-glyphs-layout

text2d doesn't require measurement so there is only one system: update_text2d_layout. It's slower than with cosmic-text, I'm not sure why. Maybe there is a problem with our cosmic-text text measurement implementation, and cosmic-text itself isn't slow?

many-glyphs-update_text2d_layout

ickshonpe avatar Nov 25 '25 22:11 ickshonpe

It looks like your PR is a breaking change, but you didn't provide a migration guide.

Please review the instructions for writing migration guides, then expand or revise the content in the migration guides directory to reflect your changes.

github-actions[bot] avatar Nov 25 '25 22:11 github-actions[bot]

It looks like your PR has been selected for a highlight in the next release blog post, but you didn't provide a release note.

Please review the instructions for writing release notes, then expand or revise the content in the release notes directory to showcase your changes.

github-actions[bot] avatar Nov 25 '25 22:11 github-actions[bot]

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-21940

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[bot] avatar Nov 25 '25 22:11 github-actions[bot]

Just curious, what is the motivation for switching from cosmic-text to parley? I'm not very familiar with the intricacies of text rendering.

lomirus avatar Nov 26 '25 02:11 lomirus

Just curious, what is the motivation for switching from cosmic-text to parley? I'm not very familiar with the intricacies of text rendering.

@lomirus Unsure if you’re on the Bevy discord, but the motivation context can be found here: https://discord.com/channels/691052431525675048/1424875292908064899/1438454359863328858

Specifically, the author of this PR wrote:

The difference between parley and cosmic-text really isn't that much, they both have a lot of the same dependencies and the APIs are just a layer over mostly the same data etc For me, the main advantage with parley I think is that its less complicated while supporting more or less the same features and the text internals have been a mess since the shaping changes back in bevy 11 or whenever it was so if we have to rework everything anyway to support font collections in 0.18, it makes sense to me to switch now

kfc35 avatar Dec 02 '25 00:12 kfc35