{"id":73,"date":"2007-05-11T21:33:20","date_gmt":"2007-05-11T19:33:20","guid":{"rendered":" http:\/\/www.nsonic.de\/blog\/2007\/05\/display-chinese-character\/"},"modified":"2007-05-11T21:33:24","modified_gmt":"2007-05-11T19:33:24","slug":"display-chinese-character","status":"publish","type":"post","link":"https:\/\/www.nsonic.de\/blog\/2007\/05\/display-chinese-character\/","title":{"rendered":"Display Chinese Character"},"content":{"rendered":"<p><em>> currently i gave up (because of no time) but i&#8217;ll try the suggestions from<br \/>\n> Vincent Yip. He has posted some chinese text here and if i&#8217;m able to copy<br \/>\nit<br \/>\n> to delphi&#8230; well then all that i need is an &#8220;input-interface&#8221; <span class=\"wp-smiley emoji emoji-smile\" title=\":-)\">smile<\/span> <\/em><\/p>\n<p>I think you&#8217;ll find it doesn&#8217;t work like that. The reason is that the VCL<br \/>\ncomponents all use the SBCS string writing functions. I have now succeeded<br \/>\nin displaying Chinese characters from the MS Song and MS Hei TT fonts.<\/p>\n<p>To do this, you must convert the GB2312 string to Unicode, then pass the<br \/>\nUnicode wide string to the OutTextW function.<\/p>\n<p>The following code will display the characters, if you pass it a string such<br \/>\nas the GB one that Vincent Yip provided (thanks Vincent!).<\/p>\n<p>[code lang=&#8221;delphi&#8221;]{&#8212;-XieHanZi&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br \/>\n&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-}<br \/>\n\/\/ The Font property of the canvas parameter MUST be set to a UNICODE<br \/>\n\/\/ Chinese font, such as MS-Hei or MS-Song<br \/>\nprocedure XieHanZi(Canvas:TCanvas; x,y:integer; GB:string);<br \/>\nvar W:PWideChar;<br \/>\n       GBlength, UNILength, WSize:integer;<br \/>\nbegin<br \/>\n  GBLength:=Length(GB);<\/p>\n<p>  \/\/ Horrible things happened when I used a PWideChar cast on<br \/>\n  \/\/ a WideString, and this is the only reliable way I found:<\/p>\n<p>  \/\/ Each single char in GB could become two bytes<br \/>\n  \/\/ Also might need two bytes for the zero terminator.<br \/>\n  WSize:=GBLength*2 + 2;<br \/>\n  GetMem(W, WSize);<\/p>\n<p>  \/\/ It seems that MultiByteToWideChar doesn&#8217;t put in a 0 terminator<br \/>\n   ZeroMemory(W,WSize);<\/p>\n<p>  \/\/ Convert from code page 936 (PRC, Singapore) to UNICODE<br \/>\n   MultiByteToWideChar(936,0,PChar(GB),GBLength,W,WSize);<\/p>\n<p>  \/\/ Get length of UNICODE string<br \/>\n   UNILength:=LStrLenW(W);<\/p>\n<p>  \/\/ Write the text<br \/>\n  TextOutW(Canvas.Handle, x,y,W,UNILength);<\/p>\n<p>  \/\/ Clean up<br \/>\n  FreeMem(W, GBLength*2+2);<br \/>\nend;<\/p>\n<p>{&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br \/>\n&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;}[\/code]<\/p>\n<p> This can easily be modified to display MingLiu in Big5, just change the<br \/>\ncode page 936 to 950, and pass a big5 string instead of GB.<\/p>\n<p>[tags]Delphi, Chinese[\/tags]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>> currently i gave up (because of no time) but i&#8217;ll try the suggestions from > Vincent Yip. He has posted some chinese&hellip;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":""},"categories":[11],"tags":[89,75],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p71Tml-1b","_links":{"self":[{"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/posts\/73"}],"collection":[{"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/comments?post=73"}],"version-history":[{"count":0,"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/posts\/73\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/media?parent=73"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/categories?post=73"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.nsonic.de\/blog\/wp-json\/wp\/v2\/tags?post=73"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}