Printers, added test for printing images to selectprinter sample

git-svn-id: trunk@18972 -
This commit is contained in:
jesus 2009-03-12 22:18:27 +00:00
parent 5066e9c035
commit 5b8f46539e
4 changed files with 143 additions and 54 deletions

View File

@ -3,14 +3,13 @@ object Form1: TForm1
Height = 507 Height = 507
Top = 142 Top = 142
Width = 339 Width = 339
HorzScrollBar.Page = 338
VertScrollBar.Page = 506
ActiveControl = Button2 ActiveControl = Button2
Caption = 'Form1' Caption = 'Form1'
ClientHeight = 507 ClientHeight = 507
ClientWidth = 339 ClientWidth = 339
OnCreate = FormCreate OnCreate = FormCreate
Position = poScreenCenter Position = poScreenCenter
LCLVersion = '0.9.27'
object Label1: TLabel object Label1: TLabel
Left = 16 Left = 16
Height = 14 Height = 14
@ -56,13 +55,9 @@ object Form1: TForm1
Width = 230 Width = 230
end> end>
DefaultColWidth = 90 DefaultColWidth = 90
FixedColor = clBtnFace
Flat = True Flat = True
Options = [goFixedVertLine, goFixedHorzLine, goVertLine, goHorzLine, goRangeSelect, goSmoothScroll]
RowCount = 15 RowCount = 15
ScrollBars = ssAutoBoth
TabOrder = 7 TabOrder = 7
TabStop = True
end end
object Button3: TButton object Button3: TButton
Left = 8 Left = 8

View File

