I need to ship a package with graphs and the client insists on using its own licensed font. The graphs have to be rendered as EPS and sent to the layout people for the reports.
I have the .ttf files for the font, with names like this :
I also have .eot, .svg and .woff versions of these files.
So I tried the extrafont
package :
ttf_import('Path/To/ttfFiles')
fonts()
[1] "FontNameSans-Bold" "FontNameSans-Light"
[3] "FontNameSans-Medium" "FontNameSans-Regular"
[5] "FontNameSerif-Bold" "FontNameSerif-Light"
[7] "FontNameSerif-Medium" "FontNameSerif-Regular"
I expected to see two families, but that obviously didn't work.
In the end, the ttf files should be included in a subfolder of the inst
folder and I should have something like:
.onLoad({
font_import(file.path(system.file(package = 'mypackage'),
"fontdir")
)
# something else to create a family FontName for
# use with postscript() or cairo_ps()
loadfonts()
})
So I can then later do:
setEPS()
postscript('somefile.eps', family = 'FontName Sans')
plot(mydata)
dev.off()
embed_fonts('somefile.eps', outfile = 'somefile-embedded.eps')
Question : What extra steps do I have to take in order to make the families available just like any other family?
EDIT: I am aware that I have to load the fonts before I can use them. But I can't load the family if it's registered wrong. The question is about registering the font family correctly so the rest works as it should.
This answer is a bit late and probably you don't need it anymore. But this might be of interest for other users on the search.
Depending on your operating system you need to perform different steps. I have a package that includes several fonts in inst/extdata/fonts/some-fonts.ttf
.
.ttf
files manually to C:/Windows/Fonts.To load the fonts when the package is loaded I adapted the .onLoad
function:
.onLoad <- function(libname, pkgname) {
if (Sys.info()[1] == "Linux") {
dir.create('~/.fonts')
file.copy("inst/extdata/fonts/some-fonts.ttf", "~/.fonts")
system('fc-cache -f ~/.fonts')
}
if (Sys.info()[1] == "Windows") {
windowsFonts()
extrafont::font_import(pattern = "some-fonts", prompt = FALSE)
extrafont::loadfonts(device = "win")
windowsFonts()
}
print(extrafont::fonts())
}
extrafont::font_import
and to register them using extrafont::loadfonts(device = "win")
.Hope this helps you, others or my future self. ;-)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With