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