Font Control

## Font Control in GrADS

Hershey Fonts
Cairo Fonts
Controlling Font Size
Temporary Overrides
Examples

### Hershey Fonts

GrADS has traditionally used the Hershey vector fonts for all text displays. The Hershey fonts are drawn as a collection of line segments, and can be rotated or scaled (stretched) in the X or Y direction; this makes them extremely flexible for different applications in GrADS. The Hershey fonts are defined in a set of font files, which are part of the GrADS distribution and should be stored in a directory named by the GADDIR environment variable. The font style is controlled with the `set font` command. Font numbers 0-5 are provided by GrADS (definitions given below); numbers 6-9 are reserved for additional user-defined Hershey font files. The script font.gs will display all the characters in a given font set.

    font 0 -- Simplex Roman
    font 1 -- Complex Roman
    font 2 -- Complex Italic
    font 3 -- Complex Greek
    font 4 -- Duplex Roman
    font 5 -- Triplex Roman

### Cairo Fonts

Beginning with GrADS version 2.1.a0, additional fonts are available with the Cairo graphics library. GrADS employs Cairo's "toy" font API; it is simpler to implement, fast, and meets GrADS's needs for drawing text. Cairo uses the freetype2 font library, which supports a number of scalable font formats including TrueType, Type 1, OpenType, X11 PCF, and Windows FNT. Whether GrADS will support all these font types depends on if they are available on your particular system. On macintosh OSX systems, available fonts are generally in two directories: `/Library/Fonts` and `/System/Library/Fonts/`. On unix systems, look in `/usr/share/fonts/` and `/usr/share/X11/fonts/`. Unfortunately, with the "toy" API, there is no way to list available font family names. Three generic family names are built-in as GrADS defaults: sans-serif, serif, and monospace. These three pre-defined default fonts correspond to font numbers 10-12. Font numbers 13-99 are reserved for user-defined font names, which are specified with the `set fontdef` command. If the user-defined font family is not available, then the display defaults to font 10 (sans-serif) . If your build of GrADS is not enabled with the Cairo graphics library, you will get an error message if you use `set font` to try to set a font number greater than 9.

### Controlling Font Size

The `set strsiz` command controls the font size for Hershey and Cairo fonts. Because the Hershey fonts are vector-based, you can give different scaling factors for the width and height of the letters and the font will stretch accordingly. For Cairo fonts, only one scaling factor (the vertical size) is appropriate -- the fonts do not deform in the X or Y dimension, they simply get bigger or smaller. If the vertical size is not given with `set strsiz`, the horizontal size will be used instead.

### Temporary Overrides

Hershey fonts correspond to single-digit font numbers; Cairo fonts correspond to double-digit font numbers. When you invoke the `set font` command and the font number is between 0 and 9, you are in hershey mode. If the font number is between 10 and 99, you are in cairo mode. Hershey and Cairo fonts cannot be mixed together in the same string.

Font Override:
To temporarily override the font in a string of text, use the back quote character (`). When you are in hershey mode, a back quote followed by a single digit selects that font number for the remainder of the string. When you are in cairo mode, a back quote followed by 'f' and a double-digit number selects that font number for the remainder of the string. See examples below.

Text Position Override:
It is also possible to use the back quote to change the position of the text, to draw a string above or below the base line for subscripts or superscripts. A back quote followed by the letter a (`a) will draw the subsequent text in the string as a superscript (above normal). A back quote followed by the letter b (`b) will draw the subsequent text in the string as a subscript (below normal). A back quote followed by the letter n (`n) will draw the subsequent text in the string in a normal position, to undo the effects of `a or `b. The use of the back quote to override the font works with the draw string command, contour labels, titles, axis labels, etc. The text position overrides `a, `b, and `n work in both hershey mode and cairo mode.

Degree Symbol:
If you are in hershey mode, you can draw a degree symbol by drawing a period with font number 3 (`3.) If you are in cairo mode, you can draw a degree symbol with a backquote followed by the letter d (`d). See examples below.

### Examples

    Hershey Mode:
    set font 0
    draw string 1.5 1.25 `1use font 2 to `2emphasize `1a particular word
    draw string 1.5 2.25 use font 3 for `3greek `0letters
    draw string 1.5 3.25 `3p`0r`a2`n = area of a circle
    draw string 1.5 4.25 label temperatures in `3.`0C or `3.`0F

    Cairo Mode:
    set font 10
    draw string 1.5 1.25 use font 11 for `f11serif`f10 and font 12 for `f12monospace
    set fontdef 13 symbol
    draw string 1.5 2.25 use symbol font for `f13greek`f10 letters

    draw string 1.5 4.25 label temperatures in `dC or `dF