12. PostScript Fonts Used by GMT

GMT uses the standard 35 fonts that come with most PostScript laserwriters. If your printer does not support some of these fonts, it will automatically substitute the default font (which is usually Courier). The following is a list of the GMT fonts:

../_images/GMT_App_G.png

The standard 35 PostScript fonts recognized by GMT.

Here is the source script for the figure above:

dy=-0.2222
y0=4.3
yy=4.0778
tr '",' '  ' < "${GMT_SOURCE_DIR}"/src/standard_adobe_fonts.h | awk '{print $2}' > tt.d
gmt begin GMT_App_G
gmt set GMT_THEME cookbook
gmt set MAP_FRAME_PEN thinner
gmt plot -R0/5.4/0/$y0 -Jx1i -B0 <<EOF
>
0.3	0
0.3	$y0
>
2.7	0
2.7	$y0
>
3	0
3	$y0
EOF
gmt text -Y${yy}i -F+f10p+jBC <<EOF
0.15	0.05	\\043
1.55	0.05	Font Name
2.85	0.05	\\043
4.15	0.05	Font Name
EOF
gmt plot <<EOF
0	0
5.4	0
EOF

let i=1
while [ $i -le 17 ]
do
	i1=$(( i-1 ))
	i2=$(( i1+17 ))
	k1=$i
	k2=$(( i+17 ))

	f1=$(sed -n ${k1}p tt.d)
	f2=$(sed -n ${k2}p tt.d)

	if [ $i1 -eq "12" ]; then
		f1="Symbol @%0%(Symbol)@%%"
	fi
	fn2=$i2
	gmt text -Y${dy}i -F+f+j <<EOF
0.15	0.03	10p,$i1		BC	$i1
0.4	0.03	10p,$i1		BL	$f1
2.85	0.03	10p,$fn2	BC	$i2
3.1	0.03	10p,$i2		BL	$f2
EOF
	let i=i+1
done

gmt text -Y${dy}i -F+f+j <<EOF
2.85	0.03	10p,Helvetica		BC	34
3.1	0.03	10p,ZapfDingbats	BL	ZapfDingbats @%0%(ZapfDingbats)@%%
EOF

gmt end show

For the special fonts Symbol (12) and ZapfDingbats (34), see the octal charts in Chapter Chart of Octal Codes for Characters. When specifying fonts in GMT, you can either give the entire font name or just the font number listed in this table. To change the fonts used in plotting basemap frames, see the man page for gmt.conf. For direct plotting of text-strings, see the man page for text.

12.1. Using non-default fonts with GMT

To add additional fonts that you may have purchased or that are available freely in the internet or at your institution, you will need to tell GMT some basic information about such fonts. GMT does not actually read or process any font files and thus does not know anything about installed fonts and their metrics. In order to use extra fonts in GMT you need to specify the PostScript name of the relevant fonts in the file PSL_custom_fonts.txt. We recommend you place this file in your GMT user directory (~/.gmt) as GMT will look there as well as in your home directory. Below is an example of a typical entry for two separate fonts:

LinBiolinumO      0.700    0
LinLibertineOB    0.700    0

The format is a space delimited list of the PostScript font name, the font’s height-point size-ratio, and a boolean variable that tells GMT to re-encode the font (if set to zero). The latter has to be set to zero as additional fonts will most likely not come in standard PostScript encoding. GMT determines how tall typical annotations might be from the font size ratio so that the vertical position of labels and titles can be adjusted to a more uniform typesetting. This ratio can be estimated from the height of the letter A for a unit font size. Now, you can set the GMT font parameters to your non-standard fonts:

gmt set FONT              LinBiolinumO \
        FONT_TITLE        28p,LinLibertineOB \
        PS_CHAR_ENCODING  ISO-8859-1 \
        MAP_DEGREE_SYMBOL degree

After setting the encoding and the degree symbol, the configuration part for GMT is finished and you can proceed to create GMT maps as usual. An example script is discussed in Example (31) Using non-default fonts in PostScript.

12.1.1. Embedding fonts in PostScript and PDF

If you have Type 1 fonts in PFA (Printer Font ASCII) format you can embed them directly by copying them at the very top of your PostScript file, before even the %!PS header comment. PFB (Printer Font Binary), TrueType or OpenType fonts cannot be embedded in PostScript directly and therefore have to be converted to PFA first.

However, you most likely will have to tell Ghostscript where to find your custom fonts in order to convert your GMT PostScript plot to PDF or an image with psconvert. When you have used the correct PostScript names of the fonts in PSL_custom_fonts.txt you only need to point the GS_FONTPATH environment variable to the directory where the font files can be found and invoke psconvert in the usual way. Likewise you can specify Ghostscript’s -sFONTPATH option on the command line with -C-sFONTPATH=/path/to/fontdir. Ghostscript, which is invoked by psconvert, does not depend on file names. It will automatically find the relevant font files by their PostScript names and embed and subset them in PDF files. This is quite convenient as the document can be displayed and printed even on other computers when the font is not available locally. There is no need to convert your fonts as Ghostscript can handle all Type 1, TrueType and OpenType fonts. Note also, that you do not need to edit Ghostscript’s Fontmap.

If you do not want or cannot embed the fonts you can convert them to outlines (shapes with fills) with Ghostscript in the following way:

gs -q -dNOCACHE -dNOSAFER -dNOPAUSE -dBATCH -dNOPLATFONTS \
   -sDEVICE=ps2write -sFONTPATH="/path/to/fontdir" \
   -sOutputFile=mapWithOutlinedFonts.ps map.ps

Note, that this only works with the ps2write device. If you need outlined fonts in PDF, create the PDF from the converted PostScript file. Also, psconvert cannot correctly crop Ghostscript converted PostScript files anymore. Use Heiko Oberdiek’s instead or crop with psconvert -A -Te before (See Example (31) Using non-default fonts in PostScript).

12.1.2. Character encoding

Since PostScript itself does not support Unicode fonts, Ghostscript will re-encode the fonts on the fly. You have to make sure to set the correct PS_CHAR_ENCODING with gmtset and save your script file with the same character encoding. Alternatively, you can substitute all non ASCII characters with their corresponding octal codes, e.g., \265 instead of μ. Note, that PostScript fonts support only a small range of glyphs and you may have to switch the PS_CHAR_ENCODING within your script.