Calculates font metrics for a specified font, font size, and style.
get_string_dimensions(string, font = "sans", size = 12, align = "center", ...)
A data.frame listing the string dimensions.
The function renders specific characters ("d"
for ascender, "g"
for descender, "x"
for neutral) using the specified font parameters. It calculates the bounding box of each character to determine the necessary adjustments for accurate text positioning.
# Get height of basic sans font
get_string_dimensions("This is a string", size=24)
#> # A tibble: 1 × 11
#> string width height left_bearing right_bearing top_bearing bottom_bearing
#> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 This is a … 178 50.2 -1 1 4.28 0.656
#> # ℹ 4 more variables: left_border <dbl>, top_border <dbl>, pen_x <dbl>,
#> # pen_y <dbl>