Skip to content

Commit a0a8d1a

Browse files
committed
blacken source files
1 parent 89c9c89 commit a0a8d1a

File tree

4 files changed

+118
-55
lines changed

4 files changed

+118
-55
lines changed

lib/fontline/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
11
#!/usr/bin/env python
22
# -*- coding: utf-8 -*-
3-
4-

lib/fontline/app.py

Lines changed: 62 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@
1414
from standardstreams import stdout, stderr
1515

1616
from fontline import settings
17-
from fontline.commands import get_font_report, modify_linegap_percent, get_linegap_percent_filepath
17+
from fontline.commands import (
18+
get_font_report,
19+
modify_linegap_percent,
20+
get_linegap_percent_filepath,
21+
)
1822
from fontline.utilities import file_exists, is_supported_filetype
1923

2024
# TODO: support integer addition and subtraction to the metrics values through new sub-commands
@@ -27,7 +31,9 @@ def main():
2731
c = Command()
2832

2933
if c.does_not_validate_missing_args():
30-
stderr("[font-line] ERROR: Please include one or more arguments with your command.")
34+
stderr(
35+
"[font-line] ERROR: Please include one or more arguments with your command."
36+
)
3137
sys.exit(1)
3238

3339
if c.is_help_request():
@@ -43,7 +49,9 @@ def main():
4349
# REPORT sub-command
4450
if c.subcmd == "report":
4551
if c.argc < 2:
46-
stderr("[font-line] ERROR: Missing file path argument(s) after the report subcommand.")
52+
stderr(
53+
"[font-line] ERROR: Missing file path argument(s) after the report subcommand."
54+
)
4755
sys.exit(1)
4856
else:
4957
for fontpath in c.argv[1:]:
@@ -53,9 +61,17 @@ def main():
5361
if is_supported_filetype(fontpath):
5462
stdout(get_font_report(fontpath))
5563
else:
56-
stderr("[font-line] ERROR: '" + fontpath + "' does not appear to be a supported font file type.")
64+
stderr(
65+
"[font-line] ERROR: '"
66+
+ fontpath
67+
+ "' does not appear to be a supported font file type."
68+
)
5769
else:
58-
stderr("[font-line] ERROR: '" + fontpath + "' does not appear to be a valid filepath.")
70+
stderr(
71+
"[font-line] ERROR: '"
72+
+ fontpath
73+
+ "' does not appear to be a valid filepath."
74+
)
5975
# PERCENT sub-command
6076
elif c.subcmd == "percent":
6177
if c.argc < 3:
@@ -65,29 +81,59 @@ def main():
6581
percent = c.argv[1]
6682
# test the percent integer argument
6783
try:
68-
percent_int = int(percent) # test that the argument can be cast to an integer value
84+
percent_int = int(
85+
percent
86+
) # test that the argument can be cast to an integer value
6987
if percent_int <= 0:
70-
stderr("[font-line] ERROR: Please enter a percent value that is greater than zero.")
88+
stderr(
89+
"[font-line] ERROR: Please enter a percent value that is greater than zero."
90+
)
7191
sys.exit(1)
7292
if percent_int > 100:
73-
stdout("[font-line] Warning: You entered a percent value over 100%. Please confirm that this is "
74-
"your intended metrics modification.")
93+
stdout(
94+
"[font-line] Warning: You entered a percent value over 100%. Please confirm that this is "
95+
"your intended metrics modification."
96+
)
7597
except ValueError:
76-
stderr("[font-line] ERROR: You entered '" + percent + "'. This argument needs to be an integer value.")
98+
stderr(
99+
"[font-line] ERROR: You entered '"
100+
+ percent
101+
+ "'. This argument needs to be an integer value."
102+
)
77103
sys.exit(1)
78104
for fontpath in c.argv[2:]:
79105
if file_exists(fontpath):
80106
if is_supported_filetype(fontpath):
81107
if modify_linegap_percent(fontpath, percent) is True:
82108
outpath = get_linegap_percent_filepath(fontpath, percent)
83-
stdout("[font-line] '" + fontpath + "' successfully modified to '" + outpath + "'.")
109+
stdout(
110+
"[font-line] '"
111+
+ fontpath
112+
+ "' successfully modified to '"
113+
+ outpath
114+
+ "'."
115+
)
84116
else: # pragma: no cover
85-
stderr("[font-line] ERROR: Unsuccessful modification of '" + fontpath + "'.")
117+
stderr(
118+
"[font-line] ERROR: Unsuccessful modification of '"
119+
+ fontpath
120+
+ "'."
121+
)
86122
else:
87-
stderr("[font-line] ERROR: '" + fontpath + "' does not appear to be a supported font file type.")
123+
stderr(
124+
"[font-line] ERROR: '"
125+
+ fontpath
126+
+ "' does not appear to be a supported font file type."
127+
)
88128
else:
89-
stderr("[font-line] ERROR: '" + fontpath + "' does not appear to be a valid filepath.")
129+
stderr(
130+
"[font-line] ERROR: '"
131+
+ fontpath
132+
+ "' does not appear to be a valid filepath."
133+
)
90134
else:
91-
stderr("[font-lines] ERROR: You used an unsupported argument to the executable. Please review the"
92-
" `font-line --help` documentation and try again.")
135+
stderr(
136+
"[font-lines] ERROR: You used an unsupported argument to the executable. Please review the"
137+
" `font-line --help` documentation and try again."
138+
)
93139
sys.exit(1)

