Skip to content
cfry002 edited this page Feb 22, 2016 · 2 revisions

Font

scene.create({t:"fontResource",url:fontUrl}) will return a Font object.

The Font object supports two functions:

getFontMetrics(pixelSize)

Returns information about the font face (font and size). It does not convey information about the text of the font. See section 3.a in FreeType documents__. The returned object has the following properties:

  • height - float - the distance between baselines
  • ascent - float - the distance from the baseline to the font ascender (note that this is a hint, not a solid rule)
  • descent - float - the distance from the baseline to the font descender (note that this is a hint, not a solid rule)
  • naturalLeading – float – the distance that must be placed between two lines of text (See linegap in section 2 in FreeType documents)
  • baseline – float – the baseline position for the first line of text in this widget

measureText(pixelSize, stringToMeasure)

Use this to get information about the bounds of the passed in stringToMeasure. Returns a pxObject whose h and w properties reflect the height and width of the text at the selected pixelSize. Note that this does not take into account any wordWrap setting that might be on a textBox object displaying this text. Use textBox.measureText in that case for full accuracy.

Clone this wiki locally