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.

graphics.xml 24KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567
  1. <?xml version="1.0" encoding="UTF-8" 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: Graphics Formats</title>
  21. <version>$Revision$</version>
  22. </header>
  23. <body>
  24. <section id="introduction">
  25. <title>Introduction</title>
  26. <p>
  27. After the Apache™ FOP 0.94 release, the image handling subsystem has been rewritten in
  28. order to improve the range of supported images and image subtypes, to lower the
  29. overall memory consumption when handling images, to produce smaller output files and to
  30. increase the performance in certain areas. Of course, this causes a few changes most of
  31. which the user will probably not notice. The most important changes are:
  32. </p>
  33. <ul>
  34. <li>
  35. The image libraries Jimi and JAI are no longer supported. Instead, Apache FOP uses the
  36. Image I/O API that was introduced with Java 1.4 for all bitmap codecs.
  37. </li>
  38. <li>
  39. Some bitmap images are no longer converted to a standardized 24 bit RGB image but are
  40. instead handled in their native format.
  41. </li>
  42. <li>
  43. A plug-in mechanism offers a possibility to add support for new formats without changing
  44. the FOP's source code.
  45. </li>
  46. </ul>
  47. <p>
  48. The actual <a href="http://xmlgraphics.apache.org/commons/image-loader.html">image loading framework</a>
  49. no longer resides in Apache FOP, but was instead placed in
  50. <a href="ext:xmlgraphics.apache.org/commons/">XML Graphics Commons</a>.
  51. </p>
  52. </section>
  53. <section id="support-overview">
  54. <title>Overview of Graphics Support</title>
  55. <p>
  56. The table below summarizes the <em>theoretical</em> support for graphical formats
  57. within FOP. In other words, within the constraints of the limitations listed here,
  58. these formats <em>should</em> work. However, many of them have not been tested,
  59. and there may be limitations that have not yet been discovered or documented.
  60. The packages needed to support some formats are not included in the FOP distribution
  61. and must be installed separately. Follow the links in the "Support Through" columns
  62. for more details.
  63. </p>
  64. <table>
  65. <tr>
  66. <th rowspan="2">Format</th>
  67. <th rowspan="2">Type</th>
  68. <th colspan="3">Support Through</th>
  69. </tr>
  70. <tr>
  71. <th><a href="#native">Apache FOP (native)</a></th>
  72. <th><a href="#batik">Apache Batik</a></th>
  73. <th><a href="#imageio">Image I/O</a></th>
  74. </tr>
  75. <tr>
  76. <td><a href="#bmp">BMP</a> (Microsoft Windows Bitmap)</td>
  77. <td>bitmap</td>
  78. <td/>
  79. <td/>
  80. <td>X [1]</td>
  81. </tr>
  82. <tr>
  83. <td><a href="#emf">EMF</a> (Windows Enhanced Metafile)</td>
  84. <td>vector (with embedded bitmaps)</td>
  85. <td>(X)</td>
  86. <td/>
  87. <td/>
  88. </tr>
  89. <tr>
  90. <td><a href="#eps">EPS</a> (Encapsulated PostScript)</td>
  91. <td>metafile (both bitmap and vector), most frequently used for vector drawings</td>
  92. <td>(X)</td>
  93. <td/>
  94. <td/>
  95. </tr>
  96. <tr>
  97. <td>GIF (Graphics Interchange Format)</td>
  98. <td>bitmap</td>
  99. <td/>
  100. <td/>
  101. <td>X</td>
  102. </tr>
  103. <tr>
  104. <td><a href="#jpeg">JPEG</a> (Joint Photographic Experts Group)</td>
  105. <td>bitmap</td>
  106. <td>(X)</td>
  107. <td/>
  108. <td>X</td>
  109. </tr>
  110. <tr>
  111. <td><a href="#png">PNG</a> (Portable Network Graphic)</td>
  112. <td>bitmap</td>
  113. <td/>
  114. <td/>
  115. <td>X</td>
  116. </tr>
  117. <tr>
  118. <td><a href="#svg">SVG</a> (Scalable Vector Graphics)</td>
  119. <td>vector (with embedded bitmaps)</td>
  120. <td/>
  121. <td>X</td>
  122. <td/>
  123. </tr>
  124. <tr>
  125. <td><a href="#tiff">TIFF</a> (Tag Image Format File)</td>
  126. <td>bitmap</td>
  127. <td>(X)</td>
  128. <td/>
  129. <td>X [1]</td>
  130. </tr>
  131. <tr>
  132. <td><a href="#wmf">WMF</a> (Windows Metafile)</td>
  133. <td>vector (with embedded bitmaps)</td>
  134. <td/>
  135. <td>(X)</td>
  136. <td/>
  137. </tr>
  138. </table>
  139. <p>
  140. Legend:
  141. </p>
  142. <ul>
  143. <li>"(X)" means restricted support. Please see the details below.</li>
  144. <li>
  145. [1]: Requires the presence of <a href="http://jai-imageio.dev.java.net/">JAI Image I/O Tools</a>
  146. (or an equivalent Image I/O compatible codec) in the classpath. JAI Image I/O Tools also
  147. adds support for JPEG 2000, WBMP, RAW and PNM. Other Image I/O codecs may provide
  148. support for additional formats.
  149. </li>
  150. </ul>
  151. <note>
  152. <a href="http://jai-imageio.dev.java.net/">JAI Image I/O Tools</a> is not the same as the
  153. <a href="http://java.sun.com/javase/technologies/desktop/media/jai/">JAI library</a>! The
  154. former simply exposes JAI's codecs using the Image&amp;nbsp;I/O API but does not include all
  155. the image manipulation functionality.
  156. </note>
  157. <section id="format-map">
  158. <title>Map of supported image formats by output format</title>
  159. <p>
  160. Not all image formats are supported for all output formats! For example, while you can
  161. use EPS (Encapsulated PostScript) files when you generate PostScript output, this format
  162. will not be supported by any other output format. Here's an overview of which image
  163. formats are supported by which output format:
  164. </p>
  165. <table>
  166. <tr>
  167. <th>Image Format</th>
  168. <th>PDF</th>
  169. <th>PostScript</th>
  170. <th>Java2D, PNG, TIFF, AWT</th>
  171. <th>PCL</th>
  172. <th>AFP</th>
  173. <th>RTF</th>
  174. </tr>
  175. <tr>
  176. <td><a href="#bmp">BMP</a> (Microsoft Windows Bitmap)</td>
  177. <td>X</td>
  178. <td>X</td>
  179. <td>X</td>
  180. <td>X</td>
  181. <td>X</td>
  182. <td>X</td>
  183. </tr>
  184. <tr>
  185. <td><a href="#emf">EMF</a> (Windows Enhanced Metafile)</td>
  186. <td/>
  187. <td/>
  188. <td/>
  189. <td/>
  190. <td/>
  191. <td>X [1]</td>
  192. </tr>
  193. <tr>
  194. <td><a href="#eps">EPS</a> (Encapsulated PostScript)</td>
  195. <td/>
  196. <td>X [1]</td>
  197. <td/>
  198. <td/>
  199. <td/>
  200. <td/>
  201. </tr>
  202. <tr>
  203. <td>GIF (Graphics Interchange Format)</td>
  204. <td>X</td>
  205. <td>X</td>
  206. <td>X</td>
  207. <td>X</td>
  208. <td>X</td>
  209. <td>X</td>
  210. </tr>
  211. <tr>
  212. <td><a href="#jpeg">JPEG</a> (Joint Photographic Experts Group)</td>
  213. <td>X [1]</td>
  214. <td>X [1]</td>
  215. <td>X</td>
  216. <td>X</td>
  217. <td>X [1]</td>
  218. <td>X</td>
  219. </tr>
  220. <tr>
  221. <td><a href="#png">PNG</a> (Portable Network Graphic)</td>
  222. <td>X</td>
  223. <td>X</td>
  224. <td>X</td>
  225. <td>X</td>
  226. <td>X</td>
  227. <td>X</td>
  228. </tr>
  229. <tr>
  230. <td><a href="#svg">SVG</a> (Scalable Vector Graphics)</td>
  231. <td>X</td>
  232. <td>X</td>
  233. <td>X</td>
  234. <td>X</td>
  235. <td>X</td>
  236. <td>X</td>
  237. </tr>
  238. <tr>
  239. <td><a href="#tiff">TIFF</a> (Tag Image Format File)</td>
  240. <td>X [2]</td>
  241. <td>X [2]</td>
  242. <td>X</td>
  243. <td>X</td>
  244. <td>X [2]</td>
  245. <td>X</td>
  246. </tr>
  247. <tr>
  248. <td><a href="#wmf">WMF</a> (Windows Metafile)</td>
  249. <td>X</td>
  250. <td>X</td>
  251. <td>X</td>
  252. <td>X</td>
  253. <td>X</td>
  254. <td>X</td>
  255. </tr>
  256. </table>
  257. <p>
  258. Legend:
  259. </p>
  260. <ul>
  261. <li>
  262. [1]: Supported without the need to decode the image.
  263. </li>
  264. <li>
  265. [2]: Supported without the need to decode the image, but only for certain subtypes.
  266. </li>
  267. </ul>
  268. </section>
  269. </section>
  270. <section id="packages">
  271. <title>Graphics Packages</title>
  272. <section id="native">
  273. <title>XML Graphics Commons Native</title>
  274. <p>
  275. <a href="ext:xmlgraphics.apache.org/commons">XML Graphics Commons</a> supports a number
  276. of graphic file formats natively as basic functionality: all bitmap formats for which
  277. there are Image I/O codecs available (JPEG, PNG, GIF, TIFF, etc.), EPS and EMF.
  278. </p>
  279. </section>
  280. <section id="fop-native">
  281. <title>FOP Native</title>
  282. <p>
  283. FOP has no native image plug-ins for the image loading framework of its own but currently
  284. hosts the Batik-dependent SVG and WMF plug-ins until they can be moved to
  285. <a href="ext:xmlgraphics.apache.org/batik">Apache Batik</a>.
  286. </p>
  287. </section>
  288. <section id="batik">
  289. <title>Apache Batik</title>
  290. <p>
  291. <a href="ext:xmlgraphics.apache.org/batik">Apache Batik</a> will later receive the
  292. SVG and WMF plug-ins for the image loading framework that are currently hosted inside
  293. FOP.
  294. </p>
  295. <p>
  296. Current FOP distributions include a distribution of the
  297. <a class="fork" href="ext:xmlgraphics.apache.org/batik">Apache Batik</a>.
  298. Because Batik's API changes frequently, it is highly recommended that you use the
  299. version that ships with FOP, at least when running FOP.
  300. </p>
  301. <warning>Batik must be run in a graphical environment.</warning>
  302. <p>
  303. Batik must be run in a graphical environment.
  304. It uses AWT classes for rendering SVG, which in turn require an X server on Unixish
  305. systems. If you run a server without X, or if you can't connect to the X server due to
  306. security restrictions or policies (a so-called "headless" environment), SVG rendering
  307. will fail.
  308. </p>
  309. <p>Here are some workarounds:</p>
  310. <ul>
  311. <li>
  312. Start Java with the <code>-Djava.awt.headless=true</code> command line option.
  313. </li>
  314. <li>
  315. Install an X server which provides an in-memory framebuffer without actually using a
  316. screen device or any display hardware. One example is Xvfb.
  317. </li>
  318. <li>
  319. Install a toolkit which emulates AWT without the need for an underlying X server. One
  320. example is the <a href="http://www.eteks.com/pja/en">PJA toolkit</a>, which is free
  321. and comes with detailed installation instructions.
  322. </li>
  323. </ul>
  324. </section>
  325. <section id="imageio">
  326. <title>Image I/O</title>
  327. <p>
  328. The image loading framework in <a href="ext:xmlgraphics.apache.org/commons">XML Graphics Commons</a>
  329. provides a wrapper to load images through the
  330. <a class="fork" href="http://java.sun.com/j2se/1.4.2/docs/guide/imageio/index.html">JDK's Image I/O API</a> (JSR 015).
  331. Image I/O allows to dynamically add additional image codecs. An example of such an
  332. add-on library are the
  333. <a class="fork" href="http://java.sun.com/products/java-media/jai/">JAI Image I/O Tools</a>
  334. available from Sun.
  335. </p>
  336. </section>
  337. </section>
  338. <section id="image-formats">
  339. <title>Details on image formats</title>
  340. <section id="bmp">
  341. <title>BMP</title>
  342. <p>
  343. BMP images are supported through an Image I/O codec. There may be limitations of the
  344. codec which are outside the control of Apache FOP.
  345. </p>
  346. </section>
  347. <section id="emf">
  348. <title>EMF</title>
  349. <p>
  350. Windows Enhanced Metafiles (EMF) are only supported in RTF output where they are
  351. embedded without decoding.
  352. </p>
  353. </section>
  354. <section id="eps">
  355. <title>EPS</title>
  356. <p>Apache FOP allows to use EPS files when generating PostScript output only.</p>
  357. <p>
  358. Other output targets can't be supported at the moment because
  359. FOP lacks a PostScript interpreter. Furthermore, FOP is currently not able
  360. to parse the preview bitmaps sometimes contained in EPS files.
  361. </p>
  362. </section>
  363. <section id="gif">
  364. <title>GIF</title>
  365. <p>
  366. GIF images are supported through an Image&amp;nbsp;I/O codec. Transparency is supported but
  367. not guaranteed to work with every output format.
  368. </p>
  369. </section>
  370. <section id="jpeg">
  371. <title>JPEG</title>
  372. <p>
  373. FOP native support (i.e. the handling of undecoded images) of JPEG does not include all
  374. variants, especially those containing unusual color lookup tables and color profiles.
  375. If you have trouble with a JPEG image in FOP, try opening it with an image processing
  376. program (such as Photoshop or Gimp) and then saving it. Specifying 24-bit color output
  377. may also help. For the PDF and PostScript renderers most JPEG images can be passed
  378. through without decompression. User reports indicate that grayscale, RGB, and
  379. CMYK color spaces are all rendered properly. However, for other output formats, the
  380. JPEG images have to be decompressed. Tests have shown that there are some limitation
  381. in some Image&amp;nbsp;I/O codecs concerning images in the CMYK color space. Work-arounds are
  382. in place but may not always work as expected.
  383. </p>
  384. </section>
  385. <section id="png">
  386. <title>PNG</title>
  387. <p>
  388. PNG images are supported through an Image&amp;nbsp;I/O codec. Transparency is supported but
  389. not guaranteed to work with every output format.
  390. </p>
  391. </section>
  392. <section id="svg">
  393. <title>SVG</title>
  394. <section id="svg-intro">
  395. <title>Introduction</title>
  396. <p>FOP uses <a href="#batik"> Apache Batik</a> for SVG support.
  397. This format can be handled as an <code>fo:instream-foreign-object</code> or in a separate
  398. file referenced with <code>fo:external-graphic</code>.</p>
  399. <note>
  400. Batik's SVG Rasterizer utility may also be used to convert standalone SVG
  401. documents into PDF. For more information please see the
  402. <a href="http://xmlgraphics.apache.org/batik/svgrasterizer.html">SVG Rasterizer documentation</a>
  403. on the Batik site.
  404. </note>
  405. </section>
  406. <section id="svg-pdf-graphics">
  407. <title>Placing SVG Graphics into PDF</title>
  408. <p>
  409. The SVG is rendered into PDF by using PDF commands to draw and fill
  410. lines and curves. This means that the graphical objects created with
  411. this remain as vector graphics. The same applies to PostScript output.
  412. For other output formats the SVG graphic may be converted to a bitmap
  413. image.
  414. </p>
  415. <p>
  416. There are a number of SVG things that cannot be converted directly into
  417. PDF. Parts of the graphic such as effects, patterns and images are inserted
  418. into the PDF as a raster graphic. The resolution of these raster images can
  419. be controlled through the "target resolution" setting in the
  420. <a href="configuration.html">configuration</a>.</p>
  421. <p>
  422. Currently transparency is limited in PDF so many SVG images that
  423. contain effects or graphics with transparent areas may not be displayed
  424. correctly.
  425. </p>
  426. </section>
  427. <section id="svg-pdf-text">
  428. <title>Placing SVG Text into PDF and PostScript</title>
  429. <p>If possible, Batik will use normal PDF or PostScript text when inserting text. It does
  430. this by checking if the text can be drawn normally and the font is
  431. supported. This example svg <a href="../dev/svg/text.svg">text.svg</a> /
  432. <!--link href="../dev/svg/text.pdf"-->text.pdf<!--/link-->
  433. shows how various types and effects with text are handled.
  434. Note that tspan and outlined text are not yet implemented.</p>
  435. <p>
  436. Otherwise, text is converted and drawn as a set of shapes by Batik, using the
  437. stroking text painter. This means that a typical character will
  438. have about 10 curves (each curve consists of at least 20 characters).
  439. This can make the output files large and when it is viewed the
  440. viewer may not normally draw those fine curves very well (In Adobe Acrobat, turning on
  441. "Smooth Line Art" in the preferences will fix this). Copy/paste functionality
  442. will not be supported in this case.
  443. If the text is inserted into the output file using the inbuilt text commands
  444. it will use a single character.
  445. </p>
  446. <p>
  447. Note that because SVG text can be rendered as either text or a vector graphic, you
  448. may need to consider settings in your viewer for both. The Acrobat viewer has both
  449. "smooth line art" and "smooth text" settings that may need to be set for SVG images
  450. to be displayed nicely on your screen (see Edit / Preferences / Display).
  451. This setting will not affect the printing of your document, which should be OK in
  452. any case, but will only affect the quality of the screen display.</p>
  453. </section>
  454. <section id="svg-scaling">
  455. <title>Scaling</title>
  456. <p>
  457. Currently, SVG images are rendered with the dimensions specified <em>in the SVG
  458. file</em>, within the viewport specified in the fo:external-graphic element.
  459. For everything to work properly, the two should be equal. The SVG standard leaves
  460. this issue as an implementation detail. Additional scaling options are available
  461. through XSL-FO means.
  462. </p>
  463. <p>
  464. If you use pixels to specify the size of an SVG graphic the "source resolution" setting
  465. in the <a href="configuration.html">configuration</a> will be used to determine the
  466. size of a pixel. The use of pixels to specify sizes is discouraged as they may
  467. be interpreted differently in different environments.
  468. </p>
  469. </section>
  470. <section id="svg-problems">
  471. <title>Known Problems</title>
  472. <ul>
  473. <li>
  474. Soft mask transparency is combined with white so that it looks better
  475. on PDF 1.3 viewers but this causes the soft mask to be slightly lighter
  476. or darker on PDF 1.4 viewers.
  477. </li>
  478. <li>
  479. There is some problem with a gradient inside a pattern which may cause a PDF
  480. error when viewed in Acrobat 5.
  481. </li>
  482. <li>
  483. Text is not always handled correctly, it may select the wrong font
  484. especially if characters have multiple fonts in the font list.
  485. </li>
  486. <li>
  487. Uniform transparency for images and other SVG elements that are converted
  488. into a raster graphic are not drawn properly in PDF. The image is opaque.
  489. </li>
  490. </ul>
  491. </section>
  492. </section>
  493. <section id="tiff">
  494. <title>TIFF</title>
  495. <p>
  496. FOP can embed TIFF images without decompression into PDF, PostScript and AFP if they
  497. have either CCITT T.4, CCITT T.6, or JPEG compression. Otherwise, a TIFF-capable
  498. Image&amp;nbsp;I/O codec is necessary for decoding the image.
  499. </p>
  500. <p>
  501. There may be some limitation concerning images in the CMYK color space.
  502. </p>
  503. </section>
  504. <section id="wmf">
  505. <title>WMF</title>
  506. <p>
  507. Windows Metafiles (WMF) are supported through classes in
  508. <a href="ext:xmlgraphics.apache.org/batik">Apache Batik</a>. At the moment, support
  509. for this format is experimental and may not always work as expected.
  510. </p>
  511. </section>
  512. </section>
  513. <section id="resolution">
  514. <title>Graphics Resolution</title>
  515. <p>
  516. Some bitmapped image file formats store a dots-per-inch (dpi) or other resolution
  517. values. FOP tries to use this resolution information whenever possible to determine
  518. the image's intrinsic size. This size is used during the layout process when it is not
  519. superseded by an explicit size on fo:external-graphic (content-width and content-height
  520. properties).
  521. </p>
  522. <p>
  523. Please note that not all images contain resolution information. If it's not available
  524. the source resolution set on the FopFactory (or through the user configuration XML) is used.
  525. The default here is 72 dpi.
  526. </p>
  527. <p>
  528. Bitmap images are generally embedded into the output format at their original resolution
  529. (as is). No resampling of the image is performed. Explicit resampling is on our wishlist,
  530. but hasn't been implemented, yet. Bitmaps included in SVG graphics may be resampled to
  531. the resolution specified in the "target resolution" setting in the
  532. <a href="configuration.html">configuration</a> if SVG filters are applied. This can be
  533. used as a work-around to resample images in FO documents.
  534. </p>
  535. </section>
  536. <section id="page-selection">
  537. <title>Page selection for multi-page formats</title>
  538. <p>
  539. Some image formats such as TIFF support multiple pages/sub-images per file. You can
  540. select a particular page using a special URI fragment in the form:
  541. &lt;uri&gt;#page=&lt;nr&gt;
  542. (for example: <code>http://localhost/images/myimage.tiff#page=3</code>)
  543. </p>
  544. </section>
  545. <section id="caching">
  546. <title>Image caching</title>
  547. <p>
  548. FOP caches images between runs. There is one cache per FopFactory instance. The URI is
  549. used as a key to identify images which means that when a particular URI appears again,
  550. the image is taken from the cache. If you have a servlet that generates a different
  551. image each time it is called with the same URI you need to use a constantly
  552. changing dummy parameter on the URI to avoid caching.
  553. </p>
  554. <p>
  555. The image cache has been improved considerably in the redesigned code. Therefore,
  556. resetting the image cache should be a thing of the past. If you
  557. still experience OutOfMemoryErrors, please notify us.
  558. </p>
  559. <p>
  560. If all else fails, the image cache can be cleared like this:
  561. <code>fopFactory.getImageManager().getCache().clearCache();</code>
  562. </p>
  563. </section>
  564. </body>
  565. </document>