You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

fonts.xml 20KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410
  1. <?xml version="1.0" standalone="no"?>
  2. <!--
  3. Licensed to the Apache Software Foundation (ASF) under one or more
  4. contributor license agreements. See the NOTICE file distributed with
  5. this work for additional information regarding copyright ownership.
  6. The ASF licenses this file to You under the Apache License, Version 2.0
  7. (the "License"); you may not use this file except in compliance with
  8. the License. You may obtain a copy of the License at
  9. http://www.apache.org/licenses/LICENSE-2.0
  10. Unless required by applicable law or agreed to in writing, software
  11. distributed under the License is distributed on an "AS IS" BASIS,
  12. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. See the License for the specific language governing permissions and
  14. limitations under the License.
  15. -->
  16. <!-- $Id$ -->
  17. <!DOCTYPE document PUBLIC "-//APACHE//DTD Documentation V2.0//EN" "http://forrest.apache.org/dtd/document-v20.dtd">
  18. <document>
  19. <header>
  20. <title>Apache FOP: Fonts</title>
  21. <version>$Revision$</version>
  22. <authors>
  23. <person name="Jeremias Märki" email=""/>
  24. <person name="Tore Engvig" email=""/>
  25. <person name="Adrian Cumiskey" email=""/>
  26. <person name="Max Berger" email=""/>
  27. </authors>
  28. </header>
  29. <body>
  30. <section id="intro">
  31. <title>Summary</title>
  32. <p>The following table summarizes the font capabilities of the various FOP renderers:</p>
  33. <table>
  34. <tr>
  35. <th>Renderer</th>
  36. <th>Base-14</th>
  37. <th>AWT/OS</th>
  38. <th>Custom</th>
  39. <th>Custom Embedding</th>
  40. </tr>
  41. <tr>
  42. <td>PDF</td>
  43. <td>yes</td>
  44. <td>no</td>
  45. <td>yes</td>
  46. <td>yes</td>
  47. </tr>
  48. <tr>
  49. <td>PostScript</td>
  50. <td>yes</td>
  51. <td>no</td>
  52. <td>yes</td>
  53. <td>yes</td>
  54. </tr>
  55. <tr>
  56. <td>PCL</td>
  57. <td>yes (modified)</td>
  58. <td>yes (painted as bitmaps)</td>
  59. <td>yes (painted as bitmaps)</td>
  60. <td>no</td>
  61. </tr>
  62. <tr>
  63. <td>AFP</td>
  64. <td>no</td>
  65. <td>no</td>
  66. <td>yes</td>
  67. <td>yes</td>
  68. </tr>
  69. <tr>
  70. <td>Java2D/AWT/Bitmap</td>
  71. <td>if available from OS</td>
  72. <td>yes</td>
  73. <td>yes</td>
  74. <td>n/a (display only)</td>
  75. </tr>
  76. <tr>
  77. <td>Print</td>
  78. <td>if available from OS</td>
  79. <td>yes</td>
  80. <td>yes</td>
  81. <td>controlled by OS printer driver</td>
  82. </tr>
  83. <tr>
  84. <td>RTF</td>
  85. <td>n/a (font metrics not needed)</td>
  86. <td>n/a</td>
  87. <td>n/a</td>
  88. <td>n/a</td>
  89. </tr>
  90. <tr>
  91. <td>TXT</td>
  92. <td>yes (used for layout but not for output)</td>
  93. <td>no</td>
  94. <td>yes (used for layout but not for output)</td>
  95. <td>no</td>
  96. </tr>
  97. <!--tr> NOT AVAILABLE
  98. <td>MIF</td>
  99. <td>n/a (font metrics not needed)</td>
  100. <td>n/a</td>
  101. <td>n/a</td>
  102. <td>n/a</td>
  103. </tr-->
  104. <!--tr> NOT AVAILABLE
  105. <td>SVG</td>
  106. <td>if available from OS</td>
  107. <td>yes</td>
  108. <td>no</td>
  109. <td>no</td>
  110. </tr-->
  111. <tr>
  112. <td>XML</td>
  113. <td>yes</td>
  114. <td>no</td>
  115. <td>yes</td>
  116. <td>n/a</td>
  117. </tr>
  118. </table>
  119. </section>
  120. <section>
  121. <title>Base-14 Fonts</title>
  122. <p>
  123. The Adobe PostScript and PDF Specification specify a set of 14 fonts that must be
  124. available to every PostScript interpreter and PDF reader:
  125. Helvetica (normal, bold, italic, bold italic),
  126. Times (normal, bold, italic, bold italic),
  127. Courier (normal, bold, italic, bold italic),
  128. Symbol and ZapfDingbats.
  129. </p>
  130. <p>
  131. Please note that recent versions of Adobe Acrobat Reader replace
  132. "Helvetica" with "Arial" and "Times" with "Times New Roman" internally.
  133. GhostScript replaces "Helvetica" with "Nimbus Sans L" and "Times" with
  134. "Nimbus Roman No9 L". Other document viewers may do similar font
  135. substitutions. If you need to make sure that there are no such
  136. substitutions, you need to specify an explicit font and embed it in
  137. the target document.
  138. </p>
  139. </section>
  140. <section>
  141. <title>Missing Fonts</title>
  142. <p>
  143. When FOP does not have a specific font at its disposal (because it's
  144. not installed in the operating system or set up in FOP's configuration),
  145. the font is replaced with "any". "any" is internally mapped to the
  146. Base-14 font "Times" (see above).
  147. </p>
  148. </section>
  149. <section id="awt">
  150. <title>Java2D/AWT/Operating System Fonts</title>
  151. <p>
  152. The Java2D family of renderers (Java2D, AWT, Print, TIFF, PNG), use the
  153. Java AWT subsystem for font metric information. Through operating system
  154. registration, the AWT subsystem knows what fonts are available on the system,
  155. and the font metrics for each one.
  156. </p>
  157. <p>
  158. When working with one of these output formats and you're missing a font, just
  159. install it in your operating system and they should be available for these
  160. renderers. Please note that this is not true for other output formats such as
  161. PDF or PostScript.
  162. </p>
  163. </section>
  164. <section id="custom">
  165. <title>Custom Fonts</title>
  166. <p>
  167. Support for custom fonts is highly output format dependent (see above table).
  168. This section shows how to add Type 1 and TrueType fonts to the PDF, PostScript and
  169. Java2D-based renderers. Other renderers (like AFP) support other font formats. Details
  170. in this case can be found on the page about <a href="output.html">output formats</a>.
  171. </p>
  172. <p>
  173. Prior to FOP version 0.94, it was always necessary to create an XML font metrics file
  174. if you wanted to add a custom font. This unconvenient step has been removed and in
  175. addition to that, FOP supports auto-registration of fonts, i.e. FOP can find fonts
  176. installed in your operating system or can scan user-specified directories for fonts.
  177. Font registration via XML font metrics file is still supported and is still necessary
  178. if you want to use a TrueType Collection (*.ttc). Direct support for TrueType
  179. collections may be added later. Furthermore, the XML font metrics files are still
  180. required if you don't want to embed, but only reference a font.
  181. </p>
  182. <p>
  183. Basic information about fonts can be found at:
  184. </p>
  185. <ul>
  186. <li><a href="http://partners.adobe.com/asn/developer/type/ftypes.html">Adobe font types</a></li>
  187. <li><a href="http://partners.adobe.com/asn/developer/technotes/fonts.html">Adobe Font Technote</a></li>
  188. </ul>
  189. </section>
  190. <section id="basics">
  191. <title>Basic font configuration</title>
  192. <p>
  193. If you want FOP to use custom fonts, you need to tell it where to find them. This
  194. is done in the configuration file and once per renderer (because each output format
  195. is a little different). In the basic form, you can either tell FOP to find your
  196. operating system fonts or you can specify directories that it will search for
  197. support fonts. These fonts will then automatically be registered.
  198. </p>
  199. <source><![CDATA[
  200. <fonts>
  201. <!-- register all the fonts found in a directory -->
  202. <directory>C:\MyFonts1</directory>
  203. <!-- register all the fonts found in a directory
  204. and all of its sub directories (use with care) -->
  205. <directory recursive="true">C:\MyFonts2</directory>
  206. <!-- automatically detect operating system installed fonts -->
  207. <auto-detect/>
  208. </fonts>]]></source>
  209. <note>
  210. Review the documentation for <a href="configuration.html">FOP Configuration</a>
  211. for instructions on making the FOP configuration available to FOP when it runs.
  212. Otherwise, FOP has no way of finding your custom font information. It is currently
  213. not possible to easily configure fonts from Java code.
  214. </note>
  215. </section>
  216. <section id="advanced">
  217. <title>Advanced font configuration</title>
  218. <p>
  219. The instructions found above should be sufficient for most users. Below are some
  220. additional instructions in case the basic font configuration doesn't lead to
  221. the desired results.
  222. </p>
  223. <section id="type1-metrics">
  224. <title>Type 1 Font Metrics</title>
  225. <p>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.
  226. To use it, run the class org.apache.fop.fonts.apps.PFMReader:</p>
  227. <p>Windows:</p>
  228. <source>java -cp build\fop.jar;lib\avalon-framework.jar;lib\commons-logging.jar;lib\commons-io.jar
  229. org.apache.fop.fonts.apps.PFMReader [options] pfm-file xml-file</source>
  230. <p>Unix:</p>
  231. <source>java -cp build/fop.jar:lib/avalon-framework.jar:lib/commons-logging.jar:lib/commons-io.jar
  232. org.apache.fop.fonts.apps.PFMReader [options] pfm-file xml-file</source>
  233. <p>PFMReader [options]:</p>
  234. <ul>
  235. <li><strong>-fn &lt;fontname&gt;</strong> By default, FOP uses the fontname from the
  236. .pfm file when embedding the font. Use the "-fn" option to override this name with one you have
  237. chosen. This may be useful in some cases to ensure that applications using the output document
  238. (Acrobat Reader for example) use the embedded font instead of a local font with the same
  239. name.</li>
  240. </ul>
  241. <note>The classpath in the above example has been simplified for readability.
  242. You will have to adjust the classpath to the names of the actual JAR files in the lib directory.
  243. xml-apis.jar, xercesImpl.jar, xalan.jar and serializer.jar are not necessary for JDK version 1.4 or later.</note>
  244. <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.
  245. FontBBox and Italic Angle can be found in the human-readable part of the PFB file or in the AFM file.
  246. 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.
  247. The constructed values however appear to have no visible influence.</note>
  248. </section>
  249. <section id="truetype-metrics">
  250. <title>TrueType Font Metrics</title>
  251. <p>FOP includes TTFReader, which reads the TTF file and generates an appropriate font metrics file for it.
  252. Use it in a similar manner to PFMReader.
  253. For example, to create such a metrics file in Windows from the TrueType font at c:\myfonts\cmr10.ttf:</p>
  254. <source>java -cp build\fop.jar;lib\avalon-framework.jar;lib\commons-logging.jar;lib\commons-io.jar
  255. org.apache.fop.fonts.apps.TTFReader [options]
  256. C:\myfonts\cmr10.ttf ttfcm.xml</source>
  257. <p>TTFReader [options]:</p>
  258. <ul>
  259. <li><strong>-d &lt;DEBUG | INFO &gt;</strong> Sets the debug level (default is
  260. INFO).</li>
  261. <li><strong>-fn &lt;fontname&gt;</strong> Same as for PFMReader.</li>
  262. <li><strong>-ttcname &lt;fontname&gt;</strong> If you're reading data from a
  263. TrueType Collection (.ttc file) you must specify which font from the collection you will read
  264. metrics from.
  265. If you read from a .ttc file without this option, the fontnames will be listed for you.</li>
  266. <li><strong>-enc ansi</strong> Creates a WinAnsi-encoded font metrics file.
  267. Without this option, a CID-keyed font metrics file is created.
  268. The table below summarizes the differences between these two encoding options as currently
  269. used within FOP.
  270. Please note that this information only applies to TrueType fonts and TrueType collections:</li>
  271. </ul>
  272. <table id="ttf-encoding">
  273. <tr>
  274. <th>Issue</th>
  275. <th>WinAnsi</th>
  276. <th>CID-keyed</th>
  277. </tr>
  278. <tr>
  279. <td>Usable Character Set</td>
  280. <td>Limited to WinAnsi character set, which is roughly equivalent to iso-8889-1.</td>
  281. <td>Limited only by the characters in the font itself.</td>
  282. </tr>
  283. <tr>
  284. <td>Embedding the Font</td>
  285. <td>Optional.</td>
  286. <td>Mandatory. Not embedding the font produces invalid PDF documents.</td>
  287. </tr>
  288. </table>
  289. <warning>
  290. You may experience failures with certain TrueType fonts, especially if they don't contain
  291. the so-called Unicode "cmap" table. TTFReader can currently not deal with font like this.
  292. </warning>
  293. </section>
  294. <section id="truetype-collections-metrics">
  295. <title>TrueType Collections Font Metrics</title>
  296. <p>TrueType collections (.ttc files) contain more than one font.
  297. 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.</p>
  298. <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).
  299. It will display all of the font names and exit with an Exception.</p>
  300. <p>Here is an example of generating a metrics file for a .ttc file:</p>
  301. <source>java -cp build\fop.jar;lib\avalon-framework.jar;lib\commons-logging.jar;lib\commons-io.jar
  302. org.apache.fop.fonts.apps.TTFReader -ttcname "MS Mincho"
  303. msmincho.ttc msminch.xml</source>
  304. </section>
  305. <section id="register">
  306. <title>Register Fonts with FOP</title>
  307. <p>You must tell FOP how to find and use the font metrics files by registering them in the <a href="configuration.html">FOP Configuration</a>. Add entries for your custom fonts, regardless of font type, to the configuration file in a manner similar to the following:</p>
  308. <source><![CDATA[
  309. <fonts>
  310. <!-- register a particular font -->
  311. <font metrics-url="file:///C:/myfonts/FTL_____.xml" kerning="yes"
  312. embed-url="file:///C:/myfonts/FTL_____.pfb">
  313. <font-triplet name="FrutigerLight" style="normal" weight="normal"/>
  314. </font>
  315. <!-- register all the fonts found in a directory -->
  316. <directory>C:\MyFonts1</directory>
  317. <!-- register all the fonts found in a directory
  318. and all of its sub directories (use with care) -->
  319. <directory recursive="true">C:\MyFonts2</directory>
  320. <!-- automatically detect operating system installed fonts -->
  321. <auto-detect/>
  322. </fonts>]]></source>
  323. <ul>
  324. <li>
  325. URLs are used to access the font metric and font files.
  326. Relative URLs are resolved relative to the font-base property (or base) if available.
  327. See <a href="configuration.html">FOP: Configuration</a> for more information.
  328. </li>
  329. <li>The "metrics-url" attribute is generally not necessary except if you run into problems with certain fonts.</li>
  330. <li>Either an "embed-url" or a "metrics-url" must be specified for font tag configurations.</li>
  331. <li>The font "kerning" attribute is optional. Default is "true".</li>
  332. <li>If embedding is off (i.e. embed-url is not set), the output will position the text correctly (from the metrics file), but it will not be displayed or printed correctly unless the viewer has the applicable font available to their local system.</li>
  333. <li>When setting the "embed-url" attribute for Type 1 fonts, be sure to specify the PFB (actual font data), not PFM (font metrics) file that you used to generate the XML font metrics file.</li>
  334. <li>The fonts "directory" tag can be used to register fonts contained within a single or list of directory paths. The "recursive" attribute can be specified to recursively add fonts from all sub directories.</li>
  335. <li>The fonts "auto-detect" tag can be used to automatically register fonts that are found to be installed on the native operating system.</li>
  336. <li>Fonts registered with "font" tag configurations override fonts found by means of "directory" tag definitions.</li>
  337. <li>Fonts found as a result of a "directory" tag configuration override fonts found as a result of the "auto-detect" tag being specified.</li>
  338. <li>
  339. If relative URLs are specified, they are evaluated relative to the value of the
  340. "font-base" setting. If there is no "font-base" setting, the fonts are evaluated
  341. relative to the base directory.
  342. </li>
  343. </ul>
  344. <!--note>Cocoon users will need to setup the config, see FOPSerializer for more information.</note-->
  345. </section>
  346. <section id="autodetect">
  347. <title>Auto-Detect and auto-embedd feature</title>
  348. <p>When the "auto-detect" flag is set in the configuration, FOP will automatically search for fonts in the default paths for your operating system.</p>
  349. <p>FOP will also auto-detect fonts which are available in the classpath, if they are described as "application/x-font" in the MANIFEST.MF file. For example, if your .jar file contains font/myfont.ttf:</p>
  350. <source>Manifest-Version: 1.0
  351. Name: font/myfont.ttf
  352. Content-Type: application/x-font</source>
  353. <p>This feature allows you to create JAR files containing fonts. The JAR files can be added to fop by providem them in the classpath, e.g. copying them into the lib/ directory.</p>
  354. </section>
  355. <section id="embedding">
  356. <title>Embedding</title>
  357. <note>The PostScript renderer does not yet support TrueType fonts, but can embed Type 1 fonts.</note>
  358. <note>The font is simply embedded into the PDF file, it is not converted.</note>
  359. <p>Font embedding is enabled in the userconfig.xml file and controlled by the embed-url attribute.
  360. If you don't specify the embed-url attribute the font will not be embedded, but will only be referenced.</p>
  361. <warning>
  362. Omitting the embed-url attribute for CID-encoded TrueType fonts will currently produce invalid
  363. PDF files! If you create the XML font metric file using the "-enc ansi" option, you can omit
  364. the embed-url attribute for TrueType fonts but you're restricted to the WinAnsi character set.
  365. </warning>
  366. <p>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.
  367. This is helpful with older versions of Acrobat Reader that preferred installed fonts over embedded fonts.</p>
  368. <p>When embedding PostScript fonts, the entire font is always embedded.</p>
  369. <p>When embedding TrueType fonts (ttf) or TrueType Collections (ttc), a subset of the
  370. original font, containing only the glyphs used, is embedded in the output document.</p>
  371. </section>
  372. <!-- The following section should no longer be required
  373. <section id="embedding-base14">
  374. <title>Explicitly embedding the base 14 fonts</title>
  375. <p>
  376. There are cases where you might want to force the embedding of one or more of the base 14 fonts that
  377. can normally be considered available on the target platform (viewer, printer). One of these cases is
  378. <a href="pdfa.html">PDF/A</a> which mandates the embedding of even the base 14 fonts. Embedding a font such as Helvetica or
  379. Courier is straight-forward. The "Symbol" and "ZapfDingbats" fonts, however, currently present a
  380. problem because FOP cannot correctly determine the encoding of these two single-byte fonts through
  381. the PFM file. FOP now correctly interprets the "encoding" value in the XML font metrics file, but the
  382. PFMReader application writes "UnknownEncoding" to the generated XML file. In order to embed "Symbol"
  383. and "ZapfDingbats" you have to manually change the XML font metrics file and specify "SymbolEncoding"
  384. or "ZapfdingbatsEncoding" encoding respectively as the value for the "encoding" element.
  385. </p>
  386. <p>Example:</p>
  387. <source><![CDATA[
  388. <?xml version="1.0" encoding="UTF-8"?>
  389. <font-metrics type="TYPE1">
  390. <font-name>Symbol</font-name>
  391. <embed/>
  392. <encoding>SymbolEncoding</encoding>
  393. <cap-height>673</cap-height>
  394. <x-height>766</x-height>
  395. [..]]]></source>
  396. </section-->
  397. </section>
  398. </body>
  399. </document>