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.

Renderer.java 5.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with
  4. * this work for additional information regarding copyright ownership.
  5. * The ASF licenses this file to You under the Apache License, Version 2.0
  6. * (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. /* $Id$ */
  18. package org.apache.fop.render;
  19. // Java
  20. import java.io.IOException;
  21. import java.io.OutputStream;
  22. import java.util.Locale;
  23. import org.apache.fop.apps.FOPException;
  24. import org.apache.fop.apps.FOUserAgent;
  25. import org.apache.fop.area.LineArea;
  26. import org.apache.fop.area.OffDocumentItem;
  27. import org.apache.fop.area.PageSequence;
  28. import org.apache.fop.area.PageViewport;
  29. import org.apache.fop.fonts.FontInfo;
  30. /**
  31. * Interface implemented by all renderers. This interface is used to control
  32. * the rendering of pages and to let block and inline level areas call the
  33. * appropriate method to render themselves. <p>
  34. *
  35. * A Renderer implementation takes areas/spaces and produces output in some
  36. * format.</p> <p>
  37. *
  38. * Typically, most renderers are subclassed from FOP's abstract implementations
  39. * ({@link AbstractRenderer}, {@link PrintRenderer}) which already handle a lot
  40. * of things letting you concentrate on the details of the output format.
  41. */
  42. public interface Renderer {
  43. /**
  44. * Role constant for Avalon.
  45. */
  46. String ROLE = Renderer.class.getName();
  47. /**
  48. * Get the MIME type of the renderer.
  49. *
  50. * @return The MIME type of the renderer, may return null if not applicable.
  51. */
  52. String getMimeType();
  53. /**
  54. * Initiates the rendering phase.
  55. * This must only be called once for a rendering. If
  56. * stopRenderer is called then this may be called again
  57. * for a new document rendering.
  58. *
  59. * @param outputStream The OutputStream to use for output
  60. * @exception IOException If an I/O error occurs
  61. */
  62. void startRenderer(OutputStream outputStream)
  63. throws IOException;
  64. /**
  65. * Signals the end of the rendering phase.
  66. * The renderer should reset to an initial state and dispose of
  67. * any resources for the completed rendering.
  68. *
  69. * @exception IOException If an I/O error occurs
  70. */
  71. void stopRenderer()
  72. throws IOException;
  73. /**
  74. * Set the User Agent.
  75. *
  76. * @param agent The User Agent
  77. */
  78. void setUserAgent(FOUserAgent agent);
  79. /**
  80. * Returns the associated user agent.
  81. * @return the user agent
  82. */
  83. FOUserAgent getUserAgent();
  84. /**
  85. * Set up the given FontInfo.
  86. *
  87. * @param fontInfo The font information
  88. * @throws FOPException if an error occurs while setting up the font info object
  89. */
  90. void setupFontInfo(FontInfo fontInfo) throws FOPException;
  91. /**
  92. * Reports if out of order rendering is supported. <p>
  93. *
  94. * Normally, all pages of a document are rendered in their natural order
  95. * (page 1, page 2, page 3 etc.). Some output formats (such as PDF) allow
  96. * pages to be output in random order. This is helpful to reduce resource
  97. * strain on the system because a page that cannot be fully resolved
  98. * doesn't block subsequent pages that are already fully resolved. </p>
  99. *
  100. * @return True if this renderer supports out of order rendering.
  101. */
  102. boolean supportsOutOfOrder();
  103. /**
  104. *
  105. * @param locale Locale of the language
  106. */
  107. void setDocumentLocale(Locale locale);
  108. /**
  109. * Tells the renderer to process an item not explicitly placed on the
  110. * document (e.g., PDF bookmarks). Note - not all renderers will process
  111. * all off-document items.
  112. *
  113. * @param odi The off-document item to be rendered
  114. */
  115. void processOffDocumentItem(OffDocumentItem odi);
  116. /**
  117. * @return the adapter for painting Java2D images (or null if not supported)
  118. */
  119. Graphics2DAdapter getGraphics2DAdapter();
  120. /**
  121. * @return the adapter for painting RenderedImages (or null if not supported)
  122. */
  123. ImageAdapter getImageAdapter();
  124. /**
  125. * This is called if the renderer supports out of order rendering. The
  126. * renderer should prepare the page so that a page further on in the set of
  127. * pages can be rendered. The body of the page should not be rendered. The
  128. * page will be rendered at a later time by the call to {@link
  129. * #renderPage(PageViewport)}.
  130. *
  131. * @param page The page viewport to use
  132. */
  133. void preparePage(PageViewport page);
  134. /**
  135. * Tells the renderer that a new page sequence starts.
  136. *
  137. * @param seqTitle The title of the page sequence
  138. * @deprecated Use {@link #startPageSequence(PageSequence)} instead
  139. */
  140. void startPageSequence(LineArea seqTitle);
  141. /**
  142. * Tells the renderer that a new page sequence starts.
  143. *
  144. * @param pageSequence the page sequence
  145. */
  146. void startPageSequence(PageSequence pageSequence);
  147. /**
  148. * Tells the renderer to render a particular page. A renderer typically
  149. * responds by packing up the current page and writing it immediately to the
  150. * output device.
  151. *
  152. * @param page The page to be rendered
  153. * @exception IOException if an I/O error occurs
  154. * @exception FOPException if a FOP interal error occurs.
  155. */
  156. void renderPage(PageViewport page)
  157. throws IOException, FOPException;
  158. }