8000 Merge pull request #22547 from anntzer/tm · matplotlib/matplotlib@6d3a068 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6d3a068

Browse files
authored
Merge pull request #22547 from anntzer/tm
Small cleanups around TexManager usage.
2 parents 73db9bf + 6762744 commit 6d3a068

File tree

3 files changed

+15
-16
lines changed

3 files changed

+15
-16
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
``TextToPath.get_texmanager``
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
... is deprecated; directly construct a `.texmanager.TexManager` instead.

lib/matplotlib/backend_bases.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
from matplotlib.backend_managers import ToolManager
5050
from matplotlib.cbook import _setattr_cm
5151
from matplotlib.path import Path
52+
from matplotlib.texmanager import TexManager
5253
from matplotlib.transforms import Affine2D
5354
from matplotlib._enums import JoinStyle, CapStyle
5455

@@ -605,13 +606,12 @@ def get_text_width_height_descent(self, s, prop, ismath):
605606
to the baseline), in display coords, of the string *s* with
606607
`.FontProperties` *prop*.
607608
"""
609+
fontsize = prop.get_size_in_points()
610+
608611
if ismath == 'TeX':
609612
# todo: handle props
610-
texmanager = self._text2path.get_texmanager()
611-
fontsize = prop.get_size_in_points()
612-
w, h, d = texmanager.get_text_width_height_descent(
613+
return TexManager().get_text_width_height_descent(
613614
s, fontsize, renderer=self)
614-
return w, h, d
615615

616616
dpi = self.points_to_pixels(72)
617617
if ismath:
@@ -620,8 +620,7 @@ def get_text_width_height_descent(self, s, prop, ismath):
620620

621621
flags = self._text2path._get_hinting_flag()
622622
font = self._text2path._get_font(prop)
623-
size = prop.get_size_in_points()
624-
font.set_size(size, dpi)
623+
font.set_size(fontsize, dpi)
625624
# the width and height of unrotated string
626625
font.set_text(s, 0.0, flags=flags)
627626
w, h = font.get_width_height()
@@ -646,7 +645,6 @@ def get_canvas_width_height(self):
646645
def get_texmanager(self):
647646
"""Return the `.TexManager` instance."""
648647
if self._texmanager is None:
649-
from matplotlib.texmanager import TexManager
650648
self._texmanager = TexManager()
651649
return self._texmanager
652650

lib/matplotlib/textpath.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55

66
import numpy as np
77

8-
from matplotlib import _text_helpers, dviread, font_manager
8+
from matplotlib import _api, _text_helpers, dviread, font_manager
99
from matplotlib.font_manager import FontProperties, get_font
1010
from matplotlib.ft2font import LOAD_NO_HINTING, LOAD_TARGET_LIGHT
1111
from matplotlib.mathtext import MathTextParser
1212
from matplotlib.path import Path
13+
from matplotlib.texmanager import TexManager
1314
from matplotlib.transforms import Affine2D
1415

1516
_log = logging.getLogger(__name__)
@@ -44,14 +45,11 @@ def _get_char_id(self, font, ccode):
4445
return urllib.parse.quote(f"{font.postscript_name}-{ccode:x}")
4546

4647
def get_text_width_height_descent(self, s, prop, ismath):
48+
fontsize = prop.get_size_in_points()
49+
4750
if ismath == "TeX":
48-
texmanager = self.get_texmanager()
49-
fontsize = prop.get_size_in_points()
50-
w, h, d = texmanager.get_text_width_height_descent(s, fontsize,
51-
renderer=None)
52-
return w, h, d
51+
return TexManager().get_text_width_height_descent(s, fontsize)
5352

54-
fontsize = prop.get_size_in_points()
5553
scale = fontsize / self.FONT_SCALE
5654

5755
if ismath:
@@ -215,10 +213,10 @@ def get_glyphs_mathtext(self, prop, s, glyph_map=None,
215213
return (list(zip(glyph_ids, xpositions, ypositions, sizes)),
216214
glyph_map_new, myrects)
217215

216+
@_api.deprecated("3.6", alternative="TexManager()")
218217
def get_texmanager(self):
219218
"""Return the cached `~.texmanager.TexManager` instance."""
220219
if self._texmanager is None:
221-
from matplotlib.texmanager import TexManager
222220
self._texmanager = TexManager()
223221
return self._texmanager
224222

@@ -227,7 +225,7 @@ def get_glyphs_tex(self, prop, s, glyph_map=None,
227225
"""Convert the string *s* to vertices and codes using usetex mode."""
228226
# Mostly borrowed from pdf backend.
229227

230-
dvifile = self.get_texmanager().make_dvi(s, self.FONT_SCALE)
228+
dvifile = TexManager().make_dvi(s, self.FONT_SCALE)
231229
with dviread.Dvi(dvifile, self.DPI) as dvi:
232230
page, = dvi
233231

0 commit comments

Comments
 (0)
0