Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

IFDocumentHandler.java 9.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  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. * Sets the intermediate format context object.
  75. * @param context the context object
  76. */
  77. void setContext(IFContext context);
  78. /**
  79. * Returns the associated intermediate format context object.
  80. * @return the context object
  81. */
  82. IFContext getContext();
  83. /**
  84. * Sets the JAXP Result object to receive the generated content.
  85. * @param result the JAXP Result object to receive the generated content
  86. * @throws IFException if an error occurs setting up the output
  87. */
  88. void setResult(Result result) throws IFException;
  89. /**
  90. * Sets the font set to work with.
  91. * @param fontInfo the font info object
  92. */
  93. void setFontInfo(FontInfo fontInfo);
  94. /**
  95. * Returns the font set to work with.
  96. * @return the font info object
  97. */
  98. FontInfo getFontInfo();
  99. /**
  100. * Sets the default font set (with no custom configuration).
  101. * @param fontInfo the font info object to populate
  102. */
  103. void setDefaultFontInfo(FontInfo fontInfo);
  104. /**
  105. * Returns the configurator for this document handler, if any.
  106. * @return the configurator or null if there's no configurator
  107. */
  108. IFDocumentHandlerConfigurator getConfigurator();
  109. /**
  110. * @return the structure tree builder
  111. */
  112. StructureTreeEventHandler getStructureTreeEventHandler();
  113. /**
  114. * Returns a document navigation handler if this feature is supported.
  115. * @return the document navigation handler or null if not supported
  116. */
  117. IFDocumentNavigationHandler getDocumentNavigationHandler();
  118. /**
  119. * Indicates whether the painter supports to handle the pages in mixed order rather than
  120. * ascending order.
  121. * @return true if out-of-order handling is supported
  122. */
  123. boolean supportsPagesOutOfOrder();
  124. /**
  125. * Returns the MIME type of the output format that is generated by this implementation.
  126. * @return the MIME type
  127. */
  128. String getMimeType();
  129. /**
  130. * Indicates the start of a document. This method may only be called once before any other
  131. * event method.
  132. * @throws IFException if an error occurs while handling this event
  133. */
  134. void startDocument() throws IFException;
  135. /**
  136. * Indicates the end of a document. This method may only be called once after the whole
  137. * document has been handled. Implementations can release resources (close streams). It is
  138. * an error to call any event method after this method.
  139. * @throws IFException if an error occurs while handling this event
  140. */
  141. void endDocument() throws IFException;
  142. /**
  143. * @param locale Locale of the document.
  144. */
  145. void setDocumentLocale(Locale locale);
  146. /**
  147. * Indicates the start of the document header. This method is called right after the
  148. * {@link #startDocument()} method. Extensions sent to this painter between
  149. * {@link #startDocumentHeader()} and {@link #endDocumentHeader()} apply to the document as
  150. * a whole (like document metadata).
  151. * @throws IFException if an error occurs while handling this event
  152. */
  153. void startDocumentHeader() throws IFException;
  154. /**
  155. * Indicates the end of the document header. This method is called before the first
  156. * page sequence.
  157. * @throws IFException if an error occurs while handling this event
  158. */
  159. void endDocumentHeader() throws IFException;
  160. /**
  161. * Indicates the start of the document trailer. This method is called after the last
  162. * page sequence. Extensions sent to the painter between
  163. * {@link #startDocumentTrailer()} and {@link #endDocumentTrailer()} apply to the document as
  164. * a whole and is used for document-level content that is only known after all pages have
  165. * been rendered (like named destinations or the bookmark tree).
  166. * @throws IFException if an error occurs while handling this event
  167. */
  168. void startDocumentTrailer() throws IFException;
  169. /**
  170. * Indicates the end of the document trailer. This method is called right before the
  171. * {@link #endDocument()} method.
  172. * @throws IFException if an error occurs while handling this event
  173. */
  174. void endDocumentTrailer() throws IFException;
  175. /**
  176. * Indicates the start of a new page sequence.
  177. * @param id the page sequence's identifier (or null if none is available)
  178. * @throws IFException if an error occurs while handling this event
  179. */
  180. void startPageSequence(String id) throws IFException;
  181. /**
  182. * Indicates the end of a page sequence.
  183. * @throws IFException if an error occurs while handling this event
  184. */
  185. void endPageSequence() throws IFException;
  186. /**
  187. * Indicates the start of a new page.
  188. * @param index the index of the page (0-based)
  189. * @param name the page name (usually the formatted page number)
  190. * @param pageMasterName the name of the simple-page-master that generated this page
  191. * @param size the size of the page (equivalent to the MediaBox in PDF)
  192. * @throws IFException if an error occurs while handling this event
  193. */
  194. void startPage(int index, String name, String pageMasterName, Dimension size)
  195. throws IFException;
  196. /**
  197. * Indicates the end of a page
  198. * @throws IFException if an error occurs while handling this event
  199. */
  200. void endPage() throws IFException;
  201. /**
  202. * Indicates the start of the page header.
  203. * @throws IFException if an error occurs while handling this event
  204. */
  205. void startPageHeader() throws IFException;
  206. /**
  207. * Indicates the end of the page header.
  208. * @throws IFException if an error occurs while handling this event
  209. */
  210. void endPageHeader() throws IFException;
  211. /**
  212. * Indicates the start of the page content. The method returns an {@link IFPainter} interface
  213. * which is used to paint the page contents.
  214. * @throws IFException if an error occurs while handling this event
  215. * @return the IFPainter for the page content
  216. */
  217. IFPainter startPageContent() throws IFException;
  218. /**
  219. * Indicates the end of the page content. Calls to the {@link IFPainter} returned by the
  220. * respective {@link #startPageContent()} method are illegal.
  221. * @throws IFException if an error occurs while handling this event
  222. */
  223. void endPageContent() throws IFException;
  224. /**
  225. * Indicates the start of the page trailer. The page trailer is used for writing down page
  226. * elements which are only know after handling the page itself (like PDF targets).
  227. * @throws IFException if an error occurs while handling this event
  228. */
  229. void startPageTrailer() throws IFException;
  230. /**
  231. * Indicates the end of the page trailer.
  232. * @throws IFException if an error occurs while handling this event
  233. */
  234. void endPageTrailer() throws IFException;
  235. /**
  236. * Handles an extension object. This can be a DOM document or any arbitrary
  237. * object. If an implementation doesn't know how to handle a particular extension it is simply
  238. * ignored.
  239. * @param extension the extension object
  240. * @throws IFException if an error occurs while handling this event
  241. */
  242. void handleExtensionObject(Object extension) throws IFException;
  243. }