intfiction.org

The Interactive Fiction Community Forum
It is currently Wed May 22, 2013 5:44 am

All times are UTC - 6 hours [ DST ]




Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Sun Jun 17, 2012 1:32 am 
Offline

Joined: Sun Apr 15, 2012 9:48 pm
Posts: 78
I know the Z-machine can do Unicode, sort of; but I'm bogging down on the details. How do I print an em-dash (Unicode U+2014), assuming I'm using Inform 6? Does the ability to display Unicode also depend on my interpreter? I'm most concerned with Parchment (ZVM, I think), but also interested in Frotz and/or Fizmo in a Linux terminal (UTF-8).

It's apparently not as easy as
Code:
print "@{2014}"


Top
 Profile Send private message  
 
PostPosted: Sun Jun 17, 2012 1:49 am 
Offline

Joined: Mon Jun 29, 2009 5:51 am
Posts: 288
Printing Unicode will depend on the capabilities of your interpreter and its display environment, including what fonts it has access to, but these days I would expect most interpreters to handle it pretty well.
Code:
print "@{2014}"

For this to work the character needs to be entered into the Zcharacter table, which has a few free slots (though not many). This would involve having a declaration at the top of the Inform 6 source like
Code:
Zcharacter table + '@{2014}';

It's often easier to just use the @print_unicode opcode from the Z-Machine 1.0 specification, like this:
Code:
@print_unicode $2014;

There's a little test file (Unicode.z5 and Unicode.inf) I wrote for testing such things that comes with Windows Frotz, which might help. Also worth reading is Roger Firth's Inform 6 FAQ entry on Unicode handling: http://www.firthworks.com/roger/informfaq/aa20.html


Top
 Profile Send private message  
 
PostPosted: Sun Jun 17, 2012 3:27 am 
Offline
User avatar

Joined: Wed Oct 14, 2009 4:02 am
Posts: 963
Web interpreters will have the best unicode support because browsers automatically find fonts with the characters you need if your normal font doesn't have them.


Top
 Profile Send private message  
 
PostPosted: Sun Jun 17, 2012 12:04 pm 
Offline

Joined: Mon Jun 29, 2009 5:51 am
Posts: 288
Dannii wrote:
Web interpreters will have the best unicode support because browsers automatically find fonts with the characters you need if your normal font doesn't have them.
Desktop interpreters can do this too: Windows Frotz uses Internet Explorer's MLang interface to achieve the same effect.


Top
 Profile Send private message  
 
PostPosted: Sun Jun 17, 2012 12:58 pm 
Offline

Joined: Sun Apr 15, 2012 9:48 pm
Posts: 78
DavidK wrote:
Code:
print "@{2014}"

For this to work the character needs to be entered into the Zcharacter table, which has a few free slots (though not many). This would involve having a declaration at the top of the Inform 6 source like
Code:
Zcharacter table + '@{2014}';

It's often easier to just use the @print_unicode opcode from the Z-Machine 1.0 specification, like this:
Code:
@print_unicode $2014;

There's a little test file (Unicode.z5 and Unicode.inf) I wrote for testing such things that comes with Windows Frotz, which might help. Also worth reading is Roger Firth's Inform 6 FAQ entry on Unicode handling: http://www.firthworks.com/roger/informfaq/aa20.html


Awesome! thanks! I had been trying almost exactly your first method, but without the "+" in the Zcharacter line. (Which now doesn't seem to make a difference.) Looks like Linux "frotz" doesn't do Unicode; everything comes through as question marks. But Linux "fizmo" does the right thing, and so does Parchment, via either method (Zcharacter plus "@{2014}", or @print_unicode).

Fortunately, Roger Firth's FAQ provides the solution! :)

Code:
[ Unicode c substitute exist;
    if (0-->31 < 1) { print (string) substitute; return; }
    @check_unicode c -> exist;
    if (exist & $0001) @print_unicode c;
    else print (string) substitute;
];

Called as Unicode($2014, "--"), this does what I want.


Top
 Profile Send private message  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 6 hours [ DST ]


Who is online

Users browsing this forum: Eric Eve and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group