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

set_font_families not working on linux #963

Open
MeetWq opened this issue Apr 4, 2024 · 3 comments
Open

set_font_families not working on linux #963

MeetWq opened this issue Apr 4, 2024 · 3 comments

Comments

@MeetWq
Copy link

MeetWq commented Apr 4, 2024

os: ubuntu 22.04
skia-safe version:

skia-safe = { version = "0.72.0", features = ["default", "textlayout"] }

I'm trying to set the font families in a paragraph, but it falls back to another font.
FontMgr.match_family_style finds the font, but FontCollection.find_typefaces does not.
I tried to run it on windows and was able to set the font families properly.

use skia_safe::{
    textlayout::{FontCollection, ParagraphBuilder, ParagraphStyle, TextStyle},
    FontMgr, FontStyle,
};

fn main() {
    let mut font_collection = FontCollection::new();
    font_collection.set_default_font_manager(FontMgr::new(), None);
    let family_name = "Ubuntu";
    let style = FontStyle::normal();
    println!(
        "match_family_style: {:?}",
        FontMgr::new()
            .match_family_style(family_name, style)
            .unwrap()
            .family_name()
    );
    println!(
        "find_typefaces: {:?}",
        font_collection.find_typefaces(&[family_name], style)[0].family_name()
    );

    let paragraph_style = ParagraphStyle::new();
    let mut paragraph_builder = ParagraphBuilder::new(&paragraph_style, &font_collection);
    let mut ts = TextStyle::new();
    ts.set_font_families(&[family_name]);
    paragraph_builder.push_style(&ts);
    paragraph_builder.add_text("test");
    let mut paragraph = paragraph_builder.build();
    paragraph.layout(100.0);
    for font_info in paragraph.get_fonts() {
        println!("font_info: {:?}", font_info.font.typeface().family_name());
    }
}

output:

match_family_style: "Ubuntu"
find_typefaces: "Noto Sans CJK SC"
font_info: "Noto Sans CJK SC"
@pragmatrix
Copy link
Member

I've installed a Ubuntu 22.04 in a container, installed Rust, libfontconfig1-dev, gcc, g++, git, curl, and fonts-ubuntu, and the output is:

match_family_style: "Ubuntu"
find_typefaces: "Ubuntu"
font_info: "Ubuntu"

after installing fonts-noto-cjk it stays the same. I am not sure why this happens.

@MeetWq
Copy link
Author

MeetWq commented Apr 7, 2024

I found out it's the locales setting causing it.
Previously the global default locale is

LANG=zh_CN.UTF-8

After I set it to English, it works.

export LANG=en_US.UTF-8

But I'm confused why locale affects this.

@MeetWq MeetWq closed this as completed Apr 8, 2024
@pragmatrix
Copy link
Member

Nice find!

Even though it is most likely an upstream Skia problem, I'd like to keep this issue open until it's clarified if it should behaving this way and why that is.

@pragmatrix pragmatrix reopened this Apr 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants