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

"Ubuntu" matches "Ubuntu-ExtraBold" #245

Open
SamRodri opened this issue Jun 5, 2024 · 3 comments
Open

"Ubuntu" matches "Ubuntu-ExtraBold" #245

SamRodri opened this issue Jun 5, 2024 · 3 comments

Comments

@SamRodri
Copy link

SamRodri commented Jun 5, 2024

On Ubuntu 24.04, run: $ cargo run --example match-font -- "Ubuntu"

Output:

Path: /usr/share/fonts/truetype/ubuntu/Ubuntu[wdth,wght].ttf
Index: 393216
Family name: Ubuntu
PostScript name: Ubuntu-ExtraBold
Style: Normal
Weight: Weight(400.0)
Stretch: Stretch(1.0)

Interesting $ fc-match "Ubuntu :weight=400" has the same error, but Firefox matches the correct font.

@mrobinson
Copy link
Member

I think this is expected behavior. "Ubuntu" is the family name and "Ubuntu Extra Bold" is the postscript name of a variant within that family. You will need to look through all the variants to find the one you need.

@SamRodri
Copy link
Author

SamRodri commented Jun 5, 2024

I expected font_kit::source::SystemSource::new().select_best_match to get the regular Ubuntu, given that the weight is NORMAL=400

@SamRodri
Copy link
Author

SamRodri commented Jun 6, 2024

I had a look into this:

First FontConfig does not have the same bug, they just use a different weight scale, normal is "80" there:
$ fc-match "Ubuntu :weight=80" outputs "Ubuntu" "Regular"

Second, the issue is that the Ubuntu font uses "named variation instances" to define multiple weights on the same TTF file (not a TTC), the OS/2 table is the same for the entire file, with the same usWeightClass, I don't know where the "named instances" are stored.

This test code:

let family = font_kit::source::SystemSource::new()
    .select_family_by_name("Ubuntu")
    .unwrap();
for handle in family.fonts() {
    let (path, index) = match &handle {
        font_kit::handle::Handle::Path { path, font_index } => (path, font_index),
        font_kit::handle::Handle::Memory { .. } => unreachable!(),
    };
    let font = handle.load().unwrap();
    println!(
        "{}, index={}, {}, {:?}",
        path.file_name().unwrap().to_string_lossy(),
        index,
        font.postscript_name().unwrap(),
        font.properties().weight,
    );
}

Outputs:

Ubuntu[wdth,wght].ttf, index=393216, Ubuntu-ExtraBold, Weight(400.0)
Ubuntu[wdth,wght].ttf, index=589824, Ubuntu-Condensed, Weight(400.0)
Ubuntu[wdth,wght].ttf, index=524288, Ubuntu-CondensedLight, Weight(400.0)
Ubuntu[wdth,wght].ttf, index=720896, Ubuntu-CondensedBold, Weight(400.0)
Ubuntu[wdth,wght].ttf, index=655360, Ubuntu-CondensedMedium, Weight(400.0)
Ubuntu[wdth,wght].ttf, index=786432, Ubuntu-CondensedExtraBold, Weight(400.0)
<Ubuntu-Italic[wdth,wght].ttf omitted>
Ubuntu[wdth,wght].ttf, index=65536, Ubuntu-Thin, Weight(400.0)
Ubuntu[wdth,wght].ttf, index=0, Ubuntu-Regular, Weight(400.0)
Ubuntu[wdth,wght].ttf, index=131072, Ubuntu-Light, Weight(400.0)
Ubuntu[wdth,wght].ttf, index=327680, Ubuntu-Bold, Weight(400.0)
Ubuntu[wdth,wght].ttf, index=262144, Ubuntu-Medium, Weight(400.0)
Ubuntu[wdth,wght].ttf, index=458752, Ubuntu-CondensedThin, Weight(400.0)


Notice the same weight for all "fonts".

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