| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -11,6 +11,7 @@ The following modules are deprecated: | |||
| 11 | 11 | The following classes, methods, functions, and attributes are deprecated: | |
| 12 | 12 | ||
| 13 | 13 | - ``afm.parse_afm``, | |
| 14 | + - ``backend_pgf.get_texcommand``, | ||
| 14 | 15 | - ``backend_qt5.error_msg_qt``, ``backend_qt5.exception_handler``, | |
| 15 | 16 | - ``backend_wx.FigureCanvasWx.macros``, | |
| 16 | 17 | - ``cbook.GetRealpathAndStat``, ``cbook.Locked``, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4,6 +4,7 @@ | |||
| 4 | 4 | import logging | |
| 5 | 5 | import math | |
| 6 | 6 | import os | |
| 7 | + from pathlib import Path | ||
| 7 | 8 | import re | |
| 8 | 9 | import shutil | |
| 9 | 10 | import subprocess | |
@@ -13,7 +14,7 @@ | |||
| 13 | 14 | import weakref | |
| 14 | 15 | ||
| 15 | 16 | import matplotlib as mpl | |
| 16 | - from matplotlib import _png, rcParams, __version__ | ||
| 17 | + from matplotlib import _png, cbook, font_manager as fm, __version__, rcParams | ||
| 17 | 18 | from matplotlib.backend_bases import ( | |
| 18 | 19 | _Backend, FigureCanvasBase, FigureManagerBase, GraphicsContextBase, | |
| 19 | 20 | RendererBase) | |
@@ -28,33 +29,13 @@ | |||
| 28 | 29 | ||
| 29 | 30 | ############################################################################### | |
| 30 | 31 | ||
| 31 | - # create a list of system fonts, all of these should work with xe/lua-latex | ||
| 32 | - system_fonts = [] | ||
| 33 | - if sys.platform == 'win32': | ||
| 34 | - from matplotlib import font_manager | ||
| 35 | - for f in font_manager.win32InstalledFonts(): | ||
| 36 | - try: | ||
| 37 | - system_fonts.append(font_manager.get_font(str(f)).family_name) | ||
| 38 | - except: | ||
| 39 | - pass # unknown error, skip this font | ||
| 40 | - else: | ||
| 41 | - # assuming fontconfig is installed and the command 'fc-list' exists | ||
| 42 | - try: | ||
| 43 | - # list scalable (non-bitmap) fonts | ||
| 44 | - fc_list = subprocess.check_output( | ||
| 45 | - ['fc-list', ':outline,scalable', 'family']) | ||
| 46 | - fc_list = fc_list.decode('utf8') | ||
| 47 | - system_fonts = [f.split(',')[0] for f in fc_list.splitlines()] | ||
| 48 | - system_fonts = list(set(system_fonts)) | ||
| 49 | - except: | ||
| 50 | - warnings.warn('error getting fonts from fc-list', UserWarning) | ||
| 51 | - | ||
| 52 | 32 | ||
| 53 | 33 | _luatex_version_re = re.compile( | |
| 54 | 34 | r'This is LuaTeX, Version (?:beta-)?([0-9]+)\.([0-9]+)\.([0-9]+)' | |
| 55 | 35 | ) | |
| 56 | 36 | ||
| 57 | 37 | ||
| 38 | + @cbook.deprecated("3.0") | ||
| 58 | 39 | def get_texcommand(): | |
| 59 | 40 | """Get chosen TeX system from rc.""" | |
| 60 | 41 | texsystem_options = ["xelatex", "lualatex", "pdflatex"] | |
@@ -77,23 +58,20 @@ def _parse_lualatex_version(output): | |||
| 77 | 58 | def get_fontspec(): | |
| 78 | 59 | """Build fontspec preamble from rc.""" | |
| 79 | 60 | latex_fontspec = [] | |
| 80 | - texcommand = get_texcommand() | ||
| 61 | + texcommand = rcParams["pgf.texsystem"] | ||
| 81 | 62 | ||
| 82 | 63 | if texcommand != "pdflatex": | |
| 83 | 64 | latex_fontspec.append("\\usepackage{fontspec}") | |
| 84 | 65 | ||
| 85 | 66 | if texcommand != "pdflatex" and rcParams["pgf.rcfonts"]: | |
| 86 | - # try to find fonts from rc parameters | ||
| 87 | - families = ["serif", "sans-serif", "monospace"] | ||
| 88 | - fontspecs = [r"\setmainfont{%s}", r"\setsansfont{%s}", | ||
| 89 | - r"\setmonofont{%s}"] | ||
| 90 | - for family, fontspec in zip(families, fontspecs): | ||
| 91 | - matches = [f for f in rcParams["font." + family] | ||
| 92 | - if f in system_fonts] | ||
| 93 | - if matches: | ||
| 94 | - latex_fontspec.append(fontspec % matches[0]) | ||
| 95 | - else: | ||
| 96 | - pass # no fonts found, fallback to LaTeX defaule | ||
| 67 | + families = ["serif", "sans\\-serif", "monospace"] | ||
| 68 | + commands = ["setmainfont", "setsansfont", "setmonofont"] | ||
| 69 | + for family, command in zip(families, commands): | ||
| 70 | + # 1) Forward slashes also work on Windows, so don't mess with | ||
| 71 | + # backslashes. 2) The dirname needs to include a separator. | ||
| 72 | + path = Path(fm.findfont(family)) | ||
| 73 | + latex_fontspec.append(r"\%s{%s}[Path=%s]" % ( | ||
| 74 | + command, path.name, path.parent.as_posix() + "/")) | ||
| 97 | 75 | ||
| 98 | 76 | return "\n".join(latex_fontspec) | |
| 99 | 77 | ||
@@ -163,7 +141,7 @@ def _font_properties_str(prop): | |||
| 163 | 141 | family = prop.get_family()[0] | |
| 164 | 142 | if family in families: | |
| 165 | 143 | commands.append(families[family]) | |
| 166 | - elif family in system_fonts and get_texcommand() != "pdflatex": | ||
| 144 | + elif family in system_fonts and rcParams["pgf.texsystem"] != "pdflatex": | ||
| 167 | 145 | commands.append(r"\setmainfont{%s}\rmfamily" % family) | |
| 168 | 146 | else: | |
| 169 | 147 | pass # print warning? | |
@@ -232,7 +210,7 @@ class LatexManagerFactory: | |||
| 232 | 210 | ||
| 233 | 211 | @staticmethod | |
| 234 | 212 | def get_latex_manager(): | |
| 235 | - texcommand = get_texcommand() | ||
| 213 | + texcommand = rcParams["pgf.texsystem"] | ||
| 236 | 214 | latex_header = LatexManager._build_latex_header() | |
| 237 | 215 | prev = LatexManagerFactory.previous_instance | |
| 238 | 216 | ||
@@ -307,7 +285,7 @@ def __init__(self): | |||
| 307 | 285 | LatexManager._unclean_instances.add(self) | |
| 308 | 286 | ||
| 309 | 287 | # test the LaTeX setup to ensure a clean startup of the subprocess | |
| 310 | - self.texcommand = get_texcommand() | ||
| 288 | + self.texcommand = rcParams["pgf.texsystem"] | ||
| 311 | 289 | self.latex_header = LatexManager._build_latex_header() | |
| 312 | 290 | latex_end = "\n\\makeatletter\n\\@@end\n" | |
| 313 | 291 | try: | |
@@ -909,7 +887,7 @@ def _print_pdf_to_fh(self, fh, *args, **kwargs): | |||
| 909 | 887 | with codecs.open(fname_tex, "w", "utf-8") as fh_tex: | |
| 910 | 888 | fh_tex.write(latexcode) | |
| 911 | 889 | ||
| 912 | - texcommand = get_texcommand() | ||
| 890 | + texcommand = rcParams["pgf.texsystem"] | ||
| 913 | 891 | cmdargs = [texcommand, "-interaction=nonstopmode", | |
| 914 | 892 | "-halt-on-error", "figure.tex"] | |
| 915 | 893 | try: | |
| Back | FazBrowse Home | New Git URL |
0 commit comments