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

Skip to content

Commit 347c408

Browse files
pwuertzpwuertz
authored andcommitted
propagate mpl.text.Text instances to backends, fix documentation
1 parent 0da885a commit 347c408

14 files changed

+34
-29
lines changed

CHANGELOG

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
2012-11-27 Added the *mtext* parameter for supplying matplotlib.text.Text
2+
instances to RendererBase.draw_tex and RendererBase.draw_text.
3+
This allows backends to utilize additional text attributes, like
4+
the alignment of text elements. - pwuertz
5+
16
2012-11-16 plt.set_cmap no longer throws errors if there is not already
27
an active colorable artist, such as an image, and just sets
38
up the colormap to use from that point forward. - PI

lib/matplotlib/backend_bases.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -443,12 +443,12 @@ def option_scale_image(self):
443443
"""
444444
return False
445445

446-
def draw_tex(self, gc, x, y, s, prop, angle, ismath='TeX!'):
446+
def draw_tex(self, gc, x, y, s, prop, angle, ismath='TeX!', mtext=None):
447447
"""
448448
"""
449449
self._draw_text_as_path(gc, x, y, s, prop, angle, ismath="TeX")
450450

451-
def draw_text(self, gc, x, y, s, prop, angle, ismath=False):
451+
def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
452452
"""
453453
Draw the text instance
454454
@@ -462,14 +462,17 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath=False):
462462
the y location of the text in display coords
463463
464464
*s*
465-
a :class:`matplotlib.text.Text` instance
465+
the text string
466466
467467
*prop*
468468
a :class:`matplotlib.font_manager.FontProperties` instance
469469
470470
*angle*
471471
the rotation angle in degrees
472472
473+
*mtext*
474+
a :class:`matplotlib.text.Text` instance
475+
473476
**backend implementers note**
474477
475478
When you are trying to determine if you have gotten your bounding box

lib/matplotlib/backends/backend_agg.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ def draw_mathtext(self, gc, x, y, s, prop, angle):
158158
y = int(y) - oy
159159
self._renderer.draw_text_image(font_image, x, y + 1, angle, gc)
160160

161-
def draw_text(self, gc, x, y, s, prop, angle, ismath):
161+
def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
162162
"""
163163
Render the text
164164
"""
@@ -215,7 +215,7 @@ def get_text_width_height_descent(self, s, prop, ismath):
215215
return w, h, d
216216

217217

218-
def draw_tex(self, gc, x, y, s, prop, angle):
218+
def draw_tex(self, gc, x, y, s, prop, angle, ismath='TeX!', mtext=None):
219219
# todo, handle props, angle, origins
220220
size = prop.get_size_in_points()
221221

lib/matplotlib/backends/backend_cairo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ def draw_image(self, gc, x, y, im):
177177

178178
im.flipud_out()
179179

180-
def draw_text(self, gc, x, y, s, prop, angle, ismath=False):
180+
def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
181181
# Note: x,y are device/display coords, not user-coords, unlike other
182182
# draw_* methods
183183
if _debug: print('%s.%s()' % (self.__class__.__name__, _fn_name()))

lib/matplotlib/backends/backend_emf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ def draw_rectangle(self, gcEdge, rgbFace, x, y, width, height):
358358
if debugPrint: print("draw_rectangle: optimizing away (%f,%f) w=%f,h=%f" % (x,y,width,height))
359359

360360

