| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| `afm.get_fontconfig_fonts` returns a list of paths and does not check for existence | ||
| ``````````````````````````````````````````````````````````````````````````````````` | ||
|
|
||
| `afm.get_fontconfig_fonts` used to return a set of paths encoded as a | ||
| ``{key: 1, ...}`` dict, and checked for the existence of the paths. It now | ||
| returns a list and dropped the existence check, as the same check is performed | ||
| by the caller (`afm.findSystemFonts`) as well. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| Expand Up | @@ -47,18 +47,19 @@ | |
| see license/LICENSE_TTFQUERY. | ||
| """ | ||
|
|
||
| import json | ||
| import os, sys, warnings | ||
| from collections import Iterable | ||
| import json | ||
| import os | ||
| import sys | ||
| from threading import Timer | ||
| import warnings | ||
|
|
||
| import matplotlib | ||
| from matplotlib import afm | ||
| from matplotlib import ft2font | ||
| from matplotlib import rcParams, get_cachedir | ||
| from matplotlib import afm, cbook, ft2font, rcParams, get_cachedir | ||
| from matplotlib.cbook import is_string_like | ||
| import matplotlib.cbook as cbook | ||
| from matplotlib.compat import subprocess | ||
| from matplotlib.fontconfig_pattern import \ | ||
| parse_fontconfig_pattern, generate_fontconfig_pattern | ||
| from matplotlib.fontconfig_pattern import ( | ||
| parse_fontconfig_pattern, generate_fontconfig_pattern) | ||
|
|
||
| try: | ||
| from functools import lru_cache | ||
| Expand Down Expand Up | @@ -262,39 +263,39 @@ def OSXInstalledFonts(directories=None, fontext='ttf'): | |
| files.extend(list_fonts(path, fontext)) | ||
| return files | ||
|
|
||
| def get_fontconfig_fonts(fontext='ttf'): | ||
|
|
||
| @lru_cache() | ||
| def _call_fc_list(): | ||
| """Cache and list the font filenames known to `fc-list`. | ||
| """ | ||
| Grab a list of all the fonts that are being tracked by fontconfig | ||
| by making a system call to ``fc-list``. This is an easy way to | ||
| grab all of the fonts the user wants to be made available to | ||
| applications, without needing knowing where all of them reside. | ||
| # Delay the warning by 5s. | ||
| timer = Timer(5, lambda: warnings.warn( | ||
| 'Matplotlib is building the font cache using fc-list. ' | ||
| 'This may take a moment.')) | ||
| timer.start() | ||
| try: | ||
| out = subprocess.check_output(['fc-list', '--format=%{file}']) | ||
| except (OSError, subprocess.CalledProcessError): | ||
| return [] | ||
| finally: | ||
| timer.cancel() | ||
| fnames = [] | ||
| for fname in out.split(b'\n'): | ||
| try: | ||
| fname = six.text_type(fname, sys.getfilesystemencoding()) | ||
| except UnicodeDecodeError: | ||
| continue | ||
| fnames.append(fname) | ||
| return fnames | ||
|
|
||
|
|
||
| def get_fontconfig_fonts(fontext='ttf'): | ||
| """List the font filenames known to `fc-list` having the given extension. | ||
| """ | ||
| fontext = get_fontext_synonyms(fontext) | ||
| return [fname for fname in _call_fc_list() | ||
|
Comment thread
Copy link
Copy Markdown
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityThis changes the return type?
Sorry, something went wrong.
All reactions
Copy link
Copy Markdown
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityFrom a set represented as a {key: 1, key: 1, ...} dict to a list, yes. I can even document this as a API break :-)
Sorry, something went wrong.
All reactions
Copy link
Copy Markdown
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality👍 , please document this. The duck typing of the likely usage is the same.
Sorry, something went wrong.
All reactions
Copy link
Copy Markdown
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Qualitydone
Sorry, something went wrong.
All reactions
|
||
| if os.path.splitext(fname)[1][1:] in fontext] | ||
|
|
||
| fontfiles = {} | ||
| try: | ||
| warnings.warn('Matplotlib is building the font cache using fc-list. This may take a moment.') | ||
| pipe = subprocess.Popen(['fc-list', '--format=%{file}\\n'], | ||
| stdout=subprocess.PIPE, | ||
| stderr=subprocess.PIPE) | ||
| output = pipe.communicate()[0] | ||
| except (OSError, IOError): | ||
| # Calling fc-list did not work, so we'll just return nothing | ||
| return fontfiles | ||
|
|
||
| if pipe.returncode == 0: | ||
| # The line breaks between results are in ascii, but each entry | ||
| # is in in sys.filesystemencoding(). | ||
| for fname in output.split(b'\n'): | ||
| try: | ||
| fname = six.text_type(fname, sys.getfilesystemencoding()) | ||
| except UnicodeDecodeError: | ||
| continue | ||
| if (os.path.splitext(fname)[1][1:] in fontext and | ||
| os.path.exists(fname)): | ||
| fontfiles[fname] = 1 | ||
|
|
||
| return fontfiles | ||
|
|
||
| def findSystemFonts(fontpaths=None, fontext='ttf'): | ||
| """ | ||
| Expand All | @@ -304,7 +305,7 @@ def findSystemFonts(fontpaths=None, fontext='ttf'): | |
| available. A list of TrueType fonts are returned by default with | ||
| AFM fonts as an option. | ||
| """ | ||
| fontfiles = {} | ||
| fontfiles = set() | ||
| fontexts = get_fontext_synonyms(fontext) | ||
|
|
||
| if fontpaths is None: | ||
| Expand All | @@ -316,26 +317,26 @@ def findSystemFonts(fontpaths=None, fontext='ttf'): | |
| for f in win32InstalledFonts(fontdir): | ||
| base, ext = os.path.splitext(f) | ||
| if len(ext)>1 and ext[1:].lower() in fontexts: | ||
| fontfiles[f] = 1 | ||
| fontfiles.add(f) | ||
| else: | ||
| fontpaths = X11FontDirectories | ||
| # check for OS X & load its fonts if present | ||
| if sys.platform == 'darwin': | ||
| for f in OSXInstalledFonts(fontext=fontext): | ||
| fontfiles[f] = 1 | ||
| fontfiles.add(f) | ||
|
|
||
| for f in get_fontconfig_fonts(fontext): | ||
| fontfiles[f] = 1 | ||
| fontfiles.add(f) | ||
|
|
||
| elif isinstance(fontpaths, six.string_types): | ||
| fontpaths = [fontpaths] | ||
|
|
||
| for path in fontpaths: | ||
| files = list_fonts(path, fontexts) | ||
| for fname in files: | ||
| fontfiles[os.path.abspath(fname)] = 1 | ||
| fontfiles.add(os.path.abspath(fname)) | ||
|
|
||
| return [fname for fname in six.iterkeys(fontfiles) if os.path.exists(fname)] | ||
| return [fname for fname in fontfiles if os.path.exists(fname)] | ||
|
|
||
| def weight_as_number(weight): | ||
| """ | ||
| Expand Down Expand Up | @@ -833,7 +834,7 @@ def set_family(self, family): | |
| family = rcParams['font.family'] | ||
| if is_string_like(family): | ||
| family = [six.text_type(family)] | ||
| elif (not is_string_like(family) and isinstance(family, Iterable)): | ||
| elif not is_string_like(family) and isinstance(family, Iterable): | ||
| family = [six.text_type(f) for f in family] | ||
| self._family = family | ||
| set_name = set_family | ||
| Expand Down | ||
| Back | FazBrowse Home | New Git URL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityThis looks like it will always come out empty.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.