Skip to contents

Used to gate font-dependent code paths and tests, and by ct_theme() to walk its font_fallback chain.

Usage

has_font(name)

Arguments

name

Font family name, as it appears in the family column of systemfonts::system_fonts() or systemfonts::registry_fonts().

Value

TRUE if name matches an available family, FALSE otherwise. Vectorised over name.

Details

Checks both font tables systemfonts maintains: families installed on the operating system (systemfonts::system_fonts()) and families registered for the current session with systemfonts::register_font() (systemfonts::registry_fonts()). Registered fonts do not appear in the system table, so checking only that one would silently reject a corporate font a user had registered from a file rather than installed.

Examples

has_font("Arial")
#> [1] FALSE

# Registered fonts count as available, so a client brand font you
# register from a file can be used by name:
if (FALSE) { # \dontrun{
systemfonts::register_font("ClientSans", plain = "~/fonts/ClientSans.ttf")
has_font("ClientSans")
ct_theme(font = "ClientSans")
} # }