Printers, added TPrinter.FileName property, based on patch from mtournay, issue #13718

git-svn-id: trunk@20805 -
This commit is contained in:
jesus 2009-07-07 05:09:52 +00:00
parent c3e4eb2a74
commit f6920f782e
11 changed files with 118 additions and 61 deletions

View File

@ -11,10 +11,10 @@ object Form1: TForm1
Position = poScreenCenter
LCLVersion = '0.9.27'
object Label1: TLabel
Left = 16
Height = 16
Top = 8
Width = 304
Left = 12
Height = 14
Top = 4
Width = 230
Caption = 'This sample show how to use the printer dialogs'
ParentColor = False
end
@ -22,7 +22,7 @@ object Form1: TForm1
Left = 8
Height = 27
Top = 51
Width = 320
Width = 176
BorderSpacing.InnerBorder = 4
Caption = 'Execute TPrinterSetupDialog'
OnClick = Button2Click
@ -32,7 +32,7 @@ object Form1: TForm1
Left = 8
Height = 27
Top = 78
Width = 320
Width = 176
BorderSpacing.InnerBorder = 4
Caption = 'Execute TPrintDialog'
OnClick = Button1Click
@ -59,10 +59,9 @@ object Form1: TForm1
MaxSize = 350
ReadOnly = True
Title.Caption = 'Value'
Width = 198
Width = 196
end>
DefaultColWidth = 120
DefaultRowHeight = 20
FixedCols = 0
FixedRows = 0
Options = [goVertLine, goRangeSelect, goSmoothScroll]
@ -70,21 +69,25 @@ object Form1: TForm1
TabOrder = 7
TitleStyle = tsNative
OnSelectCell = SGridSelectCell
ColWidths = (
120
196
)
end
object Button3: TButton
Left = 8
Height = 27
Top = 105
Width = 320
Width = 176
BorderSpacing.InnerBorder = 4
Caption = 'Get default printer info'
OnClick = Button3Click
TabOrder = 2
end
object Button4: TButton
Left = 240
Left = 200
Height = 27
Top = 157
Top = 155
Width = 88
BorderSpacing.InnerBorder = 4
Caption = 'Print test'
@ -95,7 +98,7 @@ object Form1: TForm1
Left = 8
Height = 25
Top = 132
Width = 224
Width = 176
BorderSpacing.InnerBorder = 4
Caption = 'Update printer state info'
OnClick = Button5Click
@ -105,7 +108,7 @@ object Form1: TForm1
Left = 8
Height = 25
Top = 157
Width = 224
Width = 176
BorderSpacing.InnerBorder = 4
Caption = 'Show printer properties'
OnClick = Button6Click
@ -115,20 +118,41 @@ object Form1: TForm1
Left = 8
Height = 27
Top = 24
Width = 320
Width = 176
BorderSpacing.InnerBorder = 4
Caption = 'Execute TPageSetupDialog'
OnClick = Button7Click
TabOrder = 6
end
object chkTestImgs: TCheckBox
Left = 240
Height = 22
Top = 135
Width = 82
Left = 200
Height = 17
Top = 133
Width = 65
Caption = 'Test Imgs'
TabOrder = 8
end
object chkOutputFile: TCheckBox
Left = 195
Height = 17
Top = 27
Width = 71
Caption = 'Output File'
TabOrder = 9
end
object txtOutputFile: TFileNameEdit
Left = 195
Height = 23
Top = 48
Width = 109
DialogKind = dkSave
DialogOptions = []
FilterIndex = 0
HideDirectories = False
ButtonWidth = 23
NumGlyphs = 0
TabOrder = 10
end
object PSD: TPrinterSetupDialog
Title = 'Testing dialog title'
left = 176

View File

