Skip to content

Add support for the STAT table. - #166

Merged
RazrFalcon merged 17 commits into
harfbuzz:masterfrom
inferiorhumanorgans:stat-table
Aug 22, 2024
Merged

RazrFalcon merged 17 commits into
harfbuzz:masterfrom
inferiorhumanorgans:stat-table

Conversation

@inferiorhumanorgans

Copy link
Copy Markdown
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?

Comment thread src/tables/stat.rs Resolved
Comment thread src/tables/stat.rs Resolved
Comment thread examples/font-info.rs Resolved
@RazrFalcon

Copy link
Copy Markdown
Collaborator

Thanks! Looks pretty good to me.

@yisibl

yisibl commented Aug 13, 2024

Copy link
Copy Markdown
Contributor

@RazrFalcon

Copy link
Copy Markdown
Collaborator

@yisibl good call!

Comment thread src/tables/stat.rs Resolved
Comment thread src/tables/stat.rs Resolved
Comment thread examples/font-info.rs Resolved
@RazrFalcon

Copy link
Copy Markdown
Collaborator

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

@inferiorhumanorgans

Copy link
Copy Markdown
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
Copy Markdown
Collaborator

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

Sure, let's take a look.

@inferiorhumanorgans

Copy link
Copy Markdown
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
Copy Markdown
Collaborator

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

@inferiorhumanorgans

Copy link
Copy Markdown
Contributor Author

Works for me.

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