Learn R Programming

gdtools (version 0.6.0)

font_line_metrics: Line metrics of fonts

Description

Vertical metrics of the lines of text written with a font, read from the font file: the part of a line above its baseline (ascent), the part below (descent) and their sum, the distance between the baselines of two lines in single spacing (line_height). Multiply line_height by a line spacing factor (1.5 for example) to get the distance between baselines with this spacing.

The values follow the rule of the text metrics of Windows, applied by 'Microsoft Word' for single line spacing: ascent is the usWinAscent of the 'OS/2' table plus the external leading, descent is its usWinDescent; the external leading is the line gap of the 'hhea' table, reduced by what usWinAscent and usWinDescent add to the ascender and descender of 'hhea', and not negative. Fonts without these values use the ascender, descender and line gap of 'hhea'.

These metrics depend on the font only, unlike the ascent and descent returned by strings_sizes(), which are those of the ink of the glyphs of a string. Fonts are found as with strings_sizes().

Usage

font_line_metrics(
  fontname = "sans",
  fontsize = 10,
  bold = FALSE,
  italic = FALSE
)

Value

A data.frame with columns ascent, descent and line_height, in inches, one row per font.

Arguments

fontname

A character vector of font family names. This argument is vectorized, as fontsize, bold and italic: they are recycled to the length of the longest one.

fontsize

A numeric vector of font sizes in points.

bold, italic

Logical vectors, for the bold and italic faces.

See Also

strings_sizes()

Other functions for font metrics: m_str_extents(), str_metrics(), strings_sizes()

Examples

Run this code
font_line_metrics(c("sans", "serif"), fontsize = 12)
# distance between baselines with a line spacing of 1.5, in points
font_line_metrics("sans", fontsize = 12)$line_height * 1.5 * 72

Run the code above in your browser using DataLab