65.1.2 Geometric Pens

A geometric pen is used in applications that require scalable lines, lines with unique end-styles, lines with unique join-styles, or lines that are wider than a single pixel. For example, a spreadsheet application could define each of the bars in a bar-graph as a wide line that is drawn using a geometric pen.

In addition to the three attributes shared with cosmetic pens (width, style, and color), geometric pens possess four additional attributes: a pattern, an optional hatch, an end style, and a join style.

A pattern and an optional hatch attribute are normally associated with a brush; however, they are also associated with geometric pens.The following illustration shows various lines drawn with four different geometric pens. Each pen was created with a different pattern attribute:

The first line in the previous illustration is drawn using one of the six available hatch patterns. The next line is drawn using the hollow pattern (which is identical to the null pattern). The third line is drawn using a custom pattern that was created from an 8-pixel by 8-pixel bitmap. (For more information about bitmaps and their creation, see Chapter 63, “Bitmaps.”)The fourth line is drawn using a solid pattern. A pattern is obtained by creating a brush and passing its handle to the ExtCreatePen function.

The following illustration shows lines drawn with six different geometric pens. Each pen was created with a different hatch-pattern attribute:

Two other attributes that distinguish geometric pens from cosmetic pens are the end cap and the join style. The end-cap attribute specifies the shape of a geometric pen: it can be round, square, or flat. The following illustration shows three parallel lines drawn with each type of end cap:

Geometric-Pen End-Caps

As the illustration shows, the round and square end-caps extend past the starting and ending points of a line drawn with a geometric pen while the flat end-cap does not.

The join-style attribute specifies how the ends of two geometric lines are joined: it can be beveled, mitred, or round. The following illustration shows three pairs of connected lines drawn with three different geometric pens. Each pen was created with a different join-style attribute: