-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Migrate to cosmic-text
#8808
Migrate to cosmic-text
#8808
Conversation
} | ||
|
||
#[derive(Clone, Debug)] | ||
pub struct FontQuery { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Definitely needs doc strings. I also think we should really try and avoid the Query
name if possible, since this doesn't seem to use bevy_ecs::Query, which is going to be a source of a lot of confusion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at this more, I think that "system font" is probably a better way to describe this functionality?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SystemFont
doesn't quite capture the idea as you can actually use a FontQuery
to refer to a font you loaded as an asset (since it's always loaded into the Database
), which I've confirmed works (but I probably need to test for edge cases). *Query
better captures the idea, and it's the terminology used by fontdb
, but FontSearch
could maybe work.
was this abandoned, and in that case, how would anyone pick this up? |
Not fully abandoned, but like I said in this comment, the author has been busy and would appreciate some assistance. If I was tackling this, I would personally start by creating a branch, and attempting to recreate these changes with the latest versions of both Bevy and cosmic-text. Given the level of merge conflicts, I think that doing so manually, rather than attempting to rebase these commits is likely going to be happier. Once you have something to show (it doesn't need to be complete), open up a new PR and link this one in the description. |
Okay so basically, I took and did the quickest way I could figure out, and that was to just squash all the commits by @tigregalis and then merge that one large commit into a new branch, and then do a PR. I probably messed something up, but at least I got the You can see that PR here: #10193 |
Adopted in #10193. Please follow (and chime in) there! |
# Objective - Enables support for `Display::Block` - Enables support for `Overflow::Hidden` - Allows for cleaner integration with text, image and other content layout. - Unblocks #8104 - Unlocks the possibility of Bevy creating a custom layout tree over which Taffy operates. - Enables #8808 / #10193 to remove a Mutex around the font system. ## Todo - [x] ~Fix rendering of text/images to account for padding/border on nodes (should size/position to content box rather than border box)~ In order get this into a mergeable state this PR instead zeroes out padding/border when syncing leaf node styles into Taffy to preserve the existing behaviour. #6879 can be fixed in a followup PR. ## Solution - Update the version of Taffy - Update code to work with the new version Note: Taffy 0.4 has not yet been released. This PR is being created in advance of the release to ensure that there are no blockers to upgrading once the release occurs. --- ## Changelog - Bevy now supports the `Display::Block` and `Overflow::Hidden` styles.
# Replace ab_glyph with the more capable cosmic-text Fixes #7616. Cosmic-text is a more mature text-rendering library that handles scripts and ligatures better than ab_glyph, it can also handle system fonts which can be implemented in bevy in the future Rebase of #8808 ## Changelog Replaces text renderer ab_glyph with cosmic-text The definition of the font size has changed with the migration to cosmic text. The behavior is now consistent with other platforms (e.g. the web), where the font size in pixels measures the height of the font (the distance between the top of the highest ascender and the bottom of the lowest descender). Font sizes in your app need to be rescaled to approximately 1.2x smaller; for example, if you were using a font size of 60.0, you should now use a font size of 50.0. ## Migration guide - `Text2dBounds` has been replaced with `TextBounds`, and it now accepts `Option`s to the bounds, instead of using `f32::INFINITY` to inidicate lack of bounds - Textsizes should be changed, dividing the current size with 1.2 will result in the same size as before. - `TextSettings` struct is removed - Feature `subpixel_alignment` has been removed since cosmic-text already does this automatically - TextBundles and things rendering texts requires the `CosmicBuffer` Component on them as well ## Suggested followups: - TextPipeline: reconstruct byte indices for keeping track of eventual cursors in text input - TextPipeline: (future work) split text entities into section entities - TextPipeline: (future work) text editing - Support line height as an option. Unitless `1.2` is the default used in browsers (1.2x font size). - Support System Fonts and font families - Example showing of animated text styles. Eg. throbbing hyperlinks --------- Co-authored-by: tigregalis <[email protected]> Co-authored-by: Nico Burns <[email protected]> Co-authored-by: sam edelsten <[email protected]> Co-authored-by: Dimchikkk <[email protected]> Co-authored-by: Alice Cecile <[email protected]> Co-authored-by: Rob Parrett <[email protected]>
# Replace ab_glyph with the more capable cosmic-text Fixes bevyengine#7616. Cosmic-text is a more mature text-rendering library that handles scripts and ligatures better than ab_glyph, it can also handle system fonts which can be implemented in bevy in the future Rebase of bevyengine#8808 ## Changelog Replaces text renderer ab_glyph with cosmic-text The definition of the font size has changed with the migration to cosmic text. The behavior is now consistent with other platforms (e.g. the web), where the font size in pixels measures the height of the font (the distance between the top of the highest ascender and the bottom of the lowest descender). Font sizes in your app need to be rescaled to approximately 1.2x smaller; for example, if you were using a font size of 60.0, you should now use a font size of 50.0. ## Migration guide - `Text2dBounds` has been replaced with `TextBounds`, and it now accepts `Option`s to the bounds, instead of using `f32::INFINITY` to inidicate lack of bounds - Textsizes should be changed, dividing the current size with 1.2 will result in the same size as before. - `TextSettings` struct is removed - Feature `subpixel_alignment` has been removed since cosmic-text already does this automatically - TextBundles and things rendering texts requires the `CosmicBuffer` Component on them as well ## Suggested followups: - TextPipeline: reconstruct byte indices for keeping track of eventual cursors in text input - TextPipeline: (future work) split text entities into section entities - TextPipeline: (future work) text editing - Support line height as an option. Unitless `1.2` is the default used in browsers (1.2x font size). - Support System Fonts and font families - Example showing of animated text styles. Eg. throbbing hyperlinks --------- Co-authored-by: tigregalis <[email protected]> Co-authored-by: Nico Burns <[email protected]> Co-authored-by: sam edelsten <[email protected]> Co-authored-by: Dimchikkk <[email protected]> Co-authored-by: Alice Cecile <[email protected]> Co-authored-by: Rob Parrett <[email protected]>
Fixes bevyengine#7616. Cosmic-text is a more mature text-rendering library that handles scripts and ligatures better than ab_glyph, it can also handle system fonts which can be implemented in bevy in the future Rebase of bevyengine#8808 Replaces text renderer ab_glyph with cosmic-text The definition of the font size has changed with the migration to cosmic text. The behavior is now consistent with other platforms (e.g. the web), where the font size in pixels measures the height of the font (the distance between the top of the highest ascender and the bottom of the lowest descender). Font sizes in your app need to be rescaled to approximately 1.2x smaller; for example, if you were using a font size of 60.0, you should now use a font size of 50.0. - `Text2dBounds` has been replaced with `TextBounds`, and it now accepts `Option`s to the bounds, instead of using `f32::INFINITY` to inidicate lack of bounds - Textsizes should be changed, dividing the current size with 1.2 will result in the same size as before. - `TextSettings` struct is removed - Feature `subpixel_alignment` has been removed since cosmic-text already does this automatically - TextBundles and things rendering texts requires the `CosmicBuffer` Component on them as well - TextPipeline: reconstruct byte indices for keeping track of eventual cursors in text input - TextPipeline: (future work) split text entities into section entities - TextPipeline: (future work) text editing - Support line height as an option. Unitless `1.2` is the default used in browsers (1.2x font size). - Support System Fonts and font families - Example showing of animated text styles. Eg. throbbing hyperlinks --------- Co-authored-by: tigregalis <[email protected]> Co-authored-by: Nico Burns <[email protected]> Co-authored-by: sam edelsten <[email protected]> Co-authored-by: Dimchikkk <[email protected]> Co-authored-by: Alice Cecile <[email protected]> Co-authored-by: Rob Parrett <[email protected]>
Objective
Fixes #7616
Solution
cosmic_text
, simplifying and enhancing Bevy's text rendering implementationChangelog
Changed
TextStyle::font
is no longer aHandle<Font>
, but aFontRef
.From<Handle<Font>>
is implemented forFontRef
, so in your existing code, you can call.into()
on theHandle<Font>
to convert it into aFontRef
.The definition of the font size has changed with the migration to cosmic text. The behavior is now consistent with other platforms (e.g. the web), where the font size in pixels measures the height of the font (the distance between the top of the highest ascender and the bottom of the lowest descender). Font sizes in your app need to be rescaled to approximately 1.2x smaller; for example, if you were using a font size of 60.0, you should now use a font size of 50.0.
Added
You can now query loaded fonts by family and style using
FontQuery
.From<FontQuery>
is implemented forFontRef
, so you can call.into()
on theFontQuery
to convert it into aFontRef
.You can now load system fonts using
TextPipeline::load_system_fonts
. These fonts can then be queried by aFontQuery
.Emojis and bidirectional text are now supported, provided fonts have been loaded that support them (for example, via
TextPipeline::load_system_fonts
).Check out the new
system_fonts
example in the Bevy repo.Migration Guide
The definition of the font size has changed with the migration to cosmic text. Font sizes in your app need to be rescaled to approximately 1.2x smaller; for example, if you were using a font size of 60.0, you should now use a font size of 50.0..
TextStyle::font
is no longer aHandle<Font>
, but aFontRef
. In eachTextStyle
, call.into()
on theHandle<Font>
to convert it into aFontRef
.Notes
To do
This is a draft, and there's still quite a bit of work to do. I've (liberally) peppered the code with TODOs but here is a collection:
At a high level this is what was done and still (perhaps) needs doing:
Font::get_outlined_glyph_texture
topipeline.rs
as it has nothing to do withFont
.bevy_text
)PositionedGlyph::byte_index
for Expose more info in PositionedGlyph #1319, or equivalent? this field is not used in Bevy internals or Bevy examples, so guidance is required, may be covered by Editor/Cursorfontdb
(perhaps they could re-export it)Future Work
Preferably done now:
Mutex
used forTextMeasure
purposes)fontdb
to 0.14.1 pop-os/cosmic-text#128 (take ID when loading font)Buffer
with noFontSystem
pop-os/cosmic-text#127 (cache buffer / store buffer(s) on Text component)str::Lines
withunicode-bidi
-based iterator pop-os/cosmic-text#124 (remove ownBidiParagraphs
iterator)Wrap::None
pop-os/cosmic-text#131Buffer
figure out itsheight
duringset_size
pop-os/cosmic-text#70 (simpler buffer size calculation)For future PRs, or should any of these be done in this PR?
Guidance needed
I've tried to "slip under the radar" as much as possible when it comes to the API, but in some cases user-facing API changes were unavoidable. Please consider and advise how best to design and expose these APIs.
Of particular note is the new
FontQuery
, andTextPipeline::load_system_fonts
(which probably needs to run in a parallel async task).We also need to consider re-exports.
As far as implementation goes:
Arc
/Mutex
I've introduced and how best to handle errors there.ab_glyph
used to parse the font when it loaded it into memory as aFontVec
, butfontdb
(viacosmic_text
) doesn't (parsing is a separate step, and we'd have to introducettf-parser
), so currently font data is simply aVec<u8>
.Reflect
.I think that about covers it. Have at it.