From 8d83a14a6d39d6cb78a6b1c1f53dbcf83a9a8577 Mon Sep 17 00:00:00 2001 From: jesus Date: Mon, 2 Aug 2010 19:27:43 +0000 Subject: [PATCH] Printers, Win32, retrieve printer names as UTF8, issue #17022 git-svn-id: trunk@26980 - --- .../printers/samples/rawmode/unitmain.lfm | 32 ++++++++++--------- .../printers/samples/rawmode/unitmain.pas | 4 ++- components/printers/win32/winprinters.inc | 15 +++++---- 3 files changed, 29 insertions(+), 22 deletions(-) diff --git a/components/printers/samples/rawmode/unitmain.lfm b/components/printers/samples/rawmode/unitmain.lfm index 4881a7feeb..bae49f9a68 100644 --- a/components/printers/samples/rawmode/unitmain.lfm +++ b/components/printers/samples/rawmode/unitmain.lfm @@ -1,37 +1,38 @@ object Form1: TForm1 Left = 265 - Height = 356 + Height = 369 Top = 181 Width = 452 HorzScrollBar.Page = 427 VertScrollBar.Page = 301 + ActiveControl = ListBox1 Caption = 'RawMode Print Test' - ClientHeight = 356 + ClientHeight = 369 ClientWidth = 452 Constraints.MaxHeight = 400 Constraints.MinHeight = 240 OnCreate = FormCreate LCLVersion = '0.9.29' object Label1: TLabel - Left = 15 - Height = 14 - Top = 5 - Width = 61 + Left = 12 + Height = 16 + Top = 8 + Width = 80 Caption = 'Printers List:' ParentColor = False end object Label2: TLabel Left = 11 - Height = 14 - Top = 150 - Width = 65 + Height = 16 + Top = 144 + Width = 80 Caption = 'Text to print:' ParentColor = False end object Label3: TLabel - Left = 98 - Height = 60 - Top = 286 + Left = 96 + Height = 71 + Top = 292 Width = 344 Anchors = [akLeft, akRight, akBottom] AutoSize = False @@ -47,11 +48,12 @@ object Form1: TForm1 Anchors = [akTop, akLeft, akRight] ItemHeight = 0 TabOrder = 0 + TopIndex = -1 end object Button1: TButton Left = 11 Height = 25 - Top = 321 + Top = 334 Width = 75 Anchors = [akLeft, akBottom] BorderSpacing.InnerBorder = 4 @@ -61,8 +63,8 @@ object Form1: TForm1 end object Memo1: TMemo Left = 11 - Height = 112 - Top = 168 + Height = 125 + Top = 162 Width = 430 Anchors = [akTop, akLeft, akRight, akBottom] Lines.Strings = ( diff --git a/components/printers/samples/rawmode/unitmain.pas b/components/printers/samples/rawmode/unitmain.pas index 5d4fb0f88e..31e0cce36d 100644 --- a/components/printers/samples/rawmode/unitmain.pas +++ b/components/printers/samples/rawmode/unitmain.pas @@ -87,7 +87,9 @@ begin exit; end; - Printer.PrinterIndex := Listbox1.ItemIndex; + // on a freshly retrieved printer list, either method could + // be used to select a printer: SetPrinter or PrinterIndex + //Printer.PrinterIndex := Listbox1.ItemIndex; Printer.SetPrinter(ListBox1.Items[Listbox1.ItemIndex]); Printer.Title := Caption; Printer.RawMode := True; diff --git a/components/printers/win32/winprinters.inc b/components/printers/win32/winprinters.inc index 615c35fb58..98eed20ab8 100644 --- a/components/printers/win32/winprinters.inc +++ b/components/printers/win32/winprinters.inc @@ -139,10 +139,9 @@ begin //Device is only 32 chars long, //if the Printername or share is longer than 32 chars, this will return 0 - fDC:=CreateDC(nil,PChar(Printers[PrinterIndex]),nil, PDev.DevMode); + fDC := CreateDC(nil, PChar(PDev.Name), nil, PDev.DevMode); if fDC=0 then - fDC:=CreateDC(PChar('WINSPOOL'),PChar(Printers[PrinterIndex]),nil, - PDev.DevMode); + fDC := CreateDC(PChar('WINSPOOL'),PChar(PDev.Name), nil, PDev.DevMode); {Workaround (hack) for Lexmark 1020 JetPrinter (Mono)} if fDC=0 then @@ -399,6 +398,8 @@ begin end; end; + + Result := AnsiToUTF8(Result); end; @@ -414,6 +415,7 @@ Var Flags : DWORD; DefaultPrinter : string; PDev : TPrinterDevice; TmpDevMode : PDeviceMode; + PrtStr : string; begin {$IFDEF NOPRINTERS} Lst.Clear; @@ -460,11 +462,12 @@ begin PDev.Device:=''; PDev.DefaultPaper:=0; end; - if AnsiCompareText(PDev.Name,DefaultPrinter)<>0 then - Lst.AddObject(PDev.Name,PDev) + PrtStr := AnsiToUTF8(PDev.Name); + if AnsiCompareText(PrtStr,DefaultPrinter)<>0 then + Lst.AddObject(PrtStr,PDev) else begin - Lst.Insert(0,PDev.Name); + Lst.Insert(0,PrtStr); Lst.Objects[0]:=PDev; end; Inc(InfoPrt,SizeOf(_PRINTER_INFO_2));