Print Positioning in SQR | KEVIN RESCHENBERG 09-27-2004 |
Did you ever wish you could use SQR to print more complex forms and statements? SQR can do
just about anything that, for example, Crystal Reports can do in terms of fonts and positioning.
We just need to be a little tricky about how we code the report.
Today's tip concerns positioning of elements on a printed page.
One of SQR's convenient features is the way it positions lines and columns on a page. We
can specify a particular line and column or specify relative positioning:
print $x (3, 5) ! Line 3, column 5
print $x (+1, 1) ! Next line, column 1
print $x (-1, +5) ! One line up, 5 columns to the right
print $x () ! Use current position
The page is laid out as a virtual grid, where each cell is the height and width of an average
character. This works well for a fixed-pitch font such as Courier. It can be difficult, though,
when we are using proportional fonts such as Helvetica (similar to Arial) or Times Roman. It
is also difficult to position an element precisely, as might be required in creating a form
or complex statement.
One way around this is to reduce the grid size. We can tell SQR that a typical character is only
one point high and one point wide (where a point is 1/72 of an inch). This tiny grid will allow
us to position a word or graphic at any place on the page to a precision of 1/72 inch.
In a BEGIN-SETUP section, code something like this:
#define ORIENTATION PORTRAIT ! Or LANDSCAPE
declare-layout default
orientation={ORIENTATION}
top-margin=.5
left-margin=1
line-height=1 ! Using a 1-point grid (72 per inch)
char-width=1 ! Using a 1-point grid (72 per inch)
#if '{ORIENTATION}' = 'PORTRAIT'
max-lines=792
max-columns=612
#else
max-lines=612
max-columns=792
#endif
end-declare
To position the beginning of an element 1 inch down and 1 inch to the right, we would now
code (+72, +72) . Text will print normally, even though the grid is now very small.
However, there is one complication. To print on the next line, we cannot code (+1, 1) ,
because that would be only 1 point lower and the text would overlap the previous line.
To handle this, create a variable called #Line and set it to the point size of the font plus
the number of extra points between lines (the "leading"). For example, if you are using a 10-point
font, you might want to set #Line to 12. Then, to print on the next line, code
(+#Line, 1) in your PRINT statement.
Using this technique and some of the other printing features of SQR, you can produce forms,
statements and letters that look like they have been printed from Word.
|