Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Propagate mpl.text.Text instances to the backends and fix documentation#1081

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
dmcdougall merged 5 commits intomatplotlib:masterfrompwuertz:draw_text_with_mtext
Nov 30, 2012
Merged
Show file tree
Hide file tree
Changes from1 commit
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
NextNext commit
propagate mpl.text.Text instances to backends, fix documentation
  • Loading branch information
@pwuertz
pwuertz authored andpwuertz committedNov 27, 2012
commit347c408adc48f7d88a9c16dd91fabf433dd70e7c
5 changes: 5 additions & 0 deletionsCHANGELOG
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
2012-11-27 Added the *mtext* parameter for supplying matplotlib.text.Text
instances to RendererBase.draw_tex and RendererBase.draw_text.
This allows backends to utilize additional text attributes, like
the alignment of text elements. - pwuertz

2012-11-16 plt.set_cmap no longer throws errors if there is not already
an active colorable artist, such as an image, and just sets
up the colormap to use from that point forward. - PI
Expand Down
9 changes: 6 additions & 3 deletionslib/matplotlib/backend_bases.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -443,12 +443,12 @@ def option_scale_image(self):
"""
return False

def draw_tex(self, gc, x, y, s, prop, angle, ismath='TeX!'):
def draw_tex(self, gc, x, y, s, prop, angle, ismath='TeX!', mtext=None):
"""
"""
self._draw_text_as_path(gc, x, y, s, prop, angle, ismath="TeX")

def draw_text(self, gc, x, y, s, prop, angle, ismath=False):
def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
"""
Draw the text instance

Expand All@@ -462,14 +462,17 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath=False):
the y location of the text in display coords

*s*
a :class:`matplotlib.text.Text` instance
thetext string

*prop*
a :class:`matplotlib.font_manager.FontProperties` instance

*angle*
the rotation angle in degrees

*mtext*
a :class:`matplotlib.text.Text` instance

**backend implementers note**

When you are trying to determine if you have gotten your bounding box
Expand Down
4 changes: 2 additions & 2 deletionslib/matplotlib/backends/backend_agg.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -158,7 +158,7 @@ def draw_mathtext(self, gc, x, y, s, prop, angle):
y = int(y) - oy
self._renderer.draw_text_image(font_image, x, y + 1, angle, gc)

def draw_text(self, gc, x, y, s, prop, angle, ismath):
def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
"""
Render the text
"""
Expand DownExpand Up@@ -215,7 +215,7 @@ def get_text_width_height_descent(self, s, prop, ismath):
return w, h, d


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

Expand Down
2 changes: 1 addition & 1 deletionlib/matplotlib/backends/backend_cairo.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -177,7 +177,7 @@ def draw_image(self, gc, x, y, im):

im.flipud_out()

def draw_text(self, gc, x, y, s, prop, angle, ismath=False):
def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
# Note: x,y are device/display coords, not user-coords, unlike other
# draw_* methods
if _debug: print('%s.%s()' % (self.__class__.__name__, _fn_name()))
Expand Down
2 changes: 1 addition & 1 deletionlib/matplotlib/backends/backend_emf.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -358,7 +358,7 @@ def draw_rectangle(self, gcEdge, rgbFace, x, y, width, height):
if debugPrint: print("draw_rectangle: optimizing away (%f,%f) w=%f,h=%f" % (x,y,width,height))


