Adding Graphics

The following sample program includes graphical features, a logo, solid lines, and a change of font, in the heading:

Program ex12b.sqr
begin-setup
 declare-layout default
 end-declare
end-setup
begin-program
 do main
end-program
begin-procedure main
begin-select
name  (,1,30)
city  (,+1,16)
state (,+1,5)
tot   (,+1,11) edit 99999999.99
  next-listing no-advance need=1
  let #grand_total = #grand_total + &tot
from customers
end-select
graphic (,55,12) horz-line 20
print 'Grand Total' (+2,40)
print #grand_total (,55,11) Edit 99999999.99
end-procedure ! main
begin-heading 11
 print $current-date (1,1) 
 page-number (1,60) 'Page ' 
 alter-printer point-size=14 font=4 ! switch font
 print 'Name'   (9,1) bold
 print 'City'   (,32) bold
 print 'State'  (,49) bold
 print 'Total'  (,61) bold
 alter-printer point-size=12 font=3 ! restore font
 graphic (9,1,66) horz-line 20
 print-image (1,23)
   type=bmp-file
   image-size=(21,5)
   source='acmelogo.bmp'
end-heading

The GRAPHIC command draws solid lines with the HORZ-LINE argument. The line is positioned by using a normal SQR position specifier. Note that the third number in the position specifier is the length of the line, which is given in characters. (The actual width of a character cell is determined by the CHAR-WIDTH or MAX-COLUMNS arguments of DECLARE-LAYOUT.)

The HORZ-LINE argument of the GRAPHIC HORZ-LINE command is the thickness of the line, specified in decipoints (one inch has 720 decipoints). For example, the graphic (10,1,66) horz-line 20 command specifies a horizontal line following line 10 in the report, starting with position 1 (the left side of the report) and stretching for 66 character positions (at 10 characters per inch, this is 6.6 inches). The thickness of the line is 20 decipoints, which is 1/36 of an inch or about 0.7 mm.

You can also use the GRAPHIC command to draw vertical lines, boxes, and shaded boxes. See the sqrlaser.sqr program in the SAMPLE (or SAMPLEW) subdirectory for an example.

The ALTER-PRINTER command in ex12b.sqr changes the font of the heading. When used a second time, it restores the normal font for the rest of the report. The FONT option selects a font (typeface) that is supported by the printer. The font is specified by number, but the number is printer-specific. On a PostScript printer, for example, font 3 is Courier, font 4 is Helvetica, and font 5 is Times Roman.

The POINT-SIZE option specifies type size in points. You can use a whole number or a fraction (for example, POINT-SIZE=10.5). The following command changes the font to 14-point Helvetica:

alter-printer point-size=14 font=4 ! switch font

The PRINT-IMAGE command inserts a logo. PRINT-IMAGE is followed by a print position corresponding to the upper-left corner of the image (line 1, column 19 in the sample program). The TYPE option specifies the image file type. In the example, the image is stored in Microsoft Windows bitmap format (bmp file). The size of the image is specified in terms of columns (width) and lines (height). In the example, the image is 30 characters wide (3 inches) and 7 lines high (1-1/6 inches).

In SQR, images are always stored in external files. The format of the image must match that of the printer that you are using. These formats are:

  • Microsoft Windows: bmp file images.

  • PostScript printer or view: eps file.

  • HP LaserJet: hpgl file images.

  • HTML output: GIF or JPEG formats (gif file or jpeg file).

The SOURCE option specifies the file name of the image file. In the example, the file is Acmelogo.bmp. The file is assumed to reside in the current directory or in the directory in which SQR is installed (you can place the logo file in either of these places). The file can reside in any directory, however, as long as you specify a full path name for the image file.

The output file now contains graphic language commands. SQR can produce output that is suitable for HP LaserJet printers in a file format that uses the HP PCL language or output that is suitable for PostScript printers in a file format that uses the PostScript language. SQR can also produce printer-independent output files in a special format called SQR Portable Format (SPF).

SQR can create a printer-specific output file (an .lis file) or create the output in portable format (SPF). When you create an .spf file, the name of the image file is copied into it, and the image is processed at print time, when printer-specific output is generated. When you use .spf files, a change in the contents of the image file is reflected in the report the next time you print it or view it. You can create printer-specific output by using SQR or SQR Execute to directly generate an .lis file or by using SQR Print to generate an .lis file from an .spf file.

See Understanding the Sample Program for Listing and Printing Data.