Learn R Programming

systemfonts (version 1.1.0)

match_fonts: Find a system font by name and style

Description

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)

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.

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, or 900) 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, or 9) 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

Examples

Run this code
# Get the system default sans-serif font in italic
match_fonts('sans', italic = TRUE)

# Try to match it to a thin variant
match_fonts(c('sans', 'serif'), weight = "thin")

Run the code above in your browser using DataLab