mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-12-06 17:47:26 +01:00
Printers, added test for printing images to selectprinter sample
git-svn-id: trunk@18972 -
This commit is contained in:
parent
5066e9c035
commit
5b8f46539e
@ -3,14 +3,13 @@ object Form1: TForm1
|
||||
Height = 507
|
||||
Top = 142
|
||||
Width = 339
|
||||
HorzScrollBar.Page = 338
|
||||
VertScrollBar.Page = 506
|
||||
ActiveControl = Button2
|
||||
Caption = 'Form1'
|
||||
ClientHeight = 507
|
||||
ClientWidth = 339
|
||||
OnCreate = FormCreate
|
||||
Position = poScreenCenter
|
||||
LCLVersion = '0.9.27'
|
||||
object Label1: TLabel
|
||||
Left = 16
|
||||
Height = 14
|
||||
@ -56,13 +55,9 @@ object Form1: TForm1
|
||||
Width = 230
|
||||
end>
|
||||
DefaultColWidth = 90
|
||||
FixedColor = clBtnFace
|
||||
Flat = True
|
||||
Options = [goFixedVertLine, goFixedHorzLine, goVertLine, goHorzLine, goRangeSelect, goSmoothScroll]
|
||||
RowCount = 15
|
||||
ScrollBars = ssAutoBoth
|
||||
TabOrder = 7
|
||||
TabStop = True
|
||||
end
|
||||
object Button3: TButton
|
||||
Left = 8
|
||||
|
||||
@ -1,42 +1,41 @@
|
||||
{ This is an automatically generated lazarus resource file }
|
||||
|
||||
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'
|
||||
+'idth'#3'S'#1#18'HorzScrollBar.Page'#3'R'#1#18'VertScrollBar.Page'#3#250#1#13
|
||||
+'ActiveControl'#7#7'Button2'#7'Caption'#6#5'Form1'#12'ClientHeight'#3#251#1
|
||||
+#11'ClientWidth'#3'S'#1#8'OnCreate'#7#10'FormCreate'#8'Position'#7#14'poScre'
|
||||
+'enCenter'#0#6'TLabel'#6'Label1'#4'Left'#2#16#6'Height'#2#14#3'Top'#2#8#5'Wi'
|
||||
+'dth'#3#230#0#7'Caption'#6'/This sample 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'To'
|
||||
+'p'#2'3'#5'Width'#3'@'#1#25'BorderSpacing.InnerBorder'#2#4#7'Caption'#6#27'E'
|
||||
+'xecute TPrinterSetupDialog'#7'OnClick'#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'TabOrder'#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#15'AutoFillColumn'
|
||||
+'s'#9#11'BorderStyle'#7#6'bsNone'#8'ColCount'#2#2#7'Columns'#14#1#7'MinSize'
|
||||
+#2'<'#7'MaxSize'#3'^'#1#8'ReadOnly'#9#13'Title.Caption'#6#11'Information'#5
|
||||
+'Width'#3#230#0#0#0#15'DefaultColWidth'#2'Z'#10'FixedColor'#7#9'clBtnFace'#4
|
||||
+'Flat'#9#7'Options'#11#15'goFixedVertLine'#15'goFixedHorzLine'#10'goVertLine'
|
||||
+#10'goHorzLine'#13'goRangeSelect'#14'goSmoothScroll'#0#8'RowCount'#2#15#10'S'
|
||||
+'crollBars'#7#10'ssAutoBoth'#8'TabOrder'#2#7#7'TabStop'#9#0#0#7'TButton'#7'B'
|
||||
+'utton3'#4'Left'#2#8#6'Height'#2#27#3'Top'#2'i'#5'Width'#3'@'#1#25'BorderSpa'
|
||||
+'cing.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#0#1#6
|
||||
+'Height'#2#27#3'Top'#3#155#0#5'Width'#2'E'#25'BorderSpacing.InnerBorder'#2#4
|
||||
+#7'Caption'#6#10'Print test'#7'OnClick'#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
|
||||
+#224#0#25'BorderSpacing.InnerBorder'#2#4#7'Caption'#6#25'Update printer stat'
|
||||
+'e info'#7'OnClick'#7#12'Button5Click'#8'TabOrder'#2#4#0#0#7'TButton'#7'Butt'
|
||||
+'on6'#4'Left'#2#8#6'Height'#2#25#3'Top'#3#157#0#5'Width'#3#224#0#25'BorderSp'
|
||||
+'acing.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'He'
|
||||
+'ight'#2#27#3'Top'#2#24#5'Width'#3'@'#1#25'BorderSpacing.InnerBorder'#2#4#7
|
||||
+'Caption'#6#24'Execute TPageSetupDialog'#7'OnClick'#7#12'Button7Click'#8'Tab'
|
||||
+'Order'#2#6#0#0#19'TPrinterSetupDialog'#3'PSD'#5'Title'#6#20'Testing 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'poSelectio'
|
||||
+'n'#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
|
||||
+'idth'#3'S'#1#13'ActiveControl'#7#7'Button2'#7'Caption'#6#5'Form1'#12'Client'
|
||||
+'Height'#3#251#1#11'ClientWidth'#3'S'#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#14#3'Top'#2#8#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'@'#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#15'AutoFillColumns'#9#11'BorderStyle'#7#6'bsNone'#8'C'
|
||||
+'olCount'#2#2#7'Columns'#14#1#7'MinSize'#2'<'#7'MaxSize'#3'^'#1#8'ReadOnly'#9
|
||||
+#13'Title.Caption'#6#11'Information'#5'Width'#3#230#0#0#0#15'DefaultColWidth'
|
||||
+#2'Z'#4'Flat'#9#8'RowCount'#2#15#8'TabOrder'#2#7#0#0#7'TButton'#7'Button3'#4
|
||||
+'Left'#2#8#6'Height'#2#27#3'Top'#2'i'#5'Width'#3'@'#1#25'BorderSpacing.Inner'
|
||||
+'Border'#2#4#7'Caption'#6#24'Get default printer info'#7'OnClick'#7#12'Butto'
|
||||
+'n3Click'#8'TabOrder'#2#2#0#0#7'TButton'#7'Button4'#4'Left'#3#0#1#6'Height'#2
|
||||
+#27#3'Top'#3#155#0#5'Width'#2'E'#25'BorderSpacing.InnerBorder'#2#4#7'Caption'
|
||||
+#6#10'Print test'#7'OnClick'#7#12'Button4Click'#8'TabOrder'#2#3#0#0#7'TButto'
|
||||
+'n'#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'Caption'#6#25'Update printer state info'#7
|
||||
+'OnClick'#7#12'Button5Click'#8'TabOrder'#2#4#0#0#7'TButton'#7'Button6'#4'Lef'
|
||||
+'t'#2#8#6'Height'#2#25#3'Top'#3#157#0#5'Width'#3#224#0#25'BorderSpacing.Inne'
|
||||
+'rBorder'#2#4#7'Caption'#6#23'Show printer properties'#7'OnClick'#7#12'Butto'
|
||||
+'n6Click'#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'@'#1#25'BorderSpacing.InnerBorder'#2#4#7'Caption'
|
||||
+#6#24'Execute TPageSetupDialog'#7'OnClick'#7#12'Button7Click'#8'TabOrder'#2#6
|
||||
+#0#0#19'TPrinterSetupDialog'#3'PSD'#5'Title'#6#20'Testing dialog title'#4'le'
|
||||
+'ft'#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'poWarn'
|
||||
+'ing'#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'T'
|
||||
+'PageSetupDialog'#5'PAGED'#5'Title'#6#25'Ustawienie strony raportu'#4'left'#3
|
||||
+#176#0#3'top'#3'0'#1#0#0#0
|
||||
]);
|
||||
|
||||
@ -57,6 +57,11 @@ type
|
||||
ck : Integer;
|
||||
procedure UpdatePrinterInfo;
|
||||
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 declarations }
|
||||
@ -78,6 +83,55 @@ begin
|
||||
Inc(ck);
|
||||
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;
|
||||
begin
|
||||
try
|
||||
@ -139,14 +193,49 @@ begin
|
||||
end;
|
||||
|
||||
procedure TForm1.Button4Click(Sender: TObject);
|
||||
var
|
||||
Pic: TPicture;
|
||||
pgw,pgh: Integer;
|
||||
Hin: Integer; // half inch
|
||||
begin
|
||||
try
|
||||
Printer.Title := 'Printer test for printers4lazarus package';
|
||||
Printer.BeginDoc;
|
||||
// first page reserved for
|
||||
Printer.Canvas.Font.Color:= clBlue;
|
||||
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;
|
||||
|
||||
except
|
||||
on E:Exception do
|
||||
begin
|
||||
|
||||
@ -2,21 +2,20 @@
|
||||
<CONFIG>
|
||||
<ProjectOptions>
|
||||
<PathDelim Value="\"/>
|
||||
<Version Value="6"/>
|
||||
<Version Value="7"/>
|
||||
<General>
|
||||
<Flags>
|
||||
<SaveClosedFiles Value="False"/>
|
||||
<SaveOnlyProjectUnits Value="True"/>
|
||||
<LRSInOutputDirectory Value="False"/>
|
||||
</Flags>
|
||||
<SessionStorage Value="InProjectDir"/>
|
||||
<MainUnit Value="0"/>
|
||||
<IconPath Value=".\"/>
|
||||
<TargetFileExt Value=".exe"/>
|
||||
<Title Value="selectprinter"/>
|
||||
</General>
|
||||
<PublishOptions>
|
||||
<Version Value="2"/>
|
||||
<DestinationDirectory Value="$(TestDir)\publishedproject\"/>
|
||||
<IgnoreBinaries Value="False"/>
|
||||
<IncludeFileFilter Value="*.(pas|pp|inc|lfm|lpr|lrs|lpi|lpk|sh|xml)"/>
|
||||
<ExcludeFileFilter Value="*.(bak|ppu|ppw|o|so);*~;backup"/>
|
||||
@ -36,7 +35,7 @@
|
||||
<MinVersion Build="1" Valid="True"/>
|
||||
</Item2>
|
||||
</RequiredPackages>
|
||||
<Units Count="2">
|
||||
<Units Count="4">
|
||||
<Unit0>
|
||||
<Filename Value="selectprinter.lpr"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
@ -46,21 +45,29 @@
|
||||
<Filename Value="frmselprinter.pas"/>
|
||||
<ComponentName Value="Form1"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
<ResourceFilename Value="frmselprinter.lrs"/>
|
||||
<ResourceBaseClass Value="Form"/>
|
||||
<UnitName Value="frmselprinter"/>
|
||||
</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>
|
||||
</ProjectOptions>
|
||||
<CompilerOptions>
|
||||
<Version Value="5"/>
|
||||
<Version Value="8"/>
|
||||
<PathDelim Value="\"/>
|
||||
<SearchPaths>
|
||||
<SrcPath Value="$(LazarusDir)\lcl\;$(LazarusDir)\lcl\interfaces\$(LCLWidgetType)\"/>
|
||||
</SearchPaths>
|
||||
<Parsing>
|
||||
<SyntaxOptions>
|
||||
<SyntaxMode Value="Delphi"/>
|
||||
<IncludeAssertionCode Value="True"/>
|
||||
<DelphiCompat Value="True"/>
|
||||
<UseAnsiStrings Value="True"/>
|
||||
</SyntaxOptions>
|
||||
</Parsing>
|
||||
@ -70,7 +77,6 @@
|
||||
<RangeChecks Value="True"/>
|
||||
<OverflowChecks Value="True"/>
|
||||
</Checks>
|
||||
<Generate Value="Faster"/>
|
||||
</CodeGeneration>
|
||||
<Linking>
|
||||
<Debugging>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user