Setting Character Attributes

Plplot uses two separate font systems to display characters. The traditional system uses Hershey fonts which are available for all device drivers, while the recently introduced unicode system is currently available only for the ps, psc, png, jpeg, and gif devices. For details on how to enable the unicode font system for additional device drivers using the FreeType library, see the Section called Adding FreeType Library Support to Bitmap Drivers.

Hershey fonts

There are two Hershey font character sets included with PLplot. These are known as the standard and extended character sets. The standard character set is a subset of the extended set. It contains 177 characters including the ascii characters in a normal style font, the Greek alphabet and several plotter symbols. The extended character set contains almost 1000 characters, including four font styles, and several math, musical and plotter symbols.

The extended character set is loaded into memory automatically when plstar or plstart is called. The standard character set is loaded by calling plfontld. The extended character set requires about 50 KBytes of memory, versus about 5 KBytes for the standard set. plfontld can be used to switch between the extended and standard sets (one set is unloaded before the next is loaded). plfontld can be called before plstar.

When the extended character set is loaded there are four different font styles to choose from. In this case, the routine plfont sets up the default Hershey font for all character strings. It may be overridden for any portion of a string by using an escape sequence within the text, as described below. This routine has no effect when the standard font set is loaded. The default font (1) is simple and fastest to draw; the others are useful for presentation plots on a high-resolution device.

The font codes are interpreted as follows:

Unicode fonts

The advantages of the unicode fonts over the more traditional PLplot Hershey fonts are the availability of many additional glyphs (including mathematical symbols and glyphs from other than western-European languages) and much better display of characters on computer screens using anti-aliasing and hinting. Unicode fonts are obtained by specifying a command-line option of -drvopt text for the devices (currently ps, psc, png, jpeg, gif, and wingcc) where it has been implemented.

For the ps and psc devices, there is a fixed relationship between the FCI (font characterization integer, see the Section called FCI) and the actual Type 1 fonts that are being used. This fixed relationship is specified in the Type1Lookup array in include/plfci.h. This array maps the font-family attributes of sans-serif, serif, monotype, script, and symbol to the standard postscript font families called Helvetica, Times-Roman, Courier, Times-Roman, and Symbol. (There is no script font family amongst the 35 standard Type 1 postscript fonts so that is why we map the font-family attribute of script to Times-Roman.) Similarly, this array maps the font-style attributes of upright, italic or oblique and the font-weight attributes of medium or bold to the appropriate variety of the Helvetica, Times-Roman, Courier, and Symbol font families that are part of the 35 standard Type 1 postscript fonts. These standard postscript fonts are normally installed on a user's system using the gsfonts package.

For the devices handled by the FreeType library (currently png, jpeg, and gif) there is a configurable relationship between the FCI (font characterization integer, see the Section called FCI) and the TrueType fonts that are actually used.

On Unix/Linux systems, the TrueType fonts corresponding to the 30 possible valid FCIs can be specified using ./configure options. (Use ./configure --help to see the possibilities and also the default values for the fonts.) These ./configure defaults for the 30 possibilites are taken from fonts available from the ttf-freefont font package. We recommend this font package because it has a rather complete set of glyphs for most unicode blocks. (We also recommend the gucharmap application for determining other unicode font possibilities on your system that are available via the FreeType library.)

On Windows systems, the fixed default TrueType fonts are specified in the include/plfci.h file. (NOT PROGRAMMED YET, so this statement will probably NEED REVISION.)

For all systems, the 30 possible TrueType fonts can be specified at run time using the following environment variables:

On Unix/Linux systems if these environment variables are not specified with an absolute path starting with "/", then the absolute path is specified by the configured default (see ./configure --help) or at run time with the environment variable PLPLOT_FREETYPE_FONT_DIR.

FCI

We specify the properties of unicode fonts with the FCI (font characterization integer). The FCI is a 32-bit unsigned integer whose most significant hexadecimal digit is marked with an 0x8 (0x80000000 is ORed with the FCI value to mark it) to distinguish it from a unicode (UCS4) integer (whose maximum value 0x7fffffff). Users obtain the current FCI by calling plgfci and store a new FCI to be used at the start of each subsequent string using plsfci. Independent hexadecimal values within the FCI are characterized by the hexdigit and hexpower. The hexpower is defined as the power of 16 or number of hexadecimal places to the left of the "decimal place" in the FCI where the hexdigit is stored. The interpretation of the hexdigit and hexpower values in the FCI are given in Table 3-3.

Table 3-3. FCI interpretation

 hexdigit -->01234
Font attributehexpower     
font-family0sans-serifserifmonospacescriptsymbol
font-style1uprightitalicoblique  
font-weight2mediumbold   

Note the maximum value of hexdigit is 7 and the maximum value of hexpower is 6 so there is substantial room for expansion of this scheme. On the other hand, since each font attribute is independent of the rest, what is implemented now gives us a maximum of 30 different font possibilities which is probably more than enough for most plotting purposes.

Escape sequences in text

The routines which draw text all allow you to include escape sequences in the text to be plotted. These are character sequences that are interpreted as instructions to change fonts, draw superscripts and subscripts, draw non-ASCII (e.g. Greek), and so on. All escape sequences start with a number symbol (#) by default. Some language interfaces have the capability of changing this default, but we will assume (#) in the remaining documentation of the escape sequences.

The following escape sequences are defined:

Sections of text can have an underline or overline appended. For example, the string S(freq) is obtained by specifying "#+S#+(#-freq#-)".

Greek letters are obtained by #g followed by a Roman letter. Table 3-4 shows how these letters map into Greek characters.

Table 3-4. Roman Characters Corresponding to Greek Characters

RomanABGDEZYHIKLM
GreekΑΒΓΔΕΖΗΘΙΚΛΜ
RomanNCOPRSTUFXQW
GreekΝΞΟΠΡΣΤΥΦΧΨΩ
Romanabgdezyhiklm
Greekαβγδεζηθικλμ
Romanncoprstufxqw
Greekνξοπρστυφχψω

The escape sequences #fn, #fr, #fi, #fs, and #(nnn) are designed for the four Hershey fonts, but an effort has been made to allow some limited forward compatibility so these escape sequences have a reasonable result when unicode fonts are being used. However, for maximum flexibility when using unicode fonts, these 5 escape sequences should be replaced by using the 4 escape sequences #[nnn], #<0x8nnnnnnn>, #<0xmn>, or #<FCI COMMAND STRING/> as appropriate.

Character size adjustment

The routine plschr is used to set up the size of subsequent characters drawn. The actual height of a character is the product of the default character size and a scaling factor. If no call is made to plschr, the default character size is set up depending on the number of subpages defined in the call to plstar or plstart, and the scale is set to 1.0. Under normal circumstances, it is recommended that the user does not alter the default height, but simply use the scale parameter. This can be done by calling plschr with def = 0.0 and scale set to the desired multiple of the default height. If the default height is to be changed, def is set to the new default height in millimeters, and the new character height is again set to def multiplied by scale.

The routine plssym sets up the size of all subsequent characters drawn by calls to plpoin and plsym. It operates analogously to plschr as described above.