Font Objects
Font objects allow you to specify the type style and size used when rendering objects of the IDLgrText class. You can use either TrueType outline fonts or IDL's built-in Hershey vector fonts. IDL's default font is 12 point Helvetica regular.
Each destination object includes a GetFontnames method, which returns the list of available fonts that can be used in IDLgrFont objects. This method will only return the names of the available TrueType fonts. Hershey vector fonts will not be returned as they are constant—see Fonts (IDL Reference Guide) for more information. To return all of the TrueType fonts that can be displayed in a window object (oWindow), use the following code:
See the destination object's GetFontnames method for information on how to return fonts that match specific characteristics.
TrueType Fonts
IDL provides five TrueType outline fonts for use in font objects: Courier, Helvetica, Monospace Symbol, Symbol, and Times. Your system may support additional TrueType fonts —use them in the same way as those supplied by IDL.
A string containing the font name and modifiers defines the characteristics of a font object, as described in Creating Font Objects. The TrueType fonts provided by IDL support the following modifiers:
|
Font
|
Modifier
|
|---|---|
| Courier |
bold, italic |
| Helvetica |
bold, italic |
| Monospace Symbol |
none |
| Symbol |
none |
| Times |
bold, italic |
Hershey Fonts
IDL supplies a set of vector fonts designed by Dr. A.J. Hershey. See About Hershey Vector Fonts (IDL Reference Guide) for information on Hershey fonts.
Creating Font Objects
Fonts used by font objects are specified in a string constant constructed from a font name and one or more optional modifiers. When you create a font object, assign the font name string to the NAME property or use it as the IDLgrFont::Init Fontname argument. See the following sections for an introduction to creating and configuring font objects. See "IDLgrFont" (IDL Reference Guide) for all available options when creating font objects.
Specifying a TrueType Font
The font name is the name by which your computer system knows the font (Times for the Times Roman font, for example). Modifiers specify the weight, angle, and other attributes of the font (bold specifies a weight, italic an angle). The font name string looks like this:
where other_modifiers can be any other font property supported by a given font, such as a slant. For example, the font name string for Helvetica bold italic is:
The font name string for Times Roman Regular is:
While the font name must come first in the font name string, the order in which the modifiers are specified is not important. The following statement creates a font object using a bold version of the Times Roman font, with a size of 20 points by replacing the Fontname argument with 'times*bold':
See TrueType Fonts for a list of supported modifiers.
Specifying a Hershey Vector Font
To create a font object using a vector Hershey font, use a string of the format Hershey*fontnum where fontnum is the Hershey font's index number. The following statement creates a font object using the Duplex Roman Hershey font, with a size of 14 points:
See Hershey Vector Font Samples (IDL Reference Guide) for descriptions of the Hershey fonts shipped with IDL.
Assigning a Font Object to a Text Object
To use a font object, use the FONT keyword to the IDLgrText::Init method (or change the text object's font via the SetProperty method):
or
This last example prints the Angstrom symbol by specifying an octal code. See ISO Latin 1 Encoding (IDL Reference Guide) for details.
If no font object is specified, IDL uses the default font—12 point Helvetica.
Object Graphics Embedded Formatting Examples
Embedded formatting commands are in-line commands that allow you to position text and change fonts within a single line of text. The following examples use both the positioning commands and the font selection commands. All available embedded formatting commands are listed in Embedded Formatting Commands (IDL Reference Guide).
Tip
Set the ENABLE_FORMATTING property on the IDLgrText object to use formatting commands in Object Graphics.
For example, the following lines of code produce the same output as the Direct Graphics example output shown in Formatting Command Examples (IDL Reference Guide). This example applies embedded formatting commands that control text positioning.
oText = OBJ_NEW('IDLgrText', /ENABLE_FORMATTING)
oText->SetProperty, STRING='!LLower!S!EExponent!R!IIndex' + $
'!N Normal!S!EExp!R!IInd!N!S!U Up' + $
' !R!D Down!N!S!A Above!R!B Below'
XOBJVIEW, oText
You can also change what fonts are used within the text string. For example, you can use the special math symbols available in the Hershey vector font character set (Font 9). When you use the !M formatting command, this applies the font change to the single character immediately following the !M. Subsequent characters return to the preceding font. The following example produces the same equation as that shown in A Complex Equation (IDL Reference Guide).
; String to produce equation: SS = '!6F(s) = (2!4p)!e-1/2!n !mi!s!a!e!m' + STRING("44B) +$ '!r!b!i ' + '-!m' + STRING("44B) + $ '!nF(x)e !e-i2!4p!3xs!ndx' myHersheyFont = OBJ_NEW('IDLgrFont', NAME='hershey*5', SIZE=24) otext = OBJ_NEW('IDLgrText', /ENABLE_FORMATTING) oText->SetProperty, STRING=ss, FONT=myHersheyFont XOBJVIEW, oText
The font object in this example must use a Hershey font to create the desired results. If no font is specified, the default 12 point Helvetica (not a vector font) is used, and the formatting commands create a different result. See Changing Fonts within a String (IDL Reference Guide), which defines how formatting commands are applied to Hershey vector and TrueType fonts.
See Text Objects for details on creating Text objects.
Font Objects and Resource Use
Because font objects are relatively complex, each font object uses a relatively large amount of system resources. As a result, it is better to re-use an existing font object than to create a second identical font object.