jakobhellermann / bevy-inspector-egui

Inspector plugin for the bevy game engine
Apache License 2.0
1.15k stars 169 forks source link

Cannot render CJK characters correctly #58

Closed piaoger closed 2 years ago

piaoger commented 2 years ago

CJK characters cannot be handled as shown in below image. Do you have any ideas to resolve it?

1651865032(1)

jakobhellermann commented 2 years ago

That is probably an issue with egui. If you try running one of their examples with CJK text, does it work?

piaoger commented 2 years ago

Yes, I cannot find a way to get egui raw context yesterday :)

I fixed that problem by calling setfonts api as following:

fn configure_visuals(mut egui_ctx: ResMut<EguiContext>) {
    egui_ctx.ctx_mut().set_visuals(egui::Visuals {
        window_rounding: 0.0.into(),
        ..Default::default()
    });

    // support customized fonts
    {
        let mut fonts = egui::FontDefinitions::default();

        // Install my own font (maybe supporting non-latin characters):
        // .ttf and .otf supported
           // Put my font first (highest priority):
        fonts.font_data.insert(
            "cjk_font".to_owned(),
            egui::FontData::from_static(include_bytes!("../assets/fonts/adobe/SourceHanSansCN-Normal.otf")),
        );
        fonts
            .families
            .get_mut(&egui::FontFamily::Proportional)
            .unwrap()
            .insert(0, "cjk_font".to_owned());
        egui_ctx.ctx_mut().set_fonts(fonts);
    }
}

image

jakobhellermann commented 2 years ago

Awesome, I added a note to the readme: https://github.com/jakobhellermann/bevy-inspector-egui/#common-issues