Constructor
new module:Text(positionDefinition, textopt, optionsopt)
Text constructor
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
positionDefinition | PositionDefinition | Top most point of the line start (depend on align option) | ||
text | String | <optional> | "" | Text to display |
options | TextOptions | <optional> | Drawing options |
- Source
Extends
Members
(static) alignments :TextAlignments
- TextAlignments
- Source
(static) defaultOptions :TextOptions
- TextOptions
- Source
height
Height of the text
- Overrides
- Source
height
Can't set text's height
- Overrides
- Source
lines :Array.<String>
- Array.<String>
- Source
text
Returns the text
- Source
text
Change the text
- Source
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
- Overrides
- Source
width
Can't set text's width
- Overrides
- Source
(inner, constant) measureText
Cache based text measurement
- Source
Methods
(static) from(definition) → {Text}
Name | Type | Description |
---|---|---|
definition | Object | Text definition |
- Source
- Type:
- Text
(static) getFontDefinition(options) → {String}
Return a font definition from a set of options
Name | Type | Description |
---|---|---|
options | TextOptions | Chosen options |
- Source
- Type:
- String
(static) load(url) → {Promise.<String>}
Load a font URL
Name | Type | Description |
---|---|---|
url | String | | URL or an array of URL to font files |
- Source
Promise for the generated font-family
- Type:
- Promise.<String>
(static) measure(text, optionsopt) → {TextMeasures}
Compute a text width and height
Name | Type | Attributes | Description |
---|---|---|---|
text | String | | Any text | |
options | TextOptions | <optional> | Options of the text |
- Source
- Type:
- TextMeasures
getAlignOffset() → {Number}
Return the position offset according to alignment
- Source
- Type:
- Number
getMeasures() → {TextMeasures}
Measure the text with current options
- Source
- Type:
- TextMeasures
makePath(ctx) → {Text}
Draw the text into a drawing context
Name | Type | Description |
---|---|---|
ctx | CanvasRenderingContext2D | Drawing context |
- Overrides
- Source
Itself
- Type:
- Text
(inner) formatString(string) → {Array.<String>}
Reformat passed arguments into an array of line string
Name | Type | Description |
---|---|---|
string | String | | Multiline string or Array of multiline strings to split |
- Source
- Type:
- Array.<String>
Type Definitions
TextAlignments
- Object
Name | Type | Description |
---|---|---|
left | String | The text is left-aligned. |
right | String | The text is right-aligned. |
center | String | The text is centered. |
start | String | The text is aligned at the normal start of the line. (regarding locales) |
end | String | The text is aligned at the normal end of the line. (regarding locales) |
- Source
TextMeasures
- Object
Name | Type | Description |
---|---|---|
width | Number | Horizontal size |
height | Number | Vertical size |
- Source
TextOptions
- Object
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
font | String | <optional> | "sans-serif" | Font to use (can be a URL) |
fontSize | Number | <optional> | 10 | Size of the text in pixels |
align | String | <optional> | Text.alignments.start | Text horizontal alignment |
bold | Boolean | <optional> | false | Use bold font-weight |
italic | Boolean | <optional> | false | Use italic font-style |
underscore | Boolean | <optional> | false | Draw a line under the text |
lineHeight | Number | <optional> | 1 | Ratio of line height (1 is normal, 2 is twice the space) |
- Source