The following table summarizes the font capabilities of the various FOP renderers:
Renderer | Base-14 | AWT/OS | Custom | Custom Embedding |
---|---|---|---|---|
yes | no | yes | yes | |
PostScript | yes | no | yes | yes |
TXT | yes (used for layout but not for output) | no | yes (used for layout but not for output) | no |
AWT | if available from OS | yes | yes | n/a (display only) |
if available from OS | yes | yes | controlled by OS printer driver | |
RTF | n/a (font metrics not needed) | n/a | n/a | n/a |
MIF | n/a (font metrics not needed) | n/a | n/a | n/a |
SVG | if available from OS | yes | no | no |
XML | yes | no | yes | n/a |
The Adobe PDF Specification specifies a set of 14 fonts that must be available to every PDF reader: Helvetica (normal, bold, italic, bold italic), Times (normal, bold, italic, bold italic), Courier (normal, bold, italic, bold italic), Symbol and ZapfDingbats.
The AWT family of renderers (AWT, Print, SVG), use the Java AWT libraries for font metric information. Through operating system registration, the AWT libraries know what fonts are available on the system, and the font metrics for each one.
Support for custom fonts is added by creating font metric files (written in XML) from the actual font files, and registering them with FOP. Currently only Type 1 and TrueType fonts can be added. More information about fonts can be found at:
FOP includes PFMReader, which reads the PFM file that normally comes with a Type 1 font, and generates an appropriate font metrics file for it. To use it, run the class org.apache.fop.fonts.apps.PFMReader:
Windows (on JDK 1.4 and later):
Windows (on JDK 1.3.x):
Unix (on JDK 1.4 and later):
Unix (on JDK 1.3.1):
PFMReader [options]:
FOP includes TTFReader, which reads the TTF file and generates an appropriate font metrics file for it. Use it in a similar manner to PFMReader. For example, to create such a metrics file in Windows from the TrueType font at c:\myfonts\cmr10.ttf:
TTFReader [options]:
Issue | WinAnsi | CID-keyed |
---|---|---|
Usable Character Set | Limited to WinAnsi character set, which is roughly equivalent to iso-8889-1. | Limited only by the characters in the font itself. |
Character Encoding in the Output Document. | Correct. | Never correct. Search, index, and cut-and-paste operations in the output document will produce incorrect results. |
Character Display | Correct. | Correct, but copy/paste won't work in Acrobat Reader. (FOP currently doesn't emit the /ToUnicode table which is necessary for copy/paste to work.) |
Embedding the Font | Optional. | Mandatory. Not embedding the font produces invalid PDF documents. |
TrueType collections (.ttc files) contain more than one font. To create metrics files for these fonts, you must specify which font in the collection should be generated, by using the "-ttcname" option with the TTFReader.
To get a list of the fonts in a collection, just start the TTFReader as if it were a normal TrueType file (without the -ttcname option). It will display all of the font names and exit with an Exception.
Here is an example of generating a metrics file for a .ttc file:
You must tell FOP how to find and use the font metrics files by registering them in the FOP Configuration. Add entries for your custom fonts, regardless of font type, to the configuration file in a manner similar to the following:
Font embedding is enabled in the userconfig.xml file and controlled by the embed-url attribute. If you don't specify the embed-url attribute the font will not be embedded, but will only be referenced.
When FOP embeds a font, it adds a prefix to the fontname to ensure that the name will not match the fontname of an installed font. This is helpful with older versions of Acrobat Reader that preferred installed fonts over embedded fonts.
When embedding PostScript fonts, the entire font is always embedded.
When embedding TrueType fonts (ttf) or TrueType Collections (ttc), a subset of the original font, containing only the glyphs used, is embedded in the output document. Currently, this embedded font contains only the minimum data needed to be embedded in a pdf document, and does not contain any codepage information. The PDF document contains indexes to the glyphs in the font instead of to encoded characters. While the document will be displayed correctly, the net effect of this is that searching, indexing, and cut-and-paste will not work properly.
One workaround for this behavior is to use the "-enc ansi" option when generating metrics with TTFReader. This will cause the whole font to be embedded in the pdf document. Characters will be WinAnsi encoded (as specified in the PDF spec), so you lose the ability to use characters from other character sets. See Table of TTF Encoding Options for more details.
There are cases where you might want to force the embedding of one or more of the base 14 fonts that can normally be considered available on the target platform (viewer, printer). One of these cases is PDF/A which mandates the embedding of even the base 14 fonts. Embedding a font such as Helvetica or Courier is straight-forward. The "Symbol" and "ZapfDingbats" fonts, however, currently present a problem because FOP cannot correctly determine the encoding of these two single-byte fonts through the PFM file. FOP now correctly interprets the "encoding" value in the XML font metrics file, but the PFMReader application writes "UnknownEncoding" to the generated XML file. In order to embed "Symbol" and "ZapfDingbats" you have to manually change the XML font metrics file and specify "SymbolEncoding" or "ZapfdingbatsEncoding" encoding respectively as the value for the "encoding" element.
Example: