-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
#7616
Comments
Some things to consider / possible limitations, when using It is not clear how to mix spans of different font sizes, see pop-os/cosmic-text#64 You can't currently layout text like this<div>
<span>Some text is quite </span>
<span class="big">big</span>
<span> but some text is quite </span>
<span class="small">small</span>
<span>, and sometimes text has </span>
<span class="wide-lines">wide lines, </span>
<span>but other times text has </span>
<span class="thin-lines">thin lines.</span>
</div>
<style>
div {
width: 140px;
font-size: 16pt;
line-height: 1.5;
}
.big {
font-size: 32pt;
}
.small {
font-size: 8pt;
}
.wide-lines {
line-height: 4;
}
.thin-lines {
line-height: 1;
}
</style> It is not clear how you supply your own font (i.e. as bytes, needed to load a font as an asset), see comment https://github.com/iced-rs/iced/pull/1610/files#r1054666431 - Iced seems to tackle this elsewhere as part of its implementation Perhaps we could reimplement |
You can use |
The challenge I had with it was that...
// A FontSystem provides access to detected system fonts, create one per application
let font_system = FontSystem::new();
// A SwashCache stores rasterized glyphs, create one per application
let mut swash_cache = SwashCache::new(&font_system);
// Text metrics indicate the font size and line height of a buffer
let metrics = Metrics::new(14, 20);
// A Buffer provides shaping and layout for a UTF-8 string, create one per text widget
let mut buffer = Buffer::new(&font_system, metrics);
To add fonts as the application is running (such as when the asset server loads font files) we would need to access the inner
Note I am assuming here that As a really hacky workaround:
The easiest solution would probably be to fork |
FWIW, cosmic-text seems very open to changes in general. They have already accepted PRs from both the Iced and Vizia developers. Discussion of cosmic-text development happens partly in it's github issues, but also partly in this thread in Iced's discord https://discord.com/channels/628993209984614400/1027584473631555604 |
@tigregalis The lifetime dependencies will be most likely gone soon (see pop-os/cosmic-text#39), but in the meantime you can use For font loading, you can leverage |
Great news. That looks exactly like the design I was envisioning to resolve this. Glad to learn someone's already working on it.
In this case, I guess it means we store the
Ah, that's a smart workaround. And once pop-os/cosmic-text#39 is merged, with nothing long-borrowing the |
pop-os/cosmic-text#97 has been merged, this should now be possible. |
|
Is this migration for 0.11 or should we expect it for another update? |
I'm working on this, but the progress is slow. Since 0.11 will be released one or two weeks later, it's hopefully done in 0.12. |
It is very disappointing that we are unlikely to meet the 0.12 milestone. Do you have anything I can contribute? |
From the OP on Discord. pop-os/cosmic-text#150 appears to be the linked PR. Adopting either #8808 or that PR would be incredibly useful: I'm sure the OP will be around to give feedback and review. |
@alice-i-cecile Apparently there is a new contender for text layout: https://github.com/dfrg/parley/blob/master/doc/concept.md |
Neat! IMO for this sort of dependency we should prioritize stability and longevity though, and cosmic-text has a funded open source team with a long history behind it. |
Agreed. The reason this popped up on my radar is that I've been chatting with Raph Levien, and apparently the Xilem team is going to be working on this. |
Ah, that's also a sensible team to rely on. Probably worth evaluating on the merits then. |
We've opened a new working group to handle this migration, and decide between Draft design doc: https://hackmd.io/@alice-i-cecile/rJhG8KR40/edit Open membership working group (join us!): https://discord.com/channels/691052431525675048/1248074018612051978 |
# 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 <anak.harimau@gmail.com> Co-authored-by: Nico Burns <nico@nicoburns.com> Co-authored-by: sam edelsten <samedelsten1@gmail.com> Co-authored-by: Dimchikkk <velo.app1@gmail.com> Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com> Co-authored-by: Rob Parrett <robparrett@gmail.com>
# 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 <anak.harimau@gmail.com> Co-authored-by: Nico Burns <nico@nicoburns.com> Co-authored-by: sam edelsten <samedelsten1@gmail.com> Co-authored-by: Dimchikkk <velo.app1@gmail.com> Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com> Co-authored-by: Rob Parrett <robparrett@gmail.com>
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 <anak.harimau@gmail.com> Co-authored-by: Nico Burns <nico@nicoburns.com> Co-authored-by: sam edelsten <samedelsten1@gmail.com> Co-authored-by: Dimchikkk <velo.app1@gmail.com> Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com> Co-authored-by: Rob Parrett <robparrett@gmail.com>
What problem does this solve or what need does it fill?
Our font rendering is subpar. See #2404 for an example of the rendering problems and #1325 / #1017 for some missing features.
What solution would you like?
Migrate to the well-made, well-supported [
cosmic-text
] crate that is quickly becoming the ecosystem standard.What alternative(s) have you considered?
We could try and fix all of these issues in the assorted font crates we depend on.
Additional context
Iced's migration should be informative: iced-rs/iced#1697
The text was updated successfully, but these errors were encountered: