Reading Unicode and displaying it
BlitzMax Forums/BlitzMax Programming/Reading Unicode and displaying it
| ||
Hiya, I've saved a file as Unicode (as that's what BMax seems to support) instead of UTF-8 but I can't get it to display properly with DrawText unless I do some extra work (see code sample). Is there a better way to read in the text in the first place so it's already in Unicode format? Thanks. You'll need these files: http://www.greyaliengames.com/misc/arial.ttf http://www.greyaliengames.com/misc/russian.txt Strict Graphics 800,600,0 Global Font:TImageFont = LoadImageFont("arial.ttf", 20) Local File:TStream = OpenFile("Russian.txt") 'in UTF-8 format Global TestLine$ = "" If File Then While Not Eof(File) TestLine = ReadLine(File) Exit Wend CloseFile(File) EndIf While Not KeyHit(KEY_ESCAPE) Cls SetImageFont Font DrawText "abcdefghij",10,10 DrawText "фисвуапршо",10,60 DrawText TestLine,10,110 'doesn't work 'Now decode the line from the file Local line$ = "" '2 bytes makes up a character. 'Skip the first character as it just details the file type. For Local i = 2 To Len(TestLine)/2 'The high order byte is stored after the low order byte. Local Char$ = Chr(Asc(Mid(TestLine,(i*2)-1,1))+Asc(Mid(TestLine,i*2,1))*256) Line:+Char Next DrawText line,10,200 Flip Wend |
| ||
oops answer found in this thread: http://www.blitzbasic.com/Community/posts.php?topic=69327 |