unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,Printers,Math, StdCtrls;
type
TForm1 =
class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
Type
TPageInfo =
record
width, height: Integer;
{ physical width and height, in dots }
offsetX, offsetY: Integer;
{ nonprintable margin, in dots }
resX, resY: Integer;
{ logical resolution, dots per inch }
End;
Procedure GetPageinfo(
Var info: TPageInfo;
index: Integer = -1 );
Begin
If index > -1
Then
Printer.PrinterIndex :=
index;
With Printer
Do Begin
info.resX := GetDeviceCaps(
handle, LOGPIXELSX );
info.resY := GetDeviceCaps(
handle, LOGPIXELSY );
info.offsetX := GetDeviceCaps(
handle, PHYSICALOFFSETX );
info.offsetY := GetDeviceCaps(
handle, PHYSICALOFFSETY );
info.width := GetDeviceCaps(
handle, PHYSICALWIDTH );
info.height := GetDeviceCaps(
handle, PHYSICALHEIGHT );
End;
{ With }
End;
Procedure SetCanvasZoomAndRotation(ACanvas:TCanvas;Zoom:Double;Angle:Double;CenterpointX,CenterpointY:Double);
var
form : tagXFORM;
Winkel:Double;
begin
Winkel := DegtoRad(Angle);
SetGraphicsMode(ACanvas.Handle, GM_ADVANCED);
SetMapMode(ACanvas.Handle,MM_ANISOTROPIC);
form.eM11 := Zoom * cos( Winkel);
form.eM12 := Zoom *Sin( Winkel) ;
form.eM21 := Zoom * (-sin( Winkel));
form.eM22 := Zoom * cos( Winkel) ;
form.eDx := CenterpointX;
form.eDy := CenterpointY;
SetWorldTransform(ACanvas.Handle,form);
end;
Procedure ResetCanvas(ACanvas:TCanvas);
begin
SetCanvasZoomAndRotation(ACanvas , 1, 0, 0,0);
end;
procedure TForm1.Button1Click(Sender: TObject);
var
info: TPageInfo;
begin
GetPageinfo(info);
Printer.BeginDoc;
SetCanvasZoomAndRotation(Printer.Canvas, info.height / 297,0,0,0);
Printer.Canvas.Rectangle(10,10,30,20);
Printer.Canvas.Font.Height := 10;
Printer.Canvas.TextOut(10,10,'
Test');
Printer.EndDoc;
end;
end.