wch / extrafont

Tools for using fonts in R graphics
313 stars 49 forks source link

Some (but not all) fonts work only in a bitmap device, not pdf #33

Open ellisp opened 10 years ago

ellisp commented 10 years ago

Edit - having looked more into this I find that in fact none of my pdfs correctly embed the fonts, it's just that in some cases a substitute font is used and in others pdf cannot find a font at all. So the issue is very likely something in my setup, and amounts to loadfonts() is not working for the pdf device. As this looks more like a straight "helpdesk" query I'm happy to have it dropped as an "issue" here.

I have successfully imported and loaded fonts and they all work fine in a Windows device or a png device, and some of them work in a pdf but not all do; either they return warnings and no text (Calibri) or cause an error and stop (eg Aharoni). The script at the bottom shows the problem is in about a third of my fonts.

The error message Aharoni gives when being used with a pdf is "Error in axis(side = side, at = at, labels = labels, ...) : invalid font type"

The warning message Calibri gives when being used with a pdf is multiple instances such as those below "27: In axis(side = side, at = at, labels = labels, ...) : font width unknown for character 0x30 28: In title(...) : font width unknown for character 0x41"

So, when I push something in Calibri to a pdf I get this: image

Whereas if I do the same to a png I get this: calibri

But the problem isn't that my pdf device is useless because some other fonts eg Georgia, Calisto MT, Castellar - just to pick at random - work fine.

library(extrafont)
loadfonts()

dir.create("testfonts")

f <- fonts()
for (i in 1:length(f)){
  pdf(paste0("testfonts/", f[i], ".pdf"))
    par(family=f[i])
    try(plot(1:10, 1:10, main=f[i]))
  dev.off()

 png(paste0("testfonts/", f[i], ".png"))
    par(family=f[i])
    try(plot(1:10, 1:10, main=f[i]))
  dev.off()
}

> sessionInfo()
R version 3.0.1 (2013-05-16)
Platform: x86_64-w64-mingw32/x64 (64-bit)

locale:
[1] LC_COLLATE=English_New Zealand.1252  LC_CTYPE=English_New Zealand.1252    LC_MONETARY=English_New Zealand.1252
[4] LC_NUMERIC=C                         LC_TIME=English_New Zealand.1252    

attached base packages:
[1] graphics  grDevices utils     datasets  grid      tcltk     stats     methods   base     

other attached packages:
[1] extrafont_0.14  mbie_0.5.0      zoo_1.7-10      proto_0.3-10    scales_0.2.3    plyr_1.8        reshape2_1.2.2 
[8] ggplot2_0.9.3.1

loaded via a namespace (and not attached):
 [1] colorspace_1.2-2   dichromat_2.0-0    digest_0.6.3       gtable_0.1.2       labeling_0.2       lattice_0.20-15   
 [7] MASS_7.3-26        munsell_0.4.2      RColorBrewer_1.0-5 Rttf2pt1_1.2       stringr_0.6.2      tools_3.0.1 
Lukas-1 commented 9 years ago

I have a similar problem with Calibri and the postscript device.

The png device works fine. The postscript device either gives me irregularly spaced letters, or an error like the following:

Error in mtext(unit_text, at = par("usr")[1] - (par("usr")[2] - par("usr")[1])/30, : metric information not available for this device

I hope that there is a solution to this issue with certain devices and certain fonts not working...

sessionInfo()

R version 3.1.1 (2014-07-10) Platform: x86_64-w64-mingw32/x64 (64-bit)

attached base packages: [1] stats graphics grDevices utils datasets methods base

other attached packages: [1] Rttf2pt1_1.3.1 extrafont_0.16 RColorBrewer_1.0-5

loaded via a namespace (and not attached): [1] extrafontdb_1.0 tools_3.1.1