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

Skip to content

Commit 5b36d02

Browse files
authored
Merge pull request #28390 from anntzer/gtpt
Inline RendererBase._get_text_path_transform.
2 parents 8b9cb14 + 96257a3 commit 5b36d02

File tree

1 file changed

+17
-48
lines changed

1 file changed

+17
-48
lines changed

lib/matplotlib/backend_bases.py

Lines changed: 17 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -510,75 +510,44 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
510510
angle : float
511511
The rotation angle in degrees anti-clockwise.
512512
ismath : bool or "TeX"
513-
If True, use mathtext parser. If "TeX", use tex for rendering.
513+
If True, use mathtext parser.
514514
mtext : `~matplotlib.text.Text`
515515
The original text object to be rendered.
516+
517+
Notes
518+
-----
519+
**Notes for backend implementers:**
520+
521+
`.RendererBase.draw_text` also supports passing "TeX" to the *ismath*
522+
parameter to use TeX rendering, but this is not required for actual
523+
rendering backends, and indeed many builtin backends do not support
524+
this. Rather, TeX rendering is provided by `~.RendererBase.draw_tex`.
516525
"""
517526
self._draw_text_as_path(gc, x, y, s, prop, angle, ismath)
518527

519-
def _get_text_path_transform(self, x, y, s, prop, angle, ismath):
528+
def _draw_text_as_path(self, gc, x, y, s, prop, angle, ismath):
520529
"""
521-
Return the text path and transform.
530+
Draw the text by converting them to paths using `.TextToPath`.
522531
523-
Parameters
524-
----------
525-
x : float
526-
The x location of the text in display coords.
527-
y : float
528-
The y location of the text baseline in display coords.
529-
s : str
530-
The text to be converted.
531-
prop : `~matplotlib.font_manager.FontProperties`
532-
The font property.
533-
angle : float
534-
Angle in degrees to render the text at.
535-
ismath : bool or "TeX"
536-
If True, use mathtext parser. If "TeX", use tex for rendering.
532+
This private helper supports the same parameters as
533+
`~.RendererBase.draw_text`; setting *ismath* to "TeX" triggers TeX
534+
rendering.
537535
"""
538-
539536
text2path = self._text2path
540537
fontsize = self.points_to_pixels(prop.get_size_in_points())
541538
verts, codes = text2path.get_text_path(prop, s, ismath=ismath)
542-
543539
path = Path(verts, codes)
544-
angle = np.deg2rad(angle)
545540
if self.flipy():
546541
width, height = self.get_canvas_width_height()
547542
transform = (Affine2D()
548543
.scale(fontsize / text2path.FONT_SCALE)
549-
.rotate(angle)
544+
.rotate_deg(angle)
550545
.translate(x, height - y))
551546
else:
552547
transform = (Affine2D()
553548
.scale(fontsize / text2path.FONT_SCALE)
554-
.rotate(angle)
549+
.rotate_deg(angle)
555550
.translate(x, y))
556-
557-
return path, transform
558-
559-
def _draw_text_as_path(self, gc, x, y, s, prop, angle, ismath):
560-
"""
561-
Draw the text by converting them to paths using `.TextToPath`.
562-
563-
Parameters
564-
----------
565-
gc : `.GraphicsContextBase`
566-
The graphics context.
567-
x : float
568-
The x location of the text in display coords.
569-
y : float
570-
The y location of the text baseline in display coords.
571-
s : str
572-
The text to be converted.
573-
prop : `~matplotlib.font_manager.FontProperties`
574-
The font property.
575-
angle : float
576-
Angle in degrees to render the text at.
577-
ismath : bool or "TeX"
578-
If True, use mathtext parser. If "TeX", use tex for rendering.
579-
"""
580-
path, transform = self._get_text_path_transform(
581-
x, y, s, prop, angle, ismath)
582551
color = gc.get_rgb()
583552
gc.set_linewidth(0.0)
584553
self.draw_path(gc, path, transform, rgbFace=color)

0 commit comments

Comments
 (0)