Board index FlightGear Development Nasal

Nasal/Canvas and character encoding?

Nasal is the scripting language of FlightGear.

Nasal/Canvas and character encoding?

Postby Necolatis » Fri May 05, 2017 4:01 am

Hello,

I would really like to put some Swedish ÄÖÅ characters into my canvas by using Nasal.

Sometimes I am lucky and and got one to work, but most of the time it gets to be scrambled chars.

I suspect Canvas has no problems doing it, but its Nasal that gets in the way.

So questions:
Can I possibly define them via escape chars?
What file encoding do Nasal expect when it loads a file?
Are there some methods that ruins these characters.
"Airplane travel is nature's way of making you look like your passport photo."
— Al Gore
User avatar
Necolatis
 
Posts: 2238
Joined: Mon Oct 29, 2012 1:40 am
Location: EKOD
Callsign: Leto
IRC name: Neco
Version: 2020.3.19
OS: Windows 10

Re: Nasal/Canvas and character encoding?

Postby Philosopher » Mon May 08, 2017 6:47 pm

Hey! I guess I'm going to pop in for a quick comment!

I'm pretty sure everything is UTF-8 encoded... at least I would hope that would be the case.

If you look on http://graphemica.com/%C3%84 (my favorite character website), for example, it lists the utf-8 as "0xC3 0x84" (two hexadecimal digits)

For Nasal, it looks like this would correspond to "\xC3\x85" as an escape sequence. This will ensure that it is indeed utf-8 encoded, regardless of like file and editor settings.

So I would try that. I don't know of anything else that would get in the way.

Last I recall (ahem, a couple years ago), Nasal and Canvas did indeed support special characters, so I hope it works!
Philosopher
 
Posts: 1593
Joined: Sun Aug 12, 2012 7:29 pm

Re: Nasal/Canvas and character encoding?

Postby Philosopher » Mon May 08, 2017 6:57 pm

If you're curious, the hexadecimal escapes are parsed here: https://sourceforge.net/p/flightgear/si ... lex.c#l205

The escape mechanism could readily be expanded to support better escapes, like the \uXXXX the comment mentions. If that is done, Ä would be \u00C4, and it would encode it in utf-8 I suppose. But dealing with character formats is not the most fun.
Philosopher
 
Posts: 1593
Joined: Sun Aug 12, 2012 7:29 pm

Re: Nasal/Canvas and character encoding?

Postby Necolatis » Wed May 10, 2017 5:03 pm

Very helpful, thank you.

However I found at least 2 errors in nasal (which sadly is something I need):

1 - If the char is extracted from a string using substr() and the length 1 is specified in the substr, it will take only first half of the the 2 escape chars. :(
2 - size() reports wrong size for those chars.

Those 2 errors makes it really hard to process strings in nasal with ÅÖÄ.

PS. Also it seems not all Canvas font supports them, but the mono-spaced font does, which is what I use anyway.
"Airplane travel is nature's way of making you look like your passport photo."
— Al Gore
User avatar
Necolatis
 
Posts: 2238
Joined: Mon Oct 29, 2012 1:40 am
Location: EKOD
Callsign: Leto
IRC name: Neco
Version: 2020.3.19
OS: Windows 10

Re: Nasal/Canvas and character encoding?

Postby Necolatis » Wed May 10, 2017 5:38 pm

I managed to work around those 2 faults. This is my method for transforming a horizontal string into a vertical string:

Code: Select all
   vertStr: func (str) {
      me.compiled = "";
      for(var i = 0; i < size(str); i+=1) {
         me.sub = substr(str,i,1);
         if (me.sub == "\xC3") {
            # trick to read in Swedish special chars
            me.sub = substr(str,i,2);
            i += 1;
         }
         me.compiled = me.compiled~me.sub~(i==(size(str)-1)?"":"\n");
      }
      return me.compiled;
   },
"Airplane travel is nature's way of making you look like your passport photo."
— Al Gore
User avatar
Necolatis
 
Posts: 2238
Joined: Mon Oct 29, 2012 1:40 am
Location: EKOD
Callsign: Leto
IRC name: Neco
Version: 2020.3.19
OS: Windows 10


Return to Nasal

Who is online

Users browsing this forum: No registered users and 1 guest