Skip to content

Don't try to find TeX-only fonts when layouting TeX text. #13170

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
Jan 14, 2019
Merged
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions doc/api/next_api_changes/2019-01-13-AL.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Deprecations
````````````

``Text.is_math_text`` is deprecated.
2 changes: 1 addition & 1 deletion lib/matplotlib/contour.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ def get_label_width(self, lev, fmt, fsize):
if not isinstance(lev, str):
lev = self.get_text(lev, fmt)

lev, ismath = text.Text.is_math_text(lev)
lev, ismath = text.Text()._preprocess_math(lev)
if ismath == 'TeX':
if not hasattr(self, '_TeX_manager'):
self._TeX_manager = texmanager.TexManager()
Expand Down
30 changes: 26 additions & 4 deletions lib/matplotlib/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,11 +286,12 @@ def _get_layout(self, renderer):

# Full vertical extent of font, including ascenders and descenders:
_, lp_h, lp_d = renderer.get_text_width_height_descent(
"lp", self._fontproperties, ismath=False)
"lp", self._fontproperties,
ismath="TeX" if self.get_usetex() else False)
min_dy = (lp_h - lp_d) * self._linespacing

for i, line in enumerate(lines):
clean_line, ismath = self.is_math_text(line, self.get_usetex())
clean_line, ismath = self._preprocess_math(line)
if clean_line:
w, h, d = renderer.get_text_width_height_descent(
clean_line, self._fontproperties, ismath=ismath)
Expand Down Expand Up @@ -697,8 +698,7 @@ def draw(self, renderer):
y = y + posy
if renderer.flipy():
y = canvash - y
clean_line, ismath = textobj.is_math_text(line,
self.get_usetex())
clean_line, ismath = textobj._preprocess_math(line)

if textobj.get_path_effects():
from matplotlib.patheffects import PathEffectRenderer
Expand Down Expand Up @@ -1152,6 +1152,7 @@ def set_text(self, s):
self.stale = True

@staticmethod
@cbook.deprecated("3.1")
def is_math_text(s, usetex=None):
"""
Returns a cleaned string and a boolean flag.
Expand All @@ -1174,6 +1175,27 @@ def is_math_text(s, usetex=None):
else:
return s.replace(r'\$', '$'), False

def _preprocess_math(self, s):
"""
Return the string *s* after mathtext preprocessing, and the kind of
mathtext support needed.

- If *self* is configured to use TeX, return *s* unchanged except that
a single space gets escaped, and the flag "TeX".
- Otherwise, if *s* is mathtext (has an even number of unescaped dollar
signs), return *s* and the flag True.
- Otherwise, return *s* with dollar signs unescaped, and the flag
False.
"""
if self.get_usetex():
if s == " ":
s = r"\ "
return s, "TeX"
elif cbook.is_math_text(s):
return s, True
else:
return s.replace(r"\$", "$"), False

def set_fontproperties(self, fp):
"""
Set the font properties that control the text.
Expand Down