display.newtext question

Hi all,

I am trying to display all the characters in a custom font on the screen and can’t seem to access the characters above 127.

I’ve tried using \174 like so:

display.newText ( ‘\174’ , 10 , 160 , textFont . Grobold , 54 )

but all I get displayed is white diamond with a black question mark inside it.

The character should be a registered trademark symbol.

I am convinced it is using the proper custom font but the white diamond symbol is not even in

my custom font.

All the visible characters from 0-127 seem to work properly in the above line of code.

I am using the latest public build 2013.1076(2013.4.3)

What hopefully simple thing am I doing wrong?

Thanks,

-Dennis

I’ve been doing some more experimentation and have discovered I can’t seem to access

any extended ASCII characters even using a built-in iOS font.

I’ve tried:

display.newText( “\169”, 10, 50, “ArialMT”, 52 )

display.newText( string.char(169), 10, 50, “ArialMT”, 52 )

local letter = 169

display.newText( string.char(string.fomat("%c",letter)), 10, 50, “ArialMT”, 52)

display.newText( “©®¥£¼½€™”, 10, 160,  “ArialMT”, 52 )

and none of those seem to work.

Any ideas?

Thanks,

-Dennis

Well, we do support UTF-8 characters, so if your text editor supports UTF-8 you can enter them.  UTF-8 isn’t the same as high ASCII and can’t be indexed like ASCII characters, they are multi-byte characters.   Your last example should work, if a) the font supports them and b) your editor is in UTF-8 mode.

Hi Rob,

Thanks for responding to my inquiry. I am using EditPad Pro 7. I created a new filetype *.utf and made sure it was in UTF-8 mode.

I created a new file test.utf and put this in it:

This is a test ©¾¥®£§

I then highlighted the extended characters and cut and pasted them in my draw.newText command.

Still nothing on screen.

I know this must work as I have a store in my game that I set up a couple of test accounts and set one of my devices to Great Britain and then put my game on that device. My store logic retrieved the localized price as a string and lo and behold the draw.newText was able to output £0.69 on the screen.

I am so frustrated as to what I am doing wrong. The font used in both cases above is the same and has those characters in it.

I have a feeling I am doing something trivial wrong but I just can’t put my finger on it.

Any further suggestions?

Thanks,

-Dennis

It seemed to work for me with Sublime 2.  I’m on a Mac, I don’t know if Windows in interfering with you or not.  I’m guessing you are using Windows by trying to use 164 to draw a copyright symbol.  I copied and pasted from the forums into my editor.

utf8text.png

Hi Rob,

Thanks so much for your succintct reply. I downloaded Sublime for the Mac (I have a Mac also but prefer the PC), cut the text from the forum as you indicated, pasted it into the draw.newText, saved the file as a UTF-8 format and presto!

It worked!

Took the main.lua back into Windows and into EditPad Pro 7 and took a look at the draw.newText command and here is

what I found:

display . newText( storyGroup ,“©¾¥®£§” , 10 , 160 , textFont . Grobold , 54 )

So apparently UTF-8 requires a  before each character to work properly I’m guessing.

Moral of the story I guess is that UTF-8 does not necessarily mean 1 byte? It’s a little cryptic to me but you have set me straight.

So thank you for preventing me from tearing what little hair I have left out.

You can mark this one resolved.

Thanks again,

-Dennis

I’m by no means a UTF-8 expert, but it is multi-byte.  I think that when it sees a high bit set, it reads a value which is the number of bytes and then one byte as necessary for the character sequence or something.  I don’t think you can safely copy/paste that one character, though it probably would work for those specific characters.

I’ve been doing some more experimentation and have discovered I can’t seem to access

any extended ASCII characters even using a built-in iOS font.

I’ve tried:

display.newText( “\169”, 10, 50, “ArialMT”, 52 )

display.newText( string.char(169), 10, 50, “ArialMT”, 52 )

local letter = 169

display.newText( string.char(string.fomat("%c",letter)), 10, 50, “ArialMT”, 52)

display.newText( “©®¥£¼½€™”, 10, 160,  “ArialMT”, 52 )

and none of those seem to work.

Any ideas?

Thanks,

-Dennis

Well, we do support UTF-8 characters, so if your text editor supports UTF-8 you can enter them.  UTF-8 isn’t the same as high ASCII and can’t be indexed like ASCII characters, they are multi-byte characters.   Your last example should work, if a) the font supports them and b) your editor is in UTF-8 mode.

Hi Rob,

Thanks for responding to my inquiry. I am using EditPad Pro 7. I created a new filetype *.utf and made sure it was in UTF-8 mode.

I created a new file test.utf and put this in it:

This is a test ©¾¥®£§

I then highlighted the extended characters and cut and pasted them in my draw.newText command.

Still nothing on screen.

I know this must work as I have a store in my game that I set up a couple of test accounts and set one of my devices to Great Britain and then put my game on that device. My store logic retrieved the localized price as a string and lo and behold the draw.newText was able to output £0.69 on the screen.

I am so frustrated as to what I am doing wrong. The font used in both cases above is the same and has those characters in it.

I have a feeling I am doing something trivial wrong but I just can’t put my finger on it.

Any further suggestions?

Thanks,

-Dennis

It seemed to work for me with Sublime 2.  I’m on a Mac, I don’t know if Windows in interfering with you or not.  I’m guessing you are using Windows by trying to use 164 to draw a copyright symbol.  I copied and pasted from the forums into my editor.

utf8text.png

Hi Rob,

Thanks so much for your succintct reply. I downloaded Sublime for the Mac (I have a Mac also but prefer the PC), cut the text from the forum as you indicated, pasted it into the draw.newText, saved the file as a UTF-8 format and presto!

It worked!

Took the main.lua back into Windows and into EditPad Pro 7 and took a look at the draw.newText command and here is

what I found:

display . newText( storyGroup ,“©¾¥®£§” , 10 , 160 , textFont . Grobold , 54 )

So apparently UTF-8 requires a  before each character to work properly I’m guessing.

Moral of the story I guess is that UTF-8 does not necessarily mean 1 byte? It’s a little cryptic to me but you have set me straight.

So thank you for preventing me from tearing what little hair I have left out.

You can mark this one resolved.

Thanks again,

-Dennis

I’m by no means a UTF-8 expert, but it is multi-byte.  I think that when it sees a high bit set, it reads a value which is the number of bytes and then one byte as necessary for the character sequence or something.  I don’t think you can safely copy/paste that one character, though it probably would work for those specific characters.

I was having the same problem while working on a Windows machine. I use Notepad++ for editing. Changing to UTF-8 encoding did not work for me. HOWEVER, changing to “Encode in UTF-8 without BOM” did the trick! I guess there’s more than one flavor of UTF-8?

I was having the same problem while working on a Windows machine. I use Notepad++ for editing. Changing to UTF-8 encoding did not work for me. HOWEVER, changing to “Encode in UTF-8 without BOM” did the trick! I guess there’s more than one flavor of UTF-8?