Giter VIP home page Giter VIP logo

Comments (4)

inferiorhumanorgans avatar inferiorhumanorgans commented on September 25, 2024 2

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.

from ttf-parser.

RazrFalcon avatar RazrFalcon commented on September 25, 2024

Yes, it is not implemented.

from ttf-parser.

zimond avatar zimond commented on September 25, 2024

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

from ttf-parser.

RazrFalcon avatar RazrFalcon commented on September 25, 2024

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.

from ttf-parser.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.