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

Skip to content

Commit 77a00a7

Browse files
committed
Add an rcParam for hinting, and set it to False when running tests.
svn path=/trunk/matplotlib/; revision=7712
1 parent b010441 commit 77a00a7

8 files changed

Lines changed: 28 additions & 7 deletions

File tree

lib/matplotlib/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -893,6 +893,8 @@ def test(verbosity=0):
893893
from testing.noseclasses import KnownFailure
894894
from nose.plugins.manager import PluginManager
895895
use('Agg') # use Agg backend for these tests
896+
rcParams['font.family'] = 'Bitstream Vera Sans'
897+
rcParams['text.hinting'] = False
896898
plugins = []
897899
plugins.append( KnownFailure() )
898900
plugins.extend( [plugin() for plugin in nose.plugins.builtin.plugins] )

lib/matplotlib/backends/backend_agg.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
from matplotlib.cbook import is_string_like, maxdict
3131
from matplotlib.figure import Figure
3232
from matplotlib.font_manager import findfont
33-
from matplotlib.ft2font import FT2Font, LOAD_FORCE_AUTOHINT
33+
from matplotlib.ft2font import FT2Font, LOAD_FORCE_AUTOHINT, LOAD_NO_HINTING
3434
from matplotlib.mathtext import MathTextParser
3535
from matplotlib.path import Path
3636
from matplotlib.transforms import Bbox, BboxBase
@@ -69,6 +69,12 @@ def __init__(self, width, height, dpi):
6969
if __debug__: verbose.report('RendererAgg.__init__ done',
7070
'debug-annoying')
7171

72+
def _get_hinting_flag(self):
73+
if rcParams['text.hinting']:
74+
return LOAD_FORCE_AUTOHINT
75+
else:
76+
return LOAD_NO_HINTING
77+
7278
def draw_markers(self, *kl, **kw):
7379
# for filtering to work with rastrization, methods needs to be wrapped.
7480
# maybe there is better way to do it.
@@ -132,14 +138,15 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath):
132138
if ismath:
133139
return self.draw_mathtext(gc, x, y, s, prop, angle)
134140

141+
flags = self._get_hinting_flag()
135142
font = self._get_agg_font(prop)
136143
if font is None: return None
137144
if len(s) == 1 and ord(s) > 127:
138-
font.load_char(ord(s), flags=LOAD_FORCE_AUTOHINT)
145+
font.load_char(ord(s), flags=flags)
139146
else:
140147
# We pass '0' for angle here, since it will be rotated (in raster
141148
# space) in the following call to draw_text_image).
142-
font.set_text(s, 0, flags=LOAD_FORCE_AUTOHINT)
149+
font.set_text(s, 0, flags=flags)
143150
font.draw_glyphs_to_bitmap()
144151

145152
#print x, y, int(x), int(y), s
@@ -168,8 +175,10 @@ def get_text_width_height_descent(self, s, prop, ismath):
168175
ox, oy, width, height, descent, fonts, used_characters = \
169176
self.mathtext_parser.parse(s, self.dpi, prop)
170177
return width, height, descent
178+
179+
flags = self._get_hinting_flag()
171180
font = self._get_agg_font(prop)
172-
font.set_text(s, 0.0, flags=LOAD_FORCE_AUTOHINT) # the width and height of unrotated string
181+
font.set_text(s, 0.0, flags=flags) # the width and height of unrotated string
173182
w, h = font.get_width_height()
174183
d = font.get_descent()
175184
w /= 64.0 # convert from subpixels

lib/matplotlib/config/mplconfig.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ class font(TConfig):
154154
class text(TConfig):
155155
color = T.Trait('black',mplT.ColorHandler())
156156
usetex = T.false
157+
hinting = T.true
157158

158159
class latex(TConfig):
159160
unicode = T.false
@@ -338,6 +339,7 @@ def __init__(self, tconfig):
338339
'text.latex.unicode' : (self.tconfig.text.latex, 'unicode'),
339340
'text.latex.preamble' : (self.tconfig.text.latex, 'preamble'),
340341
'text.dvipnghack' : (self.tconfig.text.latex, 'dvipnghack'),
342+
'text.hinting' : (self.tconfig.text, 'hinting'),
341343

342344
'mathtext.cal' : (self.tconfig.mathtext, 'cal'),
343345
'mathtext.rm' : (self.tconfig.mathtext, 'rm'),

lib/matplotlib/config/rcsetup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,7 @@ def __call__(self, s):
361361
'text.fontvariant' : ['normal', str],
362362
'text.fontweight' : ['normal', str],
363363
'text.fontsize' : ['medium', validate_fontsize],
364+
'text.hinting' : [True, validate_bool],
364365

365366
'mathtext.cal' : ['cursive', validate_font_properties],
366367
'mathtext.rm' : ['serif', validate_font_properties],

lib/matplotlib/mathtext.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,10 @@ def get_results(self, box):
222222
self.fonts_object.get_used_characters())
223223

224224
def get_hinting_type(self):
225-
return LOAD_FORCE_AUTOHINT
225+
if rcParams['text.hinting']:
226+
return LOAD_FORCE_AUTOHINT
227+
else:
228+
return LOAD_NO_HINTING
226229

227230
def MathtextBackendAgg():
228231
return MathtextBackendBbox(MathtextBackendAggRender())

lib/matplotlib/rcsetup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,7 @@ def __call__(self, s):
404404
'text.fontvariant' : ['normal', str],
405405
'text.fontweight' : ['normal', str],
406406
'text.fontsize' : ['medium', validate_fontsize],
407+
'text.hinting' : [True, validate_bool],
407408

408409
'mathtext.cal' : ['cursive', validate_font_properties],
409410
'mathtext.rm' : ['serif', validate_font_properties],

lib/matplotlib/text.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
from matplotlib.path import Path
2727
import matplotlib.font_manager as font_manager
28-
from matplotlib.ft2font import FT2Font, KERNING_DEFAULT, LOAD_NO_HINTING
28+
from matplotlib.ft2font import FT2Font
2929

3030

3131
def _process_text_args(override, fontdict=None, **kwargs):

matplotlibrc.template

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,9 @@ backend : %(backend)s
167167
# In that case, all text will be sent to TeX for
168168
# processing.
169169

170+
#text.hinting : True # If True, text will be hinted, otherwise not. This only
171+
# affects the Agg backend.
172+
170173
# The following settings allow you to select the fonts in math mode.
171174
# They map from a TeX font name to a fontconfig font pattern.
172175
# These settings are only used if mathtext.fontset is 'custom'.
@@ -290,7 +293,7 @@ backend : %(backend)s
290293
# A value of 20000 is probably a good
291294
# starting point.
292295
### SAVING FIGURES
293-
#path.simplify : False # When True, simplify paths by removing "invisible"
296+
#path.simplify : False # When True, simplify paths by removing "invisible"
294297
# points to reduce file size and increase rendering
295298
# speed
296299
#path.simplify_threshold : 0.1 # The threshold of similarity below which

0 commit comments

Comments
 (0)