Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1393702

Browse files
committed
Clean up some ttconv replacements
De-wrap a few lines now that we allow longer lines.
1 parent 5bc3812 commit 1393702

File tree

2 files changed

+34
-35
lines changed

2 files changed

+34
-35
lines changed

lib/matplotlib/backends/backend_pdf.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1270,9 +1270,7 @@ def embedTTFType42(font, characters, descriptor):
12701270

12711271
subset_str = "".join(chr(c) for c in characters)
12721272
_log.debug("SUBSET %s characters: %s", filename, subset_str)
1273-
with _backend_pdf_ps.get_glyphs_subset(
1274-
filename, subset_str
1275-
) as subset:
1273+
with _backend_pdf_ps.get_glyphs_subset(filename, subset_str) as subset:
12761274
fontdata = _backend_pdf_ps.font_as_file(subset)
12771275
_log.debug(
12781276
"SUBSET %s %d -> %d", filename,

lib/matplotlib/backends/backend_ps.py

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,8 @@ def _font_to_ps_type42(font_path, chars, fh):
206206
# https://github.com/matplotlib/matplotlib/issues/3135#issuecomment-571085541
207207
if font_path.endswith('.ttc'):
208208
kw['fontNumber'] = 0
209-
with fontTools.ttLib.TTFont(font_path, **kw) as font, \
210-
_backend_pdf_ps.get_glyphs_subset(font_path, subset_str) as subset:
209+
with (fontTools.ttLib.TTFont(font_path, **kw) as font,
210+
_backend_pdf_ps.get_glyphs_subset(font_path, subset_str) as subset):
211211
fontdata = _backend_pdf_ps.font_as_file(subset).getvalue()
212212
_log.debug(
213213
"SUBSET %s %d -> %d", font_path, os.stat(font_path).st_size,
@@ -216,8 +216,8 @@ def _font_to_ps_type42(font_path, chars, fh):
216216
fh.write(_serialize_type42(font, subset, fontdata))
217217
except RuntimeError:
218218
_log.warning(
219-
"The PostScript backend does not currently "
220-
"support the selected font (%s).", font_path)
219+
"The PostScript backend does not currently support the selected font (%s).",
220+
font_path)
221221
raise
222222

223223

@@ -240,32 +240,33 @@ def _serialize_type42(font, subset, fontdata):
240240
The Type-42 formatted font
241241
"""
242242
version, breakpoints = _version_and_breakpoints(font.get('loca'), fontdata)
243-
post, name = font['post'], font['name']
244-
fmt = textwrap.dedent(f"""
245-
%%!PS-TrueTypeFont-{version[0]}.{version[1]}-{font['head'].fontRevision:.7f}
246-
10 dict begin
247-
/FontType 42 def
248-
/FontMatrix [1 0 0 1 0 0] def
249-
/FontName /{name.getDebugName(6)} def
250-
/FontInfo 7 dict dup begin
251-
/FullName ({name.getDebugName(4)}) def
252-
/FamilyName ({name.getDebugName(1)}) def
253-
/Version ({name.getDebugName(5)}) def
254-
/ItalicAngle {post.italicAngle} def
255-
/isFixedPitch {'true' if post.isFixedPitch else 'false'} def
256-
/UnderlinePosition {post.underlinePosition} def
257-
/UnderlineThickness {post.underlineThickness} def
258-
end readonly def
259-
/Encoding StandardEncoding def
260-
/FontBBox [{' '.join(str(x) for x in _bounds(font))}] def
261-
/PaintType 0 def
262-
/CIDMap 0 def
263-
%s
264-
%s
265-
FontName currentdict end definefont pop
266-
""")
267-
268-
return fmt % (_charstrings(subset), _sfnts(fontdata, subset, breakpoints))
243+
post = font['post']
244+
name = font['name']
245+
chars = _generate_charstrings(subset)
246+
sfnts = _generate_sfnts(fontdata, subset, breakpoints)
247+
return textwrap.dedent(f"""
248+
%%!PS-TrueTypeFont-{version[0]}.{version[1]}-{font['head'].fontRevision:.7f}
249+
10 dict begin
250+
/FontType 42 def
251+
/FontMatrix [1 0 0 1 0 0] def
252+
/FontName /{name.getDebugName(6)} def
253+
/FontInfo 7 dict dup begin
254+
/FullName ({name.getDebugName(4)}) def
255+
/FamilyName ({name.getDebugName(1)}) def
256+
/Version ({name.getDebugName(5)}) def
257+
/ItalicAngle {post.italicAngle} def
258+
/isFixedPitch {'true' if post.isFixedPitch else 'false'} def
259+
/UnderlinePosition {post.underlinePosition} def
260+
/UnderlineThickness {post.underlineThickness} def
261+
end readonly def
262+
/Encoding StandardEncoding def
263+
/FontBBox [{_nums_to_str(*_bounds(font))}] def
264+
/PaintType 0 def
265+
/CIDMap 0 def
266+
{chars}
267+
{sfnts}
268+
FontName currentdict end definefont pop
269+
""")
269270

270271

271272
def _version_and_breakpoints(loca, fontdata):
@@ -336,7 +337,7 @@ def _bounds(font):
336337
return pen.bounds or (0, 0, 0, 0)
337338

338339

339-
def _charstrings(font):
340+
def _generate_charstrings(font):
340341
"""
341342
Transform font glyphs into CharStrings
342343
@@ -360,7 +361,7 @@ def _charstrings(font):
360361
return s
361362

362363

363-
def _sfnts(fontdata, font, breakpoints):
364+
def _generate_sfnts(fontdata, font, breakpoints):
364365
"""
365366
Transform font data into PostScript sfnts format.
366367

0 commit comments

Comments
 (0)