Color in SQR Reports | KEVIN RESCHENBERG 08-11-2014 |
Today we wrap up this series of posts on SQR report formatting. So far we have looked at these topics:
The only color we have seen comes from images. But you can also choose foreground and background colors for text.
You can specify the colors right on the PRINT statement, or you can set the color for all following text:
alter-printer font=4 point-size=16
print 'red' (1, 1) foreground=('red')
print ' reversed ' (1, 40) foreground=('white') background=('red')
print ' highlighted ' (1, 130) foreground=('red') background=('yellow')
set-color print-text-foreground=('teal') ! Or background=()
print 'First line in new color' (30, 1)
print 'Second line' (+16, 1)
This example uses some of the predefined colors. Refer to the manual for a full list, but most of the normal colors you'd expect
are available.
If you need different colors, you can create them. The syntax is a little strange but it's workable. First you need to
declare a set of colors. Then you can just use them, or redefine them on the fly. But they need to be declared first.
The new colors are defined in RGB (red/green/blue) format:
begin-setup
declare-color-map
my_heading_color = (120, 120, 0)
my_text_color = (25, 100, 150)
end-declare
declare-layout DEFAULT
line-height=1
char-width=1
end-declare
end-setup
begin-program
alter-printer font=4 point-size=16
print 'Heading Text' (1, 1) foreground=('my_heading_color')
alter-printer point-size=12
set-color print-text-foreground=('my_text_color')
print 'Body text ' (+20, 1)
alter-color-map name = 'my_text_color' value = (180, 180, 180)
set-color print-text-foreground=('my_text_color') ! This is needed
print 'And now the body text' (+13, 1)
print 'switches to this color' (+13, 1)
end-program
Although the color map entry name used for text (my_text_color) is not changing, its definition is,
and we need to do the SET-COLOR statement again.
Box background colors
We have previously drawn shaded boxes. A box can be shaded with any percentage from 0 (white/transparent) to 100 (black).
But what if we want a box with a background in another color?
Here are a couple of ways to do it.
First create a one-pixel .JPG file containing a single dot in the desired color.
For this example I'll use a light blue. Then print the image, scaling it up to the required dimensions. To add to the example, let's put a black border
around this box and then have an inner box in white (actually a 1% shading, which will be indistinguishable from white when it is printed). As in all of these
examples, we are using a one-point coordinate grid. The position of the text was determined through pure trial and error.
print-image (1, 1) type=jpeg-file source='x:\blue-dot.jpg'
image-size=(200, 100)
graphic (1, 1, 200) box 100 6 0
graphic (25, 25, 150) box 50 0 1
alter-printer font=4 point-size=18
print 'Hello World' (56, 49) bold foreground=('navy')
Or try this trick, which doesn't involve images.
Set a large font size and then print blank spaces using a background color:
alter-printer font=4 point-size=50
print ' '
(1, 1) background=('green')
alter-printer point-size=100
print ' '
(60, 50) background=('blue')
alter-printer point-size=15
print ' '
(40, 30) background=('red')
(This picture is 50% of full size.) You can control the height of the block exactly but the
width will be only approximate, since you can't print a fraction of a space. If that's not quite good enough, you could print a slightly larger box
and then erase part of it by overprinting with a white-background box. Or print two blocks of the same color, with the second one slightly overlapping
the first. By controlling the starting position of the second box (using our one-point grid) you can control the exact length of the
combined box.
Notice that the green block in this example bleeds off of the top of the page. Recall that the position of text specifies the left edge of the baseline
of the text. Therefore, since the font used in this case is very tall (50 points), the spaces extend up and run right off the page.
Beyond the various topics covered in these posts, SQR will also draw charts. Take a look at the
manual for that and other formatting options.
|