(31) Using non-default fonts in PostScript — GMT 5.1.1 documentation

### Navigation

- index
- next
- previous
- Project Home »
- GMT 5.1.1 documentation »
- The GMT historical collection »
- Search:

# (31) Using non-default fonts in PostScript

This example illustrates several possibilities to create GMT plots with non-default fonts. As these fonts are not part of the standard PostScript font collection they have to be embedded in the PS- or PDF-file with Ghostscript. See also Appendix [sec:non-default-fonts] for further information. The script includes the following steps:

- create a `CUSTOM_font_info.d` file;
- set the GMT parameters `MAP_DEGREE_SYMBOL`, `PS_CHAR_ENCODING`, and `FONT`;
- replace the default Helvetica font in the GMT-PostScript-File with sed;
- create a PostScript-File with outlined fonts (optional);
- convert GMT’s PostScript output to PDF or any image format (optional).

The script produces the plot in Figure. All standard fonts have been substituted by the free OpenType fonts Linux Libertine (title) and Linux Biolinum (annotations). Uncomment the appropriate lines in the script to make a PostScript-file with outlined fonts or to convert to a PDF-file.

    #!/bin/bash
    #		GMT EXAMPLE 31
    #
    # Purpose:	Illustrate usage of non-default fonts in PostScript
    # GMT progs:	gmtset, pscoast, psxy, pstext, pslegend
    # Unix progs:	gs, awk, cat, rm
    #
    file=example_31
    ps=.ps
    ps_outlined=_outlined.ps
    eps_outlined=_outlined.eps

    # create file CUSTOM_font_info.d in current working directory
    # and add PostScript font names of Linux Biolinum and Libertine
    $AWK '{print $1, 0.700, 0}' << EOF > CUSTOM_font_info.d
    LinBiolinumO
    LinBiolinumOI
    LinBiolinumOB
    LinLibertineOB
    EOF

    # common settings
    gmt gmtset FORMAT_GEO_MAP ddd:mm:ssF \
    MAP_DEGREE_SYMBOL colon \
    MAP_TITLE_OFFSET 20p \
    MAP_GRID_CROSS_SIZE_PRIMARY 0.4c \
    PS_LINE_JOIN round \
    PS_CHAR_ENCODING ISO-8859-5 \
    FONT LinBiolinumO \
    FONT_TITLE 24p,LinLibertineOB \
    MAP_ANNOT_OBLIQUE 42

    # map of countries
    gmt pscoast -Dl -R-7/31/64/66/r -JL15/50/40/60/16c -P \
    	-Bx10g10 -By5g5 -B+t"Europe\072 Countries and Capital Cities" -A250 \
    	-Slightblue -Glightgreen -W0.25p -N1/1p,white -K > $ps

    # mark capitals
    gmt psxy europe-capitals-ru.csv -R -J -i0,1 \
    -Sc0.15c -G196/80/80 -O -K >> $ps

    # small EU cities
    $AWK 'BEGIN {FS=","} $4 !="" && $4 <= 1000000 {print $1, $2}' europe-capitals-ru.csv | \
    gmt psxy -R -J -Sc0.15c -W0.25p -O -K >> $ps

    # big EU cities
    $AWK 'BEGIN {FS=","} $4 > 1000000 {print $1, $2}' europe-capitals-ru.csv | \
    gmt psxy -R -J -Sc0.15c -W1.25p -O -K >> $ps

    # label big EU cities
    $AWK 'BEGIN {FS=","} $4 > 1000000 {print $1, $2, $3}' europe-capitals-ru.csv | \
    gmt pstext -R -J -F+f7p,LinBiolinumOI+jBL -Dj0.1c -Gwhite -C5% -Qu -TO -O -K >> $ps

    # construct legend
    cat << EOF > legend.txt
    G -0.1c
    H 10 LinBiolinumOB Population of the European Union capital cities
    G 0.15c
    N 2
    S 0.15c c 0.15c 196/80/80 0.25p 0.5c < 1 Million inhabitants
    S 0.15c c 0.15c 196/80/80 1.25p 0.5c > 1 Million inhabitants
    N 1
    G 0.15c
    L 8 LinBiolinumOB L Population in Millions
    N 6
    EOF

    # append city names and population to legend
    $AWK 'BEGIN {FS=","; f="L 8 LinBiolinumO L"}
      $4 > 1000000 {printf "%s %s:\n%s %.2f\n", f, $3, f, $4/1e6}' \
      europe-capitals-ru.csv >> legend.txt

    # reduce annotation font size for legend
    gmt gmtset FONT_ANNOT_PRIMARY 8p

    # plot legend
    gmt pslegend -R -J -Dx7.9c/12.6c/8.0c/BL \
    -C0.3c/0.4c -L1.2 -F+p+gwhite -O legend.txt >> $ps

    # make a PostScript and a PDF file with outlined fonts
    # unfortunately gmt ps2raster won't be able to crop that file correctly anymore
    # use Heiko Oberdiek's pdfcrop (http://code.google.com/p/pdfcrop2/) instead
    # or crop with gmt ps2raster -A -Te before
    #
    # a. remove GMT logo and crop EPS:
    #gmt ps2raster -P -Au -Te -C-sFONTPATH="/fonts" -Fex31CropNoLogo $ps
    # b. make PS with outlined fonts:
    #gs -q -sPAPERSIZE=a3 -dNOCACHE -dSAFER -dNOPAUSE -dBATCH -dNOPLATFONTS \
    #  -sDEVICE=pswrite -sFONTPATH="/fonts" -sOutputFile=$ps_outlined ex31CropNoLogo.eps
    # c. make croppepd EPS:
    #gs -q -dNOCACHE -dSAFER -dNOPAUSE -dBATCH -dEPSCrop -sDEVICE=epswrite \
    #  -sOutputFile=$eps_outlined $ps_outlined
    # d. make cropped PDF:
    #gmt ps2raster -P -A -Tf $ps_outlined
    # uncomment to do conversation to PDF and PNG
    # you will get a PDF with subsetted TrueType/PostScript fonts embedded
    # which you can still edit with your favorite vector graphics editor
    #export GS_FONTPATH="/fonts"
    #gmt ps2raster -P -A -Tf $ps
    #gmt ps2raster -P -A -Tg -E110 $ps
    # clean up
    rm -f gmt.history gmt.conf CUSTOM_font_info.d legend.txt ex31CropNoLogo.eps

    exit 0

Using non-default fonts in PostScript.

### Navigation

- index
- next
- previous
- Project Home »
- GMT 5.1.1 documentation »
- The GMT historical collection »
- Search: