User Guide
Ruby Component
Advanced Pens
The Drawing section we covered the very basics of Pens. In this section we'll look at Pens in more detail and show you some of the more
advanced things that you can do with them.
Pen Alignment
By default lines drawn with a pen are centred. This means that if you have a thicker pen then part of the pen will fall on either side of the line.
Sometimes this is not the behaviour you want so you can change it using the setAlignment method for the Pen.
setAlignment alignmentType
There are just 2 options for the alignment type:
0 or “center” The pen is centred on the line
1 or “inset” The pen is inset so its outer edge always follows the line
The example below shows how the two types work in practice. The two rectangles are exactly the same size. However, the top rectangle is
drawn with the alignment centred. You can see how this makes the rectangle appear larger.
Line Joins
When you draw any shape that contains straight lines the joints between the lines are mitred together by default. A mitre joint is created
between two lines by extending both lines artificially until they cross each other and then cutting off the protruding edges.
In the diagram above the blue lines show the artificial extensions. The green area is kept to form the joint and the blue protruding parts are
removed. The end result is shown on the right.
You can change the way in which lines are joined using the setLineJoin method of the Pen object.
141 of 212
Green area is kept to form joint
End result