|
24 | 24 | "cairo backend requires that pycairo>=1.11.0 or cairocffi " |
25 | 25 | "is installed") from err |
26 | 26 |
|
| 27 | +import matplotlib as mpl |
27 | 28 | from .. import _api, cbook, font_manager |
28 | 29 | from matplotlib.backend_bases import ( |
29 | 30 | _Backend, _check_savefig_extra_args, FigureCanvasBase, FigureManagerBase, |
@@ -243,9 +244,14 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None): |
243 | 244 | ctx.new_path() |
244 | 245 | ctx.move_to(x, y) |
245 | 246 |
|
246 | | - ctx.select_font_face(*_cairo_font_args_from_font_prop(prop)) |
247 | 247 | ctx.save() |
| 248 | + ctx.select_font_face(*_cairo_font_args_from_font_prop(prop)) |
248 | 249 | ctx.set_font_size(prop.get_size_in_points() * self.dpi / 72) |
| 250 | + opts = cairo.FontOptions() |
| 251 | + opts.set_antialias( |
| 252 | + cairo.Antialias.DEFAULT if mpl.rcParams["text.antialiased"] |
| 253 | + else cairo.Antialias.NONE) |
| 254 | + ctx.set_font_options(opts) |
249 | 255 | if angle: |
250 | 256 | ctx.rotate(np.deg2rad(-angle)) |
251 | 257 | ctx.show_text(s) |
@@ -348,9 +354,9 @@ def set_alpha(self, alpha): |
348 | 354 | else: |
349 | 355 | self.ctx.set_source_rgba(rgb[0], rgb[1], rgb[2], rgb[3]) |
350 | 356 |
|
351 | | - # def set_antialiased(self, b): |
352 | | - # cairo has many antialiasing modes, we need to pick one for True and |
353 | | - # one for False. |
| 357 | + def set_antialiased(self, b): |
| 358 | + self.ctx.set_antialias( |
| 359 | + cairo.Antialias.DEFAULT if b else cairo.Antialias.NONE) |
354 | 360 |
|
355 | 361 | def set_capstyle(self, cs): |
356 | 362 | self.ctx.set_line_cap(_api.check_getitem(self._capd, capstyle=cs)) |
|
0 commit comments