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

Skip to content

Commit 44df377

Browse files
committed
added support for None for dvipng and removed the sqrt in the hack which I think is wrong
svn path=/branches/v0_91_maint/; revision=5329
1 parent 562ec2c commit 44df377

File tree

3 files changed

+28
-6
lines changed

3 files changed

+28
-6
lines changed

lib/matplotlib/rcsetup.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,16 @@ def validate_bool(b):
4242
else:
4343
raise ValueError('Could not convert "%s" to boolean' % b)
4444

45+
def validate_bool_maybe_none(b):
46+
'Convert b to a boolean or raise'
47+
if type(b) is str:
48+
b = b.lower()
49+
if b=='none': return None
50+
if b in ('t', 'y', 'yes', 'on', 'true', '1', 1, True): return True
51+
elif b in ('f', 'n', 'no', 'off', 'false', '0', 0, False): return False
52+
else:
53+
raise ValueError('Could not convert "%s" to boolean' % b)
54+
4555
def validate_float(s):
4656
'convert s to float or raise'
4757
try: return float(s)
@@ -339,7 +349,7 @@ def __call__(self, s):
339349
'text.usetex' : [False, validate_bool],
340350
'text.latex.unicode' : [False, validate_bool],
341351
'text.latex.preamble' : [[''], validate_stringlist],
342-
'text.dvipnghack' : [False, validate_bool],
352+
'text.dvipnghack' : [None, validate_bool_maybe_none],
343353
'text.fontstyle' : ['normal', str],
344354
'text.fontangle' : ['normal', str],
345355
'text.fontvariant' : ['normal', str],

lib/matplotlib/texmanager.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,12 @@ def get_grey(self, tex, fontsize=None, dpi=None):
334334
pngfile = self.make_png(tex, fontsize, dpi)
335335
X = readpng(os.path.join(self.texcache, pngfile))
336336

337-
if self._dvipng_hack_alpha or rcParams['text.dvipnghack']:
337+
if rcParams['text.dvipnghack'] is not None:
338+
hack = rcParams['text.dvipnghack']
339+
else:
340+
hack = self._dvipng_hack_alpha
341+
print 'using hack', hack
342+
if hack:
338343
# hack the alpha channel
339344
# dvipng assumed a constant background, whereas we want to
340345
# overlay these rasters with antialiasing over arbitrary
@@ -356,7 +361,9 @@ def get_grey(self, tex, fontsize=None, dpi=None):
356361
#
357362
# Since the foreground is black (0) and the background is
358363
# white (1) this reduces to red = 1-alpha or alpha = 1-red
359-
alpha = npy.sqrt(1-X[:,:,0])
364+
#alpha = npy.sqrt(1-X[:,:,0]) # should this be sqrt here?
365+
alpha = 1-X[:,:,0]
366+
360367
else:
361368
alpha = X[:,:,-1]
362369

matplotlibrc.template

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,14 @@ numerix : %(numerix)s # numpy, Numeric or numarray
147147
# beware of package collisions: color, geometry, graphicx,
148148
# type1cm, textcomp. Adobe Postscript (PSSNFS) font packages
149149
# may also be loaded, depending on your font settings
150-
#text.dvipnghack : False # some versions of dvipng don't handle
151-
# alpha channel properly. Use True to correct and flush
152-
# ~/.matplotlib/tex.cache before testing
150+
151+
#text.dvipnghack : None # some versions of dvipng don't handle alpha
152+
# channel properly. Use True to correct
153+
# and flush ~/.matplotlib/tex.cache
154+
# before testing and False to force
155+
# correction off. None will try and
156+
# guess based on your dvipng version
157+
153158
#text.markup : 'plain' # Affects how text, such as titles and labels, are
154159
# interpreted by default.
155160
# 'plain': As plain, unformatted text

0 commit comments

Comments
 (0)