module:Text

Text class
text demo

Constructor

new module:Text(positionDefinition, textopt, optionsopt)

Text constructor

Parameters:
NameTypeAttributesDefaultDescription
positionDefinitionPositionDefinition

Top most point of the line start (depend on align option)

textString<optional>
""

Text to display

optionsTextOptions<optional>

Drawing options

Extends

Members

(static) alignments :TextAlignments

Type:
  • TextAlignments

(static) defaultOptions :TextOptions

Type:
  • TextOptions

height

Height of the text

height

Can't set text's height

lines :Array.<String>

Type:
  • Array.<String>

text

Returns the text

text

Change the text

Examples
this.text = "Single line text";
this.text = "Multi\nLine text";
this.text = ["Multi", "Line text"];
this.text = ["Multi", "Line\ntext"];

width

Width of the text

width

Can't set text's width

(inner, constant) measureText

Cache based text measurement

Methods

(static) from(definition) → {Text}

Parameters:
NameTypeDescription
definitionObject

Text definition

Returns:
Type: 
Text

(static) getFontDefinition(options) → {String}

Return a font definition from a set of options

Parameters:
NameTypeDescription
optionsTextOptions

Chosen options

Returns:
Type: 
String

(static) load(url) → {Promise.<String>}

Load a font URL

Parameters:
NameTypeDescription
urlString | Array.<String>

URL or an array of URL to font files

Returns:

Promise for the generated font-family

Type: 
Promise.<String>

(static) measure(text, optionsopt) → {TextMeasures}

Compute a text width and height

Parameters:
NameTypeAttributesDescription
textString | Array.<String>

Any text

optionsTextOptions<optional>

Options of the text

Returns:
Type: 
TextMeasures

getAlignOffset() → {Number}

Return the position offset according to alignment

Returns:
Type: 
Number

getMeasures() → {TextMeasures}

Measure the text with current options

Returns:
Type: 
TextMeasures

makePath(ctx) → {Text}

Draw the text into a drawing context

Parameters:
NameTypeDescription
ctxCanvasRenderingContext2D

Drawing context

Returns:

Itself

Type: 
Text

(inner) formatString(string) → {Array.<String>}

Reformat passed arguments into an array of line string

Parameters:
NameTypeDescription
stringString | Array.<String>

Multiline string or Array of multiline strings to split

Returns:
Type: 
Array.<String>

Type Definitions

TextAlignments

Type:
  • Object
Properties
NameTypeDescription
leftString

The text is left-aligned.

rightString

The text is right-aligned.

centerString

The text is centered.

startString

The text is aligned at the normal start of the line. (regarding locales)

endString

The text is aligned at the normal end of the line. (regarding locales)

TextMeasures

Type:
  • Object
Properties
NameTypeDescription
widthNumber

Horizontal size

heightNumber

Vertical size

TextOptions

Type:
  • Object
Properties
NameTypeAttributesDefaultDescription
fontString<optional>
"sans-serif"

Font to use (can be a URL)

fontSizeNumber<optional>
10

Size of the text in pixels

alignString<optional>
Text.alignments.start

Text horizontal alignment

boldBoolean<optional>
false

Use bold font-weight

italicBoolean<optional>
false

Use italic font-style

underscoreBoolean<optional>
false

Draw a line under the text

lineHeightNumber<optional>
1

Ratio of line height (1 is normal, 2 is twice the space)