@@ -268,24 +268,22 @@ def get_fontconfig_fonts(fontext='ttf'):
268
268
269
269
fontfiles = {}
270
270
try :
271
- pipe = subprocess .Popen (['fc-list' , '' , ' file' ], stdout = subprocess .PIPE )
271
+ pipe = subprocess .Popen (['fc-list' , '--format=%{ file} \\ n ' ], stdout = subprocess .PIPE )
272
272
output = pipe .communicate ()[0 ]
273
273
except (OSError , IOError ):
274
274
# Calling fc-list did not work, so we'll just return nothing
275
275
return fontfiles
276
276
277
277
if pipe .returncode == 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 ]
278
+ # The line breaks between results are in ascii, but each entry
279
+ # is in in sys.filesystemencoding().
280
+ for fname in output .split (b'\n ' ):
281
+ try :
282
+ fname = six .text_type (fname , sys .getfilesystemencoding ())
283
+ except UnicodeDecodeError :
284
+ continue
283
285
if (os .path .splitext (fname )[1 ][1 :] in fontext and
284
286
os .path .exists (fname )):
285
- try :
286
- fname = six .text_type (fname , sys .getfilesystemencoding ())
287
- except UnicodeDecodeError :
288
- continue
289
287
fontfiles [fname ] = 1
290
288
291
289
return fontfiles
@@ -1297,7 +1295,9 @@ def fc_match(pattern, fontext):
1297
1295
fontexts = get_fontext_synonyms (fontext )
1298
1296
ext = "." + fontext
1299
1297
try :
1300
- pipe = subprocess .Popen (['fc-match' , '-sv' , pattern ], stdout = subprocess .PIPE )
1298
+ pipe = subprocess .Popen (
1299
+ ['fc-match' , '-s' , '--format=%{file}\\ n' , pattern ],
1300
+ stdout = subprocess .PIPE )
1301
1301
output = pipe .communicate ()[0 ]
1302
1302
except (OSError , IOError ):
1303
1303
return None
@@ -1306,17 +1306,15 @@ def fc_match(pattern, fontext):
1306
1306
# result in bytes and parse it as bytes, until we extract the
1307
1307
# filename, which is in sys.filesystemencoding().
1308
1308
if pipe .returncode == 0 :
1309
- for match in _fc_match_regex .finditer (output ):
1310
- file = match .group (1 )
1309
+ for fname in output .split (b'\n ' ):
1311
1310
try :
1312
- file = six .text_type (file , sys .getfilesystemencoding ())
1311
+ fname = six .text_type (fname , sys .getfilesystemencoding ())
1313
1312
except UnicodeDecodeError :
1314
1313
continue
1315
- if os .path .splitext (file )[1 ][1 :] in fontexts :
1316
- return file
1314
+ if os .path .splitext (fname )[1 ][1 :] in fontexts :
1315
+ return fname
1317
1316
return None
1318
1317
1319
- _fc_match_regex = re .compile (br'\sfile:\s+"(.*?)"' )
1320
1318
_fc_match_cache = {}
1321
1319
1322
1320
def findfont (prop , fontext = 'ttf' ):
0 commit comments