Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Backport PR #13180 on branch v3.1.x (Various TextPath cleanups.) #13502

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
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
16 changes: 16 additions & 0 deletions doc/api/next_api_changes/2019-01-13-AL.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,19 @@ Deprecations
````````````

``Text.is_math_text`` is deprecated.

``TextPath.is_math_text`` and ``TextPath.text_get_vertices_codes`` are
deprecated. As an alternative to the latter, construct a new ``TextPath``
object.

The ``usetex`` parameter of ``TextToPath.get_text_path`` is deprecated and
folded into the ``ismath`` parameter, which can now take the values False,
True, and "TeX", consistently with other low-level text processing functions.

Behavior changes
````````````````

Previously, if :rc:`text.usetex` was True, then constructing a `TextPath` on
a non-mathtext string with ``usetex=False`` would rely on the mathtext parser
(but not on usetex support!) to parse the string. The mathtext parser is not
invoked anymore, which may cause slight changes in glyph positioning.
2 changes: 0 additions & 2 deletions lib/matplotlib/backend_bases.py
Original file line number Diff line number Diff line change
Expand Up @@ -556,8 +556,6 @@ def _get_text_path_transform(self, x, y, s, prop, angle, ismath):
The font property.
s : str
The text to be converted.
usetex : bool
Whether to use matplotlib usetex mode.
ismath : bool or "TeX"
If True, use mathtext parser. If "TeX", use *usetex* mode.
"""
Expand Down
40 changes: 24 additions & 16 deletions lib/matplotlib/textpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ def get_text_width_height_descent(self, s, prop, ismath):
d /= 64.0
return w * scale, h * scale, d * scale

@cbook._delete_parameter("3.1", "usetex")
def get_text_path(self, prop, s, ismath=False, usetex=False):
"""
Convert text *s* to path (a tuple of vertices and codes for
Expand All @@ -116,12 +117,11 @@ def get_text_path(self, prop, s, ismath=False, usetex=False):
s : str
The text to be converted.

usetex : bool, optional
Whether to use tex rendering. Defaults to ``False``.
ismath : {False, True, "TeX"}
If True, use mathtext parser. If "TeX", use tex for renderering.

ismath : bool, optional
If True, use mathtext parser. Effective only if
``usetex == False``.
usetex : bool, optional
If set, forces *ismath* to True. This parameter is deprecated.

Returns
-------
Expand All @@ -146,16 +146,15 @@ def get_text_path(self, prop, s, ismath=False, usetex=False):

Also see `TextPath` for a more direct way to create a path from a text.
"""
if not usetex:
if not ismath:
font = self._get_font(prop)
glyph_info, glyph_map, rects = self.get_glyphs_with_font(
font, s)
else:
glyph_info, glyph_map, rects = self.get_glyphs_mathtext(
prop, s)
else:
if usetex:
ismath = "TeX"
if ismath == "TeX":
glyph_info, glyph_map, rects = self.get_glyphs_tex(prop, s)
elif not ismath:
font = self._get_font(prop)
glyph_info, glyph_map, rects = self.get_glyphs_with_font(font, s)
else:
glyph_info, glyph_map, rects = self.get_glyphs_mathtext(prop, s)

verts, codes = [], []

Expand Down Expand Up @@ -448,6 +447,8 @@ def __init__(self, xy, s, size=None, prop=None,

Also see :doc:`/gallery/text_labels_and_annotations/demo_text_path`.
"""
# Circular import.
from matplotlib.text import Text

if args or kwargs:
cbook.warn_deprecated(
Expand All @@ -463,8 +464,13 @@ def __init__(self, xy, s, size=None, prop=None,
self.set_size(size)

self._cached_vertices = None
self._vertices, self._codes = \
self.text_get_vertices_codes(prop, s, usetex=usetex)
s, ismath = Text(usetex=usetex)._preprocess_math(s)
if ismath == "TeX":
self._vertices, self._codes = text_to_path.get_text_path(
prop, s, usetex=True)
else:
self._vertices, self._codes = text_to_path.get_text_path(
prop, s, ismath=ismath)
self._should_simplify = False
self._simplify_threshold = rcParams['path.simplify_threshold']
self._interpolation_steps = _interpolation_steps
Expand Down Expand Up @@ -507,6 +513,7 @@ def _revalidate_path(self):
self._cached_vertices = tr.transform(self._vertices)
self._invalid = False

@cbook.deprecated("3.1")
def is_math_text(self, s):
"""
Returns True if the given string *s* contains any mathtext.
Expand All @@ -526,6 +533,7 @@ def is_math_text(self, s):
else:
return s.replace(r'\$', '$'), False

@cbook.deprecated("3.1", alternative="TextPath")
def text_get_vertices_codes(self, prop, s, usetex):
"""
Convert string *s* to a (vertices, codes) pair using font property
Expand Down