Einzelnen Beitrag anzeigen

Benutzerbild von semo
semo

Registriert seit: 24. Apr 2004
755 Beiträge
 
Delphi 2010 Professional
 
#7

Re: Druck in Millimetern / TextHeight?

  Alt 15. Nov 2004, 21:27
so, habs jetzt gefunden und um allen Interessierten den Code zur Verfügung zu stellen poste ich diesen mal gleich mit:

Code:
procedure TMainForm.DruckenClick(Sender: TObject);

  // Pixel to Millimeter
  function PixelToMM(value: Double; dpi: Integer): Double;
  begin
    Result := (value * 25.4) / dpi; // 1 Inch = 25,4 mm
  end;


var
  myRect: TRect;
  w,v: TSize;
  printCanvHandle: HDC;
  tempSchild: TSchild;
  i, a: Integer;
  tempZeile: TZeile;
  Font1: TFont;
  logoHoehe, logoBreite: Integer;
  zoomFaktor, xPos, yPos: Double;
  iAbstandGravurrand,
  gravurrandDicke: Integer;
  GravurrandOuter, GravurrandInner: TRect;
begin
  PageSetupDialog1.MarginLeft  := 0;
  PageSetupDialog1.MarginTop   := 0;
  PageSetupDialog1.MarginRight := 0;
  PageSetupDialog1.MarginBottom := 0;

  if PageSetupDialog1.Execute then
  begin

    printer.BeginDoc;
    printCanvHandle := Printer.Canvas.Handle;

    SetMapMode(printCanvHandle, mm_lometric);    // 0.1 Millimeter-Einheiten, Positive x-Achse nach rechts und positive y-Achse nach oben.
    GetWindowExtEx(printCanvHandle,w);           // die Abmessungen des Windows auslesen
    GetViewPortExtEx(printCanvHandle,v);         // die Abmessungen des Viewports auslesen
    SetMapMode(printCanvHandle, MM_ANISOTROPIC);
    SetWindowExtEx(printCanvHandle, w.cx, w.cy, nil);  //die Abmessungen des Windows festlegen
    SetViewPortExtEx(printCanvHandle,v.cx, -v.cy,nil); // die Abmessungen des Viewports festlegen


    for i:=0 to Schilder.Count-1 do
    begin
      tempSchild := TSchild(Schilder[i]);

      // -------------------------------------------------------------------  //
      // Zeilen des Schildes zeichnen:
      for a:=0 to tempSchild.Zeilen.Count-1 do
      begin
        tempZeile := TZeile(tempSchild.Zeilen[a]);

        Font1        := TFont.Create;
        Font1.Name  := tempZeile.Font.Name;
        Font1.Style := tempZeile.Font.Style;

        Printer.Canvas.Font.Assign(Font1);

        Printer.Canvas.Font.Height := Trunc(PixelToMM(Trunc(-tempZeile.Font.Size * tempZeile.Font.PixelsPerInch / 72), tempZeile.Font.PixelsPerInch) * 10);

        Printer.Canvas.TextOut( Trunc(PixelToMM(tempSchild.xPos + tempZeile.xPos, Screen.PixelsPerInch)*10),
                                Trunc(PixelToMM(tempSchild.yPos + tempZeile.yPos, Screen.PixelsPerInch)*10),
                                tempZeile.txt);
        Font1.Free;
      end;

    end;

    Printer.EndDoc;

  end;
end;
MfG
Marcus
  Mit Zitat antworten Zitat