Unicode not supported?!?
BlitzMax Forums/BlitzMax Beginners Area/Unicode not supported?!?
| ||
Hello, what am I doing wrong here? Graphics 800,600,0 SetColor 255,255,255 DrawText "Björn",20,20 Flip WaitKey I HATE asking such simple stuff that should work out of the box. :/ Grisu |
| ||
The default font probably does not have the non standard characters. Arial.ttf worksGraphics 800,600,0 Local font:TImageFont=LoadImageFont("C:\WINDOWS\Fonts\arial.ttf",12) SetImageFont(font) SetColor 255,255,255 DrawText "Björn",20,20 Flip WaitKey |
| ||
I guess you have to load a unicode font first?...Graphics 800,600,0 SetImageFont(LoadImageFont(getenv_("windir") + "\fonts\arial.ttf", 24, SMOOTHFONT)) SetBlend ALPHABLEND SetColor 255,255,255 DrawText "Björn",20,20 Flip WaitKey [edit] Lummy... [/edit] |
| ||
Thanks for hint. But this isn't working under maxgui and using a canvas as it seems. Also I need this to be cross-platform. And I doubt mac users will have arial.ttf on their system. :/ |
| ||
Then you will have to add your own font to your app. The default font only features english characters ... we found that out a few months ago when we tried to solve a similar issue with drawing german characters. PS: This has nothing to do with unicode. Unicode is needed for asian characters, not for european. Our characters all fit within the ascii. |
| ||
Thanks for the informations. |
| ||
Grisu, the following code works for me:-SuperStrict Local MyWindow:TGadget=CreateWindow("Canvas Example", 200,200,320,240) Local MyCanvas:TGadget=CreateCanvas(10,10,290,140,MyWindow) SetGraphics CanvasGraphics (MyCanvas) Local font:TImageFont=LoadImageFont("C:\WINDOWS\Fonts\arial.ttf",12) SetImageFont(font) SetColor 255,255,255 Repeat WaitEvent() Select EventID() Case EVENT_WINDOWCLOSE End Case EVENT_GADGETPAINT SetGraphics CanvasGraphics (MyCanvas) DrawText "Björn",20,20 Flip End Select Forevermake sure you set the font after the setgraphics command |
| ||
Also I need this to be cross-platform. And I doubt mac users will have arial.ttf on their system. :/ As for imagefonts, you can load a .ttf from anywhere, not just the windows fonts folder, so you can include the .ttf file with your distribution. By using the same .ttf file on Mac and PC, the output should look the same. If you want to legally distribute fonts with your app/game, you'll need to make sure that's permitted (I wouldn't suggest trying it with Microsoft's Arial for example <g>). One set of fonts that's allowed to be redistributed (as long as you don't try to sell just the fonts alone) is Arkpandora ( http://www.users.bigpond.net.au/gavindi ). This set has replacements for Arial, Monospace, Times, and Verdana. If you don't feel like messing with the .tgz there, I've mirrored the fonts as a zip at http://astronavis.com/arkpandora204.zip . These aren't unicode fonts, though they support the umlauted and other accented European characters. For unicode TTFs, one free (GNU GPL) source is http://savannah.nongnu.org/projects/freefont (though the fonts there only support a subset of characters at present). |
| ||
I sure hope Unicode fonts are supported in Blitzmax one day. I could really do with being able to use them. |
| ||
Unicode is already supported ... (came in with 1.16 or 1.18) You just need an unicode font, blitz own font is english characters only. (for external usage there is toWString / $w) |
| ||
Unicode is already supported ... (came in with 1.16 or 1.18) You just need an unicode font Yep. Here's an example: ' adapted from neilo's Arabic version Strict Graphics 640,480 ' Local font:TImageFont = LoadImageFont("c:\windows\fonts\cour.ttf",24) Local font:TImageFont = LoadImageFont("c:\windows\fonts\msgothic.ttf",24) SetImageFont font Local text$ = "" Local unicode:Short[8] Local nextChar:Short For Local i = 0 To 2 ' 6 To 0 Step -1 ReadData nextChar unicode[i]=nextChar Next text$=string.FromShorts(unicode,7) While Not KeyHit(KEY_ESCAPE) Cls DrawText text$,10,10 Flip Wend ' "Yamato" in katakana DefData $30e4, $30de, $30c8 ' A line of Arabic text ' DefData $0625,$0646,$0643,$0644,$064a,$0632,$064aWhich produces: |
| ||
On my computer the above code doesn't work without a minor change. Local font:TImageFont = LoadImageFont("c:\windows\fonts\msgothic.ttf",24) Must instead be: Local font:TImageFont = LoadImageFont("c:\windows\fonts\msgothic.ttc",24) To clarify: msgothic.ttf is instead->msgothic.ttc So if you had problems with this code in the past, this should help you. You can also try out batang.ttc. Hope this helps. |
| ||
FYI--OS X ships with Arial.ttf. |