@ -5,43 +5,48 @@ LazarusResources.Add('TForm1','FORMDATA',[
+'idth'#3'T'#1#13'ActiveControl'#7#7'Button7'#7'Caption'#6#5'Form1'#12'Client'
+'Height'#3#248#1#11'ClientWidth'#3'T'#1#8'OnCreate'#7#10'FormCreate'#8'Posit'
+'ion'#7#14'poScreenCenter'#10'LCLVersion'#6#6'0.9.27'#0#6'TLabel'#6'Label1'#4
+'Left'#2#16#6'Height'#2#16#3'Top'#2#8#5'Width'#3'0'#1#7'Caption'#6'/This sam'
+'ple show how to use the printer dialogs'#11'ParentColor'#8#0#0#7'TButton'#7
+'Button2'#4'Left'#2#8#6'Height'#2#27#3'Top'#2'3'#5'Width'#3'@'#1#25'BorderSp'
+'acing.InnerBorder'#2#4#7'Caption'#6#27'Execute TPrinterSetupDialog'#7'OnCli'
+'ck'#7#12'Button2Click'#8'TabOrder'#2#0#0#0#7'TButton'#7'Button1'#4'Left'#2#8
+#6'Height'#2#27#3'Top'#2'N'#5'Width'#3'@'#1#25'BorderSpacing.InnerBorder'#2#4
+#7'Caption'#6#20'Execute TPrintDialog'#7'OnClick'#7#12'Button1Click'#8'TabOr'
+'der'#2#1#0#0#11'TStringGrid'#5'SGrid'#4'Left'#2#8#6'Height'#3'0'#1#3'Top'#3
+#192#0#5'Width'#3'@'#1#14'AlternateColor'#7#7'clCream'#7'Anchors'#11#5'akTop'
+#6'akLeft'#7'akRight'#8'akBottom'#0#15'AutoFillColumns'#9#8'ColCount'#2#2#7
+'Columns'#14#1#5'Color'#7#9'clBtnFace'#12'SizePriority'#2#0#13'Title.Caption'
+#6#8'Property'#5'Width'#2'x'#0#1#7'MinSize'#2'<'#7'MaxSize'#3'^'#1#8'ReadOnl'
+'y'#9#13'Title.Caption'#6#5'Value'#5'Width'#3#198#0#0#0#15'DefaultColWidth'#2
+'x'#16'DefaultRowHeight'#2#20#9'FixedCols'#2#0#9'FixedRows'#2#0#7'Options'#11
+#10'goVertLine'#13'goRangeSelect'#14'goSmoothScroll'#0#8'RowCount'#2#15#8'Ta'
+'bOrder'#2#7#10'TitleStyle'#7#8'tsNative'#12'OnSelectCell'#7#15'SGridSelectC'
+'ell'#0#0#7'TButton'#7'Button3'#4'Left'#2#8#6'Height'#2#27#3'Top'#2'i'#5'Wid'
+'th'#3'@'#1#25'BorderSpacing.InnerBorder'#2#4#7'Caption'#6#24'Get default pr'
+'inter info'#7'OnClick'#7#12'Button3Click'#8'TabOrder'#2#2#0#0#7'TButton'#7
+'Button4'#4'Left'#3#240#0#6'Height'#2#27#3'Top'#3#157#0#5'Width'#2'X'#25'Bor'
+'derSpacing.InnerBorder'#2#4#7'Caption'#6#10'Print test'#7'OnClick'#7#12'But'
+'ton4Click'#8'TabOrder'#2#3#0#0#7'TButton'#7'Button5'#4'Left'#2#8#6'Height'#2
+#25#3'Top'#3#132#0#5'Width'#3#224#0#25'BorderSpacing.InnerBorder'#2#4#7'Capt'
+'ion'#6#25'Update printer state info'#7'OnClick'#7#12'Button5Click'#8'TabOrd'
+'er'#2#4#0#0#7'TButton'#7'Button6'#4'Left'#2#8#6'Height'#2#25#3'Top'#3#157#0
+#5'Width'#3#224#0#25'BorderSpacing.InnerBorder'#2#4#7'Caption'#6#23'Show pri'
+'nter properties'#7'OnClick'#7#12'Button6Click'#8'TabOrder'#2#5#0#0#7'TButto'
+'n'#7'Button7'#4'Left'#2#8#6'Height'#2#27#3'Top'#2#24#5'Width'#3'@'#1#25'Bor'
+'derSpacing.InnerBorder'#2#4#7'Caption'#6#24'Execute TPageSetupDialog'#7'OnC'
+'lick'#7#12'Button7Click'#8'TabOrder'#2#6#0#0#9'TCheckBox'#11'chkTestImgs'#4
+'Left'#3#240#0#6'Height'#2#22#3'Top'#3#135#0#5'Width'#2'R'#7'Caption'#6#9'Te'
+'st Imgs'#8'TabOrder'#2#8#0#0#19'TPrinterSetupDialog'#3'PSD'#5'Title'#6#20'T'
+'esting dialog title'#4'left'#3#176#0#3'top'#3#240#0#0#0#12'TPrintDialog'#2
+'PD'#5'Title'#6#13'Testing title'#7'Collate'#9#6'Copies'#2#1#8'FromPage'#2#2
+#7'MinPage'#2#2#7'MaxPage'#2#5#7'Options'#11#13'poPrintToFile'#10'poPageNums'
+#11'poSelection'#9'poWarning'#6'poHelp'#0#11'PrintToFile'#9#6'ToPage'#2#3#4
+'left'#3#176#0#3'top'#3#16#1#0#0#10'TPopupMenu'#10'PopupMenu1'#4'left'#3#216
+#0#3'top'#3#240#0#0#0#16'TPageSetupDialog'#5'PAGED'#5'Title'#6#25'Ustawienie'
+' strony raportu'#4'left'#3#176#0#3'top'#3'0'#1#0#0#0
+'Left'#2#12#6'Height'#2#14#3'Top'#2#4#5'Width'#3#230#0#7'Caption'#6'/This sa'
+'mple show how to use the printer dialogs'#11'ParentColor'#8#0#0#7'TButton'#7
+'Button2'#4'Left'#2#8#6'Height'#2#27#3'Top'#2'3'#5'Width'#3#176#0#25'BorderS'
+'pacing.InnerBorder'#2#4#7'Caption'#6#27'Execute TPrinterSetupDialog'#7'OnCl'
+'ick'#7#12'Button2Click'#8'TabOrder'#2#0#0#0#7'TButton'#7'Button1'#4'Left'#2
+#8#6'Height'#2#27#3'Top'#2'N'#5'Width'#3#176#0#25'BorderSpacing.InnerBorder'
+#2#4#7'Caption'#6#20'Execute TPrintDialog'#7'OnClick'#7#12'Button1Click'#8'T'
+'abOrder'#2#1#0#0#11'TStringGrid'#5'SGrid'#4'Left'#2#8#6'Height'#3'0'#1#3'To'
+'p'#3#192#0#5'Width'#3'@'#1#14'AlternateColor'#7#7'clCream'#7'Anchors'#11#5
+'akTop'#6'akLeft'#7'akRight'#8'akBottom'#0#15'AutoFillColumns'#9#8'ColCount'
+#2#2#7'Columns'#14#1#5'Color'#7#9'clBtnFace'#12'SizePriority'#2#0#13'Title.C'
+'aption'#6#8'Property'#5'Width'#2'x'#0#1#7'MinSize'#2'<'#7'MaxSize'#3'^'#1#8
+'ReadOnly'#9#13'Title.Caption'#6#5'Value'#5'Width'#3#196#0#0#0#15'DefaultCol'
+'Width'#2'x'#9'FixedCols'#2#0#9'FixedRows'#2#0#7'Options'#11#10'goVertLine'
+#13'goRangeSelect'#14'goSmoothScroll'#0#8'RowCount'#2#15#8'TabOrder'#2#7#10
+'TitleStyle'#7#8'tsNative'#12'OnSelectCell'#7#15'SGridSelectCell'#9'ColWidth'
+'s'#1#2'x'#3#196#0#0#0#0#7'TButton'#7'Button3'#4'Left'#2#8#6'Height'#2#27#3
+'Top'#2'i'#5'Width'#3#176#0#25'BorderSpacing.InnerBorder'#2#4#7'Caption'#6#24
+'Get default printer info'#7'OnClick'#7#12'Button3Click'#8'TabOrder'#2#2#0#0
+#7'TButton'#7'Button4'#4'Left'#3#200#0#6'Height'#2#27#3'Top'#3#155#0#5'Width'
+#2'X'#25'BorderSpacing.InnerBorder'#2#4#7'Caption'#6#10'Print test'#7'OnClic'
+'k'#7#12'Button4Click'#8'TabOrder'#2#3#0#0#7'TButton'#7'Button5'#4'Left'#2#8
+#6'Height'#2#25#3'Top'#3#132#0#5'Width'#3#176#0#25'BorderSpacing.InnerBorder'
+#2#4#7'Caption'#6#25'Update printer state info'#7'OnClick'#7#12'Button5Click'
+#8'TabOrder'#2#4#0#0#7'TButton'#7'Button6'#4'Left'#2#8#6'Height'#2#25#3'Top'
+#3#157#0#5'Width'#3#176#0#25'BorderSpacing.InnerBorder'#2#4#7'Caption'#6#23
+'Show printer properties'#7'OnClick'#7#12'Button6Click'#8'TabOrder'#2#5#0#0#7
+'TButton'#7'Button7'#4'Left'#2#8#6'Height'#2#27#3'Top'#2#24#5'Width'#3#176#0
+#25'BorderSpacing.InnerBorder'#2#4#7'Caption'#6#24'Execute TPageSetupDialog'
+#7'OnClick'#7#12'Button7Click'#8'TabOrder'#2#6#0#0#9'TCheckBox'#11'chkTestIm'
+'gs'#4'Left'#3#200#0#6'Height'#2#17#3'Top'#3#133#0#5'Width'#2'A'#7'Caption'#6
+#9'Test Imgs'#8'TabOrder'#2#8#0#0#9'TCheckBox'#13'chkOutputFile'#4'Left'#3
+#195#0#6'Height'#2#17#3'Top'#2#27#5'Width'#2'G'#7'Caption'#6#11'Output File'
+#8'TabOrder'#2#9#0#0#13'TFileNameEdit'#13'txtOutputFile'#4'Left'#3#195#0#6'H'
+'eight'#2#23#3'Top'#2'0'#5'Width'#2'm'#10'DialogKind'#7#6'dkSave'#13'DialogO'
+'ptions'#11#0#11'FilterIndex'#2#0#15'HideDirectories'#8#11'ButtonWidth'#2#23
+#9'NumGlyphs'#2#0#8'TabOrder'#2#10#0#0#19'TPrinterSetupDialog'#3'PSD'#5'Titl'
+'e'#6#20'Testing dialog title'#4'left'#3#176#0#3'top'#3#240#0#0#0#12'TPrintD'
+'ialog'#2'PD'#5'Title'#6#13'Testing title'#7'Collate'#9#6'Copies'#2#1#8'From'
+'Page'#2#2#7'MinPage'#2#2#7'MaxPage'#2#5#7'Options'#11#13'poPrintToFile'#10
+'poPageNums'#11'poSelection'#9'poWarning'#6'poHelp'#0#11'PrintToFile'#9#6'To'
+'Page'#2#3#4'left'#3#176#0#3'top'#3#16#1#0#0#10'TPopupMenu'#10'PopupMenu1'#4
+'left'#3#216#0#3'top'#3#240#0#0#0#16'TPageSetupDialog'#5'PAGED'#5'Title'#6#25
+'Ustawienie strony raportu'#4'left'#3#176#0#3'top'#3'0'#1#0#0#0
]);

