nchar_ttype {formatters} | R Documentation |
Calculate font-specific string width
Description
This function returns the width of each element x
as a multiple of the width of the space character
for in declared font, rounded up to the nearest
integer. This is used extensively in the text rendering
(toString()
) and pagination machinery for
calculating word wrapping, default column widths,
lines per page, etc.
Usage
nchar_ttype(
x,
fontspec = font_spec(),
tol = sqrt(.Machine$double.eps),
raw = FALSE
)
Arguments
x |
( |
fontspec |
( |
tol |
( |
raw |
( |
Details
String width is defined in terms of spaces within
the specified font. For monospace fonts, this definition
collapses to the number of characters in the string
(nchar()
), but for truetype fonts it does not.
For raw = FALSE
, non-integer values (the norm in a truetype
setting) for the number of spaces a string takes up is rounded
up, unless the multiple is less than tol
above the last integer
before it. E.g., if k - num_spaces < tol
for an integer
k
, k
is returned instead of k+1
.
See Also
Examples
nchar_ttype("hi there!")
nchar_ttype("hi there!", font_spec("Times"))