Import web fonts into a bs_theme()
When used with any of the main font settings in bs_theme() (e.g.,
base_font, code_font, heading_font), these font objects ensure relevant
font file resources are included with the theme. A particular font object should
define an single font family — if you need multiple families, a list() of
font objects may be provided to bs_theme().
font_face(
family,
src,
weight = NULL,
style = NULL,
display = c("swap", "auto", "block", "fallback", "optional"),
stretch = NULL,
variant = NULL,
unicode_range = NULL
)
font_link(family, href)
font_google(
family,
local = TRUE,
cache = sass_file_cache(dir = cache_context_dir(), max_size = 100 * 1024^2),
wght = NULL,
ital = NULL,
display = c("swap", "auto", "block", "fallback", "optional")
)family |
A character string with a single font family name. |
src |
A character vector for the |
weight |
A character (or numeric) vector for the |
style |
A character vector for the |
display |
the |
stretch |
A character vector for the |
variant |
A character vector for the |
unicode_range |
A character vector for |
href |
A URL resource pointing to the font data. |
local |
Whether or not download and bundle local (woff) font files. |
cache |
A |
wght |
One of the following:
|
ital |
One of the following:
|
a list with a special class.
With local (i.e., self-hosted) fonts, clients (i.e., end users) can render
fonts without an internet connection. By default, google_font() will
automatically download, cache, and serve font files locally. Non-Google fonts
may also be served locally, but you'll have to download and serve local file
using something like shiny::addResourcePath() (or similar) and provide the
relevant files to a font_face() definiton.
With remotely hosted fonts, clients (i.e., end users) need an internet
connection to render the fonts. Remote fonts can be implemented using
font_google(..., local = FALSE) (hosted via Google), font_link() (hosted
via href URL), or font_face() (hosted via src URL).
# If you have an internet connection, running the following code
# will download, cache, and import the relevant Google Font files
# for local use
theme <- bs_theme(
base_font = font_google("Fira Sans"),
code_font = font_google("Fira Code"),
heading_font = font_google("Fredoka One")
)
if (interactive()) {
bs_theme_preview(theme)
}
# Three different yet equivalent ways of importing a remotely-hosted Google Font
a <- font_google("Crimson Pro", wght = "200..900", local = FALSE)
b <- font_link(
"Crimson Pro",
href = "https://fonts.googleapis.com/css2?family=Crimson+Pro:wght@200..900"
)
url <- "https://fonts.gstatic.com/s/crimsonpro/v13/q5uDsoa5M_tv7IihmnkabARboYF6CsKj.woff2"
c <- font_face(
family = "Crimson Pro",
style = "normal",
weight = "200 900",
src = paste0("url(", url, ") format('woff2')")
)
theme <- bs_theme(base_font = c)
if (interactive()) {
bs_theme_preview(theme)
}Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.