Einzelnen Beitrag anzeigen

JoelH
(Gast)

n/a Beiträge
 
#6
  Alt 2. Jun 2003, 10:30
Ich hab mir jetzt mal eine kleine Testunit gebaut und es differiert wirklich um einige Prozent. Je nach Schriftgrösse und Art um ca. 17%.

Hier die Testdatei
Delphi-Quellcode:
unit paintprint;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, printers,
  ExtCtrls, StdCtrls;

type
  TForm1 = class(TForm)
    paintbox: TPaintBox;
    Button1: TButton;
    Button2: TButton;
    fnt: TFontDialog;
    edt: TEdit;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
    procedure MyDruck;
    procedure MyPaint;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  na : string;
  diffv, diffh : integer;

implementation

{$R *.DFM}

procedure TForm1.MyDruck;

var
    outdc : HDC; { PrinterCanvasHandle }
    bx,by,texter,textheight : integer;
    fontsize, fontheight : integer;
    hres,vres,hsiz,vsiz : integer; { Canvasdimensionen }
    help : string;
    helperh,helperv : single;
    fonthoehe : integer;
begin
  Printer.Orientation := poPortrait;
  Printer.BeginDoc;
  outdc := Printer.Canvas.handle;
  hres := GetDeviceCaps(outdc,HORZRES); {display width in pixels}
  vres := GetDeviceCaps(outdc,VERTRES); {display height in pixels}
  hsiz := GetDeviceCaps(outdc,HORZSIZE); {display width in mm}
  vsiz := GetDeviceCaps(outdc,VERTSIZE); {display height in mm}
  Printer.canvas.font.name := na;
  fontsize := StrToInt(edt.text);
  Printer.canvas.font.size := fontsize;
  fontheight := Printer.Canvas.Font.Height;
  fonthoehe := round((((-1)*fontheight)/hres)*hsiz);
  bx := 10;
  by := 10;
  texter := Printer.Canvas.TextWidth('TEXTTEST');
  textheight := Printer.Canvas.TextHeight('TEXTTEST');
  texter := round((texter/hres)*hsiz);
  textheight := round((textheight/vres)*vsiz);
  helperh := texter/diffh;
  helperv := textheight/diffv;
  help := 'TextWidth : '+InttoStr(texter)+' mm ## Textheight : '+InttoStr(textheight)+' mm'+
          #13+#10+'HDiff : '+FloatToStr(helperh)+' ## VDiff : '+FloatToStr(helperv)+
          #13+#10+'Fontheight '+InttoStr(fonthoehe)+' mm';
  showmessage(help);
  Printer.canvas.TextOut(bx,by,'TEXTTEST');
  Printer.EndDoc;
end;

procedure TForm1.MyPaint;

var
    outdc : HDC; { CanvasHandle }
    bx,by,texter,textheight : integer;
    fontsize, fontheight : integer;
    hres,vres,hsiz,vsiz : integer; { Canvasdimensionen }
    help : string;
    fonthoehe : integer;
begin
  outdc := paintbox.Canvas.handle;
  hres := GetDeviceCaps(outdc,HORZRES); {display width in pixels}
  vres := GetDeviceCaps(outdc,VERTRES); {display height in pixels}
  hsiz := GetDeviceCaps(outdc,HORZSIZE); {display width in mm}
  vsiz := GetDeviceCaps(outdc,VERTSIZE); {display height in mm}
  Paintbox.canvas.font.name := na;
  fontsize := StrToInt(edt.text);
  Paintbox.canvas.font.size := fontsize;
  fontheight := Paintbox.Canvas.Font.Height;
  fonthoehe := round((((-1)*fontheight)/hres)*hsiz);
  bx := 10;
  by := 10;
  texter := Paintbox.Canvas.TextWidth('TEXTTEST');
  textheight := Paintbox.Canvas.TextHeight('TEXTTEST');
  texter := round((texter/hres)*hsiz);
  textheight := round((textheight/vres)*vsiz);
  help := 'TextWidth : '+InttoStr(texter)+' mm ## Textheight : '+InttoStr(textheight)+' mm'+
          #13+#10+'Fontheight '+InttoStr(fonthoehe)+' mm';;
  showmessage(help);
  Paintbox.canvas.TextOut(bx,by,'TEXTTEST');
  diffh := texter;
  diffv := textheight;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
 MyPaint;
 MyDruck;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  fnt.Execute;
  na := fnt.Font.Name;
  showmessage(na);
end;

end.
Ist einfach eine Form mit 2 Buttons, einem Fontdialog(fnt), einer Paintbox(Paintbox) und einem Editfeld(edt) zum eingeben der FontSize.
  Mit Zitat antworten Zitat