printers, fixed rawmode printing using cups, issue #9462

git-svn-id: trunk@11845 -
This commit is contained in:
jesus 2007-08-22 18:06:57 +00:00
parent c3d8e9f2e7
commit d60d9566d3
7 changed files with 80 additions and 76 deletions

View File

@ -1,3 +1,9 @@
msgid ""
msgstr ""
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
#: ideprinting:sdescrpfselection
msgid "Print..."
msgstr ""

View File

@ -144,11 +144,11 @@
<Type Value="RunAndDesignTime"/>
<RequiredPkgs Count="2">
<Item1>
<PackageName Value="LCL"/>
</Item1>
<Item2>
<PackageName Value="FCL"/>
<MinVersion Major="1" Valid="True"/>
</Item1>
<Item2>
<PackageName Value="LCL"/>
</Item2>
</RequiredPkgs>
<UsageOptions>

View File

@ -1,7 +1,7 @@
<?xml version="1.0"?>
<CONFIG>
<ProjectOptions>
<PathDelim Value="\"/>
<PathDelim Value="/"/>
<Version Value="5"/>
<General>
<Flags>
@ -11,7 +11,7 @@
<MainUnit Value="0"/>
<IconPath Value="./"/>
<TargetFileExt Value=".exe"/>
<ActiveEditorIndexAtStart Value="0"/>
<ActiveEditorIndexAtStart Value="1"/>
</General>
<VersionInfo>
<ProjectVersion Value=""/>
@ -43,7 +43,7 @@
<UnitName Value="rawmodetest"/>
<CursorPos X="40" Y="17"/>
<TopLine Value="1"/>
<UsageCount Value="20"/>
<UsageCount Value="21"/>
</Unit0>
<Unit1>
<Filename Value="unitmain.pas"/>
@ -51,19 +51,18 @@
<IsPartOfProject Value="True"/>
<ResourceFilename Value="unitmain.lrs"/>
<UnitName Value="unitmain"/>
<CursorPos X="20" Y="20"/>
<TopLine Value="19"/>
<CursorPos X="21" Y="54"/>
<TopLine Value="3"/>
<EditorIndex Value="0"/>
<UsageCount Value="20"/>
<UsageCount Value="21"/>
<Loaded Value="True"/>
</Unit1>
</Units>
</ProjectOptions>
<CompilerOptions>
<Version Value="5"/>
<PathDelim Value="\"/>
<SearchPaths>
<SrcPath Value="$(LazarusDir)\lcl\;$(LazarusDir)\lcl\interfaces\$(LCLWidgetType)\"/>
<SrcPath Value="$(LazarusDir)/lcl/;$(LazarusDir)/lcl/interfaces/$(LCLWidgetType)/"/>
</SearchPaths>
<CodeGeneration>
<Generate Value="Faster"/>

View File

@ -1,41 +1,41 @@
object Form1: TForm1
Left = 265
Height = 284
Height = 302
Top = 181
Width = 365
HorzScrollBar.Page = 364
VertScrollBar.Page = 283
Width = 428
HorzScrollBar.Page = 427
VertScrollBar.Page = 301
ActiveControl = ListBox1
Caption = 'RawMode Print Test'
ClientHeight = 284
ClientWidth = 365
ClientHeight = 302
ClientWidth = 428
Constraints.MaxHeight = 400
Constraints.MinHeight = 240
OnCreate = FormCreate
object Label1: TLabel
Left = 15
Height = 14
Height = 13
Top = 5
Width = 61
Width = 69
Caption = 'Printers List:'
ParentColor = False
end
object Label2: TLabel
Left = 11
Height = 14
Height = 13
Top = 150
Width = 71
Width = 78
Caption = 'String to print:'
ParentColor = False
end
object Label3: TLabel
Left = 104
Height = 70
Top = 202
Width = 247
Left = 96
Height = 80
Top = 204
Width = 320
Anchors = [akTop, akLeft, akRight, akBottom]
AutoSize = False
Caption = 'NOTE: This sample is meant to sent an alphanumeric string to a Dot-Matrix class printer'#13#10'Which doesn''t need special codes to start printing. Label, LaserJet or DeskJet printers might need'#13#10'some special prefix codes to work correctly.'
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
WordWrap = True
end
@ -43,9 +43,10 @@ object Form1: TForm1
Left = 11
Height = 115
Top = 25
Width = 343
Width = 406
Anchors = [akTop, akLeft, akRight]
TabOrder = 0
TopIndex = -1
end
object Button1: TButton
Left = 11
@ -61,7 +62,7 @@ object Form1: TForm1
Left = 11
Height = 23
Top = 170
Width = 342
Width = 405
Anchors = [akTop, akLeft, akRight]
TabOrder = 2
end

View File

@ -1,25 +1,25 @@
{ 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#28#1#3'Top'#3#181#0#5'Wid'
+'th'#3'm'#1#18'HorzScrollBar.Page'#3'l'#1#18'VertScrollBar.Page'#3#27#1#13'A'
+'ctiveControl'#7#8'ListBox1'#7'Caption'#6#18'RawMode Print Test'#12'ClientHe'
+'ight'#3#28#1#11'ClientWidth'#3'm'#1#21'Constraints.MaxHeight'#3#144#1#21'Co'
+'nstraints.MinHeight'#3#240#0#8'OnCreate'#7#10'FormCreate'#0#6'TLabel'#6'Lab'
+'el1'#4'Left'#2#15#6'Height'#2#14#3'Top'#2#5#5'Width'#2'='#7'Caption'#6#14'P'
+'rinters List:'#11'ParentColor'#8#0#0#6'TLabel'#6'Label2'#4'Left'#2#11#6'Hei'
+'ght'#2#14#3'Top'#3#150#0#5'Width'#2'G'#7'Caption'#6#16'String to print:'#11
+'ParentColor'#8#0#0#6'TLabel'#6'Label3'#4'Left'#2'h'#6'Height'#2'F'#3'Top'#3
+#202#0#5'Width'#3#247#0#7'Anchors'#11#5'akTop'#6'akLeft'#7'akRight'#8'akBott'
+'om'#0#8'AutoSize'#8#7'Caption'#6#233'NOTE: This sample is meant to sent an '
+'alphanumeric string to a Dot-Matrix class printer'#13#10'Which doesn''t nee'
+'d special codes to start printing. Label, LaserJet or DeskJet printers migh'
+'t need'#13#10'some special prefix codes to work correctly.'#11'ParentColor'
+#8#8'WordWrap'#9#0#0#8'TListBox'#8'ListBox1'#4'Left'#2#11#6'Height'#2's'#3'T'
+'op'#2#25#5'Width'#3'W'#1#7'Anchors'#11#5'akTop'#6'akLeft'#7'akRight'#0#8'Ta'
+'bOrder'#2#0#0#0#7'TButton'#7'Button1'#4'Left'#2#11#6'Height'#2#25#3'Top'#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'V'#1#7'Anchors'#11#5'akTop'#6
+'akLeft'#7'akRight'#0#8'TabOrder'#2#2#0#0#0
'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
]);

View File

@ -498,8 +498,6 @@ var
if Result then NewPath:=CurPath;
end;
var
Extension: String;
begin
if FBeginDocCount>0 then
raise Exception.Create('TCUPSPrinter.DoBeginDoc already called. Maybe you forgot an EndDoc?');
@ -511,49 +509,48 @@ begin
and (not TryTemporaryPath('/var/tmp/')) then
NewPath:='';
FOutputFileName := AppendPathDelim(NewPath)+
'OutPrinter_'+FormatDateTime('yyyymmmddd-hhnnss',Now);
if RawMode then
Extension:='.raw'
else
Extension:='.ps';
TPostscriptPrinterCanvas(Canvas).OutputFileName:=AppendPathDelim(NewPath)
+'OutPrinter_'+FormatDateTime('yyyymmmddd-hhnnss',Now)+Extension;
FOutputFileName := FOutputFileName + '.raw'
else begin
FOutputFileName := FOutputFileName + '.ps';
TPostscriptPrinterCanvas(Canvas).OutputFileName := FOutputFileName;
end;
end;
//If not aborted, send PostScript file to printer.
//After, delete this file.
procedure TCUPSPrinter.DoEndDoc(aAborded: Boolean);
procedure TCUPSPrinter.DoEndDoc(aAborted: Boolean);
begin
inherited DoEndDoc(aAborded);
inherited DoEndDoc(aAborted);
dec(FBeginDocCount);
Exclude(FStates,cpsPaperRectValid);
{$IFDEF LogPrintOutFile}
with TPostScriptPrinterCanvas(Canvas) do
if FileExists(OutPutFileName) then
CopyFile(OutPutFileName, 'printout'+ExtractFileExt(OutPutFileName));
{$ENDIF}
if RawMode then begin
if not aAborded and (fRawModeStream<>nil)
if not aAborted and (FRawModeStream<>nil)
and (FRawModeStream.Size>0) then
with TPostScriptPrinterCanvas(Canvas) do begin
begin
try
fRawModeStream.SaveToFile(OutputFileName);
PrintFile(OutputFileName);
DeleteFile(OutputFileName);
FRawModeStream.SaveToFile(FOutputFileName);
finally
FRawModeStream.Clear;
end;
end;
end else begin
if not aAborded then
PrintFile(TPostscriptPrinterCanvas(Canvas).OutPutFileName);
DeleteFile(TPostscriptPrinterCanvas(Canvas).OutPutFileName);
end else
TPostscriptPrinterCanvas(Canvas).OutPutFileName:='';
if not aAborted and FileExists(FOutputFileName) then begin
{$IFDEF LogPrintoutFile}
CopyFile(FOutputFileName, 'printjob'+ExtractFileExt(FOutputFileName));
{$ENDIF}
PrintFile(FOutputFileName);
DeleteFile(FOutputFilename);
end;
TPostscriptPrinterCanvas(Canvas).OutPutFileName:='';
end;
procedure TCUPSPrinter.DoResetPrintersList;

View File

@ -95,6 +95,7 @@ type
fCachePaperRectResult: Integer;
FBeginDocCount: Integer;
fRawModeStream: TMemoryStream;
FOutputFilename: string;
function GetCupsRequest : Pipp_t;
procedure DoCupsConnect;
@ -113,7 +114,7 @@ type
function GetCanvasRef : TPrinterCanvasRef; override;
procedure DoBeginDoc; override;
procedure DoEndDoc(aAborded : Boolean); override;
procedure DoEndDoc(aAborted : Boolean); override;
procedure DoResetPrintersList; override;