Learn R Programming

gdtools (version 0.5.0)

strings_sizes: Compute strings sizes

Description

Determines widths, ascent and descent in inches. Font lookup is performed by 'systemfonts' (so any font registered via systemfonts::register_font(), register_gfont(), or font_set() is found), then Cairo computes the actual metrics. The results are accurate for devices whose rendering finds the same font -- this is guaranteed for 'systemfonts'-based devices (ragg, svglite, ggiraph) and true for Cairo devices (cairo_pdf(), ...) when the font is also installed at the system level. For devices with their own font engine (pdf(), png(), ...) the metrics may not match the rendering.

Usage

strings_sizes(
  x,
  fontname = "sans",
  fontsize = 10,
  bold = FALSE,
  italic = FALSE
)

Arguments

x

A character vector of strings to measure. All arguments are vectorized and recycled to match the length of x.

fontname

A character vector specifying the font family name (e.g., "sans", "serif", "mono"). Default is "sans". This argument is vectorized.

fontsize

A numeric vector specifying the font size in points. Default is 10. This argument is vectorized.

bold

A logical vector indicating whether the text should be bold. Default is FALSE. This argument is vectorized.

italic

A logical vector indicating whether the text should be italic. Default is FALSE. This argument is vectorized.

See Also

Other functions for font metrics: m_str_extents(), str_metrics()

Examples

Run this code
strings_sizes(letters)
strings_sizes("Hello World!", bold = TRUE, italic = FALSE,
  fontname = "sans", fontsize = 12)

Run the code above in your browser using DataLab