Skip to content

Commit 60bf88f

Browse files
committed
Merge branch 'patch' of https://github.com/moyogo/font-line into v0.6.1
2 parents 0437fba + 711c45c commit 60bf88f

File tree

2 files changed

+127
-121
lines changed

2 files changed

+127
-121
lines changed

lib/fontline/commands.py

Lines changed: 64 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,17 @@ def get_font_report(fontpath):
1414
tt = ttLib.TTFont(fontpath)
1515

1616
# Vertical metrics values as integers
17-
os2_typo_ascender = tt['OS/2'].__dict__['sTypoAscender']
18-
os2_typo_descender = tt['OS/2'].__dict__['sTypoDescender']
19-
os2_win_ascent = tt['OS/2'].__dict__['usWinAscent']
20-
os2_win_descent = tt['OS/2'].__dict__['usWinDescent']
21-
os2_typo_linegap = tt['OS/2'].__dict__['sTypoLineGap']
22-
hhea_ascent = tt['hhea'].__dict__['ascent']
23-
hhea_descent = tt['hhea'].__dict__['descent']
24-
hhea_linegap = tt['hhea'].__dict__['lineGap']
25-
ymax = tt['head'].__dict__['yMax']
26-
ymin = tt['head'].__dict__['yMin']
27-
units_per_em = tt['head'].__dict__['unitsPerEm']
17+
os2_typo_ascender = tt['OS/2'].sTypoAscender
18+
os2_typo_descender = tt['OS/2'].sTypoDescender
19+
os2_win_ascent = tt['OS/2'].usWinAscent
20+
os2_win_descent = tt['OS/2'].usWinDescent
21+
os2_typo_linegap = tt['OS/2'].sTypoLineGap
22+
hhea_ascent = tt['hhea'].ascent
23+
hhea_descent = tt['hhea'].descent
24+
hhea_linegap = tt['hhea'].lineGap
25+
ymax = tt['head'].yMax
26+
ymin = tt['head'].yMin
27+
units_per_em = tt['head'].unitsPerEm
2828

2929
# Calculated values
3030
os2_typo_total_height = os2_typo_ascender + -(os2_typo_descender)
@@ -35,56 +35,62 @@ def get_font_report(fontpath):
3535
hheaascdesc_to_upm = 1.0 * hhea_total_height / units_per_em
3636

