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.
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
strings_sizes(letters)
#> width ascent descent
#> 1 0.07791667 0.07569444 0.0013888889
#> 2 0.08541667 0.10555556 0.0013888889
#> 3 0.06666667 0.07583333 0.0013888889
#> 4 0.08541667 0.10555556 0.0013888889
#> 5 0.07833333 0.07583333 0.0013888889
#> 6 0.04777778 0.10625000 0.0000000000
#> 7 0.08541667 0.07583333 0.0333333333
#> 8 0.08583333 0.10555556 0.0000000000
#> 9 0.03583333 0.10236111 0.0000000000
#> 10 0.03583333 0.10236111 0.0333333333
#> 11 0.07416667 0.10555556 0.0000000000
#> 12 0.03583333 0.10555556 0.0000000000
#> 13 0.12986111 0.07583333 0.0000000000
#> 14 0.08583333 0.07583333 0.0000000000
#> 15 0.08402778 0.07583333 0.0013888889
#> 16 0.08541667 0.07583333 0.0333333333
#> 17 0.08541667 0.07583333 0.0333333333
#> 18 0.05736111 0.07583333 0.0000000000
#> 19 0.06652778 0.07583333 0.0013888889
#> 20 0.05013889 0.09152778 0.0013888889
#> 21 0.08583333 0.07444444 0.0013888889
#> 22 0.07055556 0.07444444 0.0000000000
#> 23 0.10916667 0.07458333 -0.0001388889
#> 24 0.07347222 0.07444444 0.0000000000
#> 25 0.07083333 0.07444444 0.0333333333
#> 26 0.06527778 0.07444444 0.0000000000
strings_sizes("Hello World!", bold = TRUE, italic = FALSE,
fontname = "sans", fontsize = 12)
#> width ascent descent
#> 1 1.018167 0.1266667 0.002166667