Learn R Programming

gdtools

The package gdtools provides functionalities to get font metrics and to generate base64 encoded string from raster matrix. It is used by package ‘flextable’ and ‘rvg’ to allow font metric calculation but can also be used to compute the exact size a text would have with specific font options (size, bold, italic).

library(gdtools)
str_extents(c("a string", "a longer string"), 
  fontsize = 24, bold = TRUE, italic = TRUE)
#>           [,1]     [,2]
#> [1,]  86.68359 22.60547
#> [2,] 166.68750 22.60547

Another set of functions is provided to support the collection of fonts from ‘Google Fonts’ in a cache. Their use is simple within ‘R Markdown’ documents and ‘shiny’ applications but also with graphic productions generated with the ‘ggiraph’, ‘ragg’ and ‘svglite’ packages or with tabular productions from the ‘flextable’ package.

# Download to a user cache and register the font with systemfonts
register_gfont(family = "Open Sans")

If you need a ‘Google Font’ to be installed on your machine, you can use install_gfont_script().

install_gfont_script("Fira Sans", file = "firafont.sh")

You then have to run ./firafont.sh.

Installation

You can install the released version of gdtools from CRAN with:

install.packages("gdtools")

And the development version from GitHub with:

# install.packages("remotes")
remotes::install_github("davidgohel/gdtools")

Copy Link

Version

Install

install.packages('gdtools')

Monthly Downloads

77,084

Version

0.4.0

License

GPL-3 | file LICENSE

Maintainer

Last Published

August 28th, 2024

Functions in gdtools (0.4.0)

raster_str

Draw/preview a raster into a string
fonts_cache_dir

manage font working directory
str_extents

Compute string extents.
install_gfont_script

Shell command to install a font from 'Google Fonts'
installed_gfonts

List installed 'Google Fonts'
register_liberationsans

Register font 'Liberation Sans'
set_dummy_conf

Set and unset a minimalistic Fontconfig configuration
str_metrics

Get font metrics for a string.
gfontHtmlDependency

'Google Font' HTML dependency
glyphs_match

Validate glyph entries
liberationsansHtmlDependency

'Liberation Sans' Font HTML dependency
m_str_extents

Compute string extents for a vector of string.
sys_fonts

List fonts for 'systemfonts'.
version_freetype

Version numbers of C libraries
dummy_setup

dummy 'Google Fonts' cache
fontconfig_reinit

reload Fontconfig configuration
font_family_exists

Check if font family exists.
addGFontHtmlDependency

Use a font in Shiny or Markdown
raster_write

Draw/preview a raster to a png file
register_gfont

Register a 'Google Fonts'
match_family

Find best family match with systemfonts
check_gfonts

Checks the operability of 'gfonts'