Purpose
Specifies a line style for graphic objects. You can use this clause in the MapBasic window in MapInfo Pro.
Syntax
Pen pen_expr
pen_expr is a Pen expression, for example, MakePen( width, pattern, color )
Description
The Pen clause specifies a line style―in other words, a set of thickness, pattern, and color settings that dictate the appearance of a line or polyline object.
The Pen clause is not a complete MapBasic statement. Various object-related statements, such as the Create Line statement, let you include a Pen clause to specify an object's line style. The keyword Pen may be followed by an expression which evaluates to a Pen value. This expression can be a Pen variable:
Pen pen_var
or a call to a function (for example, the CurrentPen() function or the MakePen() function) which returns a Pen value:
Pen MakePen(1, 2, BLUE)
You can create an interleaved line style by adding 128 to the pattern value. The following example draws a two (2) pixel cyan colored line using pattern 101 in an interleaved style (101+128=229):
Pen MakePen(2, 229, CYAN)
With some MapBasic statements (for example, the Set Map statement), the keyword Pen can be followed immediately by the three parameters that define a Pen style (width, pattern, and color) within parentheses:
Pen(1, 2, BLUE)
Some MapBasic statements take a Pen expression as a parameter (for example, the name of a Pen variable), rather than a full Pen clause (the keyword Pen followed by the name of a Pen variable). The Alter Object statement is one example.
You can also directly assign a string-based style clause into a variable of type Pen. For example,
dim fnt as Font
fnt = "Font (""Arial"",0,9,0)"
'this assignment will work now, and string-based font clause will convert
Font variable.
The following table summarizes the components that define a Pen:
Component | Description |
---|---|
width | Integer value, usually from 1 to 7, representing the thickness of the line (in pixels). To create an invisible line style, specify a width of zero, and use a pattern value of 1 (one). To specify a width using points, calculate the pen width from a point size using the PointsToPenWidth() function. This calculation multiplies the point size by 10 and then adds 10 to the result, so the pen width is always larger than 10. |
pattern | Integer value from 1 to 118; see table below. Pattern 1 is invisible.
To specify an interleaved line style, add 128 to the pattern. However, not all patterns benefit from an interleaved line style. |
color | Integer RGB color value; see RGB() function. |
The available pen patterns appear in the figure below.
Examples
Include "MAPBASIC.DEF"
Dim cable As Object
Create Line
Into Variable cable
(73.5, 42.6) (73.67, 42.9)
Pen MakePen(1, 2, BLACK)
Apply line styles to a layer in a map as a layer style override: Pen width = 5 points; Line style B17 in line style picker; penpattern = 66.
Set Map Window <windowid>
Layer 1 Display Global
Global Line (60,194,16711680)
' Interleave: 194 = 66 + 128
Set Map Window 234499920
Layer 1 Display Global
Global Line MakePen(PointsToPenWidth(5),66,16711680)
' 5 point line, non-interleaved
See Also:
Alter Object statement, CreateLine() function, Create Pline statement, CurrentPen() function, IsPenWidthPixels() function, MakePen() function, PointsToPenWidth() function, PenWidthToPoints() function, RGB() function, Set Style statement