Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 95a49d3

Browse filesBrowse files
NelleVdmcdougall
authored andcommitted
PEP8 fixes on type1font.py
1 parent 0891026 commit 95a49d3
Copy full SHA for 95a49d3

File tree

Expand file treeCollapse file tree

1 file changed

+44
-33
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+44
-33
lines changed

‎lib/matplotlib/type1font.py

Copy file name to clipboardExpand all lines: lib/matplotlib/type1font.py
+44-33Lines changed: 44 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
def ord(x):
3636
return x
3737

38+
3839
class Type1Font(object):
3940
"""
4041
A class representing a Type-1 font, for use by backends.
@@ -75,13 +76,13 @@ def _read(self, file):
7576
data = b''
7677
while len(rawdata) > 0:
7778
if not rawdata.startswith(b'\x80'):
78-
raise RuntimeError('Broken pfb file (expected byte 128, got %d)' % \
79-
ord(rawdata[0]))
79+
raise RuntimeError('Broken pfb file (expected byte 128, '
80+
'got %d)' % ord(rawdata[0]))
8081
type = ord(rawdata[1])
81-
if type in (1,2):
82+
if type in (1, 2):
8283
length, = struct.unpack('<i', rawdata[2:6])
83-
segment = rawdata[6:6+length]
84-
rawdata = rawdata[6+length:]
84+
segment = rawdata[6:6 + length]
85+
rawdata = rawdata[6 + length:]
8586

8687
if type == 1: # ASCII text: include verbatim
8788
data += segment
@@ -91,7 +92,8 @@ def _read(self, file):
9192
elif type == 3: # end of file
9293
break
9394
else:
94-
raise RuntimeError('Unknown segment type %d in pfb file' % type)
95+
raise RuntimeError('Unknown segment type %d in pfb file' %
96+
type)
9597

9698
return data
9799

@@ -129,7 +131,7 @@ def _split(self, data):
129131
# but if we read a pfa file, this part is already in hex, and
130132
# I am not quite sure if even the pfb format guarantees that
131133
# it will be in binary).
132-
binary = b''.join([unichr(int(data[i:i+2], 16)).encode('latin-1')
134+
binary = b''.join([unichr(int(data[i:i + 2], 16)).encode('latin-1')
133135
for i in range(len1, idx, 2)])
134136

135137
return data[:len1], binary, data[idx:]
@@ -138,6 +140,7 @@ def _split(self, data):
138140
_token = re.compile(br'/{0,2}[^]\0\t\r\v\n ()<>{}/%[]+')
139141
_comment = re.compile(br'%[^\r\n\v]*')
140142
_instring = re.compile(br'[()\\]')
143+
141144
@classmethod
142145
def _tokens(cls, text):
143146
"""
@@ -146,7 +149,8 @@ def _tokens(cls, text):
146149
"""
147150
pos = 0
148151
while pos < len(text):
149-
match = cls._comment.match(text[pos:]) or cls._whitespace.match(text[pos:])
152+
match = cls._comment.match(text[pos:]) or \
153+
cls._whitespace.match(text[pos:])
150154
if match:
151155
yield ('whitespace', match.group())
152156
pos += match.end()
@@ -156,17 +160,18 @@ def _tokens(cls, text):
156160
depth = 1
157161
while depth:
158162
match = cls._instring.search(text[pos:])
159-
if match is None: return
163+
if match is None:
164+
return
160165
pos += match.end()
161166
if match.group() == '(':
162167
depth += 1
163168
elif match.group() == ')':
164169
depth -= 1
165-
else: # a backslash - skip the next character
170+
else: # a backslash - skip the next character
166171
pos += 1
167172
yield ('string', text[start:pos])
168-
elif text[pos:pos+2] in ('<<', '>>'):
169-
yield ('delimiter', text[pos:pos+2])
173+
elif text[pos:pos + 2] in ('<<', '>>'):
174+
yield ('delimiter', text[pos:pos + 2])
170175
pos += 2
171176
elif text[pos] == '<':
172177
start = pos
@@ -192,8 +197,8 @@ def _parse(self):
192197
Compatibility" of the Type-1 spec.
193198
"""
194199
# Start with reasonable defaults
195-
prop = { 'weight': 'Regular', 'ItalicAngle': 0.0, 'isFixedPitch': False,
196-
'UnderlinePosition': -100, 'UnderlineThickness': 50 }
200+
prop = {'weight': 'Regular', 'ItalicAngle': 0.0, 'isFixedPitch': False,
201+
'UnderlinePosition': -100, 'UnderlineThickness': 50}
197202
tokenizer = self._tokens(self.parts[0])
198203
filtered = itertools.ifilter(lambda x: x[0] != 'whitespace', tokenizer)
199204
for token, value in filtered:
@@ -208,16 +213,20 @@ def _parse(self):
208213
elif token == b'string':
209214
value = value.lstrip(b'(').rstrip(b')')
210215
elif token == b'number':
211-
if b'.' in value: value = float(value)
212-
else: value = int(value)
213-
else: # more complicated value such as an array
216+
if b'.' in value:
217+
value = float(value)
218+
else:
219+
value = int(value)
220+
else: # more complicated value such as an array
214221
value = None
215222
if key != b'FontInfo' and value is not None:
216223
prop[key] = value
217224

218225
# Fill in the various *Name properties
219226
if 'FontName' not in prop:
220-
prop['FontName'] = prop.get('FullName') or prop.get('FamilyName') or 'Unknown'
227+
prop['FontName'] = (prop.get('FullName') or
228+
prop.get('FamilyName') or
229+
'Unknown')
221230
if 'FullName' not in prop:
222231
prop['FullName'] = prop['FontName']
223232
if 'FamilyName' not in prop:
@@ -230,25 +239,27 @@ def _parse(self):
230239
def _transformer(cls, tokens, slant, extend):
231240
def fontname(name):
232241
result = name
233-
if slant: result += '_Slant_' + str(int(1000*slant))
234-
if extend != 1.0: result += '_Extend_' + str(int(1000*extend))
242+
if slant:
243+
result += '_Slant_' + str(int(1000 * slant))
244+
if extend != 1.0:
245+
result += '_Extend_' + str(int(1000 * extend))
235246
return result
236247

237248
def italicangle(angle):
238-
return str(float(angle) - np.arctan(slant)/np.pi*180)
249+
return str(float(angle) - np.arctan(slant) / np.pi * 180)
239250

240251
def fontmatrix(array):
241252
array = array.lstrip('[').rstrip(']').strip().split()
242-
array = [ float(x) for x in array ]
243-
oldmatrix = np.eye(3,3)
244-
oldmatrix[0:3,0] = array[::2]
245-
oldmatrix[0:3,1] = array[1::2]
253+
array = [float(x) for x in array]
254+
oldmatrix = np.eye(3, 3)
255+
oldmatrix[0:3, 0] = array[::2]
256+
oldmatrix[0:3, 1] = array[1::2]
246257
modifier = np.array([[extend, 0, 0],
247258
[slant, 1, 0],
248259
[0, 0, 1]])
249260
newmatrix = np.dot(modifier, oldmatrix)
250-
array[::2] = newmatrix[0:3,0]
251-
array[1::2] = newmatrix[0:3,1]
261+
array[::2] = newmatrix[0:3, 0]
262+
array[1::2] = newmatrix[0:3, 1]
252263
return '[' + ' '.join(str(x) for x in array) + ']'
253264

254265
def replace(fun):
@@ -275,15 +286,16 @@ def suppress(tokens):
275286
pass
276287
yield ''
277288

278-
table = { '/FontName': replace(fontname),
279-
'/ItalicAngle': replace(italicangle),
280-
'/FontMatrix': replace(fontmatrix),
281-
'/UniqueID': suppress }
289+
table = {'/FontName': replace(fontname),
290+
'/ItalicAngle': replace(italicangle),
291+
'/FontMatrix': replace(fontmatrix),
292+
'/UniqueID': suppress}
282293

283294
while True:
284295
token, value = next(tokens)
285296
if token == 'name' and value in table:
286-
for value in table[value](itertools.chain([(token, value)], tokens)):
297+
for value in table[value](itertools.chain([(token, value)],
298+
tokens)):
287299
yield value
288300
else:
289301
yield value
@@ -311,4 +323,3 @@ def transform(self, effects):
311323
buffer.close()
312324

313325
return Type1Font((result, self.parts[1], self.parts[2]))
314-

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.