Revision: 6133
          http://matplotlib.svn.sourceforge.net/matplotlib/?rev=6133&view=rev
Author:   efiring
Date:     2008-09-29 07:06:28 +0000 (Mon, 29 Sep 2008)

Log Message:
-----------
Add dpi kwarg and docstring to Text.get_window_extent()

Modified Paths:
--------------
    trunk/matplotlib/lib/matplotlib/text.py

Modified: trunk/matplotlib/lib/matplotlib/text.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/text.py     2008-09-28 22:05:23 UTC (rev 
6132)
+++ trunk/matplotlib/lib/matplotlib/text.py     2008-09-29 07:06:28 UTC (rev 
6133)
@@ -166,7 +166,7 @@
         self._rotation = rotation
         self._fontproperties = fontproperties
         self._bbox = None
-        self._bbox_patch = None # a FanceBboxPatch instance
+        self._bbox_patch = None # a FancyBboxPatch instance
         self._renderer = None
         if linespacing is None:
             linespacing = 1.2   # Maybe use rcParam later.
@@ -356,7 +356,7 @@
 
     def get_bbox_patch(self):
         """
-        Retrun the bbox Patch object. Returns None if the the
+        Return the bbox Patch object. Returns None if the the
         FancyBboxPatch is not made.
         """
         return self._bbox_patch
@@ -519,9 +519,32 @@
         "Return the vertical alignment as string"
         return self._verticalalignment
 
-    def get_window_extent(self, renderer=None):
+    def get_window_extent(self, renderer=None, dpi=None):
+        '''
+        Return a Bbox bounding the text, in display units (dots).
+
+        In addition to being used internally,
+        this is useful for specifying clickable regions in
+        a png file on a web page.
+
+        *renderer* defaults to the _renderer attribute of the
+        text object.  This is not assigned until the first execution
+        of the draw() method, so you must use this kwarg if you
+        want to call get_window_extent() prior to the first draw().
+        For getting web page regions, it is simpler to call the
+        method after saving the figure.
+
+        *dpi* defaults to self.figure.dpi; the renderer dpi is
+        irrelevant.  For the web application, if figure.dpi is not
+        the value used when saving the figure, then the value that
+        was used must be specified as the *dpi* argument.
+
+        '''
         #return _unit_box
         if not self.get_visible(): return Bbox.unit()
+        if dpi is not None:
+            dpi_orig = self.figure.dpi
+            self.figure.dpi = dpi
         if self._text == '':
             tx, ty = self._get_xy_display()
             return Bbox.from_bounds(tx,ty,0,0)
@@ -531,11 +554,12 @@
         if self._renderer is None:
             raise RuntimeError('Cannot get window extent w/o renderer')
 
-        angle = self.get_rotation()
         bbox, info = self._get_layout(self._renderer)
         x, y = self.get_position()
         x, y = self.get_transform().transform_point((x, y))
         bbox = bbox.translated(x, y)
+        if dpi is not None:
+            self.figure.dpi = dpi_orig
         return bbox
 
     def set_backgroundcolor(self, color):


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Matplotlib-checkins mailing list
Matplotlib-checkins@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins

Reply via email to