Text in Latin 1 Format
BlitzMax Forums/BlitzMax Programming/Text in Latin 1 Format
| ||
| I'm creating a project which will have multiple languages and thus, uses a number of accented characters. Is it possible to store text in Latin 1 format? If I store a string in a file and grab the ASC value, is that ASCII or Laatin 1? |
| ||
| You have to use text streams. Strings are stored in Unicode format, so there can be 16 bit chars in a string , and this is semothing very usual in some languages (japanese, arabic, etc) I suggest you take a look to textStreams or, if possible, use the function SaveText. This function will choose the apropiate encoding for you, depending of the contents of the string you're saving to disk. |
| ||
| So there's absolutely no way to store text within a program in Latin 1? Hmmm... |
| ||
I don't know about Latin 1 per se (<- OMG, Latin! <g>), but you can store Unicode within a BMax program via DefData (and maybe(?) strings with the recent Unicode upgrades, but definately with DefData if nothing else):' adapted from neilo's Arabic version
Strict
Graphics 640,480
' Local font:TImageFont = LoadImageFont("c:\windows\fonts\cour.ttf",24) ' original, Arabic example
Local font:TImageFont = LoadImageFont("c:\windows\fonts\msgothic.ttf",24) ' for Japanese
SetImageFont font
Local text$ = ""
Local unicode:Short[8]
Local nextChar:Short
For Local i = 0 To 2 ' 6 To 0 Step -1 ' <- reverse order for Arabic
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,$064a |
| ||
| Yes you can store text in latin 1, using TextStreams and setting the apropiate encoding, but Latin1 is not compatible with all characters, so you run the risk of saving wrong text in your files if you use always latin 1. I suggest you to use always unicode big endian (this will save each character in 16 bits, so your filles will be double size of a standar latin 1 file, but you will avoid any incompatibility issue). The other possibility is check if the data you want to save has any character greater than 255. In that case you have to use unicode, otherwise you can use latin1 safely. (that's the way the SaveText function works) |