Friday, October 27, 2006, 4:48:21 AM, Felipe wrote:
FMdC> Hello,
FMdC> I would like to create some official guidelines about how to implement
FMdC> unicode support for win32 interface, so volunteers can base on those
FMdC> to implement it and we get a uniform work. And I think that a good
FMdC> example to create a guideline is by an example.
[snip]
FMdC> Please comment, find bugs, improve, modify, etc.
Two comments:
First, the code snippet might look somewhat simpler:
var
WideText: WideString;
...
{$ifdef UnicodeWinInterface}
if UnicodeEnabledOS then
begin
WideText := Utf8Decode(ButtonCaption);
GetTextExtentPoint32W(hdcNewBitmap, PWideChar(WideText), Length(WideText),
TextSize);
end
else
begin
AnsiText := Utf8ToAnsi(ButtonCaption);
GetTextExtentPoint32(hdcNewBitmap, LPSTR(AnsiText), Length(AnsiText),
TextSize);
end;
{$else}
GetTextExtentPoint32(hdcNewBitmap, LPSTR(ButtonCaption),
Length(ButtonCaption), TextSize);
{$endif}
UTF8Decode function counts number of required WideChars by iterating
through its UTF-8 argument. It does not yet support dword-sized chars,
but, when it eventually will, this code will not require any changes.
Furthermore, if you look into RTL source, you'll find out that
Utf8ToAnsi() is nothing more than Utf8Decode() whose WideString result is then
casted to AnsiString. Therefore you may assign WideText variable
before the 'if' block, and later just write 'AnsiText := WideText'
instead of calling Utf8ToAnsi. But this is just fine tuning...
Second, this particular API function - GetTextExtentPoint32() - can be
used unconditionally with 'W' suffix, even on Windows9x. So this
example may become even more simple :)
--
Best regards,
Sergei
_________________________________________________________________
To unsubscribe: mail [EMAIL PROTECTED] with
"unsubscribe" as the Subject
archives at http://www.lazarus.freepascal.org/mailarchives