def draw_text(self, gc, x, y, s, prop, angle, ismath=False):
def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
"""
Draw the text.Text instance s at x,y (display coords) with font
properties instance prop at angle in degrees, using GraphicsContext gc
Expand Down
2 changes: 1 addition & 1 deletionlib/matplotlib/backends/backend_gdk.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -138,7 +138,7 @@ def draw_image(self, gc, x, y, im):
im.flipud_out()


def draw_text(self, gc, x, y, s, prop, angle, ismath):
def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
x, y = int(x), int(y)

if x < 0 or y < 0: # window has shrunk and text is off the edge
Expand Down
4 changes: 2 additions & 2 deletionslib/matplotlib/backends/backend_macosx.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -111,7 +111,7 @@ def draw_image(self, gc, x, y, im):
*gc.get_clip_path())
im.flipud_out()

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

def draw_text(self, gc, x, y, s, prop, angle, ismath=False):
def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
if ismath:
self._draw_mathtext(gc, x, y, s, prop, angle)
else:
Expand Down
4 changes: 2 additions & 2 deletionslib/matplotlib/backends/backend_pdf.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1671,7 +1671,7 @@ def draw_mathtext(self, gc, x, y, s, prop, angle):
# Pop off the global transformation
self.file.output(Op.grestore)

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

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

# This function is rather complex, since there is no way to
Expand Down
6 changes: 3 additions & 3 deletionslib/matplotlib/backends/backend_pgf.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -595,10 +595,10 @@ def draw_image(self, gc, x, y, im):
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))
writeln(self.fh, r"\end{pgfscope}")

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

def draw_text(self, gc, x, y, s, prop, angle, ismath=False):
def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
s = common_texification(s)

# apply font properties
Expand Down
4 changes: 2 additions & 2 deletionslib/matplotlib/backends/backend_ps.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -649,7 +649,7 @@ def draw_path_collection(self, gc, master_transform, paths, all_transforms,

self._path_collection_id += 1

def draw_tex(self, gc, x, y, s, prop, angle, ismath='TeX!'):
def draw_tex(self, gc, x, y, s, prop, angle, ismath='TeX!', mtext=None):
"""
draw a Text instance
"""
Expand DownExpand Up@@ -684,7 +684,7 @@ def draw_tex(self, gc, x, y, s, prop, angle, ismath='TeX!'):
self._pswriter.write(ps)
self.textcnt += 1

def draw_text(self, gc, x, y, s, prop, angle, ismath):
def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
"""
draw a Text instance
"""
Expand Down
4 changes: 2 additions & 2 deletionslib/matplotlib/backends/backend_svg.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1053,10 +1053,10 @@ def _draw_text_as_text(self, gc, x, y, s, prop, angle, ismath):

writer.end(u'g')

def draw_tex(self, gc, x, y, s, prop, angle):
def draw_tex(self, gc, x, y, s, prop, angle, ismath='TeX!', mtext=None):
self._draw_text_as_path(gc, x, y, s, prop, angle, ismath="TeX")

def draw_text(self, gc, x, y, s, prop, angle, ismath):
def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
clipid = self._get_clip(gc)
if clipid is not None:
# Cannot apply clip-path directly to the text, because
Expand Down
2 changes: 1 addition & 1 deletionlib/matplotlib/backends/backend_template.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -104,7 +104,7 @@ def draw_path(self, gc, path, transform, rgbFace=None):
def draw_image(self, gc, x, y, im):
pass

def draw_text(self, gc, x, y, s, prop, angle, ismath=False):
def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
pass

def flipy(self):
Expand Down
6 changes: 1 addition & 5 deletionslib/matplotlib/backends/backend_wx.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -361,11 +361,7 @@ def draw_image(self, gc, x, y, im):
gc.gfx_ctx.DrawBitmap(bitmap,int(l),int(self.height-b),int(w),int(-h))
gc.unselect()

def draw_text(self, gc, x, y, s, prop, angle, ismath):
"""
Render the matplotlib.text.Text instance
None)
"""
def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
if ismath: s = self.strip_math(s)
DEBUG_MSG("draw_text()", 1, self)
gc.select()
Expand Down
9 changes: 5 additions & 4 deletionslib/matplotlib/text.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -585,10 +585,11 @@ def draw(self, renderer):
if self.get_path_effects():
for path_effect in self.get_path_effects():
path_effect.draw_tex(renderer, gc, x, y, clean_line,
self._fontproperties, angle)
self._fontproperties, angle,
mtext=self)
else:
renderer.draw_tex(gc, x, y, clean_line,
self._fontproperties, angle)
self._fontproperties, angle, mtext=self)
else:
for line, wh, x, y in info:
if not np.isfinite(x) or not np.isfinite(y):
Expand All@@ -604,11 +605,11 @@ def draw(self, renderer):
for path_effect in self.get_path_effects():
path_effect.draw_text(renderer, gc, x, y, clean_line,
self._fontproperties, angle,
ismath=ismath)
ismath=ismath, mtext=self)
else:
renderer.draw_text(gc, x, y, clean_line,
self._fontproperties, angle,
ismath=ismath)
ismath=ismath, mtext=self)

gc.restore()
renderer.close_group('text')
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp