1

Plots rendered through svglite look differently when rendered through Travis, then when rendered locally.

This happens, because my local machine (macOS in this case) aliases different (more standard?) fonts for the default R plots

gdtools::match_family("Arial")
## [1] "Arial"
gdtools::match_family("sans")
## [1] "Bitstream Vera Sans"

... than travis ci:

gdtools::match_family("Arial")
## [1] "Liberation Sans"
gdtools::match_family("sans")
## [1] "DejaVu Sans"

"Liberation Sans", in turn, is not necessarily available on all computers viewing the svg (it wasn't on mine, until I ran brew cask install font-liberation-sans).

So, while the locally-generated SVGs have pretty decent portability (~"Arial"), the TravisCI-generated (~"Liberation Sans") do not.

I'd like rock-solid portability that works on every computer with a reasonable current browser. I understand from svglite fonts vignette that I should probably use User font aliases to accomplish this, but I have not managed to get it to work, and am pretty confused about the whole font businesses.

I just want SVGs from svglite that look the same everywhere.

Here's the boilerplate index.Rmd that creates the different plots.

---
title: "index"
author: "foo"
date: "11/2/2018"
output:
  rmarkdown::html_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```

# `png` Device

```{r png, echo=FALSE, dev = 'png'}
plot(pressure)
```


# `svg` Device

```{r svg, echo=FALSE, dev = 'svg'}
plot(pressure)
```


# `svglite` Device

```{r svglite, echo=FALSE, dev = 'svglite'}
plot(pressure)
```

(The entire repo and travis builds is here, finished website is at http://datascience.phil.fau.de/rmdbpl/).

When rendered locally (macOS) all three plots look roughly the same:

rendered locally

When build on Travis CI, the plot rendered through svglite, viewed on a machine without "Liberation Sans" will substitute a serif fonts, which looks bad.

travis

hrbrmstr
  • 77,368
  • 11
  • 139
  • 205
maxheld
  • 3,963
  • 2
  • 32
  • 51
  • if anyone has enough points to add an `svglite` tag to this question, that'd be great. – maxheld Nov 25 '18 at 13:59
  • 1
    Max of 5 tags regardless of rep – hrbrmstr Nov 25 '18 at 14:09
  • 1
    Have you tried adding `gdtools::match_family("Arial")` to an R code block in the Rmd and seeing what it says? Also, have you tried installing any OS font packages (Travis-CI base builds are pretty bare-bones) – hrbrmstr Nov 25 '18 at 14:21
  • @hrbrmstr ah, yes of course – I cut it down to 4 tags, one available for `svglite` now. – maxheld Nov 25 '18 at 15:39
  • @hrbrmstr great idea, thanks, hadn't thought about it. Updated in the above, but it doesn't seem like the root of the problem to me, b/c all aliases look pretty sans-serif. But I don't get all this font business, so I might be wrong. – maxheld Nov 25 '18 at 15:41
  • 1
    Ah, so I'm wondering, now, if you're viewing the svglite-generated document on a system _without_ Liberation Sans. What happens if you install https://www.fontsquirrel.com/fonts/liberation-sans on the OS you're viewing the generated HTML document from? – hrbrmstr Nov 25 '18 at 16:00
  • yikes, yes, that solves the problem (on my machine), thanks @hrbrmstr, but still doesn't exactly make the svg portable. Going to update the question accordingly. – maxheld Nov 25 '18 at 18:34
  • Right. You'll need to specify an actual font like "Helvetica" which is more universal and ensure Helvetica is installed in your travis config – hrbrmstr Nov 25 '18 at 18:58

0 Answers0