Calculates font metrics for a specified font, font size, and style. The function renders specific characters to measure ascender and descender heights, which are used for text alignment and positioning in graphical outputs.

get_font_metrics(font, font_size, style = "plain")

Arguments

font

A character string specifying the font family (e.g., "Arial", "Times", "Helvetica").

font_size

A numeric value specifying the size of the font in points.

style

A character string specifying the font style, such as "plain", "italic", or "bold". Default is "plain".

Value

A list containing:

ascender_adjustment

Numeric value of the height adjustment needed for ascenders.

descender_adjustment

Numeric value of the height adjustment needed for descenders.

neutral_height

Numeric value of the height of a neutral character.

Details

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.

Examples

# Get height of basic sans font
get_font_metrics("sans", 60)
#> $ascender_adjustment
#> [1] 14
#> 
#> $descender_adjustment
#> [1] 14
#> 
#> $neutral_height
#> [1] 31
#> 
#> $total_height
#> [1] 56
#>