- - * - WhiteUnicorn - * - -




* #WhiteUnicorn/ StartPage/ Documentation/DelphiFAQ >


Frequently Asked Questions

Detecting what direction a printer will rotate for a portrait

Question:

Some printers seems to rotate the portrait orientation to achieve a landscape page differently than others. This seems to affect the direction of a rotated font. How can I tell what direction a printer will rotate output on a landscape page, and if landscape mode is available on a given printer?

Answer:

The following example demonstrates how to call the Windows API

function DeviceCapabilities(), to find out how a portrait page is

rotated to achieve a landscape page, enabling you to adjust your

output accordingly. Generally, a print driver will rotate a

landscape page either 90 degrees, or 270 degrees from its portrait

orientation.



Example:



uses Printers;



{$IFDEF WIN32}

function DeviceCapabilitiesA(pDevice : PAnsiChar;

                             pPort : PAnsiChar;

                             fwCapability : Word;

                             pOutput : PAnsiChar;

                             DevMode : PDeviceModeA): Integer stdcall;

  external 'winspool.drv' name 'DeviceCapabilitiesA';



function DeviceCapabilitiesW(pDevice : PWideChar;

                             pPort : PWideChar;

                             fwCapability: Word;

                             pOutput: PWideChar;

                             DevMode: PDeviceModeW): Integer stdcall;

  external 'winspool.drv' name 'DeviceCapabilitiesW';



function DeviceCapabilities(pDevice : PChar;

                            pPort : PChar;

                            fwCapability : Word;

                            pOutput : PChar;

                            DevMode: PDeviceMode): Integer stdcall

  external 'winspool.drv' name 'DeviceCapabilitiesA';

{$ENDIF}



procedure TForm1.Button1Click(Sender: TObject);

var

  Device : array[0..255] of char;

  Driver : array[0..255] of char;

  Port   : array[0..255] of char;

  hDMode : THandle;

  Rotation : integer;

begin

  if PrintDialog1.Execute then begin

   {Reset the printer}

    Printer.PrinterIndex := Printer.PrinterIndex;

    Printer.GetPrinter(Device, Driver, Port, hDMode);

    Rotation :=

      DeviceCapabilities(Device,

                         Port,

                         DC_ORIENTATION,

                         nil,

                         nil);

    case Rotation of

     0 :  ShowMessage('This device does not ' +

                      'support landscape');

     90 :  ShowMessage('This device rotates the portrait ' +

                      'orientation 90 degrees ' +

                      'to support landscape');

     270 :  ShowMessage('This device rotates the portrait ' +

                        'orientation 270 degrees ' +

                        'to support landscape');

    end;

  end;

end;




* #WhiteUnicorn/ StartPage/ Documentation/DelphiFAQ >



- - * - Anastasija aka WhiteUnicorn - * - - LJLiveJournal
PFPhotoFile