1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
|
<?xml version="1.0" standalone="no"?>
<!DOCTYPE document PUBLIC "-//APACHE//DTD Documentation V1.1//EN"
"http://cvs.apache.org/viewcvs.cgi/*checkout*/xml-forrest/src/resources/schema/dtd/document-v11.dtd">
<document>
<header>
<title>Fonts</title>
<authors>
<person name="Jeremias Märki" email=""/>
<person name="Tore Engvig" email=""/>
</authors>
</header>
<body>
<section id="intro">
<title>Important</title>
<p>The information on this page applies primarily to the PDF renderer. The PostScript renderer
also supports custom fonts but doesn't support font embedding, yet. This page does
<strong>not</strong> apply to the AWT, PCL, MIF and other renderers.</p>
<p>The AWT renderer relies upon AWT to provide the available fonts. And it's the printer
driver of your operating system that decides if a font is embedded when using the AWT
renderer.</p>
</section>
<section id="status">
<title>Status</title>
<p>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.
</p>
<p>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 3, etc.) are supported at this time.
More information about font types can be found at
the <link href="http://partners.adobe.com/asn/developer/type/ftypes.html">
Adobe font types</link>. There is also lots more font information
on this <link href="http://partners.adobe.com/asn/developer/technotes/fonts.html">Adobe Font Technote</link>.
</p>
<note>
The font is simply embedded into the PDF file, it is not converted.
</note>
</section>
<section id="type1">
<title>Adding Type 1 fonts</title>
<p>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.
</p>
<section id="type1-metrics">
<title>Generating a font metrics file</title>
<p> Run the class org.apache.fop.fonts.apps.PFMReader to generate the XML file.
</p>
<p>Windows:</p>
<source>
java -cp build\fop.jar;lib\avalon-framework.jar;lib\xml-apis.jar;
lib\xercesImpl.jar;lib\xalan.jar
org.apache.fop.fonts.apps.PFMReader pfm-file xml-file
</source>
<p>Unix:</p>
<source>
java -cp build/fop.jar:lib/avalon-framework.jar:lib/xml-apis.jar:
lib/xercesImpl.jar:lib/xalan.jar
org.apache.fop.fonts.apps.PFMReader pfm-file xml-file
</source>
<note>
The classpath in the above example has been simplified for readibity.
You will have to adjust the classpath to the names of the actual JAR files in the lib directory.
avalon-framework.jar is necessary only for versions 0.20.5 or later.
xml-apis.jar, xercesImpl.jar and xalan.jar are not necessary for JDK version 1.4 or later.
</note>
<note>The tool will construct some values (FontBBox, StemV and ItalicAngle) based on assumptions and
calculations which are only an approximation to the real values. FontBBox and Italic Angle can be found in
the human-readable part of the PFB file or in the AFM file. The PFMReader tool does not yet interpret PFB or AFM files, so if you want
to be correct, you may have to adjust the values in the XML file manually. The constructed values however
appear to have no visible influence.
</note>
</section>
<section id="type1-register">
<title>Register the fonts within FOP</title>
<p>
Edit conf/userconfig.xml and add entries for the font
if the fonts section,
ie:
</p>
<source><![CDATA[<font metrics-file="FTL_____.xml" kerning="yes"
embed-file="C:\myfonts\FTL_____.pfb">
<font-triplet name="FrutigerLight" style="normal" weight="normal">
</font>]]></source>
<note>
Starting from FOP version 0.20.5 you can use URLs for the paths to the font files. Relative URLs are resolved
relative to the fontBaseDir property (or baseDir) if available.
</note>
<note>
Make sure you specify the PFB file in the embed-file attribute
and not the PFM you used to generate the XML font metrics file.
</note>
<note>
If you do not want the font embedded in the PDF then remove the
"embed-file" attribute. The PDF will then contain text using
the font with the font metrics and to view it properly the
font will need to be installed where it is being viewed.
</note>
<note>
Cocoon users will need to setup the config, see FOPSerializer
for more information.
</note>
</section>
</section>
<section id="truetype">
<title>Adding TrueType Fonts</title>
<p>Adding TrueType fonts is almost identical to the process of
adding Type 1 fonts. The main difference is in the first
step.</p>
<section id="truetype-metrics">
<title>Generating a font metrics file</title>
<p>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
your TrueType font file.
</p>
<p>
Create metrics for the fontfile (we assume the file has
the name cmr10.ttf and exists in c:\myfonts\):
</p>
<source>
java -cp build\fop.jar;lib\avalon-framework.jar;lib\xml-apis.jar;
lib\xercesImpl.jar;lib\xalan.jar
org.apache.fop.fonts.apps.TTFReader
C:\myfonts\cmr10.ttf ttfcm.xml
</source>
</section>
<section id="truetype-collections">
<title>TrueType collections</title>
<p>
TrueType collections (.ttc files) contains more than one
font. To create metrics for a ttc file you must specify
the font in the collection with the -ttcname option to
TTFReader.
</p>
<p>
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 then display all the font
names and exit with an Exception...
</p>
<p>
Example on generating metrics for a .ttc file:
</p>
<source>
java -cp build\fop.jar;lib\avalon-framework.jar;lib\xml-apis.jar;
lib\xercesImpl.jar;lib\xalan.jar
org.apache.fop.fonts.apps.TTFReader -ttcname "MS Mincho"
msmincho.ttc msminch.xml
</source>
</section>
<section id="truetype-register">
<title>Register the fonts within FOP</title>
<p>
Similiar to Type 1 fonts.
</p>
<source><![CDATA[<font metrics-file="cyberbit.xml" kerning="yes"
embed-file="C:\WINNT\Fonts\Cyberbit.ttf">
<font-triplet name="Cyberbit" style="normal" weight="normal">
</font>]]></source>
</section>
</section>
<section id="embedding">
<title>Embedding fonts</title>
<p>
Font embedding is enabled in the userconfig.xml file and controlled by the embed-file attribute.
If you don't specify the embed-file attribute the font will not be embedded, but will only be referenced.
</p>
<p>
When FOP embeds a font, it scrambles its fontname by inserting a prefix that ensures that the fontname 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.
</p>
<p>
When embedding PostScript fonts, the entire font is always embedded.
</p>
<p>
When embedding TrueType fonts (ttf) or TrueType Collections (ttc), a new font, containing only the glyphs used, is created from the original font and embedded in the pdf.
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.
</p>
<p>
One workaround for this behavior is to use the -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.
</p>
</section>
<note>
Be sure to start FOP with the option to find the config file ("-c conf/userconfig.xml" from the command line). Otherwise, it has no way of finding your custom font information.
</note>
</body>
</document>
|