mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-12-03 06:58:53 +01:00
Printers, updated rawmode test
git-svn-id: trunk@26978 -
This commit is contained in:
parent
1bafc6648c
commit
d974b14966
1
.gitattributes
vendored
1
.gitattributes
vendored
@ -1735,7 +1735,6 @@ components/printers/samples/dialogs/selectprinter.lpr svneol=native#text/pascal
|
||||
components/printers/samples/rawmode/rawmodetest.lpi svneol=native#text/plain
|
||||
components/printers/samples/rawmode/rawmodetest.lpr svneol=native#text/pascal
|
||||
components/printers/samples/rawmode/unitmain.lfm svneol=native#text/plain
|
||||
components/printers/samples/rawmode/unitmain.lrs svneol=native#text/pascal
|
||||
components/printers/samples/rawmode/unitmain.pas svneol=native#text/pascal
|
||||
components/printers/unix/cupsdyn.pp svneol=native#text/pascal
|
||||
components/printers/unix/cupslcl.pas svneol=native#text/plain
|
||||
|
||||
@ -1,20 +1,19 @@
|
||||
<?xml version="1.0"?>
|
||||
<CONFIG>
|
||||
<ProjectOptions>
|
||||
<PathDelim Value="/"/>
|
||||
<Version Value="5"/>
|
||||
<Version Value="8"/>
|
||||
<General>
|
||||
<Flags>
|
||||
<SaveClosedFiles Value="False"/>
|
||||
<SaveOnlyProjectUnits Value="True"/>
|
||||
<LRSInOutputDirectory Value="False"/>
|
||||
</Flags>
|
||||
<MainUnit Value="0"/>
|
||||
<IconPath Value="./"/>
|
||||
<TargetFileExt Value=".exe"/>
|
||||
<ActiveEditorIndexAtStart Value="1"/>
|
||||
<ActiveWindowIndexAtStart Value="0"/>
|
||||
</General>
|
||||
<VersionInfo>
|
||||
<ProjectVersion Value=""/>
|
||||
<StringTable Comments="" CompanyName="" FileDescription="" FileVersion="0.0.0.0" InternalName="" LegalCopyright="" LegalTrademarks="" OriginalFilename="" ProductName="" ProductVersion=""/>
|
||||
</VersionInfo>
|
||||
<PublishOptions>
|
||||
<Version Value="2"/>
|
||||
@ -41,32 +40,37 @@
|
||||
<Filename Value="rawmodetest.lpr"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
<UnitName Value="rawmodetest"/>
|
||||
<CursorPos X="40" Y="17"/>
|
||||
<TopLine Value="1"/>
|
||||
<UsageCount Value="21"/>
|
||||
<CursorPos X="40" Y="17"/>
|
||||
<UsageCount Value="23"/>
|
||||
</Unit0>
|
||||
<Unit1>
|
||||
<Filename Value="unitmain.pas"/>
|
||||
<ComponentName Value="Form1"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
<ResourceFilename Value="unitmain.lrs"/>
|
||||
<ComponentName Value="Form1"/>
|
||||
<ResourceBaseClass Value="Form"/>
|
||||
<UnitName Value="unitmain"/>
|
||||
<CursorPos X="21" Y="54"/>
|
||||
<TopLine Value="3"/>
|
||||
<IsVisibleTab Value="True"/>
|
||||
<EditorIndex Value="0"/>
|
||||
<UsageCount Value="21"/>
|
||||
<WindowIndex Value="0"/>
|
||||
<TopLine Value="74"/>
|
||||
<CursorPos X="30" Y="91"/>
|
||||
<UsageCount Value="23"/>
|
||||
<Loaded Value="True"/>
|
||||
<LoadedDesigner Value="True"/>
|
||||
</Unit1>
|
||||
</Units>
|
||||
</ProjectOptions>
|
||||
<CompilerOptions>
|
||||
<Version Value="5"/>
|
||||
<Version Value="9"/>
|
||||
<SearchPaths>
|
||||
<SrcPath Value="$(LazarusDir)/lcl/;$(LazarusDir)/lcl/interfaces/$(LCLWidgetType)/"/>
|
||||
</SearchPaths>
|
||||
<CodeGeneration>
|
||||
<Generate Value="Faster"/>
|
||||
</CodeGeneration>
|
||||
<Parsing>
|
||||
<SyntaxOptions>
|
||||
<UseAnsiStrings Value="False"/>
|
||||
</SyntaxOptions>
|
||||
</Parsing>
|
||||
<Linking>
|
||||
<Options>
|
||||
<Win32>
|
||||
|
||||
@ -1,39 +1,39 @@
|
||||
object Form1: TForm1
|
||||
Left = 265
|
||||
Height = 302
|
||||
Height = 356
|
||||
Top = 181
|
||||
Width = 428
|
||||
Width = 452
|
||||
HorzScrollBar.Page = 427
|
||||
VertScrollBar.Page = 301
|
||||
ActiveControl = ListBox1
|
||||
Caption = 'RawMode Print Test'
|
||||
ClientHeight = 302
|
||||
ClientWidth = 428
|
||||
ClientHeight = 356
|
||||
ClientWidth = 452
|
||||
Constraints.MaxHeight = 400
|
||||
Constraints.MinHeight = 240
|
||||
OnCreate = FormCreate
|
||||
LCLVersion = '0.9.29'
|
||||
object Label1: TLabel
|
||||
Left = 15
|
||||
Height = 13
|
||||
Height = 14
|
||||
Top = 5
|
||||
Width = 69
|
||||
Width = 61
|
||||
Caption = 'Printers List:'
|
||||
ParentColor = False
|
||||
end
|
||||
object Label2: TLabel
|
||||
Left = 11
|
||||
Height = 13
|
||||
Height = 14
|
||||
Top = 150
|
||||
Width = 78
|
||||
Caption = 'String to print:'
|
||||
Width = 65
|
||||
Caption = 'Text to print:'
|
||||
ParentColor = False
|
||||
end
|
||||
object Label3: TLabel
|
||||
Left = 96
|
||||
Height = 80
|
||||
Top = 204
|
||||
Width = 320
|
||||
Anchors = [akTop, akLeft, akRight, akBottom]
|
||||
Left = 98
|
||||
Height = 60
|
||||
Top = 286
|
||||
Width = 344
|
||||
Anchors = [akLeft, akRight, akBottom]
|
||||
AutoSize = False
|
||||
Caption = 'NOTE: This sample is meant to sent an alphanumeric string to a Dot-Matrix class printer which doesn''t need special codes to start printing. Label, LaserJet or DeskJet printers might need'#10'some special prefix codes to work correctly.'
|
||||
ParentColor = False
|
||||
@ -43,27 +43,37 @@ object Form1: TForm1
|
||||
Left = 11
|
||||
Height = 115
|
||||
Top = 25
|
||||
Width = 406
|
||||
Width = 430
|
||||
Anchors = [akTop, akLeft, akRight]
|
||||
ItemHeight = 0
|
||||
TabOrder = 0
|
||||
TopIndex = -1
|
||||
end
|
||||
object Button1: TButton
|
||||
Left = 11
|
||||
Height = 25
|
||||
Top = 205
|
||||
Top = 321
|
||||
Width = 75
|
||||
Anchors = [akLeft, akBottom]
|
||||
BorderSpacing.InnerBorder = 4
|
||||
Caption = 'Print'
|
||||
OnClick = Button1Click
|
||||
TabOrder = 1
|
||||
end
|
||||
object Edit1: TEdit
|
||||
object Memo1: TMemo
|
||||
Left = 11
|
||||
Height = 23
|
||||
Top = 170
|
||||
Width = 405
|
||||
Anchors = [akTop, akLeft, akRight]
|
||||
Height = 112
|
||||
Top = 168
|
||||
Width = 430
|
||||
Anchors = [akTop, akLeft, akRight, akBottom]
|
||||
Lines.Strings = (
|
||||
''
|
||||
'H E L L O'
|
||||
''
|
||||
'Sending raw data to attached printer'
|
||||
'is very easy with Printer.RawMode'
|
||||
''
|
||||
'And it''s portable!'
|
||||
)
|
||||
TabOrder = 2
|
||||
end
|
||||
end
|
||||
|
||||
@ -1,25 +0,0 @@
|
||||
{ This is an automatically generated lazarus resource file }
|
||||
|
||||
LazarusResources.Add('TForm1','FORMDATA',[
|
||||
'TPF0'#6'TForm1'#5'Form1'#4'Left'#3#9#1#6'Height'#3'.'#1#3'Top'#3#181#0#5'Wid'
|
||||
+'th'#3#172#1#18'HorzScrollBar.Page'#3#171#1#18'VertScrollBar.Page'#3'-'#1#13
|
||||
+'ActiveControl'#7#8'ListBox1'#7'Caption'#6#18'RawMode Print Test'#12'ClientH'
|
||||
+'eight'#3'.'#1#11'ClientWidth'#3#172#1#21'Constraints.MaxHeight'#3#144#1#21
|
||||
+'Constraints.MinHeight'#3#240#0#8'OnCreate'#7#10'FormCreate'#0#6'TLabel'#6'L'
|
||||
+'abel1'#4'Left'#2#15#6'Height'#2#13#3'Top'#2#5#5'Width'#2'E'#7'Caption'#6#14
|
||||
+'Printers List:'#11'ParentColor'#8#0#0#6'TLabel'#6'Label2'#4'Left'#2#11#6'He'
|
||||
+'ight'#2#13#3'Top'#3#150#0#5'Width'#2'N'#7'Caption'#6#16'String to print:'#11
|
||||
+'ParentColor'#8#0#0#6'TLabel'#6'Label3'#4'Left'#2'`'#6'Height'#2'P'#3'Top'#3
|
||||
+#204#0#5'Width'#3'@'#1#7'Anchors'#11#5'akTop'#6'akLeft'#7'akRight'#8'akBotto'
|
||||
+'m'#0#8'AutoSize'#8#7'Caption'#6#231'NOTE: This sample is meant to sent an a'
|
||||
+'lphanumeric string to a Dot-Matrix class printer which doesn''t need specia'
|
||||
+'l codes to start printing. Label, LaserJet or DeskJet printers might need'
|
||||
+#10'some special prefix codes to work correctly.'#11'ParentColor'#8#8'WordWr'
|
||||
+'ap'#9#0#0#8'TListBox'#8'ListBox1'#4'Left'#2#11#6'Height'#2's'#3'Top'#2#25#5
|
||||
+'Width'#3#150#1#7'Anchors'#11#5'akTop'#6'akLeft'#7'akRight'#0#8'TabOrder'#2#0
|
||||
+#8'TopIndex'#2#255#0#0#7'TButton'#7'Button1'#4'Left'#2#11#6'Height'#2#25#3'T'
|
||||
+'op'#3#205#0#5'Width'#2'K'#25'BorderSpacing.InnerBorder'#2#4#7'Caption'#6#5
|
||||
+'Print'#7'OnClick'#7#12'Button1Click'#8'TabOrder'#2#1#0#0#5'TEdit'#5'Edit1'#4
|
||||
+'Left'#2#11#6'Height'#2#23#3'Top'#3#170#0#5'Width'#3#149#1#7'Anchors'#11#5'a'
|
||||
+'kTop'#6'akLeft'#7'akRight'#0#8'TabOrder'#2#2#0#0#0
|
||||
]);
|
||||
@ -14,15 +14,18 @@ type
|
||||
|
||||
TForm1 = class(TForm)
|
||||
Button1: TButton;
|
||||
Edit1: TEdit;
|
||||
Label1: TLabel;
|
||||
Label2: TLabel;
|
||||
Label3: TLabel;
|
||||
ListBox1: TListBox;
|
||||
Memo1: TMemo;
|
||||
procedure Button1Click(Sender: TObject);
|
||||
procedure FormCreate(Sender: TObject);
|
||||
private
|
||||
{ private declarations }
|
||||
procedure PrintString(S:String);
|
||||
procedure PrintStream(St:TStream);
|
||||
procedure PrintSample;
|
||||
public
|
||||
{ public declarations }
|
||||
end;
|
||||
@ -32,6 +35,8 @@ var
|
||||
|
||||
implementation
|
||||
|
||||
{$R *.lfm}
|
||||
|
||||
{ TForm1 }
|
||||
|
||||
procedure TForm1.FormCreate(Sender: TObject);
|
||||
@ -40,13 +45,39 @@ begin
|
||||
Listbox1.Items.Assign(Printer.Printers);
|
||||
end;
|
||||
|
||||
procedure PrintRawString(const S:String);
|
||||
procedure TForm1.PrintString(S: String);
|
||||
var
|
||||
Written: Integer;
|
||||
begin
|
||||
Printer.BeginDoc;
|
||||
Printer.Write(S[1], Length(S), Written);
|
||||
Printer.EndDoc;
|
||||
end;
|
||||
|
||||
const
|
||||
MaxBufSize = 256;
|
||||
|
||||
procedure TForm1.PrintStream(St: TStream);
|
||||
var
|
||||
Written: Integer;
|
||||
Buffer: array[0..MaxBufSize-1] of byte;
|
||||
begin
|
||||
while St.Position<St.Size do begin
|
||||
Written := St.Read(Buffer, MaxBufSize);
|
||||
Printer.Write(Buffer, Written, Written);
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TForm1.PrintSample;
|
||||
var
|
||||
S: TStringStream;
|
||||
begin
|
||||
// print a plain string
|
||||
PrintString('=== FIRST A STRING ==='+LineEnding);
|
||||
PrintString(Memo1.Text);
|
||||
PrintString('=== NOW USING A STREAM ==='+LineEnding);
|
||||
// print using a stream
|
||||
S := TStringStream.Create(Memo1.Text);
|
||||
PrintStream(S);
|
||||
S.Free;
|
||||
end;
|
||||
|
||||
procedure TForm1.Button1Click(Sender: TObject);
|
||||
@ -55,18 +86,15 @@ begin
|
||||
ShowMessage('Select a printer from the list');
|
||||
exit;
|
||||
end;
|
||||
if Edit1.Text='' then begin
|
||||
ShowMessage('There is nothing to print!');
|
||||
exit;
|
||||
end;
|
||||
|
||||
Printer.PrinterIndex := Listbox1.ItemIndex;
|
||||
Printer.SetPrinter(ListBox1.Items[Listbox1.ItemIndex]);
|
||||
Printer.Title := Caption;
|
||||
Printer.RawMode := True;
|
||||
PrintRawString(Edit1.Text);
|
||||
Printer.BeginDoc;
|
||||
PrintSample;
|
||||
Printer.EndDoc;
|
||||
|
||||
end;
|
||||
|
||||
initialization
|
||||
{$I unitmain.lrs}
|
||||
|
||||
end.
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user