Fanning Software Consulting

Embedding Greek Characters in Object Graphics Text

QUESTION: Is it possible to include special characters or even Greek symbols in an object graphics text object? It seems to me it is not possible to change fonts within a single text string.

ANSWER: Yes, it is possible. All you have to do it set the ENABLE_FORMATTING keyword when you create the IDLgrText object and you can use the usual embedded text formatting commands available to you in direct graphics. You must also make sure you are using the Symbol true-type font that is distributed with IDL. What is difficult is finding the greek formatting commands in the IDL documentation!

The secret is to look up "true-type fonts" in the index of the IDL On-Line Help. Then choose the "samples" sub-topic. (On some on-line help systems I've had to use "fonts' in the index, then find "true-type fonts".) You should find yourself on a True-Type Font Samples page. Now click the "Symbol" link and you are looking at our favorite chart of octal values. Remember how to read this. Find the symbol you are interested in. Look at its row number. Multiply that number by 10 and add it to the symbol's column number. This is the octal value of the symbol.

Let's take an example. Find the small epsilon symbol. Its row number is "14x" (the x is there only to remind you to multiply the 14 by 10) and its column number is "5". Ok, then, 14 times 10 plus 5 is 145. But remember this is an octal value! In IDL, we represent an octal value like this:

   IDL> octal_value = "145B

Notice the double quote in front of the value, but no ending quotes. The B is there just to make this value a byte value. We do this because byte values are easily converted to strings.

We can express this value in various ways. For example, we can express it as a decimal value:

   IDL> Print, octal_value
        101

We can express it as a hexadecimal value:

   IDL> Print, octal_value, Format='(Z4)'
        65

We can even express it as a string value (the letter e):

   IDL> Print, String(octal_value)
        e

All of these ways of expressing the value are equivalent. And we can use whatever format is convenient when we are formulating our string that contains this character glyph. All we have to do it to be sure the Symbol font is selected. With embedded formatting enabled, we use the !9 escape characters to select the Symbol font. These ways of embedding an epsilon character are all equivalent.

  IDL> str = 'This is the Greek epsilon character: (!9e!X)'
  IDL> str = 'This is the Greek epsilon character: (!9' + String("145B) + '!X)'
  IDL> str = 'This is the Greek epsilon character: (!9' + String(101B) + '!X)'
  IDL> str = "This is the Greek epsilon character: (!9" + String('65'xB) + "!X)"

To display this as an object graphics text object, choose the first of the formulations above, and then type this:

  IDL> oString = Obj_New('IDLgrText', Enable_Formatting=1, str)
  IDL> XObjView, oString 

You will see the text in the window. (If you don't, grab the XObjView window and re-size it. Now you should see the text. I don't know why this is needed, occasionally.)

Google
 
Web Coyote's Guide to IDL Programming