Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

text_width

Calculate the width of a string, ignoring new-lines


Description

This is a very simple alternative to shape_string() that simply calculates the width of strings without taking any newline into account. As such it is suitable to calculate the width of words or lines that has already been splitted by \n. Input is recycled to the length of strings.

Usage

text_width(
  strings,
  family = "",
  italic = FALSE,
  bold = FALSE,
  size = 12,
  res = 72,
  include_bearing = TRUE,
  path = NULL,
  index = 0
)

Arguments

strings

A character vector of strings

family

The name of the font family

italic

logicals indicating the font style

bold

logicals indicating the font style

size

The pointsize of the font to use for size related measures

res

The ppi of the size related mesures

include_bearing

Logical, should left and right bearing be included in the string width?

path

path an index of a font file to circumvent lookup based on family and style

index

path an index of a font file to circumvent lookup based on family and style

Value

A numeric vector giving the width of the strings in pixels. Use the provided res value to convert it into absolute values.

Examples

strings <- c('A short string', 'A very very looong string')
text_width(strings)

textshaping

Bindings to the 'HarfBuzz' and 'Fribidi' Libraries for Text Shaping

v0.3.4
MIT + file LICENSE
Authors
Thomas Lin Pedersen [cre, aut] (<https://orcid.org/0000-0002-5147-4711>), RStudio [cph]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.