Free-Format Printing

JADE enables you to place output directly on a printer page at any location on the page without the use of frames and to draw rotated text and characters.

Although the getPrintPosition and setPrintPosition methods enable you to control the line position for your print output, printing graphics and multiple panes across the page when using print frames is not straightforward. (For details about using frames to define your report layouts, see "Defining Your JADE Report Layouts", earlier in this chapter.)

You can use the free-format print facilities to dynamically construct a page of output, treating the output page as whole canvas, or you can supplement the use of frames with these facilities.

Support for free-format printing:

The Printer class graphics properties and methods, similar to those defined in the Window class, allow dynamic text and graphics to be output to a window.

The Printer class properties that you can use for free-format printing are summarized in the following table.

Property Description
drawFillColor Contains the color used to fill in shapes drawn with the printer graphics methods
drawFillStyle Contains the pattern used to fill the shapes drawn using the printer graphics methods
drawFontBold Used when constructing the font used for drawing text
drawFontItalic Used when constructing the font used for drawing text.
drawFontName Used when constructing the font used for drawing text
drawFontSize Used when constructing the font used for drawing text
drawFontStrikethru Used when constructing the font used for drawing text
drawFontUnderline Used when constructing the font used for drawing text
drawStyle Defines the line style for output from printer graphics methods
drawTextAlign Contains the alignment used when outputting text on the printer using the drawTextAt and drawTextIn methods
drawTextCharRotation Specifies the angle in degrees between each characters base line and the x axis of the device
drawTextRotation Specifies the angle in degrees between the base line of the text output and the x axis of the page
drawWidth Contains the line width for output from printer graphics methods

The Printer class methods that you can use for free-format printing are summarized in the following table.

Method Description
drawArc Draws an elliptical arc on the printer page
drawChord Draws a chord on the printer page (that is, an arc with the end points joined and the interior filled)
drawEllipse Draws an ellipse on the printed page
drawFilledRectangle Draws a filled rectangle on the printed page
drawLine Draws a line on the printed page
drawPie Draws a pie-shaped wedge on the printed page
drawRectangle Draws the border of a rectangle on the printed page
drawRoundRectangle Draws a rectangle with rounded corners on the printed page
drawSolidRectangle Draws a rectangle filled with the same color as the border on the printed page
drawTextAt Draws a text string on the printer page
drawTextIn Draws a text string with a bounded rectangle on the printer page
drawTextSize Returns the size of the text on the print page, using the current drawFont property values
drawTextSizeIn Returns the size of the text in a bounding rectangle on the print page, using the current drawFont property values

The method shown in the following example prints a calendar page for a specified month, by placing output directly on to a printer page at a specified location on the page.

printCalendarMonth(printer: Printer input; prettyPicture: Frame input;
                   month: Integer; year: Integer) updating;
vars
    x, y, xinc, yinc           : Integer;
    xstart, ystart, day, width : Integer;
    date                       : Date;
begin
    width := printer.pageWidth;
    // print pretty picture
    prettyPicture.left   := (width - prettyPicture.width)/2 + 30;
    printer.setPrintPosition(40);
    printer.drawFontName := "Arial";      // now print the month name
    printer.drawFontSize := 30;
    printer.drawTextAlign := printer.DrawTextAlign_Center;
    ystart := printer.getPrintPosition() + 10;
    date.setDate(1, month, year);
    printer.drawTextAt(date.monthName, (width/2).Integer, ystart, Black);
    // set next position after the month text
    x := printer.drawTextSize(date.monthName, y);
    ystart := ystart + y + 30;
    yinc   := ((printer.pageHeight - ystart - 50)/5).Integer;
    xinc   := ((width - 60)/ 7).Integer;
    xstart := ((width - xinc * 7)/2).Integer + 30;
    printer.drawFontSize := 12;
    date.setDate(7, 11, 1999);            // Sunday
    // draw squares
    foreach x in xstart to xstart + xinc*7 step xinc do
        printer.drawLine(x, ystart - 20, x, ystart + yinc*5, Black);
        if x < xstart + xinc * 7 then
            printer.drawTextAt(date.dayName, (x + xinc/2).Integer,
                               ystart - 20, Black);
            date := date + 1;
        endif;
    endforeach;
    foreach y in ystart to ystart + yinc*7 step yinc do
        printer.drawLine(xstart, y, xstart + xinc*7, y, Black);
    endforeach;
    date.setDate(1, month, year);         // print day numbers
    day := date.dayOfWeek mod 7;          // day number
    printer.drawTextAlign := Printer.DrawTextAlign_Left;
    printer.drawFontSize := 14;
    y := ystart;
    while month = date.month do
        printer.drawTextAt(date.day.String, xstart + day *
                           xinc + 6, y + 4, Black);
        date := date + 1;
        day := day + 1;
        if day = 7 then
            day := 0;
            y := y + yinc;
            if y >= ystart + yinc*5 then
                y := ystart;
            endif;
        endif;
    endwhile;
    printer.newPage;
    app.printer.close;
end;