Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb002924

Browse files
committed
Pass explicit font paths to fontspec in backend_pgf.
1 parente22a16a commitb002924

File tree

2 files changed

+17
-38
lines changed

2 files changed

+17
-38
lines changed

‎doc/api/next_api_changes/2018-02-15-AL-deprecations.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ The following modules are deprecated:
1111
The following classes, methods, functions, and attributes are deprecated:
1212

1313
- ``afm.parse_afm``,
14+
- ``backend_pgf.get_texcommand``,
1415
- ``backend_qt5.error_msg_qt``, ``backend_qt5.exception_handler``,
1516
- ``backend_wx.FigureCanvasWx.macros``,
1617
- ``cbook.GetRealpathAndStat``, ``cbook.Locked``,

‎lib/matplotlib/backends/backend_pgf.py

Lines changed: 16 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
importlogging
55
importmath
66
importos
7+
frompathlibimportPath
78
importre
89
importshutil
910
importsubprocess
@@ -13,7 +14,7 @@
1314
importweakref
1415

1516
importmatplotlibasmpl
16-
frommatplotlibimport_png,rcParams,__version__
17+
frommatplotlibimport_png,cbook,font_managerasfm,__version__,rcParams
1718
frommatplotlib.backend_basesimport (
1819
_Backend,FigureCanvasBase,FigureManagerBase,GraphicsContextBase,
1920
RendererBase)
@@ -28,33 +29,13 @@
2829

2930
###############################################################################
3031

31-
# create a list of system fonts, all of these should work with xe/lua-latex
32-
system_fonts= []
33-
ifsys.platform=='win32':
34-
frommatplotlibimportfont_manager
35-
forfinfont_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]forfinfc_list.splitlines()]
48-
system_fonts=list(set(system_fonts))
49-
except:
50-
warnings.warn('error getting fonts from fc-list',UserWarning)
51-
5232

5333
_luatex_version_re=re.compile(
5434
r'This is LuaTeX, Version (?:beta-)?([0-9]+)\.([0-9]+)\.([0-9]+)'
5535
)
5636

5737

38+
@cbook.deprecated("3.0")
5839
defget_texcommand():
5940
"""Get chosen TeX system from rc."""
6041
texsystem_options= ["xelatex","lualatex","pdflatex"]
@@ -77,23 +58,20 @@ def _parse_lualatex_version(output):
7758
defget_fontspec():
7859
"""Build fontspec preamble from rc."""
7960
latex_fontspec= []
80-
texcommand=get_texcommand()
61+
texcommand=rcParams["pgf.texsystem"]
8162

8263
iftexcommand!="pdflatex":
8364
latex_fontspec.append("\\usepackage{fontspec}")
8465

8566
iftexcommand!="pdflatex"andrcParams["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-
forfamily,fontspecinzip(families,fontspecs):
91-
matches= [fforfinrcParams["font."+family]
92-
iffinsystem_fonts]
93-
ifmatches:
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+
forfamily,commandinzip(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+
dirname=Path(fm.findfont(family)).parent.as_posix()+"/"
73+
latex_fontspec.append(
74+
r"\%s{%s}[Path=%s]"% (command,basename,dirname))
9775

9876
return"\n".join(latex_fontspec)
9977

@@ -163,7 +141,7 @@ def _font_properties_str(prop):
163141
family=prop.get_family()[0]
164142
iffamilyinfamilies:
165143
commands.append(families[family])
166-
eliffamilyinsystem_fontsandget_texcommand()!="pdflatex":
144+
eliffamilyinsystem_fontsandrcParams["pgf.texsystem"]!="pdflatex":
167145
commands.append(r"\setmainfont{%s}\rmfamily"%family)
168146
else:
169147
pass# print warning?
@@ -232,7 +210,7 @@ class LatexManagerFactory:
232210

233211
@staticmethod
234212
defget_latex_manager():
235-
texcommand=get_texcommand()
213+
texcommand=rcParams["pgf.texsystem"]
236214
latex_header=LatexManager._build_latex_header()
237215
prev=LatexManagerFactory.previous_instance
238216

@@ -307,7 +285,7 @@ def __init__(self):
307285
LatexManager._unclean_instances.add(self)
308286

309287
# test the LaTeX setup to ensure a clean startup of the subprocess
310-
self.texcommand=get_texcommand()
288+
self.texcommand=rcParams["pgf.texsystem"]
311289
self.latex_header=LatexManager._build_latex_header()
312290
latex_end="\n\\makeatletter\n\\@@end\n"
313291
try:
@@ -909,7 +887,7 @@ def _print_pdf_to_fh(self, fh, *args, **kwargs):
909887
withcodecs.open(fname_tex,"w","utf-8")asfh_tex:
910888
fh_tex.write(latexcode)
911889

912-
texcommand=get_texcommand()
890+
texcommand=rcParams["pgf.texsystem"]
913891
cmdargs= [texcommand,"-interaction=nonstopmode",
914892
"-halt-on-error","figure.tex"]
915893
try:

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp