font

Choose a font with font("Helvetica") and set its size with style.fontSize(32). Use font.metrics() when arranging text along a shared baseline or aligning text with other elements.

font.metrics()

Returns a new table of measurements for the current font, size, and text renderer. All measurements are in points. Changing the drawing style later does not change a previously returned table.

Ascent and descent are positive distances above and below the baseline. Leading is the extra spacing between lines. These describe the font, not the bounds of a particular string; use textSize() to measure a string. Shadows, outlines, and tags within a string do not affect these measurements.

font("Helvetica")
style.fontSize(32)
local metrics = font.metrics()
local baseline = 200
style.textMode(CORNER)
text("Hello", 40, baseline - metrics.descent)

Native and atlas measurements can differ. Atlas font sizes use whole points.

Returns:

A snapshot of the current font measurements.

Return type:

table$private.metrics

class font.private.metrics

A table of font measurements, in points.

size: number

The effective font size.

ascent: number

The distance above the baseline.

descent: number

The distance below the baseline.

leading: number

The additional spacing between lines.

xHeight: number

The height of a lowercase x.

capHeight: number

The height of a capital letter.

underlinePosition: number

The signed underline position relative to the baseline; negative is below it.

underlineThickness: number

The underline thickness.