THE TECHNIQUE OF BANDING

Banding is the technique of defining a page of graphics as a series of separately constructed rectangles called bands. This approach relieves a printer driver of the necessity of constructing an entire bitmapped page image in memory. Banding is most important for raster printers that have no high-level page-composition control, such as dot-matrix printers and some laser printers.

Banding is one of the most misunderstood aspects of programming for the printer in Windows. Part of the problem lies in the documentation for the GetDeviceCaps function. The RC_BANDING bit of the value returned from GetDeviceCaps with the RASTERCAPS index is documented as ”requires banding support.“ Programmers looking at this documentation assume that their applications must use banding with such printers. But this isn't so. Most of the information available from GetDeviceCaps is intended solely for the GDI module. This information allows GDI to determine what the device can do by itself and what it needs help with. The banding requirement falls into this category.

In general, an application program doesn't need to include its own banding logic. As you've seen, when you make GDI calls that define a page of graphics, the GDI module stores these calls in a metafile and then uses banding to set a clipping region before playing this metafile into the printer device driver. This is transparent to the application program. Under certain conditions, however, an application might want to take over the responsibility for doing banding. When an application uses banding, the GDI module doesn't create the intermediary metafile. Instead, the drawing commands for each band are passed to the printer device driver. There are two advantages to this approach:

It can increase printing speed. The application needs to call only those GDI functions that draw something in each particular band, which is faster than having the GDI module play the entire metafile into the device driver for each band. Even if the program simply draws the entire page for each band, the process can still be faster than having the GDI module create and read the disk-based metafile, because the program doesn't have to access a disk.

It can reduce the disk space normally required for printing. If the application is printing bitmaps but is not doing its own banding, then these bitmaps must be stored in the metafile that GDI creates. This situation can result in a metafile as large as the printer output file that the GDI module eventually creates.

Banding is particularly important for printing bitmaps, because they occupy a large amount of space in the metafile. (Printing a bitmap requires selecting the bitmap into a memory device context and using BitBlt or StretchBlt to write it to the printer device context.)

But banding also further complicates the printing process, as you'll see when we create PRINT4, the final version of our printing program.