Giter Club home page Giter Club logo

extrafont's People

Contributors

beanumber avatar dschwilk avatar gabrielmagno avatar gvfarns avatar jrnold avatar laresbernardo avatar renesuarezsoto avatar statnmap avatar tstenborg avatar wch avatar xyloforce avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

extrafont's Issues

Gostscript call fails

Thanks for doing the hard work on this package.

I have been trying extrafont out with R3.0.0 on a windows 7 64bit PC.

I can install and load fonts just fine.

When I run the example and get to:

embed_fonts('fonttest.pdf', outfile='fonttest-embed.pdf')

I get:

Error: /undefinedfilename in ("fonttest.pdf")
Operand stack:

Execution stack:
%interp_exit .runexec2 --nostringval-- --nostringval-- --nostringval-- 2 %stopped_push --nostringval-- --nostringval-- --nostringval-- false 1 %stopped_push
Dictionary stack:
--dict:1175/1684(ro)(G)-- --dict:0/20(G)-- --dict:77/200(L)--
Current allocation mode is local
Last OS error: Invalid argument
GPL Ghostscript 9.07: Unrecoverable error, exit code 1
Error in embedFonts(file = file, format = format, outfile = outfile, options = paste(paste("-I", :
status 1 in running command 'C:/gs/gs9.07/bin/gswin64c.exe -dNOPAUSE -dBATCH -q -dAutoRotatePages=/None -sDEVICE=pdfwrite -sOutputFile=C:\Users\mbpssmr\AppData\Local\Temp\RtmpWGZ2Ku\Rembed234c60bc65f "-sFONTPATH=" -I"C:\R\R-3.0.0\library\extrafontdb\fontmap" ""fonttest.pdf""'
In addition: Warning message:
running command 'C:/gs/gs9.07/bin/gswin64c.exe -dNOPAUSE -dBATCH -q -dAutoRotatePages=/None -sDEVICE=pdfwrite -sOutputFile=C:\Users\mbpssmr\AppData\Local\Temp\RtmpWGZ2Ku\Rembed234c60bc65f "-sFONTPATH=" -I"C:\R\R-3.0.0\library\extrafontdb\fontmap" ""fonttest.pdf""' had status 1

However if I go to the command line and run gs manually:

C:\Rwd>C:/gs/gs9.07/bin/gswin64c.exe -dNOPAUSE -dBATCH -q - AutoRotatePages=/None -sDEVICE=pdfwrite -sOutputFile=out.pdf "-sFONTPATH=" -I"C:\R\R-3.0.0\library\extrafontdb\fontmap" "font_plot.pdf"

Everything works and I get a pdf with fonts correctly embedded.

""fonttest.pdf""' causes the problem with /undefinedfilename.

When this is corrected gs runs, but does not produce a useful output untill sOutputFile is set to something useful.

Fix hyphens/minus signs that are zero width

The hyphens are also missing in some fonts. Here's an example of zero-width:

set.seed(23)
z <- rnorm(500)

pdf("Arialz.pdf", family="Arial")
hist(z, main="Histogram of -- Standard Z", xlim=c(-5, 5))
text(x=-3, y=60, col="red", expression(bold(This)~underline(is)~a~italic(test.)))
dev.off()

Have font_import scan ~/.fonts

On Linux and probably *BSD and any systems using X, it is customary that users can install fonts to ~/.fonts. It would be convenient if that, in addition to system directories, was scanned by default by font_import.

When loadfonts(quiet=TRUE), it should suppress warnings

This is to avoid showing warnings when extrafont is loaded:

> library(extrafont)
Registering fonts with R
Warning in loadfonts("pdf", quiet = TRUE) :
  More than one version of regular/bold/italic found for Apple Braille. Skipping setup for this font.
Warning in loadfonts("pdf", quiet = TRUE) :
  No regular (non-bold, non-italic) version of Brush Script MT. Skipping setup for this font.

Unrecoverable error with Ghostscript 9.16 Mac OSX?

Hello,

I recently started having an issue with embedding fonts via extrafont::embed_fonts, and I have no idea why. I have the following functions that I use to produce pdfs with CM Roman font:

toDev  <-  function (expr, dev, filename, ..., verbose = TRUE) {
    if (verbose) {
        cat(sprintf('Creating %s\\n', filename))
    }
    dev(filename, family = 'CM Roman', ...)
    on.exit(dev.off())
    eval.parent(substitute(expr))
}

toPdf  <-  function (expr, filename, ...) {
    toDev(expr, pdf, filename, ...)
}

If I run

library(extrafont)
library(fontcm)
extrafont::loadfonts(quiet = TRUE)

myPlot  <-  function () {
	plot(0, 0)	
}

toPdf(myPlot(), '~/Desktop/myPLot.pdf', width = 7, height = 7)
extrafont::embed_fonts('~/Desktop/myPLot.pdf')

I get this error:

Error: /undefinedfilename in (~/Desktop/myPLot.pdf)
Operand stack:

Execution stack:
   %interp_exit   .runexec2   --nostringval--   --nostringval--   --nostringval--   2   %stopped_push   --nostringval--   --nostringval--   --nostringval--   false   1   %stopped_push
Dictionary stack:
   --dict:1184/1684(ro)(G)--   --dict:0/20(G)--   --dict:78/200(L)--
Current allocation mode is local
Last OS error: Invalid argument
GPL Ghostscript 9.16: Unrecoverable error, exit code 1
Error in gettextf("status %d in running command '%s'", ret, cmd) : 
  object 'cmd' not found

I get the same error if I use instead

grDevices::embedFonts('~/Desktop/myPLot.pdf')

This has never happened to me before, and I have been using this workflow with extrafont::embed_fonts for years now. Any ideas of what could be causing this? Here are my sessionInfo() specs:

R version 3.4.1 (2017-06-30)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: OS X El Capitan 10.11.6

Matrix products: default
BLAS: /Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRblas.0.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRlapack.dylib

locale:
[1] en_AU.UTF-8/en_AU.UTF-8/en_AU.UTF-8/C/en_AU.UTF-8/en_AU.UTF-8

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

other attached packages:
[1] fontcm_1.1     extrafont_0.17

loaded via a namespace (and not attached):
[1] compiler_3.4.1  tools_3.4.1     extrafontdb_1.0 Rttf2pt1_1.3.4 

Thanks!

Missing minus symbol

Dear Winston,

I realise this has been raised as an issue previously, but it is marked as 'closed' however I still have this problem. I apologise in advance if I am overlooking something obvious but I have been unable to find a solution.

After installing extrafont, I import my fonts:

> library(extrafontdb)
> library(extrafont)
> ttf_import()
Scanning ttf files in /Library/Fonts/, /System/Library/Fonts, ~/Library/Fonts/ ...
Extracting .afm files from .ttf files...
/Library/Fonts/AlBayan.ttf : No FontName. Skipping.
/Library/Fonts/AlBayanBold.ttf : No FontName. Skipping.
/Library/Fonts/Andale Mono.ttf => /Users/sc7512/Library/R/3.0/library/extrafontdb/metrics/Andale Mono

...and so on

This give me multiple warnings:

> warnings()
Warning messages:
1: running command ''/Users/sc7512/Library/R/3.0/library/Rttf2pt1/exec//ttf2pt1' -a -GfAe '/Library/Fonts/AlBayan.ttf' '/var/folders/28/d8jlmryn3l3gm6xbn0fz_dp000g1x6/T//RtmpSvfRxg/fonts/AlBayan' 2>&1' had status 1
2: running command ''/Users/sc7512/Library/R/3.0/library/Rttf2pt1/exec//ttf2pt1' -a -GfAe '/Library/Fonts/AlBayanBold.ttf' '/var/folders/28/d8jlmryn3l3gm6xbn0fz_dp000g1x6/T//RtmpSvfRxg/fonts/AlBayanBold' 2>&1' had status 1
3: running command ''/Users/sc7512/Library/R/3.0/library/Rttf2pt1/exec//ttf2pt1' -a -GfAe '/Library/Fonts/Apple Chancery.ttf' '/var/folders/28/d8jlmryn3l3gm6xbn0fz_dp000g1x6/T//RtmpSvfRxg/fonts/Apple Chancery' 2>&1' had status 1
4: running command ''/Users/sc7512/Library/R/3.0/library/Rttf2pt1/exec//ttf2pt1' -a -GfAe '/Library/Fonts/Apple LiGothic Medium.ttf' '/var/folders/28/d8jlmryn3l3gm6xbn0fz_dp000g1x6/T//RtmpSvfRxg/fonts/Apple LiGothic Medium' 2>&1' had status 1
5: running command ''/Users/sc7512/Library/R/3.0/library/Rttf2pt1/exec//ttf2pt1' -a -GfAe '/Library/Fonts/Apple LiSung Light.ttf' '/var/folders/28/d8jlmryn3l3gm6xbn0fz_dp000g1x6/T//RtmpSvfRxg/fonts/Apple LiSung Light' 2>&1' had status 1
6: running command ''/Users/sc7512/Library/R/3.0/library/Rttf2pt1/exec//ttf2pt1' -a -GfAe '/Library/Fonts/ArialHB.ttf' '/var/folders/28/d8jlmryn3l3gm6xbn0fz_dp000g1x6/T//RtmpSvfRxg/fonts/ArialHB' 2>&1' had status 1
7: running command ''/Users/sc7512/Library/R/3.0/library/Rttf2pt1/exec//ttf2pt1' -a -GfAe '/Library/Fonts/ArialHBBold.ttf' '/var/folders/28/d8jlmryn3l3gm6xbn0fz_dp000g1x6/T//RtmpSvfRxg/fonts/ArialHBBold' 2>&1' had status 1
8: running command ''/Users/sc7512/Library/R/3.0/library/Rttf2pt1/exec//ttf2pt1' -a -GfAe '/Library/Fonts/BiauKai.ttf' '/var/folders/28/d8jlmryn3l3gm6xbn0fz_dp000g1x6/T//RtmpSvfRxg/fonts/BiauKai' 2>&1' had status 1
9: running command ''/Users/sc7512/Library/R/3.0/library/Rttf2pt1/exec//ttf2pt1' -a -GfAe '/Library/Fonts/Chalkduster.ttf' '/var/folders/28/d8jlmryn3l3gm6xbn0fz_dp000g1x6/T//RtmpSvfRxg/fonts/Chalkduster' 2>&1' had status 134
10: running command ''/Users/sc7512/Library/R/3.0/library/Rttf2pt1/exec//ttf2pt1' -a -GfAe '/Library/Fonts/Corsiva.ttf' '/var/folders/28/d8jlmryn3l3gm6xbn0fz_dp000g1x6/T//RtmpSvfRxg/fonts/Corsiva' 2>&1' had status 1
11: running command ''/Users/sc7512/Library/R/3.0/library/Rttf2pt1/exec//ttf2pt1' -a -GfAe '/Library/Fonts/CorsivaBold.ttf' '/var/folders/28/d8jlmryn3l3gm6xbn0fz_dp000g1x6/T//RtmpSvfRxg/fonts/CorsivaBold' 2>&1' had status 1
12: running command ''/Users/sc7512/Library/R/3.0/library/Rttf2pt1/exec//ttf2pt1' -a -GfAe '/Library/Fonts/HeadlineA.ttf' '/var/folders/28/d8jlmryn3l3gm6xbn0fz_dp000g1x6/T//RtmpSvfRxg/fonts/HeadlineA' 2>&1' had status 1
13: running command ''/Users/sc7512/Library/R/3.0/library/Rttf2pt1/exec//ttf2pt1' -a -GfAe '/Library/Fonts/Hei.ttf' '/var/folders/28/d8jlmryn3l3gm6xbn0fz_dp000g1x6/T//RtmpSvfRxg/fonts/Hei' 2>&1' had status 1
14: running command ''/Users/sc7512/Library/R/3.0/library/Rttf2pt1/exec//ttf2pt1' -a -GfAe '/Library/Fonts/Kai.ttf' '/var/folders/28/d8jlmryn3l3gm6xbn0fz_dp000g1x6/T//RtmpSvfRxg/fonts/Kai' 2>&1' had status 1
15: running command ''/Users/sc7512/Library/R/3.0/library/Rttf2pt1/exec//ttf2pt1' -a -GfAe '/Library/Fonts/Kokonor.ttf' '/var/folders/28/d8jlmryn3l3gm6xbn0fz_dp000g1x6/T//RtmpSvfRxg/fonts/Kokonor' 2>&1' had status 134
16: running command ''/Users/sc7512/Library/R/3.0/library/Rttf2pt1/exec//ttf2pt1' -a -GfAe '/Library/Fonts/KufiStandardGK.ttf' '/var/folders/28/d8jlmryn3l3gm6xbn0fz_dp000g1x6/T//RtmpSvfRxg/fonts/KufiStandardGK' 2>&1' had status 1
17: running command ''/Users/sc7512/Library/R/3.0/library/Rttf2pt1/exec//ttf2pt1' -a -GfAe '/Library/Fonts/NewPeninimMT.ttf' '/var/folders/28/d8jlmryn3l3gm6xbn0fz_dp000g1x6/T//RtmpSvfRxg/fonts/NewPeninimMT' 2>&1' had status 1
18: running command ''/Users/sc7512/Library/R/3.0/library/Rttf2pt1/exec//ttf2pt1' -a -GfAe '/Library/Fonts/NewPeninimMTBold.ttf' '/var/folders/28/d8jlmryn3l3gm6xbn0fz_dp000g1x6/T//RtmpSvfRxg/fonts/NewPeninimMTBold' 2>&1' had status 1
19: running command ''/Users/sc7512/Library/R/3.0/library/Rttf2pt1/exec//ttf2pt1' -a -GfAe '/Library/Fonts/NewPeninimMTBoldInclined.ttf' '/var/folders/28/d8jlmryn3l3gm6xbn0fz_dp000g1x6/T//RtmpSvfRxg/fonts/NewPeninimMTBoldInclined' 2>&1' had status 1
20: running command ''/Users/sc7512/Library/R/3.0/library/Rttf2pt1/exec//ttf2pt1' -a -GfAe '/Library/Fonts/NewPeninimMTInclined.ttf' '/var/folders/28/d8jlmryn3l3gm6xbn0fz_dp000g1x6/T//RtmpSvfRxg/fonts/NewPeninimMTInclined' 2>&1' had status 1
21: running command ''/Users/sc7512/Library/R/3.0/library/Rttf2pt1/exec//ttf2pt1' -a -GfAe '/Library/Fonts/NISC18030.ttf' '/var/folders/28/d8jlmryn3l3gm6xbn0fz_dp000g1x6/T//RtmpSvfRxg/fonts/NISC18030' 2>&1' had status 1
22: running command ''/Users/sc7512/Library/R/3.0/library/Rttf2pt1/exec//ttf2pt1' -a -GfAe '/Library/Fonts/Osaka.ttf' '/var/folders/28/d8jlmryn3l3gm6xbn0fz_dp000g1x6/T//RtmpSvfRxg/fonts/Osaka' 2>&1' had status 1
23: running command ''/Users/sc7512/Library/R/3.0/library/Rttf2pt1/exec//ttf2pt1' -a -GfAe '/Library/Fonts/OsakaMono.ttf' '/var/folders/28/d8jlmryn3l3gm6xbn0fz_dp000g1x6/T//RtmpSvfRxg/fonts/OsakaMono' 2>&1' had status 1
24: running command ''/Users/sc7512/Library/R/3.0/library/Rttf2pt1/exec//ttf2pt1' -a -GfAe '/Library/Fonts/PCmyoungjo.ttf' '/var/folders/28/d8jlmryn3l3gm6xbn0fz_dp000g1x6/T//RtmpSvfRxg/fonts/PCmyoungjo' 2>&1' had status 1
25: running command ''/Users/sc7512/Library/R/3.0/library/Rttf2pt1/exec//ttf2pt1' -a -GfAe '/Library/Fonts/Pilgiche.ttf' '/var/folders/28/d8jlmryn3l3gm6xbn0fz_dp000g1x6/T//RtmpSvfRxg/fonts/Pilgiche' 2>&1' had status 1
26: running command ''/Users/sc7512/Library/R/3.0/library/Rttf2pt1/exec//ttf2pt1' -a -GfAe '/Library/Fonts/Raanana.ttf' '/var/folders/28/d8jlmryn3l3gm6xbn0fz_dp000g1x6/T//RtmpSvfRxg/fonts/Raanana' 2>&1' had status 1
27: running command ''/Users/sc7512/Library/R/3.0/library/Rttf2pt1/exec//ttf2pt1' -a -GfAe '/Library/Fonts/RaananaBold.ttf' '/var/folders/28/d8jlmryn3l3gm6xbn0fz_dp000g1x6/T//RtmpSvfRxg/fonts/RaananaBold' 2>&1' had status 1
28: running command ''/Users/sc7512/Library/R/3.0/library/Rttf2pt1/exec//ttf2pt1' -a -GfAe '/Library/Fonts/Skia.ttf' '/var/folders/28/d8jlmryn3l3gm6xbn0fz_dp000g1x6/T//RtmpSvfRxg/fonts/Skia' 2>&1' had status 1
29: running command ''/Users/sc7512/Library/R/3.0/library/Rttf2pt1/exec//ttf2pt1' -a -GfAe '/Library/Fonts/华文仿宋.ttf' '/var/folders/28/d8jlmryn3l3gm6xbn0fz_dp000g1x6/T//RtmpSvfRxg/fonts/华文仿宋' 2>&1' had status 1
30: running command ''/Users/sc7512/Library/R/3.0/library/Rttf2pt1/exec//ttf2pt1' -a -GfAe '/Library/Fonts/华文细黑.ttf' '/var/folders/28/d8jlmryn3l3gm6xbn0fz_dp000g1x6/T//RtmpSvfRxg/fonts/华文细黑' 2>&1' had status 1
31: running command ''/Users/sc7512/Library/R/3.0/library/Rttf2pt1/exec//ttf2pt1' -a -GfAe '/Library/Fonts/华文黑体.ttf' '/var/folders/28/d8jlmryn3l3gm6xbn0fz_dp000g1x6/T//RtmpSvfRxg/fonts/华文黑体' 2>&1' had status 1
32: running command ''/Users/sc7512/Library/R/3.0/library/Rttf2pt1/exec//ttf2pt1' -a -GfAe '/System/Library/Fonts/Apple Color Emoji.ttf' '/var/folders/28/d8jlmryn3l3gm6xbn0fz_dp000g1x6/T//RtmpSvfRxg/fonts/Apple Color Emoji' 2>&1' had status 1
33: running command ''/Users/sc7512/Library/R/3.0/library/Rttf2pt1/exec//ttf2pt1' -a -GfAe '/System/Library/Fonts/Apple Symbols.ttf' '/var/folders/28/d8jlmryn3l3gm6xbn0fz_dp000g1x6/T//RtmpSvfRxg/fonts/Apple Symbols' 2>&1' had status 1
34: running command ''/Users/sc7512/Library/R/3.0/library/Rttf2pt1/exec//ttf2pt1' -a -GfAe '/System/Library/Fonts/LastResort.ttf' '/var/folders/28/d8jlmryn3l3gm6xbn0fz_dp000g1x6/T//RtmpSvfRxg/fonts/LastResort' 2>&1' had status 1
35: In readLines(fd, 30) : seek on a gzfile connection returned an internal error
36: In readLines(fd, 30) : seek on a gzfile connection returned an internal error
37: In grepl("^FamilyName", text) : input string 4 is invalid in this locale
38: In grepl("^FontName", text) : input string 4 is invalid in this locale
39: In grepl("^FullName", text) : input string 4 is invalid in this locale
40: In grepl("^Weight", text) : input string 4 is invalid in this locale
41: In readLines(fd, 30) : seek on a gzfile connection returned an internal error
42: In grepl("^FamilyName", text) : input string 4 is invalid in this locale
43: In grepl("^FontName", text) : input string 4 is invalid in this locale
44: In grepl("^FullName", text) : input string 4 is invalid in this locale
45: In grepl("^Weight", text) : input string 4 is invalid in this locale
46: In readLines(fd, 30) : seek on a gzfile connection returned an internal error
47: In grepl("^FamilyName", text) : input string 4 is invalid in this locale
48: In grepl("^FontName", text) : input string 4 is invalid in this locale
49: In grepl("^FullName", text) : input string 4 is invalid in this locale
50: In grepl("^Weight", text) : input string 4 is invalid in this locale

Despite this, load fonts() seems to work:

Registering font with R using pdfFonts(): .Keyboard
Registering font with R using pdfFonts(): Andale Mono
More than one version of regular/bold/italic found for Apple Braille. Skipping setup for this font.
Registering font with R using pdfFonts(): AppleMyungjo
Registering font with R using pdfFonts(): Arial Black
Registering font with R using pdfFonts(): Arial
Registering font with R using pdfFonts(): Arial Narrow
Registering font with R using pdfFonts(): Arial Rounded MT Bold

etc.

and the fonts which imported without error are listed as loaded and available:

> fonts()
 [1] ".Keyboard"               "Andale Mono"             "Apple Braille"           "AppleMyungjo"           
 [5] "Arial Black"             "Arial"                   "Arial Narrow"            "Arial Rounded MT Bold"  
 [9] "Arial Unicode MS"        "Batang"                  "Bookshelf Symbol 7"      "Brush Script MT"        
[13] "Calibri"                 "Cambria"                 "Cambria Math"            "Candara"                
[17] "Comic Sans MS"           "Consolas"                "Constantia"              "Corbel"                 
[21] "Courier New"             "Franklin Gothic Book"    "Franklin Gothic Medium"  "Gabriola"               
[25] "Georgia"                 "Gill Sans MT"            "Gulim"                   "Impact"                 
[29] "Khmer Sangam MN"         "Lao Sangam MN"           "Lucida Console"          "Lucida Sans Unicode"    
[33] "Marlett"                 "Meiryo"                  "Microsoft Yi Baiti"      "Microsoft Himalaya"     
[37] "Microsoft Sans Serif"    "Microsoft Tai Le"        "MingLiU_HKSCS-ExtB"      "MingLiU_HKSCS"          
[41] "MingLiU"                 "MingLiU-ExtB"            "Mongolian Baiti"         "MS Gothic"              
[45] "MS Mincho"               "MS PGothic"              "MS PMincho"              "MS Reference Sans Serif"
[49] "MS Reference Specialty"  "Myanmar Sangam MN"       "Palatino Linotype"       "Perpetua"               
[53] "PMingLiU"                "PMingLiU-ExtB"           "SimHei"                  "SimSun"                 
[57] "SimSun-ExtB"             "Tahoma"                  "Times New Roman"         "Trebuchet MS"           
[61] "Tw Cen MT"               "Verdana"                 "Webdings"                "Wingdings"              
[65] "Wingdings 2"             "Wingdings 3"           

However, my chosen font (Gill Sans MT) does not display minus characters:

a <- 0:100
b <- -50:50
pdf("test.pdf", family="Gill Sans MT", height=10, width=10)
Warning messages:
1: In pdf("test.pdf", family = "Gill Sans MT", height = 10, width = 10) :
  unknown AFM entity encountered
2: In pdf("test.pdf", family = "Gill Sans MT", height = 10, width = 10) :
  unknown AFM entity encountered
3: In pdf("test.pdf", family = "Gill Sans MT", height = 10, width = 10) :
  unknown AFM entity encountered
4: In pdf("test.pdf", family = "Gill Sans MT", height = 10, width = 10) :
  unknown AFM entity encountered
plot(a~b)
Warning messages:
1: In axis(side = side, at = at, labels = labels, ...) :
  font width unknown for character 0x2d
2: In axis(side = side, at = at, labels = labels, ...) :
  font width unknown for character 0x2d
3: In axis(side = side, at = at, labels = labels, ...) :
  font width unknown for character 0x2d
4: In axis(side = side, at = at, labels = labels, ...) :
  font width unknown for character 0x2d
> dev.off()
null device 
          1 
> embed_fonts("test.pdf")

The resulting plot displays the missing character box where a minus symbol should be.

My session info is:

> sessionInfo()
R version 3.0.1 (2013-05-16)
Platform: x86_64-apple-darwin10.8.0 (64-bit)

locale:
[1] en_GB.UTF-8/en_GB.UTF-8/en_GB.UTF-8/C/en_GB.UTF-8/en_GB.UTF-8

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

other attached packages:
[1] extrafont_0.15  extrafontdb_1.0

loaded via a namespace (and not attached):
[1] Rttf2pt1_1.2 tools_3.0.1 

I would be very grateful for your help with this problem,

Best wishes,

Steve

extrafont fonts not recognized

I followed the instructions and installed the Robot font family (downloaded from Google Fonts), but I can't seem to get pdf() to recognize the font.

When I type subset(fonttable(), FamilyName == "Roboto"), it seems to show that the font is loaded, but when I try to generate the pdf, I get an error:

pdf("test.pdf", width=4, height=7, family="Roboto")
Error in pdf("Glycosylation Burden.pdf", width = 4, height = 7, family = "Roboto") :
unknown family 'Roboto'

subset(fonttable(), FamilyName == "Roboto")
package afmfile fontfile FullName FamilyName FontName Bold Italic Symbol afmsymfile
158 NA Roboto-Black.afm.gz ~/Dropbox/Public/Exported Fonts/Roboto/Roboto-Black.ttf Roboto Black Roboto Roboto-Black FALSE FALSE FALSE NA
159 NA Roboto-BlackItalic.afm.gz ~/Dropbox/Public/Exported Fonts/Roboto/Roboto-BlackItalic.ttf Roboto Black Italic Roboto Roboto-BlackItalic FALSE TRUE FALSE NA
160 NA Roboto-Bold.afm.gz ~/Dropbox/Public/Exported Fonts/Roboto/Roboto-Bold.ttf Roboto Bold Roboto Roboto-Bold TRUE FALSE FALSE NA
161 NA Roboto-BoldItalic.afm.gz ~/Dropbox/Public/Exported Fonts/Roboto/Roboto-BoldItalic.ttf Roboto Bold Italic Roboto Roboto-BoldItalic TRUE TRUE FALSE NA
162 NA Roboto-Italic.afm.gz ~/Dropbox/Public/Exported Fonts/Roboto/Roboto-Italic.ttf Roboto Italic Roboto Roboto-Italic FALSE TRUE FALSE NA
163 NA Roboto-Light.afm.gz ~/Dropbox/Public/Exported Fonts/Roboto/Roboto-Light.ttf Roboto Light Roboto Roboto-Light FALSE FALSE FALSE NA
164 NA Roboto-LightItalic.afm.gz ~/Dropbox/Public/Exported Fonts/Roboto/Roboto-LightItalic.ttf Roboto Light Italic Roboto Roboto-LightItalic FALSE TRUE FALSE NA
165 NA Roboto-Medium.afm.gz ~/Dropbox/Public/Exported Fonts/Roboto/Roboto-Medium.ttf Roboto Medium Roboto Roboto-Medium FALSE FALSE FALSE NA
166 NA Roboto-MediumItalic.afm.gz ~/Dropbox/Public/Exported Fonts/Roboto/Roboto-MediumItalic.ttf Roboto Medium Italic Roboto Roboto-MediumItalic FALSE TRUE FALSE NA
167 NA Roboto-Regular.afm.gz ~/Dropbox/Public/Exported Fonts/Roboto/Roboto-Regular.ttf Roboto Regular Roboto Roboto-Regular FALSE FALSE FALSE NA
168 NA Roboto-Thin.afm.gz ~/Dropbox/Public/Exported Fonts/Roboto/Roboto-Thin.ttf Roboto Thin Roboto Roboto-Thin FALSE FALSE FALSE NA
169 NA Roboto-ThinItalic.afm.gz ~/Dropbox/Public/Exported Fonts/Roboto/Roboto-ThinItalic.ttf Roboto Thin Italic Roboto Roboto-ThinItalic FALSE TRUE FALSE NA

This might be related. After I quit and restarted R
library(extrafont)
Error : .onAttach failed in attachNamespace() for 'extrafont', details:
call: (function (...)
error: invalid arguments in 'pdfFonts' (must be font names)
Error: package or namespace load failed for ‘extrafont’

"No FontName. Skipping" during font_import()

e.g.:

/Library/Fonts/BigCaslon.ttf : No FontName. Skipping.

and (more spectacularly):

/Library/Fonts/Chalkduster.ttfsh: line 1: 86587 Abort trap: 6
'/Library/Frameworks/R.framework/Versions/3.0/Resources/library/Rttf2pt1/exec//ttf2pt1' -a -GfAe '/Library/Fonts/Chalkduster.ttf' '/var/folders/jd/hrv5pvps34lflzkmt6q1czsc0000gp/T//RtmpAT3LLx/fonts/Chalkduster' 2>&1
 : No FontName. Skipping.

I also received a number of warnings (this is an excerpt):

38: In readLines(fd, 30) : seek on a gzfile connection returned an internal error
39: In readLines(fd, 30) : seek on a gzfile connection returned an internal error
40: In grepl("^FamilyName", text) : input string 4 is invalid in this locale
41: In grepl("^FontName", text) : input string 4 is invalid in this locale
42: In grepl("^FullName", text) : input string 4 is invalid in this locale
43: In grepl("^Weight", text) : input string 4 is invalid in this locale

Mac OS X 10.7.5, R 3.0.1
R version 3.0.1 (2013-05-16)
Platform: x86_64-apple-darwin10.8.0 (64-bit)

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

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

other attached packages:
[1] extrafont_0.15 devtools_1.3 NADA_1.5-5 survival_2.37-4

loaded via a namespace (and not attached):
[1] colorspace_1.2-3 dichromat_2.0-0 digest_0.6.3 evaluate_0.4.7 extrafontdb_1.0
[6] ggplot2_0.9.3.1.99 grid_3.0.1 gtable_0.1.2 httr_0.2 labeling_0.2
[11] MASS_7.3-29 memoise_0.1 munsell_0.4.2 parallel_3.0.1 plyr_1.8
[16] proto_0.3-10 RColorBrewer_1.0-5 RCurl_1.95-4.1 reshape2_1.2.2 Rttf2pt1_1.2
[21] scales_0.2.3 stringr_0.6.2 tools_3.0.1 whisker_0.3-2

No spaces printed in PDF device

Hello,

First, extrafont is great! Thanks so much for maintaining this package. I am trying to make figures using Myriad Pro. To do so I am using the 'pdf' function and choosing the family "Myriad Pro". I get the PDF with all the text in Myriad Pro as desired but with no spaces between words! I am getting warning messages after every line where I include spaces in the text (In text.default(x + ats/perdeg, y + dy - 0.5 * cxy[2], labs, adj = c(0.4, : font width unknown for character 0x20).

Below is the part of the script used to produce the figure:
pdf("H_sampling_V3.pdf", family="Myriad Pro", width=4.527559,height=5.90551)
plot(d_leu,col=makeTransparent("green4",alpha=0.3),add=T,border="green4")
text(-102,15,"Mexico",cex=0.75)
lines(c(-102,-100),c(16,18),col="gray30")
#The following is printed in the PDF as 'ElSalvador', with no space
text(-83,18,"El Salvador",cex=0.75)
lines(c(-88.5,-88.5+3),c(14,17),col="gray30")
maps::map.scale(x=-108,y=-17,relwidth = 0.2,metric=TRUE,ratio = FALSE,cex=0.7)
dev.off()

Do you have idea what I could be doing wrong? I also tried using 'embed_fonts' and I got an error saying that the GhostScript was not found. I appreaciate very much any help on this. Thank you in advance.

Best,

Laura

downloaded font should be in /Library/Fonts not in ~/Library/Fonts

It seems that this library is no longer maintained, still an issue so others can maybe solve this problem.

When downloading a .ttf on Mac OS, it is stored in ~/Library/Fonts. Confusingly extrafont does find the font when running font_import. After import, it is also shown when running fonts. However, it still is not available for use.

It does work when moving the .ttf file to /Library/Fonts . Apparently this is the folder extrafonts looks. Make sure to remove the .ttf file from ~/Library/Fonts and rerun the import_font.

"More than one version of regular/bold/italic found for Open Sans. Skipping setup for this font" problem.

Hi,

When I load fonts, I receive output as follows:
> loadfonts() Liberation Sans already registered with pdfFonts(). More than one version of regular/bold/italic found for Open Sans. Skipping setup for this font. Open Sans Extrabold already registered with pdfFonts(). Open Sans Semibold already registered with pdfFonts().

Function fonttable() returns following result:
fonttable

When I try to save ggplot2 graphs to PDF files with Open Sans font, it generates lots of warnings, and creates file without text.

I've tried to reinstall extrafontdb, as suggested here, but it didn't help.

What may I do to have it working properly?

add ~/.local/share/fonts to search path for linux

Greetings,

I used this for the first time and was a bit perplexed as I knew I had a font installed but font_import() wasn't finding it. It was in ~/.local/share/fonts/, which according to the arch linux wiki is the recommended path for user fonts:

To install fonts system-wide (available for all users), move the folder to the /usr/share/fonts/ directory. The files need to be readable by every user, use chmod to set the correct permissions (i.e. at least 0444 for files and 0555 for directories). To install fonts for only a single user, use ~/.local/share/fonts (~/.fonts/ is now deprecated).

Could you add this to your search paths? From looking at the path building, I figured it would just be this change, but I didn't look everywhere:

 # Possible font paths, depending on the system
    paths <-
      c("/usr/share/fonts/",                    # Ubuntu/Debian/Arch/Gentoo
        "/usr/X11R6/lib/X11/fonts/TrueType/",   # RH 6
        "~/.fonts/",                            # User fonts
        "~/.local/share/fonts)                  # User fonts (added)
    return(paths[file.exists(paths)])

It seems both may be advised... I'm on arch linux, but in googling to find out how widespread this is, it's a mixed bag. Arch and gentoo mention the new location, but ubuntu, freebsd, and debian still reference the ~/.fonts directory in their docs.

The new recommendation appears to be a combination of:

$XDG_DATA_HOME defines the base directory relative to which user specific data files should be stored. If $XDG_DATA_HOME is either not set or empty, a default equal to $HOME/.local/share should be used.

This element contains a directory name which will be scanned for font files to include in the set of available fonts. If 'prefix' is set to "xdg", the value in the XDG_DATA_HOME environment variable will be added as the path prefix. please see XDG Base Directory Specification for more details.

So, perhaps depending on the distro the xdg value is set as the prefix and thus the path needs to be $XDG_DATA_HOME/fonts ($HOME/.local/share/fonts), not just ~/.fonts.

P.S. Credit to this bug for putting those last two points together. For this being a "thing" to mention on the arch linux wiki, I was surprised at the lack of information on why one vs. the other.

font_import() failed to 'CreateProcess' on Win7 32bit SP1

Hi:
Could you please look into a problem regarding tt2pt1.exe?

When I run font_import(), it fails with a warning message:
Scanning ttf files in C:\WINDOWS\Fonts ... Extracting .afm files from .ttf files... C:\Windows\Fonts\Arial.TTFError in system2(ttf2pt1, c(args, shQuote(ttfiles[i]), shQuote(tmpfiles[i])), : 'CreateProcess' failed to run 'C:\Docs\R\R-33~1.2\library\Rttf2pt1\exec\ttf2pt1.exe -a -G fAe "C:\Windows\Fonts\Arial.TTF" "C:\Users\xx\AppData\Local\Temp\RtmpILTO8i/fonts/Arial"'

And when I double click tt2pt1.exe in \Rttf2pt1\exec, it pops up a warning "The version of this file is not compatible with the version of Windows you're running." So I doubt if tt2pt1.exe is of a wrong version.

My sessionInfo

> sessionInfo()
R version 3.3.2 (2016-10-31)
Platform: i386-w64-mingw32/i386 (32-bit)
Running under: Windows 7 (build 7601) Service Pack 1

locale:
[1] LC_COLLATE=English_United States.1252                        LC_CTYPE=Chinese (Simplified)_People's Republic of China.936
[3] LC_MONETARY=English_United States.1252                       LC_NUMERIC=C                                                
[5] LC_TIME=English_United States.1252                          

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

other attached packages:
[1] extrafont_0.17  devtools_1.12.0

Thanks!

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

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 

Add wrapper for windows fonts

This is for bitmap output on Windows:

windowsFonts(Georgia=windowsFont("Georgia"))
ggplot(mtcars, aes(x=wt, y=mpg)) + geom_point() +
    opts(title="Title text goes here") +
    opts(plot.title = theme_text(size = 16, family="Georgia", face="italic"))

Will probably need to scan the fonts files with ttf2pt1 to get names.

embed_fonts fails (Mac, R 3.0)

embed_fonts fails:

embed_fonts("xxxx/temp.pdf", outfile="xxxx/temp_embed.pdf")
Error: /undefinedfilename in ('xxxx/temp.pdf')
Operand stack:

Execution stack:
%interp_exit .runexec2 --nostringval-- --nostringval-- --nostringval-- 2 %stopped_push --nostringval-- --nostringval-- --nostringval-- false 1 %stopped_push
Dictionary stack:
--dict:1156/1684(ro)(G)-- --dict:0/20(G)-- --dict:77/200(L)--
Current allocation mode is local
Last OS error: 2
GPL Ghostscript 9.05: Unrecoverable error, exit code 1
Error in embedFonts(file = file, format = format, outfile = outfile, options = paste(paste("-I", :
status 1 in running command '/usr/local/bin/gs -dNOPAUSE -dBATCH -q -dAutoRotatePages=/None -sDEVICE=pdfwrite -sOutputFile=/var/folders/qw/38815kvs6gl5h_q2jxl4wmcm0000gn/T//RtmptQaKe8/Rembed7793151304e5 '-sFONTPATH=' -I'/Users/jxchong/Library/R/3.0/library/extrafontdb/fontmap' "'xxxx/temp.pdf'"'

However I can fix up the command and run it manually via command line:

/usr/local/bin/gs -dNOPAUSE -dBATCH -q -dAutoRotatePages=/None -sDEVICE=pdfwrite -sOutputFile=xxxx/GB_embed.pdf '-sFONTPATH=' -I'/Users/jxchong/Library/R/3.0/library/extrafontdb/fontmap' 'xxxx/temp.pdf'

  1. too many quotes around the input file in the embed_fonts command (nested double and single quotes)
  2. the output file is being sent to a temporary directory even though I specified it with outfile

negative signs cause warning and errors in plot

I love extrafont, so thank you! But, I have run into something I can't seem to figure out. Minimal example of issue below. Negative values in scatterplot cause issues with plot output -- the negative signs overlap the values in the resulting plot.

This works just fine:

library(ggplot2)
library(extrafont)

fonts()

V1 <- sample(1:1000,512)
V2 <- sample(1:1000,512)
df2 = as.data.frame(cbind(V1,V2))
p <- ggplot(df2, aes(V1, V2)) + 
    geom_point()+
    theme(text = element_text(family="Roboto Condensed"))
ggsave("test.pdf", plot=p,  width=4, height=4)
embed_fonts("test.pdf",outfile="test.pdf")

But, when I add negative values to the data frame (only differences in code below are in assignments of values to V1 and V2), I get a warning and the negative signs overlap with the values on the axes in the resultant plot.

V1 <- sample(c(-1000:1000),512)
V2 <- sample(c(-1000:1000),512)
df2 = as.data.frame(cbind(V1,V2))
p <- ggplot(df2, aes(V1, V2)) + 
    geom_point()+
    theme(text = element_text(family="Roboto Condensed"))
ggsave("test2.pdf", plot=p,  width=4, height=4)
embed_fonts("test2.pdf",outfile="test2.pdf")

Below includes what was in my console (including the warning message:

> library(ggplot2)
> library(extrafont)
>
> fonts()
[1] "DejaVu Sans"            "DejaVu Sans Condensed"  "DejaVu Sans Light"
[4] "Roboto Condensed"       "Roboto Condensed Light"
>
> V1 <- sample(1:1000,512)
> V2 <- sample(1:1000,512)
> df2 = as.data.frame(cbind(V1,V2))
> p <- ggplot(df2, aes(V1, V2)) +
+     geom_point()+
+     theme(text = element_text(family="Roboto Condensed"))
> ggsave("test.pdf", plot=p,  width=4, height=4)
> embed_fonts("test.pdf",outfile="test.pdf")
>
> V1 <- sample(c(-1000:1000),512)
> V2 <- sample(c(-1000:1000),512)
> df2 = as.data.frame(cbind(V1,V2))
> p <- ggplot(df2, aes(V1, V2)) +
+     geom_point()+
+     theme(text = element_text(family="Roboto Condensed"))
> ggsave("test2.pdf", plot=p,  width=4, height=4)
There were 50 or more warnings (use warnings() to see the first 50)
> embed_fonts("test2.pdf",outfile="test2.pdf")
>
> warnings()
Warning messages:
1: In grid.Call(C_textBounds, as.graphicsAnnot(x$label),  ... :
  font width unknown for character 0x2d
2: In grid.Call(C_textBounds, as.graphicsAnnot(x$label),  ... :
  font width unknown for character 0x2d
3: In grid.Call(C_textBounds, as.graphicsAnnot(x$label),  ... :
  font width unknown for character 0x2d
4: In grid.Call(C_textBounds, as.graphicsAnnot(x$label),  ... :

sessionInfo() below

sessionInfo()
R version 3.4.3 Patched (2018-01-20 r74142)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Red Hat Enterprise Linux Server release 6.9 (Santiago)

Matrix products: default
BLAS: /jhpce/shared/jhpce/core/conda/miniconda-3/envs/svnR-3.4.x/R/3.4.x/lib64/R/lib/libRblas.so
LAPACK: /jhpce/shared/jhpce/core/conda/miniconda-3/envs/svnR-3.4.x/R/3.4.x/lib64/R/lib/libRlapack.so

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8
 [4] LC_COLLATE=en_US.UTF-8     LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                  LC_ADDRESS=C
[10] LC_TELEPHONE=C             LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

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

other attached packages:
[1] extrafont_0.17  dplyr_0.7.4     purrr_0.2.4     readr_1.1.1     tidyr_0.7.2     tibble_1.4.1
[7] ggplot2_2.2.1   tidyverse_1.1.1

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.14     compiler_3.4.3   cellranger_1.1.0 pillar_1.0.1     plyr_1.8.4
 [6] bindr_0.1        forcats_0.2.0    tools_3.4.3      lubridate_1.6.0  jsonlite_1.5
[11] nlme_3.1-131     gtable_0.2.0     lattice_0.20-35  pkgconfig_2.0.1  rlang_0.1.6
[16] psych_1.7.8      parallel_3.4.3   haven_1.1.0      bindrcpp_0.2     Rttf2pt1_1.3.5
[21] xml2_1.1.1       stringr_1.2.0    httr_1.3.1       hms_0.4.0        grid_3.4.3
[26] glue_1.2.0       R6_2.2.2         readxl_1.0.0     foreign_0.8-69   extrafontdb_1.0
[31] modelr_0.1.1     reshape2_1.4.3   magrittr_1.5     scales_0.5.0     rvest_0.3.2
[36] assertthat_0.2.0 mnormt_1.5-5     colorspace_1.3-2 labeling_0.3     stringi_1.1.6
[41] lazyeval_0.2.1   munsell_0.4.3    broom_0.4.3

Calibri font doesn't work in postscript device, only in .PNG

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

Calibri is a screen-optimized font that comes preinstalled with all new versions of Windows / Microsoft Office as the default font for Powerpoint and Word, and so it's a safe choice for use in Powerpoint files that may be transferred across computers. I would like my R vector graphics to have the same font as the powerpoint text.

Has anyone gotten Calibri to work on their system? Might there be a fix for this problem?
Thank you for your help.

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

Warning in load fonts() : More than one version of regular/bold/italic font

I tried to install and use the Georgia font in Ubuntu and R 2.15.1 but got a message: Warning in load fonts() : More than one version of regular/bold/italic font for Georgia. Skipping setup for this font. Finally the font has not been registered, so I cannot use it. Is there any workaround for the problem?

embed_fonts() causes broken wireframe when drape is translucent

When making translucent wireframe plots using the lattice package, embed_fonts() causes the wires to be rendered as dashed lines when they should be solid lines.

# R version 3.1.1
# x86_64-apple-darwin13.1.0
# OS X 10.9.4

require(extrafont)
loadfonts(device = 'pdf')

require(lattice)

# translucent colours for drape
col.regions <- paste(grey(seq(0, 1, length.out = 100)), '99', sep = '')

pdf('volcano.pdf')

wireframe(
    volcano,
    lty = 1,
    drape = T, col.regions = col.regions
)

dev.off()
embed_fonts('volcano.pdf')

This happens whatever the value of the family argument in pdf(), and only when translucent colours are used.

EPS processed with embed_fonts() fails to show up in Word 2007 while embedFonts() with defaults does

I installed this package from CRAN (0.12). I imported system fonts, loaded fonts for postscript, and tried to create a postscript device with Verdana font family. I tried Calibri as well.

I got some unknown AFM entity encountered warnings, and it looks like character width is not estimated well as I can see with XnView image viewer. Nevertheless I can insert this file into MS Word 2007 though with ugly preview generated from wrong fonts.

If I try to embed fonts with embed_fonts, I get EPS unusable in MS Word. It adds as an icon when I drag it there. If I try to insert it, it says An error occured while importing this file. <full path name to my file.eps>.

If I try to epstool --test-eps one_generated_with_embed_fonts.eps, I see the following:

GPL Ghostscript 9.05 (2012-02-08)
Copyright (C) 2010 Artifex Software, Inc.  All rights reserved.
This software comes with NO WARRANTY: see the file PUBLIC for details.
"C:\Program Files\gs\gs9.05\bin\gswin32c.exe"  -dNOEPS -dNOPAUSE -dBATCH -dNODISPLAY  "c:\docume~1\tito0003\locals~1\temp\gsviewa03704"
GPL Ghostscript 9.05 (2012-02-08)
Copyright (C) 2010 Artifex Software, Inc.  All rights reserved.
This software comes with NO WARRANTY: see the file PUBLIC for details.
EPSWARN FAIL: EPS file must not set page size: /a4

EPSWARN FAIL

"C:\Program Files\gs\gs9.05\bin\gswin32c.exe"  -dNOPAUSE -dBATCH -sDEVICE=bbox   -c "<</PageSize [9400 9400] /PageOffset [3000 3000]>> setpagedevice" -f "c:\docume~1\tito0003\locals~1\temp\gsviewa03704"
%%BoundingBox: 0 0 0 0
%%HiResBoundingBox: 0.000000 0.000000 0.000000 0.000000

File has   %%BoundingBox: 0 0 504 360
Correct is %%BoundingBox: -3000 -3000 -3000 -3000
File bounding box needs to be larger
File used PostScript operators that are prohibited in an EPS file.
File is not EPS.
FAIL: File does not comply with EPS specification.
Failed

The weird thing is that if I just use embedFonts(args[1], outfile=args[2]), it does produce useable EPS, though fonts are missing.

Embedding Cambria font isn't working

I'm running R version 3.0.1 (2013-05-16) on Mac OS X v. 10.8.5, and I'm having trouble embedding the Cambria font in a PDF of a plot created with ggplot2.

I followed all of the instructions for installing extrafont, I created the plot, and then embedded the fonts, using embed_fonts(), which leads to 45 warnings. (The first time it led to 49 warnings, so I assume that the 4 warnings that have disappeared are the warnings that you mentioned might be thrown about missing characters in your instructions.)

The problem seems to be that spaces are not embedding properly, nor are single quotation marks ('). Here is the resulting image:

example

And here are the 45 warnings:

Warning messages:
1: In grid.Call(L_textBounds, as.graphicsAnnot(x$label),  ... :
  font width unknown for character 0x20
2: In grid.Call(L_textBounds, as.graphicsAnnot(x$label),  ... :
  font width unknown for character 0x20
3: In grid.Call(L_textBounds, as.graphicsAnnot(x$label),  ... :
  font width unknown for character 0x20
4: In grid.Call(L_textBounds, as.graphicsAnnot(x$label),  ... :
  font width unknown for character 0x20
5: In grid.Call(L_textBounds, as.graphicsAnnot(x$label),  ... :
  font width unknown for character 0x20
6: In grid.Call(L_textBounds, as.graphicsAnnot(x$label),  ... :
  font width unknown for character 0x27
7: In grid.Call(L_textBounds, as.graphicsAnnot(x$label),  ... :
  font width unknown for character 0x27
8: In grid.Call(L_textBounds, as.graphicsAnnot(x$label),  ... :
  font width unknown for character 0x20
9: In grid.Call(L_textBounds, as.graphicsAnnot(x$label),  ... :
  font width unknown for character 0x20
10: In grid.Call(L_textBounds, as.graphicsAnnot(x$label),  ... :
  font width unknown for character 0x20
11: In grid.Call(L_textBounds, as.graphicsAnnot(x$label),  ... :
  font width unknown for character 0x20
12: In grid.Call(L_textBounds, as.graphicsAnnot(x$label),  ... :
  font width unknown for character 0x20
13: In grid.Call(L_textBounds, as.graphicsAnnot(x$label),  ... :
  font width unknown for character 0x20
14: In grid.Call(L_textBounds, as.graphicsAnnot(x$label),  ... :
  font width unknown for character 0x20
15: In grid.Call(L_textBounds, as.graphicsAnnot(x$label),  ... :
  font width unknown for character 0x20
16: In grid.Call(L_textBounds, as.graphicsAnnot(x$label),  ... :
  font width unknown for character 0x20
17: In grid.Call(L_textBounds, as.graphicsAnnot(x$label),  ... :
  font width unknown for character 0x20
18: In grid.Call(L_textBounds, as.graphicsAnnot(x$label),  ... :
  font width unknown for character 0x20
19: In grid.Call(L_textBounds, as.graphicsAnnot(x$label),  ... :
  font width unknown for character 0x20
20: In grid.Call(L_textBounds, as.graphicsAnnot(x$label),  ... :
  font width unknown for character 0x20
21: In grid.Call(L_textBounds, as.graphicsAnnot(x$label),  ... :
  font width unknown for character 0x27
22: In grid.Call(L_textBounds, as.graphicsAnnot(x$label),  ... :
  font width unknown for character 0x27
23: In grid.Call(L_textBounds, as.graphicsAnnot(x$label),  ... :
  font width unknown for character 0x20
24: In grid.Call(L_textBounds, as.graphicsAnnot(x$label),  ... :
  font width unknown for character 0x20
25: In grid.Call(L_textBounds, as.graphicsAnnot(x$label),  ... :
  font width unknown for character 0x20
26: In grid.Call(L_textBounds, as.graphicsAnnot(x$label),  ... :
  font width unknown for character 0x20
27: In grid.Call(L_textBounds, as.graphicsAnnot(x$label),  ... :
  font width unknown for character 0x20
28: In grid.Call(L_textBounds, as.graphicsAnnot(x$label),  ... :
  font width unknown for character 0x20
29: In grid.Call(L_textBounds, as.graphicsAnnot(x$label),  ... :
  font width unknown for character 0x20
30: In grid.Call(L_textBounds, as.graphicsAnnot(x$label),  ... :
  font width unknown for character 0x20
31: In grid.Call.graphics(L_text, as.graphicsAnnot(x$label),  ... :
  font width unknown for character 0x20
32: In grid.Call.graphics(L_text, as.graphicsAnnot(x$label),  ... :
  font width unknown for character 0x20
33: In grid.Call.graphics(L_text, as.graphicsAnnot(x$label),  ... :
  font width unknown for character 0x20
34: In grid.Call.graphics(L_text, as.graphicsAnnot(x$label),  ... :
  font width unknown for character 0x20
35: In grid.Call.graphics(L_text, as.graphicsAnnot(x$label),  ... :
  font width unknown for character 0x20
36: In grid.Call.graphics(L_text, as.graphicsAnnot(x$label),  ... :
  font width unknown for character 0x27
37: In grid.Call.graphics(L_text, as.graphicsAnnot(x$label),  ... :
  font width unknown for character 0x27
38: In grid.Call.graphics(L_text, as.graphicsAnnot(x$label),  ... :
  font width unknown for character 0x20
39: In grid.Call.graphics(L_text, as.graphicsAnnot(x$label),  ... :
  font width unknown for character 0x20
40: In grid.Call.graphics(L_text, as.graphicsAnnot(x$label),  ... :
  font width unknown for character 0x20
41: In grid.Call.graphics(L_text, as.graphicsAnnot(x$label),  ... :
  font width unknown for character 0x20
42: In grid.Call.graphics(L_text, as.graphicsAnnot(x$label),  ... :
  font width unknown for character 0x20
43: In grid.Call.graphics(L_text, as.graphicsAnnot(x$label),  ... :
  font width unknown for character 0x20
44: In grid.Call.graphics(L_text, as.graphicsAnnot(x$label),  ... :
  font width unknown for character 0x20
45: In grid.Call.graphics(L_text, as.graphicsAnnot(x$label),  ... :
  font width unknown for character 0x20

How to use extrafont in a package?

I'm writing a package where I would like to include some plotting functions with a specified font.

I added extrafont to the imports field in DESCRIPTION, and use extrafont::choose_font() to choose a font from several options. However, I have to attach extrafont package manually to get the font to work.

I noticed that extrafont use .onAttach() to register fonts, and by default packages in imports will be loaded but not attached. So when I load my package, .onAttach() will not run, right? Is there any way to get around this without adding it to the depends field? Thanks.

Installation failure for extrafont ... welcoming help for resolution

Got following, already known issues, yet appearing to be unsolved.
....
Found FontName for 1079 fonts.
Scanning afm files in /home/fabien/R/i686-pc-linux-gnu-library/3.3/extrafontdb/metrics
Error in if (grepl("Symbol", FamilyName)) Symbol <- TRUE else Symbol <- FALSE :
argument is of length zero
In addition: There were 50 or more warnings (use warnings() to see the first 50)
...
see attached file for R session information and text of warnings ...

font_import.txt

Font path

I am running R on Arch Linux, where the default /usr/share/fonts/truetype/ path is rather /usr/share/fonts/TTF. I can imagine it can be even trickier on other distros :)

Wouldn't it be easier to search for all files in /usr/share/fonts as the ttf_import function is already filtering by pattern?

Font path

I am running R on Arch Linux, where the default /usr/share/fonts/truetype/ path is rather /usr/share/fonts/TTF. I can imagine it can be even trickier on other distros :)

Wouldn't it be easier to search for all files in /usr/share/fonts as the ttf_import function is already filtering by pattern?

embed_fonts fails

Hi Winston,

embed_fonts fails In my environment.

> pdf("font_plot.pdf", family="Impact", width=4, height=4)
> plot(mtcars$mpg, mtcars$wt, 
+      main = "Fuel Efficiency of 32 Cars",
+      xlab = "Weight (x1000 lb)",
+      ylab = "Miles per Gallon")
> dev.off()
null device 
          1 
> embed_fonts("font_plot.pdf", outfile="font_plot_embed.pdf")

*** Warning: GenericResourceDir doesn't point to a valid resource directory.
               the -sGenericResourceDir=... option can be used to set this.

   **** Error reading a content stream. The page may be incomplete.
   **** File did not complete the page properly and may be damaged.
   **** Warning: File has unbalanced q/Q operators (too many q's)

   **** This file had errors that were repaired or ignored.
   **** The file was produced by: 
   **** >>>> R 2.15.2 <<<<
   **** Please notify the author of the software that produced this
   **** file that it does not conform to Adobe's published PDF
   **** specification.

> 

but this modification removes the error and generate an font-embedded pdf successfully.

> embed_fonts2 <- function (file, format, outfile = file, options = "", fontpaths = character(0)) 
+ {
+   if (missing(format)) {
+     suffix <- gsub(".+[.]", "", file)
+     format <- switch(suffix, ps = , eps = "pswrite", pdf = "pdfwrite")
+   }
+   force(outfile)
+   file <- paste("'", file, "'", sep = "")
+   embedFonts(file = file, format = format, outfile = outfile, 
+              fontpaths = fontpaths)
+ }
> embed_fonts2("font_plot.pdf", outfile="font_plot_embed.pdf", fontpaths="/Library/Fonts")

Here is my sessionInfo.

> sessionInfo()
R version 2.15.2 (2012-10-26)
Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)

locale:
[1] ja_JP.UTF-8/ja_JP.UTF-8/ja_JP.UTF-8/C/ja_JP.UTF-8/ja_JP.UTF-8

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

other attached packages:
[1] extrafontdb_1.0 ggplot2_0.9.3   extrafont_0.13  devtools_0.8   

loaded via a namespace (and not attached):
 [1] colorspace_1.2-0   dichromat_1.2-4    digest_0.6.0       evaluate_0.4.3     grid_2.15.2        gtable_0.1.2       httr_0.2           labeling_0.1      
 [9] MASS_7.3-22        memoise_0.1        munsell_0.4        parallel_2.15.2    plyr_1.8           proto_0.3-10       RColorBrewer_1.0-5 RCurl_1.95-3      
[17] reshape2_1.2.2     Rttf2pt1_1.1       scales_0.2.3       stringr_0.6.2      tools_2.15.2       whisker_0.1       

do you have any idea?

error after loadfonts()

I can't use extrafonts after what looks like a successful installation in R.
extrafont gives an error:

loadfonts()
Error in (function (...)  : 
  invalid arguments in 'pdfFonts' (must be font names)

What can I do to solve this?

Here is the sequence:

successful:

install.packages("extrafont")
library(extrafont)

then font_import() concludes with the following warnings:

> warnings() Warning messages: 1: running command ''/home/henk/R/x86_64-pc-linux-gnu-library/3.2/Rttf2pt1/exec//ttf2pt1' -a -GfAe '/usr/share/fonts/opentype/ipaexfont-gothic/ipaexg.ttf' '/tmp/RtmpnkkKzG/fonts/ipaexg' 2>&1' had status 134 2: running command ''/home/henk/R/x86_64-pc-linux-gnu-library/3.2/Rttf2pt1/exec//ttf2pt1' -a -GfAe '/usr/share/fonts/opentype/ipaexfont-mincho/ipaexm.ttf' '/tmp/RtmpnkkKzG/fonts/ipaexm' 2>&1' had status 134 3: running command ''/home/henk/R/x86_64-pc-linux-gnu-library/3.2/Rttf2pt1/exec//ttf2pt1' -a -GfAe '/usr/share/fonts/truetype/droid/DroidSansJapanese.ttf' '/tmp/RtmpnkkKzG/fonts/DroidSansJapanese' 2>&1' had status 1 4: running command ''/home/henk/R/x86_64-pc-linux-gnu-library/3.2/Rttf2pt1/exec//ttf2pt1' -a -GfAe '/usr/share/fonts/opentype/ipaexfont-mincho/ipaexm.ttf' '/tmp/RtmpnkkKzG/fonts/ipaexm' 2>&1' had status 134 5: running command ''/home/henk/R/x86_64-pc-linux-gnu-library/3.2/Rttf2pt1/exec//ttf2pt1' -a -GfAe '/usr/share/fonts/truetype/ttf-ancient-scripts/Symbola717.ttf' '/tmp/RtmpnkkKzG/fonts/Symbola717' 2>&1' had status 139 6: In grepl("^FamilyName", text) : input string 4 is invalid in this locale 7: In grepl("^FontName", text) : input string 4 is invalid in this locale 8: In grepl("^FullName", text) : input string 4 is invalid in this locale

then loadfonts() gives an error:

Registering font with R using pdfFonts(): Gentium Book Basic
Registering font with R using pdfFonts(): Georgia
Registering font with R using pdfFonts(): 
Error in (function (...)  : 
  invalid arguments in 'pdfFonts' (must be font names)

sessioninfo:

> sessionInfo()
R version 3.2.3 (2015-12-10)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 15.04

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=nl_NL.UTF-8        LC_COLLATE=en_US.UTF-8     LC_MONETARY=nl_NL.UTF-8    LC_MESSAGES=en_US.UTF-8    LC_PAPER=nl_NL.UTF-8      
 [8] LC_NAME=C                  LC_ADDRESS=C               LC_TELEPHONE=C             LC_MEASUREMENT=nl_NL.UTF-8 LC_IDENTIFICATION=C       

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

other attached packages:
[1] extrafont_0.17

loaded via a namespace (and not attached):
 [1] colorspace_1.2-6   scales_0.4.0       plyr_1.8.3         magrittr_1.5       rsconnect_0.4.1.11 tools_3.2.3        gtable_0.2.0       Rcpp_0.12.4        ggplot2_2.1.0      extrafontdb_1.0   
[11] grid_3.2.3         Rttf2pt1_1.3.3     munsell_0.4.3

Unknown device "pswrite" using gswin64c ghostscript

I cannot embed fonts on Windows 7 using gswin64 version 9.10. I am getting an unknown device "pswrite" issue. After googling around it seems that the "pswrite" driver in gswin64c may be deprecated. Here are the command I ran on an eps file:

# embed fonts
Sys.setenv(R_GSCMD = "C:/Program Files/gs/gs9.10/bin/gswin64c.exe")
loadfonts(device="postscript")
setwd( dirname(paste0( drive , "Output Data/Plots/Predictive Maps/Publication Maps/EPS Files/test.eps" ) ) )
embed_fonts( file = "test.eps" , outfile = "test-embed.eps" )
#Unknown device: pswrite
#Unrecoverable error: undefined in .uninstallpagedevice
#Operand stack:
#  defaultdevice
#Error in embedFonts(file = file, format = format, outfile = outfile, options = paste(paste("-I",  : 
#                                                                                             status 1 in running command 'C:\PROGRA~1\gs\gs9.10\bin\gswin64c.exe -dNOPAUSE -dBATCH -q -dAutoRotatePages=/None -sDEVICE=pswrite -sOutputFile=C:\Users\sohanlon\AppData\Local\Temp\RtmpOokqf0\Rembed128427c8232e "-sFONTPATH=" -I"C:\Dropbox\R\R64_Win_Libs\extrafontdb\fontmap"  "test.eps"'
#                                                                                           In addition: Warning message:
#                                                                                             running command 'C:\PROGRA~1\gs\gs9.10\bin\gswin64c.exe -dNOPAUSE -dBATCH -q -dAutoRotatePages=/None -sDEVICE=pswrite -sOutputFile=C:\Users\sohanlon\AppData\Local\Temp\RtmpOokqf0\Rembed128427c8232e "-sFONTPATH=" -I"C:\Dropbox\R\R64_Win_Libs\extrafontdb\fontmap"  "test.eps"' had status 1 

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

locale:
  [1] LC_COLLATE=English_United Kingdom.1252  LC_CTYPE=English_United Kingdom.1252    LC_MONETARY=English_United Kingdom.1252 LC_NUMERIC=C                           
[5] LC_TIME=English_United Kingdom.1252    

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

other attached packages:
  [1] Rttf2pt1_1.2       extrafontdb_1.0    ggmap_2.3          extrafont_0.16     gplots_2.11.3      KernSmooth_2.23-10 caTools_1.14       gdata_2.13.2      
[9] mcmcse_1.0-1       spBayes_0.3-7      Formula_1.1-1      magic_1.5-4        abind_1.4-0        gridExtra_0.9.1    gtools_3.0.0       coda_0.16-1       
[17] geoRglm_0.9-2      geoR_1.7-4         MASS_7.3-27        rgeos_0.2-19       RColorBrewer_1.0-5 data.table_1.8.11  maptools_0.8-25    lattice_0.20-15   
[25] foreign_0.8-54     rgdal_0.8-10       plyr_1.8           reshape2_1.2.2     ggplot2_0.9.3.1    raster_2.1-49      sp_1.0-11         

loaded via a namespace (and not attached):
  [1] bitops_1.0-5        colorspace_1.2-2    dichromat_2.0-0     digest_0.6.3        gtable_0.1.2        labeling_0.2        mapproj_1.2-1       maps_2.3-2         
[9] munsell_0.4.2       png_0.1-5           proto_0.3-10        RandomFields_2.0.66 RgoogleMaps_1.2.0.3 rjson_0.2.12        scales_0.2.3        splancs_2.01-33    
[17] stringr_0.6.2       tools_3.0.1        

Use with sweave and beamer

Hi,

I wanted to use a custom font within my .Rnw beamer presentation. A minimal working example that reproduces the error is:

\documentclass{beamer}
\begin{document}
\begin{frame}[plain]
<<echo=FALSE>>= 
library(ggplot2)
library(extrafont)
@
\begin{figure}
\centering
<<label = test, fig=TRUE, include=FALSE, echo=FALSE, message=FALSE>>=
ggplot(mtcars, aes(x=wt, y=mpg)) + geom_point() +
  ggtitle("Fuel Efficiency of 32 Cars") +
  xlab("Weight (x1000 lb)") + ylab("Miles per Gallon") +
  theme_bw() +
  theme(text=element_text(family="Garamond", size=14))
@
\includegraphics[width=\textwidth]{test}
\end{figure}
\end{frame}
\end{document}

and the error message looks like this:

Writing to file test.tex
Processing code chunks with options ...
 1 : keep.source term verbatim (test.Rnw:6)
Registering fonts with R
 2 : keep.source term verbatim pdf  (label = test, test.Rnw:12)
Error in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y,  : 
  invalid font type
Calls: <Anonymous> ... drawDetails -> drawDetails.text -> grid.Call.graphics
In addition: There were 50 or more warnings (use warnings() to see the first 50)
Execution halted

Any help would be greatly appreciated.

Warnings & all characters end up on top of each other

My code:

#Create local directory for my packages
dir.create(path = "M:/PortableSoftware/R-3.0.2/mylibrary")

#Set local library for my packages
my.library <- "M:/PortableSoftware/R-3.0.2/mylibrary"

#Set repository
my.repo <- getOption(x = "repos")
my.repo["CRAN"] <- "http://cran.uib.no/"

#Install extrafont package
install.packages(pkgs = "extrafont", lib = my.library, repos = my.repo, dependencies = TRUE, type = "win.binary", verbose = TRUE)

#Load extrafont package
library(package = "extrafont", lib.loc = my.library, verbose = TRUE)

#Import all .ttf fonts in a given directory
ttf_import(paths = "M:/MyStuff/Fonts/timesnewroman6.80/")

#Verify that the fonts were imported
fonts()
fonttable()

#Register the imported fonts for R's pdf (or postscript) device
loadfonts(device = "pdf", quiet = FALSE)

#Testing if it worked
pdf("font_plot.pdf", family="Times New Roman", width=4, height=4)
plot(mtcars$mpg, mtcars$wt,
    main = "Fuel Efficiency of 32 Cars",
    xlab = "Weight (x1000 lb)",
    ylab = "Miles per Gallon")
dev.off()

Console output:

`
R version 3.0.2 (2013-09-25) -- "Frisbee Sailing"
Copyright (C) 2013 The R Foundation for Statistical Computing
Platform: x86_64-w64-mingw32/x64 (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> #Create local directory for my packages
> dir.create(path = "M:/PortableSoftware/R-3.0.2/mylibrary")
Warning message:
In dir.create(path = "M:/PortableSoftware/R-3.0.2/mylibrary") :
  'M:\PortableSoftware\R-3.0.2\mylibrary' already exists
> 
> #Set local library for my packages
> my.library <- "M:/PortableSoftware/R-3.0.2/mylibrary"
> 
> #Set repository
> my.repo <- getOption(x = "repos")
> my.repo["CRAN"] <- "http://cran.uib.no/"
> 
> #Install extrafont package
> install.packages(pkgs = "extrafont", lib = my.library, repos = my.repo, dependencies = TRUE, type = "win.binary", verbose = TRUE)
trying URL 'http://cran.uib.no/bin/windows/contrib/3.0/extrafont_0.15.zip'
Content type 'application/zip' length 34007 bytes (33 Kb)
opened URL
downloaded 33 Kb

package ‘extrafont’ successfully unpacked and MD5 sums checked

The downloaded binary packages are in
        C:\Users\sverrej\AppData\Local\Temp\RtmpYrkbZs\downloaded_packages
> 
> #Load extrafont package
> library(package = "extrafont", lib.loc = my.library, verbose = TRUE)
Registering fonts with R
> 
> #Import all .ttf fonts in a given directory
> ttf_import(paths = "M:/MyStuff/Fonts/timesnewroman6.80/")
Scanning ttf files in M:/MyStuff/Fonts/timesnewroman6.80/ ...
Extracting .afm files from .ttf files...
M:\MyStuff\Fonts\timesnewroman6.80\times.ttf : TimesNewRomanPSMT already registered in fonts database. Skipping.
M:\MyStuff\Fonts\timesnewroman6.80\timesbd.ttf : TimesNewRomanPS-BoldMT already registered in fonts database. Skipping.
M:\MyStuff\Fonts\timesnewroman6.80\timesbi.ttf : TimesNewRomanPS-BoldItalicMT already registered in fonts database. Skipping.
M:\MyStuff\Fonts\timesnewroman6.80\timesi.ttf : TimesNewRomanPS-ItalicMT already registered in fonts database. Skipping.
Found FontName for 0 fonts.
Scanning afm files in M:/PortableSoftware/R-3.0.2/mylibrary/extrafontdb/metrics
Warning messages:
1: In readLines(fd, 30) :
  seek on a gzfile connection returned an internal error
2: In readLines(fd, 30) :
  seek on a gzfile connection returned an internal error
3: In readLines(fd, 30) :
  seek on a gzfile connection returned an internal error
4: In readLines(fd, 30) :
  seek on a gzfile connection returned an internal error
> 
> #Verify that the fonts were imported
> fonts()
[1] "Times New Roman"
> fonttable()
  package        afmfile                                           fontfile
1      NA timesbi.afm.gz M:\\MyStuff\\Fonts\\timesnewroman6.80\\timesbi.ttf
2      NA timesbd.afm.gz M:\\MyStuff\\Fonts\\timesnewroman6.80\\timesbd.ttf
3      NA  timesi.afm.gz  M:\\MyStuff\\Fonts\\timesnewroman6.80\\timesi.ttf
4      NA   times.afm.gz   M:\\MyStuff\\Fonts\\timesnewroman6.80\\times.ttf
                     FullName      FamilyName                     FontName  Bold Italic
1 Times New Roman Bold Italic Times New Roman TimesNewRomanPS-BoldItalicMT  TRUE   TRUE
2        Times New Roman Bold Times New Roman       TimesNewRomanPS-BoldMT  TRUE  FALSE
3      Times New Roman Italic Times New Roman     TimesNewRomanPS-ItalicMT FALSE   TRUE
4             Times New Roman Times New Roman            TimesNewRomanPSMT FALSE  FALSE
  Symbol afmsymfile
1  FALSE         NA
2  FALSE         NA
3  FALSE         NA
4  FALSE         NA
> 
> #Register the imported fonts for R's pdf (or postscript) device
> loadfonts(device = "pdf", quiet = FALSE)
Times New Roman already registered with pdfFonts().
> 
> #Testing if it worked
> pdf("font_plot.pdf", family="Times New Roman", width=4, height=4)
Warning messages:
1: In pdf("font_plot.pdf", family = "Times New Roman", width = 4, height = 4) :
  unknown AFM entity encountered
2: In pdf("font_plot.pdf", family = "Times New Roman", width = 4, height = 4) :
  unknown AFM entity encountered
3: In pdf("font_plot.pdf", family = "Times New Roman", width = 4, height = 4) :
  unknown AFM entity encountered
4: In pdf("font_plot.pdf", family = "Times New Roman", width = 4, height = 4) :
  unknown AFM entity encountered
> plot(mtcars$mpg, mtcars$wt,
+ main = "Fuel Efficiency of 32 Cars",
+ xlab = "Weight (x1000 lb)",
+ ylab = "Miles per Gallon")
There were 50 or more warnings (use warnings() to see the first 50)
> dev.off()
null device 
          1 
> warnings()
Warning messages:
1: In axis(side = side, at = at, labels = labels, ...) :
  font width unknown for character 0x6d
2: In axis(side = side, at = at, labels = labels, ...) :
  font width unknown for character 0x31
3: In axis(side = side, at = at, labels = labels, ...) :
  font width unknown for character 0x30
4: In axis(side = side, at = at, labels = labels, ...) :
  font width unknown for character 0x31
5: In axis(side = side, at = at, labels = labels, ...) :
  font width unknown for character 0x30
6: In axis(side = side, at = at, labels = labels, ...) :
  font metrics unknown for character 0x4d
7: In axis(side = side, at = at, labels = labels, ...) :
  font width unknown for character 0x31
8: In axis(side = side, at = at, labels = labels, ...) :
  font width unknown for character 0x35
9: In axis(side = side, at = at, labels = labels, ...) :
  font width unknown for character 0x31
10: In axis(side = side, at = at, labels = labels, ...) :
  font width unknown for character 0x35
11: In axis(side = side, at = at, labels = labels, ...) :
  font width unknown for character 0x32
12: In axis(side = side, at = at, labels = labels, ...) :
  font width unknown for character 0x30
13: In axis(side = side, at = at, labels = labels, ...) :
  font width unknown for character 0x32
14: In axis(side = side, at = at, labels = labels, ...) :
  font width unknown for character 0x30
15: In axis(side = side, at = at, labels = labels, ...) :
  font width unknown for character 0x32
16: In axis(side = side, at = at, labels = labels, ...) :
  font width unknown for character 0x35
17: In axis(side = side, at = at, labels = labels, ...) :
  font width unknown for character 0x32
18: In axis(side = side, at = at, labels = labels, ...) :
  font width unknown for character 0x35
19: In axis(side = side, at = at, labels = labels, ...) :
  font width unknown for character 0x33
20: In axis(side = side, at = at, labels = labels, ...) :
  font width unknown for character 0x30
21: In axis(side = side, at = at, labels = labels, ...) :
  font width unknown for character 0x33
22: In axis(side = side, at = at, labels = labels, ...) :
  font width unknown for character 0x30
23: In axis(side = side, at = at, labels = labels, ...) :
  font width unknown for character 0x6d
24: In axis(side = side, at = at, labels = labels, ...) :
  font width unknown for character 0x32
25: In axis(side = side, at = at, labels = labels, ...) :
  font width unknown for character 0x32
26: In axis(side = side, at = at, labels = labels, ...) :
  font width unknown for character 0x33
27: In axis(side = side, at = at, labels = labels, ...) :
  font width unknown for character 0x33
28: In axis(side = side, at = at, labels = labels, ...) :
  font width unknown for character 0x34
29: In axis(side = side, at = at, labels = labels, ...) :
  font width unknown for character 0x34
30: In axis(side = side, at = at, labels = labels, ...) :
  font width unknown for character 0x35
31: In axis(side = side, at = at, labels = labels, ...) :
  font width unknown for character 0x35
32: In title(...) : font width unknown for character 0x46
33: In title(...) : font width unknown for character 0x75
34: In title(...) : font width unknown for character 0x65
35: In title(...) : font width unknown for character 0x6c
36: In title(...) : font width unknown for character 0x20
37: In title(...) : font width unknown for character 0x45
38: In title(...) : font width unknown for character 0x66
39: In title(...) : font width unknown for character 0x66
40: In title(...) : font width unknown for character 0x69
41: In title(...) : font width unknown for character 0x63
42: In title(...) : font width unknown for character 0x69
43: In title(...) : font width unknown for character 0x65
44: In title(...) : font width unknown for character 0x6e
45: In title(...) : font width unknown for character 0x63
46: In title(...) : font width unknown for character 0x79
47: In title(...) : font width unknown for character 0x20
48: In title(...) : font width unknown for character 0x6f
49: In title(...) : font width unknown for character 0x66
50: In title(...) : font width unknown for character 0x20
> 

The output:

extrafont

Error loading fonts with `font_import()`

Hi Winston,

Did things in this order:

install.packages(c("extrafontdb", "extrafont", "Rttf2pt1"))
library(extrafontdb)
library(Rttf2pt2)
library(extrafont)

font_import()

I get the following error:

Importing fonts may take a few minutes,
depending on the number of fonts and the speed of the system.
Continue? [y/n] y
Scanning ttf files in  ...
Extracting .afm files from .ttf files...
Error in data.frame(fontfile = ttfiles, FontName = "", stringsAsFactors = FALSE):
arguments imply differing number of rows: 0, 1

Any suggestions?

Spaces in filename

Hi,
I would find it extremely helpful if embed_fonts was able to use filenames that have spaces in them. See the example below.
Thanks,
Doug

Example

m <- mtcars[1:10,]
p <- ggplot(m, aes(x = wt, y = mpg, color = hp)) + geom_point()

Works

filename <- "~/Desktop/foo.pdf"
ggsave(filename, p)
embed_fonts(filename)

Does not work

filename <- "~/Desktop/foo 2.pdf"
ggsave(filename, p)
embed_fonts(filename)
Error: /undefinedfilename in (/Users/dougmitarotonda/Desktop/foo)
Operand stack:

Execution stack:
%interp_exit .runexec2 --nostringval-- --nostringval-- --nostringval-- 2 %stopped_push --nostringval-- --nostringval-- --nostringval-- false 1 %stopped_push
Dictionary stack:
--dict:1156/1684(ro)(G)-- --dict:0/20(G)-- --dict:77/200(L)--
Current allocation mode is local
Last OS error: 2
GPL Ghostscript 9.05: Unrecoverable error, exit code 1
Error in embedFonts(file = file, format = format, outfile = outfile, options = paste(paste("-I", :
status 1 in running command 'gs -dNOPAUSE -dBATCH -q -dAutoRotatePages=/None -sDEVICE=pdfwrite -sOutputFile=/var/folders/tc/6t_2yc616dz74f9zpf8cy_hm0000gp/T//Rtmp5ea4Fc/Rembed7a00addeece -sFONTPATH= -I'/Users/dougmitarotonda/R/extrafontdb/fontmap' ~/Desktop/foo 2.pdf'

Cambria regular not being imported

When using the package, almost everything works fine. An exception is the following: I cannot use the Cambria regular font because it never gets imported. It seems to be an odd bug, because it does detect and import the Cambria Bold, Cambria Italic and Cambria Bold Italic fonts, just not the regular.

I keep trying to call "font_import()", and getting:

C:\Windows\Fonts\cambriab.ttf : Cambria-Bold already registered in fonts database. Skipping.
C:\Windows\Fonts\cambriai.ttf : Cambria-Italic already registered in fonts database. Skipping.
C:\Windows\Fonts\cambriaz.ttf : Cambria-BoldItalic already registered in fonts database. Skipping.

No mention, whatsoever, to 'cambria.ttf'. And when I navigate with Windows Explorer to "C:\Windows\Fonts", it is there.

font_import() imports fonts twice if ttf font location includes symlinks (ubuntu)

I have had a problem with the call font_import(pattern="Arial") importing each font twice. This then caused the warning : Warning in load fonts() : More than one version of regular/bold/italic . . ." I was able to manually edit the file /usr/local/lib/R/site-library/extrafontdb/fontmap/fonttable.csv and, sure enough every line was duplicated. I removed every other line and things worked fine. If the dplicates are left in, my ggplot calls fail.

I believe this is because /usr/share/fonts/truetype/msttcorefonts includes lowercase short symbolic links to several MS fonts. I did not want to delete them as I'm not sure who is using those alternative file names (eg arialbd.ttf -> Arial_Bold.ttf), perhaps wine?

perhaps font_import() could check for duplicate files when building fonttable.csv?

This is on kubuntu 13.10

Error in if (grepl("Symbol", FamilyName))

How can I resolve the following error, which I receive during font_import(). I'm using extrafont_0.16:

....
/usr/share/fonts/truetype/unfonts-core/UnPilgiBold.ttf => /usr/local/lib/R/site-library/extrafontdb/metrics/UnPilgiBold
/usr/share/fonts/truetype/unfonts-core/UnPilgi.ttf => /usr/local/lib/R/site-library/extrafontdb/metrics/UnPilgi
/usr/share/fonts/truetype/unifont/unifont.ttf => /usr/local/lib/R/site-library/extrafontdb/metrics/unifont
Found FontName for 1510 fonts.
Scanning afm files in /usr/local/lib/R/site-library/extrafontdb/metrics
Error in if (grepl("Symbol", FamilyName)) Symbol <- TRUE else Symbol <- FALSE :
argument is of length zero
In addition: There were 50 or more warnings (use warnings() to see the first 50)

How to use FontName

It is unclear how to use different fonts from the same family. For example, I have

fonttable()[c(59,81),4:9]
FullName FamilyName FontName Bold Italic Symbol
59 Kievit Medium Kievit Kievit-Medium FALSE FALSE FALSE
81 Kievit Regular Kievit Kievit-Regular FALSE FALSE FALSE

I'm not sure how to specify one or the other in e.g. a pdf file. Is it possible, and if so, can something be noted in the documentation?

Make error when installing Rttf2pt1 freetype2 (experimental support for OTF/TTC)

I tried to use the experimental versions of Rttf2pt1 and extrafont for OTF/TTC support (after http://blog.revolutionanalytics.com/2012/09/how-to-use-your-favorite-fonts-in-r-charts.html):

install_github("Rttf2pt1", "wch", "freetype2")
install_github("extrafont", "wch", "freetype")

The second package installs fine, but the first one returns:

Error: Command failed (1)
make: invalid option -- g
make: invalid option -- O
make: invalid option -- 2
make: invalid option -- a
make: invalid option -- c

make: *** [all] Error 2
ERROR: compilation failed for package 'Rttf2pt1'

Also, running font_import() now returns No FontName. Skipping. for every font, even for the standard ones it would normally find (running install.packages("extrafont") doesn't solve the problem)

Running R 3.0.2 on OS X 10.8.5

No font could be found

I loaded the xkcd font into the current directory. Following steps:

font_import(".", prompt = F)
loadfonts()
# Registering font with R using pdfFonts(): xkcd
ggplot(data = tg, aes(dose, len)) + geom_point() + theme(text=element_text(size=16, family="xkcd"))

# Error in grid.Call(L_textBounds, as.graphicsAnnot(x$label), x$x, x$y,  : 
#  polygon edge not found
# In addition: Warning message:
# In grid.Call(L_textBounds, as.graphicsAnnot(x$label), x$x, x$y,  :
#  no font could be found for family "xkcd"

fonts()
# [1] "xkcd"

fonttable()
#  package     afmfile                                                   fontfile FullName
#1      NA xkcd.afm.gz /Users/mac/Documents/statinference-course-project/xkcd.ttf     xkcd
#  FamilyName FontName  Bold Italic Symbol afmsymfile
#1       xkcd     xkcd FALSE  FALSE  FALSE         NA

What could possibly go wrong?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.