Skip to contents

Check systemfonts family for freetype compatibility

Usage

check_systemfonts_family(family = "Arial", path = NULL, debug = FALSE, ...)

Arguments

family

character vector with font family names.

path

character, default NULL, with optional file path to one or more specific font files. When provided, the 'family' argument is ignored.

debug

logical whether to print any error message, default is FALSE.

...

additional arguments are passed to systemfonts::font_info(), which may be useful to specify arguments such as: italic=TRUE, weight="bold", or width="condensed" for example. Alternatively, argument path can be used to point to a specific font file, thereby circumventing family and style.

Value

integer vector with the number of valid font info rows returned by systemfonts::font_info(), for each entry provided in family.

Details

This function simply checks whether the systemfonts API for freetype recognizes a font file being valid, given a font family value. The main purpose is to avoid trying to use a font family which would may produce an error, since it may terminate the R session.

It is thin a wrapper for systemfonts::font_info().

When a font 'fails' it causes an error that can be reviewed with argument debug=TRUE. The error is usually this format:

"Failed to open font file (/font/path/family.ttf) with freetype error 6"

The error originates from the freetype API, and means the file is not usable by that API. It sometimes happens when a font file has a newer format than is recognized by the freetype API.

Examples

check_systemfonts_family(c("Noto Sans Syriac", "Skia", "PingFang TC", "Arial"))
#> Noto Sans Syriac             Skia      PingFang TC            Arial 
#>                0                0                0                1 

check_systemfonts_family(c("Arial", "Arial"))
#> Arial Arial 
#>     1     1 

xpaths <- subset_systemfonts(grepl("Helvetica", family), trim_path=FALSE)$path
check_systemfonts_family(xpaths[1])
#> /System/Library/Fonts/Helvetica.ttc 
#>                                   1