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.

images.xml 5.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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 V1.3//EN" "http://forrest.apache.org/dtd/document-v13.dtd">
  18. <document>
  19. <header>
  20. <title>Apache™ FOP Design: Images</title>
  21. <version>$Revision$</version>
  22. </header>
  23. <body>
  24. <section id="intro">
  25. <title>Introduction</title>
  26. <p>Images may only be needed to be loaded when the image is rendered to the
  27. output or to find the dimensions.<br/>
  28. An image url may be invalid, this can be costly to find out so we need to
  29. keep a list of invalid image urls.</p>
  30. <p>We have a number of different caching schemes that are possible.</p>
  31. <p>All images are referred to using the url given in the XSL:FO after
  32. removing "url('')" wrapping. This does
  33. not include any sort of resolving such as relative -&gt; absolute. The
  34. external graphic in the FO Tree and the image area in the Area Tree only
  35. have the url as a reference.
  36. The images are handled through a static interface in ImageFactory.</p>
  37. </section>
  38. <section>
  39. <title>Threading</title>
  40. <p>In a single threaded case with one document the image should be released
  41. as soon as the renderer caches it. If there are multiple documents then
  42. the images could be held in a weak cache in case another document needs to
  43. load the same image.</p>
  44. <p>In a multi threaded case many threads could be attempting to get the same
  45. image. We need to make sure an image will only be loaded once at a
  46. particular time. Once a particular document is finished then we can move
  47. all the images to a common weak cache.</p>
  48. </section>
  49. <section>
  50. <title>Caches</title>
  51. <section>
  52. <title>LRU</title>
  53. <p>All images are in a common cache regardless of context. To limit the size
  54. of the cache the LRU image is removed to keep the amount of memory used
  55. low. Each image can supply the amount of data held in memory.</p>
  56. </section>
  57. <section>
  58. <title>Context</title>
  59. <p>Images are cached according to the context, using the FOUserAgent as a key.
  60. Once the context is finished the images are added to a common weak hashmap
  61. so that other contexts can load these images or the data will be garbage
  62. collected if required.</p>
  63. <p>If images are to be used commonly then we cannot dispose of data in the
  64. FopImage when cached by the renderer. Also if different contexts have
  65. different base directories for resolving relative url's then the loading
  66. and caching must be separate. We can have a cache that shares images among
  67. all contexts or only loads an image for a context.</p>
  68. </section>
  69. <p>The cache uses an image loader so that it can synchronize the image
  70. loading on an image by image basis. Finding and adding an image loader to
  71. the cache is also synchronized to prevent thread problems.</p>
  72. </section>
  73. <section>
  74. <title>Invalid Images</title>
  75. <p>
  76. If an image cannot be loaded for some reason, for example the url is
  77. invalid or the image data is corrupt or an unknown type. Then it should
  78. only attempt to load the image once. All other attempts to get the image
  79. should return null so that it can be easily handled.<br/>
  80. This will prevent any extra processing or waiting.</p>
  81. </section>
  82. <section>
  83. <title>Reading</title>
  84. <p>Once a stream is opened for the image url then a set of image readers is
  85. used to determine what type of image it is. The reader can peek at the
  86. image header or if necessary load the image. The reader can also get the
  87. image size at this stage.
  88. The reader then can provide the mime type to create the image object to
  89. load the rest of the information.</p>
  90. </section>
  91. <section>
  92. <title>Data</title>
  93. <p>The data usually need for an image is the size and either a bitmap or the
  94. original data. Images such as jpeg and eps can be embedded into the
  95. document with the original data. SVG images are converted into a DOM which
  96. needs to be rendered to the PDF. Other images such as gif, tiff etc. are
  97. converted into a bitmap.
  98. Data is loaded by the FopImage by calling load(type) where type is the type of data to load.</p>
  99. </section>
  100. <section>
  101. <title>Rendering</title>
  102. <p>Different renderers need to have the information in different forms.</p>
  103. <section>
  104. <title>PDF</title>
  105. <dl><dt>original data</dt> <dd>JPG, EPS</dd>
  106. <dt>bitmap</dt> <dd>gif, tiff, bmp, png</dd>
  107. <dt>other</dt> <dd>SVG</dd></dl>
  108. </section>
  109. <section>
  110. <title>PS</title>
  111. <dl><dt>bitmap</dt> <dd>JPG, gif, tiff, bmp, png</dd>
  112. <dt>other</dt> <dd>SVG</dd></dl>
  113. </section>
  114. <section>
  115. <title>awt</title>
  116. <dl><dt>bitmap</dt> <dd>JPG, gif, tiff, bmp, png</dd>
  117. <dt>other</dt> <dd>SVG</dd></dl>
  118. </section>
  119. <p>The renderer uses the url to retrieve the image from the ImageFactory and
  120. then load the required data depending on the image mime type. If the
  121. renderer can insert the image into the document and use that data for all
  122. future references of the same image then it can cache the reference in the
  123. renderer and the image can be released from the image cache.</p>
  124. </section>
  125. </body>
  126. </document>