Revision: 5299
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=5299&view=rev
Author: dsdale
Date: 2008-05-29 06:54:04 -0700 (Thu, 29 May 2008)
Log Message:
-----------
fixed two bugs in texmanager: dvipng version comparison, and
another related to the addition of the get_gray method
Modified Paths:
--------------
branches/v0_91_maint/CHANGELOG
branches/v0_91_maint/lib/matplotlib/texmanager.py
Modified: branches/v0_91_maint/CHANGELOG
===================================================================
--- branches/v0_91_maint/CHANGELOG 2008-05-29 13:01:40 UTC (rev 5298)
+++ branches/v0_91_maint/CHANGELOG 2008-05-29 13:54:04 UTC (rev 5299)
@@ -1,3 +1,8 @@
+2008-05-29 Fixed two bugs in texmanager.py:
+ improved comparison of dvipng versions
+ fixed a bug introduced when get_grey method was added
+ - DSD
+
2008-05-29 Implement path clipping in SVG backend - MGD
2008-05-28 Fix crashing of PDFs in xpdf and ghostscript when two-byte
Modified: branches/v0_91_maint/lib/matplotlib/texmanager.py
===================================================================
--- branches/v0_91_maint/lib/matplotlib/texmanager.py 2008-05-29 13:01:40 UTC
(rev 5298)
+++ branches/v0_91_maint/lib/matplotlib/texmanager.py 2008-05-29 13:54:04 UTC
(rev 5299)
@@ -34,6 +34,7 @@
"""
import copy, glob, md5, os, shutil, sys, warnings
+import distutils.version
import numpy as npy
import matplotlib as mpl
from matplotlib import rcParams
@@ -44,14 +45,15 @@
if sys.platform.startswith('win'): cmd_split = '&'
else: cmd_split = ';'
-def get_dvipng_version():
+def dvipng_hack_alpha():
stdin, stdout = os.popen4('dvipng -version')
for line in stdout:
if line.startswith('dvipng '):
version = line.split()[-1]
mpl.verbose.report('Found dvipng version %s'% version,
'helpful')
- return version
+ version = distutils.version.LooseVersion(version)
+ return version < distutils.version.LooseVersion('1.6')
raise RuntimeError('Could not obtain dvipng version')
@@ -76,7 +78,7 @@
if not os.path.exists(texcache):
os.mkdir(texcache)
- dvipngVersion = get_dvipng_version()
+ _dvipng_hack_alpha = dvipng_hack_alpha()
# mappable cache of
rgba_arrayd = {}
@@ -332,8 +334,28 @@
pngfile = self.make_png(tex, fontsize, dpi)
X = readpng(os.path.join(self.texcache, pngfile))
- if (self.dvipngVersion < '1.6') or rcParams['text.dvipnghack']:
- # hack the alpha channel as described in comment above
+ if self._dvipng_hack_alpha or rcParams['text.dvipnghack']:
+ # hack the alpha channel
+ # dvipng assumed a constant background, whereas we want to
+ # overlay these rasters with antialiasing over arbitrary
+ # backgrounds that may have other figure elements under them.
+ # When you set dvipng -bg Transparent, it actually makes the
+ # alpha channel 1 and does the background compositing and
+ # antialiasing itself and puts the blended data in the rgb
+ # channels. So what we do is extract the alpha information
+ # from the red channel, which is a blend of the default dvipng
+ # background (white) and foreground (black). So the amount of
+ # red (or green or blue for that matter since white and black
+ # blend to a grayscale) is the alpha intensity. Once we
+ # extract the correct alpha information, we assign it to the
+ # alpha channel properly and let the users pick their rgb. In
+ # this way, we can overlay tex strings on arbitrary
+ # backgrounds with antialiasing
+ #
+ # red = alpha*red_foreground + (1-alpha)*red_background
+ #
+ # Since the foreground is black (0) and the background is
+ # white (1) this reduces to red = 1-alpha or alpha = 1-red
alpha = npy.sqrt(1-X[:,:,0])
else:
alpha = X[:,:,-1]
@@ -346,26 +368,6 @@
"""
Return tex string as an rgba array
"""
- # dvipng assumes a constant background, whereas we want to
- # overlay these rasters with antialiasing over arbitrary
- # backgrounds that may have other figure elements under them.
- # When you set dvipng -bg Transparent, it actually makes the
- # alpha channel 1 and does the background compositing and
- # antialiasing itself and puts the blended data in the rgb
- # channels. So what we do is extract the alpha information
- # from the red channel, which is a blend of the default dvipng
- # background (white) and foreground (black). So the amount of
- # red (or green or blue for that matter since white and black
- # blend to a grayscale) is the alpha intensity. Once we
- # extract the correct alpha information, we assign it to the
- # alpha channel properly and let the users pick their rgb. In
- # this way, we can overlay tex strings on arbitrary
- # backgrounds with antialiasing
- #
- # red = alpha*red_foreground + (1-alpha)*red_background
- #
- # Since the foreground is black (0) and the background is
- # white (1) this reduces to red = 1-alpha or alpha = 1-red
if not fontsize: fontsize = rcParams['font.size']
if not dpi: dpi = rcParams['savefig.dpi']
r,g,b = rgb
@@ -375,7 +377,7 @@
if Z is None:
alpha = self.get_grey(tex, fontsize, dpi)
- Z = npy.zeros((X.shape[0], X.shape[1], 4), npy.float)
+ Z = npy.zeros((alpha.shape[0], alpha.shape[1], 4), npy.float)
Z[:,:,0] = r
Z[:,:,1] = g
Z[:,:,2] = b
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: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Matplotlib-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins