@@ -3061,24 +3061,50 @@ def register_fonts():
30613061 # https://www.cufonfonts.com
30623062 # WARNING: If you include a font file with an unrecognized style,
30633063 # matplotlib may use that font instead of the 'normal' one! Valid styles:
3064- # 'ultralight', 'light', 'normal', 'regular', 'book', 'medium', 'roman',
3065- # 'semibold', 'demibold', 'demi', 'bold', 'heavy', 'extra bold', 'black'
3066- # https://matplotlib.org/api/font_manager_api.html
3067- paths = ':' .join (_get_data_paths ('fonts' ))
3064+ # 'ultralight', 'light', 'normal', 'regular', 'book', 'medium', 'roman',
3065+ # 'semibold', 'demibold', 'demi', 'bold', 'heavy', 'extra bold', 'black'
3066+ # https://matplotlib.org/api/font_manager_api.html
3067+ # For macOS the only fonts with 'Thin' in one of the .ttf file names
3068+ # are Helvetica Neue and .SF NS Display Condensed. Never try to use these!
3069+ paths = ':' .join (_get_data_paths ('fonts' )[::- 1 ]) # user paths come first
30683070 if 'TTFPATH' not in os .environ :
30693071 os .environ ['TTFPATH' ] = paths
30703072 elif paths not in os .environ ['TTFPATH' ]:
30713073 os .environ ['TTFPATH' ] += (':' + paths )
30723074
3073- # Load font manager and rebuild only if necessary!
3074- # Font cache rebuild can be >50% of total import time, ~1s!!!
3075+ # Detect user-input .ttc fonts
30753076 import matplotlib .font_manager as mfonts
3076- files_loaded = {font .fname for font in mfonts .fontManager .ttflist }
3077- files_ttfpath = {* mfonts .findSystemFonts (paths .split (':' ))}
3078- if not (files_ttfpath <= files_loaded ):
3079- mfonts ._rebuild ()
3077+ fnames_proplot = {* mfonts .findSystemFonts (paths .split (':' ))}
3078+ fnames_proplot_ttc = {
3079+ file for file in fnames_proplot if os .path .splitext (file )[1 ] == '.ttc'
3080+ }
3081+ if fnames_proplot_ttc :
3082+ _warn_proplot (
3083+ 'Ignoring the following .ttc fonts because they cannot be '
3084+ 'saved into PDF or EPS files (see matplotlib issue #3135): '
3085+ + ', ' .join (map (repr , sorted (fnames_proplot_ttc )))
3086+ + '. Please consider expanding them into separate .ttf files.'
3087+ )
3088+
3089+ # Rebuild font cache only if necessary! Can be >50% of total import time!
3090+ fnames_all = {font .fname for font in mfonts .fontManager .ttflist }
3091+ fnames_proplot -= fnames_proplot_ttc
3092+ if not fnames_all >= fnames_proplot :
3093+ if hasattr (mfonts .fontManager , 'addfont' ):
3094+ for fname in fnames_proplot :
3095+ mfonts .fontManager .addfont (fname )
3096+ mfonts .json_dump (mfonts .fontManager , mfonts ._fmcache )
3097+ else :
3098+ _warn_proplot ('Rebuilding font manager.' )
3099+ mfonts ._rebuild ()
3100+
3101+ # Remove ttc files *after* rebuild
3102+ mfonts .fontManager .ttflist = [
3103+ font for font in mfonts .fontManager .ttflist
3104+ if os .path .splitext (font .fname )[1 ] != '.ttc'
3105+ ]
30803106
3081- # Populate font lists
3107+ # Populate font name lists, with proplot fonts *first*
30823108 fonts_proplot = sorted ({
30833109 font .name for font in mfonts .fontManager .ttflist
30843110 if any (path in font .fname for path in paths .split (':' ))
0 commit comments