|
From: <ef...@us...> - 2010-06-01 16:38:41
|
Revision: 8361
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=8361&view=rev
Author: efiring
Date: 2010-06-01 16:38:34 +0000 (Tue, 01 Jun 2010)
Log Message:
-----------
contour: Jouni's patch to close 2797414 and 3009921; clabel with mathtext
Modified Paths:
--------------
trunk/matplotlib/lib/matplotlib/contour.py
trunk/matplotlib/lib/matplotlib/text.py
Modified: trunk/matplotlib/lib/matplotlib/contour.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/contour.py 2010-06-01 03:11:39 UTC (rev 8360)
+++ trunk/matplotlib/lib/matplotlib/contour.py 2010-06-01 16:38:34 UTC (rev 8361)
@@ -17,6 +17,8 @@
import matplotlib.text as text
import matplotlib.cbook as cbook
import matplotlib.mlab as mlab
+import matplotlib.mathtext as mathtext
+import matplotlib.texmanager as texmanager
# Import needed for adding manual selection capability to clabel
from matplotlib.blocking_input import BlockingContourLabeler
@@ -268,10 +270,21 @@
def get_label_width(self, lev, fmt, fsize):
"get the width of the label in points"
- if cbook.is_string_like(lev):
+ if not cbook.is_string_like(lev):
+ lev = self.get_text(lev, fmt)
+
+ lev, ismath = text.Text.is_math_text(lev)
+ if ismath == 'TeX':
+ if not hasattr(self, '_TeX_manager'):
+ self._TeX_manager = texmanager.TexManager()
+ lw, _, _ = self._TeX_manager.get_text_width_height_descent(lev, fsize)
+ elif ismath:
+ if not hasattr(self, '_mathtext_parser'):
+ self._mathtext_parser = mathtext.MathTextParser('bitmap')
+ img, _ = self._mathtext_parser.parse(lev, dpi=72, prop=self.labelFontProps)
+ lw = img.get_width() # at dpi=72, the units are PostScript points
+ else:
lw = (len(lev)) * fsize
- else:
- lw = (len(self.get_text(lev,fmt))) * fsize
return lw
@@ -330,7 +343,7 @@
if xsize == 1:
ysize = nsize
else:
- ysize = labelwidth
+ ysize = int(labelwidth)
XX = np.resize(linecontour[:,0],(xsize, ysize))
YY = np.resize(linecontour[:,1],(xsize, ysize))
Modified: trunk/matplotlib/lib/matplotlib/text.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/text.py 2010-06-01 03:11:39 UTC (rev 8360)
+++ trunk/matplotlib/lib/matplotlib/text.py 2010-06-01 16:38:34 UTC (rev 8361)
@@ -963,9 +963,14 @@
"""
self._text = '%s' % (s,)
- def is_math_text(self, s):
+ @staticmethod
+ def is_math_text(s):
"""
- Returns True if the given string *s* contains any mathtext.
+ Returns a cleaned string and a boolean flag.
+ The flag indicates if the given string *s* contains any mathtext,
+ determined by counting unescaped dollar signs. If no mathtext
+ is present, the cleaned string has its dollar signs unescaped.
+ If usetex is on, the flag always has the value "TeX".
"""
# Did we find an even number of non-escaped dollar signs?
# If so, treat is as math text.
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|