Class: TextMetrics

Tiny. TextMetrics

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

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

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

Name Type Description
text string

the text that was measured

style Tiny.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

Classes

FontMetrics

Members

staticTiny.TextMetrics.BASELINE_MULTIPLIERnumber

Baseline multiplier for calculate font metrics.

Version:
  • 1.2.0
Default Value:
  • 1.4

staticTiny.TextMetrics.BASELINE_SYMBOLstring

Baseline symbol for calculate font metrics.

Version:
  • 1.2.0
Default Value:
  • M

staticTiny.TextMetrics.METRICS_STRINGstring

String used for calculate font metrics.

Version:
  • 1.2.0
Default Value:
  • |Éq

Methods

staticTiny.TextMetrics.clearMetrics(font)

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.

Version:
  • 1.2.0

staticTiny.TextMetrics.measureFont(font){Tiny.TextMetrics~FontMetrics}

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

Name Type Description
font string

String representing the style of the font

Returns:
Type Description
Tiny.TextMetrics~FontMetrics Font properties object

staticTiny.TextMetrics.measureText(text, style, wordWrap, canvas){Tiny.TextMetrics}

Measures the supplied string of text and returns a Rectangle.

Name Type Description
text string

the text to measure.

style Tiny.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.

Returns:
Type Description
Tiny.TextMetrics measured width and height of the text.
Documentation generated by JSDoc 3.4.3 on Fri Jul 09 2021 19:32:27 GMT+0800 (CST)