Constructor
new Text(text, fontopt, strokeopt, backgroundopt, opacityopt, xopt, yopt)
Constructor of Text shape. Color, Gradient, or background image are specified in "background" argument, because it's a Shape.
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
text | string | Text to be drawn as shape | ||
font | object | <optional> | Font object, such as {size: 13, name: "sans-serif", ...}. | |
stroke | Stroke | <optional> | null | Stroke object. |
background | string | <optional> | "#000000" | Background string, CSS style. See Shape#background for details. |
opacity | number | <optional> | 1 | Opacity of the shape. Valid value is a decimal between 0 - 1. |
x | number | <optional> | 0 | X position of top-left corner of text |
y | number | <optional> | 0 | Y position of top-left corner of text //@param {number} [width] - Width of the text bounding box. null means all in one line. No wrapping. //@param {number} [height] - Height of the text bounding box. null means auto-detect, without limit. |
Classes
Methods
font(fontopt) → {this|Object}
Gets or sets the font used for the Text shape. See the example for font object format.
| Name | Type | Attributes | Description |
|---|---|---|---|
font | Object | <optional> | Font object. |
- Type:
- this |
Object
textShape.font({name: "sans-serif", size: 14, italic: true}); // Sets new font.
const font = textShape.font(); // gets component's font
// Full list of supported font properties:
const font = {
name: string, // Font family name (e.g., "sans-serif")
size: number, // Font size in pixels
bold: boolean, // Whether the text is bold
italic: boolean, // Whether the text is italic
underlined: boolean, // Whether the text is underlined
strikethrough: boolean, // Whether the text has a strikethrough
direction: string, // Text direction: "ltr" or "rtl"
kerning: boolean, // Enable or disable kerning
ligatures: boolean, // Enable or disable font ligatures
tracking: number // Letter spacing adjustment: -1, 0 (default), or 1
};text(text) → {string|Text}
Sets new text to the shape. this will recreate the graphics of the shape for the new text.
| Name | Type | Description |
|---|---|---|
text | string | New text for the shape. |
If called without parameters, current text value is returned; otherwise this Text shape object is returned.
- Type:
- string |
Text
toObject(includeopt) → {object}
Returns a JSON object that contains this shape properties. It may be converted back to this shape.
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
include | string | <optional> | "all" | Specified what to include. "all" is default. Valid values are: "all", "stroke", "background", "points", "basic". |
Returns an object containing this shape's properties.
- Type:
- object