Skip to main content

TextPath

new Konva.TextPath(config)

Path constructor.

Parameters

NameTypeDescription
configObject
fontFamily (optional)Stringdefault is Arial
fontSize (optional)Numberdefault is 12
fontStyle (optional)StringCan be 'normal', 'italic', or 'bold', '500' or even 'italic bold'. 'normal' is the default.
fontVariant (optional)Stringcan be normal or small-caps. Default is normal
textBaseline (optional)StringCan be 'top', 'bottom', 'middle', 'alphabetic', 'hanging'. Default is middle
textString
dataStringSVG data string
kerningFuncfunctiona getter for kerning values for the specified characters
fill (optional)Stringfill color
fillPatternImage (optional)Imagefill pattern image
fillPatternX (optional)Number
fillPatternY (optional)Number
fillPatternOffset (optional)Objectobject with x and y component
fillPatternOffsetX (optional)Number
fillPatternOffsetY (optional)Number
fillPatternScale (optional)Objectobject with x and y component
fillPatternScaleX (optional)Number
fillPatternScaleY (optional)Number
fillPatternRotation (optional)Number
fillPatternRepeat (optional)Stringcan be "repeat", "repeat-x", "repeat-y", or "no-repeat". The default is "no-repeat"
fillLinearGradientStartPoint (optional)Objectobject with x and y component
fillLinearGradientStartPointX (optional)Number
fillLinearGradientStartPointY (optional)Number
fillLinearGradientEndPoint (optional)Objectobject with x and y component
fillLinearGradientEndPointX (optional)Number
fillLinearGradientEndPointY (optional)Number
fillLinearGradientColorStops (optional)Arrayarray of color stops
fillRadialGradientStartPoint (optional)Objectobject with x and y component
fillRadialGradientStartPointX (optional)Number
fillRadialGradientStartPointY (optional)Number
fillRadialGradientEndPoint (optional)Objectobject with x and y component
fillRadialGradientEndPointX (optional)Number
fillRadialGradientEndPointY (optional)Number
fillRadialGradientStartRadius (optional)Number
fillRadialGradientEndRadius (optional)Number
fillRadialGradientColorStops (optional)Arrayarray of color stops
fillEnabled (optional)Booleanflag which enables or disables the fill. The default value is true
fillPriority (optional)Stringcan be color, linear-gradient, radial-graident, or pattern. The default value is color. The fillPriority property makes it really easy to toggle between different fill types. For example, if you want to toggle between a fill color style and a fill pattern style, simply set the fill property and the fillPattern properties, and then use setFillPriority('color') to render the shape with a color fill, or use setFillPriority('pattern') to render the shape with the pattern fill configuration
stroke (optional)Stringstroke color
strokeWidth (optional)Numberstroke width
fillAfterStrokeEnabled (optional)BooleanShould we draw fill AFTER stroke? Default is false.
hitStrokeWidth (optional)Numbersize of the stroke on hit canvas. The default is "auto" - equals to strokeWidth
strokeHitEnabled (optional)Booleanflag which enables or disables stroke hit region. The default is true
perfectDrawEnabled (optional)Booleanflag which enables or disables using buffer canvas. The default is true
shadowForStrokeEnabled (optional)Booleanflag which enables or disables shadow for stroke. The default is true
strokeScaleEnabled (optional)Booleanflag which enables or disables stroke scale. The default is true
strokeEnabled (optional)Booleanflag which enables or disables the stroke. The default value is true
lineJoin (optional)Stringcan be miter, round, or bevel. The default is miter
lineCap (optional)Stringcan be butt, round, or square. The default is butt
shadowColor (optional)String
shadowBlur (optional)Number
shadowOffset (optional)Objectobject with x and y component
shadowOffsetX (optional)Number
shadowOffsetY (optional)Number
shadowOpacity (optional)Numbershadow opacity. Can be any real number between 0 and 1
shadowEnabled (optional)Booleanflag which enables or disables the shadow. The default value is true
dash (optional)Array
dashEnabled (optional)Booleanflag which enables or disables the dashArray. The default value is true
x (optional)Number
y (optional)Number
width (optional)Number
height (optional)Number
visible (optional)Boolean
listening (optional)Booleanwhether or not the node is listening for events
id (optional)Stringunique id
name (optional)Stringnon-unique name
opacity (optional)Numberdetermines node opacity. Can be any number between 0 and 1
scale (optional)Objectset scale
scaleX (optional)Numberset scale x
scaleY (optional)Numberset scale y
rotation (optional)Numberrotation in degrees
offset (optional)Objectoffset from center point and rotation point
offsetX (optional)Numberset offset x
offsetY (optional)Numberset offset y
draggable (optional)Booleanmakes the node draggable. When stages are draggable, you can drag and drop the entire stage by dragging any portion of the stage
dragDistance (optional)Number
dragBoundFunc (optional)function

