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.

IFDocumentHandler.java 8.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  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.intermediate;
  19. import java.awt.Dimension;
  20. import javax.xml.transform.Result;
  21. import org.apache.fop.apps.FOUserAgent;
  22. import org.apache.fop.fonts.FontInfo;
  23. /**
  24. * Interface used to paint whole documents layouted by Apache FOP.
  25. * <p>
  26. * Call sequence:
  27. * <p>
  28. * <pre>
  29. * startDocument()
  30. * startDocumentHeader()
  31. * [handleExtension()]*
  32. * endDocumentHeader()
  33. * [
  34. * startPageSequence()
  35. * [
  36. * startPage()
  37. * startPageHeader()
  38. * [handleExtension()]*
  39. * endPageHeader()
  40. * startPageContent()
  41. * (#box)+
  42. * endPageContent()
  43. * startPageTrailer()
  44. * (addTarget())*
  45. * endPageTrailer()
  46. * endPage()
  47. * ]*
  48. * endPageSequence()
  49. * ]*
  50. * startDocumentTrailer()
  51. * [handleExtension()]*
  52. * endDocumentTrailer()
  53. * endDocument()
  54. *
  55. * #box:
  56. * startBox() (#pageContent)+ endBox() |
  57. * startViewport() (#pageContext)+ endViewport()
  58. *
  59. * #pageContent:
  60. * (
  61. * setFont() |
  62. * drawText() |
  63. * drawRect() |
  64. * drawImage() |
  65. * TODO etc. etc. |
  66. * handleExtensionObject()
  67. * )
  68. * </pre>
  69. */
  70. public interface IFDocumentHandler {
  71. /**
  72. * Set the user agent.
  73. * @param userAgent The user agent
  74. */
  75. void setUserAgent(FOUserAgent userAgent);
  76. /**
  77. * Returns the associated user agent.
  78. * @return the user agent
  79. */
  80. FOUserAgent getUserAgent();
  81. /**
  82. * Sets the JAXP Result object to receive the generated content.
  83. * @param result the JAXP Result object to receive the generated content
  84. * @throws IFException if an error occurs setting up the output
  85. */
  86. void setResult(Result result) throws IFException;
  87. /**
  88. * Sets the font set to work with.
  89. * @param fontInfo the font info object
  90. */
  91. void setFontInfo(FontInfo fontInfo);
  92. /**
  93. * Returns the font set to work with.
  94. * @return the font info object
  95. */
  96. FontInfo getFontInfo();
  97. /**
  98. * Sets the default font set (with no custom configuration).
  99. * @param fontInfo the font info object to populate
  100. */
  101. void setDefaultFontInfo(FontInfo fontInfo);
  102. /**
  103. * Returns the configurator for this document handler, if any.
  104. * @return the configurator or null if there's no configurator
  105. */
  106. IFDocumentHandlerConfigurator getConfigurator();
  107. /**
  108. * Returns a document navigation handler if this feature is supported.
  109. * @return the document navigation handler or null if not supported
  110. */
  111. IFDocumentNavigationHandler getDocumentNavigationHandler();
  112. /**
  113. * Indicates whether the painter supports to handle the pages in mixed order rather than
  114. * ascending order.
  115. * @return true if out-of-order handling is supported
  116. */
  117. boolean supportsPagesOutOfOrder();
  118. /**
  119. * Returns the MIME type of the output format that is generated by this implementation.
  120. * @return the MIME type
  121. */
  122. String getMimeType();
  123. /**
  124. * Indicates the start of a document. This method may only be called once before any other
  125. * event method.
  126. * @throws IFException if an error occurs while handling this event
  127. */
  128. void startDocument() throws IFException;
  129. /**
  130. * Indicates the end of a document. This method may only be called once after the whole
  131. * document has been handled. Implementations can release resources (close streams). It is
  132. * an error to call any event method after this method.
  133. * @throws IFException if an error occurs while handling this event
  134. */
  135. void endDocument() throws IFException;
  136. /**
  137. * Indicates the start of the document header. This method is called right after the
  138. * {@code #startDocument()} method. Extensions sent to this painter between
  139. * {@code #startDocumentHeader()} and {@code #endDocumentHeader()} apply to the document as
  140. * a whole (like document metadata).
  141. * @throws IFException if an error occurs while handling this event
  142. */
  143. void startDocumentHeader() throws IFException;
  144. /**
  145. * Indicates the end of the document header. This method is called before the first
  146. * page sequence.
  147. * @throws IFException if an error occurs while handling this event
  148. */
  149. void endDocumentHeader() throws IFException;
  150. /**
  151. * Indicates the start of the document trailer. This method is called after the last
  152. * page sequence. Extensions sent to the painter between
  153. * {@code #startDocumentTrailer()} and {@code #endDocumentTrailer()} apply to the document as
  154. * a whole and is used for document-level content that is only known after all pages have
  155. * been rendered (like named destinations or the bookmark tree).
  156. * @throws IFException if an error occurs while handling this event
  157. */
  158. void startDocumentTrailer() throws IFException;
  159. /**
  160. * Indicates the end of the document trailer. This method is called right before the
  161. * {@code #endDocument()} method.
  162. * @throws IFException if an error occurs while handling this event
  163. */
  164. void endDocumentTrailer() throws IFException;
  165. /**
  166. * Indicates the start of a new page sequence.
  167. * @param id the page sequence's identifier (or null if none is available)
  168. * @throws IFException if an error occurs while handling this event
  169. */
  170. void startPageSequence(String id) throws IFException;
  171. /**
  172. * Indicates the end of a page sequence.
  173. * @throws IFException if an error occurs while handling this event
  174. */
  175. void endPageSequence() throws IFException;
  176. /**
  177. * Indicates the start of a new page.
  178. * @param index the index of the page (0-based)
  179. * @param name the page name (usually the formatted page number)
  180. * @param pageMasterName the name of the simple-page-master that generated this page
  181. * @param size the size of the page (equivalent to the MediaBox in PDF)
  182. * @throws IFException if an error occurs while handling this event
  183. */
  184. void startPage(int index, String name, String pageMasterName, Dimension size)
  185. throws IFException;
  186. /**
  187. * Indicates the end of a page
  188. * @throws IFException if an error occurs while handling this event
  189. */
  190. void endPage() throws IFException;
  191. /**
  192. * Indicates the start of the page header.
  193. * @throws IFException if an error occurs while handling this event
  194. */
  195. void startPageHeader() throws IFException;
  196. /**
  197. * Indicates the end of the page header.
  198. * @throws IFException if an error occurs while handling this event
  199. */
  200. void endPageHeader() throws IFException;
  201. /**
  202. * Indicates the start of the page content. The method returns an {@code IFPainter} interface
  203. * which is used to paint the page contents.
  204. * @throws IFException if an error occurs while handling this event
  205. * @return the IFPainter for the page content
  206. */
  207. IFPainter startPageContent() throws IFException;
  208. /**
  209. * Indicates the end of the page content. Calls to the {@code IFPainter} returned by the
  210. * respective {@code #startPageContent()} method are illegal.
  211. * @throws IFException if an error occurs while handling this event
  212. */
  213. void endPageContent() throws IFException;
  214. /**
  215. * Indicates the start of the page trailer. The page trailer is used for writing down page
  216. * elements which are only know after handling the page itself (like PDF targets).
  217. * @throws IFException if an error occurs while handling this event
  218. */
  219. void startPageTrailer() throws IFException;
  220. /**
  221. * Indicates the end of the page trailer.
  222. * @throws IFException if an error occurs while handling this event
  223. */
  224. void endPageTrailer() throws IFException;
  225. /**
  226. * Handles an extension object. This can be a DOM document or any arbitrary
  227. * object. If an implementation doesn't know how to handle a particular extension it is simply
  228. * ignored.
  229. * @param extension the extension object
  230. * @throws IFException if an error occurs while handling this event
  231. */
  232. void handleExtensionObject(Object extension) throws IFException;
  233. //TODO Prototype the following:
  234. //ContentHandler handleExtension() throws Exception
  235. }