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

Custom fonts have vertical offset with unicode symbols #2700

Closed
woelper opened this issue Feb 8, 2023 · 3 comments · Fixed by #2724
Closed

Custom fonts have vertical offset with unicode symbols #2700

woelper opened this issue Feb 8, 2023 · 3 comments · Fixed by #2724
Labels
bug Something is broken text Problems related to text

Comments

@woelper
Copy link

woelper commented Feb 8, 2023

Egui default font with 0.21:

image

Noto sans with 0.19:
image

Noto sans with 0.21:
image

Although a bit hard to see, all symbols are offset in the y direction. I tried different fonts such as IBM plex, and they show this as well.

Describe the bug
Symbols are not vertically aligned with text if using a custom font.

To Reproduce
Steps to reproduce the behavior:

pub fn new(cc: &eframe::CreationContext<'_>) -> Self {
    let mut fonts = FontDefinitions::default();
    fonts.font_data.insert(
        "my_font".to_owned(),
        FontData::from_static(include_bytes!("../res/fonts/NotoSans-Regular.ttf")),
        // FontData::from_static(include_bytes!("../res/fonts/IBMPlexSans-Regular.ttf")),
    );
    fonts
        .families
        .get_mut(&FontFamily::Proportional)
        .unwrap()
        .insert(0, "my_font".to_owned());
    cc.egui_ctx.set_fonts(fonts);
    Default::default()
}
@woelper woelper added the bug Something is broken label Feb 8, 2023
@woelper
Copy link
Author

woelper commented Feb 8, 2023

Actually after reading your post and trying Inter (which worked and is vertically aligned with symbols) I am not so sure any more if I just picked the wrong fonts. Noto and Plex are pretty common though and I wonder what they do differently.

@emilk
Copy link
Owner

emilk commented Feb 9, 2023

There may be a "vertical offset" font attribute that egui ignores, and shouldn't. In any case, you can tweak the y-offset when you load your fonts using https://docs.rs/egui/latest/egui/struct.FontData.html#method.tweak

@emilk emilk added the text Problems related to text label Feb 9, 2023
@aevyrie
Copy link
Contributor

aevyrie commented Feb 12, 2023

I've run into this using Roboto, and had to add a manual y offset in the font tweaks. Issue found when upgrading to v0.20.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something is broken text Problems related to text
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants