Skip to content

Commit 8118ec3

Browse files
committed
Move some things out of contexts to reduce indent.
1 parent 771d604 commit 8118ec3

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

lib/matplotlib/backends/backend_ps.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -229,22 +229,21 @@ def _font_to_ps_type42(font_path, chars, fh):
229229
fh : file-like
230230
Where to write the font.
231231
"""
232+
subset_str = ''.join(chr(c) for c in chars)
233+
_log.debug("SUBSET %s characters: %s", font_path, subset_str)
232234
try:
233-
subset_str = ''.join(chr(c) for c in chars)
234-
_log.debug("SUBSET %s characters: %s", font_path, subset_str)
235235
fontdata = _backend_pdf_ps.get_glyphs_subset(font_path, subset_str)
236236
_log.debug("SUBSET %s %d -> %d", font_path, os.stat(font_path).st_size,
237237
fontdata.getbuffer().nbytes)
238238

239239
# Give ttconv a subsetted font along with updated glyph_ids.
240+
font = FT2Font(fontdata)
241+
glyph_ids = [font.get_char_index(c) for c in chars]
240242
with TemporaryDirectory() as tmpdir:
241243
tmpfile = os.path.join(tmpdir, "tmp.ttf")
242-
font = FT2Font(fontdata)
243-
glyph_ids = [font.get_char_index(c) for c in chars]
244244

245245
with open(tmpfile, 'wb') as tmp:
246246
tmp.write(fontdata.getvalue())
247-
tmp.flush()
248247

249248
# TODO: allow convert_ttf_to_ps to input file objects (BytesIO)
250249
convert_ttf_to_ps(os.fsencode(tmpfile), fh, 42, glyph_ids)

0 commit comments

Comments
 (0)