Alice Cecile
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    1
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # Cosmic-text vs parley ## The text stack Text is a shockingly complex subject. In order to get from "font" to "pixel on screen", a number of key steps must be performed. These are roughly ordered, although the whole process is non-linear and earlier steps sometimes need to coordinate with later ones in an iterative process. 1. Font loading: getting the font files from the disk into a Rust struct that we can work with - `bevy_asset` - Note that system fonts should probably be mmap'd to avoid duplicating memory across processes. - Linebender has been considering trying to get the ecosystem to standardise on something like: ``` struct Font { // Raw file data of a font/collection data: Arc<dyn AsRef<[T]> + Send + Sync>, // Index of the font within a file containing a collection of fonts index: u32, } ``` as a representation for fonts. Would this work for Bevy? (EDIT: looks like fontdb uses an almost indentical representation which is convenient) 2. Font enumeration: listing and working with the available system fonts - Bevy 0.13: none - Cosmic Text: [`font-db`](https://github.com/RazrFalcon/fontdb) - Parley: [`fontique`](https://github.com/linebender/parley/tree/main/fontique) - [`font-kit`](https://github.com/pcwalton/font-kit) is another prominent option in this space 3. Font selection: selecting a font to use based on the developer's request - Bevy 0.13: none - On some level, this is fundamentally Bevy's problem: it needs to play nice with loaded fonts, support fallbacks, [abstract over font variants](https://github.com/bevyengine/bevy/issues/9725)... - However both `cosmic-text` and `parley` handle this already: we may be able to hook in 4. Font parsing: making sense of font data - Bevy 0.13: [`abglyph`](https://docs.rs/ab_glyph/latest/ab_glyph/) - Cosmic Text: [`ttf-parser`](https://github.com/RazrFalcon/ttf-parser) - Parley: [`read-fonts`](https://crates.io/crates/read-fonts) 5. Text processing: choosing which string to display. This may involve localization, handling of control characters and so on. - effectively ommitted, although [`fluent`](https://github.com/projectfluent/fluent-rs) is the de facto standard localization tool 6. Font shaping: combining characters via ligatures, subsituting characters based on context and more - Bevy 0.13: ommitted - Cosmic Text: [`rustybuzz`](https://github.com/RazrFalcon/rustybuzz) - Parley: [`swash`](https://github.com/dfrg/swash) - Bindings to C++ Harfbuzz (`rust_harfbuzz` or `harfbuzz_rs`) should also be considered. 7. Line breaking: determining where lines should be split based on word boundaries and the available space - Bevy 0.13: [`glyph_brush_layout`](https://docs.rs/glyph_brush_layout/latest/glyph_brush_layout/) - Cosmic Text: first-party code - Parley: first-party code 8. Position adjustment: finalizing kerning and other positioning to ensure an aesthetic result - Bevy 0.13: `glyph_brush_layout` - Cosmic Text: first-party code - Parley: first-party code 9. Rasterization: turning the procedural instructions in the font files into pixels for each character. Note that this can be replaced with other forms of rendering, such as SDF-based approaches - Bevy 0.13: `ab_glyph` - Cosmic Text: `swash` - Parley: `swash` - `skrifa` is a newer option here being developed to replace `freetype` in Chromium. It is a bit early, but will be able to be dropped in wherever swash is currently used. - Makepad has some cool SDF code which could be adapted. 10. UI node layout: text elements must be positioned within their UI nodes and the UI nodes must be positioned relative to each other - `taffy` and `bevy_ui` 11. Rendering: using a camera to turn the objects into pixels on the screen - `bevy_ui` and `bevy_render` For a more comprehensive and expert overview of this process, please read [Text Rendering Hates You](https://faultlore.com/blah/text-hates-you/). Nicoburns has prepared an excellent [resource on text handling](https://docs.google.com/document/d/1jDX1KtqjmLHOAXGhzbgOzIin-YMpXGxRjJLcVLYnwX0/edit#heading=h.7wzc3121454) for Linebender: please take a look at this for additional ## Motivation Bevy's current solution for font loading and rasterization is `ab_glyph`. It functions, but doesn't handle complex features very well and there doesn't seem to be any appetite to expand its scope. Notably missing: - [variable weight fonts](https://fonts.google.com/knowledge/introducing_type/introducing_variable_fonts): these embed information about a continuous spectrum of weights (light to bold) and styles (italic, normal) into a single font file - [bidirectional text support](https://www.unicode.org/faq/bidi.html): handles languages that are not written left-to-right, and what happens when you mix them - [system font loading](https://practicaltypography.com/system-fonts.html): every user will have their own set of installed fonts. Using these can be valuable for reducing binary size (especially on the web), but they can also make reasonable fallbacks if something goes wrong or could be used to customize tools like the Bevy Editor - text input and editing: this is notoriously hard once edge cases get involved, and we still don't have a functioning text input widget - font shaping is completely ommitted, making it completely unsuitable for many non-Latin alphabet languages (and ugly even for those) In addition, there are several outstanding bugs and limitations resulting in [ugly results](https://github.com/bevyengine/bevy/issues/2404). Others in the Rust ecosystem have noticed these deficiencies, and created their own solutions to meet more sophisticated needs. As [previously discussed](https://github.com/bevyengine/bevy/issues/7616), we should follow suit and migrate away from `ab_glyph`. [`allsorts`](https://github.com/yeslogic/allsorts) is another competent, profesionally made alternative in this space, but is explicitly not suited to dynamic text handling as needed by Bevy and other GUI crates. As a result, it's not under consideration. ## User-Level Font API Requirements To the extent possible, the Bevy APIs should not expose details of which font backend is being used. In an ideal world, one could switch between backends via a feature flag, however it may not be that easy in practice. Many details of the font system can be hidden from Bevy users - for example, the specifics of glyph caching might be different for different backends. But there are several key APIs which will need to be exposed to users: * Loading font collections that are stored as Bevy assets. * Loading system fonts * Rendering and layout (creating entities which produce rendered text, both for 2d bevy_ui and 3d world-space text). * Text editing methods: picking & selection rects, possibly cursor movement (e.g. advance to next character, end of line, and so on). We will need suitable abstractions for each of these. ## `cosmic-text` [`cosmic-text`](https://github.com/pop-os/cosmic-text) is maintained by PopOS, a relatively new, commercial Linux distribution. It generally seems well-made, and they have expressed openness to feedback and collaboration. There were difficulties during [previous](https://github.com/bevyengine/bevy/pull/8808) [attempts](https://github.com/bevyengine/bevy/pull/10193) to migrate: it does not support multiple fonts of different sizes within a line. This was a regression from Bevy's current feature set, which was deemed unacceptable. The [PR to fix that](https://github.com/pop-os/cosmic-text/pull/235) was open since November 2023, but is now merged thanks to the help of Jeremy Soller, the lead `cosmic-text` maintainer once the importance was brought to his attention. In addition to PopOS's own projects, `cosmic-text` is currently used by: - [`iced`](https://crates.io/crates/iced) - [`basalt`](https://crates.io/crates/basalt) - [`zed`/`gpui`](https://github.com/zed-industries/zed) - [`lapce`/`floem`](https://github.com/lapce/floem) Additionally: - Graphite (a Rust-based vector graphic editing tool) is considering using `cosmic-text` but [appears to be blocked](https://github.com/GraphiteEditor/Graphite/pull/1589) on the same issue as us. - [`egui-cosmic-text`](https://crates.io/crates/egui_cosmic_text) is a working third-party extension to `egui` which uses `cosmic-text` - [`bevy_cosmic_edit`](https://github.com/Dimchikkk/bevy_cosmic_edit) is a third-party integration of Bevy and `cosmic-text` to provide complex text input support ### Why we should use `cosmic-text` - `cosmic-text` is used in production and seems to largely work well - this is true both for System76's own projects and also for other major projects - [`glyphon`](https://lib.rs/crates/glyphon) could be integrated as well, allowing us to replace `bevy_text` - this might reduce our maintanence burden, but would also fragment Bevy's rendering - backed by System76, which is a stable, open-source-first company - `cosmic-text`'s lead maintainer, Jeremy Soller, has been very communicative and helpful ### Why we shouldn't use `cosmic-text` - `cosmic-text` is using `rustybuzz`, which is [fighting an uphill battle](https://github.com/RazrFalcon/rustybuzz/issues/74) trying to keep up with the C code (`harfbuzz`) that is the de facto moving standard for font shaping ## Background on `parley` [`parley`](https://crates.io/crates/parley) is a young project created as part of [Linebender](https://github.com/linebender), a UI group funded by Google Fonts, led by Raph Levien that is working to create [Xilem](https://github.com/linebender/xilem), a new GUI framework. Linebender is explicitly collaborative (go [talk to them](https://xi.zulipchat.com/#narrow/stream/147921-general)), and working to create solid stand-alone crates that can be shared across the ecosystem. `parley` is currently relatively young and not particularly thoroughly documented. Several members of their team are well-known to the Bevy community: both Nico Burns and DJMcNab are notable Bevy alumni / collaborators. `parley` is used by: - [`blitz`](https://github.com/DioxusLabs/blitz), a lightweight, modular, extensible web renderer by the Dioxus team - [`xilem`](https://github.com/linebender/xilem0), Linebender's flagship GUI project ### Why we should use `parley` - `parley` is actively developed, by engineers that we know, trust and have strong relationships with - `swash`'s approach to font shaping shows more promise and is likely to be more future-proof - `parley` is backed by Google Fonts, and has a wealth of expertise to draw on - `parley` is deliberately designed as a ecosystem building block and welcomes collaboration - Linebender's experimental perfectionism is a good cultural fit for the Bevy project - [`vello`](https://github.com/linebender/vello) is designed for use with `parley`, which would allow us to replace Bevy's UI rendering - like with `glyphon`, this trades off control and uniformity for faster access to features and more collaboration ### Why we shouldn't use `parley` - `parley` is young, and as a result is not particularly mature, stable, well-tested or well-documented - Google has a history of suddenly killing projects - Linebender (and Raph) have a desire for getting things just right, which can lead to some NIH and extended prototyping ## Recommendation In summary, both `cosmic-text` and `parley` are reasonable options for Bevy's needs. Both are featureful, well-maintained and open to collaboration on problems we encounter. `cosmic-text` is a profesionally-made, pragmatic crate that's designed to get something decent working *today*. `parley` is a principled, bubbling research project aiming to be the best possible text handling crate. We've had difficulties integrating `cosmic-text` in the past, but with thanks to [some communication]((https://discord.com/channels/691052431525675048/1248074018612051978/1248311012411707392)) with the maintainers, that has been resolved. `parley` is still young, but its rate of development is likely to outstrip Bevy's needs regardless: we're starting from a very poor foundation and so even buggy or limited functionality is dramatically better than what currently exists. TBD! ## Migration strategy TBD! Depends on the crate chosen. ## Relevant Issues ### Layout Bugs * [#13063 `TextLayoutInfo` doesn't contain every processed glyph](https://github.com/bevyengine/bevy/issues/13063) * [#13036 Words that are wider than its container are not wrapped](https://github.com/bevyengine/bevy/issues/13036) * [#12319 Line Break doesn't clear trailing whitespace](https://github.com/bevyengine/bevy/issues/12319) * [#12098 Ui Text does not word wrap if next "word" begins with a dot](https://github.com/bevyengine/bevy/issues/12098) * [#12085 Text Overflow Bug](https://github.com/bevyengine/bevy/issues/12085) * [#11589 fix text height calc](https://github.com/bevyengine/bevy/pull/11589) * [#11542 wrapped text measure doesn't propagate up correctly](https://github.com/bevyengine/bevy/issues/11542) * [#11375 Text is cut off in render_ui_to_texture example with high scale factors.](https://github.com/bevyengine/bevy/issues/11375) * [#11359 JustifyText::Right behaves badly](https://github.com/bevyengine/bevy/issues/11359) * [#8525 UI text is sometimes shifted to the left of where it should be](https://github.com/bevyengine/bevy/issues/8525) * [#8518 Squeezed text nodes early text wrap](https://github.com/bevyengine/bevy/issues/8518) ### Rendering * [#13010 Indic font rendering incorrectly](https://github.com/bevyengine/bevy/issues/13010) * [#10720 Pixelated text font is blurry](https://github.com/bevyengine/bevy/issues/10720) * [#2404 Replace the font renderer with one without the issues of anti-aliasing/hinting/subpixel/baseline](https://github.com/bevyengine/bevy/issues/2404) ### Feature Requests / Other * [#12194 Support for WOFF2 compressed font files](https://github.com/bevyengine/bevy/issues/12194) * [#11593 Add support for bitmap glyphs in OTF fonts](https://github.com/bevyengine/bevy/issues/11593) * [#9944 Mixing Text and non-Text content in UIs](https://github.com/bevyengine/bevy/issues/9944) * [#9761 `\t` tab escape sequence support in text](https://github.com/bevyengine/bevy/issues/9761) * [#9725 Better abstraction for dealing with font styles and variants](https://github.com/bevyengine/bevy/issues/9725) * [#9280 Add option to allow UI text to scale with parent.](https://github.com/bevyengine/bevy/issues/9280) * [#9278 Text sections with the same font should be batched together](https://github.com/bevyengine/bevy/issues/9278) * [#8998 Vertical Text](https://github.com/bevyengine/bevy/issues/8998) * [#8781 Support line-height / letter-spacing in bevy_text](https://github.com/bevyengine/bevy/issues/8781) * [#7714 Text should not store a flat list of sections](https://github.com/bevyengine/bevy/issues/7714) * [#7616 Migrate to cosmic-text](https://github.com/bevyengine/bevy/issues/7616) * [#6967 Changing the color of a TextSection triggers a redraw of the full Text](https://github.com/bevyengine/bevy/issues/6967) * [#5667 Some unicode characters are not rendered correctly](https://github.com/bevyengine/bevy/issues/5667) * [#1890 Text rasterization is based on world units instead of pixels](https://github.com/bevyengine/bevy/issues/1890) * [#1325 Support using system fonts](https://github.com/bevyengine/bevy/issues/1325)

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully