#1 2011-02-17 19:23:56

migajek
Member
Registered: 2010-10-01
Posts: 89

TGDIPages - draw text - character encoding problem

Hi,
so I have this problem, I need to print some 'regional' characters. They're handled incorrectly.
System character set is windows-1250.
Regular Canvas.Textout handles these characters correctly.

Here's the screenshot (left - Edit1 on the left, report on the right)
tmpfu.png

and the code

        DrawText('direct ' + Edit1.Text);
        DrawText('utf8ToString' + UTF8ToString(Edit1.Text));
        DrawText('StringToUTF8' + StringToUTF8(Edit1.Text));

yeah, I know those conversions doesn't make sense but I just wanted to try everything before asking for help wink

Offline

#2 2011-02-18 10:59:53

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,655
Website

Re: TGDIPages - draw text - character encoding problem

Which version of Delphi are you using?

What are the "regional" characters?
Which text alignment are you using here?

Can you step in TGDIPages.InternalUnicodeString() then guess what GetACP() return?

Offline

#3 2011-02-18 13:17:14

migajek
Member
Registered: 2010-10-01
Posts: 89

Re: TGDIPages - draw text - character encoding problem

Delphi7 ... Regional characters - ą ę ś ć ź ł ń ó ż
GetACP returns 1250.
TextAlign := taLeft; just before printing the sting.

Offline

#4 2011-02-18 13:28:21

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,655
Website

Re: TGDIPages - draw text - character encoding problem

In the method, could you step into those lines:

    {$ifndef USEPDFPRINTER}
    if GetACP<>1252 then begin
    {$endif}
      // low-level MBCS RTL function including last widechar #0
      StringToWideChar(s,PW,PWLen*2+1);
      PWLen := lstrlenW(PW);
    {$ifndef USEPDFPRINTER}
    end else
      // fast WinAnsi conversion using a fixed table from SynCommons
      for i := 0 to PWLen do // includes S[length(s)+1]=#0 -> last widechar #0
        PWordArray(PW)[i] := WinAnsiTable[PByteArray(s)[i]];
    {$endif}
    {$endif}

And see what's inside the PW buffer after the call to StringToWideChar?

Offline

#5 2011-02-18 14:28:29

migajek
Member
Registered: 2010-10-01
Posts: 89

Re: TGDIPages - draw text - character encoding problem

greenshot2011218144910.png

Offline

#6 2011-02-18 16:50:49

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,655
Website

Re: TGDIPages - draw text - character encoding problem

So the Delphi function is wrong and doesn't seem to get the right code page...

Could you change the StringToWideChar lines with this:

    {$ifndef USEPDFPRINTER}
    if GetACP<>1252 then begin
    {$endif}
      // low-level MBCS RTL function including last widechar #0
      PWLen := MultiByteToWideChar(GetACP, 0, Pointer(s), Length(s), PW, PWLen);
      PW[PWLen] := #0;
    {$ifndef USEPDFPRINTER}
    end else

Offline

#7 2011-02-18 17:16:27

migajek
Member
Registered: 2010-10-01
Posts: 89

Re: TGDIPages - draw text - character encoding problem

MultiByteToWideChar method solved the problem big_smile smile Thank you!

Offline

Board footer

Powered by FluxBB