In addition to standard pens you can define you own.
To define a pen use method addCustomPen(name,pen_def)
,
where name
- name of your pen, pen_def
- pen definition object.
Two types of pen definitions Shape Pen and Compound Pen are described below.
Before using your a pen on the Pen Panel create an icon
and assing it using the method setIcons()
,
for example:
painter.setIcon({ 'rohmb' : 'rhomb.gif' });
Shape pen puts specified shapes along drawn curve.
Example:painter.addCustomPen('rhomb', { type : 'shape', path : 'M -4 0 L 0 -4 L 4 0 L 0 4 Z', advance: 20, width : 8 });
name
- defines the pen name wich can be used for the pen panel or custom tools.pen_def
is an object defining the pen parameters:type
- type of pen definition (must be 'shape')path
- path describing the shape (see below)advance
- distance between the shapes along the curvewidth
- pen width (maximum width of the shape in all possible direction - 360 around)M x y
- move pointer toL x y
- line toQ x1 y1 x2 y2
- quadratic bezier segmentC x1 y1 x2 y2 x3 y3
- cubic bezier segmentZ
- close the pathCompound Pen is summ or difference of two pens, usually a standard pen and a shape pen.
Example:painter.addCustomPen( 'solid_with_rhomb_holes', { type : 'compound', pen1 : { width:8 }, //solid pen pen2 : { type : 'shape', path : 'M -4 0 L 0 -4 L 4 0 L 0 4 Z', advance: 20 }, operation : 'sub', //subtract pen2 from pen1 width : 8 });
type
- must be 'compound'pen1
- the 1st pen in the compoundpen2
- the 2nd pen in the compoundoperation
- 'add' or 'sub'width
- effective pen width (in any direction - maximum)