Style
Style is used for changing the visual styles of items contained within a Paper.js project and is returned by item.style and project.currentStyle.
All properties of Style are also reflected directly in Item, i.e.: item.fillColor.
To set multiple style properties in one go, you can pass an object to item.style. This is a convenient way to define a style once and apply it to a series of items:
Example: Styling paths
var path = new Path.Circle(new Point(80, 50), 30);
path.style = {
fillColor: new Color(1, 0, 0),
strokeColor: 'black',
strokeWidth: 5
};Example: Styling text items
var text = new PointText(view.center);
text.content = 'Hello world.';
text.style = {
fontFamily: 'Courier New',
fontWeight: 'bold',
fontSize: 20,
fillColor: 'red',
justification: 'center'
};Example: Styling groups
Properties
viewThe view that this style belongs to.
Read only.
Type:
View
Stroke Style
strokeColorThe color of the stroke.
Type:
Color⟋null
Example:Setting the stroke color of a path:
strokeWidthThe width of the stroke.
Default:
1Type:
Number
Example:Setting an item's stroke width:
strokeCapThe shape to be used at the beginning and end of open
Pathitems, when they have a stroke.Values:
'round','square','butt'Default:
'butt'Type:
String
Example:A look at the different stroke caps:
strokeJoinThe shape to be used at the segments and corners of
Pathitems when they have a stroke.Values:
'miter','round','bevel'Default:
'miter'Type:
String
Example:A look at the different stroke joins:
strokeScalingSpecifies whether the stroke is to be drawn taking the current affine transformation into account (the default behavior), or whether it should appear as a non-scaling stroke.
Default:
trueType:
Boolean
dashOffsetThe dash offset of the stroke.
Default:
0Type:
Number
dashArraySpecifies an array containing the dash and gap lengths of the stroke.
Default:
[]Type:
Array of
Numbers
Example:
miterLimitThe miter limit of the stroke. When two line segments meet at a sharp angle and miter joins have been specified for
strokeJoin, it is possible for the miter to extend far beyond thestrokeWidthof the path. The miterLimit imposes a limit on the ratio of the miter length to thestrokeWidth.Default:
10Type:
Number
Fill Style
fillColorThe fill color.
Type:
Color⟋null
Example:Setting the fill color of a path to red:
fillRuleThe fill-rule with which the shape gets filled. Please note that only modern browsers support fill-rules other than
'nonzero'.Values:
'nonzero','evenodd'Default:
'nonzero'Type:
String
Shadow Style
shadowColorThe shadow color.
Type:
Color⟋null
Example:Creating a circle with a black shadow:
shadowBlurThe shadow’s blur radius.
Default:
0Type:
Number
shadowOffsetThe shadow’s offset.
Default:
0Type:
Point
Selection Style
selectedColorThe color the item is highlighted with when selected. If the item does not specify its own color, the color defined by its layer is used instead.
Type:
Color⟋null
Character Style
fontFamilyThe font-family to be used in text content.
Default:
'sans-serif'Type:
String
fontWeightThe font-weight to be used in text content.
Default:
'normal'Type:
String⟋Number
fontSizeThe font size of text content, as a number in pixels, or as a string with optional units
'px','pt'and'em'.Default:
10Type:
Number⟋String
leadingThe text leading of text content.
Default:
fontSize * 1.2Type:
Number⟋String
Paragraph Style
justificationThe justification of text paragraphs.
Values:
'left','right','center'Default:
'left'Type:
String
Was this helpful?