[R] How to load fonts in text3d?

Duncan Murdoch murdoch.duncan at gmail.com
Mon Mar 27 21:21:14 CEST 2017


On 27/03/2017 1:09 PM, olsen wrote:
> I'm trying to run the example given in ?text3d as follows:
>
> library(rgl)
> open3d()
> famnum <- rep(1:4, 8)
> family <- c("serif", "sans", "mono", "symbol")[famnum]
> font <- rep(rep(1:4, each = 4), 2)
> cex <- rep(1:2, each = 16)
> text3d(font, cex, famnum, text = paste(family, font), adj = 0.5,
>        color = "blue", family = family, font = font, cex = cex)
>
> This results in a couple of warning messages of the following kind:
>
> In rgl.texts(x = c(1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 3L,  ... :
>   font family "serif" not found, using "bitmap"
>
> I would like to use another font instead of bitmap but it seems to
> switchback to bitmap whatever argument I give as family e.g. 'family =
> "FreeSans"'.
> Wonder if this is a bug or I'm doing something wrong.
>
> This is on
> R version 3.3.2 (2016-10-31)
> Platform: x86_64-pc-linux-gnu (64-bit)
> Running under: Debian GNU/Linux 9 (stretch)
> with the following rgl version loaded:
> [1] rgl_0.96.0

What do you see if you run rglFonts()?  It should list the fonts you 
have installed.  On MacOS, I see

 > rglFonts()
$serif
[1] 
"/Library/Frameworks/R.framework/Versions/3.3/Resources/library/rgl/fonts/FreeSerif.ttf"
[2] 
"/Library/Frameworks/R.framework/Versions/3.3/Resources/library/rgl/fonts/FreeSerif.ttf"
[3] 
"/Library/Frameworks/R.framework/Versions/3.3/Resources/library/rgl/fonts/FreeSerif.ttf"
[4] 
"/Library/Frameworks/R.framework/Versions/3.3/Resources/library/rgl/fonts/FreeSerif.ttf"

$sans
[1] 
"/Library/Frameworks/R.framework/Versions/3.3/Resources/library/rgl/fonts/FreeSans.ttf"
[2] 
"/Library/Frameworks/R.framework/Versions/3.3/Resources/library/rgl/fonts/FreeSans.ttf"
[3] 
"/Library/Frameworks/R.framework/Versions/3.3/Resources/library/rgl/fonts/FreeSans.ttf"
[4] 
"/Library/Frameworks/R.framework/Versions/3.3/Resources/library/rgl/fonts/FreeSans.ttf"

$mono
[1] 
"/Library/Frameworks/R.framework/Versions/3.3/Resources/library/rgl/fonts/FreeMono.ttf"
[2] 
"/Library/Frameworks/R.framework/Versions/3.3/Resources/library/rgl/fonts/FreeMono.ttf"
[3] 
"/Library/Frameworks/R.framework/Versions/3.3/Resources/library/rgl/fonts/FreeMono.ttf"
[4] 
"/Library/Frameworks/R.framework/Versions/3.3/Resources/library/rgl/fonts/FreeMono.ttf"

$symbol
[1] 
"/Library/Frameworks/R.framework/Versions/3.3/Resources/library/rgl/fonts/FreeSerif.ttf"
[2] 
"/Library/Frameworks/R.framework/Versions/3.3/Resources/library/rgl/fonts/FreeSerif.ttf"
[3] 
"/Library/Frameworks/R.framework/Versions/3.3/Resources/library/rgl/fonts/FreeSerif.ttf"
[4] 
"/Library/Frameworks/R.framework/Versions/3.3/Resources/library/rgl/fonts/FreeSerif.ttf"

If you don't have Freetype installed on your system, you won't be able 
to use any of those.

Duncan Murdoch



More information about the R-help mailing list