httpgd
httpgd copied to clipboard
fonts not working on Linux
Hello,
I have been testing out R in VSCode and the fonts don't appear to be working properly (and appear to be a serifed font). I have seen #85, but unlike in that post, it does appear that the fonts are installed on the machine. The exported plots (I checked pdf and png) have the correct font, but Vscode/R/httpgd plot display does not. The problem occurs in both a "normal" R environment and a conda environment in Linux.
I have been through the httpgd documents, the svglite documentation, and systemfonts documentation (like the commenter in #85), but I'm not really sure where to start with this issue. Do you have any suggestions?
Editing to add that the plots are working properly locally (Mac), and that when I don't use httpgd when I'm working remotely (linux) the X window also displays the proper font.
Thanks! Jen
I have a same problem when using httpgd in a remote vscode server, but works fine in native vscode on windows/linux
Thanks for trying out httpgd and opening the issue!
Fonts are not embedded in the SVG so they have to be installed both on the server as well as locally.
If they are and it still does not work let us know
How can I find out what's the font that is missing? 🙈
You can look it up in the .SVG if you open it in a text editor. Otherwise you can attach it here then I will have a look.
I should maybe open a separate issue for this, but given {svglite} supports passing a URL for a @font-face declaration to the device's web_fonts argument, it would be great it we could supply that string to {httpgd} too.
I'm running a workshop using a VSCode dev container that will run in Codespaces, and I'd love to be able to supply a font that works as well in {httpgd}'s viewer as it does in rendered raster plots. Like the other commenters, I can't get fonts to appear in the viewer even if they're installed on both the container and my own system (they work great in the viewer if I use it on macOS natively).
The container I have set up is here: https://github.com/jimjam-slam/icuc11-workshop-dataviz/tree/main (you can launch it in Codespaces here).
The fonts are kept in .devcontainer and transfered to /usr/local/share/fonts in the container. .Rprofile then registers them with systemfonts::register_font to overwrite sans. ~~I'm assuming I also need to add something like this block in the VSCode-R Wiki~~ (nope, that's to open the web page in VSCode instead!).
I find that font support is unchanged even if I manually call hgd() with system_fonts or user_fonts supplied. It doesn't take the web_fonts argument, though, so maybe that's not surprising!
I'm running the VSCode R extension, which uses httpgd, and e.g:
r$> hist(c(1,2,3,1,2,3))
Warning message:
No fonts detected on your system. Using an empty font.
This doesn't happen when running the same line from a non-attached R repl.
This is macOS Sonoma, but I guess it's the same issue.
Fonts are not embedded in the SVG so they have to be installed both on the server as well as locally.
This works, to be clear, you have to go to the URL (in vscode there's an icon with a square and an arrow pointing to the top right above the plot), then inspect the page or otherwise access the SVG that you see displayed there. Open it in a text editor, you'll see a bunch of font-family attributes, which in my case were "DejaVu Sans" or "Nimbus Sans" (seemingly at random). I installed these fonts on my Mac, then rebooted, and it worked.
My setup: MacBook running VSCode, remote server with R extension running on remote with latest httpgd.
@nx10 I do not know if you are involved with the VS Code integration, but it would be nice to somehow expose the system_fonts argument to allow for some kind of mapping between sans and a font that already exists on the host.
I'm coming here to second @agilly's comment, which somehow was written in a way such that I finally understood... I tried for many hours to do all sorts of fancy things with system fonts, VS-Code settings, etc. In the end the solution for me was simple:
- Download the DejaVu Sans font or whatever is in the SVG if it's diferent for you) to my laptop, I downloaded the font from: https://www.fontsquirrel.com/fonts/dejavu-sans
- Install the DejaVu Sans font on my personal computer/laptop using the Font Book application (instructions: https://support.apple.com/guide/font-book/install-and-validate-fonts-fntbk1000/mac)
- Re-open the VSCode Instance.
I am utilizing a CodeServer instance via Open OnDemand. The job is handled via a slurm scheduler, the OS is Rocky9. My laptop/local computer is an Apple M1 operating under the Monterey OS.