A list of products available on this site
Documentation for XtraMania's xtras
Prices and links to the online store
Xtras, PDFs, samples
Have a question? Ask us!
Contacts
Logo. www.xtramaina.com  
Home Search E-mail
ActiveCompanion Usage/Common/Unicode support

ActiveCompanionSet xtras for Macromedia Director

Unicode Conversion Support

Macromedia Director (up to the current version MX 2004) uses MBCS text encoding. MBCS states for Multi Byte Code String. In MBCS each character is encoded by one or more bytes. Mapping of the particular character and its numerical code is based on the current Code Page (default for user's system). Some languages (English, French, German other European languages) do not use more than one byte for encoding one character. Other languages (Japanese, Arabic and other) do really use multi byte feature of MBCS.

Unicode defines numerical values for all known characters of almost all used languages. Unicode (or wide) character is normally encoded by two bytes, although hieroglyphs might be encoded with a couple of wide characters.
COM technology internally assumes that all text data is in Unicode. So, here comes the problem of conversion text inside VbScriptXtra at the moment of passing text data from Director to COM and vice versa.

Unicode to MBCS conversion always assumes some specific code page for MBCS encoding. Normally system default code page is used. In most cases the default code page provides correct conversion between Unicode and MBCS. However default code page might be incorrect choice for some multilingual applications build with Macromedia Director.

Consider an application that stores some text data in database. Application is expected to be distributed all over the World. Suppose text data in database is in French and it is encoded in Unicode. While application is being developed in France everything is fine since in France most systems probably has ANSI Latin 1 (1252) code page as a system default code page. When French text data in Unicode comes to Director through VbScriptXtra, it is being converted to MBCS with ANSI Latin 1 code page and then it is displayed on stage with fonts that know how to display ANSI Latin 1 characters.

What happens if we run this application under system with another default code page? For example with Cyrillic code page. Text data from database comes in Unicode. If the xtra tries to convert it by using default (Cyrillic) code page it most likely will be converted as some Latin characters and a lot of '?' questions, because certain characters that are in Latin 1 code page do not present in Cyrillic code page. So after this conversion we get some MBCS data, but French fonts will not be able to display it properly, since some characters have been replaced by questions during conversion. So end-user will not be able to see French text under Cyrillic system.

That is why VbScriptXtra provides a special CodePage property that controls which code page is used for text conversion between Unicode and MBCS. In the above example, even under Cyrillic system VbScriptXtra could convert Unicode text into MBCS with ANSI Latin 1 (1252) code page.

Note also that even though VbScriptXtra can convert Unicode text into certain code page, it does not fully solve the problem of displaying such text in Director. There is one more transformation left. It is rendering character codes to the correct glyphs with some font. There are several font encoding standarts. Some fonts have their glyphs marked with Unicode-base indexes (modern OpenType fonts). Using such fonts require MBCS to Unicode translation but it depends on the current system locale that may differ from the needed locale. So text is displayed correctly only if the system locale matches the expected one. Other fonts (older ttf fonts) may be encoded by default for the certain code page. These fonts may be used with Director to display proper glyphs without worrying about the current system locale. It is possible to display Chinese text on system with default locale set to Russian for example.

VbScriptXtra v2.3 offers even more functionality with handling Unicode text. COM Automation objects natively operates with Unicode text, so VbScriptXtra had to always translate Unicode to MBCS in order to represent it ro Director. Now VbScriptXtra supports special mode for handling Unicode. If UnicodeAsBinaryMode is set for the object, then Unicode text is returned via updated Binary wrapper whose ContentsType is set to #UnicodeString. It allows directly operate with Unicode data without translating it into MBCS. Binary objects containing Unicode data are properly typecasted into Unicode string when used as arguments to COM Automation objects.

So, there is another alternative that may solve the problem of displaying Unicode text in Director. Use Flash object as a text sprite. Flash (v7 and higher) handles text in Unicode. So, it is possible to make a Flash component that will accept Unicode text (as a hex string for example) and display it with one of system Unicode fonts. VbScriptXtra's Unicode features can provide a bridge between the Unicode text stored in database and Flash displaying Unicode text on Director's stage.

The sample below shows Unicode text translation with Binary wrapper.

vb = xtra("VbScriptXtra")

-- Create wrapper
s = vb.CreateWrapper( #UnicodeString )

s.String = "Some text"

put s
--"< VbScriptXtra, UnicodeString, Size: 18 byte(s) >"

put s.HexString
-- "53006F006D00650020007400650078007400"

put s.String
-- "Some text"

s.CodePage = 65001 -- UTF8 encoding
put s.String
-- "Some text'"

See detailed description of the CodePage property and other Unicode features of VbScriptXtra in PDF documentation. See MSDN for a list of possible code page indentifiers.

Use system helper wrapper to find out system default code page. Also it provides full control over keyboard layout. Multilingual application may automatically switch keyboard language and layout as needed.

Site homeSearchContact author © Eugene Shoustrov. www.xtramania.com