Einzelnen Beitrag anzeigen

Benutzerbild von Bummi
Bummi

Registriert seit: 15. Jun 2010
Ort: Augsburg Bayern Süddeutschland
3.470 Beiträge
 
Delphi XE3 Enterprise
 
#10

AW: Drucker liefert unterschiedliche Fontgrößen

  Alt 4. Nov 2011, 13:56
Da ich immer gerne au Dinge zurückgreife die ich schon länger nutze, vielleicht lässt sich hieraus was machen.

Die Idee ist direkt mit Millimetern zu arbeiten ....

den GetPageinfo-Teil habe ich von hathor übernommen ....

Delphi-Quellcode:
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.
Thomas Wassermann H₂♂
Das Problem steckt meistens zwischen den Ohren
DRY DRY KISS
H₂ (wenn bei meinen Snipplets nichts anderes angegeben ist Lizenz: WTFPL)
  Mit Zitat antworten Zitat