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

Skip to content

Commit 82741f5

Browse files
authored
Merge pull request #13502 from meeseeksmachine/auto-backport-of-pr-13180-on-v3.1.x
Backport PR #13180 on branch v3.1.x (Various TextPath cleanups.)
2 parents d966e54 + b392c9f commit 82741f5

File tree

3 files changed

+40
-18
lines changed

3 files changed

+40
-18
lines changed

doc/api/next_api_changes/2019-01-13-AL.rst

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,19 @@ Deprecations
22
````````````
33

44
``Text.is_math_text`` is deprecated.
5+
6+
``TextPath.is_math_text`` and ``TextPath.text_get_vertices_codes`` are
7+
deprecated. As an alternative to the latter, construct a new ``TextPath``
8+
object.
9+
10+
The ``usetex`` parameter of ``TextToPath.get_text_path`` is deprecated and
11+
folded into the ``ismath`` parameter, which can now take the values False,
12+
True, and "TeX", consistently with other low-level text processing functions.
13+
14+
Behavior changes
15+
````````````````
16+
17+
Previously, if :rc:`text.usetex` was True, then constructing a `TextPath` on
18+
a non-mathtext string with ``usetex=False`` would rely on the mathtext parser
19+
(but not on usetex support!) to parse the string. The mathtext parser is not
20+
invoked anymore, which may cause slight changes in glyph positioning.

lib/matplotlib/backend_bases.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -556,8 +556,6 @@ def _get_text_path_transform(self, x, y, s, prop, angle, ismath):
556556
The font property.
557557
s : str
558558
The text to be converted.
559-
usetex : bool
560-
Whether to use matplotlib usetex mode.
561559
ismath : bool or "TeX"
562560
If True, use mathtext parser. If "TeX", use *usetex* mode.
563561
"""

lib/matplotlib/textpath.py

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ def get_text_width_height_descent(self, s, prop, ismath):
102102
d /= 64.0
103103
return w * scale, h * scale, d * scale
104104

105+
@cbook._delete_parameter("3.1", "usetex")
105106
def get_text_path(self, prop, s, ismath=False, usetex=False):
106107
"""
107108
Convert text *s* to path (a tuple of vertices and codes for
@@ -116,12 +117,11 @@ def get_text_path(self, prop, s, ismath=False, usetex=False):
116117
s : str
117118
The text to be converted.
118119
119-
usetex : bool, optional
120-
Whether to use tex rendering. Defaults to ``False``.
120+
ismath : {False, True, "TeX"}
121+
If True, use mathtext parser. If "TeX", use tex for renderering.
121122
122-
ismath : bool, optional
123-
If True, use mathtext parser. Effective only if
124-
``usetex == False``.
123+
usetex : bool, optional
124+
If set, forces *ismath* to True. This parameter is deprecated.
125125
126126
Returns
127127
-------
@@ -146,16 +146,15 @@ def get_text_path(self, prop, s, ismath=False, usetex=False):
146146
147147
Also see `TextPath` for a more direct way to create a path from a text.
148148
"""
149-
if not usetex:
150-
if not ismath:
151-
font = self._get_font(prop)
152-
glyph_info, glyph_map, rects = self.get_glyphs_with_font(
153-
font, s)
154-
else:
155-
glyph_info, glyph_map, rects = self.get_glyphs_mathtext(
156-
prop, s)
157-
else:
149+
if usetex:
150+
ismath = "TeX"
151+
if ismath == "TeX":
158152
glyph_info, glyph_map, rects = self.get_glyphs_tex(prop, s)
153+
elif not ismath:
154+
font = self._get_font(prop)
155+
glyph_info, glyph_map, rects = self.get_glyphs_with_font(font, s)
156+
else:
157+
glyph_info, glyph_map, rects = self.get_glyphs_mathtext(prop, s)
159158

160159
verts, codes = [], []
161160

@@ -448,6 +447,8 @@ def __init__(self, xy, s, size=None, prop=None,
448447
449448
Also see :doc:`/gallery/text_labels_and_annotations/demo_text_path`.
450449
"""
450+
# Circular import.
451+
from matplotlib.text import Text
451452

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

465466
self._cached_vertices = None
466-
self._vertices, self._codes = \
467-
self.text_get_vertices_codes(prop, s, usetex=usetex)
467+
s, ismath = Text(usetex=usetex)._preprocess_math(s)
468+
if ismath == "TeX":
469+
self._vertices, self._codes = text_to_path.get_text_path(
470+
prop, s, usetex=True)
471+
else:
472+
self._vertices, self._codes = text_to_path.get_text_path(
473+
prop, s, ismath=ismath)
468474
self._should_simplify = False
469475
self._simplify_threshold = rcParams['path.simplify_threshold']
470476
self._interpolation_steps = _interpolation_steps
@@ -507,6 +513,7 @@ def _revalidate_path(self):
507513
self._cached_vertices = tr.transform(self._vertices)
508514
self._invalid = False
509515

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

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

0 commit comments

Comments
 (0)