Skip to content
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

Added functionality to set the font family for the Cairo device #145

Open
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

casparvl
Copy link

@casparvl casparvl commented Sep 20, 2021

This PR partly solves IRkernel/IRkernel#604 .

As suggested in that issue, fonts for axes labels sometimes appear to have poor resolution. To resolve this, it is suggested in that issue to use the Cairo device, by setting options(bitmapType='Cairo') in the startup argv for the kernel (i.e. in the kernel.json).

This does indeed make sure that the Cairo device is used from that point onward. However, it will still use the default font. In my case that was a Helvetica, a (low-resolution) X11 font, and the resulting axes labels would still show the poor resolution.

The solution is to use a vector-type font, such as sans. The problem is that for png plot types with the Cairo device, the repr.plot.family is ignored.

This PR makes sure that the font family specified in repr.plot.family is indeed set to the Cairo devices.

I already suggested the change a long time ago but never found the time to make the change, test it, and PR it... In that thread, I proposed this approach to @flying-sheep who also considered it a good approach.

For me, with this PR, I can now do

options(repr.plot.width = 10, repr.plot.height = 8, repr.plot.res=96, repr.plot.family='FreeMono')

ggplot(iris) + geom_point(aes(Sepal.Width, Petal.Width)) + cowplot::theme_cowplot(
    font_size=25)

and get:
image
While with

options(repr.plot.family='LiberationMono')
ggplot(iris) + geom_point(aes(Sepal.Width, Petal.Width)) + cowplot::theme_cowplot(
    font_size=25)

I get
image

These samples clearly show that the repr.plot.family is now respected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants