Mastodon
Programmierung

Display Chinese Character

> currently i gave up (because of no time) but i’ll try the suggestions from
> Vincent Yip. He has posted some chinese text here and if i’m able to copy
it
> to delphi… well then all that i need is an “input-interface” smile

I think you’ll find it doesn’t work like that. The reason is that the VCL
components all use the SBCS string writing functions. I have now succeeded
in displaying Chinese characters from the MS Song and MS Hei TT fonts.

To do this, you must convert the GB2312 string to Unicode, then pass the
Unicode wide string to the OutTextW function.

The following code will display the characters, if you pass it a string such
as the GB one that Vincent Yip provided (thanks Vincent!).

[code lang=”delphi”]{—-XieHanZi—————————————————————
———————-}
// The Font property of the canvas parameter MUST be set to a UNICODE
// Chinese font, such as MS-Hei or MS-Song
procedure XieHanZi(Canvas:TCanvas; x,y:integer; GB:string);
var W:PWideChar;
GBlength, UNILength, WSize:integer;
begin
GBLength:=Length(GB);

// Horrible things happened when I used a PWideChar cast on
// a WideString, and this is the only reliable way I found:

// Each single char in GB could become two bytes
// Also might need two bytes for the zero terminator.
WSize:=GBLength*2 + 2;
GetMem(W, WSize);

// It seems that MultiByteToWideChar doesn’t put in a 0 terminator
ZeroMemory(W,WSize);

// Convert from code page 936 (PRC, Singapore) to UNICODE
MultiByteToWideChar(936,0,PChar(GB),GBLength,W,WSize);

// Get length of UNICODE string
UNILength:=LStrLenW(W);

// Write the text
TextOutW(Canvas.Handle, x,y,W,UNILength);

// Clean up
FreeMem(W, GBLength*2+2);
end;

{—————————————————————————
————————–}[/code]

This can easily be modified to display MingLiu in Big5, just change the
code page 936 to 950, and pass a big5 string instead of GB.

[tags]Delphi, Chinese[/tags]

0 Kommentare zu “Display Chinese Character

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht.