Printing a Virtual Buffer

Fastgraph includes three functions, fg_printdc(), fg_printer(), and fg_vbprint(), that work together for printing rectangular regions from the active virtual buffer on the selected Windows printer.

The fg_printdc() function establishes the printer device context, which directs subsequent printing to the associated printer. Its only parameter is a handle to the printer device context; this is often obtained through the Print common dialog box. If you do not call fg_printdc(), or if you pass it a zero device context, printing will be directed to the default Windows printer.

The fg_printer() function provides necessary print job control. It accepts a single integer parameter whose value is one of the identifiers or numeric values shown here:

ABORTDOC (2)

Aborts the current print job

ENDDOC (11)

Ends a print job

NEWFRAME (1)

Issues a page eject

STARTDOC (10)

Starts a print job

For STARTDOC requests, the fg_printer() return value will be one of the following:

0

Success

-1

Default printer not defined

-2

Printer is off-line or otherwise unavailable

-3

Printer does not support the STRETCHDIB function

-4

Error creating the printer device context

For ABORTDOC, ENDDOC, and NEWFRAME requests, the fg_printer() return value will be zero. C++Builder and Delphi programs that select a printer through the Print dialog box should use the TPrinter methods Abort(), BeginDoc(), EndDoc(), and NewPage() in place of the functionality provided by fg_printer().

The fg_vbprint() function prints a rectangular region from the active virtual buffer on the selected printer, scaling the printed image as requested. Its parameters are similar to those of fg_vbscale(), but fg_vbprint() takes one additional parameter that specifies the units of the destination (printer) coordinates. Acceptable values for the units parameter are:

0

device units (no translation)

1

percentage

2

0.01 inches

3

0.001 inches

4

millimeters

5

0.1 millimeters

6

0.01 millimeters

A typical one-page print sequence looks something like this:

C/C++:

fg_printer(STARTDOC);
fg_vbprint(...);
fg_printer(NEWFRAME);
fg_printer(ENDDOC);

Delphi:

fg_printer(10);  { STARTDOC }
fg_vbprint(...);
fg_printer(1);   { NEWFRAME }
fg_printer(11);  { ENDDOC }

Visual Basic:

Call fg_printer(10)  ' STARTDOC
Call fg_vbprint(...)
Call fg_printer(1)   ' NEWFRAME
Call fg_printer(11)  ' ENDDOC

We'll now present some sample fg_vbprint() calls that print the entire contents of a 640x480 virtual buffer. Our first example creates a 64x48-millimeter printed image in the upper left corner of the page:

C/C++ and Delphi:

fg_vbprint(0,639,0,479,0,64,0,48,4);

Visual Basic:

Call fg_vbprint(0, 639, 0, 479, 0, 64, 0, 48, 4)

If we wanted to print the same image 30 millimeters from the left edge of the page and 20 millimeters from the top edge, we would add these offsets to the destination coordinates:

C/C++ and Delphi:

fg_vbprint(0,639,0,479,30,94,20,68,4);

Visual Basic:

Call fg_vbprint(0, 639, 0, 479, 30, 94, 20, 68, 4)

If we instead wanted to express the printer coordinates in inches, here is how to print a 5x3-inch printed image in the upper left corner of the page:

C/C++ and Delphi:

fg_vbprint(0,639,0,479,0,500,0,300,2);

Visual Basic:

Call fg_vbprint(0, 639, 0, 479, 0, 500, 0, 300, 2)

It's often useful to express printer coordinates as percentages of the available printing area. This call would scale the image to print the entire printing area:

C/C++ and Delphi:

fg_vbprint(0,639,0,479,0,100,0,100,1);

Visual Basic:

Call fg_vbprint(0, 639, 0, 479, 0, 100, 0, 100, 1)

Finally, here's how we would print an image one-half the size of the printing area, centered in the middle of the page:

C/C++ and Delphi:

fg_vbprint(0,639,0,479,25,75,25,75,1);

Visual Basic:

Call fg_vbprint(0, 639, 0, 479, 25, 75, 25, 75, 1)

<< Prev

Next >>

Contents
Fastgraph Home Page

 

copyright 2001 Ted Gruber Software, Inc.