|
22 | 22 | from matplotlib.text import Text |
23 | 23 | from matplotlib.path import Path |
24 | 24 | from matplotlib import _png, rcParams |
25 | | -from matplotlib import font_manager |
26 | | -from matplotlib.ft2font import FT2Font |
27 | 25 | from matplotlib.cbook import is_string_like, is_writable_file_like |
28 | 26 | from matplotlib.compat import subprocess |
29 | 27 | from matplotlib.compat.subprocess import check_output |
|
33 | 31 |
|
34 | 32 | # create a list of system fonts, all of these should work with xe/lua-latex |
35 | 33 | system_fonts = [] |
36 | | -for f in font_manager.findSystemFonts(): |
| 34 | +if sys.platform.startswith('win'): |
| 35 | + from matplotlib import font_manager |
| 36 | + from matplotlib.ft2font import FT2Font |
| 37 | + for f in font_manager.win32InstalledFonts(): |
| 38 | + try: |
| 39 | + system_fonts.append(FT2Font(str(f)).family_name) |
| 40 | + except: |
| 41 | + pass # unknown error, skip this font |
| 42 | +else: |
| 43 | + # assuming fontconfig is installed and the command 'fc-list' exists |
37 | 44 | try: |
38 | | - system_fonts.append(FT2Font(f).family_name) |
39 | | - except RuntimeError: |
40 | | - pass # some fonts on osx are known to fail, print? |
| 45 | + # list scalable (non-bitmap) fonts |
| 46 | + fc_list = check_output(['fc-list', ':outline,scalable', 'family']) |
| 47 | + fc_list = fc_list.decode('utf8') |
| 48 | + system_fonts = [f.split(',')[0] for f in fc_list.splitlines()] |
| 49 | + system_fonts = list(set(system_fonts)) |
41 | 50 | except: |
42 | | - pass # unknown error, skip this font |
43 | | - |
| 51 | + warnings.warn('error getting fonts from fc-list', UserWarning) |
44 | 52 |
|
45 | 53 | def get_texcommand(): |
46 | 54 | """Get chosen TeX system from rc.""" |
|
0 commit comments