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 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <?xml version="1.0" standalone="no"?>
  2. <!-- Overview -->
  3. <document>
  4. <header>
  5. <title>Images</title>
  6. <subtitle>All you wanted to know about Images in FOP !</subtitle>
  7. <authors> <person name="Keiron Liddle" email="keiron@aftexsw.com"/>
  8. </authors>
  9. </header>
  10. <body>
  11. <s1 title="Images in FOP"> <note> this is still in progress, input in the code is welcome. Needs documenting formats, testing.
  12. So all those people interested in images should get involved.</note>
  13. <p>Images may only be needed to be loaded when the image is rendered to the
  14. output or to find the dimensions.<br/>
  15. An image url may be invalid, this can be costly to find out so we need to
  16. keep a list of invalid image urls.</p>
  17. <p>We have a number of different caching schemes that are possible.</p>
  18. <p>All images are referred to using the url given in the XSL:FO after
  19. removing "url('')" wrapping. This does
  20. not include any sort of resolving such as relative -> absolute. The
  21. external graphic in the FO Tree and the image area in the Area Tree only
  22. have the url as a reference.
  23. The images are handled through a static interface in ImageFactory.<br/></p>
  24. <p>(insert image)</p>
  25. <s2 title="Threading">
  26. <p>In a single threaded case with one document the image should be released
  27. as soon as the renderer caches it. If there are multiple documents then
  28. the images could be held in a weak cache in case another document needs to
  29. load the same image.</p>
  30. <p>In a multi threaded case many threads could be attempting to get the same
  31. image. We need to make sure an image will only be loaded once at a
  32. particular time. Once a particular document is finished then we can move
  33. all the images to a common weak cache.</p>
  34. </s2>
  35. <s2 title="Caches">
  36. <s3 title="LRU">
  37. <p>All images are in a common cache regardless of context. To limit the size
  38. of the cache the LRU image is removed to keep the amount of memory used
  39. low. Each image can supply the amount of data held in memory.</p>
  40. </s3>
  41. <s3 title="Context">
  42. <p>Images are cached according to the context, using the FOUserAgent as a key.
  43. Once the context is finished the images are added to a common weak hashmap
  44. so that other contexts can load these images or the data will be garbage
  45. collected if required.</p>
  46. <p>If images are to be used commonly then we cannot dispose of data in the
  47. FopImage when cached by the renderer. Also if different contexts have
  48. different base directories for resolving relative url's then the loading
  49. and caching must be separate. We can have a cache that shares images among
  50. all contexts or only loads an image for a context.</p>
  51. </s3>
  52. <p>The cache uses an image loader so that it can synchronize the image
  53. loading on an image by image basis. Finding and adding an image loader to
  54. the cache is also synchronized to prevent thread problems.</p>
  55. </s2>
  56. <s2 title="Invalid Images">
  57. <p>
  58. If an image cannot be loaded for some reason, for example the url is
  59. invalid or the image data is corrupt or an unknown type. Then it should
  60. only attempt to load the image once. All other attempts to get the image
  61. should return null so that it can be easily handled.<br/>
  62. This will prevent any extra processing or waiting.</p>
  63. </s2>
  64. <s2 title="Reading">
  65. <p>Once a stream is opened for the image url then a set of image readers is
  66. used to determine what type of image it is. The reader can peek at the
  67. image header or if necessary load the image. The reader can also get the
  68. image size at this stage.
  69. The reader then can provide the mime type to create the image object to
  70. load the rest of the information.<br/></p></s2>
  71. <s2 title="Data">
  72. <p>The data usually need for an image is the size and either a bitmap or the
  73. original data. Images such as jpeg and eps can be embedded into the
  74. document with the original data. SVG images are converted into a DOM which
  75. needs to be rendered to the PDF. Other images such as gif, tiff etc. are
  76. converted into a bitmap.
  77. Data is loaded by the FopImage by calling load(type) where type is the type of data to load.<br/></p></s2>
  78. <s2 title="Rendering">
  79. <p>Different renderers need to have the information in different forms.</p>
  80. <s3 title="PDF">
  81. <dl><dt>original data</dt> <dd>JPG, EPS</dd>
  82. <dt>bitmap</dt> <dd>gif, tiff, bmp, png</dd>
  83. <dt>other</dt> <dd>SVG</dd></dl>
  84. </s3>
  85. <s3 title="PS">
  86. <dl><dt>bitmap</dt> <dd>JPG, gif, tiff, bmp, png</dd>
  87. <dt>other</dt> <dd>SVG</dd></dl>
  88. </s3>
  89. <s3 title="awt">
  90. <dl><dt>bitmap</dt> <dd>JPG, gif, tiff, bmp, png</dd>
  91. <dt>other</dt> <dd>SVG</dd></dl></s3>
  92. <p>The renderer uses the url to retrieve the image from the ImageFactory and
  93. then load the required data depending on the image mime type. If the
  94. renderer can insert the image into the document and use that data for all
  95. future references of the same image then it can cache the reference in the
  96. renderer and the image can be released from the image cache.</p></s2>
  97. </s1>
  98. </body></document>