SQR Proportional Font Positioning | KEVIN RESCHENBERG 08-08-2014 |
In the last post, on SQR print positioning and the report grid, we ended with this example:
That is the result of printing "First", "Second" and "Third" in sequence using the current position each time:
print 'First' (1,1)
print 'Second' ()
print 'Third' ()
alter-printer font=4
print 'First' (3,1)
print 'Second' ()
print 'Third' ()
alter-printer point-size=20
print 'First' (5,1)
print 'Second' ()
print 'Third' ()
First let's take a look at the ALTER-PRINTER statement. It can take several types of parameters (see the manual), but
for our purposes right now we need just the FONT and POINT-SIZE parameters. There are 72 points in an inch. This
makes point-based measurements less precise than, say, pixels—but points will give us much more control than just full
character widths, as we'll see later.
The font is specified as a number. Find these numbers in your .INI file. (Look for a file named
SQR.INI or, if you are a PeopleSoft user, it might be called PSSQR.INI. It's also specified in the Runtime section on the configuration panel
in the SQR debugger.) I'm looking at this file now and see two sections: [Fonts] and [PDF Fonts],
with slightly different font names for certain numbers. The PDF Fonts are probably the exact ones you see in the output. In general, you
would most likely use one of these:
- 3 = Courier [New], a fixed-pitch font
- 4 = Helvetica, a proportional sans-serif font very similar to Arial
- 5 = Times [New] Roman, a proportional serif font
In my opinion, Times Roman is rather ugly at smaller sizes and I avoid it.
There are other fonts such as MS UI Gothic. Then
there are the bold and oblique (italic) fonts. We normally don't need to specify a bold font because we can just use the BOLD specifier
when printing. But for italic we do need to switch the font.
With that out of the way, let's look back at the positioning problem. Fixed-pitch fonts are the ones where every character takes
the same space. In proportional fonts characters take different amounts of space. Proportional fonts are generally easier to read
and look better.
If, as in the first example above, we want to print "First", "Second" and "Third" together in sequence in a proportional font, we
need to stop relying on SQR's default position and just do this:
print 'FirstSecondThird' ()
What if we are trying to print three values stored in variables? This situation comes up when we want
to print first and last name, or city, state and zip code. Just do the same thing using concatenation:
! The WRONG way:
print $FirstName (1, 1)
print ' ' ()
print $LastName ()
! The RIGHT way:
let $x = $FirstName || ' ' || $LastName
print $x (1, 1)
Note that this is the way to do it if the parts of the string are supposed to flow together naturally as a single string.
If instead you want the parts to be
in separate columns on the report then print them separately, giving a column number for each.
The next positioning problem will be illustrated in two ways. First, look carefully at the image above comparing fixed and proportional
fonts. The line spacing on the proportional font is very tight. It would be nice if we could advance just a little more for each
line, but the only possibility after (+1) is (+2) and that would be too much space. (Fractional lines are not allowed.)
Positioning within a line is a similar problem. Suppose we wanted to print "The quick brown fox jumps over the lazy dog." Each PRINT statement
can print either normal or bold text, not both. So we would have to do something like this:
alter-printer font=4 ! Helvetica
print 'The jumps over the lazy dog.' (1, 1)
print ' quick brown fox' (1, 1) bold
It works, but...UGH! And it works only if you know the exact text in advance (no variable data) and do a lot of trial and error. It's best to avoid
having different fonts or font styles (bold/italic) combined within a single text string (phrase or sentence).
However, a number of these positioning challenges can be solved using a one-point coordinate system, up next.
|