PDF Fonts
How the formatter and PDF Viewer use fonts
The formatter (for example, FOP) creates the PDF and the PDF Viewer (typically Adobe's PDF Reader) reads it.
In order to lay out the PDF, the formatter needs to know details about the fonts used in the document, particularly the widths of all the glyphs used. It needs this information to calculate line lengths, hyphenation, justification, etc. This information is known as the metrics of the font, and it is stored with each font. Some formatters can read the metrics directly from the system's font folder. Others (such as earlier versions of FOP) need the metrics in a special format it can understand. When the metrics of a font are available to the formatter, the formatter can successfully lay out the PDF. You must ensure that the font metrics files of all the fonts you use in your document are available to the formatter you are using.
The formatter can either reference a font or embed it in the PDF file. If the font is referenced, then the PDF Viewer (for example, Adobe Reader) typically will look for that font in its own font resource folder (which contains the Base 14 fonts) first, and then in the system's font folder. If the font is available, it will be used when the PDF is displayed. Otherwise the Viewer will use an alternative from its resource folder or generate an error. An alternative font may have different metrics and could therefore generate display errors.
If the formatter embeds a font in the PDF file, then the PDF Viewer uses the embedded font. The formatter may embed the entire character set of a font or only a subset that contains the glyphs used in the document. This factor affects the size of the PDF file and, possibly, copyright issues surrounding font use (see note below). You might be able to influence the choice between these two options when you set the options for your formatter.
Using fonts in StyleVision
•The default document font used in the PDF output is Helvetica (Acrobat PDF Reader versions prior to 4.0) or Arial MT (Acrobat PDF Reader version 4.0 or later). So, if no font is specified for any text in the design document, Helvetica/ArialMT (a Base 14 font) will be used.
•If you specify Helvetica or Times in the SPS, and if the Acrobat PDF Reader used to view the PDF output is version 4 or higher, then the PDF Reader will use Arial MT and Times New Roman PS MT, respectively, from its own font resources folder. Acrobat PDF Reader does this even if Helvetica and Times are active on the system.
•In StyleVision, you can change the default font for the entire document by first selecting all the text in the document. Then, in the Styles sidebar, select the texts item in the Styles For column, and with the Font group selected, assign the desired font to the font-family attribute. This font is assigned to each text node in the document. An alternative font can then be set for individual text nodes as required.
•If in the XSL Options tab of the Options dialog (Tools | Options) you select FOP 0.93/1.0/2.0 compliant, then only the font-family values Helvetica, Times, Courier, and Symbol (exactly as spelled here) will be passed through to the XSLT-for-FO. Entering any other font-family value on a node will remove the font-family attribute from that node in the resulting FO document—leading to the default Helvetica/ArialMT being output for that node.
•If in the XSL Options tab of the Options dialog (Tools | Options) you select Full usage of XSL-FO standard, then any font-family you enter in the Text Style window will be passed to the XSLT-for-FO document. If the selected font is not available to the formatter, an error may result. In order to avoid such errors, add alternative fonts and a generic fallback. For example:
font-family="Bodoni, Garamond, serif"
In this example, Garamond is a second choice, and the generic serif is the fallback font. If neither Bodoni nor Garamond is available, then the generic serif font is used. The three generic fonts are: serif (Times or Times New Roman PS MT, depending on the Acrobat Reader version), sans-serif (Helvetica or ArialMT), and monospace (Courier).
Note for HTML use: CSS2 allows alternative choices, as well as a generic font as a fallback (serif, sans-serif, monospace, cursive, and fantasy).
Making fonts available to the formatter
Most formatters already have available to them the Base 14 fonts. It is important to know the names by which the formatter recognizes these Base 14 fonts so that you correctly indicate them to the formatter. This is the basic font support provided by formatters. You can, however, increase the number of fonts available to the formatter by carrying out a few straightforward steps specific to the formatter you are using. The steps for FOP are given below.
Font support in FOP
There are two steps involved in setting up custom fonts:
1.Informing FOP how to find the font files.
2.Informing FOP how to use the fonts.
How to find the required font files
More recent versions of FOP can automatically detect system fonts or can scan user-specified directories for fonts and register these with FOP. See the Fonts page at the FOP website
If you are using an earlier version of FOP, you will need to first generate a font metrics file (an XML file) for each required font from the font's PostScript or TrueType font files. FOP provides PFM Reader and TTF Reader utilities to convert PostScript and TrueType fonts, respectively, to XML font metrics file. For details of how to do this, see the FOP Fonts page. Next, in the FOP configuration file, the required metrics file for each font must be specified in the metrics-url attribute of the respective font element.
<font metrics-url="arial.xml" kerning="yes" embed-url="arial.ttf">
<font-triplet name="Arial" style="normal" weight="normal"/>
<font-triplet name="ArialMT" style="normal" weight="normal"/>
</font>
Telling FOP how to use the fonts
The FOP configuration file—an XML file called fop.xconf and located in the conf folder in the FOP installation folder—must be edited so that FOP knows how to use the fonts correctly. For each font that you wish to have FOP render, add a font element at the location indicated by the font-element placeholder in the document:
<font metrics-url="arial.xml" kerning="yes" embed-url="arial.ttf">
<font-triplet name="Arial" style="normal" weight="normal"/>
<font-triplet name="ArialMT" style="normal" weight="normal"/>
</font>
In the example above,
metrics-url | URL of the metrics file. If not absolute, relative to the path in the font-base element of the configuration file. Optional. |
embed-url | URL of the font file (usually located in %WINDIR%\Fonts). Required if the Viewer does not have the file on its local system. |
name | Maps this font name to the font defined with metrics-url and/or embed-url. |
style | Maps this font style to the font defined with metrics-url and/or embed-url. |
weight | Maps this font weight to the font defined with metrics-url and/or embed-url. |
For more details, see Registering Fonts with FOP at the FOP website.
Editing the batch file (fop.bat) to read the configuration file
After the configuration file has been edited as described above, the FOP executable (fop.bat), which is in the FOP installation folder, must be edited so that FOP reads the configuration file. Do this by changing the last line of fop.bat from:
"%JAVACMD%" […] org.apache.fop.cli.Main %FOP_CMD_LINE_ARGS%
to include the location of the configuration file:
"%JAVACMD%" […] org.apache.fop.cli.Main %FOP_CMD_LINE_ARGS% -c conf\fop.xconf
See Starting FOP at the FOP website.
Note on font copyrights
Font usage is subject to copyright laws, and the conditions for use vary. Before embedding a font—especially if you are embedding the entire font—make sure that you are allowed to do so under the license you have purchased for that font.
Character sets
Note that the character sets of fonts differ from each other. The Base 14 fonts cover the ISO-8859-1 characters plus the glyphs in the Symbol and Zapf Dingbats fonts. If your document contains a character that is not covered by the Base 14 fonts, then you will have to use a font that contains this character in its character set. Some fonts, such as Arial Unicode, offer the characters covered by Unicode.
Note: When entering font sizes, do not use an intervening space between the point size and its unit. For example, 12pt is correct, 12 pt is incorrect.