Creating a Sun Symbol

QUESTION: Do you know how to create a circular, typographically correct sun symbol using IDL?

ANSWER: Well, I'm not sure I know what a “typographically correct” sun symbol looks like, but let's suppose we can find one. What we need is a true-type font that has a sun symbol in its character set. A quick search (although not exhaustive) in Google for a free true-type font that meets our requirements suggest the MARVOSYM symbol font might do the job for us. It's sun symbol is listed as having a value of 192 in this particular font character set.

I downloaded and unzipped the zip file containing the Marvosym font from the web page above. Then, I installed the font in the directory on my machine with my other true-type fonts. On my Windows machine, I found the Fonts Control Panel and chose "Install New Font" in the File menu of the Control Panel. I then browsed to the marvosym.ttf file and installed the font. A similar process exists on other machines. (I could have just dragged the marvosym.ttf file into my C:\WINDOWS\FONTS directory directly to install it.)

Once the font is installed, you can use it directly in IDL direct graphics plots and in PostScript output. For example, to create a direct graphics plot using the sun symbol, I typed the following code.

   Device, Set_Font='marvosym', /TT_FONT
   Plot, Indgen(11), Position=[0.15, 0.15, 0.9, 0.85], $
      Charsize=1.5, Font=1, Color=FSC_Color('black'), $
      Background=FSC_Color('ivory'), $
      Title='!3This is a sun symbol: !X' + String(192B)
   Device, Set_Font='Helvetica', /TT_FONT

Notice that I am using true-type fonts (Font=1) in these commands. The idea here is that the default font is set to the Marvosym font. Then, the title string is drawn with the Helvetica font (!3). Just before the sun symbol is drawn, the title string is switched back to the default font (!X) and the sun symbol is drawn. The results are shown in the figure below. You can clearly see that true-type fonts are not particularly beautiful fonts in IDL direct graphics windows. Notice that after the plot is drawn, the default font is set back to the Helvetica font. If I forget to do this, and I draw a second plot with true-type fonts, the characters in the text annotations will be in Marvosym symbols, not the normal text characters I expect.

Sun symbol using IDL direct graphics.
This figure shows the sun symbol used in an IDL direct graphics plot.
 

While disappointing in direct graphics plots, true-type fonts do look terrific when used in PostScript output. Here are the commands to make the same plot in a PostScript file.

   thisDevice = !D.Name
   Set_Plot, 'PS'
   Device, /ISOLATIN1, COLOR=1, BITS_PER_PIXEL=8, FILE='sun_symbol_test.ps'
   Device, Set_Font='marvosym', /TT_FONT
   Plot, Indgen(11), Position=[0.15, 0.15, 0.9, 0.85], $
      Charsize=1.5, Font=1, Color=FSC_Color('black'), $
      Title='!3This is a sun symbol: !X' + String(192B)
   Device, Set_Font='Helvetica', /TT_FONT
   Device, /Close_File
   Set_Plot, thisDevice

You see the PostScript output in the figure below. (I converted the PostScript file to a PDF file, so I could take a snapshot of the output for the figure.)

Sun symbol in the PostScript device.
This figure shows the sun symbol used in a PostScript plot.
 

Naturally, the symbol can be used as a subscript as well.

   thisDevice = !D.Name
   Set_Plot, 'PS'
   Device, /ISOLATIN1, COLOR=1, BITS_PER_PIXEL=8, FILE='sun_symbol_test.ps'
   Device, Set_Font='marvosym', /TT_FONT
   Plot, Indgen(11), Position=[0.15, 0.15, 0.9, 0.85], $
      Charsize=1.5, Font=1, Color=FSC_Color('black'), $
      Title='!3Units are R / R!D!X' + String(192B) + '!N'
   Device, Set_Font='Helvetica', /TT_FONT
   Device, /Close_File
   Set_Plot, thisDevice
Sun symbol as subscript in the PostScript device.
This figure shows the sun symbol used as a subscript in a PostScript plot.
 

Sun Symbol Using Object Graphics

I can do something similar in IDL object graphics output, but here I have to install the Marvosym font in a different place, and I have to make a change to an IDL file to allow the Marvosym font to be mapped correctly. I installed the marvosym.ttf file in the true-type fonts directory of the IDL distribution. Normally, this directory is found in the !IDL_DIR/resource/fonts/tt directory. (I actually just copied the marvosym.ttf file from my C:\WINDOWS\FONTS directory into this IDL directory.)

Also in this IDL true-type fonts directory is a file named ttfont.map. This is a text file that allows font mapping. Open the file and add the following line to the end of the file.

   "Marvosym"                     marvosym.ttf   0.75           1.0

