Skip to content

Respect antialiasing settings in cairo backends as well. #19719

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions lib/matplotlib/backends/backend_cairo.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"cairo backend requires that pycairo>=1.11.0 or cairocffi "
"is installed") from err

import matplotlib as mpl
from .. import _api, cbook, font_manager
from matplotlib.backend_bases import (
_Backend, _check_savefig_extra_args, FigureCanvasBase, FigureManagerBase,
Expand Down Expand Up @@ -244,9 +245,14 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
ctx.new_path()
ctx.move_to(x, y)

ctx.select_font_face(*_cairo_font_args_from_font_prop(prop))
ctx.save()
ctx.select_font_face(*_cairo_font_args_from_font_prop(prop))
ctx.set_font_size(prop.get_size_in_points() * self.dpi / 72)
opts = cairo.FontOptions()
opts.set_antialias(
cairo.Antialias.DEFAULT if mpl.rcParams["text.antialiased"]
else cairo.Antialias.NONE)
ctx.set_font_options(opts)
if angle:
ctx.rotate(np.deg2rad(-angle))
ctx.show_text(s)
Expand Down Expand Up @@ -349,9 +355,9 @@ def set_alpha(self, alpha):
else:
self.ctx.set_source_rgba(rgb[0], rgb[1], rgb[2], rgb[3])

# def set_antialiased(self, b):
# cairo has many antialiasing modes, we need to pick one for True and
# one for False.
def set_antialiased(self, b):
self.ctx.set_antialias(
cairo.Antialias.DEFAULT if b else cairo.Antialias.NONE)

def set_capstyle(self, cs):
self.ctx.set_line_cap(_api.check_getitem(self._capd, capstyle=cs))
Expand Down
2 changes: 1 addition & 1 deletion matplotlibrc.template
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@
# unchanged. Set to 6 to obtain previous behavior. Values
# other than 0 or 6 have no defined meaning.
#text.antialiased: True # If True (default), the text will be antialiased.
# This only affects the Agg backend.
# This only affects raster outputs.

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