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.9KB

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