Search code examples
ghostscriptpostscript

How to use custom fonts in Ghostscript/PostScript?


I convert a PostScript file to PDF by Ghostscript. I have a problem embedding/installing Type 1 fonts.

  1. For installing Type 1 Font, I can add the PFA file path to Ghostscript Fontmap, which should be in /usr/share/ghostscript/version/FONTMAP, but I have no such file in /usr/share/ghostscript/9.50` or similar folders on Ubuntu 20.04.
  2. How can I include the font file directly within the script:

Instead of

/Times-Bold findfont 10 scalefont setfont

something like

(/home/font.pfa) 10 scalefont setfont
  1. Does PostScript/Ghostscript use AFM file data or read the glyph widths or just from the glyph structure provided in PFA file?

Solution

    1. The fonts and Fontmap file can be placed in several directories. Here is a typical search path:

      /usr/share/ghostscript/9.52/Resource/Init/Fontmap

      /usr/share/ghostscript/9.52/lib/Fontmap

      /usr/share/ghostscript/9.52/Resource/Font/Fontmap

      /usr/share/ghostscript/fonts/Fontmap

      /usr/share/fonts/Type1/Fontmap

      /usr/share/fonts/Fontmap

    2. I sometimes use fonts that are not installed in the search path just in the current working directory. I use the gs -P and either of these work:

      (font.pfa) 12 selectfont

      /font.pfa 12 selectfont

    The search path can also be modified by adding the directories to the GS_FONTPATH or GS_LIB environment variables.

    1. The AFM file is not mandatory and the metrics can be obtained from the font alone. Some programs use the AFM file instead of the actual fonts and so they are needed for those programs.