Skip to content

Class TextMetrics ​

The size of laid-out text, from Text.measure. It is a plain table.

lua
local metrics = Text.measure("Hazel", { size = 20 })
local centred_left = (output:area().width - metrics.width) / 2

Properties ​

metrics.width: numberwidth ​

The width of the widest line, in logical pixels.

  • Can have a fraction. math.ceil it for a box that holds it.

metrics.height: numberheight ​

The height of all the lines together.

  • One line's height for text that doesn't wrap, empty text included.

metrics.baseline: numberbaseline ​

From the top of the text to the first line's baseline. Use it to line up text of different sizes, or to place an underline.

metrics.text: stringtext ​

What would be drawn.

  • With an ellipsis cut, the text that is left.
  • Wrapped text has a "\n" where each line breaks.
  • Without max_width, the text as given, with line breaks and tabs turned into spaces.