Hello,

I would like to create some official guidelines about how to implement
unicode support for win32 interface, so volunteers can base on those
to implement it and we get a uniform work. And I think that a good
example to create a guideline is by an example.

Consider the line 292 of the win32wsbuttons.pp file:

 GetTextExtentPoint32(hdcNewBitmap, LPSTR(ButtonCaption),
Length(ButtonCaption), TextSize);

My initial idea is to transform this into:

var
 WideText: PWideChar;
 AnsiText: string;
 WideSize: Integer;

 ........

{$ifdef UnicodeWinInterface}
 if UnicodeEnabledOS then
 begin
   WideSize := Utf8ToUnicode(nil, ButtonCaption, 0);
   WideText := GetMem(WideSize * 2);
   Utf8ToUnicode(WideText, ButtonCaption, WideSize);
   GetTextExtentPoint32W(hdcNewBitmap, WideText, Length(WideText), TextSize);
   FreeMem(WideText);
 end
 else
 begin
   AnsiText := Utf8ToAnsi(ButtonCaption);
   GetTextExtentPoint32(hdcNewBitmap, LPSTR(AnsiText),
Length(AnsiText), TextSize);
 end;
{$else}
 GetTextExtentPoint32(hdcNewBitmap, LPSTR(ButtonCaption),
Length(ButtonCaption), TextSize);
{$endif}

The original code remains equal on the else part of the ifdef.

I already tested this approach on fpGUI and seams to work well. I
didn´t try to compile, so small erros may be present.

I analized the code on Utf8ToUnicode and it returns the number of
characters written + 1 for the null-terminator. This line:

   WideText := GetMem(WideSize * 2);

Is correct, because Utf8ToUnicode doesn´t seam to support UTF-16
characters that are dword sized. Else it would fail for them.

Please comment, find bugs, improve, modify, etc.
--
Felipe Monteiro de Carvalho

_________________________________________________________________
    To unsubscribe: mail [EMAIL PROTECTED] with
               "unsubscribe" as the Subject
  archives at http://www.lazarus.freepascal.org/mailarchives

Reply via email to