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

Skip to content

Move slow FontManager warning to FontManager constructor. #17277

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 30, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 18 additions & 17 deletions lib/matplotlib/font_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,11 +256,6 @@ def win32InstalledFonts(directory=None, fontext='ttf'):
@lru_cache()
def _call_fc_list():
"""Cache and list the font filenames known to `fc-list`."""
# Delay the warning by 5s.
timer = Timer(5, lambda: _log.warning(
'Matplotlib is building the font cache using fc-list. '
'This may take a moment.'))
timer.start()
try:
if b'--format' not in subprocess.check_output(['fc-list', '--help']):
_log.warning( # fontconfig 2.7 implemented --format.
Expand All @@ -269,8 +264,6 @@ def _call_fc_list():
out = subprocess.check_output(['fc-list', '--format=%{file}\\n'])
except (OSError, subprocess.CalledProcessError):
return []
finally:
timer.cancel()
return [os.fsdecode(fname) for fname in out.split(b'\n')]


Expand Down Expand Up @@ -983,16 +976,24 @@ def __init__(self, size=None, weight='normal'):

self.afmlist = []
self.ttflist = []
for fontext in ["afm", "ttf"]:
for path in [*findSystemFonts(paths, fontext=fontext),
*findSystemFonts(fontext=fontext)]:
try:
self.addfont(path)
except OSError as exc:
_log.info("Failed to open font file %s: %s", path, exc)
except Exception as exc:
_log.info("Failed to extract font properties from %s: %s",
path, exc)

# Delay the warning by 5s.
timer = Timer(5, lambda: _log.warning(
'Matplotlib is building the font cache; this may take a moment.'))
timer.start()
try:
for fontext in ["afm", "ttf"]:
for path in [*findSystemFonts(paths, fontext=fontext),
*findSystemFonts(fontext=fontext)]:
try:
self.addfont(path)
except OSError as exc:
_log.info("Failed to open font file %s: %s", path, exc)
except Exception as exc:
_log.info("Failed to extract font properties from %s: "
"%s", path, exc)
finally:
timer.cancel()

def addfont(self, path):
"""
Expand Down