3737
# The file path header
38-
report_string = " \n"
39-
report_string = report_string + "=== " + fontpath + " ===\n"
40-
namerecord_list = tt['name'].__dict__['names']
38+
report = [" "]
39+
report.append("=== " + fontpath + " ===")
40+
namerecord_list = tt['name'].names
4141
# The version string
4242
for needle in namerecord_list:
43-
if needle.__dict__['langID'] == 0 and needle.__dict__['nameID'] == 5:
44-
report_string = report_string + str(needle.__dict__['string']) + "\n"
43+
if needle.langID == 0 and needle.nameID == 5:
44+
report.append(needle.toStr())
45+
break
4546
# The SHA1 string
46-
report_string = report_string + "SHA1: " + get_sha1(fontpath) + "\n\n"
47+
report.append("SHA1: " + get_sha1(fontpath))
48+
report.append("")
4749
# The vertical metrics strings
48-
report_string = report_string + "--- Metrics ---" + "\n"
49-
report_string = report_string + "[head] Units per Em: \t" + str(units_per_em) + "\n"
50-
report_string = report_string + "[head] yMax: \t\t" + str(ymax) + "\n"
51-
report_string = report_string + "[head] yMin: \t\t" + str(ymin) + "\n"
52-
report_string = report_string + "[OS/2] TypoAscender: \t" + str(os2_typo_ascender) + "\n"
53-
report_string = report_string + "[OS/2] TypoDescender: \t" + str(os2_typo_descender) + "\n"
54-
report_string = report_string + "[OS/2] WinAscent: \t" + str(os2_win_ascent) + "\n"
55-
report_string = report_string + "[OS/2] WinDescent: \t" + str(os2_win_descent) + "\n"
56-
report_string = report_string + "[hhea] Ascent: \t\t" + str(hhea_ascent) + "\n"
57-
report_string = report_string + "[hhea] Descent: \t" + str(hhea_descent) + "\n\n"
58-
report_string = report_string + "[hhea] LineGap: \t" + str(hhea_linegap) + "\n"
59-
report_string = report_string + "[OS/2] TypoLineGap: \t" + str(os2_typo_linegap) + "\n\n"
60-
report_string = report_string + "--- Height Calculations by Table Values ---" + "\n"
61-
report_string = report_string + "[OS/2] TypoAscender to TypoDescender: \t" + str(os2_typo_total_height) + "\n"
62-
report_string = report_string + "[OS/2] WinAscent to WinDescent: \t" + str(os2_win_total_height) + "\n"
63-
report_string = report_string + "[hhea] Ascent to Descent: \t\t" + str(hhea_total_height) + "\n\n"
64-
report_string = report_string + "--- Delta Values ---" + "\n"
65-
report_string = report_string + "WinAscent to TypoAscender: \t" + str(os2_win_ascent - os2_typo_ascender) + "\n"
66-
report_string = report_string + "Ascent to TypoAscender: \t" + str(hhea_ascent - os2_typo_ascender) + "\n"
67-
report_string = report_string + "WinDescent to TypoDescender: \t" + str(os2_win_descent - -(os2_typo_descender)) + "\n"
68-
report_string = report_string + "Descent to TypoDescender: \t" + str(os2_typo_descender - hhea_descent) + "\n\n"
69-
report_string = report_string + "--- Ratios ---" + "\n"
70-
report_string = report_string + "(Typo Asc + Desc + Linegap) / UPM: \t" + str('{0:.3g}'.format(typo_to_upm)) + "\n"
71-
report_string = report_string + "(winAsc + winDesc) / UPM: \t\t" + str('{0:.3g}'.format(winascdesc_to_upm)) + "\n"
72-
report_string = report_string + "(hhea Asc + Desc) / UPM: \t\t" + str('{0:.3g}'.format(hheaascdesc_to_upm))
73-
74-
return report_string
50+
report.append("--- Metrics ---")
51+
report.append("[head] Units per Em: \t{}".format(units_per_em))
52+
report.append("[head] yMax: \t\t{}".format(ymax))
53+
report.append("[head] yMin: \t\t{}".format(ymin))
54+
report.append("[OS/2] TypoAscender: \t{}".format(os2_typo_ascender))
55+
report.append("[OS/2] TypoDescender: \t{}".format(os2_typo_descender))
56+
report.append("[OS/2] WinAscent: \t{}".format(os2_win_ascent))
57+
report.append("[OS/2] WinDescent: \t{}".format(os2_win_descent))
58+
report.append("[hhea] Ascent: \t\t{}".format(hhea_ascent))
59+
report.append("[hhea] Descent: \t{}".format(hhea_descent))
60+
report.append("")
61+
report.append("[hhea] LineGap: \t{}".format(hhea_linegap))
62+
report.append("[OS/2] TypoLineGap: \t{}".format(os2_typo_linegap))
63+
report.append("")
64+
report.append("--- Height Calculations by Table Values ---")
65+
report.append("[OS/2] TypoAscender to TypoDescender: \t{}".format(os2_typo_total_height))
66+
report.append("[OS/2] WinAscent to WinDescent: \t{}".format(os2_win_total_height))
67+
report.append("[hhea] Ascent to Descent: \t\t{}".format(hhea_total_height))
68+
report.append("")
69+
report.append("--- Delta Values ---")
70+
report.append("WinAscent to TypoAscender: \t{}".format(os2_win_ascent - os2_typo_ascender))
71+
report.append("Ascent to TypoAscender: \t{}".format(hhea_ascent - os2_typo_ascender))
72+
report.append("WinDescent to TypoDescender: \t{}".format(os2_win_descent - -(os2_typo_descender)))
73+
report.append("Descent to TypoDescender: \t{}".format(os2_typo_descender - hhea_descent))
74+
report.append("")
75+
report.append("--- Ratios ---")
76+
report.append("(Typo Asc + Desc + Linegap) / UPM: \t{0:.3g}".format(typo_to_upm))
77+
report.append("(winAsc + winDesc) / UPM: \t\t{0:.3g}".format(winascdesc_to_upm))
78+
report.append("(hhea Asc + Desc) / UPM: \t\t{0:.3g}".format(hheaascdesc_to_upm))
79+
80+
return "\n".join(report)
7581

7682

7783
def modify_linegap_percent(fontpath, percent):
7884
try:
7985
tt = ttLib.TTFont(fontpath)
8086

8187
# get observed start values from the font
82-
os2_typo_ascender = tt['OS/2'].__dict__['sTypoAscender']
83-
os2_typo_descender = tt['OS/2'].__dict__['sTypoDescender']
84-
os2_typo_linegap = tt['OS/2'].__dict__['sTypoLineGap']
85-
hhea_ascent = tt['hhea'].__dict__['ascent']
86-
hhea_descent = tt['hhea'].__dict__['descent']
87-
units_per_em = tt['head'].__dict__['unitsPerEm']
88+
os2_typo_ascender = tt['OS/2'].sTypoAscender
89+
os2_typo_descender = tt['OS/2'].sTypoDescender
90+
os2_typo_linegap = tt['OS/2'].sTypoLineGap
91+
hhea_ascent = tt['hhea'].ascent
92+
hhea_descent = tt['hhea'].descent
93+
units_per_em = tt['head'].unitsPerEm
8894

8995
# calculate necessary delta values
9096
os2_typo_ascdesc_delta = os2_typo_ascender + -(os2_typo_descender)
@@ -130,14 +136,14 @@ def modify_linegap_percent(fontpath, percent):
130136
os2_win_descent = -hhea_descent
131137

132138
# define updated values from above calculations
133-
tt['hhea'].__dict__['lineGap'] = hhea_linegap
134-
tt['OS/2'].__dict__['sTypoAscender'] = os2_typo_ascender
135-
tt['OS/2'].__dict__['sTypoDescender'] = os2_typo_descender
136-
tt['OS/2'].__dict__['sTypoLineGap'] = os2_typo_linegap
137-
tt['OS/2'].__dict__['usWinAscent'] = os2_win_ascent
138-
tt['OS/2'].__dict__['usWinDescent'] = os2_win_descent
139-
tt['hhea'].__dict__['ascent'] = hhea_ascent
140-
tt['hhea'].__dict__['descent'] = hhea_descent
139+
tt['hhea'].lineGap = hhea_linegap
140+
tt['OS/2'].sTypoAscender = os2_typo_ascender
141+
tt['OS/2'].sTypoDescender = os2_typo_descender
142+
tt['OS/2'].sTypoLineGap = os2_typo_linegap
143+
tt['OS/2'].usWinAscent = os2_win_ascent
144+
tt['OS/2'].usWinDescent = os2_win_descent
145+
tt['hhea'].ascent = hhea_ascent
146+
tt['hhea'].descent = hhea_descent
141147

142148
tt.save(get_linegap_percent_filepath(fontpath, percent))
143149
return True

tests/test_percent_cmd.py

Lines changed: 63 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -120,15 +120,15 @@ def test_percent_cmd_ttf_file_10_percent_default_approach(capsys):
120120

121121
tt = ttLib.TTFont(newfont_path)
122122

123-
os2_typo_ascender = tt['OS/2'].__dict__['sTypoAscender']
124-
os2_typo_descender = tt['OS/2'].__dict__['sTypoDescender']
125-
os2_win_ascent = tt['OS/2'].__dict__['usWinAscent']
126-
os2_win_descent = tt['OS/2'].__dict__['usWinDescent']
127-
os2_typo_linegap = tt['OS/2'].__dict__['sTypoLineGap']
128-
hhea_ascent = tt['hhea'].__dict__['ascent']
129-
hhea_descent = tt['hhea'].__dict__['descent']
130-
hhea_linegap = tt['hhea'].__dict__['lineGap']
131-
units_per_em = tt['head'].__dict__['unitsPerEm']
123+
os2_typo_ascender = tt['OS/2'].sTypoAscender
124+
os2_typo_descender = tt['OS/2'].sTypoDescender
125+
os2_win_ascent = tt['OS/2'].usWinAscent
126+
os2_win_descent = tt['OS/2'].usWinDescent
127+
os2_typo_linegap = tt['OS/2'].sTypoLineGap
128+
hhea_ascent = tt['hhea'].ascent
129+
hhea_descent = tt['hhea'].descent
130+
hhea_linegap = tt['hhea'].lineGap
131+
units_per_em = tt['head'].unitsPerEm
132132

133133
assert os2_typo_ascender == 1556
134134
assert os2_typo_descender == -492
@@ -166,15 +166,15 @@ def test_percent_cmd_otf_file_10_percent_default_approach(capsys):
166166

167167
tt = ttLib.TTFont(newfont_path)
168168

