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

Get font-weight value #78

Closed
swampthang opened this issue Apr 4, 2017 · 2 comments
Closed

Get font-weight value #78

swampthang opened this issue Apr 4, 2017 · 2 comments

Comments

@swampthang
Copy link

swampthang commented Apr 4, 2017

Where in the font object would I look to obtain a font-weight value as a number (400, 500, etc) or a string (bold, normal, etc)

Also, is there something that would tell me if the font is a monospace?

@Pomax
Copy link
Contributor

Pomax commented Apr 4, 2017

as long as you understand that font weights are not CSS font weights, you can query the OS/2 table for usWeightClass (https://www.microsoft.com/typography/otspec/os2.htm#wtc). Note that in OpenType-land this is not the same as the font style classification: you can have a normal font with weight 999 or a bold font with weight 1. There is no specification-defined relation between the two. The subfamily string for the font (regular, italic, bold, bold italic) can be found in the name table, as name record id 2 (if supplied in the font. It might be missing). There is also the OS/2 table's fsSelection value that overlaps with that, https://www.microsoft.com/typography/otspec/os2.htm#fst.

Finally, to tell if a font is monospaced, you can check the bProportion bit in the Panose classification (https://www.microsoft.com/typography/otspec/os2.htm#pan) but this is not super reliable. You can also check the "post" table for the isFixedPitch value (https://www.microsoft.com/typography/otspec/post.htm). And finally, you can check the "hmtx" table (https://www.microsoft.com/typography/otspec/hmtx.htm) because if your font is truly monospaced, there is only one horizontal metric value instead of a large number of different widths for (ranges of) glyph(s).

@swampthang
Copy link
Author

Thanks a bunch, Pomax. Much appreciated.

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