PrintPos is a positional print method that outputs single-line text. There are several overloaded versions, but the "full version" looks like this:
procedure PrintPos(
Text: string;
Justify: TPrintJustify;
X, Y, LeftLimit, RightLimit: Double;
TextStyle: TTextStyle = tsNormal;
TruncateMode: TStringCutMode = scmChar); overload;
When PrintPos has output text, it advances the cursor X position (XPos) to the end of that text, allowing further text to begin printing immediately afterwards. In contrast, the cursor Y position (YPos) is not changed. This makes it easier to realign text vertically and maintain a logical vertical reference point.
Example A: Positional Behaviour
To demonstrate this behaviour, consider the following code which outputs four strings. It starts by explicitly setting a vertical YPos to 30mm. The string "Elsewhere" is then printed at cursor position (110, 45). Although the XPos will be advanced from 110 by the width of "Elsewhere", the YPos will remain at 30mm as set (ie it will not change to 45mm, the YPos for "Elsewhere").
This means that when "One " is printed at XPos = 100, the current YPos of 30mm will apply. When "Two " and then "Three" are both printed without any positional coordinates, the output simply follows on sequentially as the XPos is advanced.
The result looks as though the single string "One Two Three" was output at (100, 30).
The Code | The Output |
YPos := 30; |
Note: To advance the cursor y-position following a call to PrintPos, you could call the NewLine or AdvanceYPos methods, for example, or directly reset the YPos property.
Example B: Text Justification
PrintPos can left, centre, or right justify text using the Justify parameter. In this code, "Sample Text" is printed for each justification about XPos = 100mm.
The Code | The Output |
PrintPos('Sample Text', jLeft, 100); |
Example C: Text (Font) Styles
PrintPos can apply any combination of font style using the TextStyle parameter. The basic styles available are bold, italic, strikethrough, and underline.
The Code | The Output |
YPos := 30; etc etc PrintPos('Sample Text', jLeft, 100, tsBIS); |
The available TextStyle values (TTextStyle) are: tsNormal (default), tsB, tsU, tsI, tsS, tsBU, tsBI, tsBS, tsIU, tsSU, tsIS, tsBIU, tsBSU, tsBIS, tsISU and tsBISU.
These styles apply only to the text being output in the respective PrintPos statement - there is no need to turn the specified style off because tsNormal is restored automatically.
Example D: Text Truncation and Text Extents
Justified text can also be output within left and right extents using the LeftLimit and RightLimit parameters. The point about which text is justified may be inside or outside the text extent range. In addition, the TruncateMode parameter allows you to control how text is truncated at the limits. Clip by character with scmChar mode (default), or clip by word with scmWord mode.
This sample code prints the phrase "Sample Text Truncation" between the limits of 100mm and 130mm, using justification and truncation variations:
The Code | The Output |
YPos := 90; |