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

  • view

    The view that this style belongs to.

    Read only.

    • Type:

    • View

Stroke Style

  • strokeColor

    The color of the stroke.

    • Type:

    • Color⟋null

    Example:Setting the stroke color of a path:

  • strokeWidth

    The width of the stroke.

    • Default:

    • 1

    • Type:

    • Number

    Example:Setting an item's stroke width:

  • strokeCap

    The shape to be used at the beginning and end of open Path items, when they have a stroke.

    • Values:

    • 'round', 'square', 'butt'

    • Default:

    • 'butt'

    • Type:

    • String

    Example:A look at the different stroke caps:

  • strokeJoin

    The shape to be used at the segments and corners of Path items when they have a stroke.

    • Values:

    • 'miter', 'round', 'bevel'

    • Default:

    • 'miter'

    • Type:

    • String

    Example:A look at the different stroke joins:

  • strokeScaling

    Specifies 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:

    • true

    • Type:

    • Boolean

  • dashOffset

    The dash offset of the stroke.

    • Default:

    • 0

    • Type:

    • Number

  • dashArray

    Specifies an array containing the dash and gap lengths of the stroke.

    • Default:

    • []

    • Type:

    • Array of Numbers

    Example:

  • miterLimit

    The 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 the strokeWidth of the path. The miterLimit imposes a limit on the ratio of the miter length to the strokeWidth.

    • Default:

    • 10

    • Type:

    • Number

Fill Style

  • fillColor

    The fill color.

    • Type:

    • Color⟋null

    Example:Setting the fill color of a path to red:

  • fillRule

    The 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

  • shadowColor

    The shadow color.

    • Type:

    • Color⟋null

    Example:Creating a circle with a black shadow:

  • shadowBlur

    The shadow’s blur radius.

    • Default:

    • 0

    • Type:

    • Number

  • shadowOffset

    The shadow’s offset.

    • Default:

    • 0

    • Type:

    • Point

Selection Style

  • selectedColor

    The 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

  • fontFamily

    The font-family to be used in text content.

    • Default:

    • 'sans-serif'

    • Type:

    • String

  • fontWeight

    The font-weight to be used in text content.

    • Default:

    • 'normal'

    • Type:

    • String⟋Number

  • fontSize

    The font size of text content, as a number in pixels, or as a string with optional units 'px', 'pt' and 'em'.

    • Default:

    • 10

    • Type:

    • Number⟋String

  • leading

    The text leading of text content.

    • Default:

    • fontSize * 1.2

    • Type:

    • Number⟋String

Paragraph Style

  • justification

    The justification of text paragraphs.

    • Values:

    • 'left', 'right', 'center'

    • Default:

    • 'left'

    • Type:

    • String

Was this helpful?