nx10 / httpgd

Asynchronous http server graphics device for R.
https://nx10.github.io/httpgd
GNU General Public License v2.0
377 stars 19 forks source link

Font handling is strange? #51

Closed psobolewskiPhD closed 3 years ago

psobolewskiPhD commented 3 years ago

I originally reported this as an issue with the {sftheme} https://github.com/amirmasoudabdol/sfthemes/issues/3 This is occurring with When using this theme that uses the Inter family of fonts, everything works well, except for a strange issue where ggplot legend title doesn't respect the font settings. The wrong face is used for the bold legend title in VS Code WebView or in Chrome, as well as when saved to png. (Incidentally, in Mac OS Safari I don't get any of the text elements in Inter...) plot Here's the output from ggsave(): test

I have the whole Inter family installed, MacOS Big Sur, M1, using {systemfonts} and {extrafont} if that helps.

nx10 commented 3 years ago

Thank you for reporting, I will look into it.

nx10 commented 3 years ago

I just updated the font handling can you try the newest development version from github?

Plots do look a bit broken for me with that package on any graphics device:

image

(This is with the R studio GD)

psobolewskiPhD commented 3 years ago

On my end, the test plot

ggplot(mtcars) +
   geom_point(aes(x = wt, y = mpg, colour = factor(gear))) +
   labs(title = "Fuel Economy",
        subtitle = "Fuel economy declines as weight increases, 1973-74",
        caption = "Data from the 1974 Motor Trend US magazine.",
        x = "Weight (1000 lbs)",
        y = "MPG",
        colour = "Gears") +
   facet_grid(vs ~ am) +
   sf_set_inter(theme_linedraw()) +
   scale_colour_ios_light()

looks correct in VS Code (and Chrome) plot This is with the save to PNG in httpgd. Resolution lower than ggsave() but the font handling appears correct and the behavior is proper with (+)/zoom.

BTW in Safari now the fonts are even more interesting: plot-2 The font is not respected anywhere but the Legend title?

nx10 commented 3 years ago

Can you attach the SVG file?

psobolewskiPhD commented 3 years ago

Here's the dark theme with bumping the font size up: PNG from VS Code (using the icon in httpgd) plot SVG from safari (zipped, apparently not supported by GitHub) plot-2.svg.zip

PNG from Safari (using the icon in httpgd) plot-3

nx10 commented 3 years ago

It seems like Safari can not find the "Inter" font on your computer. Have you tried restarting your computer? You can also embed it into the SVGs if you start httpgd with:

hgd(extra_css = "@import url('https://fonts.googleapis.com/css2?family=Inter&display=swap');")
psobolewskiPhD commented 3 years ago

So doing: httpgd::hgd(extra_css = "@import url('https://fonts.googleapis.com/css2?family=Inter&display=swap');") gives me a blank screen in VS Code and Safari and Chrome... I'm pretty sure I've restarted numerous times since installing Inter, but probably not since installing the sfthemes and httpgd? Can't be sure..

psobolewskiPhD commented 3 years ago

I'm going to restart VS Code et al. and see what that does. (sometimes I still get the blank canvas in httpgd randomly).

nx10 commented 3 years ago

If you have used the script of Kun Ren for using httpgd in vscode, make sure to add the extra_css argument to the hgd(..., extra_css = ...) call in your .Rprofile

The blank screen issue is most likely this https://github.com/nx10/httpgd/issues/50 bug in R itself which will be fixed in the upcoming R version.

psobolewskiPhD commented 3 years ago

OK! I'll try that—will it make all plots render with Inter? I actually prefer Fira, just noticed this strange issue with this theme that uses Inter... Edit: using {firatheme} which is my default Safari also doesn't render it. Chrome is fine, likewise when switching back to Inter.

nx10 commented 3 years ago

The extra_css argument will just include an URL for Inter as a source in all plots, in case that font is used but not available.

psobolewskiPhD commented 3 years ago

Thanks for the info. Honestly, I never use Safari for this stuff, just VS Code and the issues seem resolved there. I rather control the font in the theme/ggplot call and not at the .Rprofile level, so I think the current behavior is fine. Now I'm getting broken PDFs generated via ggsave() with this {sftheme} so something else seems to be an issue...

nx10 commented 3 years ago

Thank you for for your reports, yes it does seem like sftheme is a bit unstable at the moment. Glad it works as expected in vscode now!

psobolewskiPhD commented 3 years ago

No no, thank you for httpgd which is legit awesome and for being patient with me and my crappy issues!