Text

Text shape is used to draw text as a shape. It can also have a Stroke, background, and everything like other shapes have.

In Text shape you can also specify font parameters, like name, size, underlines, italic, bold, strikethrough and more. Check out FontFamily enum for generic font family names that can be used for cross-platform compatibility.

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.

Parameters:
NameTypeAttributesDefaultDescription
textstring

Text to be drawn as shape

fontobject<optional>

Font object, such as {size: 13, name: "sans-serif", ...}.

strokeStroke<optional>
null

Stroke object.

backgroundstring<optional>
"#000000"

Background string, CSS style. See Shape#background for details.

opacitynumber<optional>
1

Opacity of the shape. Valid value is a decimal between 0 - 1.

xnumber<optional>
0

X position of top-left corner of text

ynumber<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

Text

Methods

font(fontopt) → {this|Object}

Gets or sets the font used for the Text shape. See the example for font object format.

Parameters:
NameTypeAttributesDescription
fontObject<optional>

Font object.

Returns:
Type: 
this | Object
Example
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.

Parameters:
NameTypeDescription
textstring

New text for the shape.

Returns:

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.

Parameters:
NameTypeAttributesDefaultDescription
includestring<optional>
"all"

Specified what to include. "all" is default. Valid values are: "all", "stroke", "background", "points", "basic".

Returns:

Returns an object containing this shape's properties.

Type: 
object