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

Commite1750a8

Browse files
anntzertimhoffm
authored andcommitted
Don't try to find TeX-only fonts when layouting TeX text. (#13170)
Text.is_math_text is only ever called with self.get_usetex() as secondargument, so just change it to a private method (Text._preprocess_math)that calls self.get_usetex() internally; deprecate is_math_text whichis clearly a private internal helper. This also helps clarifying thatusetex mode is only ever called if self.get_usetex() is True (in thetextobj.is_math_text(...) line, textobj is actually the same object(!)as self so shares the same get_usetex() value).In Text._get_layout, if self.get_usetex() is True (and only in thatcase), self._fontproperties can refer to a TeX-only font (e.g. "ComputerModern Roman"). If that's the case, don't try to callrenderer.get_text_width_height_descent with ismath=False, as that wouldtrigger a font resolution that can fail (perhaps there's no "ComputerModern Roman" font available in the font cache; it may only be availableto TeX) and cause a spurious warning.
1 parenta598811 commite1750a8

File tree

3 files changed

+31
-5
lines changed

3 files changed

+31
-5
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Deprecations
2+
````````````
3+
4+
``Text.is_math_text`` is deprecated.

‎lib/matplotlib/contour.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ def get_label_width(self, lev, fmt, fsize):
264264
ifnotisinstance(lev,str):
265265
lev=self.get_text(lev,fmt)
266266

267-
lev,ismath=text.Text.is_math_text(lev)
267+
lev,ismath=text.Text()._preprocess_math(lev)
268268
ifismath=='TeX':
269269
ifnothasattr(self,'_TeX_manager'):
270270
self._TeX_manager=texmanager.TexManager()

‎lib/matplotlib/text.py

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -286,11 +286,12 @@ def _get_layout(self, renderer):
286286

287287
# Full vertical extent of font, including ascenders and descenders:
288288
_,lp_h,lp_d=renderer.get_text_width_height_descent(
289-
"lp",self._fontproperties,ismath=False)
289+
"lp",self._fontproperties,
290+
ismath="TeX"ifself.get_usetex()elseFalse)
290291
min_dy= (lp_h-lp_d)*self._linespacing
291292

292293
fori,lineinenumerate(lines):
293-
clean_line,ismath=self.is_math_text(line,self.get_usetex())
294+
clean_line,ismath=self._preprocess_math(line)
294295
ifclean_line:
295296
w,h,d=renderer.get_text_width_height_descent(
296297
clean_line,self._fontproperties,ismath=ismath)
@@ -697,8 +698,7 @@ def draw(self, renderer):
697698
y=y+posy
698699
ifrenderer.flipy():
699700
y=canvash-y
700-
clean_line,ismath=textobj.is_math_text(line,
701-
self.get_usetex())
701+
clean_line,ismath=textobj._preprocess_math(line)
702702

703703
iftextobj.get_path_effects():
704704
frommatplotlib.patheffectsimportPathEffectRenderer
@@ -1152,6 +1152,7 @@ def set_text(self, s):
11521152
self.stale=True
11531153

11541154
@staticmethod
1155+
@cbook.deprecated("3.1")
11551156
defis_math_text(s,usetex=None):
11561157
"""
11571158
Returns a cleaned string and a boolean flag.
@@ -1174,6 +1175,27 @@ def is_math_text(s, usetex=None):
11741175
else:
11751176
returns.replace(r'\$','$'),False
11761177

1178+
def_preprocess_math(self,s):
1179+
"""
1180+
Return the string *s* after mathtext preprocessing, and the kind of
1181+
mathtext support needed.
1182+
1183+
- If *self* is configured to use TeX, return *s* unchanged except that
1184+
a single space gets escaped, and the flag "TeX".
1185+
- Otherwise, if *s* is mathtext (has an even number of unescaped dollar
1186+
signs), return *s* and the flag True.
1187+
- Otherwise, return *s* with dollar signs unescaped, and the flag
1188+
False.
1189+
"""
1190+
ifself.get_usetex():
1191+
ifs==" ":
1192+
s=r"\ "
1193+
returns,"TeX"
1194+
elifcbook.is_math_text(s):
1195+
returns,True
1196+
else:
1197+
returns.replace(r"\$","$"),False
1198+
11771199
defset_fontproperties(self,fp):
11781200
"""
11791201
Set the font properties that control the text.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp