font_add_google | R Documentation |
The two versions of this function are equivalent, but the "underscore" naming is preferred.
This function will search the Google Fonts repository (https://fonts.google.com/) for a specified family name, download the proper font files, and then add them to sysfonts. This function requires the jsonlite and curl packages.
font_add_google(
name,
family = name,
regular.wt = 400,
bold.wt = 700,
repo = "http://fonts.gstatic.com/",
db_cache = TRUE,
handle = curl::new_handle()
)
font.add.google(
name,
family = name,
regular.wt = 400,
bold.wt = 700,
repo = "http://fonts.gstatic.com/",
handle = curl::new_handle()
)
name |
name of the font that will be searched in Google Fonts |
family |
specifies the family name of this font in R. This can be any string,
not necessarily the same as |
regular.wt |
font weight for the regular font face, usually 400 |
bold.wt |
font weight for the bold font face, usually 700 |
repo |
the site that hosts the font files. Default is the official
repository |
db_cache |
whether to obtain font metadata from a cache site. Using cache
is typically faster, but not as update-to-date as using the official
API. If |
handle |
a curl handle object passed to |
There are thousands of open source fonts in the Google Fonts
repository (https://fonts.google.com/).
This function will try to search the font family specified
by the name
argument, and then automatically
download the font files for all possible font faces
("regular", "bold", "italic" and "bold italic",
but no"symbol").
If fonts are found and downloaded successfully, they will be
also added to sysfonts with the given family name.
Yixuan Qiu <https://statr.me/>
font_families_google()
## Not run:
font_add_google("Alegreya Sans", "aleg")
if(require(showtext))
{
wd = setwd(tempdir())
pdf("google-fonts-ex.pdf")
showtext_begin()
par(family = "aleg")
plot(0:5,0:5, type="n")
text(1:4, 1:4, "Alegreya Sans", font=1:4, cex = 2)
showtext_end()
dev.off()
setwd(wd)
}
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.