yeslogic / fontconfig-rs

Safe wrapper around freedesktop.org's fontconfig library, for locating fonts on UNIX like systems.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

how to get font name by FAMILY_LANG?

lencil opened this issue · comments

in some case, one font has many family name of each lang. I need get non-english FAMILY name, but use Pattern.get_string(FC_FULLNAME.as_cstr()), only one name will generate.

I think you need to get the lang property of the font (FC_LANG), then loop over each language and build a pattern that matches the font and that language. Then match again for each language. With the language included in the pattern Pattern.get_string(FC_FULLNAME.as_cstr()) should return the name in that language.

I'm not 100% certain we expose all the bits to do this in the high-level wrapper. You might need to use fontconfig-sys directly. Then when you have it working let us know what is missing from the high-level API.

ok, wait for me to try again with fontconfg-sys.

use FC_NAMELANG work fine. no fontcong-sys needed.

    let fc = Fontconfig::new().unwrap();
    let mut pat = Pattern::new(&fc);
    let family = CString::new("FZShuti").ok().unwrap();
    pat.add_string(FC_FAMILY.as_cstr(), &family);
    pat.add_string(fontconfig::FC_NAMELANG.as_cstr(), &CString::new("zh-cn").ok().unwrap());
    let font_match = pat.font_match();
    print!("{}", font_match.name().unwrap());

Great 👍 Ok to close the issue?