From d60d9566d3c1c8a930e56717b16a97a2ed23b78b Mon Sep 17 00:00:00 2001 From: jesus Date: Wed, 22 Aug 2007 18:06:57 +0000 Subject: [PATCH] printers, fixed rawmode printing using cups, issue #9462 git-svn-id: trunk@11845 - --- .../printers/design/languages/ideprinting.po | 6 +++ components/printers/printer4lazarus.lpk | 6 +-- .../printers/samples/rawmode/rawmodetest.lpi | 15 +++--- .../printers/samples/rawmode/unitmain.lfm | 35 ++++++------- .../printers/samples/rawmode/unitmain.lrs | 42 ++++++++-------- components/printers/unix/cupsprinters.inc | 49 +++++++++---------- components/printers/unix/cupsprinters_h.inc | 3 +- 7 files changed, 80 insertions(+), 76 deletions(-) diff --git a/components/printers/design/languages/ideprinting.po b/components/printers/design/languages/ideprinting.po index 42b5f0ef3a..a12dfe4056 100644 --- a/components/printers/design/languages/ideprinting.po +++ b/components/printers/design/languages/ideprinting.po @@ -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 "" diff --git a/components/printers/printer4lazarus.lpk b/components/printers/printer4lazarus.lpk index dce787157d..7275bd305f 100644 --- a/components/printers/printer4lazarus.lpk +++ b/components/printers/printer4lazarus.lpk @@ -144,11 +144,11 @@ - - - + + + diff --git a/components/printers/samples/rawmode/rawmodetest.lpi b/components/printers/samples/rawmode/rawmodetest.lpi index 8ea527f3b7..53eb01ef19 100644 --- a/components/printers/samples/rawmode/rawmodetest.lpi +++ b/components/printers/samples/rawmode/rawmodetest.lpi @@ -1,7 +1,7 @@ - + @@ -11,7 +11,7 @@ - + @@ -43,7 +43,7 @@ - + @@ -51,19 +51,18 @@ - - + + - + - - + diff --git a/components/printers/samples/rawmode/unitmain.lfm b/components/printers/samples/rawmode/unitmain.lfm index 5ea69ba703..55599684de 100644 --- a/components/printers/samples/rawmode/unitmain.lfm +++ b/components/printers/samples/rawmode/unitmain.lfm @@ -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 diff --git a/components/printers/samples/rawmode/unitmain.lrs b/components/printers/samples/rawmode/unitmain.lrs index 2023324fb2..ea8bac8841 100644 --- a/components/printers/samples/rawmode/unitmain.lrs +++ b/components/printers/samples/rawmode/unitmain.lrs @@ -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 ]); diff --git a/components/printers/unix/cupsprinters.inc b/components/printers/unix/cupsprinters.inc index c6df4eb35d..2f290bcd25 100644 --- a/components/printers/unix/cupsprinters.inc +++ b/components/printers/unix/cupsprinters.inc @@ -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; diff --git a/components/printers/unix/cupsprinters_h.inc b/components/printers/unix/cupsprinters_h.inc index 2949329413..4af156b172 100644 --- a/components/printers/unix/cupsprinters_h.inc +++ b/components/printers/unix/cupsprinters_h.inc @@ -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;