SAMPLE: HPClip.exe Uses Scaling Factor to Set Clipping Region

ID: Q63939

The information in this article applies to:

SUMMARY

HPClip.exe is a sample that demonstrates how to use a scaling factor to set a clipping region on a printer device that supports a lower graphics resolution than text resolution.

MORE INFORMATION

The following file is available for download from the Microsoft Software Library:

 ~ HPClip.exe (size: 18915 bytes) 

For more information about downloading files from the Microsoft Software Library, please see the following article in the Microsoft Knowledge Base:

   ARTICLE-ID: Q119591
   TITLE     : How to Obtain Microsoft Support Files from Online Services

In the Microsoft Windows graphical environment, printer drivers that can create graphics in finer resolutions than text support the GETSCALINGFACTOR printer escape. For example, the HP LaserJet printer with the HPPCL driver can create graphics at 300, 150, and 75 dots per inch (dpi). Because text on this printer is always printed in 300 dpi, the printer driver responds to this printer escape to inform the caller of the scaling factors from the text resolution to the current graphics resolution, for both the X and Y axes. If the user sets the graphics resolution of an HPPCL printer to 150 dpi through the Control Panel, the driver returns the values (1, 1) for this escape (exponent of 2). If the graphics resolution is 75 dpi, the scaling factors are (2, 2). The same logic holds for 300 dpi; the scaling factors are (0, 0). The X and Y factors are always the same on HPPCL because this printer always has the same resolutions on the X and Y axes. On another printer device, the two factors may differ from each other.

The scaling factors are typically used to set clipping regions on this type of printer device. Because the graphics device interface (GDI) sets a clipping region only at the text resolution, it is the application's responsibility to adjust the region's coordinates before passing them to the call that creates the region. For example, suppose an application creates a rectangular clipping region on an HPPCL printer. The coordinates (X1, Y1) specify the upper-left corner and (X2, Y2) the lower-right corner, all in device units. Before passing these parameters to the CreateRectRgn() function, the application must send the GETSCALINGFACTOR printer escape to obtain the current scaling factors. If the current graphics resolution is 150 dpi, the scaling factors should be (1, 1). The application would adjust the coordinates to (X1 >> 1, Y1 >> 1) and (X2 >> 1, Y2 >> 1), which is equivalent to dividing each by 2. After Windows creates the region, calling the SelectClipRgn() function selects the region into the device context as the clipping region.

REFERENCES

The GETSCALINGFACTOR printer escape is documented in Chapter 5 of the Microsoft Windows Software Development Kit (SDK) "Programmer's Reference, Volume 3: Messages, Structures, and Macros" manual for version 3.1, and in Chapter 11 of the Microsoft Windows Device Driver Kit (DDK) "Device Driver Adaptation Guide."

Additional query words: DDKPRINT Keywords : GdiPrnMisc

Last Reviewed: July 8, 1998