I am trying to draw some greek characters using graphics.drawstring. This works well for UTF-8 characters that require only a single byte, but when I try to draw a string that is double byte, I fail.
For example, the lowercase greek alpha is represented in UTF-16 as alpha = &u03b1, where alpha is a string. This prints just fine, but if I try to draw the string using
I get a “?”. This is true for all characters that use two bytes. So I am obviously doing something wrong. Can anyone help?
What don’t are you using to draw?
I just put this into a canvas’s Paint event and it works (at least on on OS X):
Dim alpha As String = &u03b1
g.DrawString(alpha, 30, 30)
Is the data to be printed coming from an outside source like a database or a text file? Then make sure that the strings have the right encoding, for example if they come in as UTF-16, you would have to convert it:
Dim utf8String As String = incoming.DefineEncoding(Encodings.UTF16).ConvertEncoding(Encodings.UTF8)
That should have said “font”.
Thanks to Eli’s comment, I now have this working on cocoa. I have not had similar success in carbon, however, and have not tried windows yet.