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

Missing instance records in fvar::Table #129

Open
zimond opened this issue Sep 20, 2023 · 4 comments
Open

Missing instance records in fvar::Table #129

zimond opened this issue Sep 20, 2023 · 4 comments

Comments

@zimond
Copy link
Contributor

zimond commented Sep 20, 2023

related #120.

I think based on the spec, there are instance records in fvar. But currently ttf-parser only parses axis record?

@RazrFalcon
Copy link
Collaborator

Yes, it is not implemented.

@zimond
Copy link
Contributor Author

zimond commented Sep 21, 2023

@RazrFalcon do you mind if I submit a PR for this?

@RazrFalcon
Copy link
Collaborator

Sure. Note that the PostScript name field is optional, making parsing more convoluted, since you cannot use read_array16

You can check it using:

let has_post_script_name = instance_length == (axes_count * 4) + 6;

I guess the only way to implement it is by creating a custom wrapper for InstanceRecords data blob with a get method that will do the parsing.

@inferiorhumanorgans
Copy link
Contributor

If an iterator pattern works then something like this is possible:

let names = face.tables().name.unwrap().names;

let fvar = face.tables().fvar.unwrap();

for instance in fvar.instances() {
    let subfamily = names
        .into_iter()
        .find(|n| n.name_id == instance.subfamily_name_id && n.is_unicode())
        .unwrap()
        .to_string()
        .unwrap();

    let ps_name = instance
        .ps_name_id
        .and_then(|name_id| {
            names
                .into_iter()
                .find(|n| n.name_id == name_id && n.is_unicode())
        })
        .and_then(|n| n.to_string());

    println!("subfamily: {subfamily}, ps_name: {ps_name:?}");
    for (axis, value) in fvar.axes.into_iter().zip(instance.user_tuples) {
        let axis_name = axis.tag.to_string();
        println!("\t{axis_name} {value:?}")
    }
    println!();
}

e.g.

./target/debug/examples/fvar ~/Library/Fonts/RobotoCondensed-VariableFont_wght.ttf
subfamily: Thin, ps_name: Some("RobotoCondensed-Thin")
        wght Fixed(100.0)

subfamily: ExtraLight, ps_name: Some("RobotoCondensed-ExtraLight")
        wght Fixed(200.0)

subfamily: Light, ps_name: Some("RobotoCondensed-Light")
        wght Fixed(300.0)

subfamily: Regular, ps_name: Some("RobotoCondensed-Regular")
        wght Fixed(400.0)

subfamily: Medium, ps_name: Some("RobotoCondensed-Medium")
        wght Fixed(500.0)

subfamily: SemiBold, ps_name: Some("RobotoCondensed-SemiBold")
        wght Fixed(600.0)

subfamily: Bold, ps_name: Some("RobotoCondensed-Bold")
        wght Fixed(700.0)

subfamily: ExtraBold, ps_name: Some("RobotoCondensed-ExtraBold")
        wght Fixed(800.0)

subfamily: Black, ps_name: Some("RobotoCondensed-Black")
        wght Fixed(900.0)

https://github.com/inferiorhumanorgans/ttf-parser/tree/fvar-instance

I'll hold off on a PR until someone who actually wants this feature can chime in with a use case and whether or not this is sufficient.

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

3 participants