8000 Backport PR #19719: Respect antialiasing settings in cairo backends a… · matplotlib/matplotlib@daadab5 · GitHub
[go: up one dir, main page]

Skip to content

Commit daadab5

Browse files
timhoffmmeeseeksmachine
authored andcommitted
Backport PR #19719: Respect antialiasing settings in cairo backends as well.
1 parent cb03754 commit daadab5

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

lib/matplotlib/backends/backend_cairo.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"cairo backend requires that pycairo>=1.11.0 or cairocffi "
2525
"is installed") from err
2626

27+
import matplotlib as mpl
2728
from .. import _api, cbook, font_manager
2829
from matplotlib.backend_bases import (
2930
_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):
243244
ctx.new_path()
244245
ctx.move_to(x, y)
245246

246-
ctx.select_font_face(*_cairo_font_args_from_font_prop(prop))
247247
ctx.save()
248+
ctx.select_font_face(*_cairo_font_args_from_font_prop(prop))
248249
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)
249255
if angle:
250256
ctx.rotate(np.deg2rad(-angle))
251257
ctx.show_text(s)
@@ -348,9 +354,9 @@ def set_alpha(self, alpha):
348354
else:
349355
self.ctx.set_source_rgba(rgb[0], rgb[1], rgb[2], rgb[3])
350356

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)
354360

355361
def set_capstyle(self, cs):
356362
self.ctx.set_line_cap(_api.check_getitem(self._capd, capstyle=cs))

matplotlibrc.template

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@
326326
# unchanged. Set to 6 to obtain previous behavior. Values
327327
# other than 0 or 6 have no defined meaning.
328328
#text.antialiased: True # If True (default), the text will be antialiased.
329-
# This only affects the Agg backend.
329+
# This only affects raster outputs.
330330

331331
## The following settings allow you to select the fonts in math mode.
332332
#mathtext.fontset: dejavusans # Should be 'dejavusans' (default),

0 commit comments

Comments
 (0)
0