View File

@ -25,7 +25,7 @@ interface
uses
Classes, SysUtils, Types, LResources, Forms, Controls, Graphics, Dialogs, Buttons,
PrintersDlgs, StdCtrls, Grids, Menus;
PrintersDlgs, StdCtrls, Grids, Menus, EditBtn;
type
@ -39,7 +39,9 @@ type
Button5: TButton;
Button6: TButton;
Button7: TButton;
chkOutputFile: TCheckBox;
chkTestImgs: TCheckBox;
txtOutputFile: TFileNameEdit;
Label1: TLABEL;
PAGED: TPageSetupDialog;
PD: TPrintDialog;
@ -161,6 +163,10 @@ var
begin
try
Printer.Title := 'Printer test for printers4lazarus package';
if chkOutputFile.Checked then
Printer.FileName := txtOutputFile.FileName
else
Printer.FileName := '';
Printer.BeginDoc;
// some often used consts

View File

@ -43,8 +43,8 @@
</Unit0>
<Unit1>
<Filename Value="frmselprinter.pas"/>
<ComponentName Value="Form1"/>
<IsPartOfProject Value="True"/>
<ComponentName Value="Form1"/>
<ResourceBaseClass Value="Form"/>
<UnitName Value="frmselprinter"/>
</Unit1>

