Skip to content
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

Support using system fonts #1325

Open
inodentry opened this issue Jan 26, 2021 · 10 comments
Open

Support using system fonts #1325

inodentry opened this issue Jan 26, 2021 · 10 comments
Labels
A-Text Rendering and layout for characters A-UI Graphical user interfaces, styles, layouts, and widgets C-Enhancement A new feature

Comments

@inodentry
Copy link
Contributor

Currently, to display text in bevy UI, a font file needs to be loaded as an asset.

Considering that bevy UI should be usable for general GUI applications (such as the future bevy editor) as well as games, it should support using fonts from the operating system. There should be a way to get the standard fonts that other GUI apps on the user's system use, or other installed fonts.

@visualcode-t
Copy link

Also: #1017

@tigregalis
Copy link
Contributor

Maybe font-kit could be used? Amethyst does the below:

use font_kit::{
    error::SelectionError,
    family_name::FamilyName,
    handle::Handle,
    properties::{Properties, Style},
    source::SystemSource,
};

/// Returns the default system font.
pub fn default_system_font() -> Result<Handle, SelectionError> {
    let source = SystemSource::new();
    let default_fonts = &[
        FamilyName::Title("arial".to_string()),
        FamilyName::SansSerif,
        FamilyName::Monospace,
        FamilyName::Fantasy,
    ];
    source.select_best_match(default_fonts, Properties::new().style(Style::Normal))
}

@inodentry
Copy link
Contributor Author

inodentry commented Jan 27, 2021

I didn't know about font-kit! Looks like an awesome crate exactly for this purpose!

Seems like it would be great to have integrated into bevy (or future Distill?) as the loader/source for font assets.

It looks like it could also provide font rendering (as an abstraction over freetype/directwrite/coretext/etc). Would we want to use it for that too?

@inodentry
Copy link
Contributor Author

@cart is using font-kit in bevy something you'd find desirable? I might want to play around with that this weekend, if you agree that it's a good idea.

@cart
Copy link
Member

cart commented Jan 30, 2021

Bevy used to render text using skribo, which in turn depends on font-kit. I explicitly moved off of it because it rendered the same fonts differently on different platforms (because internally it uses the native platform api to rasterize). For me cross platform consistency was more important than consistency of fonts rendered within the same os. Consistency across platforms is a hard requirement for me.

Additionally, moving to ab_glyph saved us 24 dependencies. Part of that could have been skribo, but im pretty sure most came from font-kit.

Font-kit is "big". All we really need is a way to discover and load fonts on a given platform, and that is a small subset of the features it provides. Before merging a pr with font-kit, I would want a cost benefit breakdown of features gained vs compile time + dependency count.

I don't want to reinvent the wheel. But I also don't want to strap on a monster truck wheel to a golf cart.
(im being intentionally dramatic here ... font-kit might not fit the metaphor).

@tigregalis
Copy link
Contributor

tigregalis commented Jan 30, 2021

It appears the font discovery/loading capability is all within the sources module (and that module doesn't go much further than that). Perhaps they might be encouraged to split it out into a separate crate.

@inodentry
Copy link
Contributor Author

I filed an issue with font-kit to ask about this.

@karroffel karroffel added C-Enhancement A new feature A-UI Graphical user interfaces, styles, layouts, and widgets labels Jan 30, 2021
@alice-i-cecile
Copy link
Member

cosmic_text includes font loading features. It looks like a fantastic, well-supported solution, and I think the right path forward for this issue is to migrate to cosmic_text and use their system fonts functionality.

@tigregalis
Copy link
Contributor

cosmic_text includes font loading features. It looks like a fantastic, well-supported solution, and I think the right path forward for this issue is to migrate to cosmic_text and use their system fonts functionality.

When you say migrate, do you mean replace ab-glyph, or simply to add on cosmic_text's system fonts functionality?

@alice-i-cecile
Copy link
Member

I would like to replace ab-glyph completely.

@nicoburns nicoburns added the A-Text Rendering and layout for characters label May 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Text Rendering and layout for characters A-UI Graphical user interfaces, styles, layouts, and widgets C-Enhancement A new feature
Projects
Status: Todo
Development

No branches or pull requests

7 participants