Package 'extrafont'

Title: Tools for Using Fonts
Description: Tools to using fonts other than the standard PostScript fonts. This package makes it easy to use system TrueType fonts and with PDF or PostScript output files, and with bitmap output files in Windows. extrafont can also be used with fonts packaged specifically to be used with, such as the fontcm package, which has Computer Modern PostScript fonts with math symbols.
Authors: Winston Chang <[email protected]>
Maintainer: Winston Chang <[email protected]>
License: GPL-2
Version: 0.19
Built: 2024-10-09 02:42:23 UTC
Source: https://github.com/wch/extrafont

Help Index


Choose an installed font from a list

Description

For a sequence of font family names, return the first one installed on the system. This makes it easy for code to specify a preferred font-family, but fall back to other font families if that is not installed on the system. This function acts much like the CSS font-family property.

Usage

choose_font(fonts, quiet = TRUE)

Arguments

fonts

character List of font family names to try.

quiet

logical Do not print warning if the preferred font not found.

Value

character. First font in fonts that is installed on the system or "" if none of those are installed.

Examples

choose_font(c("GillSans",  "Verdana", "sans"), quiet = TRUE)
choose_font(c("BemeboStd", "Garamond", "serif"), quiet = TRUE)

Embeds fonts that are listed in the local Fontmap

Description

Embeds fonts that are listed in the local Fontmap

Usage

embed_fonts(file, format, outfile = file, options = "")

Arguments

file

Name of input file.

format

File format. (see ?embedFonts)

outfile

Name of the output file (with fonts embedded). (Default is same as input file)

options

Other arguments passed to embedFonts.

See Also

loadfonts

Examples

## Not run: 
loadfonts()
pdf('fonttest.pdf')
library(ggplot2)

p <- ggplot(mtcars, aes(x=wt, y=mpg)) + geom_point()

# Run only the code below that is appropriate for your system
# On Mac and Windows, Impact should be available
p + opts(axis.title.x=theme_text(size=16, family="Impact", colour="red"))

# On Linux, Purisa may be available
p + opts(axis.title.x=theme_text(size=16, family="Purisa", colour="red"))
dev.off()

embed_fonts('fonttest.pdf', outfile='fonttest-embed.pdf')

## End(Not run)

extrafont package

Description

This package is used for using and embedding fonts other than the basic Postscript fonts.

Details

For use instructions, see https://github.com/wch/extrafont.


Add font from an installed package to fonts database

Description

This is usually not called directly, but via font_install.

Usage

font_addpackage(pkg = NULL)

Arguments

pkg

The name of the font package, e.g., "fontcm".

See Also

font_install


Import system fonts

Description

Presently only supports TrueType fonts.

Usage

font_import(paths = NULL, recursive = TRUE, prompt = TRUE, pattern = NULL)

Arguments

paths

A vector of directories to search in. (Default is to auto-detect based on OS)

recursive

Search recursively in directories? (Default TRUE)

prompt

Show confirmation prompt? (Default TRUE)

pattern

A regular expression that the filenames must match.

Examples

font_import()

Install a font package and register it in the fonts database

Description

If the font package specified by fontpkg is not already installed, it will be downloaded from CRAN. The font package will then be registered in the fonts database.

Usage

font_install(fontpkg = NULL, prompt = TRUE)

Arguments

fontpkg

The name of an R package containing a font, e.g., "fontcm".

prompt

Ask user to install font from CRAN if not already installed

Examples

## Not run: 
font_install('fontcm')

## End(Not run)

Show the fonts that are registered in the font table (and available for embedding)

Description

Show the fonts that are registered in the font table (and available for embedding)

Usage

fonts()

Returns the full font table

Description

Returns the full font table

Usage

fonttable()

Reads the fonttable database and registers those fonts with R

Description

This registers fonts so that they can be used with the pdf, postscript, or Windows bitmap output device. It must be run once in each R session.

Usage

loadfonts(device = c("all", "pdf", "postscript", "win"), quiet = FALSE)

Arguments

device

The output device. If "all", then it will load "pdf", "postscript", and "win" (if on Windows).

quiet

If FALSE, print a status message as each font is registered. If TRUE, don't print.

Value

A named list with up to three elements, one for each device for which fonts were loaded. Each device element is a named list, with an element for each family that was the function attempted to register with that device. The value is NULL if the function did not register the font family due to problems or because the font family was already registered. If value is the return value of windowsFonts for "win", postscriptFonts for "postscript", and pdfFonts for "pdf".

See Also

embed_fonts, #ifdef windows windowsFont, windowsFonts, #endif postscriptFonts, pdfFonts, Type1Font.


Imports all TrueType fonts in a directory and all subdirectories

Description

Imports all TrueType fonts in a directory and all subdirectories

Usage

ttf_import(paths = NULL, recursive = TRUE, pattern = NULL)

Arguments

paths

A vector of directories to search in. (Default is to auto-detect based on OS)

recursive

Search recursively in directories? (Default TRUE)

pattern

A regular expression that the filenames must match.