View File

@ -846,7 +846,10 @@ begin
CopyFile(FOutputFileName, 'printjob'+ExtractFileExt(FOutputFileName));
{$ENDIF}
{$IFNDEF DoNotPrint}
PrintFile(FOutputFileName);
if Filename<>'' then
CopyFile(FOutputFileName, FileName)
else
PrintFile(FOutputFileName);
{$ENDIF}
DeleteFileUTF8(FOutputFilename);
end;

View File

@ -241,7 +241,7 @@ begin
if RawMode then begin
Doc1.DocName := pchar(Title);
Doc1.OutputFile := nil;
Doc1.OutputFile := pchar(Filename);
Doc1.DataType := 'RAW';
if StartDocPrinter(FPrinterHandle, 1, PByte(@Doc1))=0 then begin
@ -263,6 +263,7 @@ begin
FillChar(Inf,SizeOf(Inf),0);
Inf.cbSize:=SizeOf(Inf);
Inf.lpszDocName:=PChar(Title);
Inf.lpszOutput:=PChar(Filename);
StartDoc(fDC,@Inf);
StartPage(fDC);

View File

@ -113,5 +113,9 @@ After obtaining a CGImageRef, the next step to implement the RawImage_fromDevice
<issue name="TProgressBar.Step">
<short>Progress bar step is not supported</short>
</issue>
<issue name="TPrinter.FileName">
<short>The format of generated file is system dependant</short>
<descr>The content of file created by using this property depends of the printer backend used, for example when using CUPS (mainly under Unix type systems) it will be postscript while under Windows it will be in a printer unspecified format</descr>
</issue>
</widgetset>
</package>

