Class: TextMetrics


The TextMetrics object represents the measurement of a block of text with a specified style.

let style = new PIXI.TextStyle({fontFamily : 'Arial', fontSize: 24, fill : 0xff1010, align : 'center'})
let textMetrics = PIXI.TextMetrics.measureText('Your text', style)

new PIXI.TextMetrics (text, style, width, height, lines, lineWidths, lineHeight, maxLineWidth, fontProperties)

Name Type Description
text string

the text that was measured

style PIXI.TextStyle

the style that was measured

width number

the measured width of the text

height number

the measured height of the text

lines array

an array of the lines of text broken by new lines and wrapping if specified in style

lineWidths array

an array of the line widths for each line matched to lines

lineHeight number

the measured line height for this style

maxLineWidth number

the maximum line width for all measured lines

fontProperties Object

the font properties object from TextMetrics.measureFont




PIXI.TextMetrics.BASELINE_MULTIPLIER number static

Baseline multiplier for calculate font metrics.

Default Value:
  • 1.4

PIXI.TextMetrics.BASELINE_SYMBOL string static

Baseline symbol for calculate font metrics.

Default Value:
  • M

PIXI.TextMetrics.METRICS_STRING string static

String used for calculate font metrics.

Default Value:
  • |Éq


PIXI.TextMetrics.clearMetrics (font) static

Clear font metrics in metrics cache.

Name Type Description
font string optional

font name. If font name not set then clear cache for all fonts.

PIXI.TextMetrics.measureFont (font)PIXI.TextMetrics~FontMetrics static

Calculates the ascent, descent and fontSize of a given font-style

Name Type Description
font string

String representing the style of the font

Type Description
PIXI.TextMetrics~FontMetrics Font properties object

PIXI.TextMetrics.measureText (text, style, wordWrap, canvas)PIXI.TextMetrics static

Measures the supplied string of text and returns a Rectangle.

Name Type Description
text string

the text to measure.

style PIXI.TextStyle

the text style to use for measuring

wordWrap boolean optional

optional override for if word-wrap should be applied to the text.

canvas HTMLCanvasElement optional

optional specification of the canvas to use for measuring.

Type Description
PIXI.TextMetrics measured width and height of the text.