Skip to contents

get_embedded_font() returns which font is actually embedded by cairo_pdf() for a given character. has_font() tries to determine if a given font is available on the OS.

Usage

get_embedded_font(font, char)

has_font(font)

Arguments

font

A character vector of font(s).

char

A character vector of character(s) to be embedded by grid::grid.text()

Value

get_embedded_font() returns character vector of fonts that were actually embedded by cairo_pdf(). NA's means no embedded font detected: this either means that no font was found or that a color emoji font was found and instead of a font an image was embedded.

Details

get_embedded_font() depends on the suggested pdftools package being installed and R being compiled with Cairo support. has_font() depends on either the suggested systemfonts (preferred) or pdftools packages being installed.

Examples

 if (requireNamespace("pdftools", quietly = TRUE) &&
     capabilities("cairo") &&
     !piecepackr:::is_cairo_maybe_buggy()) {
   chars <- c("a", "\u2666")
   fonts <- c("sans", "Sans Noto", "Noto Sans", "Noto Sans Symbols2")
   try(get_embedded_font(fonts, chars))
 }
#>   char     requested_font            embedded_font
#> 1    a               sans       NimbusSans-Regular
#> 2    ♦               sans       NimbusSans-Regular
#> 3    a          Sans Noto               DejaVuSans
#> 4    ♦          Sans Noto               DejaVuSans
#> 5    a          Noto Sans         NotoSans-Regular
#> 6    ♦          Noto Sans               DejaVuSans
#> 7    a Noto Sans Symbols2               DejaVuSans
#> 8    ♦ Noto Sans Symbols2 NotoSansSymbols2-Regular

 if (requireNamespace("systemfonts", quietly = TRUE) ||
     (requireNamespace("pdftools", quietly = TRUE) &&
      capabilities("cairo")) && !piecepackr:::is_cairo_maybe_buggy()) {
   try(has_font("Dejavu Sans"))
 }
#> [1] TRUE