Class: Text

fabric.Text

new Text() → {fabric.Text}

Text class
Source:
Tutorials:
See:
Returns:
thisArg
Type
fabric.Text

Extends

Members

(static) ATTRIBUTE_NAMES

List of attribute names to account for when parsing SVG element (used by fabric.Text.fromElement)
Source:

(static) DEFAULT_SVG_FONT_SIZE

Default SVG font size
Source:

__charBounds

contains characters bounding boxes
Source:

__corner :number|string|any

keeps the value of the last hovered coner during mouse move. 0 is no corner, or 'mt', 'ml', 'mtr' etc.. It should be private, but there is no harm in using it as a read-only property.
Type:
  • number | string | any
Inherited From:
Default Value:
  • 0
Source:

_fontSizeMult :Number

Text Line proportion to font Size (in pixels)
Type:
  • Number
Default Value:
  • 1.13
Source:

_measuringContext :CanvasRenderingContext2D

Reference to a context to measure text char or couple of chars the cacheContext of the canvas will be used or a freshly created one if the object is not on canvas once created it will be referenced on fabric._measuringContext to avoide creating a canvas for every text object created.
Type:
  • CanvasRenderingContext2D
Source:

_styleProperties :Array

Array of properties that define a style unit.
Type:
  • Array
Default Value:
  • ["stroke","strokeWidth","fill","fontFamily","fontSize","fontWeight","fontStyle","underline","overline","linethrough","textBackgroundColor"]
Source:

aCoords

Describe object's corner position in canvas object absolute coordinates properties are tl,tr,bl,br and describe the four main corner. each property is an object with x, y, instance of Fabric.Point. The coordinates depends from this properties: width, height, scaleX, scaleY skewX, skewY, angle, strokeWidth, top, left. Those coordinates are usefull to understand where an object is. They get updated with oCoords but they do not need to be updated when zoom or panning change. The coordinates get updated with @method setCoords. You can calculate them without updating with @method calcCoords(true);
Inherited From:
Source:

angle :Number

Angle of rotation of an object (in degrees)
Type:
  • Number
Inherited From:
Source:

backgroundColor :String

Background color of an object.
Type:
  • String
Inherited From:
Source:

borderColor :String

