Set of Installed Fonts

Provides a set of fonts with permissive licences. This is useful when you want to avoid system fonts to make sure your outputs are reproducible.


fontquiver installs a set of fonts with permissive licences. It is useful for packages that needs controlled versions of fonts.

Installation

Get the development version from github with:

# install.packages("devtools")
devtools::install_github("lionel-/fontquiver")

Usage

Fonts installed in R packages

fontquiver is an interface to fonts installed as R packages. It provides convenient and structured access, for instance, to the Bitstream Vera font family installed with the fontBitstreamVera package, or the Liberation family that comes with fontLiberation. The fonts too heavy to be distributed on CRAN can be accessed by fontquiver through Github-only packages such as fontDejaVu. Each package bundles a set of fonts (or fontset as they are called in fontquiver) which typically includes bold and italic faces for sans and serif fonts, but may also include more exotic variations (condensed, ultra light, etc). Call fontset_list() to check which fontsets are currently installed on your computer.

Fonts installed in the R library can be useful for a variety of purposes. They can be used in web applications with the htmlFontDependency() tool. They are also helpful to create reproducible outputs. An example of this is the vdiffr package which relies on fontquiver to create SVGs that are reproducible across platforms. Without fontquiver fonts, the SVGs generated by svglite would have slight differences depending on the versions of the system fonts used to compute text metrics.

Categories of fonts

The standard categories of fonts in R are the sans, serif, and mono families and the plain, italic, bold, and bolditalic faces. However, font nomenclatures are extremely rich and go well beyond those 12 categories. For example the DéjàVu set contains a font whose variant and style are Serif Condensed and Extra Light. For this reason, fontquiver uses the categories provided by the font util fc-scan from Fontconfig. The terms "variants" and "styles" refer to those categories while "families" and "faces" refer to R's categories.

To check which variants and styles are available for a given fontset:

fontset_variants("DejaVu")
fontset_styles("Bitstream Vera", variant = "Serif")

Font getters

fontquiver provides several getters to access font objects. They all take a fontset name as argument. They may also take variant/style or family/face arguments.

font() takes a fontest, a variant and a style, and returns an atomic font object. Those objects contain fields such as ttf, fullname, or version:

font("Bitstream Vera", "Sans", "Roman")
font("Bitstream Vera", "Serif", "Bold")$ttf

The other getters return collections of fonts. font_variants() returns a tree of lists with the outer list containing all variants of a fontset and the inner lists containing all styles for a given variant. Similarly, font_families() returns a tree of fonts structured according to families and faces:

font_variants("Liberation")
font_families("Liberation")

If you need a specific variant or family, font styles() and font_faces() return a list of fonts:

font_styles("DejaVu", "Sans Condensed")
font_faces("DejaVu", "Mono")

Applications

Web dependency on an installed font

The htmlFontDependency() tool takes any font object or collection of font objects. It copies the relevant fonts in woff format to a temporary directory and creates a CSS linking to those fonts.

# install.packages("htmltools")
 
# Create font dependency
liberation <- font_families("Liberation")
mono <- font_styles("DejaVu", "Sans Mono")
html_dep <- htmlFontDependency(liberation, mono)
 
span_mono <- htmltools::tags$span(
  style = "font-family:'Deja Vu Sans Mono'; font-style:italic;",
  "Text rendered with monospace italic font"
)
span_bold <- htmltools::tags$span(
  style = "font-family:'Bitstream Vera Sans'; font-weight:700;",
  "Text rendered with sans bold font"
)
 
# Add font dependency to an HTML object and print
text <- htmltools::div(span_mono, span_bold, html_dep)
htmltools::html_print(text)

User fonts in svglite

You can supply fontquiver fonts to svglite:

svglite::stringSVG(user_fonts = font_families("Liberation"), {
  plot(1:10)
})

See the fonts vignette in the svglite package for more about this.

News

fontquiver 0.2.1

  • Set minimum R version to 3.0.0.

fontquiver 0.2.0

  • Add Liberation and Symbola fonts

  • Removed font_bitstream_vera() and font_dejavu() getters. They are replaced by a family of generic font getters: font() to retrieve the font for a given variant and style, and fonts() to retieve all fonts defined in a fontset.

  • Add font_families() and font_faces() to retrieve font files organised according to R's nomenclature of fonts. Conversely there is now font_variants() and font_styles() which organise fonts according to fontconfig's categories. Also, font_symbol() allows to retrieve a symbol font defined by a fontset (currently only the Symbola fontset defines one).

  • htmlFontDependency() now takes fonts and collections of fonts (as returned by font_families() and friends) as argument.

  • htmlFontDependency() now uses the style-linking idiom for generating CSS.

fontquiver 0.1.0

Initial release

  • Add font_bitstream_vera() and font_dejavu(). The latter require installing the fontDejaVu package from Github: devtools::install_github("lionel-/fontDejaVu").

  • Implement htmlFontDependency() to include font dependency in web pages or applications.

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("fontquiver")

0.2.1 by Lionel Henry, 2 years ago


Browse source code at https://github.com/cran/fontquiver


Authors: Lionel Henry [cre, aut] , RStudio [cph] , George Douros [cph] (Symbola font)


Documentation:   PDF Manual  


GPL-3 | file LICENSE license


Imports fontBitstreamVera, fontLiberation

Suggests testthat, htmltools


Imported by freetypeharfbuzz, vdiffr.

Suggested by gdtools, ggExtra, svglite.


See at CRAN