To determine if a font is italic, you can look at fsSelection
of the OS/2
table,
checking the 0th and 9th bit:
For instance, here’s fsSelection for "Inter Medium Italic":
node -p '(129).toString(2).split("").reverse().join("")'
=> 10000001 == ITALIC | USE_TYPO_METRICS
Bit# Value Meaning
0 1 ITALIC Font contains italic or oblique glyphs.
1 0 UNDERSCORE glyphs are underscored.
2 0 NEGATIVE glyphs have their foreground and background reversed.
3 0 OUTLINED Outline (hollow) glyphs, otherwise they are solid.
4 0 STRIKEOUT glyphs are overstruck.
5 0 BOLD glyphs are emboldened.
6 0 REGULAR glyphs are in the standard weight/style for the font.
7 1 USE_TYPO_METRICS
8 0 WWS The font has 'name' table strings consistent with a weight...
9 0 OBLIQUE Font contains oblique glyphs.
(10-15 are reserved)
and here’s fsSelection for "Inter Medium” (not italic):
node -p '(192).toString(2).split("").reverse().join("")'
=> 00000011 == REGULAR | USE_TYPO_METRICS
Bit# Value Meaning
0 0 ITALIC Font contains italic or oblique glyphs.
1 0 UNDERSCORE glyphs are underscored.
2 0 NEGATIVE glyphs have their foreground and background reversed.
3 0 OUTLINED Outline (hollow) glyphs, otherwise they are solid.
4 0 STRIKEOUT glyphs are overstruck.
5 0 BOLD glyphs are emboldened.
6 1 REGULAR glyphs are in the standard weight/style for the font.
7 1 USE_TYPO_METRICS
8 0 WWS The font has 'name' table strings consistent with a weight...
9 0 OBLIQUE Font contains oblique glyphs.
(10-15 are reserved)
There's also macStyle
in the head
table, which can be checked as well to support really old fonts.
macStyle
is 16 bits:
Bit# Meaning
0 Bold
1 Italic
2 Underline
3 Outline
4 Shadow
5 Condensed
6 Extended
(7–15 are reserved)
Example: for "Inter Medium Italic", macStyle
is 0100000
, and for "Inter Medium" it's 0000000
.
Note that the current OT spec states that fsSelection
takes priority over macStyle
(on Windows at least), and that PANOSE and post
table should always be ignored when determining
bold or italic. (i.e. italicAngle
of the post
table should be ignored.)
Check the usWeightClass
of the OS/2
table.
For instance, for "Inter Medium" it's 500
Value Description
100 Thin
200 Extra-light (Ultra-light)
300 Light
400 Normal (Regular)
500 Medium
600 Semi-bold (Demi-bold)
700 Bold
800 Extra-bold (Ultra-bold)
900 Black (Heavy)
Check the usWidthClass
of the OS/2
table.
For instance, for "Inter Medium" it's 5
Value Description % of normal
1 Ultra-condensed 50%
2 Extra-condensed 62.5%
3 Condensed 75%
4 Semi-condensed 87.5%
5 Medium (normal) 100%
6 Semi-expanded 112.5%
7 Expanded 125%
8 Extra-expanded 150%
9 Ultra-expanded 200%