Color of controlling borders of an object (when it's active)
Type:
  • String
Inherited From:
Default Value:
  • rgba(102,153,255,0.75)
Source:

borderDashArray :Array

Array specifying dash pattern of an object's borders (hasBorder must be true)
Type:
  • Array
Since:
  • 1.6.2
Inherited From:
Source:

borderOpacityWhenMoving :Number

Opacity of object's controlling borders when object is active and moving
Type:
  • Number
Inherited From:
Default Value:
  • 0.4
Source:

borderScaleFactor :Number

Scale factor of object's controlling borders
Type:
  • Number
Inherited From:
Default Value:
  • 1
Source:

cacheProperties :Array

List of properties to consider when checking if cache needs refresh
Type:
  • Array
Overrides:
Source:

centeredRotation :Boolean

When true, this object will use center point as the origin of transformation when being rotated via the controls. Backwards incompatibility note: This property replaces "centerTransform" (Boolean).
Type:
  • Boolean
Since:
  • 1.3.4
Inherited From:
Default Value:
  • true
Source:

centeredScaling :Boolean

When true, this object will use center point as the origin of transformation when being scaled via the controls. Backwards incompatibility note: This property replaces "centerTransform" (Boolean).
Type:
  • Boolean
Since:
  • 1.3.4
Inherited From:
Source:

charSpacing :Number

additional space between characters expressed in thousands of em unit
Type:
  • Number
Source:

clipTo :function

Function that determines clipping of an object (context is passed as a first argument) Note that context origin is at the object's center point (not left/top corner)
Type:
  • function
Inherited From:
Deprecated:
  • since 2.0.0
Source:

cornerColor :String

Color of controlling corners of an object (when it's active)
Type:
  • String
Inherited From:
Default Value:
  • rgba(102,153,255,0.5)
Source:

cornerDashArray :Array

Array specifying dash pattern of an object's control (hasBorder must be true)
Type:
  • Array
Since:
  • 1.6.2
Inherited From:
Source:

cornerSize :Number

Size of object's controlling corners (in pixels)
Type:
  • Number
Inherited From:
Default Value:
  • 13
Source:

cornerStrokeColor :String

Color of controlling corners of an object (when it's active and transparentCorners false)
Type:
  • String
Since:
  • 1.6.2
Inherited From:
Source:

cornerStyle :String

Specify style of control, 'rect' or 'circle'
Type:
  • String
Since:
  • 1.6.2
Inherited From:
Source:

dirty :Boolean

When set to `true`, object's cache will be rerendered next render call. since 1.7.0
Type:
  • Boolean
Inherited From:
Default Value:
  • true
Source:

evented :Boolean

When set to `false`, an object can not be a target of events. All events propagate through it. Introduced in v1.3.4
Type:
  • Boolean
Inherited From:
Default Value:
  • true
Source:

excludeFromExport :Boolean

When `true`, object is not exported in SVG or OBJECT/JSON since 1.6.3
Type:
  • Boolean
Inherited From:
Source:

fill :String

Color of object's fill
Type:
  • String
Inherited From:
Default Value:
  • rgb(0,0,0)
Source:

fillRule :String

Fill rule used to fill an object accepted values are nonzero, evenodd Backwards incompatibility note: This property was used for setting globalCompositeOperation until v1.4.12 (use `fabric.Object#globalCompositeOperation` instead)
Type:
  • String
Inherited From:
Default Value:
  • nonzero
Source:

flipX :Boolean

When true, an object is rendered as flipped horizontally
Type:
  • Boolean
Inherited From:
Source:

flipY :Boolean

When true, an object is rendered as flipped vertically
Type:
  • Boolean
Inherited From:
Source:

fontFamily :String

Font family
Type:
  • String
Default Value:
  • Times New Roman
Source:

fontSize :Number

Font size (in pixels)
Type:
  • Number
Default Value:
  • 40
Source:

fontStyle :String

Font style . Possible values: "", "normal", "italic" or "oblique".
Type:
  • String
Default Value:
  • normal
Source:

fontWeight :Number|String

Font weight (e.g. bold, normal, 400, 600, 800)
Type:
  • Number | String
Default Value:
  • normal
Source:

globalCompositeOperation :String

Composite rule used for canvas globalCompositeOperation
Type:
  • String
Inherited From:
Default Value:
  • source-over
Source:

hasBorders :Boolean

When set to `false`, object's controlling borders are not rendered
Type:
  • Boolean
Inherited From:
Default Value:
  • true
Source:

hasControls :Boolean

When set to `false`, object's controls are not displayed and can not be used to manipulate object
Type:
  • Boolean
Inherited From:
Default Value:
  • true
Source:

hasRotatingPoint :Boolean

When set to `false`, object's controlling rotating point will not be visible or selectable
Type:
  • Boolean
Inherited From:
Default Value:
  • true
Source:

height :Number

Object height
Type:
  • Number
Inherited From:
Source:

hoverCursor :String

Default cursor value used when hovering over this object on canvas
Type:
  • String
Inherited From:
Source:

includeDefaultValues :Boolean

When `false`, default object's values are not included in its serialization
Type:
  • Boolean
Inherited From:
Default Value:
  • true
Source:

left :Number

Left position of an object. Note that by default it's relative to object left. You can change this by setting originX={left/center/right}
Type:
  • Number
Inherited From:
Source:

lineHeight :Number

Line height
Type:
  • Number
Default Value:
  • 1.16
Source:

linethrough :String

Text decoration linethrough.
Type:
  • String
Source:

lockMovementX :Boolean

When `true`, object horizontal movement is locked
Type:
  • Boolean
Inherited From:
Source:

lockMovementY :Boolean

When `true`, object vertical movement is locked
Type:
  • Boolean
Inherited From:
Source:

lockRotation :Boolean

When `true`, object rotation is locked
Type:
  • Boolean
Inherited From:
Source:

lockScalingFlip :Boolean

When `true`, object cannot be flipped by scaling into negative values
Type:
  • Boolean
Inherited From:
Source:

lockScalingX :Boolean

When `true`, object horizontal scaling is locked
Type:
  • Boolean
Inherited From:
Source:

lockScalingY :Boolean

When `true`, object vertical scaling is locked
Type:
  • Boolean
Inherited From:
Source:

lockSkewingX :Boolean

When `true`, object horizontal skewing is locked
Type:
  • Boolean
Inherited From:
Source:

lockSkewingY :Boolean

When `true`, object vertical skewing is locked
Type:
  • Boolean
Inherited From:
Source:

lockUniScaling :Boolean

When `true`, object non-uniform scaling is locked
Type:
  • Boolean
Inherited From:
Source:

minScaleLimit :Number

Minimum allowed scale value of an object
Type:
  • Number
Inherited From:
Source:

moveCursor :String

Default cursor value used when moving this object on canvas
Type:
  • String
Inherited From:
Source:

noScaleCache :Boolean

When `true`, cache does not get updated during scaling. The picture will get blocky if scaled too much and will be redrawn with correct details at the end of scaling. this setting is performance and application dependant. default to true since 1.7.0
Type:
  • Boolean
Inherited From:
Default Value:
  • true
Source:

objectCaching :Boolean

When `true`, object is cached on an additional canvas. default to true since 1.7.0
Type:
  • Boolean
Inherited From:
Default Value:
  • true
Source:

oCoords

Describe object's corner position in canvas element coordinates. properties are tl,mt,tr,ml,mr,bl,mb,br,mtr for the main controls. each property is an object with x, y and corner. The `corner` property contains in a similar manner the 4 points of the interactive area of the corner. The coordinates depends from this properties: width, height, scaleX, scaleY skewX, skewY, angle, strokeWidth, viewportTransform, top, left, padding. The coordinates get updated with @method setCoords. You can calculate them without updating with @method calcCoords;
Inherited From:
Source:

opacity :Number

Opacity of an object
Type:
  • Number
Inherited From:
Default Value:
  • 1
Source:

originX :String

Horizontal origin of transformation of an object (one of "left", "right", "center") See http://jsfiddle.net/1ow02gea/244/ on how originX/originY affect objects in groups
Type:
  • String
Inherited From:
Default Value:
  • left
Source:

originY :String

Vertical origin of transformation of an object (one of "top", "bottom", "center") See http://jsfiddle.net/1ow02gea/244/ on how originX/originY affect objects in groups
Type:
  • String
Inherited From:
Default Value:
  • top
Source:

overline :String

Text decoration overline.
Type:
  • String
Source:

padding :Number

Padding between object and its controlling borders (in pixels)
Type:
  • Number
Inherited From:
Source:

paintFirst :String

Determins if the fill or the stroke is drawn first (one of "fill" or "stroke")
Type:
  • String
Inherited From:
Default Value:
  • fill
Source:

perPixelTargetFind :Boolean

When set to `true`, objects are "found" on canvas on per-pixel basis rather than according to bounding box
Type:
  • Boolean
Inherited From:
Source:

rotatingPointOffset :Number

Offset for object's controlling rotating point (when enabled via `hasRotatingPoint`)
Type:
  • Number
Inherited From:
Default Value:
  • 40
Source:

scaleX :Number

Object scale factor (horizontal)
Type:
  • Number
Inherited From:
Default Value:
  • 1
Source:

scaleY :Number

Object scale factor (vertical)
Type:
  • Number
Inherited From:
Default Value:
  • 1
Source:

selectable :Boolean

When set to `false`, an object can not be selected for modification (using either point-click-based or group-based selection). But events still fire on it.
Type:
  • Boolean
Inherited From:
Default Value:
  • true
Source:

selectionBackgroundColor :String

Selection Background color of an object. colored layer behind the object when it is active. does not mix good with globalCompositeOperation methods.
Type:
  • String
Inherited From:
Source:

shadow :fabric.Shadow

Shadow object representing shadow of this shape. Backwards incompatibility note: This property was named "textShadow" (String) until v1.2.11
Type:
Overrides:
Source:

skewX :Number

Angle of skew on x axes of an object (in degrees)
Type:
  • Number
Inherited From:
Source:

skewY :Number

Angle of skew on y axes of an object (in degrees)
Type:
  • Number
Inherited From:
Source:

statefullCache :Boolean

When `true`, object properties are checked for cache invalidation. In some particular situation you may want this to be disabled ( spray brush, very big, groups) or if your application does not allow you to modify properties for groups child you want to disable it for groups. default to false since 1.7.0
Type:
  • Boolean
Inherited From:
Default Value:
  • false
Source:

stateProperties :Array

List of properties to consider when checking if state of an object is changed (fabric.Object#hasStateChanged) as well as for history (undo/redo) purposes
Type:
  • Array
Overrides:
Source:

stroke :String

When defined, an object is rendered via stroke and this property specifies its color. Backwards incompatibility note: This property was named "strokeStyle" until v1.1.6
Type:
  • String
Overrides:
Source:

strokeDashArray :Array

Array specifying dash pattern of an object's stroke (stroke must be defined)
Type:
  • Array
Inherited From:
Source:

strokeLineCap :String

Line endings style of an object's stroke (one of "butt", "round", "square")
Type:
  • String
Inherited From:
Default Value:
  • butt
Source:

strokeLineJoin :String

Corner style of an object's stroke (one of "bevil", "round", "miter")
Type:
  • String
Inherited From:
Default Value:
  • miter
Source:

strokeMiterLimit :Number

Maximum miter length (used for strokeLineJoin = "miter") of an object's stroke
Type:
  • Number
Inherited From:
Default Value:
  • 10
Source:

strokeWidth :Number

Width of a stroke used to render this object
Type:
  • Number
Inherited From:
Default Value:
  • 1
Source:

styles :Object

Object containing character styles (where top-level properties corresponds to line number and 2nd-level properties -- to char number in a line)
Type:
  • Object
Source:

textAlign :String

Text alignment. Possible values: "left", "center", "right" or "justify".
Type:
  • String
Default Value:
  • left
Source:

textBackgroundColor :String

Background color of text lines
Type:
  • String
Source:

top :Number

Top position of an object. Note that by default it's relative to object top. You can change this by setting originY={top/center/bottom}
Type:
  • Number
Inherited From:
Source:

transformMatrix :Array

Transform matrix (similar to SVG's transform matrix)
Type:
  • Array
Inherited From:
Source:

transparentCorners :Boolean

When true, object's controlling corners are rendered as transparent inside (i.e. stroke instead of fill)
Type:
  • Boolean
Inherited From:
Default Value:
  • true
Source:

type :String

Type of an object
Type:
  • String
Overrides:
Default Value:
  • text
Source:

underline :String

Text decoration underline.
Type:
  • String
Source:

visible :Boolean

When set to `false`, an object is not rendered on canvas
Type:
  • Boolean
Inherited From:
Default Value:
  • true
Source:

width :Number

Object width
Type:
  • Number
Inherited From:
Source:

Methods

(static) fromElement(element, callback, optionsopt)

Returns fabric.Text instance from an SVG element (not yet implemented)
Parameters:
Name Type Attributes Description
element SVGElement Element to parse
callback function callback function invoked after parsing
options Object <optional>
Options object
Source:

(static) fromObject(object, callbackopt)

Returns fabric.Text instance from an object representation
Parameters:
Name Type Attributes Description
object Object Object to create an instance from
callback function <optional>
Callback to invoke when an fabric.Text instance is created
Source:

_calcRotateMatrix() → {Array}

calculate rotation matrix of an object
Inherited From:
Source:
Returns:
rotation matrix for the object
Type
Array

_getFontDeclaration(styleObjectopt) → {String}

return font declaration string for canvas context
Parameters:
Name Type Attributes Description
styleObject Object <optional>
object
Source:
Returns:
font declaration formatted for canvas context.
Type
String

_getStyleDeclaration(lineIndex, charIndex) → {Object}

get the reference, not a clone, of the style object for a given character
Parameters:
Name Type Description
lineIndex Number
charIndex Number
Source:
Returns:
style object
Type
Object

_limitCacheSize(dims) → {Object|Object|Object|Object}

Limit the cache dimensions so that X * Y do not cross fabric.perfLimitSizeTotal and each side do not cross fabric.cacheSideLimit those numbers are configurable so that you can get as much detail as you want making bargain with performances.
Parameters:
Name Type Description
dims Object
Properties
Name Type Description
width Object width of canvas
height Object height of canvas
zoomX Object zoomX zoom value to unscale the canvas before drawing cache
zoomY Object zoomY zoom value to unscale the canvas before drawing cache
Inherited From:
Source:
Returns:
  • .width width of canvas
    Type
    Object
  • .height height of canvas
    Type
    Object
  • .zoomX zoomX zoom value to unscale the canvas before drawing cache
    Type
    Object
  • .zoomY zoomY zoom value to unscale the canvas before drawing cache
    Type
    Object

_measureLine(lineIndex) → {Object|Object}

measure every grapheme of a line, populating __charBounds
Parameters:
Name Type Description
lineIndex Number
Source:
Returns:
  • object.width total width of characters
    Type
    Object
  • object.widthOfSpaces length of chars that match this._reSpacesAndTabs
    Type
    Object

_renderControls(ctx, styleOverrideopt)

Renders controls and borders for the object
Parameters:
Name Type Attributes Description
ctx CanvasRenderingContext2D Context to render on
styleOverride Object <optional>
properties to override the object style
Inherited From:
Source:

_set(key, value) → {fabric.Text}

Sets specified property to a specified value
Parameters:
Name Type Description
key String
value *
Overrides:
  • fabric.Object#_set
Source:
Returns:
thisArg
Type
fabric.Text

_setupCompositeOperation(ctx)

Sets canvas globalCompositeOperation for specific object custom composition operation for the particular object can be specifed using globalCompositeOperation property
Parameters:
Name Type Description
ctx CanvasRenderingContext2D Rendering canvas context
Inherited From:
Source:

_splitTextIntoLines(text) → {Array}

Returns the text as an array of lines.
Parameters:
Name Type Description
text String text to split
Source:
Returns:
Lines in the text
Type
Array

adjustPosition(to)

Parameters:
Name Type Description
to String One of 'left', 'center', 'right'
Inherited From:
Source:

animate(property, value) → {fabric.Object}

Animates object's properties
Parameters:
Name Type Description
property String | Object Property to animate (if string) or properties to animate (if object)
value Number | Object Value to animate property to (if string was given first) or options object
Inherited From:
Source:
Tutorials:
Returns:
thisArg
Type
fabric.Object

bringForward(intersectingopt) → {fabric.Object}

Moves an object up in stack of drawn objects
Parameters:
Name Type Attributes Description
intersecting Boolean <optional>
If `true`, send object in front of next upper intersecting object
Inherited From:
Source:
Returns:
thisArg
Type
fabric.Object

bringToFront() → {fabric.Object}

Moves an object to the top of the stack of drawn objects
Inherited From:
Source:
Returns:
thisArg
Type
fabric.Object

calcCoords() → {Object}

Calculate and returns the .coords of an object.
Inherited From:
Source:
Returns:
Object with tl, tr, br, bl ....
Type
Object

calcTransformMatrix(skipGroupopt) → {Array}

calculate trasform Matrix that represent current transformation from object properties.
Parameters:
Name Type Attributes Description
skipGroup Boolean <optional>
return transformMatrix for object and not go upward with parents
Inherited From:
Source:
Returns:
matrix Transform Matrix for the object
Type
Array

center() → {fabric.Object}

Centers object vertically and horizontally on canvas to which is was added last You might need to call `setCoords` on an object after centering, to update controls area.
Inherited From:
Source:
Returns:
thisArg
Type
fabric.Object

centerH() → {fabric.Object}

Centers object horizontally on canvas to which it was added last. You might need to call `setCoords` on an object after centering, to update controls area.
Inherited From:
Source:
Returns:
thisArg
Type
fabric.Object

centerV() → {fabric.Object}

Centers object vertically on canvas to which it was added last. You might need to call `setCoords` on an object after centering, to update controls area.
Inherited From:
Source:
Returns:
thisArg
Type
fabric.Object

cleanStyle(property)

Check if characters in a text have a value for a property whose value matches the textbox's value for that property. If so, the character-level property is deleted. If the character has no other properties, then it is also deleted. Finally, if the line containing that character has no other characters then it also is deleted.
Parameters:
Name Type Description
property string The property to compare between characters and text.
Source:

clone(callback, propertiesToIncludeopt)

Clones an instance, using a callback method will work for every object.
Parameters:
Name Type Attributes Description
callback function Callback is invoked with a clone as a first argument
propertiesToInclude Array <optional>
Any properties that you might want to additionally include in the output
Inherited From:
Source:

cloneAsImage(callback, optionsopt) → {fabric.Object}

Creates an instance of fabric.Image out of an object
Parameters:
Name Type Attributes Description
callback function callback, invoked with an instance as a first argument
options Object <optional>
for clone as image, passed to toDataURL
Properties
Name Type Attributes Description
enableRetinaScaling Boolean <optional>
enable retina scaling for the cloned image
Inherited From:
Source:
Returns:
thisArg
Type
fabric.Object

complexity() → {Number}

Returns complexity of an instance
Overrides:
Source:
Returns:
complexity
Type
Number

containsPoint(point, linesopt, absoluteopt, calculateopt) → {Boolean}

Checks if point is inside the object
Parameters:
Name Type Attributes Description
point fabric.Point Point to check against
lines Object <optional>
object returned from @method _getImageLines
absolute Boolean <optional>
use coordinates without viewportTransform
calculate Boolean <optional>
use coordinates of current position instead of .oCoords
Inherited From:
Source:
Returns:
true if point is inside the object
Type
Boolean

drawBorders(ctx, styleOverride) → {fabric.Object}

Draws borders of an object's bounding box. Requires public properties: width, height Requires public options: padding, borderColor
Parameters:
Name Type Description
ctx CanvasRenderingContext2D Context to draw on
styleOverride Object object to override the object style
Inherited From:
Source:
Returns:
thisArg
Type
fabric.Object

drawBordersInGroup(ctx, options, styleOverride) → {fabric.Object}

Draws borders of an object's bounding box when it is inside a group. Requires public properties: width, height Requires public options: padding, borderColor
Parameters:
Name Type Description
ctx CanvasRenderingContext2D Context to draw on
options object object representing current object parameters
styleOverride Object object to override the object style
Inherited From:
Source:
Returns:
thisArg
Type
fabric.Object

drawCacheOnCanvas(ctx)

Paint the cached copy of the object on the target context.
Parameters:
Name Type Description
ctx CanvasRenderingContext2D Context to render on
Inherited From:
Source:

drawControls(ctx, styleOverride) → {fabric.Object}

Draws corners of an object's bounding box. Requires public properties: width, height Requires public options: cornerSize, padding
Parameters:
Name Type Description
ctx CanvasRenderingContext2D Context to draw on
styleOverride Object object to override the object style
Inherited From:
Source:
Returns:
thisArg
Type
fabric.Object

drawObject(ctx)

Execute the drawing operation for an object on a specified context
Parameters:
Name Type Description
ctx CanvasRenderingContext2D Context to render on
Inherited From:
Source:

drawSelectionBackground(ctx) → {fabric.Object}

Draws a colored layer behind the object, inside its selection borders. Requires public options: padding, selectionBackgroundColor this function is called when the context is transformed has checks to be skipped when the object is on a staticCanvas
Parameters:
Name Type Description
ctx CanvasRenderingContext2D Context to draw on
Inherited From:
Source:
Returns:
thisArg
Type
fabric.Object

enlargeSpaces()

Enlarge space boxes and shift the others
Source:

fxStraighten(callbacks) → {fabric.Object}

Same as fabric.Object.prototype.straighten but with animation
Parameters:
Name Type Description
callbacks Object Object with callback functions
Properties
Name Type Attributes Description
onComplete function <optional>
Invoked on completion
onChange function <optional>
Invoked on every step of animation
Inherited From:
Source:
Returns:
thisArg
Type
fabric.Object

get2DCursorLocation(selectionStartopt, skipWrappingopt)

Returns 2d representation (lineIndex and charIndex) of cursor (or selection start)
Parameters:
Name Type Attributes Description
selectionStart Number <optional>
Optional index. When not given, current selectionStart is used.
skipWrapping Boolean <optional>
consider the location for unwrapped lines. usefull to manage styles.
Source:

getBoundingRect(absoluteopt, calculateopt) → {Object}

Returns coordinates of object's bounding rectangle (left, top, width, height) the box is intented as aligned to axis of canvas.
Parameters:
Name Type Attributes Description
absolute Boolean <optional>
use coordinates without viewportTransform
calculate Boolean <optional>
use coordinates of current position instead of .oCoords
Inherited From:
Source:
Returns:
Object with left, top, width, height properties
Type
Object

getCenterPoint() → {fabric.Point}

Returns the real center coordinates of the object
Inherited From:
Source:
Returns:
Type
fabric.Point

getCompleteStyleDeclaration(lineIndex, charIndex) → {Object}

return a new object that contains all the style property for a character the object returned is newly created
Parameters:
Name Type Description
lineIndex Number of the line where the character is
charIndex Number position of the character on the line
Source:
Returns:
style object
Type
Object

getCoords()

return correct set of coordinates for intersection
Inherited From:
Source:

getHeightOfChar(l, c) → {Number}

return height of char in fontSize for a character at lineIndex, charIndex
Parameters:
Name Type Description
l Number line Index
c Number char index
Source:
Returns:
fontSize of that character
Type
Number

getLocalPointer(e, pointeropt) → {Object}

Returns coordinates of a pointer relative to an object
Parameters:
Name Type Attributes Description
e Event Event to operate upon
pointer Object <optional>
Pointer to operate upon (instead of event)
Inherited From:
Source:
Returns:
Coordinates of a pointer (x, y)
Type
Object

getMeasuringContext(text, optionsopt) → {fabric.Text}

Return a contex for measurement of text string. if created it gets stored for reuse
Parameters:
Name Type Attributes Description
text String Text string
options Object <optional>
Options object
Source:
Returns:
thisArg
Type
fabric.Text

getObjectOpacity() → {Number}

Return the object opacity counting also the group property
Inherited From:
Source:
Returns:
Type
Number

getObjectScaling() → {Object}

Return the object scale factor counting also the group scaling
Inherited From:
Source:
Returns:
object with scaleX and scaleY properties
Type
Object

getPointByOrigin(originX, originY) → {fabric.Point}

Returns the coordinates of the object as if it has a different origin
Parameters:
Name Type Description
originX String Horizontal origin: 'left', 'center' or 'right'
originY String Vertical origin: 'top', 'center' or 'bottom'
Inherited From:
Source:
Returns:
Type
fabric.Point

getScaledHeight() → {Number}

Returns height of an object bounding box counting transformations
Inherited From:
Source:
Returns:
height value
Type
Number

getScaledWidth() → {Number}

Returns width of an object bounding box counting transformations
Inherited From:
Source:
Returns:
width value
Type
Number

getSelectionStyles(startIndexopt, endIndexopt, completeopt) → {Array}

Gets style of a current selection/cursor (at the start position) if startIndex or endIndex are not provided, slectionStart or selectionEnd will be used.
Parameters:
Name Type Attributes Description
startIndex Number <optional>
Start index to get styles at
endIndex Number <optional>
End index to get styles at, if not specified selectionEnd or startIndex + 1
complete Boolean <optional>
get full style or not
Source:
Returns:
styles an array with one, zero or more Style objects
Type
Array

getSvgFilter() → {String}

Returns filter for svg shadow
Inherited From:
Source:
Returns:
Type
String

getSvgId() → {String}

Returns id attribute for svg output
Inherited From:
Source:
Returns:
Type
String

getSvgSpanStyles(style, useWhiteSpace) → {String}

Returns styles-string for svg-export
Parameters:
Name Type Description
style Object style properties for the span a boolean to skip shadow filter output
useWhiteSpace Boolean a boolean to include an additional attribute in the style.
Inherited From:
Source:
Returns:
Type
String

getSvgStyles(skipShadow) → {String}

Returns styles-string for svg-export
Parameters:
Name Type Description
skipShadow Boolean a boolean to skip shadow filter output
Overrides:
Source:
Returns:
Type
String

getSvgTransform() → {String}

Returns transform-string for svg-export
Inherited From:
Source:
Returns:
Type
String

getSvgTransformMatrix() → {String}

Returns transform-string for svg-export from the transform matrix of single elements
Inherited From:
Source:
Returns:
Type
String

getViewportTransform() → {Boolean}

Retrieves viewportTransform from Object's canvas if possible
Inherited From:
Source:
Returns:
Type
Boolean

hasStateChanged(propertySetopt) → {Boolean}

Returns true if object state (one of its state properties) was changed
Parameters:
Name Type Attributes Description
propertySet String <optional>
optional name for the set of property we want to save
Inherited From:
Source:
Returns:
true if instance' state has changed since `fabric.Object#saveState` was called
Type
Boolean

initDimensions()

Initialize or update text dimensions. Updates this.width and this.height with the proper values. Does not return dimensions.
Source:

initialize(text, optionsopt) → {fabric.Text}

Constructor
Parameters:
Name Type Attributes Description
text String Text string
options Object <optional>
Options object
Overrides:
Source:
Returns:
thisArg
Type
fabric.Text

intersectsWithObject(other, absoluteopt, calculateopt) → {Boolean}

Checks if object intersects with another object
Parameters:
Name Type Attributes Description
other Object Object to test
absolute Boolean <optional>
use coordinates without viewportTransform
calculate Boolean <optional>
use coordinates of current position instead of .oCoords
Inherited From:
Source:
Returns:
true if object intersects with another object
Type
Boolean

intersectsWithRect(pointTL, pointBR, absoluteopt, calculateopt) → {Boolean}

Checks if object intersects with an area formed by 2 points
Parameters:
Name Type Attributes Description
pointTL Object top-left point of area
pointBR Object bottom-right point of area
absolute Boolean <optional>
use coordinates without viewportTransform
calculate Boolean <optional>
use coordinates of current position instead of .oCoords
Inherited From:
Source:
Returns:
true if object intersects with an area formed by 2 points
Type
Boolean

isCacheDirty(skipCanvas)

Check if cache is dirty
Parameters:
Name Type Description
skipCanvas Boolean skip canvas checks because this object is painted on parent canvas.
Inherited From:
Source:

isContainedWithinObject(other, absoluteopt, calculateopt) → {Boolean}

Checks if object is fully contained within area of another object
Parameters:
Name Type Attributes Description
other Object Object to test
absolute Boolean <optional>
use coordinates without viewportTransform
calculate Boolean <optional>
use coordinates of current position instead of .oCoords
Inherited From:
Source:
Returns:
true if object is fully contained within area of another object
Type
Boolean

isContainedWithinRect(pointTL, pointBR, absoluteopt, calculateopt) → {Boolean}

Checks if object is fully contained within area formed by 2 points
Parameters:
Name Type Attributes Description
pointTL Object top-left point of area
pointBR Object bottom-right point of area
absolute Boolean <optional>
use coordinates without viewportTransform
calculate Boolean <optional>
use coordinates of current position instead of .oCoords
Inherited From:
Source:
Returns:
true if object is fully contained within area formed by 2 points
Type
Boolean

isControlVisible(controlName) → {Boolean}

Returns true if the specified control is visible, false otherwise.
Parameters:
Name Type Description
controlName String The name of the control. Possible values are 'tl', 'tr', 'br', 'bl', 'ml', 'mt', 'mr', 'mb', 'mtr'.
Inherited From:
Source:
Returns:
true if the specified control is visible, false otherwise
Type
Boolean

isEmptyStyles(lineIndex) → {Boolean}

Returns true if object has no styling or no styling in a line
Parameters:
Name Type Description
lineIndex Number
Source:
Returns:
Type
Boolean

isOnScreen(calculateopt) → {Boolean}

Checks if object is contained within the canvas with current viewportTransform the check is done stopping at first point that appear on screen
Parameters:
Name Type Attributes Description
calculate Boolean <optional>
use coordinates of current position instead of .oCoords
Inherited From:
Source:
Returns:
true if object is fully contained within canvas
Type
Boolean

isType(type) → {Boolean}

Returns true if specified type is identical to the type of an instance
Parameters:
Name Type Description
type String Type to check against
Inherited From:
Source:
Returns:
Type
Boolean

measureLine(lineIndex) → {Number}

measure a text line measuring all characters.
Parameters:
Name Type Description
lineIndex Number line number
Source:
Returns:
Line width
Type
Number

moveTo(index) → {fabric.Object}

Moves an object to specified level in stack of drawn objects
Parameters:
Name Type Description
index Number New position of object
Inherited From:
Source:
Returns:
thisArg
Type
fabric.Object

needsItsOwnCache()

When set to `true`, force the object to have its own cache, even if it is inside a group it may be needed when your object behave in a particular way on the cache and always needs its own isolated canvas to render correctly. Created to be overridden since 1.7.12
Inherited From:
Source:
Returns:
false

onDeselect()

Callback; invoked right before object is about to go from active to inactive
Overrides:
Source:

onSelect(optionsopt)

This callback function is called every time _discardActiveObject or _setActiveObject try to to select this object. If the function returns true, the process is cancelled
Parameters:
Name Type Attributes Description
options Object <optional>
options sent from the upper functions
Properties
Name Type Attributes Description
e Event <optional>
event if the process is generated by an event
Inherited From:
Source:

removeStyle(props)

Remove a style property or properties from all individual character styles in a text object. Deletes the character style object if it contains no other style props. Deletes a line style object if it contains no other character styles.
Parameters:
Name Type Description
props String The property to remove from character styles.
Source:

render(ctx)

Renders text instance on a specified context
Parameters:
Name Type Description
ctx CanvasRenderingContext2D Context to render on
Overrides:
Source:

rotate(angle) → {fabric.Object}

Sets "angle" of an instance with centered rotation
Parameters:
Name Type Description
angle Number Angle value (in degrees)
Inherited From:
Source:
Returns:
thisArg
Type
fabric.Object

saveState(optionsopt) → {fabric.Object}

Saves state of an object
Parameters:
Name Type Attributes Description
options Object <optional>
Object with additional `stateProperties` array to include when saving state
Inherited From:
Source:
Returns:
thisArg
Type
fabric.Object

scale(value) → {fabric.Object}

Scales an object (equally by x and y)
Parameters:
Name Type Description
value Number Scale factor
Inherited From:
Source:
Returns:
thisArg
Type
fabric.Object

scaleToHeight(value, absolute) → {fabric.Object}

Scales an object to a given height, with respect to bounding box (scaling by x/y equally)
Parameters:
Name Type Description
value Number New height value
absolute Boolean ignore viewport
Inherited From:
Source:
Returns:
thisArg
Type
fabric.Object

scaleToWidth(value, absolute) → {fabric.Object}

Scales an object to a given width, with respect to bounding box (scaling by x/y equally)
Parameters:
Name Type Description
value Number New width value
absolute Boolean ignore viewport
Inherited From:
Source:
Returns:
thisArg
Type
fabric.Object

sendBackwards(intersectingopt) → {fabric.Object}

Moves an object down in stack of drawn objects
Parameters:
Name Type Attributes Description
intersecting Boolean <optional>
If `true`, send object behind next lower intersecting object
Inherited From:
Source:
Returns:
thisArg
Type
fabric.Object

sendToBack() → {fabric.Object}

Moves an object to the bottom of the stack of drawn objects
Inherited From:
Source:
Returns:
thisArg
Type
fabric.Object

setColor(color) → {fabric.Object}

Sets "color" of an instance (alias of `set('fill', …)`)
Parameters:
Name Type Description
color String Color value
Inherited From:
Source:
Returns:
thisArg
Type
fabric.Object

setControlsVisibility(optionsopt) → {fabric.Object}

Sets the visibility state of object controls.
Parameters:
Name Type Attributes Description
options Object <optional>
Options object
Properties
Name Type Attributes Description
bl Boolean <optional>
true to enable the bottom-left control, false to disable it
br Boolean <optional>
true to enable the bottom-right control, false to disable it
mb Boolean <optional>
true to enable the middle-bottom control, false to disable it
ml Boolean <optional>
true to enable the middle-left control, false to disable it
mr Boolean <optional>
true to enable the middle-right control, false to disable it
mt Boolean <optional>
true to enable the middle-top control, false to disable it
tl Boolean <optional>
true to enable the top-left control, false to disable it
tr Boolean <optional>
true to enable the top-right control, false to disable it
mtr Boolean <optional>
true to enable the middle-top-rotate control, false to disable it
Inherited From:
Source:
Returns:
thisArg
Type
fabric.Object

setControlVisible(controlName, visible) → {fabric.Object}

Sets the visibility of the specified control.
Parameters:
Name Type Description
controlName String The name of the control. Possible values are 'tl', 'tr', 'br', 'bl', 'ml', 'mt', 'mr', 'mb', 'mtr'.
visible Boolean true to set the specified control visible, false otherwise
Inherited From:
Source:
Returns:
thisArg
Type
fabric.Object

setCoords(ignoreZoomopt, skipAbsoluteopt) → {fabric.Object}

Sets corner position coordinates based on current angle, width and height See https://github.com/kangax/fabric.js/wiki/When-to-call-setCoords
Parameters:
Name Type Attributes Description
ignoreZoom Boolean <optional>
set oCoords with or without the viewport transform.
skipAbsolute Boolean <optional>
skip calculation of aCoords, usefull in setViewportTransform
Inherited From:
Source:
Returns:
thisArg
Type
fabric.Object

setGradient(property, optionsopt) → {fabric.Object}

Sets gradient (fill or stroke) of an object Backwards incompatibility note: This method was named "setGradientFill" until v1.1.0
Parameters:
Name Type Attributes Description
property String Property name 'stroke' or 'fill'
options Object <optional>
Options object
Properties
Name Type Attributes Default Description
type String <optional>
Type of gradient 'radial' or 'linear'
x1 Number <optional>
0 x-coordinate of start point
y1 Number <optional>
0 y-coordinate of start point
x2 Number <optional>
0 x-coordinate of end point
y2 Number <optional>
0 y-coordinate of end point
r1 Number <optional>
0 Radius of start point (only for radial gradients)
r2 Number <optional>
0 Radius of end point (only for radial gradients)
colorStops Object <optional>
Color stops object eg. {0: 'ff0000', 1: '000000'}
gradientTransform Object <optional>
transforMatrix for gradient
Inherited From:
Source:
See:
Returns:
thisArg
Type
fabric.Object
Examples

Set linear gradient

object.setGradient('fill', {
  type: 'linear',
  x1: -object.width / 2,
  y1: 0,
  x2: object.width / 2,
  y2: 0,
  colorStops: {
    0: 'red',
    0.5: '#005555',
    1: 'rgba(0,0,255,0.5)'
  }
});
canvas.renderAll();

Set radial gradient

object.setGradient('fill', {
  type: 'radial',
  x1: 0,
  y1: 0,
  x2: 0,
  y2: 0,
  r1: object.width / 2,
  r2: 10,
  colorStops: {
    0: 'red',
    0.5: '#005555',
    1: 'rgba(0,0,255,0.5)'
  }
});
canvas.renderAll();

setOnGroup()

This callback function is called by the parent group of an object every time a non-delegated property changes on the group. It is passed the key and value as parameters. Not adding in this function's signature to avoid Travis build error about unused variables.
Inherited From:
Source:

setOptions(optionsopt)

Sets object's properties from options
Parameters:
Name Type Attributes Description
options Object <optional>
Options object
Inherited From:
Source:

setPatternFill(options) → {fabric.Object}

Sets pattern fill of an object
Parameters:
Name Type Description
options Object Options object
Properties
Name Type Attributes Default Description
source String | HTMLImageElement Pattern source
repeat String <optional>
repeat Repeat property of a pattern (one of repeat, repeat-x, repeat-y or no-repeat)
offsetX Number <optional>
0 Pattern horizontal offset from object's left/top corner
offsetY Number <optional>
0 Pattern vertical offset from object's left/top corner
Inherited From:
Source:
See:
Returns:
thisArg
Type
fabric.Object
Example

Set pattern

fabric.util.loadImage('http://fabricjs.com/assets/escheresque_ste.png', function(img) {
  object.setPatternFill({
    source: img,
    repeat: 'repeat'
  });
  canvas.renderAll();
});

setPositionByOrigin(pos, originX, originY) → {void}

Sets the position of the object taking into consideration the object's origin
Parameters:
Name Type Description
pos fabric.Point The new position of the object
originX String Horizontal origin: 'left', 'center' or 'right'
originY String Vertical origin: 'top', 'center' or 'bottom'
Inherited From:
Source:
Returns:
Type
void

setSelectionStyles(stylesopt, startIndexopt, endIndexopt) → {fabric.IText}

Sets style of a current selection, if no selection exist, do not set anything.
Parameters:
Name Type Attributes Description
styles Object <optional>
Styles object
startIndex Number <optional>
Start index to get styles at
endIndex Number <optional>
End index to get styles at, if not specified selectionEnd or startIndex + 1
Source:
Returns:
thisArg
Type
fabric.IText

setShadow(optionsopt) → {fabric.Object}

Sets shadow of an object
Parameters:
Name Type Attributes Description
options Object | String <optional>
Options object or string (e.g. "2px 2px 10px rgba(0,0,0,0.2)")
Properties
Name Type Attributes Default Description
color String <optional>
rgb(0,0,0) Shadow color
blur Number <optional>
0 Shadow blur
offsetX Number <optional>
0 Shadow horizontal offset
offsetY Number <optional>
0 Shadow vertical offset
Inherited From:
Source:
See:
Returns:
thisArg
Type
fabric.Object
Examples

Set shadow with string notation

object.setShadow('2px 2px 10px rgba(0,0,0,0.2)');
canvas.renderAll();

Set shadow with object notation

object.setShadow({
  color: 'red',
  blur: 10,
  offsetX: 20,
  offsetY: 20
});
canvas.renderAll();

setupState(optionsopt) → {fabric.Object}

Setups state of an object
Parameters:
Name Type Attributes Description
options Object <optional>
Object with additional `stateProperties` array to include when saving state
Inherited From:
Source:
Returns:
thisArg
Type
fabric.Object

shouldCache() → {Boolean}

Decide if the object should cache or not. Create its own cache level objectCaching is a global flag, wins over everything needsItsOwnCache should be used when the object drawing method requires a cache step. None of the fabric classes requires it. Generally you do not cache objects in groups because the group outside is cached.
Inherited From:
Source:
Returns:
Type
Boolean

straighten() → {fabric.Object}

Straightens an object (rotating it from current angle to one of 0, 90, 180, 270, etc. depending on which is closer)
Inherited From:
Source:
Returns:
thisArg
Type
fabric.Object

styleHas(lineIndex) → {Boolean}

Returns true if object has a style property or has it ina specified line
Parameters:
Name Type Description
lineIndex Number
Source:
Returns:
Type
Boolean

toDatalessObject(propertiesToIncludeopt) → {Object}

Returns (dataless) object representation of an instance
Parameters:
Name Type Attributes Description
propertiesToInclude Array <optional>
Any properties that you might want to additionally include in the output
Inherited From:
Source:
Returns:
Object representation of an instance
Type
Object

toDataURL(options) → {String}

Converts an object into a data-url-like string
Parameters:
Name Type Description
options Object Options object
Properties
Name Type Attributes Default Description
format String <optional>
png The format of the output image. Either "jpeg" or "png"
quality Number <optional>
1 Quality level (0..1). Only used for jpeg.
multiplier Number <optional>
1 Multiplier to scale by
left Number <optional>
Cropping left offset. Introduced in v1.2.14
top Number <optional>
Cropping top offset. Introduced in v1.2.14
width Number <optional>
Cropping width. Introduced in v1.2.14
height Number <optional>
Cropping height. Introduced in v1.2.14
enableRetina Boolean <optional>
Enable retina scaling for clone image. Introduce in 1.6.4
Inherited From:
Source:
Returns:
Returns a data: URL containing a representation of the object in the format specified by options.format
Type
String

toJSON(propertiesToIncludeopt) → {Object}

Returns a JSON representation of an instance
Parameters:
Name Type Attributes Description
propertiesToInclude Array <optional>
Any properties that you might want to additionally include in the output
Inherited From:
Source:
Returns:
JSON
Type
Object

toLocalPoint(point, originX, originY) → {fabric.Point}

Returns the point in local coordinates
Parameters:
Name Type Description
point fabric.Point The point relative to the global coordinate system
originX String Horizontal origin: 'left', 'center' or 'right'
originY String Vertical origin: 'top', 'center' or 'bottom'
Inherited From:
Source:
Returns:
Type
fabric.Point

toObject(propertiesToIncludeopt) → {Object}

Returns object representation of an instance
Parameters:
Name Type Attributes Description
propertiesToInclude Array <optional>
Any properties that you might want to additionally include in the output
Overrides:
Source:
Returns:
Object representation of an instance
Type
Object

toString() → {String}

Returns string representation of an instance
Overrides:
Source:
Returns:
String representation of text object
Type
String

toSVG(reviveropt) → {String}

Returns SVG representation of an instance
Parameters:
Name Type Attributes Description
reviver function <optional>
Method for further parsing of svg representation.
Source:
Returns:
svg representation of an instance
Type
String

transform(ctx, fromLeft)

Transforms context when rendering an object
Parameters:
Name Type Description
ctx CanvasRenderingContext2D Context
fromLeft Boolean When true, context is transformed to object's top/left corner. This is used when rendering text on Node
Inherited From:
Source:

translateToCenterPoint(point, originX, originY) → {fabric.Point}

Translates the coordinates from origin to center coordinates (based on the object's dimensions)
Parameters:
Name Type Description
point fabric.Point The point which corresponds to the originX and originY params
originX String Horizontal origin: 'left', 'center' or 'right'
originY String Vertical origin: 'top', 'center' or 'bottom'
Inherited From:
Source:
Returns:
Type
fabric.Point

translateToGivenOrigin(point, fromOriginX, fromOriginY, toOriginX, toOriginY) → {fabric.Point}

Translates the coordinates from a set of origin to another (based on the object's dimensions)
Parameters:
Name Type Description
point fabric.Point The point which corresponds to the originX and originY params
fromOriginX String Horizontal origin: 'left', 'center' or 'right'
fromOriginY String Vertical origin: 'top', 'center' or 'bottom'
toOriginX String Horizontal origin: 'left', 'center' or 'right'
toOriginY String Vertical origin: 'top', 'center' or 'bottom'
Inherited From:
Source:
Returns:
Type
fabric.Point

translateToOriginPoint(center, originX, originY) → {fabric.Point}

Translates the coordinates from center to origin coordinates (based on the object's dimensions)
Parameters:
Name Type Description
center fabric.Point The point which corresponds to center of the object
originX String Horizontal origin: 'left', 'center' or 'right'
originY String Vertical origin: 'top', 'center' or 'bottom'
Inherited From:
Source:
Returns:
Type
fabric.Point

viewportCenter() → {fabric.Object}

Centers object on current viewport of canvas to which it was added last. You might need to call `setCoords` on an object after centering, to update controls area.
Inherited From:
Source:
Returns:
thisArg
Type
fabric.Object

viewportCenterH() → {fabric.Object}

Centers object horizontally on current viewport of canvas to which it was added last. You might need to call `setCoords` on an object after centering, to update controls area.
Inherited From:
Source:
Returns:
thisArg
Type
fabric.Object

viewportCenterV() → {fabric.Object}

Centers object vertically on current viewport of canvas to which it was added last. You might need to call `setCoords` on an object after centering, to update controls area.
Inherited From:
Source:
Returns:
thisArg
Type
fabric.Object

willDrawShadow() → {Boolean}

Check if this object or a child object will cast a shadow used by Group.shouldCache to know if child has a shadow recursively
Inherited From:
Source:
Returns:
Type
Boolean