title: Extrafont and ggsave: Characters end up on top of another
body: <p>I'm currently trying to use Arial.ttf in all my plots. I have found several manuals about fonts online, I'm however running into issues when I try to save the pot via ggsave and the default device.</p>
  
  <h1>Minimal working example</h1>
  
  <p>I'm running the following minimal working example to reproduce this bug:</p>
  
  <pre><code>Sys.setenv(R_GSCMD="D:/gs/bin/gswin64c.exe")
  
  library(ggplot2)
  
  require(extrafont)
  font_import(prompt = F, pattern = "arial.ttf")
  font_import(prompt = F, pattern = "JOKERMAN.TTF")
  loadfonts(device="win", quiet = T)
  loadfonts(device="pdf", quiet = T)
  
  plot &lt;- ggplot(mtcars, aes(wt, mpg, colour = hp)) + geom_point()
  jokerman_plot &lt;- plot + theme_bw(base_family = "Jokerman")
  arial_plot &lt;- plot + theme_bw(base_family = "Arial")
  
  ggsave("arial_plot.png", arial_plot)
  ggsave("arial_plot.pdf", arial_plot)
  embed_fonts("arial_plot.pdf")
  
  ggsave("jokerman_plot.png", jokerman_plot)
  ggsave("jokerman_plot.pdf", jokerman_plot)
  embed_fonts("jokerman_plot.pdf")
  </code></pre>
  
  <p>This results in the following (correct) PNG images:</p>
  
  <p><a href="https://i.stack.imgur.com/1vSW7.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1vSW7.png" alt="Correct arial plot"></a> <a href="https://i.stack.imgur.com/3sTp3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3sTp3.png" alt="Correct Jokerman plot"></a></p>
  
  <p>The Arial PDF, however, has all characters stacked on top of each other (the Jokerman PDF renders correct):</p>
  
  <p><a href="https://i.stack.imgur.com/mhtXY.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/mhtXY.png" alt="Jumbled plot"></a></p>
  
  <h1>Warning output</h1>
  
  <p>The following warning messages are generated by this script.</p>
  
  <pre><code>Warning messages:
  1: In grid.Call(L_textBounds, as.graphicsAnnot(x$label),  ... :
    font width unknown for character 0x68
  2: In grid.Call(L_textBounds, as.graphicsAnnot(x$label),  ... :
    font width unknown for character 0x70
  3: In grid.Call(L_textBounds, as.graphicsAnnot(x$label),  ... :
    font metrics unknown for character 0x4d
  4: In grid.Call(L_textBounds, as.graphicsAnnot(x$label),  ... :
    font width unknown for character 0x68
  5: In grid.Call(L_textBounds, as.graphicsAnnot(x$label),  ... :
    font width unknown for character 0x70
  6: In grid.Call(L_textBounds, as.graphicsAnnot(x$label),  ... :
    font width unknown for character 0x4e
  7: In grid.Call(L_textBounds, as.graphicsAnnot(x$label),  ... :
    font width unknown for character 0x41
  8: In grid.Call(L_textBounds, as.graphicsAnnot(x$label),  ... :
    font metrics unknown for character 0x4d
  9: In grid.Call(L_textBounds, as.graphicsAnnot(x$label),  ... :
    font width unknown for character 0x31
  10: In grid.Call(L_textBounds, as.graphicsAnnot(x$label),  ... :
    font width unknown for character 0x30
  11: In grid.Call(L_textBounds, as.graphicsAnnot(x$label),  ... :
    font width unknown for character 0x30
  12: In grid.Call(L_textBounds, as.graphicsAnnot(x$label),  ... :
    font width unknown for character 0x31
  13: In grid.Call(L_textBounds, as.graphicsAnnot(x$label),  ... :
    font width unknown for character 0x35
  14: In grid.Call(L_textBounds, as.graphicsAnnot(x$label),  ... :
    font width unknown for character 0x30
  15: In grid.Call(L_textBounds, as.graphicsAnnot(x$label),  ... :
    font width unknown for character 0x32
  16: In grid.Call(L_textBounds, as.graphicsAnnot(x$label),  ... :
    font width unknown for character 0x30
  17: In grid.Call(L_textBounds, as.graphicsAnnot(x$label),  ... :
    font width unknown for character 0x30
  18: In grid.Call(L_textBounds, as.graphicsAnnot(x$label),  ... :
    font width unknown for character 0x32
  19: In grid.Call(L_textBounds, as.graphicsAnnot(x$label),  ... :
    font width unknown for character 0x35
  20: In grid.Call(L_textBounds, as.graphicsAnnot(x$label),  ... :
    font width unknown for character 0x30
  21: In grid.Call(L_textBounds, as.graphicsAnnot(x$label),  ... :
    font width unknown for character 0x33
  22: In grid.Call(L_textBounds, as.graphicsAnnot(x$label),  ... :
    font width unknown for character 0x30
  23: In grid.Call(L_textBounds, as.graphicsAnnot(x$label),  ... :
    font width unknown for character 0x30
  24: In grid.Call(L_textBounds, as.graphicsAnnot(x$label),  ... :
    font width unknown for character 0x4e
  25: In grid.Call(L_textBounds, as.graphicsAnnot(x$label),  ... :
    font width unknown for character 0x41
  26: In grid.Call(L_textBounds, as.graphicsAnnot(x$label),  ... :
    font width unknown for character 0x4e
  27: In grid.Call(L_textBounds, as.graphicsAnnot(x$label),  ... :
    font width unknown for character 0x41
  28: In grid.Call(L_textBounds, as.graphicsAnnot(x$label),  ... :
    font width unknown for character 0x31
  29: In grid.Call(L_textBounds, as.graphicsAnnot(x$label),  ... :
    font width unknown for character 0x30
  30: In grid.Call(L_textBounds, as.graphicsAnnot(x$label),  ... :
    font width unknown for character 0x30
  31: In grid.Call(L_textBounds, as.graphicsAnnot(x$label),  ... :
    font width unknown for character 0x31
  32: In grid.Call(L_textBounds, as.graphicsAnnot(x$label),  ... :
    font width unknown for character 0x35
  33: In grid.Call(L_textBounds, as.graphicsAnnot(x$label),  ... :
    font width unknown for character 0x30
  34: In grid.Call(L_textBounds, as.graphicsAnnot(x$label),  ... :
    font width unknown for character 0x32
  35: In grid.Call(L_textBounds, as.graphicsAnnot(x$label),  ... :
    font width unknown for character 0x30
  36: In grid.Call(L_textBounds, as.graphicsAnnot(x$label),  ... :
    font width unknown for character 0x30
  37: In grid.Call(L_textBounds, as.graphicsAnnot(x$label),  ... :
    font width unknown for character 0x32
  38: In grid.Call(L_textBounds, as.graphicsAnnot(x$label),  ... :
    font width unknown for character 0x35
  39: In grid.Call(L_textBounds, as.graphicsAnnot(x$label),  ... :
    font width unknown for character 0x30
  40: In grid.Call(L_textBounds, as.graphicsAnnot(x$label),  ... :
    font width unknown for character 0x33
  41: In grid.Call(L_textBounds, as.graphicsAnnot(x$label),  ... :
    font width unknown for character 0x30
  42: In grid.Call(L_textBounds, as.graphicsAnnot(x$label),  ... :
    font width unknown for character 0x30
  43: In grid.Call(L_textBounds, as.graphicsAnnot(x$label),  ... :
    font width unknown for character 0x4e
  44: In grid.Call(L_textBounds, as.graphicsAnnot(x$label),  ... :
    font width unknown for character 0x41
  45: In grid.Call(L_textBounds, as.graphicsAnnot(x$label),  ... :
    font width unknown for character 0x6d
  46: In grid.Call(L_textBounds, as.graphicsAnnot(x$label),  ... :
    font width unknown for character 0x70
  47: In grid.Call(L_textBounds, as.graphicsAnnot(x$label),  ... :
    font width unknown for character 0x67
  48: In grid.Call(L_textBounds, as.graphicsAnnot(x$label),  ... :
    font metrics unknown for character 0x4d
  49: In grid.Call(L_textBounds, as.graphicsAnnot(x$label),  ... :
    font width unknown for character 0x6d
  50: In grid.Call(L_textBounds, as.graphicsAnnot(x$label),  ... :
    font width unknown for character 0x70
  </code></pre>
  
  <h1>Session info</h1>
  
  <p>My current <code>sessionInfo()</code></p>
  
  <pre><code>R version 3.3.0 (2016-05-03)
  Platform: x86_64-w64-mingw32/x64 (64-bit)
  Running under: Windows &gt;= 8 x64 (build 9200)
  
  locale:
  [1] LC_COLLATE=German_Germany.1252  LC_CTYPE=German_Germany.1252    LC_MONETARY=German_Germany.1252
  [4] LC_NUMERIC=C                    LC_TIME=German_Germany.1252    
  
  attached base packages:
  [1] stats     graphics  grDevices utils     datasets  methods   base     
  
  other attached packages:
  [1] extrafont_0.17      ggplot2_2.1.0       RevoUtilsMath_3.2.5
  
  loaded via a namespace (and not attached):
   [1] labeling_0.3     colorspace_1.2-6 scales_0.4.0     assertthat_0.1   plyr_1.8.3       tools_3.3.0     
   [7] gtable_0.2.0     ggthemes_3.0.3   Rcpp_0.12.5      extrafontdb_1.0  grid_3.3.0       digest_0.6.9    
  [13] Rttf2pt1_1.3.4   munsell_0.4.3  
  </code></pre>
  
  <h1>Attempted solutions</h1>
  
  <ul>
  <li>I've tried several ways of renaming the generated AMF files to no avail</li>
  <li>I've thought that maybe the encoding of my source file might matter, so I changed it to UTF-8 (no change)</li>
  <li>Resetting extrafontdb multiple times</li>
  <li>Reinstalling ghostscript multiple times</li>
  </ul>
  
  <h1>Workarounds</h1>
  
  <p>I have currently two workarounds, I would, however, prefer to use the "native" PDF device as configured in R or ggplot for portability sake</p>
  
  <ol>
  <li>Specify cairo_pdf as a device (This can cause secondary issues with output or some plots to render slightly different). The PDF is fine, so could this point to a bug in the default PDF device?</li>
  <li>Use PNG/bitmap output (I want to use the plots in print, so vector output is preferred)</li>
  <li>Rely on R using ArialMT as default. I'm not sure if ArialMT is exactly the same font as used in my (Latex) document, so I would like to specify to font explicitly.</li>
  </ol>