Skip to content

Multiple fonts in a single Text do not work unless there is a space character #22191

@rparrett

Description

@rparrett

Bevy version and features

0.18.0-rc.1 and
current main (bisected to #21699 and further upstream, see pop-os/cosmic-text#445)

Relevant system information

SystemInfo { os: "macOS 15.6.1 Sequoia", kernel: "24.6.0", cpu: "Apple M4 Max", core_count: "16", memory: "64.0 GiB" }
AdapterInfo { name: "Apple M4 Max", vendor: 0, device: 0, device_type: IntegratedGpu, driver: "", driver_info: "", backend: Metal }

What you did

Place the following code in examples and cargo run --example 22190.

22190.rs
//! #22190

use bevy::prelude::*;

fn main() {
    let mut app = App::new();

    app.add_plugins(DefaultPlugins).add_systems(Startup, setup);

    app.run();
}

fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
    let garamond = TextFont {
        font: asset_server.load("fonts/EBGaramond12-Regular.otf"),
        ..default()
    };

    let sans_bold = TextFont {
        font: asset_server.load("fonts/FiraSans-Bold.ttf"),
        ..default()
    };

    commands.spawn(Camera2d);

    commands.spawn((
        Text::new("default"),
        Node {
            position_type: PositionType::Absolute,
            top: px(100),
            left: px(100),
            ..default()
        },
        children![
            (TextSpan::new("garamond"), garamond.clone()),
            (TextSpan::new("sans_bold"), sans_bold.clone())
        ],
    ));

    commands.spawn((
        Text::new("default "),
        Node {
            position_type: PositionType::Absolute,
            top: px(140),
            left: px(100),
            ..default()
        },
        children![
            (TextSpan::new("garamond "), garamond.clone()),
            (TextSpan::new("sans_bold "), sans_bold.clone())
        ],
    ));
}

What went wrong

Each line of text should show 3 separate fonts. But on the top line of text where there are no space characters, there is only one font.

Image

Additional information

Discovered while migrating bevy_simple_text_input.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-TextRendering and layout for charactersC-BugAn unexpected or incorrect behaviorS-BlockedThis cannot move forward until something else changes

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions