@@ -14,25 +14,25 @@ def get_font_report(fontpath):
14
14
tt = ttLib .TTFont (fontpath )
15
15
16
16
# Vertical metrics values as integers
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
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
22
try :
23
- os2_x_height = tt [' OS/2' ].sxHeight
23
+ os2_x_height = tt [" OS/2" ].sxHeight
24
24
except AttributeError :
25
25
os2_x_height = "---- (OS/2 table does not contain sxHeight record)"
26
26
try :
27
- os2_cap_height = tt [' OS/2' ].sCapHeight
27
+ os2_cap_height = tt [" OS/2" ].sCapHeight
28
28
except AttributeError :
29
29
os2_cap_height = "---- (OS/2 table does not contain sCapHeight record)"
30
- hhea_ascent = tt [' hhea' ].ascent
31
- hhea_descent = tt [' hhea' ].descent
32
- hhea_linegap = tt [' hhea' ].lineGap
33
- ymax = tt [' head' ].yMax
34
- ymin = tt [' head' ].yMin
35
- units_per_em = tt [' head' ].unitsPerEm
30
+ hhea_ascent = tt [" hhea" ].ascent
31
+ hhea_descent = tt [" hhea" ].descent
32
+ hhea_linegap = tt [" hhea" ].lineGap
33
+ ymax = tt [" head" ].yMax
34
+ ymin = tt [" head" ].yMin
35
+ units_per_em = tt [" head" ].unitsPerEm
36
36
37
37
# Calculated values
38
38
os2_typo_total_height = os2_typo_ascender + - (os2_typo_descender )
@@ -45,7 +45,7 @@ def get_font_report(fontpath):
45
45
# The file path header
46
46
report = [" " ]
47
47
report .append ("=== " + fontpath + " ===" )
48
- namerecord_list = tt [' name' ].names
48
+ namerecord_list = tt [" name" ].names
49
49
# The version string
50
50
for needle in namerecord_list :
51
51
if needle .nameID == 5 :
@@ -72,15 +72,27 @@ def get_font_report(fontpath):
72
72
report .append ("[OS/2] TypoLineGap: \t {}" .format (os2_typo_linegap ))
73
73
report .append ("" )
74
74
report .append ("--- Height Calculations by Table Values ---" )
75
- report .append ("[OS/2] TypoAscender to TypoDescender: \t {}" .format (os2_typo_total_height ))
75
+ report .append (
76
+ "[OS/2] TypoAscender to TypoDescender: \t {}" .format (os2_typo_total_height )
77
+ )
76
78
report .append ("[OS/2] WinAscent to WinDescent: \t {}" .format (os2_win_total_height ))
77
79
report .append ("[hhea] Ascent to Descent: \t \t {}" .format (hhea_total_height ))
78
80
report .append ("" )
79
81
report .append ("--- Delta Values ---" )
80
- report .append ("WinAscent to TypoAscender: \t {}" .format (os2_win_ascent - os2_typo_ascender ))
81
- report .append ("Ascent to TypoAscender: \t {}" .format (hhea_ascent - os2_typo_ascender ))
82
- report .append ("WinDescent to TypoDescender: \t {}" .format (os2_win_descent - - (os2_typo_descender )))
83
- report .append ("Descent to TypoDescender: \t {}" .format (os2_typo_descender - hhea_descent ))
82
+ report .append (
83
+ "WinAscent to TypoAscender: \t {}" .format (os2_win_ascent - os2_typo_ascender )
84
+ )
85
+ report .append (
86
+ "Ascent to TypoAscender: \t {}" .format (hhea_ascent - os2_typo_ascender )
87
+ )
88
+ report .append (
89
+ "WinDescent to TypoDescender: \t {}" .format (
90
+ os2_win_descent - - (os2_typo_descender )
91
+ )
92
+ )
93
+ report .append (
94
+ "Descent to TypoDescender: \t {}" .format (os2_typo_descender - hhea_descent )
95
+ )
84
96
report .append ("" )
85
97
report .append ("--- Ratios ---" )
86
98
report .append ("(Typo Asc + Desc + Linegap) / UPM: \t {0:.3g}" .format (typo_to_upm ))
@@ -95,12 +107,12 @@ def modify_linegap_percent(fontpath, percent):
95
107
tt = ttLib .TTFont (fontpath )
96
108
97
109
# get observed start values from the font
98
- os2_typo_ascender = tt [' OS/2' ].sTypoAscender
99
- os2_typo_descender = tt [' OS/2' ].sTypoDescender
100
- os2_typo_linegap = tt [' OS/2' ].sTypoLineGap
101
- hhea_ascent = tt [' hhea' ].ascent
102
- hhea_descent = tt [' hhea' ].descent
103
- units_per_em = tt [' head' ].unitsPerEm
110
+ os2_typo_ascender = tt [" OS/2" ].sTypoAscender
111
+ os2_typo_descender = tt [" OS/2" ].sTypoDescender
112
+ os2_typo_linegap = tt [" OS/2" ].sTypoLineGap
113
+ hhea_ascent = tt [" hhea" ].ascent
114
+ hhea_descent = tt [" hhea" ].descent
115
+ units_per_em = tt [" head" ].unitsPerEm
104
116
105
117
# calculate necessary delta values
106
118
os2_typo_ascdesc_delta = os2_typo_ascender + - (os2_typo_descender )
@@ -146,19 +158,24 @@ def modify_linegap_percent(fontpath, percent):
146
158
os2_win_descent = - hhea_descent
147
159
148
160
# define updated values from above calculations
149
- tt [' hhea' ].lineGap = hhea_linegap
150
- tt [' OS/2' ].sTypoAscender = os2_typo_ascender
151
- tt [' OS/2' ].sTypoDescender = os2_typo_descender
152
- tt [' OS/2' ].sTypoLineGap = os2_typo_linegap
153
- tt [' OS/2' ].usWinAscent = os2_win_ascent
154
- tt [' OS/2' ].usWinDescent = os2_win_descent
155
- tt [' hhea' ].ascent = hhea_ascent
156
- tt [' hhea' ].descent = hhea_descent
161
+ tt [" hhea" ].lineGap = hhea_linegap
162
+ tt [" OS/2" ].sTypoAscender = os2_typo_ascender
163
+ tt [" OS/2" ].sTypoDescender = os2_typo_descender
164
+ tt [" OS/2" ].sTypoLineGap = os2_typo_linegap
165
+ tt [" OS/2" ].usWinAscent = os2_win_ascent
166
+ tt [" OS/2" ].usWinDescent = os2_win_descent
167
+ tt [" hhea" ].ascent = hhea_ascent
168
+ tt [" hhea" ].descent = hhea_descent
157
169
158
170
tt .save (get_linegap_percent_filepath (fontpath , percent ))
159
171
return True
160
172
except Exception as e : # pragma: no cover
161
- stderr ("[font-line] ERROR: Unable to modify the line spacing in the font file '" + fontpath + "'. " + str (e ))
173
+ stderr (
174
+ "[font-line] ERROR: Unable to modify the line spacing in the font file '"
175
+ + fontpath
176
+ + "'. "
177
+ + str (e )
178
+ )
162
179
sys .exit (1 )
163
180
164
181
0 commit comments