status R build
status Coverage

The package gdtools provides functionalities to get font metrics and to generate base64 encoded string from raster matrix. It is used by package ggiraph 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).


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


And the development version from GitHub with:

# install.packages("devtools")


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

For mac os users

This package needs X11 to be available on mac os machines. This will make cairo, font-config and other system dependancies available. This is documented here: R for Mac OS X ; X11 can be downloaded from XQuartz website.

Try the gdtools package in your browser

Any scripts or data that you put into this service are public.

gdtools documentation built on March 18, 2022, 7:12 p.m.