View File

@ -4,5 +4,9 @@
<issue name="TComboBox.DropDownCount">
<short>Combo box DropDownCount property is not supported</short>
</issue>
<issue name="TPrinter.FileName">
<short>The format of generated file is system dependant</short>
<descr>The content of file created by using this property depends of the printer backend used, for example when using CUPS (mainly under Unix type systems) it will be postscript while under Windows it will be in a printer unspecified format</descr>
</issue>
</widgetset>
</package>

View File

@ -4,5 +4,9 @@
<issue name="TComboBox.DropDownCount">
<short>Combo box DropDownCount property is not supported</short>
</issue>
<issue name="TPrinter.FileName">
<short>The format of generated file is system dependant</short>
<descr>The content of file created by using this property depends of the printer backend used, for example when using CUPS (mainly under Unix type systems) it will be postscript while under Windows it will be in a printer unspecified format</descr>
</issue>
</widgetset>
</package>

View File

@ -23,5 +23,9 @@ MSDN Docs: http://msdn2.microsoft.com/en-us/library/bb760816(VS.85).aspx</descr>
<short>Tray icon hint string length is limited</short>
<descr>TTrayIcon.Hint may have a maximum length of 127 WideChars (will usually be more then 127 Bytes in a UTF-8 string, but may be less too, depending on the string). It's a Windows limitation, which can't be worked around.</descr>
</issue>
<issue name="TPrinter.FileName">
<short>The format of generated file is system dependant</short>
<descr>The content of file created by using this property depends of the printer backend used, for example when using CUPS (mainly under Unix type systems) it will be postscript while under Windows it will be in a printer unspecified format</descr>
</issue>
</widgetset>
</package>

View File

@ -160,6 +160,7 @@ type
TPrinter = class(TObject)
private
fCanvas : TCanvas; //Active canvas object
FFileName : string; //Filename for output file
fFonts : TStrings; //Accepted font by printer
fPageNumber : Integer; //Current page number
fPrinters : TStrings; //Printers names list
@ -239,6 +240,7 @@ type
property PrinterState : TPrinterState read DoGetPrinterState;
property Copies : Integer read GetCopies write SetCopies;
property Printers: TStrings read GetPrinters;
property FileName: string read FFileName write FFileName;
property Fonts: TStrings read GetFonts;
property Canvas: TCanvas read GetCanvas;
property PageHeight: Integer read GetPageHeight;