Displaying Displaying Non-English Text on Widgets
QUESTION: If I want to display some non-English text with accented characters (eg. Source des donnêes) in a widget element, it doesn't display properly, as you can see if the figure below. Is this an IDL issue?
IDL> msg = Dialog_Message('Source des données', /CENTER, /INFO)
|Non-English language characters do not
always render properly in widget elements.
ANSWER: Bernat Puigdomènech provides the answer and a solution.
Yes, this is an IDL issue. In IDL, all characters are coded using the ASCII table and values less than 32 or greater than 126 do not have printable representations.
The ASCII table (American Standard Code for Information Interchange) is the character-enconding scheme based on the ordering of the English alphabet. Computers can only understand numbers and the ASCII table codes the numerical representation of every English character.
For example, if you want to get the ASCII value of the character S, you can do this.
IDL> Print, Byte('S') 83
The problem here is that some characters, like é, are not included in the English alphabet and when you want to get the associated binary code, IDL will give you something like this.
IDL> Print, Byte('é') 195 169
The character é is not included in the ASCII table and that's why IDL gives you two numbers. Because of that, the widget text is not displayed properly.
Instead of using the default ASCII table used by IDL, you can use the ANSI character table. This table includes the ASCII character set (values 0 to 127), plus an extend character set (values from 128 to 255). With this extension you can have the numerical representation of any character you want. In the ANSI table, the code for é is 233.
Using this principle, the program ANSI_VALUE parses an input string (or array of strings) and converts all the characters to its binary representation. Please note that displaying the program in a browser will likely result in these special characters being mangled. It would be better to choose the Save Link As... button and save the file to disk instead.
Now, you can try this.
IDL> msg = Dialog_Message(ANSI_Value('Source des données'), /CENTER ,/INFO)
Voilà! You will be able to represent any character you want, as you can see in the figure below.
|The ANSI_Value program converts
non-English characters to the proper
representation for widget display.
Version of IDL used to prepare this article: IDL 7.0.1.