Llaves
Llaves

Reputation: 743

Problems with extrafonts in R - afm errors

I'm trying to use the extrafonts package. When I import the fonts I get numerous warnings. When I try to use the fonts in the pdf() command, I get numerous warnings about unknown AFM entities. I've seen a number of posts that suggest removing the copyright line from the AFM file, but that would require fixing hundreds of files. I did edit a couple of files, but the problems continue. About the only fonts I can get to work are the core fonts available on Windows like Arial and Courier. When I tried Palatino Linotype, I get a large number of warnings (font width unknown...) and the pdf output (a plot) has no glyphs. This font works in other programs, like Word. In other cases (eg, Franklin Gothic Book) I get some sort of default font, but at least glyphs appear.

My pdf command looks like this:

pdf("plot_out2.pdf", family= "Franklin Gothic Book", width=8.5, height=11)

This produces these warnings:

Warning messages:
1: In pdf("plot_out2.pdf", family = "Franklin Gothic Book", width = 8.5,  :
  unknown AFM entity encountered
2: In pdf("plot_out2.pdf", family = "Franklin Gothic Book", width = 8.5,  :
  unknown AFM entity encountered
3: In pdf("plot_out2.pdf", family = "Franklin Gothic Book", width = 8.5,  :
  unknown AFM entity encountered
4: In pdf("plot_out2.pdf", family = "Franklin Gothic Book", width = 8.5,  :
  unknown AFM entity encountered

Do I need to re-install the fonts? If so, do I need to delete something first? Is there a utility for repairing all the afm.gz files? Do I need to embed the fonts, even when I'm reading them on the same computer that generated the pdf?

Environment:
Windows 7, 64 bit. RStudio, R 2.15. Some of my fonts were installed by CorelDraw, others by ArcMap. Probably other sources, too.

Upvotes: 3

Views: 2353

Answers (1)

farnsy
farnsy

Reputation: 2470

I think the other poster is suggesting that you don't have your fonts registered with the pdf device correctly or you are using the wrong name for your font. This stuff should be handled by the extrafont package when you import fonts. You can see what fonts are available and correctly mapped by looking at the output of names(pdfFonts). Any name you see there should be available for use in your pdf document (use the same spelling and capitalization).

However, this does not appear to be your problem as I can reproduce your experience. For example

> library(extrafont)
Registering fonts with R
> "Tahoma" %in% names(pdfFonts())
[1] TRUE
> pdf("testfile.pdf",family="Tahoma")
Warning messages:
1: In pdf("testfile.pdf", family = "Tahoma") :
  unknown AFM entity encountered
2: In pdf("testfile.pdf", family = "Tahoma") :
  unknown AFM entity encountered
3: In pdf("testfile.pdf", family = "Tahoma") :
  unknown AFM entity encountered
4: In pdf("testfile.pdf", family = "Tahoma") :
  unknown AFM entity encountered
> plot(rnorm(100),rnorm(100))
> dev.off()
> embed_fonts("testfile.pdf")

In this case the font does get embedded despite the warnings as I can verify in my pdf output.

I'd suggest taking this up with the package developer. It looks like a bug.

Edit: I took a look at the code and Rttf2pt1 was adding a keyword to the AFM files that R's postscript utility doesn't accept. I submitted a solution to the dev so hopefully this particular warning won't be a problem in the future. The other issues you are having (missing glyphs) may be a more difficult fix.

Upvotes: 2

Related Questions