TIP: Click on subject to list as thread! ANSI
echo: delphi
to: RON TUYNMAN
from: STEVE ROGERS
date: 1997-08-15 15:59:00
subject: RE: DELPHI UNLEASHED? 1/2

RT> SR> You may be interested in a little printer unit I've done.
  > ...I'm interested!
  OK, it's a bit rough but it looks like my schedule isn't going to let
  me finish it anytime soon.
unit
  inchprint;
interface
function xInch(x : single) : word;
function yInch(y : single) : word;
function CurrentLinesPerPage : word;
function PageCenter : word;
function PageMiddle : word;
procedure BeginDoc;
procedure EndDoc;
procedure SetLeftMargin(Margin : word);
procedure SetTopMargin(Margin : word);
procedure TxtOut(x,y : word;s : string);
procedure WriteLine(s : string);
{-----------------------}
implementation
uses
  Printers,Windows;
var
  isPrinting : boolean;
  CurrentLine,
  TopMargin,
  LeftMargin  : word;
{-----------------------}
function xInch;
{ returns pixels in "x" inches, scaled to Printer resolution }
begin
  isPrinting:= Printer.Printing;
  if not isPrinting then
    Printer.BeginDoc;
  xInch:= round(x * GetDeviceCaps(Printer.canvas.handle,LOGPIXELSx));
  if not isPrinting then
    Printer.Abort;
end;
{-----------------------}
function yInch;
{ returns pixels in "y" inches, scaled to Printer resolution }
begin
  isPrinting:= Printer.Printing;
  if not isPrinting then
    Printer.BeginDoc;
  yInch:= round(y * GetDeviceCaps(Printer.canvas.handle,LOGPIXELSy));
  if not isPrinting then
    Printer.Abort;
end;
{-----------------------}
function CurrentLinesPerPage;
begin
  with Printer do begin
    isPrinting:= Printing;
    if not isPrinting then
      Printer.BeginDoc;
    CurrentLinesPerPage:= (PageHeight - TopMargin) div 
anvas.TextHeight('X');
    if not isPrinting then
      Printer.Abort;
  end;
end;
{-----------------------}
function PageCenter : word;
begin
  PageCenter:= (Printer.PageWidth - LeftMargin) div 2;
end;
{-----------------------}
function PageMiddle : word;
begin
  PageMiddle:= (Printer.PageHeight - TopMargin) div 2;
end;
{-----------------------}
procedure BeginDoc;
begin
  Printer.BeginDoc;
  CurrentLine:= TopMargin;
end;
{-----------------------}
procedure EndDoc;
begin
  Printer.EndDoc;
end;
{-----------------------}
procedure SetTopMargin;
begin
  isPrinting:= Printer.Printing;
  if not isPrinting then
    Printer.BeginDoc;
  TopMargin:= round(Margin -
              GetDeviceCaps(Printer.canvas.handle,PHYSICALOFFSETy));
  if not isPrinting then
    Printer.Abort;
end;
{-----------------------}
procedure SetLeftMargin;
begin
  isPrinting:= Printer.Printing;
  if not isPrinting then
    Printer.BeginDoc;
  LeftMargin:= round(Margin -
                    GetDeviceCaps(Printer.canvas.handle,PHYSICALOFFSETx));
  if not isPrinting then
    Printer.Abort;
end;
{-----------------------}
procedure TxtOut;
begin
  Printer.Canvas.TextOut(xInch(x) + LeftMargin,
                         yInch(y) + TopMargin,
                         s);
end;
{-----------------------}
procedure FormFeed;
begin
  Printer.NewPage;
  CurrentLine:= TopMargin;
end;
{-----------------------}
procedure WriteLine;
begin
  with Printer do begin
    if (CurrentLine + Canvas.TextHeight(s) >
        Printer.PageHeight - TopMargin) then
      FormFeed;
    Canvas.TextOut(LeftMargin,CurrentLine,(s));
    inc(CurrentLine,Canvas.TextHeight(s));
>>> Continued to next message
--- PCBoard (R) v15.3/M 5
---------------
* Origin: Riverdale, Ga (1:133/9024)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.