lib/fontline/commands.py

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

1616
# 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
2222
try:
23-
os2_x_height = tt['OS/2'].sxHeight
23+
os2_x_height = tt["OS/2"].sxHeight
2424
except AttributeError:
2525
os2_x_height = "---- (OS/2 table does not contain sxHeight record)"
2626
try:
27-
os2_cap_height = tt['OS/2'].sCapHeight
27+
os2_cap_height = tt["OS/2"].sCapHeight
2828
except AttributeError:
2929
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
3636

3737
# Calculated values
3838
os2_typo_total_height = os2_typo_ascender + -(os2_typo_descender)
@@ -45,7 +45,7 @@ def get_font_report(fontpath):
4545
# The file path header
4646
report = [" "]
4747
report.append("=== " + fontpath + " ===")
48-
namerecord_list = tt['name'].names
48+
namerecord_list = tt["name"].names
4949
# The version string
5050
for needle in namerecord_list:
5151
if needle.nameID == 5:
@@ -72,15 +72,27 @@ def get_font_report(fontpath):
7272
report.append("[OS/2] TypoLineGap: \t{}".format(os2_typo_linegap))
7373
report.append("")
7474
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+
)
7678
report.append("[OS/2] WinAscent to WinDescent: \t{}".format(os2_win_total_height))
7779
report.append("[hhea] Ascent to Descent: \t\t{}".format(hhea_total_height))
7880
report.append("")
7981
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+
)
8496
report.append("")
8597
report.append("--- Ratios ---")
8698
report.append("(Typo Asc + Desc + Linegap) / UPM: \t{0:.3g}".format(typo_to_upm))
@@ -95,12 +107,12 @@ def modify_linegap_percent(fontpath, percent):
95107
tt = ttLib.TTFont(fontpath)
96108

97109
# 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
104116

105117
# calculate necessary delta values
106118
os2_typo_ascdesc_delta = os2_typo_ascender + -(os2_typo_descender)
@@ -146,19 +158,24 @@ def modify_linegap_percent(fontpath, percent):
146158
os2_win_descent = -hhea_descent
147159

148160
# 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
157169

158170
tt.save(get_linegap_percent_filepath(fontpath, percent))
159171
return True
160172
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+
)
162179
sys.exit(1)
163180

164181

lib/fontline/utilities.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77

88
def file_exists(filepath):
99
"""Tests for existence of a file on the string filepath"""
10-
if os.path.exists(filepath) and os.path.isfile(filepath): # test that exists and is a file
10+
if os.path.exists(filepath) and os.path.isfile(
11+
filepath
12+
): # test that exists and is a file
1113
return True
1214
else:
1315
return False
@@ -16,13 +18,13 @@ def file_exists(filepath):
1618
def is_supported_filetype(filepath):
1719
"""Tests file extension to determine appropriate file type for the application"""
1820
testpath = filepath.lower()
19-
if testpath.endswith('.ttf') or testpath.endswith('.otf'):
21+
if testpath.endswith(".ttf") or testpath.endswith(".otf"):
2022
return True
2123
else:
2224
return False
2325

2426

2527
def get_sha1(filepath):
26-
with open(filepath, 'rb') as bin_reader:
28+
with open(filepath, "rb") as bin_reader:
2729
data = bin_reader.read()
2830
return hashlib.sha1(data).hexdigest()

0 commit comments

Comments
 (0)