@ -1,42 +1,41 @@
{ This is an automatically generated lazarus resource file }
LazarusResources.Add('TForm1','FORMDATA',[ LazarusResources.Add('TForm1','FORMDATA',[
'TPF0'#6'TForm1'#5'Form1'#4'Left'#3' '#1#6'Height'#3#251#1#3'Top'#3#142#0#5'W' 'TPF0'#6'TForm1'#5'Form1'#4'Left'#3' '#1#6'Height'#3#251#1#3'Top'#3#142#0#5'W'
+'idth'#3'S'#1#18'HorzScrollBar.Page'#3'R'#1#18'VertScrollBar.Page'#3#250#1#13 +'idth'#3'S'#1#13'ActiveControl'#7#7'Button2'#7'Caption'#6#5'Form1'#12'Client'
+'ActiveControl'#7#7'Button2'#7'Caption'#6#5'Form1'#12'ClientHeight'#3#251#1 +'Height'#3#251#1#11'ClientWidth'#3'S'#1#8'OnCreate'#7#10'FormCreate'#8'Posit'
+#11'ClientWidth'#3'S'#1#8'OnCreate'#7#10'FormCreate'#8'Position'#7#14'poScre' +'ion'#7#14'poScreenCenter'#10'LCLVersion'#6#6'0.9.27'#0#6'TLabel'#6'Label1'#4
+'enCenter'#0#6'TLabel'#6'Label1'#4'Left'#2#16#6'Height'#2#14#3'Top'#2#8#5'Wi' +'Left'#2#16#6'Height'#2#14#3'Top'#2#8#5'Width'#3#230#0#7'Caption'#6'/This sa'
+'dth'#3#230#0#7'Caption'#6'/This sample show how to use the printer dialogs' +'mple show how to use the printer dialogs'#11'ParentColor'#8#0#0#7'TButton'#7
+#11'ParentColor'#8#0#0#7'TButton'#7'Button2'#4'Left'#2#8#6'Height'#2#27#3'To' +'Button2'#4'Left'#2#8#6'Height'#2#27#3'Top'#2'3'#5'Width'#3'@'#1#25'BorderSp'
+'p'#2'3'#5'Width'#3'@'#1#25'BorderSpacing.InnerBorder'#2#4#7'Caption'#6#27'E' +'acing.InnerBorder'#2#4#7'Caption'#6#27'Execute TPrinterSetupDialog'#7'OnCli'
+'xecute TPrinterSetupDialog'#7'OnClick'#7#12'Button2Click'#8'TabOrder'#2#0#0 +'ck'#7#12'Button2Click'#8'TabOrder'#2#0#0#0#7'TButton'#7'Button1'#4'Left'#2#8
+#0#7'TButton'#7'Button1'#4'Left'#2#8#6'Height'#2#27#3'Top'#2'N'#5'Width'#3'@' +#6'Height'#2#27#3'Top'#2'N'#5'Width'#3'@'#1#25'BorderSpacing.InnerBorder'#2#4
+#1#25'BorderSpacing.InnerBorder'#2#4#7'Caption'#6#20'Execute TPrintDialog'#7 +#7'Caption'#6#20'Execute TPrintDialog'#7'OnClick'#7#12'Button1Click'#8'TabOr'
+'OnClick'#7#12'Button1Click'#8'TabOrder'#2#1#0#0#11'TStringGrid'#5'SGrid'#4 +'der'#2#1#0#0#11'TStringGrid'#5'SGrid'#4'Left'#2#8#6'Height'#3'0'#1#3'Top'#3
+'Left'#2#8#6'Height'#3'0'#1#3'Top'#3#192#0#5'Width'#3'@'#1#15'AutoFillColumn' +#192#0#5'Width'#3'@'#1#15'AutoFillColumns'#9#11'BorderStyle'#7#6'bsNone'#8'C'
+'s'#9#11'BorderStyle'#7#6'bsNone'#8'ColCount'#2#2#7'Columns'#14#1#7'MinSize' +'olCount'#2#2#7'Columns'#14#1#7'MinSize'#2'<'#7'MaxSize'#3'^'#1#8'ReadOnly'#9
+#2'<'#7'MaxSize'#3'^'#1#8'ReadOnly'#9#13'Title.Caption'#6#11'Information'#5 +#13'Title.Caption'#6#11'Information'#5'Width'#3#230#0#0#0#15'DefaultColWidth'
+'Width'#3#230#0#0#0#15'DefaultColWidth'#2'Z'#10'FixedColor'#7#9'clBtnFace'#4 +#2'Z'#4'Flat'#9#8'RowCount'#2#15#8'TabOrder'#2#7#0#0#7'TButton'#7'Button3'#4
+'Flat'#9#7'Options'#11#15'goFixedVertLine'#15'goFixedHorzLine'#10'goVertLine' +'Left'#2#8#6'Height'#2#27#3'Top'#2'i'#5'Width'#3'@'#1#25'BorderSpacing.Inner'
+#10'goHorzLine'#13'goRangeSelect'#14'goSmoothScroll'#0#8'RowCount'#2#15#10'S' +'Border'#2#4#7'Caption'#6#24'Get default printer info'#7'OnClick'#7#12'Butto'
+'crollBars'#7#10'ssAutoBoth'#8'TabOrder'#2#7#7'TabStop'#9#0#0#7'TButton'#7'B' +'n3Click'#8'TabOrder'#2#2#0#0#7'TButton'#7'Button4'#4'Left'#3#0#1#6'Height'#2
+'utton3'#4'Left'#2#8#6'Height'#2#27#3'Top'#2'i'#5'Width'#3'@'#1#25'BorderSpa' +#27#3'Top'#3#155#0#5'Width'#2'E'#25'BorderSpacing.InnerBorder'#2#4#7'Caption'
+'cing.InnerBorder'#2#4#7'Caption'#6#24'Get default printer info'#7'OnClick'#7 +#6#10'Print test'#7'OnClick'#7#12'Button4Click'#8'TabOrder'#2#3#0#0#7'TButto'
+#12'Button3Click'#8'TabOrder'#2#2#0#0#7'TButton'#7'Button4'#4'Left'#3#0#1#6 +'n'#7'Button5'#4'Left'#2#8#6'Height'#2#25#3'Top'#3#132#0#5'Width'#3#224#0#25
+'Height'#2#27#3'Top'#3#155#0#5'Width'#2'E'#25'BorderSpacing.InnerBorder'#2#4 +'BorderSpacing.InnerBorder'#2#4#7'Caption'#6#25'Update printer state info'#7
+#7'Caption'#6#10'Print test'#7'OnClick'#7#12'Button4Click'#8'TabOrder'#2#3#0 +'OnClick'#7#12'Button5Click'#8'TabOrder'#2#4#0#0#7'TButton'#7'Button6'#4'Lef'
+#0#7'TButton'#7'Button5'#4'Left'#2#8#6'Height'#2#25#3'Top'#3#132#0#5'Width'#3 +'t'#2#8#6'Height'#2#25#3'Top'#3#157#0#5'Width'#3#224#0#25'BorderSpacing.Inne'
+#224#0#25'BorderSpacing.InnerBorder'#2#4#7'Caption'#6#25'Update printer stat' +'rBorder'#2#4#7'Caption'#6#23'Show printer properties'#7'OnClick'#7#12'Butto'
+'e info'#7'OnClick'#7#12'Button5Click'#8'TabOrder'#2#4#0#0#7'TButton'#7'Butt' +'n6Click'#8'TabOrder'#2#5#0#0#7'TButton'#7'Button7'#4'Left'#2#8#6'Height'#2
+'on6'#4'Left'#2#8#6'Height'#2#25#3'Top'#3#157#0#5'Width'#3#224#0#25'BorderSp' +#27#3'Top'#2#24#5'Width'#3'@'#1#25'BorderSpacing.InnerBorder'#2#4#7'Caption'
+'acing.InnerBorder'#2#4#7'Caption'#6#23'Show printer properties'#7'OnClick'#7 +#6#24'Execute TPageSetupDialog'#7'OnClick'#7#12'Button7Click'#8'TabOrder'#2#6
+#12'Button6Click'#8'TabOrder'#2#5#0#0#7'TButton'#7'Button7'#4'Left'#2#8#6'He' +#0#0#19'TPrinterSetupDialog'#3'PSD'#5'Title'#6#20'Testing dialog title'#4'le'
+'ight'#2#27#3'Top'#2#24#5'Width'#3'@'#1#25'BorderSpacing.InnerBorder'#2#4#7 +'ft'#3#176#0#3'top'#3#240#0#0#0#12'TPrintDialog'#2'PD'#5'Title'#6#13'Testing'
+'Caption'#6#24'Execute TPageSetupDialog'#7'OnClick'#7#12'Button7Click'#8'Tab' +' title'#7'Collate'#9#6'Copies'#2#1#8'FromPage'#2#2#7'MinPage'#2#2#7'MaxPage'
+'Order'#2#6#0#0#19'TPrinterSetupDialog'#3'PSD'#5'Title'#6#20'Testing dialog ' +#2#5#7'Options'#11#13'poPrintToFile'#10'poPageNums'#11'poSelection'#9'poWarn'
+'title'#4'left'#3#176#0#3'top'#3#240#0#0#0#12'TPrintDialog'#2'PD'#5'Title'#6 +'ing'#6'poHelp'#0#11'PrintToFile'#9#6'ToPage'#2#3#4'left'#3#176#0#3'top'#3#16
+#13'Testing title'#7'Collate'#9#6'Copies'#2#1#8'FromPage'#2#2#7'MinPage'#2#2 +#1#0#0#10'TPopupMenu'#10'PopupMenu1'#4'left'#3#216#0#3'top'#3#240#0#0#0#16'T'
+#7'MaxPage'#2#5#7'Options'#11#13'poPrintToFile'#10'poPageNums'#11'poSelectio' +'PageSetupDialog'#5'PAGED'#5'Title'#6#25'Ustawienie strony raportu'#4'left'#3
+'n'#9'poWarning'#6'poHelp'#0#11'PrintToFile'#9#6'ToPage'#2#3#4'left'#3#176#0 +#176#0#3'top'#3'0'#1#0#0#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

@ -57,6 +57,11 @@ type
ck : Integer; ck : Integer;
procedure UpdatePrinterInfo; procedure UpdatePrinterInfo;
procedure AddInfo(const Desc : String; Const Info : String); procedure AddInfo(const Desc : String; Const Info : String);
procedure DrawGraphic(X,Y,AWidth,AHeight:Integer; Graphic: TGraphic);
function CM(Avalue: Double; VertRes:boolean=true): Integer;
function MM(AValue: Double; VertRes:boolean=true): Integer;
function Inch(AValue: Double; VertRes:boolean=true): Integer;
function Per(AValue: Double; VertRes:boolean=true): Integer;
public public
{ public declarations } { public declarations }
@ -78,6 +83,55 @@ begin
Inc(ck); Inc(ck);
end; end;
procedure TForm1.DrawGraphic(X, Y, AWidth, Aheight: Integer; Graphic: TGraphic);
var
Ratio: Double;
begin
if (AWidth<=0) or (AHeight<=0) then begin
if Graphic.Height=0 then
ratio := 1
else
ratio := Graphic.Height/Graphic.Width;
if AWidth<=0 then
AWidth := round(AHeight/ratio)
else
if AHeight<=0 then
AHeight := round(AWidth * ratio);
end;
if (AWidth>0) and (AHeight>0) then
Printer.Canvas.StretchDraw(Bounds(X,Y,AWidth,AHeight), Graphic);
end;
function TForm1.CM(Avalue: Double; VertRes: boolean=true): Integer;
begin
result := MM(AValue*10, vertRes);
end;
function TForm1.MM(AValue: Double; VertRes:boolean=true): Integer;
begin
if VertRes then
result := Round(AValue*Printer.YDPI/25.4)
else
result := Round(AValue*Printer.XDPI/25.4);
end;
function TForm1.Inch(AValue: Double; VertRes:boolean=true): Integer;
begin
if VertRes then
result := Round(AValue*Printer.YDPI)
else
result := Round(AValue*Printer.XDPI);
end;
function TForm1.Per(AValue: Double; VertRes:boolean=true): Integer;
begin
if VertRes then
result := Round(AValue*Printer.PageHeight/100)
else
result := Round(AValue*Printer.PageWidth/100);
end;
procedure TForm1.UpdatePrinterInfo; procedure TForm1.UpdatePrinterInfo;
begin begin
try try
@ -139,14 +193,49 @@ begin
end; end;
procedure TForm1.Button4Click(Sender: TObject); procedure TForm1.Button4Click(Sender: TObject);
var
Pic: TPicture;
pgw,pgh: Integer;
Hin: Integer; // half inch
begin begin
try try
Printer.Title := 'Printer test for printers4lazarus package'; Printer.Title := 'Printer test for printers4lazarus package';
Printer.BeginDoc; Printer.BeginDoc;
// first page reserved for
Printer.Canvas.Font.Color:= clBlue; Printer.Canvas.Font.Color:= clBlue;
Printer.Canvas.Font.Size := 12; Printer.Canvas.Font.Size := 12;
Printer.Canvas.TextOut(0,0,'This is test for lazarus printer4lazarus package'); Printer.Canvas.TextOut(CM(0.5),CM(0.5),
'This is test for lazarus printer4lazarus package');
// some often used consts
pgw := Printer.PageWidth-1;
pgh := Printer.PageHeight-1;
Hin := Inch(0.5);
// print margins marks, assumes XRes=YRes
Printer.Canvas.Pen.Color:=clBlack;
Printer.Canvas.Line(0, HIn, 0, 0); // top-left
Printer.Canvas.Line(0, 0, HIn, 0);
Printer.Canvas.Line(0, pgh-HIn, 0, pgh); // bottom-left
Printer.Canvas.Line(0, pgh, HIn, pgh);
Printer.Canvas.Line(pgw-Hin, pgh, pgw, pgh); // bottom-right
Printer.Canvas.Line(pgw,pgh,pgw,pgh-HIn);
Printer.Canvas.Line(pgw-Hin, 0, pgw, 0); // top-right
Printer.Canvas.Line(pgw,0,pgw,HIn);
// Image test
Pic := TPicture.Create;
Pic.LoadFromFile('../../../../images/splash_logo.png');
// draw logo scaled down to 7 centimeters wide preserving image aspect
DrawGraphic(CM(1.5), CM(1.5), MM(70), 0, Pic.Graphic);
// left 3 mm at the right and do it again but using 2 inch tall image
DrawGraphic(CM(1.5+7)+MM(3), CM(1.5), 0, Inch(2), Pic.Graphic);
Pic.Free;
Printer.EndDoc; Printer.EndDoc;
except except
on E:Exception do on E:Exception do
begin begin

View File

@ -2,21 +2,20 @@
<CONFIG> <CONFIG>
<ProjectOptions> <ProjectOptions>
<PathDelim Value="\"/> <PathDelim Value="\"/>
<Version Value="6"/> <Version Value="7"/>
<General> <General>
<Flags> <Flags>
<SaveClosedFiles Value="False"/> <SaveClosedFiles Value="False"/>
<SaveOnlyProjectUnits Value="True"/> <SaveOnlyProjectUnits Value="True"/>
<LRSInOutputDirectory Value="False"/>
</Flags> </Flags>
<SessionStorage Value="InProjectDir"/> <SessionStorage Value="InProjectDir"/>
<MainUnit Value="0"/> <MainUnit Value="0"/>
<IconPath Value=".\"/>
<TargetFileExt Value=".exe"/> <TargetFileExt Value=".exe"/>
<Title Value="selectprinter"/> <Title Value="selectprinter"/>
</General> </General>
<PublishOptions> <PublishOptions>
<Version Value="2"/> <Version Value="2"/>
<DestinationDirectory Value="$(TestDir)\publishedproject\"/>
<IgnoreBinaries Value="False"/> <IgnoreBinaries Value="False"/>
<IncludeFileFilter Value="*.(pas|pp|inc|lfm|lpr|lrs|lpi|lpk|sh|xml)"/> <IncludeFileFilter Value="*.(pas|pp|inc|lfm|lpr|lrs|lpi|lpk|sh|xml)"/>
<ExcludeFileFilter Value="*.(bak|ppu|ppw|o|so);*~;backup"/> <ExcludeFileFilter Value="*.(bak|ppu|ppw|o|so);*~;backup"/>
@ -36,7 +35,7 @@
<MinVersion Build="1" Valid="True"/> <MinVersion Build="1" Valid="True"/>
</Item2> </Item2>
</RequiredPackages> </RequiredPackages>
<Units Count="2"> <Units Count="4">
<Unit0> <Unit0>
<Filename Value="selectprinter.lpr"/> <Filename Value="selectprinter.lpr"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
@ -46,21 +45,29 @@
<Filename Value="frmselprinter.pas"/> <Filename Value="frmselprinter.pas"/>
<ComponentName Value="Form1"/> <ComponentName Value="Form1"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
<ResourceFilename Value="frmselprinter.lrs"/> <ResourceBaseClass Value="Form"/>
<UnitName Value="frmselprinter"/> <UnitName Value="frmselprinter"/>
</Unit1> </Unit1>
<Unit2>
<Filename Value="..\..\..\..\..\..\..\lazarus\components\PRINTERS\WIN32\winprndialogs.inc"/>
<IsPartOfProject Value="True"/>
</Unit2>
<Unit3>
<Filename Value="..\..\..\..\..\..\..\lazarus\components\PRINTERS\LINUX\cupsprndialogs.inc"/>
<IsPartOfProject Value="True"/>
</Unit3>
</Units> </Units>
</ProjectOptions> </ProjectOptions>
<CompilerOptions> <CompilerOptions>
<Version Value="5"/> <Version Value="8"/>
<PathDelim Value="\"/> <PathDelim Value="\"/>
<SearchPaths> <SearchPaths>
<SrcPath Value="$(LazarusDir)\lcl\;$(LazarusDir)\lcl\interfaces\$(LCLWidgetType)\"/> <SrcPath Value="$(LazarusDir)\lcl\;$(LazarusDir)\lcl\interfaces\$(LCLWidgetType)\"/>
</SearchPaths> </SearchPaths>
<Parsing> <Parsing>
<SyntaxOptions> <SyntaxOptions>
<SyntaxMode Value="Delphi"/>
<IncludeAssertionCode Value="True"/> <IncludeAssertionCode Value="True"/>
<DelphiCompat Value="True"/>
<UseAnsiStrings Value="True"/> <UseAnsiStrings Value="True"/>
</SyntaxOptions> </SyntaxOptions>
</Parsing> </Parsing>
@ -70,7 +77,6 @@
<RangeChecks Value="True"/> <RangeChecks Value="True"/>
<OverflowChecks Value="True"/> <OverflowChecks Value="True"/>
</Checks> </Checks>
<Generate Value="Faster"/>
</CodeGeneration> </CodeGeneration>
<Linking> <Linking>
<Debugging> <Debugging>