git-svn-id: https://svn.code.sf.net/p/kolmck/code@65 91bb2d04-0c0c-4d2d-88a5-bbb6f4c1fa07
This commit is contained in:
@@ -69,46 +69,46 @@ Still missing (I suppose):
|
||||
|
||||
interface
|
||||
|
||||
uses Windows,Messages,KOL,KOLPrintCommon;
|
||||
uses Windows, Messages, KOL, KOLPrintCommon;
|
||||
|
||||
type
|
||||
TPrinterState = (psNeedHandle,psHandle,psOtherHandle);
|
||||
TPrinterOrientation = (poPortrait,poLandscape);
|
||||
{* Paper orientation}
|
||||
TMarginOption = (mgInches,mgMillimeters);
|
||||
{* Margin option}
|
||||
TPrinterState = (psNeedHandle, psHandle, psOtherHandle);
|
||||
TPrinterOrientation = (poPortrait, poLandscape);
|
||||
{* Paper orientation}
|
||||
TMarginOption = (mgInches, mgMillimeters);
|
||||
{* Margin option}
|
||||
|
||||
PPrinter =^TPrinter;
|
||||
PPrinter = ^TPrinter;
|
||||
TKOLPrinter = PPrinter;
|
||||
TPrinter = object(TObj)
|
||||
{*}
|
||||
private
|
||||
{ Private declarations }
|
||||
fDevice,fDriver,fPort : String;
|
||||
fDevMode : THandle;
|
||||
fDeviceMode : PDeviceMode;
|
||||
fCanvas : PCanvas; // KOL canvas
|
||||
fTitle : String;
|
||||
fState : TPrinterState; // DC is allocated or need new DC becouse params were changed
|
||||
fAborted : Boolean;
|
||||
fPrinting : Boolean;
|
||||
fPageNumber : Integer;
|
||||
fOutput : String;
|
||||
PrinterInfo : TPrinterInfo;
|
||||
fRec : TRect;
|
||||
fMargins : TRect; //Margins (in pixels)
|
||||
fAssigned : Boolean; //if TRUE ,there is a printer with correctly assigned information
|
||||
fDevice, fDriver, fPort: string;
|
||||
fDevMode: THandle;
|
||||
fDeviceMode: PDeviceMode;
|
||||
fCanvas: PCanvas; // KOL canvas
|
||||
fTitle: string;
|
||||
fState: TPrinterState; // DC is allocated or need new DC becouse params were changed
|
||||
fAborted: Boolean;
|
||||
fPrinting: Boolean;
|
||||
fPageNumber: Integer;
|
||||
fOutput: string;
|
||||
PrinterInfo: TPrinterInfo;
|
||||
fRec: TRect;
|
||||
fMargins: TRect; //Margins (in pixels)
|
||||
fAssigned: Boolean; //if TRUE ,there is a printer with correctly assigned information
|
||||
protected
|
||||
function GetHandle : HDC;
|
||||
procedure SetHandle(Value : HDC);
|
||||
function GetCanvas : PCanvas;
|
||||
function GetCopies : Integer;
|
||||
procedure SetCopies(const Value : Integer);
|
||||
function GetOrientation : TPrinterOrientation;
|
||||
procedure SetOrientation(const Value : TPrinterOrientation);
|
||||
function GetPageHeight : Integer;
|
||||
function GetPageWidth : Integer;
|
||||
function Scale : Integer;
|
||||
function GetHandle: HDC;
|
||||
procedure SetHandle(Value: HDC);
|
||||
function GetCanvas: PCanvas;
|
||||
function GetCopies: Integer;
|
||||
procedure SetCopies(const Value: Integer);
|
||||
function GetOrientation: TPrinterOrientation;
|
||||
procedure SetOrientation(const Value: TPrinterOrientation);
|
||||
function GetPageHeight: Integer;
|
||||
function GetPageWidth: Integer;
|
||||
function Scale: Integer;
|
||||
procedure Prepare;
|
||||
procedure DefPrinter;
|
||||
public
|
||||
@@ -122,66 +122,64 @@ TMarginOption = (mgInches,mgMillimeters);
|
||||
{* End print process end send it to print spooler}
|
||||
procedure NewPage;
|
||||
{* Request new page}
|
||||
procedure Assign(Source : PPrinterInfo);
|
||||
procedure Assign(Source: PPrinterInfo);
|
||||
{* Assign information about selected printer for example from Print/Page dialogs}
|
||||
procedure AssignMargins(cMargins : TRect; Option : TMarginOption);
|
||||
procedure AssignMargins(cMargins: TRect; Option: TMarginOption);
|
||||
{* Assign information about paper margins for example from TKOLPageSetupDialog
|
||||
(in thousands of inches scale)}
|
||||
procedure WriteLn(const Text : String);
|
||||
procedure WriteLn(const Text: string);
|
||||
{* Print tekst with TKOLPrinter selected font.Note: can be invoked more than once, but currently
|
||||
only for text ended with #10#13 (other is not properly wraped around right page corner ;-( )}
|
||||
procedure RE_Print(RichEdit : PControl);
|
||||
procedure RE_Print(RichEdit: PControl);
|
||||
{* Print content of TKOLRichEdit (if Rich is not TKOLRichEdit nothing happens)
|
||||
with full formating of course :-)}
|
||||
property Assigned : Boolean read fAssigned;
|
||||
property Assigned: Boolean read fAssigned;
|
||||
{* If TRUE, there is a default or assigned previoulsy printer (by Assign).Always check
|
||||
this property to avoid access violation when there is no printer in system}
|
||||
property Title : String read fTitle write fTitle;
|
||||
property Title: string read fTitle write fTitle;
|
||||
{* Title of print process in print manager window}
|
||||
function Info : PPrinterInfo;
|
||||
function Info: PPrinterInfo;
|
||||
{* Returns info of selected print}
|
||||
property Output : String read fOutput write fOutput;
|
||||
property Output: string read fOutput write fOutput;
|
||||
{* Let print to the file.Assign file path to this property.}
|
||||
property Handle : HDC read GetHandle write SetHandle;
|
||||
property Handle: HDC read GetHandle write SetHandle;
|
||||
{*}
|
||||
property Canvas : PCanvas read GetCanvas;
|
||||
property Canvas: PCanvas read GetCanvas;
|
||||
{*}
|
||||
property Copies : Integer read GetCopies write SetCopies;
|
||||
property Copies: Integer read GetCopies write SetCopies;
|
||||
{* Number of copies}
|
||||
property Orientation : TPrinterOrientation read GetOrientation write SetOrientation;
|
||||
property Orientation: TPrinterOrientation read GetOrientation write SetOrientation;
|
||||
{* Page orientation}
|
||||
property Margins : TRect read fMargins write fMargins;
|
||||
property Margins: TRect read fMargins write fMargins;
|
||||
{* Page margins (in pixels)}
|
||||
property PageHeight : Integer read GetPageHeight;
|
||||
property PageHeight: Integer read GetPageHeight;
|
||||
{* Page height in logical pixels}
|
||||
property PageWidth : Integer read GetPageWidth;
|
||||
property PageWidth: Integer read GetPageWidth;
|
||||
{* Page width in logical pixels}
|
||||
property PageNumber : Integer read fPageNumber;
|
||||
property PageNumber: Integer read fPageNumber;
|
||||
{* Currently printed page number}
|
||||
property Printing : Boolean read fPrinting;
|
||||
property Printing: Boolean read fPrinting;
|
||||
{* Indicate printing process}
|
||||
property Aborted : Boolean read fAborted;
|
||||
property Aborted: Boolean read fAborted;
|
||||
{* Indicate abort of printing process}
|
||||
|
||||
end;
|
||||
|
||||
|
||||
function Printer : PPrinter;
|
||||
function Printer: PPrinter;
|
||||
{* Returns pointer to global TKOLPrinter object}
|
||||
procedure RecreatePrinter;
|
||||
{* Recreates global Printer pbject }
|
||||
|
||||
function NewPrinter(PrinterInfo : PPrinterInfo) : PPrinter;
|
||||
function NewPrinter(PrinterInfo: PPrinterInfo): PPrinter;
|
||||
{* Global function for creating TKOLPrinter instance.Usually not needed, becouse
|
||||
inluding KOLPrinters causes creating of global TKOLPrinter instance.}
|
||||
|
||||
|
||||
|
||||
implementation
|
||||
uses RichEdit;
|
||||
|
||||
uses
|
||||
RichEdit;
|
||||
|
||||
type
|
||||
|
||||
PtagPD = ^tagPD;
|
||||
tagPD = packed record
|
||||
lStructSize: DWORD;
|
||||
@@ -209,26 +207,19 @@ const
|
||||
PD_RETURNDC = $00000100;
|
||||
PD_RETURNDEFAULT = $00000400;
|
||||
|
||||
|
||||
|
||||
var
|
||||
FPrinter : PPrinter = nil;
|
||||
FPrinter : PPrinter = nil;
|
||||
|
||||
function PrintDlg(var PrintDlg: tagPD): BOOL; stdcall;external 'comdlg32.dll' name 'PrintDlgA';
|
||||
function PrintDlg(var PrintDlg: tagPD): BOOL; stdcall; external 'comdlg32.dll' name 'PrintDlgA';
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function AbortProc(Handle : HDC; Error : Integer) : Bool ; stdcall;
|
||||
function AbortProc(Handle: HDC; Error: Integer): Bool; stdcall;
|
||||
begin
|
||||
Result := not fPrinter.Aborted;
|
||||
end;
|
||||
|
||||
function NewPrinter(PrinterInfo : PPrinterInfo) : PPrinter;
|
||||
function NewPrinter(PrinterInfo: PPrinterInfo): PPrinter;
|
||||
begin
|
||||
New(Result,Create);
|
||||
New(Result, Create);
|
||||
Result.fTitle := '';
|
||||
Result.fOutput := '';
|
||||
Result.fAborted := False;
|
||||
@@ -239,15 +230,14 @@ begin
|
||||
Result.fMargins.Left := 10;
|
||||
Result.fMargins.Bottom := 10;
|
||||
Result.fMargins.Right := 10;
|
||||
FillChar(Result.fRec,sizeof(Result.fRec),0);
|
||||
if PrinterInfo = nil then Result.DefPrinter
|
||||
FillChar(Result.fRec, sizeof(Result.fRec), 0);
|
||||
if PrinterInfo = nil then
|
||||
Result.DefPrinter
|
||||
else
|
||||
Result.Assign(PrinterInfo);
|
||||
|
||||
end;
|
||||
|
||||
|
||||
function Printer : PPrinter;
|
||||
function Printer: PPrinter;
|
||||
begin
|
||||
if FPrinter = nil then
|
||||
FPrinter := NewPrinter(nil);
|
||||
@@ -256,12 +246,10 @@ end;
|
||||
|
||||
procedure RecreatePrinter;
|
||||
begin
|
||||
Free_And_Nil( FPrinter );
|
||||
Free_And_Nil(FPrinter);
|
||||
FPrinter := NewPrinter(nil);
|
||||
end;
|
||||
|
||||
|
||||
|
||||
destructor TPrinter.Destroy;
|
||||
begin
|
||||
Prepare;
|
||||
@@ -277,56 +265,52 @@ end;
|
||||
procedure TPrinter.Prepare;
|
||||
begin
|
||||
{ Free previously used resources }
|
||||
if (fState <> psOtherHandle) and (fCanvas <> nil) then
|
||||
begin
|
||||
if (fState <> psOtherHandle) and (fCanvas <> nil) then begin
|
||||
fCanvas.Free;
|
||||
fCanvas := nil; {+++}
|
||||
end;
|
||||
if fDevMode <> 0 then
|
||||
begin
|
||||
if fDevMode <> 0 then begin
|
||||
GlobalUnlock(fDevMode);
|
||||
GlobalFree(fDevMode);
|
||||
end;
|
||||
end;
|
||||
|
||||
function TPrinter.Scale : Integer;
|
||||
function TPrinter.Scale: Integer;
|
||||
var
|
||||
DC : HDC;
|
||||
ScreenH,PrinterH : Integer;
|
||||
DC : HDC;
|
||||
ScreenH, PrinterH : Integer;
|
||||
begin
|
||||
DC := GetDC(0);
|
||||
ScreenH := GetDeviceCaps(DC,LOGPIXELSY);
|
||||
PrinterH := GetDeviceCaps(fCanvas.Handle,LOGPIXELSY);
|
||||
ReleaseDC(0,DC);
|
||||
ScreenH := GetDeviceCaps(DC, LOGPIXELSY);
|
||||
PrinterH := GetDeviceCaps(fCanvas.Handle, LOGPIXELSY);
|
||||
ReleaseDC(0, DC);
|
||||
Result := PrinterH div ScreenH;
|
||||
end;
|
||||
|
||||
procedure TPrinter.WriteLn(const Text : String);
|
||||
procedure TPrinter.WriteLn(const Text: string);
|
||||
var
|
||||
OldFontSize,PageH,Size,Len : Integer;
|
||||
pC : PChar;
|
||||
Rect : TRect;
|
||||
Metrics : TTextMetric;
|
||||
NewText : String;
|
||||
OldFontSize, PageH, Size, Len: Integer;
|
||||
pC : PChar;
|
||||
Rect : TRect;
|
||||
Metrics : TTextMetric;
|
||||
NewText : string;
|
||||
|
||||
procedure ComputeRect;
|
||||
{ Start from new line.Rect is the rest of page from current new line to the bottom. First probe
|
||||
procedure ComputeRect;
|
||||
{ Start from new line.Rect is the rest of page from current new line to the bottom. First probe
|
||||
how many characters do not fit on this rect.}
|
||||
begin
|
||||
Len := 1;
|
||||
while Windows.DrawText(fCanvas.Handle,pC,Len,Rect,DT_CALCRECT + DT_WORDBREAK + DT_NOCLIP + DT_NOPREFIX + DT_EXPANDTABS) < PageH do
|
||||
begin
|
||||
Len := 1;
|
||||
while Windows.DrawText(fCanvas.Handle, pC, Len, Rect, DT_CALCRECT + DT_WORDBREAK + DT_NOCLIP + DT_NOPREFIX + DT_EXPANDTABS) < PageH do begin
|
||||
Rect.Right := fRec.Right; //must be, becouse DrawText shorten right corner
|
||||
Len := Len + 100;
|
||||
if Len > Size then
|
||||
begin
|
||||
if Len > Size then begin
|
||||
Len := Size;
|
||||
Break;
|
||||
end;
|
||||
end;
|
||||
|
||||
{ Next : Count backwards to find exact characters which fit on required page rect.}
|
||||
while Windows.DrawText(fCanvas.Handle,pC,Len,Rect,DT_CALCRECT + DT_WORDBREAK + DT_NOCLIP + DT_NOPREFIX + DT_EXPANDTABS) > PageH do
|
||||
while Windows.DrawText(fCanvas.Handle, pC, Len, Rect, DT_CALCRECT + DT_WORDBREAK + DT_NOCLIP + DT_NOPREFIX + DT_EXPANDTABS) > PageH do
|
||||
Len := Len - 1;
|
||||
|
||||
{ Find position of last space or line end (#13#10) to not break word
|
||||
@@ -340,31 +324,28 @@ begin
|
||||
}
|
||||
|
||||
{ Finally draw it!}
|
||||
Windows.DrawText(fCanvas.Handle,pC,Len,Rect,DT_WORDBREAK + DT_NOCLIP + DT_NOPREFIX + DT_EXPANDTABS);
|
||||
|
||||
|
||||
end;
|
||||
Windows.DrawText(fCanvas.Handle, pC, Len, Rect, DT_WORDBREAK + DT_NOCLIP + DT_NOPREFIX + DT_EXPANDTABS);
|
||||
|
||||
end;
|
||||
|
||||
begin
|
||||
if Length(Text) <=0 then Exit;
|
||||
if Text[Length(Text)] <> #10 then NewText := Text + #13#10
|
||||
else
|
||||
NewText := Text;
|
||||
pC := PChar(NewText);
|
||||
Size := Length(NewText);
|
||||
SetMapMode(fCanvas.Handle,MM_TEXT);
|
||||
OldFontSize := fCanvas.Font.FontHeight;
|
||||
fCanvas.Font.FontHeight := fCanvas.Font.FontHeight * Scale;
|
||||
SelectObject(fCanvas.Handle,fCanvas.Font.Handle);
|
||||
PageH := GetPageHeight - fMargins.Bottom;
|
||||
GetTextMetrics(fCanvas.Handle,Metrics);
|
||||
while Size > 0 do
|
||||
begin
|
||||
if Length(Text) <= 0 then Exit;
|
||||
if Text[Length(Text)] <> #10 then NewText := Text + #13#10
|
||||
else
|
||||
NewText := Text;
|
||||
pC := PChar(NewText);
|
||||
Size := Length(NewText);
|
||||
SetMapMode(fCanvas.Handle, MM_TEXT);
|
||||
OldFontSize := fCanvas.Font.FontHeight;
|
||||
fCanvas.Font.FontHeight := fCanvas.Font.FontHeight * Scale;
|
||||
SelectObject(fCanvas.Handle, fCanvas.Font.Handle);
|
||||
PageH := GetPageHeight - fMargins.Bottom;
|
||||
GetTextMetrics(fCanvas.Handle, Metrics);
|
||||
while Size > 0 do begin
|
||||
Rect := fRec;
|
||||
ComputeRect;
|
||||
Inc(pC,Len + 1);
|
||||
Dec(Size,Len + 1);
|
||||
Inc(pC, Len + 1);
|
||||
Dec(Size, Len + 1);
|
||||
if (Size > 0) and (fRec.Left <= fMargins.Left) then NewPage;
|
||||
end;
|
||||
if (Rect.Bottom > PageH) then begin
|
||||
@@ -378,17 +359,16 @@ while Size > 0 do
|
||||
NewText := '';
|
||||
end;
|
||||
|
||||
|
||||
procedure TPrinter.DefPrinter;
|
||||
var
|
||||
ftagPD : tagPD;
|
||||
DevNames : PDevNames;
|
||||
ftagPD : tagPD;
|
||||
DevNames : PDevNames;
|
||||
begin
|
||||
fAssigned := false;
|
||||
fState := psHandle;
|
||||
Prepare;
|
||||
{ Get DC of default printer }
|
||||
FillChar(ftagPD,sizeof(tagPD),0);
|
||||
FillChar(ftagPD, sizeof(tagPD), 0);
|
||||
ftagPD.Flags := PD_RETURNDC + PD_RETURNDEFAULT;
|
||||
ftagPD.lStructSize := sizeof(ftagPD);
|
||||
if not PrintDlg(ftagPD) then Exit;
|
||||
@@ -397,9 +377,9 @@ begin
|
||||
fDevMode := ftagPD.hDevMode;
|
||||
fDeviceMode := PDevMode(GlobalLock(fDevMode));
|
||||
try
|
||||
fDriver := String(PChar(DevNames) + DevNames^.wDriverOffset);
|
||||
fDevice := String(PChar(DevNames) + DevNames^.wDeviceOffset);
|
||||
fPort := String(PChar(DevNames) + DevNames^.wOutputOffset);
|
||||
fDriver := string(PChar(DevNames) + DevNames^.wDriverOffset);
|
||||
fDevice := string(PChar(DevNames) + DevNames^.wDeviceOffset);
|
||||
fPort := string(PChar(DevNames) + DevNames^.wOutputOffset);
|
||||
finally
|
||||
GlobalUnlock(ftagPD.hDevNames);
|
||||
GlobalFree(ftagPD.hDevNames);
|
||||
@@ -407,11 +387,11 @@ begin
|
||||
fCanvas := NewCanvas(ftagPD.hDC);
|
||||
end;
|
||||
|
||||
procedure TPrinter.Assign(Source : PPrinterInfo);
|
||||
procedure TPrinter.Assign(Source: PPrinterInfo);
|
||||
var
|
||||
Size : Integer;
|
||||
DevMode : PDevMode;
|
||||
fhDC : HDC;
|
||||
Size : Integer;
|
||||
DevMode : PDevMode;
|
||||
fhDC : HDC;
|
||||
begin
|
||||
fAssigned := false;
|
||||
if (Source = nil) or
|
||||
@@ -419,19 +399,18 @@ begin
|
||||
(Source^.ADevice = nil) and
|
||||
(Source^.APort = nil) and
|
||||
(Source^.ADevMode = 0) then DefPrinter
|
||||
else
|
||||
begin
|
||||
else begin
|
||||
Prepare;
|
||||
fDriver := String(Source^.ADriver);
|
||||
fDevice := String(Source^.ADevice);
|
||||
fPort := String(Source^.APort);
|
||||
fDriver := string(Source^.ADriver);
|
||||
fDevice := string(Source^.ADevice);
|
||||
fPort := string(Source^.APort);
|
||||
DevMode := PDevMode(GlobalLock(Source^.ADevMode));
|
||||
try
|
||||
Size := sizeof(DevMode^);
|
||||
fDevMode := GlobalAlloc(GHND,Size);
|
||||
fDevMode := GlobalAlloc(GHND, Size);
|
||||
fDeviceMode := PDevMode(GlobalLock(fDevMode));
|
||||
CopyMemory(fDeviceMode,DevMode,Size);
|
||||
fhDC := CreateDC(PChar(fDriver),PChar(fDevice),PChar(fPort),fDeviceMode);
|
||||
CopyMemory(fDeviceMode, DevMode, Size);
|
||||
fhDC := CreateDC(PChar(fDriver), PChar(fDevice), PChar(fPort), fDeviceMode);
|
||||
finally
|
||||
GlobalUnlock(Source^.ADevMode);
|
||||
end;
|
||||
@@ -440,27 +419,24 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
procedure TPrinter.AssignMargins(cMargins : TRect;Option : TMarginOption);
|
||||
procedure TPrinter.AssignMargins(cMargins: TRect; Option: TMarginOption);
|
||||
var
|
||||
PH,PW : Integer;
|
||||
PH, PW : Integer;
|
||||
begin
|
||||
PH := GetDeviceCaps(fCanvas.Handle,LOGPIXELSY);
|
||||
PW := GetDeviceCaps(fCanvas.Handle,LOGPIXELSX);
|
||||
PH := GetDeviceCaps(fCanvas.Handle, LOGPIXELSY);
|
||||
PW := GetDeviceCaps(fCanvas.Handle, LOGPIXELSX);
|
||||
case Option of
|
||||
mgInches:
|
||||
begin
|
||||
fMargins.Top := round((cMargins.Top*PH)/1000);
|
||||
fMargins.Left := round((cMargins.Left*PW)/1000);
|
||||
fMargins.Bottom := round((cMargins.Bottom*PH)/1000);
|
||||
fMargins.Right := round((cMargins.Right*PW)/1000);
|
||||
mgInches: begin
|
||||
fMargins.Top := round((cMargins.Top * PH) / 1000);
|
||||
fMargins.Left := round((cMargins.Left * PW) / 1000);
|
||||
fMargins.Bottom := round((cMargins.Bottom * PH) / 1000);
|
||||
fMargins.Right := round((cMargins.Right * PW) / 1000);
|
||||
end;
|
||||
mgMillimeters:
|
||||
begin
|
||||
fMargins.Top := round((cMargins.Top*PH)/2540);
|
||||
fMargins.Left := round((cMargins.Left*PW)/2540);
|
||||
fMargins.Bottom := round((cMargins.Bottom*PH)/2540);
|
||||
fMargins.Right := round((cMargins.Right*PW)/2540);
|
||||
mgMillimeters: begin
|
||||
fMargins.Top := round((cMargins.Top * PH) / 2540);
|
||||
fMargins.Left := round((cMargins.Left * PW) / 2540);
|
||||
fMargins.Bottom := round((cMargins.Bottom * PH) / 2540);
|
||||
fMargins.Right := round((cMargins.Right * PW) / 2540);
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
@@ -472,24 +448,23 @@ begin
|
||||
EndDoc;
|
||||
end;
|
||||
|
||||
|
||||
procedure TPrinter.BeginDoc;
|
||||
var
|
||||
doc : DOCINFOA;
|
||||
doc : DOCINFOA;
|
||||
begin
|
||||
fRec.Top := fMargins.Top;
|
||||
fRec.Left := fMargins.Left;
|
||||
fRec.Right := GetPageWidth - fMargins.Right ;
|
||||
fRec.Right := GetPageWidth - fMargins.Right;
|
||||
fRec.Bottom := GetPageHeight - fMargins.Bottom;
|
||||
fAborted := False;
|
||||
fPageNumber :=1;
|
||||
fPageNumber := 1;
|
||||
fPrinting := True;
|
||||
FillChar(doc,sizeof(DOCINFOA),0);
|
||||
FillChar(doc, sizeof(DOCINFOA), 0);
|
||||
doc.lpszDocName := PChar(fTitle);
|
||||
if (fOutput <> '') then doc.lpszOutput := PChar(fOutput);
|
||||
doc.cbSize := sizeof(doc);
|
||||
SetAbortProc(fCanvas.Handle,AbortProc);
|
||||
StartDoc(fCanvas.Handle,doc);
|
||||
SetAbortProc(fCanvas.Handle, AbortProc);
|
||||
StartDoc(fCanvas.Handle, doc);
|
||||
StartPage(fCanvas.Handle);
|
||||
end;
|
||||
|
||||
@@ -503,42 +478,35 @@ begin
|
||||
fPrinting := False;
|
||||
end;
|
||||
|
||||
|
||||
|
||||
|
||||
function TPrinter.GetHandle : HDC;
|
||||
function TPrinter.GetHandle: HDC;
|
||||
var
|
||||
fhDC : HDC;
|
||||
fhDC : HDC;
|
||||
begin
|
||||
if (fState = psNeedHandle) and (fCanvas <> nil) then
|
||||
begin
|
||||
if (fState = psNeedHandle) and (fCanvas <> nil) then begin
|
||||
fCanvas.Free;
|
||||
fhDC := CreateDC(PChar(fDriver),PChar(fDevice),PChar(fPort),fDeviceMode);
|
||||
fhDC := CreateDC(PChar(fDriver), PChar(fDevice), PChar(fPort), fDeviceMode);
|
||||
fCanvas := NewCanvas(fhDC);
|
||||
fState := psHandle;
|
||||
end;
|
||||
Result := fCanvas.Handle;
|
||||
end;
|
||||
|
||||
procedure TPrinter.SetHandle(Value : HDC);
|
||||
procedure TPrinter.SetHandle(Value: HDC);
|
||||
begin
|
||||
if Value <> fCanvas.Handle then
|
||||
begin
|
||||
if Value <> fCanvas.Handle then begin
|
||||
if fCanvas <> nil then fCanvas.Free;
|
||||
fCanvas := NewCanvas(Value);
|
||||
fState := psOtherHandle;
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
function TPrinter.GetCanvas : PCanvas;
|
||||
function TPrinter.GetCanvas: PCanvas;
|
||||
begin
|
||||
GetHandle;
|
||||
Result := fCanvas;
|
||||
end;
|
||||
|
||||
|
||||
function TPrinter.Info : PPrinterInfo;
|
||||
function TPrinter.Info: PPrinterInfo;
|
||||
begin
|
||||
with PrinterInfo do begin
|
||||
ADevice := PChar(fDevice);
|
||||
@@ -549,19 +517,17 @@ begin
|
||||
Result := @PrinterInfo;
|
||||
end;
|
||||
|
||||
function TPrinter.GetCopies : Integer;
|
||||
function TPrinter.GetCopies: Integer;
|
||||
begin
|
||||
Result := fDeviceMode^.dmCopies;
|
||||
end;
|
||||
|
||||
|
||||
procedure TPrinter.SetCopies(const Value : Integer);
|
||||
procedure TPrinter.SetCopies(const Value: Integer);
|
||||
begin
|
||||
fDeviceMode^.dmCopies := Value;
|
||||
end;
|
||||
|
||||
|
||||
function TPrinter.GetOrientation : TPrinterOrientation;
|
||||
function TPrinter.GetOrientation: TPrinterOrientation;
|
||||
begin
|
||||
if System.Assigned(fDeviceMode) and (fDeviceMode^.dmOrientation = DMORIENT_PORTRAIT) then
|
||||
Result := poPortrait
|
||||
@@ -569,24 +535,24 @@ begin
|
||||
Result := poLandscape;
|
||||
end;
|
||||
|
||||
procedure TPrinter.SetOrientation(const Value : TPrinterOrientation);
|
||||
procedure TPrinter.SetOrientation(const Value: TPrinterOrientation);
|
||||
const
|
||||
Orientations : array [TPrinterOrientation] of Integer = (DMORIENT_PORTRAIT,DMORIENT_LANDSCAPE);
|
||||
Orientations : array[TPrinterOrientation] of Integer = (DMORIENT_PORTRAIT, DMORIENT_LANDSCAPE);
|
||||
begin
|
||||
fDeviceMode^.dmOrientation := Orientations[Value];
|
||||
end;
|
||||
|
||||
function TPrinter.GetPageHeight : Integer;
|
||||
function TPrinter.GetPageHeight: Integer;
|
||||
begin
|
||||
if fCanvas <> nil then
|
||||
Result := GetDeviceCaps(fCanvas.Handle,VERTRES)
|
||||
Result := GetDeviceCaps(fCanvas.Handle, VERTRES)
|
||||
else Result := 0;
|
||||
end;
|
||||
|
||||
function TPrinter.GetPageWidth : Integer;
|
||||
function TPrinter.GetPageWidth: Integer;
|
||||
begin
|
||||
if fCanvas <> nil then
|
||||
Result := GetDeviceCaps(fCanvas.Handle,HORZRES)
|
||||
Result := GetDeviceCaps(fCanvas.Handle, HORZRES)
|
||||
else Result := 0;
|
||||
end;
|
||||
|
||||
@@ -598,19 +564,18 @@ begin
|
||||
fRec.Bottom := GetPageHeight - fMargins.Bottom;
|
||||
EndPage(fCanvas.Handle);
|
||||
StartPage(fCanvas.Handle);
|
||||
SelectObject(fCanvas.Handle,fCanvas.Font.Handle);
|
||||
SelectObject(fCanvas.Handle, fCanvas.Font.Handle);
|
||||
Inc(fPageNumber);
|
||||
end;
|
||||
|
||||
|
||||
procedure TPrinter.RE_Print(RichEdit : PControl);
|
||||
procedure TPrinter.RE_Print(RichEdit: PControl);
|
||||
var
|
||||
Range: TFormatRange;
|
||||
Range : TFormatRange;
|
||||
LastChar, MaxLen, LogX, LogY, OldMap: Integer;
|
||||
SaveRect: TRect;
|
||||
TextLenEx: TGetTextLengthEx;
|
||||
SaveRect : TRect;
|
||||
TextLenEx : TGetTextLengthEx;
|
||||
begin
|
||||
if IndexOfStr(RichEdit.SubClassName,'obj_RichEdit') = -1 then Exit;
|
||||
if IndexOfStr(RichEdit.SubClassName, 'obj_RichEdit') = -1 then Exit;
|
||||
FillChar(Range, SizeOf(TFormatRange), 0);
|
||||
with Range do begin
|
||||
BeginDoc;
|
||||
@@ -618,22 +583,22 @@ begin
|
||||
hdcTarget := hdc;
|
||||
LogX := GetDeviceCaps(Handle, LOGPIXELSX);
|
||||
LogY := GetDeviceCaps(Handle, LOGPIXELSY);
|
||||
rc.Top := fMargins.Top*1440 div LogY;
|
||||
rc.Left := fMargins.Left*1440 div LogX;
|
||||
rc.Right := (GetPageWidth - fMargins.Right) * 1440 div LogX ;
|
||||
rc.Top := fMargins.Top * 1440 div LogY;
|
||||
rc.Left := fMargins.Left * 1440 div LogX;
|
||||
rc.Right := (GetPageWidth - fMargins.Right) * 1440 div LogX;
|
||||
rc.Bottom := (GetPageHeight - fMargins.Bottom) * 1440 div LogY;
|
||||
rcPage := rc;
|
||||
SaveRect := rc;
|
||||
LastChar := 0;
|
||||
// if RichEdit.Version >= 2 then begin
|
||||
// if RichEdit.Version >= 2 then begin
|
||||
with TextLenEx do begin
|
||||
flags := GTL_DEFAULT;
|
||||
codepage := CP_ACP;
|
||||
end;
|
||||
MaxLen := RichEdit.Perform(EM_GETTEXTLENGTHEX, WParam(@TextLenEx), 0);
|
||||
// end
|
||||
// else
|
||||
// MaxLen := Length(RichEdit.RE_Text[ reRTF, True ]);
|
||||
// end
|
||||
// else
|
||||
// MaxLen := Length(RichEdit.RE_Text[ reRTF, True ]);
|
||||
chrg.cpMax := -1;
|
||||
OldMap := SetMapMode(hdc, MM_TEXT);
|
||||
SendMessage(RichEdit.Handle, EM_FORMATRANGE, 0, 0); { flush buffer }
|
||||
@@ -652,12 +617,10 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
initialization
|
||||
//FPrinter := NewPrinter(nil);
|
||||
//FPrinter := NewPrinter(nil);
|
||||
|
||||
finalization
|
||||
Free_And_Nil( FPrinter );
|
||||
Free_And_Nil(FPrinter);
|
||||
end.
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user