vl_strwidth() / vl_strheight() return the rendered width/height of each
string, using the same shaping (textshaping/HarfBuzz + systemfonts)
the renderer uses, so measurements match drawn text. Device-independent (does
not need an open scene). Vectorised over label. (Named vl_* to avoid masking
grDevices::strwidth().)
Usage
vl_strwidth(
label,
family = "",
fontface = "plain",
fontsize = 12,
cex = 1,
unit = "in",
features = NULL
)
vl_strheight(
label,
family = "",
fontface = "plain",
fontsize = 12,
cex = 1,
unit = "in",
features = NULL
)Arguments
- label
Character vector of strings to measure, or a rich label from
md()(or a list of them). Rich labels are measured with the same run composition the renderer draws, so super/subscripts and bold runs are accounted for;family/fontface/fontsizethen supply the base style the label's runs are relative to.- family
Font family (e.g.
"sans","serif","mono", or a specific family name).""uses the system default.- fontface
One of
"plain","bold","italic","bold.italic".- fontsize
Font size in points.
- cex
Multiplier applied to
fontsize.- unit
Output unit: one of
"in","pt","mm","cm".- features
OpenType features as a named vector of four-character tags (e.g.
c(tnum = 1)), matchingvl_gpar()'sfeatures. Measurement must use the same features as drawing, or reserved space will not match.
Examples
vl_strwidth(c("short", "a longer label"), fontsize = 14)
#> [1] 0.499566 1.332248