Inherited from: Konva.Shape

Own Methods

getTextWidth()

get text width in pixels

data(data)

get/set SVG path data string. This method also automatically parses the data string into a data array. Currently supported SVG data: M, m, L, l, H, h, V, v, Q, q, T, t, C, c, S, s, A, a, Z, z

Parameters:

  • data (String): svg path string

Returns: String

Example:

// get data
var data = shape.data();

// set data
shape.data('M200,100h100v50z');

fontFamily(fontFamily)

get/set font family

Parameters:

  • fontFamily (String)

Returns: String

Example:

// get font family
var fontFamily = shape.fontFamily();

// set font family
shape.fontFamily('Arial');

fontSize(fontSize)

get/set font size in pixels

Parameters:

  • fontSize (Number)

Returns: Number

Example:

// get font size
var fontSize = shape.fontSize();

// set font size to 22px
shape.fontSize(22);

fontStyle(fontStyle)

get/set font style. Can be 'normal', 'italic', or 'bold', '500' or even 'italic bold'. 'normal' is the default.

Parameters:

  • fontStyle (String)

Returns: String

Example:

// get font style
var fontStyle = shape.fontStyle();

// set font style
shape.fontStyle('bold');

align(align)

get/set horizontal align of text. Can be 'left', 'center', 'right' or 'justify'

Parameters:

  • align (String)

Returns: String

Example:

// get text align
var align = text.align();

// center text
text.align('center');

// align text to right
text.align('right');

letterSpacing(letterSpacing)

get/set letter spacing. The default is 0.

Parameters:

  • letterSpacing (Number)

Returns: Number

Example:

// get letter spacing value
var letterSpacing = shape.letterSpacing();

// set the letter spacing value
shape.letterSpacing(2);

textBaseline(textBaseline)

get/set text baseline. The default is 'middle'. Can be 'top', 'bottom', 'middle', 'alphabetic', 'hanging'

Parameters:

  • textBaseline (String)

Returns: String

Example:

// get current text baseline
var textBaseline = shape.textBaseline();

// set new text baseline
shape.textBaseline('top');

fontVariant(fontVariant)

get/set font variant. Can be 'normal' or 'small-caps'. 'normal' is the default.

Parameters:

  • fontVariant (String)

Returns: String

Example:

// get font variant
var fontVariant = shape.fontVariant();

// set font variant
shape.fontVariant('small-caps');

getText(text)

get/set text

Parameters:

  • text (String)

Returns: String

Example:

// get text
var text = text.text();

// set text
text.text('Hello world!');

textDecoration(textDecoration)

get/set text decoration of a text. Can be '', 'underline', 'line-through', or a combination like 'underline line-through'.

Parameters:

  • textDecoration (String)

Returns: String

Example:

// get text decoration
var textDecoration = shape.textDecoration();

// underline text
shape.textDecoration('underline');

// line-through text
shape.textDecoration('line-through');

// combine both
shape.textDecoration('underline line-through');

kerningFunc(kerningFunc)

get/set kerning function.

Parameters:

  • kerningFunc (String)

Returns: String

Example:

// get text decoration
var kerningFunc = text.kerningFunc();

// center text
text.kerningFunc(function(leftChar, rightChar) {
return 1;
});

direction(direction)

get/set text direction. Can be 'inherit', 'ltr' or 'rtl'. Default is 'inherit'. Setting 'rtl' reverses the per-glyph layout order along the path, so Hebrew/Arabic strings read correctly when scanned right-to-left. This is a pragmatic fix limited by canvas TextPath rendering: each glyph is still drawn independently, so Arabic cursive joining and full Unicode bidi reordering of mixed-direction text are not supported. For best results, pair direction: 'rtl' with align: 'right' so the text starts at the end of the path.

Parameters:

  • direction (String)

Returns: String

Example:

// get direction
var direction = textpath.direction();

// set direction
textpath.direction('rtl');

Inherited Methods

Konva.TextPath also has all methods of its parent classes. Each link below opens the full documentation of the method on the class that defines it.

From Konva.Shape

From Konva.Node