|
30 | 30 | from matplotlib.cbook import is_string_like, maxdict |
31 | 31 | from matplotlib.figure import Figure |
32 | 32 | 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 |
34 | 34 | from matplotlib.mathtext import MathTextParser |
35 | 35 | from matplotlib.path import Path |
36 | 36 | from matplotlib.transforms import Bbox, BboxBase |
@@ -69,6 +69,12 @@ def __init__(self, width, height, dpi): |
69 | 69 | if __debug__: verbose.report('RendererAgg.__init__ done', |
70 | 70 | 'debug-annoying') |
71 | 71 |
|
| 72 | + def _get_hinting_flag(self): |
| 73 | + if rcParams['text.hinting']: |
| 74 | + return LOAD_FORCE_AUTOHINT |
| 75 | + else: |
| 76 | + return LOAD_NO_HINTING |
| 77 | + |
72 | 78 | def draw_markers(self, *kl, **kw): |
73 | 79 | # for filtering to work with rastrization, methods needs to be wrapped. |
74 | 80 | # maybe there is better way to do it. |
@@ -132,14 +138,15 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath): |
132 | 138 | if ismath: |
133 | 139 | return self.draw_mathtext(gc, x, y, s, prop, angle) |
134 | 140 |
|
| 141 | + flags = self._get_hinting_flag() |
135 | 142 | font = self._get_agg_font(prop) |
136 | 143 | if font is None: return None |
137 | 144 | 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) |
139 | 146 | else: |
140 | 147 | # We pass '0' for angle here, since it will be rotated (in raster |
141 | 148 | # 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) |
143 | 150 | font.draw_glyphs_to_bitmap() |
144 | 151 |
|
145 | 152 | #print x, y, int(x), int(y), s |
@@ -168,8 +175,10 @@ def get_text_width_height_descent(self, s, prop, ismath): |
168 | 175 | ox, oy, width, height, descent, fonts, used_characters = \ |
169 | 176 | self.mathtext_parser.parse(s, self.dpi, prop) |
170 | 177 | return width, height, descent |
| 178 | + |
| 179 | + flags = self._get_hinting_flag() |
171 | 180 | 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 |
173 | 182 | w, h = font.get_width_height() |
174 | 183 | d = font.get_descent() |
175 | 184 | w /= 64.0 # convert from subpixels |
|
0 commit comments