169-
os2_typo_ascender = tt['OS/2'].__dict__['sTypoAscender']
170-
os2_typo_descender = tt['OS/2'].__dict__['sTypoDescender']
171-
os2_win_ascent = tt['OS/2'].__dict__['usWinAscent']
172-
os2_win_descent = tt['OS/2'].__dict__['usWinDescent']
173-
os2_typo_linegap = tt['OS/2'].__dict__['sTypoLineGap']
174-
hhea_ascent = tt['hhea'].__dict__['ascent']
175-
hhea_descent = tt['hhea'].__dict__['descent']
176-
hhea_linegap = tt['hhea'].__dict__['lineGap']
177-
units_per_em = tt['head'].__dict__['unitsPerEm']
169+
os2_typo_ascender = tt['OS/2'].sTypoAscender
170+
os2_typo_descender = tt['OS/2'].sTypoDescender
171+
os2_win_ascent = tt['OS/2'].usWinAscent
172+
os2_win_descent = tt['OS/2'].usWinDescent
173+
os2_typo_linegap = tt['OS/2'].sTypoLineGap
174+
hhea_ascent = tt['hhea'].ascent
175+
hhea_descent = tt['hhea'].descent
176+
hhea_linegap = tt['hhea'].lineGap
177+
units_per_em = tt['head'].unitsPerEm
178178

179179
assert os2_typo_ascender == 1556
180180
assert os2_typo_descender == -492
@@ -212,15 +212,15 @@ def test_percent_cmd_ttf_file_30_percent_default_approach(capsys):
212212

213213
tt = ttLib.TTFont(newfont_path)
214214

215-
os2_typo_ascender = tt['OS/2'].__dict__['sTypoAscender']
216-
os2_typo_descender = tt['OS/2'].__dict__['sTypoDescender']
217-
os2_win_ascent = tt['OS/2'].__dict__['usWinAscent']
218-
os2_win_descent = tt['OS/2'].__dict__['usWinDescent']
219-
os2_typo_linegap = tt['OS/2'].__dict__['sTypoLineGap']
220-
hhea_ascent = tt['hhea'].__dict__['ascent']
221-
hhea_descent = tt['hhea'].__dict__['descent']
222-
hhea_linegap = tt['hhea'].__dict__['lineGap']
223-
units_per_em = tt['head'].__dict__['unitsPerEm']
215+
os2_typo_ascender = tt['OS/2'].sTypoAscender
216+
os2_typo_descender = tt['OS/2'].sTypoDescender
217+
os2_win_ascent = tt['OS/2'].usWinAscent
218+
os2_win_descent = tt['OS/2'].usWinDescent
219+
os2_typo_linegap = tt['OS/2'].sTypoLineGap
220+
hhea_ascent = tt['hhea'].ascent
221+
hhea_descent = tt['hhea'].descent
222+
hhea_linegap = tt['hhea'].lineGap
223+
units_per_em = tt['head'].unitsPerEm
224224

225225
assert os2_typo_ascender == 1556
226226
assert os2_typo_descender == -492
@@ -260,15 +260,15 @@ def test_percent_cmd_ttf_file_10_percent_google_approach(capsys):
260260

261261
tt = ttLib.TTFont(newfont_path)
262262

263-
os2_typo_ascender = tt['OS/2'].__dict__['sTypoAscender']
264-
os2_typo_descender = tt['OS/2'].__dict__['sTypoDescender']
265-
os2_win_ascent = tt['OS/2'].__dict__['usWinAscent']
266-
os2_win_descent = tt['OS/2'].__dict__['usWinDescent']
267-
os2_typo_linegap = tt['OS/2'].__dict__['sTypoLineGap']
268-
hhea_ascent = tt['hhea'].__dict__['ascent']
269-
hhea_descent = tt['hhea'].__dict__['descent']
270-
hhea_linegap = tt['hhea'].__dict__['lineGap']
271-
units_per_em = tt['head'].__dict__['unitsPerEm']
263+
os2_typo_ascender = tt['OS/2'].sTypoAscender
264+
os2_typo_descender = tt['OS/2'].sTypoDescender
265+
os2_win_ascent = tt['OS/2'].usWinAscent
266+
os2_win_descent = tt['OS/2'].usWinDescent
267+
os2_typo_linegap = tt['OS/2'].sTypoLineGap
268+
hhea_ascent = tt['hhea'].ascent
269+
hhea_descent = tt['hhea'].descent
270+
hhea_linegap = tt['hhea'].lineGap
271+
units_per_em = tt['head'].unitsPerEm
272272

273273
assert os2_typo_ascender == 885
274274
assert os2_typo_descender == -215
@@ -306,15 +306,15 @@ def test_percent_cmd_ttf_file_30_percent_google_approach(capsys):
306306

307307
tt = ttLib.TTFont(newfont_path)
308308

