|
| |
FOP (building PDF files) normally supports only the base 14 font package defined in the Adobe PDF specification.
That includes the following fonts: Helvetica, Times, Courier, Symbol and ZapfDingbats.
Font support in FOP can be extended by the addition of font metric files (written in XML) created from Adobe
Type 1 fonts and Truetype fonts. No other font types (Type 0, Type 3, etc.) are supported at this time. The current method
of adding fonts to FOP requires the package to be recompiled. You can also embed fonts into pdf files; see below.
|
| | | | Adding additional Type 1 fonts | | | | |
| |
As mentioned above you need an XML file containing font metrics to be able to use an additional font. FOP
contains a tool that can generate such a font metrics file from a PFM file, which normally comes with the font file.
| | | | Register the fonts within FOP | | | | |
| |
Open the class org.apache.fop.render.pdf.FontSetup and add entries to the ones present according to
the following example:
fontInfo.addMetrics("F14", new ZapfDingbats());
fontInfo.addMetrics("F15", new BauerBodoniRoman()); //This is the new entry.
...
fontInfo.addFontProperties("F14", "ZapfDingbats", "normal", "normal");
fontInfo.addFontProperties("F15", "BauerBodoni", "normal", "normal"); //This is the new entry.
Note: The class name to use is visible in the <class-name> element of the font metrics file.
|
| |
In the src/codegen directory you find the font metrics files for the base 14 fonts. The are being transformed
during build into Java classes and then compiled. The newly generated font metrics file must be included in this
process. To do that open build.xml and add entries according to the following example:
<property name="ZapfDingbats.xml" value="${build.codegen}/ZapfDingbats.xml"/>
<property name="BauerBodoni.xml" value="${build.codegen}/BauerBodoni.xml"/>
...
<xslt infile="${ZapfDingbats.xml}" xsltfile="${fontfile.xsl}"
outfile="${build.src}/${replacestring}/render/pdf/fonts/ZapfDingbats.java" smart="yes"/>
<xslt infile="${BauerBodoni.xml}" xsltfile="${t1fontfile.xsl}"
outfile="${build.src}/${replacestring}/render/pdf/fonts/BauerBodoniRoman.java" smart="yes"/>
Rebuild FOP!
Note: Be sure to use ${t1fontfile.xsl} instead of ${fontfile.xsl}. This is neccessary because of the additional metrics
information needed for non base 14 fonts.
|
|
| | | | Adding additional TrueType | | | | |
| |
Adding Truetype fonts is almost identical to the process of adding type 1 fonts. The main difference is in the first step.
| | | | Register the fonts within FOP | | | | |
| |
Open the class org.apache.fop.render.pdf.FontSetup and add entries to the ones present according to
the following example:
fontInfo.addMetrics("F14", new ZapfDingbats());
fontInfo.addMetrics("F19", new TCM()); //This is the new entry.
...
fontInfo.addFontProperties("F14", "ZapfDingbats", "normal", "normal");
fontInfo.addFontProperties("F19", "TCM", "normal", "normal"); //This is the new entry.
Note: The class name to use is visible in the <class-name> element of the font metrics file.
|
| |
In the src/codegen directory you find the font metrics files for the base 14 fonts. The are being transformed
during build into Java classes and then compiled. The newly generated font metrics file must be included in this
process. To do that open build.xml and add entries according to the following example:
Look for the section "Initialization target" and add the following line at the end of it
<property name="tcm.xml" value="${build.codegen}/tcm.xml">
then search for the section "Generate the source code". At the end of this section you can find
templates for type 1 and truetype fonts. use them with your font name:
<xslt infile="${tcm.xml}" xsltfile="${ttffontfile.xsl}"
outfile="${build.src}/${replacestring}/render/pdf/fonts/TCM.java" smart="yes"/>
|
| |
edit conf\userconfig.xml and add TCM to the list of embedded fonts
Don't forget: If you have embedded fonts, you must run Fop with the flag -cuserconfig.xml,
otherwise the settings in userconfig.xml will not be read.
|
Rebuild FOP!
|
|
|