The last three lines of my ttfont.map file now look like this.

   "Monospace Symbol"             tt9831z_.ttf	0.668945	1.0
   "ENVI Symbols"                 envisym_.ttf	1.0		1.0
   "Marvosym"                     marvosym.ttf  0.75            1.0

Save the ttfont.map file and you are ready to use the Marvosym fonts in an object graphics program. The idea is basically the same as before. Here is some simple code that you can run in IDL to illustrate the process.

   theText = '!3This is a sun symbol: !X' + String(192B)
   marsosymfont = Obj_New('IDLgrFont', 'Marvosym', Size=14)
   aString = Obj_New('IDLgrText', theText, Color=[0,0,0], $
      Location=[0.5, 0.5, 0.0], Alignment=0.5, Font=marsosymfont, $
      ENABLE_FORMATTING=1)
   XObjView, aString

And the figure below shows how I used this process to create a title for an object graphics plot. As you can see, true-type fonts look nice in object graphics output in IDL.

Sun symbol in an object graphics plot.
This figure shows the sun symbol used in an object graphics plot.
 

Yikes! Isn't There Something Simpler!?

This is all well and good, but it is a pain in the kester, too. If you can live with Hershey fonts, Craig Markwardt points out that something like this works perfectly OK.

   Plot, Indgen(11), Position=[0.15, 0.15, 0.9, 0.85], $
      Charsize=1.5, Color=FSC_Color('black'), $
      Background=FSC_Color('ivory'), $
      Title='This is a sun symbol: !Mn!X'

Or, if you have TexToIDL installed.

   Plot, Indgen(11), Position=[0.15, 0.15, 0.9, 0.85], $
      Charsize=1.5, Color=FSC_Color('black'), $
      Background=FSC_Color('ivory'), $
      Title='This is a sun symbol: ' + TexToIDL('\odot')
Simple sun symbol in an direct graphics plot.
This figure shows a simple way of producing the sun symbol used in a direct graphics
plot. Only Hershey fonts are allowed with this method.
 

Another method of producing a sun symbol is with the IDL program SunSymbol from the NASA Astronomy Library. This method works with Hershey fonts and with PostScript output. Here are the commands I used to produce the PostScript output shown in the figure below. Note that the program automatically shows the sun symbol as a subscripted symbol, and that the center dot is not exactly in the center of the circle in this method.

   thisDevice = !D.Name
   Set_Plot, 'PS'
   Device, COLOR=1, BITS_PER_PIXEL=8, FILE='nasa_sun_symbol_test.ps'
   Plot, Indgen(11), Position=[0.15, 0.15, 0.9, 0.85], $
      Charsize=1.5, Font=0, Color=FSC_Color('black'), $
      XTitle='M / M' + SunSymbol(FONT=0), $
      YTitle='Height (R' + SunSymbol(font=0)+')'
   Device, Set_Font='Helvetica', /TT_FONT
   Device, /Close_File
   Set_Plot, thisDevice
Sun symbol with NASA SunSymbol program.
PostScript output of the sun symbol, using the SunSymbol program.
 

Article Update

After this article was written Michael Williams pointed out that it is possible you may have a font with the sun symbol already on your computer. On a Macintosh, for example, the Apple Symbols true-type font has a sun symbol, and on Windows computers, the Arial Unicode MS font does as well. In fact, I found this font already installed on my Windows computer. Here is the code I used to produce a PostScript version of the plot above.

   thisDevice = !D.Name
   Set_Plot, 'PS'
   Device, /ISOLATIN1, COLOR=1, BITS_PER_PIXEL=8, FILE='sun_symbol_test.ps'
   Device, Set_Font='arial unicode MS', /TT_FONT
   Plot, Indgen(11), Position=[0.15, 0.15, 0.9, 0.85], $
      Charsize=2.0, Font=1, Color=FSC_Color('black'), $
      Background=FSC_Color('ivory'), $
      Title='!3This is a sun symbol: !X!Z(2609)'
   Device, Set_Font='Helvetica', /TT_FONT
   Device, /Close_File
   Set_Plot, thisDevice

The only thing different about this code is that I used the Unicode designation !Z(2609) to specify the sun symbol. I found the Unicode number by opening this font in the Character Map application that comes with Windows, selecting the sun symbol and reading the Unicode value. Here is what the output looked like.

Sun symbol with Arial Unicode MS font in Windows.
PostScript output of the sun symbol, using the Arial Unicode MS font in Windows.
 

Version of IDL used to prepare this article: IDL 7.0.3.

Google
 
Web Coyote's Guide to IDL Programming