How could I print a unicode string??

BlitzMax Forums/BlitzMax Programming/How could I print a unicode string??

Pinete(Posted 2005) [#1]
Hi all,

Please I need help in the next subject..

I'm trying to write a unicode string to screen but
all my efforts are completely unsucessful!

For example, I go to a russian web page, copy some text
with cyrilic characters and paste into my code.

I've been reading all the related info and some posts but
I don't know how to do it, how to convert or somethign similar...

I'm working with the fantastic BLide. This IDE allow me
to work with unicode strings..

Please help!!!


BlitzSupport(Posted 2005) [#2]
It's not quite possible yet, but I had a query about this yesterday and Mark explained that:

· the BlitzMax compiler supports Unicode characters, but;
· the Windows IDE doesn't support them (yet), though the Mac IDE does -- this will be down to the platform-specific editor controls used;
· outputting Unicode text via the Print command will work in the Mac console but not the Windows one, which doesn't support the UTF8 encoding used;
· DrawText needs an upgrade to support Unicode characters.

Mark does understand the need to support this, and intends to try and get the Windows IDE and DrawText supporting Unicode text as time permits.


Pinete(Posted 2005) [#3]
Thanks a lot for your response, James.

Unicode is key in terms of marketing. In order to selling your games all over the world, there exist a lot of territories (rusia, china, japan, etc...) interested in publishing but uses to ask for the game traslated to his language to close the deal and this is a problem.

Thanks again!

Best regards!


ziggy(Posted 2005) [#4]
IF your problem is outputing the unicode characters in the windows console, you can convert them to ansi, in a very easy way:

Make your bmx source in ANSI (this will treat any spetial character as a single 8 bits character, not converting it to 16 bits).

And make the output text via standario.writebytes, and not using the print command.

I use this to make a 'on the fly' conversion, and it works fine:

Strict

PrintLine("Thís ís àn ansï striñg with spetial châracters.")


Function StringToBuffer:TBank(PBuffer:TBank ptr, Str:String)
	local buffer:TBank = var(PBuffer)
	buffer.resize(len(Str))
	for local i = 1 to len(str)
		buffer.pokebyte(i-1,asc(mid(str,i,1)))
	Next
end function

function PrintLine(Com:String)
	local Buffer:TBank = new TBank
	StringToBuffer(varptr(Buffer),Com)
	standardiostream.writebytes(buffer.buf(), buffer.Size())
	StringToBuffer(varptr(Buffer),chr(13)+chr(10)) 'line feed
	standardiostream.writebytes(buffer.buf(), buffer.Size())
	flushstream(standardiostream)	
end function


This function will solve the problem in the official IDE and in the windows console, as long as BlitzMax continues outputing the text in a non-windows console compatible UF8 format. IT would be great that the print command uses the standar output encoding of the windows distribution where the program is running. But no news about that... BLIde works with unicode encoding, to ensure 100% compatibility with blitzMax, so if you use this functions to output ANSI text, it won't be displayed correctly in the BLIde console window, you can always Bluid and 'run the application in a real console' to see everything is outputing correctly.


Grisu(Posted 2005) [#5]
Unicode would be great!


RexRhino(Posted 2005) [#6]
Unicode is definitly an extremly important feature.


BlitzSupport(Posted 2005) [#7]

'run the application in a real console' to see everything is outputing correctly.


Hmm, in a real console I get...
"Thİs İs Ón ans´ stri±g with spetial chÔracters."

... though it's correct in the IDE output!


Perturbatio(Posted 2005) [#8]
Hmm, in a real console I get...

yeah, I get the same


ziggy(Posted 2005) [#9]
It's logical, in a real console, on a MAC you need to output UNICODE, in a windows, it dependes on your international distribution, it can be ANSI or UNICODE. If it's ANSI, you will see the text correctly, if not, you'll get garbage. I mean, the problem is WINDOWS is not supporting well UNICODE output in most of its distributions. the official IDE is not supporting unicode in windows. So, you can use the function I mentioned above to see the output in the official IDE and in a non unicode console, but you'll get garbage in a unicode console (mac, linux and some windows)...