Dimchikkk / bevy_cosmic_edit

Apache License 2.0
86 stars 9 forks source link

how to use external fonts? #157

Closed databasedav closed 1 month ago

databasedav commented 2 months ago

for example, if i want to use the FiraMono-Medium.ttf font packaged with bevy, i have the following code

let font_bytes: &[u8] = include_bytes!("../assets/fonts/FiraMono-Medium.ttf");
let font_config = CosmicFontConfig {
    fonts_dir_path: None,
    font_bytes: Some(vec![font_bytes]),
    load_system_fonts: true,
};

App::new()
    .add_plugins(DefaultPlugins)
    .add_plugins(CosmicEditPlugin {
        font_config,
        ..default()
    })

but specifying attrs = attrs.family(Family::Name("Fira Mono")); doesn't seem to do anything, how do i tell which Family::Name string actually maps to the fira mono .ttf? attrs = attrs.family(Family::Name("Victor Mono")); works as expected

Dimchikkk commented 2 months ago

Victor Mono Regular has normal font weight that is 400 (this is default weight), Fira Mono Medium has medium font weight that is 500. To use Fira Mono Medium have to set font weight to medium:

    attrs = attrs.family(Family::Name("Fira Mono"));
    attrs = attrs.weight(FontWeight::MEDIUM);