Skip to content

Commit e795c96

Browse files
committed
added support for [OS/2] xHeight and [OS/2] CapHeight metrics in report table
1 parent 8b7638e commit e795c96

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

lib/fontline/commands.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ def get_font_report(fontpath):
1919
os2_win_ascent = tt['OS/2'].usWinAscent
2020
os2_win_descent = tt['OS/2'].usWinDescent
2121
os2_typo_linegap = tt['OS/2'].sTypoLineGap
22+
os2_x_height = tt['OS/2'].sxHeight
23+
os2_cap_height = tt['OS/2'].sCapHeight
2224
hhea_ascent = tt['hhea'].ascent
2325
hhea_descent = tt['hhea'].descent
2426
hhea_linegap = tt['hhea'].lineGap
@@ -40,7 +42,7 @@ def get_font_report(fontpath):
4042
namerecord_list = tt['name'].names
4143
# The version string
4244
for needle in namerecord_list:
43-
if needle.langID == 0 and needle.nameID == 5:
45+
if needle.nameID == 5:
4446
report.append(needle.toStr())
4547
break
4648
# The SHA1 string
@@ -51,6 +53,8 @@ def get_font_report(fontpath):
5153
report.append("[head] Units per Em: \t{}".format(units_per_em))
5254
report.append("[head] yMax: \t\t{}".format(ymax))
5355
report.append("[head] yMin: \t\t{}".format(ymin))
56+
report.append("[OS/2] CapHeight: \t{}".format(os2_cap_height))
57+
report.append("[OS/2] xHeight: \t{}".format(os2_x_height))
5458
report.append("[OS/2] TypoAscender: \t{}".format(os2_typo_ascender))
5559
report.append("[OS/2] TypoDescender: \t{}".format(os2_typo_descender))
5660
report.append("[OS/2] WinAscent: \t{}".format(os2_win_ascent))

tests/test_report_cmd.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,42 @@ def test_report_cmd_reportstring_upm(capsys):
7575
assert "[head] Units per Em: \t2048" in out
7676

7777

78+
def test_report_cmd_reportstring_ymax(capsys):
79+
from fontline.app import main
80+
filepath = os.path.join('tests', 'testingfiles', 'Hack-Regular.ttf')
81+
sys.argv = ['font-line', 'report', filepath]
82+
main()
83+
out, err = capsys.readouterr()
84+
assert "[head] yMax: \t\t2001" in out
85+
86+
87+
def test_report_cmd_reportstring_ymin(capsys):
88+
from fontline.app import main
89+
filepath = os.path.join('tests', 'testingfiles', 'Hack-Regular.ttf')
90+
sys.argv = ['font-line', 'report', filepath]
91+
main()
92+
out, err = capsys.readouterr()
93+
assert "[head] yMin: \t\t-573" in out
94+
95+
96+
def test_report_cmd_reportstring_capheight(capsys):
97+
from fontline.app import main
98+
filepath = os.path.join('tests', 'testingfiles', 'Hack-Regular.ttf')
99+
sys.argv = ['font-line', 'report', filepath]
100+
main()
101+
out, err = capsys.readouterr()
102+
assert "[OS/2] CapHeight: \t1493" in out
103+
104+
105+
def test_report_cmd_reportstring_xheight(capsys):
106+
from fontline.app import main
107+
filepath = os.path.join('tests', 'testingfiles', 'Hack-Regular.ttf')
108+
sys.argv = ['font-line', 'report', filepath]
109+
main()
110+
out, err = capsys.readouterr()
111+
assert "[OS/2] xHeight: \t1120" in out
112+
113+
78114
def test_report_cmd_reportstring_typoascender(capsys):
79115
from fontline.app import main
80116
filepath = os.path.join('tests', 'testingfiles', 'Hack-Regular.ttf')

0 commit comments

Comments
 (0)