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

Add support for the STAT table. #166

Merged
merged 17 commits into from
Aug 22, 2024

Conversation

inferiorhumanorgans
Copy link
Contributor

https://learn.microsoft.com/en-us/typography/opentype/spec/stat

This PR adds support for parsing the STAT table and its related data types. It's a pretty simple table but as in #87 the issues of testing and API design deserve some consideration.

Additionally, should this be placed behind a feature?

src/tables/stat.rs Outdated Show resolved Hide resolved
src/tables/stat.rs Outdated Show resolved Hide resolved
@RazrFalcon
Copy link
Collaborator

Thanks! Looks pretty good to me.

@yisibl
Copy link
Contributor

yisibl commented Aug 13, 2024

It looks like we can update the table in the readme.
https://github.com/RazrFalcon/ttf-parser?tab=readme-ov-file#alternatives

@RazrFalcon
Copy link
Collaborator

@yisibl good call!

src/tables/stat.rs Outdated Show resolved Hide resolved
examples/font-info.rs Outdated Show resolved Hide resolved
@RazrFalcon
Copy link
Collaborator

Ok, 1.51 compatibility is broken, but we're good otherwise.

@inferiorhumanorgans
Copy link
Contributor Author

Ok – I've rolled up a few other minor changes. I've also set up a few functions to abstract over getting the value and flags. If that seems in scope for this PR I can push those as well.

@RazrFalcon
Copy link
Collaborator

If that seems in scope for this PR I can push those as well.

Sure, let's take a look.

@inferiorhumanorgans
Copy link
Contributor Author

I'm not sure how far down the rabbit hole it's worth going with providing a higher level API. What I've exposed so far should be useful for both dynamic (e.g. name_id) and non-dynamic (e.g. contains) fonts.

For instance:

fn is_stat_italic() -> bool {
  if let Some(stat) = face.tables().stat {
    if let Some(subtable) = stat.subtable_for_axis(Tag::from_bytes(b"ital"), None) {
      if subtable.contains(Fixed(1.0)) {
        return true;
      }
    }
  }

  return false
}
fn is_bold() -> bool {
  if let Some(stat) = face.tables().stat {
    if let Some(subtable) = stat.subtable_for_axis(Tag::from_bytes(b"wght"), None) {
      if let Some(value) = subtable.value() {
        let named_weight = Weight::from(value.0 as u16);
        if named_weight == Weight::Bold {
          return true;
        }
      }
    }
  }

  return false
}

@RazrFalcon
Copy link
Collaborator

If you think it's good enough I'm fine with merging it.

@inferiorhumanorgans
Copy link
Contributor Author

Works for me.

@RazrFalcon RazrFalcon merged commit 9a5549c into harfbuzz:master Aug 22, 2024
2 checks passed
@inferiorhumanorgans inferiorhumanorgans deleted the stat-table branch August 22, 2024 16:52
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

Successfully merging this pull request may close these issues.

3 participants