Categories | Alphabetical | Classes | All Contents | [ < ] | [ > ]

About TrueType Fonts


Beginning with version 5.2, five TrueType font families are included with IDL. The fonts included are:

Font Family
Italic
Bold
BoldItalic
Courier
Courier Italic
Courier Bold
Courier Bold Italic
Helvetica
Helvetica Italic
Helvetica Bold
Helvetica Bold Italic
Monospace Symbol
 
 
 
Times
Times Italic
Times Bold
Times Bold Italic
Symbol
 
 
 

When TrueType fonts are rendered on an IDL graphics device or destination object, the font outlines are first scaled to the proper size. After scaling, IDL converts the character outline information to a set of polygons using a triangulation algorithm. When text in a TrueType font is displayed, IDL is actually drawing a set of polygons calculated from the font information. This process has two side effects:

  1. Computation time is used to triangulate and create the polygons. This means that you may notice a slight delay the first time you use text in a particular font and size. Once the polygons have been created, the information is cached by IDL and there is no need to re-triangulate each time text is displayed. Subsequent uses of the same font and size happen quickly.
  2. Because the TrueType font outlines are converted into polygons, you may notice some chunkiness in the displayed characters, especially at small point sizes. The smoothness of the characters will vary with the quality of the TrueType font you are using, the point size, and the general smoothness of the font outlines.

Using TrueType Fonts

To use the TrueType font system with IDL Direct Graphics, either set the value of the IDL system variable !P.FONT equal to 1 (one), or set the FONT keyword to on one of the Direct Graphics routines equal to 1.

Once the TrueType font system is selected, use the SET_FONT keyword to the DEVICE routine to select the font to use. The value of the SET_FONT keyword is a font name string. The font name is the name by which IDL knows the font; the names of the TrueType fonts included with IDL are listed under About TrueType Fonts. Finally, specify the TT_FONT keyword in the call to the DEVICE procedure. For example, to use Helvetica Bold Italic, use the following statement:

DEVICE, SET_FONT='Helvetica Bold Italic', /TT_FONT 

To use Times Roman Regular:

DEVICE, SET_FONT='Times', /TT_FONT 

IDL's default TrueType font is 12 point Helvetica regular.

Specifying Font Size

To specify the size of a TrueType font, use the SET_CHARACTER_SIZE keyword to the DEVICE procedure. The SET_CHARACTER_SIZE keyword takes a two-element vector as its argument. The first element specifies the width of the "average" character in the font (in pixels) and calculates a scaling factor that determines the height of the characters. (It is not important what the "average" character is; it is used only to calculate a scaling factor that will be applied to all of the characters in the font.) The second element of the vector specifies the number of pixels between baselines of lines of text.

The ratio of the "average" character's height to its width differs from font to font, so specifying the same value [x, y] to the SET_CHARACTER_SIZE keyword may produce characters of different sizes in different fonts.

Note
While the first element of the vector specified to SET_CHARACTER_SIZE is technically a width, it is important to note that the width value has no effect on the widths of individual characters in the font. The width value is used only to calculate the appropriate scaling factor for the font.

For example, the following IDL commands display the word "Hello There" on the screen in Helvetica Bold, in letters based on an "average" character that is 70 pixels wide, with 90 pixels between lines:

DEVICE, FONT='Helvetica Bold', /TT_FONT, 
SET_CHARACTER_SIZE=[70,90] 
XYOUTS, 0.1, 0.5, 'Hello!CThere' 

You can also use the CHARSIZE keyword to the graphics routines or the CHARSIZE field of the !P System Variable to change the size of characters to a multiple of the size of the currently-selected character size. For example, to create characters one half the size of the current character size, you could use the following command:

XYOUTS, 0.1, 0.5, 'Hello!CThere', CHARSIZE=0.5 

Note that changing the CHARSIZE adjusts both the character size and the space between lines.

Using Embedded Formatting Commands

Embedded formatting commands allow you to position text and change fonts within a single line of text. A subset of the embedded formatting commands available for use with the vector fonts are also available when using the TrueType font system. See Embedded Formatting Commands for a list of in-line formatting commands.

IDL TrueType Font Resource Files

The TrueType font system relies on a resource file named ttfont.map, located in the resource/fonts/tt subdirectory of the IDL directory. The format of the ttfont.map file is:

FontName    FileName    DirectGraphicsScale    ObjectGraphicsScale 

where the fields in each column must be separated by white space (spaces and/or tabs). The fields contain the following information

The Fontname field contains the name that would be used for the SET_FONT keywords to the DEVICE routine.

The Filename field contains the name of the TrueType font file. On UNIX platforms, IDL will search for the file specified in the FileName field in the current directory (that is, in the resource/fonts/tt subdirectory of the IDL directory) if a bare filename is provided, or it will look for the file in the location specified by the fully-qualified file name if a complete path is provided. Because different platforms use different path-specification syntax, we recommend that you place any TrueType font files you wish to add to the ttfont.map file in the resource/fonts/tt subdirectory of the IDL directory. On Windows platforms, this entry may be '*', in which case the font will be loaded from the operating system font list, but that the following two scale entries will be honored.

The DirectGraphicsScale field contains a correction factor that will be applied when choosing a scale factor for the glyphs prior to being rendered on a Direct Graphics device. If you want the tallest character in the font to fit exactly within the vertical dimension of the device's current character size (as set via the SET_CHARACTER_SIZE keyword to the DEVICE procedure), set the scale factor equal to 1.0. Change the scale factor to a smaller number to scale a smaller portion of the tallest character into the character size.

For example, suppose the tallest character in your font is "Ã". Setting the scale factor to 1.0 will scale this character to fit the current character size, and then apply the same scaling to all characters in the font. As a result, the letter "M" will fill only approximately 85% of the full height of the character size. To scale the font such that the height of the "M" fills the vertical dimension of the character size, you would include the value 0.85 in the scale field of the ttfont.map file.

The ObjectGraphicsScale field contains a correction factor that will be applied when choosing a scale factor for the glyphs prior to being rendered on a Object Graphics device. (This field works just like the DirectGraphicsScale field.) This scale factor should be set to 1.0 if the maximum ascent among all glyphs within a given font is to fit exactly within the font size (as set via the SIZE property to the IDLgrFont object).

Adding Your Own Fonts

To add a your own font to the list of fonts known to IDL, use a text editor to edit the ttfont.map file, adding the FontName, FileName, DirectGraphicsScale, and ObjectGraphicsScale fields for your font. You will need to restart IDL for the changes to the ttfont.map file to take effect. On Windows systems, you can use fonts that are not mentioned in the ttfont.map file, as long as they are installed in the Fonts control panel, as described below.

Warning
If you choose to modify the ttfont.map file, be sure to keep a backup copy of the original file so you can restore the defaults if necessary. Note also that applications that use text may appear different on different platforms if the scale entries in the ttfont.map file have been altered.

Where IDL Searches for Fonts

The TrueType font files included with IDL are located in the resource/fonts/tt subdirectory of the IDL directory. When attempting to resolve a font name (specified via the FONT keyword to the DEVICE procedure), IDL will look in the ttfont.map file first. If it fails to find the specified font file in the ttfont.map file, it will search for the font file in the following locations:

UNIX

No further search will be performed. If the specified font is not included in the ttfont.map file, IDL will substitute Helvetica.

Microsoft Windows

If the specified font is not included in the ttfont.map file, IDL will search the list of fonts installed in the system (the fonts installed in the Font control panel). If the specified font is not found, IDL will substitute Helvetica.


Categories | Alphabetical | Classes | All Contents | [ < ] | [ > ]