This function locates the font file (and index) best matching a name and
optional style. A font file will be returned even if a perfect match
isn't found, but it is not necessarily similar to the requested family and
it should not be relied on for font substitution. The aliases "sans"
,
"serif"
, "mono"
, "symbol"
, and "emoji"
match to their respective
system defaults (""
is equivalent to "sans"
). match_font()
has been
deprecated in favour of match_fonts()
which provides vectorisation, as well
as querying for different weights (rather than just "normal" and "bold") as
well as different widths.
Usage
match_fonts(family, italic = FALSE, weight = "normal", width = "undefined")
match_font(family, italic = FALSE, bold = FALSE)
Arguments
- family
The name of the font families to match
- italic
logical indicating the font slant
- weight
The weight to query for, either in numbers (
0
,100
,200
,300
,400
,500
,600
,700
,800
, or900
) or strings ("undefined"
,"thin"
,"ultralight"
,"light"
,"normal"
,"medium"
,"semibold"
,"bold"
,"ultrabold"
, or"heavy"
).NA
will be interpreted as"undefined"
/0
- width
The width to query for either in numbers (
0
,1
,2
,3
,4
,5
,6
,7
,8
, or9
) or strings ("undefined"
,"ultracondensed"
,"extracondensed"
,"condensed"
,"semicondensed"
,"normal"
,"semiexpanded"
,"expanded"
,"extraexpanded"
, or"ultraexpanded"
).NA
will be interpreted as"undefined"
/0
- bold
logical indicating whether the font weight
Value
A list containing the paths locating the font files, the 0-based index of the font in the files and the features for the font in case a registered font was located.
Examples
# Get the system default sans-serif font in italic
match_fonts('sans', italic = TRUE)
#> # A tibble: 1 × 3
#> path index features
#> <chr> <int> <list>
#> 1 /usr/share/fonts/truetype/dejavu/DejaVuSans-Oblique.ttf 0 <font_ftr>
# Try to match it to a thin variant
match_fonts(c('sans', 'serif'), weight = "thin")
#> # A tibble: 2 × 3
#> path index features
#> <chr> <int> <list>
#> 1 /usr/share/fonts/truetype/dejavu/DejaVuSans-ExtraLight… 0 <font_ftr>
#> 2 /usr/share/fonts/truetype/dejavu/DejaVuSerif.ttf 0 <font_ftr>