361-
def draw_text(self, gc, x, y, s, prop, angle, ismath=False):
361+
def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
362362
"""
363363
Draw the text.Text instance s at x,y (display coords) with font
364364
properties instance prop at angle in degrees, using GraphicsContext gc

lib/matplotlib/backends/backend_gdk.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ def draw_image(self, gc, x, y, im):
138138
im.flipud_out()
139139

140140

141-
def draw_text(self, gc, x, y, s, prop, angle, ismath):
141+
def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
142142
x, y = int(x), int(y)
143143

144144
if x < 0 or y < 0: # window has shrunk and text is off the edge

lib/matplotlib/backends/backend_macosx.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def draw_image(self, gc, x, y, im):
111111
*gc.get_clip_path())
112112
im.flipud_out()
113113

114-
def draw_tex(self, gc, x, y, s, prop, angle):
114+
def draw_tex(self, gc, x, y, s, prop, angle, ismath='TeX!', mtext=None):
115115
# todo, handle props, angle, origins
116116
size = prop.get_size_in_points()
117117
texmanager = self.get_texmanager()
@@ -128,7 +128,7 @@ def _draw_mathtext(self, gc, x, y, s, prop, angle):
128128
self.mathtext_parser.parse(s, self.dpi, prop)
129129
gc.draw_mathtext(x, y, angle, 255 - image.as_array())
130130

131-
def draw_text(self, gc, x, y, s, prop, angle, ismath=False):
131+
def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
132132
if ismath:
133133
self._draw_mathtext(gc, x, y, s, prop, angle)
134134
else:

lib/matplotlib/backends/backend_pdf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1671,7 +1671,7 @@ def draw_mathtext(self, gc, x, y, s, prop, angle):
16711671
# Pop off the global transformation
16721672
self.file.output(Op.grestore)
16731673

1674-
def draw_tex(self, gc, x, y, s, prop, angle):
1674+
def draw_tex(self, gc, x, y, s, prop, angle, ismath='TeX!', mtext=None):
16751675
texmanager = self.get_texmanager()
16761676
fontsize = prop.get_size_in_points()
16771677
dvifile = texmanager.make_dvi(s, fontsize)
@@ -1763,7 +1763,7 @@ def encode_string(self, s, fonttype):
17631763
return s.encode('cp1252', 'replace')
17641764
return s.encode('utf-16be', 'replace')
17651765

1766-
def draw_text(self, gc, x, y, s, prop, angle, ismath=False):
1766+
def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
17671767
# TODO: combine consecutive texts into one BT/ET delimited section
17681768

17691769
# This function is rather complex, since there is no way to

lib/matplotlib/backends/backend_pgf.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -595,10 +595,10 @@ def draw_image(self, gc, x, y, im):
595595
writeln(self.fh, r"\pgftext[at=\pgfqpoint{%fin}{%fin},left,bottom]{\pgfimage[interpolate=true,width=%fin,height=%fin]{%s}}" % (x * f, y * f, w * f, h * f, fname_img))
596596
writeln(self.fh, r"\end{pgfscope}")
597597

598-
def draw_tex(self, gc, x, y, s, prop, angle, ismath="TeX!"):
599-
self.draw_text(gc, x, y, s, prop, angle, ismath)
598+
def draw_tex(self, gc, x, y, s, prop, angle, ismath="TeX!", mtext=None):
599+
self.draw_text(gc, x, y, s, prop, angle, ismath, mtext)
600600

601-
def draw_text(self, gc, x, y, s, prop, angle, ismath=False):
601+
def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
602602
s = common_texification(s)
603603

604604
# apply font properties

lib/matplotlib/backends/backend_ps.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,7 @@ def draw_path_collection(self, gc, master_transform, paths, all_transforms,
649649

650650
self._path_collection_id += 1
651651

652-
def draw_tex(self, gc, x, y, s, prop, angle, ismath='TeX!'):
652+
def draw_tex(self, gc, x, y, s, prop, angle, ismath='TeX!', mtext=None):
653653
"""
654654
draw a Text instance
655655
"""
@@ -684,7 +684,7 @@ def draw_tex(self, gc, x, y, s, prop, angle, ismath='TeX!'):
684684
self._pswriter.write(ps)
685685
self.textcnt += 1
686686

687-
def draw_text(self, gc, x, y, s, prop, angle, ismath):
687+
def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
688688
"""
689689
draw a Text instance
690690
"""

0 commit comments

Comments
 (0)