SQR Print Positioning with A One-Point Grid | KEVIN RESCHENBERG 08-09-2014 |
Recall that SQR positions characters on the page using a coordinate grid that corresponds to the default character size in a fixed-pitch font.
In the post on SQR proportional font positioning we saw that this doesn't work in many cases—it doesn't
give us enough control over positioning of elements. The way around this is to redefine the grid, making each "cell" very small:
begin-setup
declare-layout DEFAULT
line-height=1
char-width=1
end-declare
end-setup
begin-program
alter-printer font=4
print 'First line' (1, 1)
print 'Second line' (+1, 1) ! WRONG
print 'Third line' (25, 1)
print 'Fourth line' (+13, 1)
end-program
This sets up the coordinate system so that each position is just one point (1/72 inch) by one point. The result:
Normally we advance to the next line by using (+1) as shown for "Second line". But we have now redefined the grid, so one "line" (row)
is very short. Instead of around 60 print lines on the page, we now have over 700 (at one point per line). Therefore, to advance to the next line
on the page, we need to jump a lot more—around 12 points or so. I chose 13 for the line spacing in this example, as shown for "Fourth line".
Note that you can even specify fractional point sizes here, so instead of a 1-point line height you could specify .1 point. In that case
you would have over 7,000 lines on the page. This is more precision then I've ever needed, but there it is.
DECLARE-LAYOUT provides flexibility through many different parameters. A lot of them specify the same dimensions in different
ways. For example, you can specify top and/or bottom margins or the page height or the maximum number of lines or the line height... These parameters all
conflict with each other and there is some sort of hierarchy that determines which settings override other settings.
Just specify as few as necessary to get the desired result. The intricacies of DECLARE-PRINTER, DECLARE-REPORT and DECLARE-LAYOUT are
way out of scope for this discussion. So I'm just showing the minimum, using the default layout.
Another quick aside: We will be hard-coding a lot of numbers and that can make the program very difficult to maintain. To avoid this, #DEFINE the
various values at the top of the program. Then you can make most changes in just one place:
#define LINE 13
...
print 'First line' (1, 1)
print 'Next line' (+{LINE}, 1)
print 'Another line' (+{LINE}, 1)
Now that we have better control over positioning text, we can proceed to lines, boxes and images.
|