|
62 | 62 | parse_fontconfig_pattern, generate_fontconfig_pattern |
63 | 63 |
|
64 | 64 | USE_FONTCONFIG = False |
65 | | - |
66 | 65 | verbose = matplotlib.verbose |
67 | 66 |
|
68 | 67 | font_scalings = { |
@@ -276,11 +275,14 @@ def get_fontconfig_fonts(fontext='ttf'): |
276 | 275 | return fontfiles |
277 | 276 |
|
278 | 277 | if pipe.returncode == 0: |
279 | | - output = str(output) |
280 | | - for line in output.split('\n'): |
281 | | - fname = line.split(':')[0] |
| 278 | + # The bulk of the output from fc-list is ascii, so we keep the |
| 279 | + # result in bytes and parse it as bytes, until we extract the |
| 280 | + # filename, which is in sys.filesystemencoding(). |
| 281 | + for line in output.split(b'\n'): |
| 282 | + fname = line.split(b':')[0] |
282 | 283 | if (os.path.splitext(fname)[1][1:] in fontext and |
283 | 284 | os.path.exists(fname)): |
| 285 | + fname = six.text_type(fname, sys.getfilesystemencoding()) |
284 | 286 | fontfiles[fname] = 1 |
285 | 287 |
|
286 | 288 | return fontfiles |
@@ -570,7 +572,7 @@ def createFontList(fontfiles, fontext='ttf'): |
570 | 572 | continue |
571 | 573 | else: |
572 | 574 | try: |
573 | | - font = ft2font.FT2Font(str(fpath)) |
| 575 | + font = ft2font.FT2Font(fpath) |
574 | 576 | except RuntimeError: |
575 | 577 | verbose.report("Could not open font file %s"%fpath) |
576 | 578 | continue |
@@ -720,7 +722,7 @@ def get_name(self): |
720 | 722 | Return the name of the font that best matches the font |
721 | 723 | properties. |
722 | 724 | """ |
723 | | - return ft2font.FT2Font(str(findfont(self))).family_name |
| 725 | + return ft2font.FT2Font(findfont(self)).family_name |
724 | 726 |
|
725 | 727 | def get_style(self): |
726 | 728 | """ |
@@ -1246,7 +1248,7 @@ def findfont(self, prop, fontext='ttf', directory=None, |
1246 | 1248 | else: |
1247 | 1249 | verbose.report( |
1248 | 1250 | 'findfont: Matching %s to %s (%s) with score of %f' % |
1249 | | - (prop, best_font.name, best_font.fname, best_score)) |
| 1251 | + (prop, best_font.name, repr(best_font.fname), best_score)) |
1250 | 1252 | result = best_font.fname |
1251 | 1253 |
|
1252 | 1254 | if not os.path.isfile(result): |
@@ -1296,15 +1298,19 @@ def fc_match(pattern, fontext): |
1296 | 1298 | output = pipe.communicate()[0] |
1297 | 1299 | except (OSError, IOError): |
1298 | 1300 | return None |
| 1301 | + |
| 1302 | + # The bulk of the output from fc-list is ascii, so we keep the |
| 1303 | + # result in bytes and parse it as bytes, until we extract the |
| 1304 | + # filename, which is in sys.filesystemencoding(). |
1299 | 1305 | if pipe.returncode == 0: |
1300 | 1306 | for match in _fc_match_regex.finditer(output): |
1301 | 1307 | file = match.group(1) |
1302 | | - file = file.decode(sys.getfilesystemencoding()) |
| 1308 | + file = six.text_type(file, sys.getfilesystemencoding()) |
1303 | 1309 | if os.path.splitext(file)[1][1:] in fontexts: |
1304 | 1310 | return file |
1305 | 1311 | return None |
1306 | 1312 |
|
1307 | | - _fc_match_regex = re.compile(br'\sfile:\s+"([^"]*)"') |
| 1313 | + _fc_match_regex = re.compile(br'\sfile:\s+"(.*?)"') |
1308 | 1314 | _fc_match_cache = {} |
1309 | 1315 |
|
1310 | 1316 | def findfont(prop, fontext='ttf'): |
|
0 commit comments