309-
os2_typo_ascender = tt['OS/2'].__dict__['sTypoAscender']
310-
os2_typo_descender = tt['OS/2'].__dict__['sTypoDescender']
311-
os2_win_ascent = tt['OS/2'].__dict__['usWinAscent']
312-
os2_win_descent = tt['OS/2'].__dict__['usWinDescent']
313-
os2_typo_linegap = tt['OS/2'].__dict__['sTypoLineGap']
314-
hhea_ascent = tt['hhea'].__dict__['ascent']
315-
hhea_descent = tt['hhea'].__dict__['descent']
316-
hhea_linegap = tt['hhea'].__dict__['lineGap']
317-
units_per_em = tt['head'].__dict__['unitsPerEm']
309+
os2_typo_ascender = tt['OS/2'].sTypoAscender
310+
os2_typo_descender = tt['OS/2'].sTypoDescender
311+
os2_win_ascent = tt['OS/2'].usWinAscent
312+
os2_win_descent = tt['OS/2'].usWinDescent
313+
os2_typo_linegap = tt['OS/2'].sTypoLineGap
314+
hhea_ascent = tt['hhea'].ascent
315+
hhea_descent = tt['hhea'].descent
316+
hhea_linegap = tt['hhea'].lineGap
317+
units_per_em = tt['head'].unitsPerEm
318318

319319
assert os2_typo_ascender == 985
320320
assert os2_typo_descender == -315
@@ -355,15 +355,15 @@ def test_percent_cmd_ttf_file_10_percent_adobe_approach(capsys):
355355

356356
tt = ttLib.TTFont(newfont_path)
357357

358-
os2_typo_ascender = tt['OS/2'].__dict__['sTypoAscender']
359-
os2_typo_descender = tt['OS/2'].__dict__['sTypoDescender']
360-
os2_win_ascent = tt['OS/2'].__dict__['usWinAscent']
361-
os2_win_descent = tt['OS/2'].__dict__['usWinDescent']
362-
os2_typo_linegap = tt['OS/2'].__dict__['sTypoLineGap']
363-
hhea_ascent = tt['hhea'].__dict__['ascent']
364-
hhea_descent = tt['hhea'].__dict__['descent']
365-
hhea_linegap = tt['hhea'].__dict__['lineGap']
366-
units_per_em = tt['head'].__dict__['unitsPerEm']
358+
os2_typo_ascender = tt['OS/2'].sTypoAscender
359+
os2_typo_descender = tt['OS/2'].sTypoDescender
360+
os2_win_ascent = tt['OS/2'].usWinAscent
361+
os2_win_descent = tt['OS/2'].usWinDescent
362+
os2_typo_linegap = tt['OS/2'].sTypoLineGap
363+
hhea_ascent = tt['hhea'].ascent
364+
hhea_descent = tt['hhea'].descent
365+
hhea_linegap = tt['hhea'].lineGap
366+
units_per_em = tt['head'].unitsPerEm
367367

368368
assert os2_typo_ascender == 750
369369
assert os2_typo_descender == -250
@@ -401,15 +401,15 @@ def test_percent_cmd_ttf_file_30_percent_adobe_approach(capsys):
401401

402402
tt = ttLib.TTFont(newfont_path)
403403

404-
os2_typo_ascender = tt['OS/2'].__dict__['sTypoAscender']
405-
os2_typo_descender = tt['OS/2'].__dict__['sTypoDescender']
406-
os2_win_ascent = tt['OS/2'].__dict__['usWinAscent']
407-
os2_win_descent = tt['OS/2'].__dict__['usWinDescent']
408-
os2_typo_linegap = tt['OS/2'].__dict__['sTypoLineGap']
409-
hhea_ascent = tt['hhea'].__dict__['ascent']
410-
hhea_descent = tt['hhea'].__dict__['descent']
411-
hhea_linegap = tt['hhea'].__dict__['lineGap']
412-
units_per_em = tt['head'].__dict__['unitsPerEm']
404+
os2_typo_ascender = tt['OS/2'].sTypoAscender
405+
os2_typo_descender = tt['OS/2'].sTypoDescender
406+
os2_win_ascent = tt['OS/2'].usWinAscent
407+
os2_win_descent = tt['OS/2'].usWinDescent
408+
os2_typo_linegap = tt['OS/2'].sTypoLineGap
409+
hhea_ascent = tt['hhea'].ascent
410+
hhea_descent = tt['hhea'].descent
411+
hhea_linegap = tt['hhea'].lineGap
412+
units_per_em = tt['head'].unitsPerEm
413413

414414
assert os2_typo_ascender == 750
415415
assert os2_typo_descender == -250

0 commit comments

Comments
 (0)