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.

LayoutManager.java 9.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  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.layoutmgr;
  19. import java.util.List;
  20. import java.util.Stack;
  21. import org.apache.fop.area.Area;
  22. import org.apache.fop.datatypes.PercentBaseContext;
  23. import org.apache.fop.fo.FObj;
  24. /**
  25. * The interface for all LayoutManagers.
  26. */
  27. public interface LayoutManager extends PercentBaseContext {
  28. /**
  29. * Set the parent layout manager.
  30. * The parent layout manager is required for adding areas.
  31. *
  32. * @param lm the parent layout manager
  33. */
  34. void setParent(LayoutManager lm);
  35. /**
  36. * Get the parent layout manager.
  37. * @return the parent layout manager.
  38. */
  39. LayoutManager getParent();
  40. /**
  41. * initialize the layout manager. Allows each layout manager
  42. * to calculate often used values.
  43. */
  44. void initialize();
  45. /**
  46. * Get the active PageSequenceLayoutManager instance for this
  47. * layout process.
  48. * @return the PageSequenceLayoutManager
  49. */
  50. PageSequenceLayoutManager getPSLM();
  51. /**
  52. * Return a value indicating whether this LayoutManager has laid out
  53. * all its content (or generated BreakPossibilities for all content.)
  54. *
  55. * @return true if this layout manager is finished
  56. */
  57. boolean isFinished();
  58. /**
  59. * Set a flag indicating whether the LayoutManager has laid out all
  60. * its content. This is generally called by the LM itself, but can
  61. * be called by a parentLM when backtracking.
  62. *
  63. * @param isFinished the value to set the finished flag to
  64. */
  65. void setFinished(boolean isFinished);
  66. /**
  67. * Get the parent area for an area.
  68. * This should get the parent depending on the class of the
  69. * area passed in.
  70. *
  71. * @param childArea the child area to get the parent for
  72. * @return the parent Area
  73. */
  74. Area getParentArea(Area childArea);
  75. /**
  76. * Add the area as a child of the current area.
  77. * This is called by child layout managers to add their
  78. * areas as children of the current area.
  79. *
  80. * @param childArea the child area to add
  81. */
  82. void addChildArea(Area childArea);
  83. /**
  84. * Tell the layout manager to add all the child areas implied
  85. * by Position objects which will be returned by the
  86. * Iterator.
  87. *
  88. * @param posIter the position iterator
  89. * @param context the context
  90. */
  91. void addAreas(PositionIterator posIter, LayoutContext context);
  92. /**
  93. * Create more child LMs of the parent, up to child LM index pos
  94. * @param pos index up to which child LMs are requested
  95. * @return true if requested index does exist
  96. */
  97. boolean createNextChildLMs(int pos);
  98. /**
  99. * @return the list of child LMs
  100. */
  101. List getChildLMs();
  102. /**
  103. * Add the LM in the argument to the list of child LMs;
  104. * set this LM as the parent;
  105. * initialize the LM.
  106. * @param lm the LM to be added
  107. */
  108. void addChildLM(LayoutManager lm);
  109. /**
  110. * Add the LMs in the argument to the list of child LMs;
  111. * @param newLMs the list of LMs to be added
  112. */
  113. void addChildLMs(List newLMs);
  114. /**
  115. * Get a sequence of KnuthElements representing the content
  116. * of the node assigned to the LM.
  117. *
  118. * @param context the LayoutContext used to store layout information
  119. * @param alignment the desired text alignment
  120. * @return the list of KnuthElements
  121. */
  122. List getNextKnuthElements(LayoutContext context, int alignment);
  123. /**
  124. * Get a sequence of KnuthElements representing the content
  125. * of the node assigned to the LM, after changes have been applied
  126. *
  127. * In the context of line breaking, this method is called after hyphenation has
  128. * been performed, in order to receive the sequence of elements representing the
  129. * text together with all possible hyphenation points.
  130. * For example, if the text "representation" originates a single box element
  131. * when getNextKnuthElements() is called, it will be now split in syllables
  132. * (rep-re-sen-ta-tion) each one originating a box and divided by additional
  133. * elements allowing a line break.
  134. *
  135. * In the context of page breaking, this method is called only if the pages need
  136. * to be "vertically justified" modifying (also) the quantity of lines created by
  137. * the paragraphs, and after a first page breaking has been performed.
  138. * According to the result of the first page breaking, each paragraph now knows
  139. * how many lines it must create (among the existing layout possibilities) and
  140. * has to create a sequence of elements representing this layout; in particular,
  141. * each box, representing a line, will contain a LineBreakPositions that will be
  142. * used in the addAreas() phase.
  143. *
  144. * LMs having children look at the old list of elements in order to know which
  145. * ones they must get the new elements from, as break conditions of preserved
  146. * linefeeds can divide children into smaller groups (page sequences or
  147. * paragraphs).
  148. * LMs having no children can simply return the old elements if they have nothing
  149. * to change.
  150. *
  151. * Inline LMs need to know the text alignment because it affects the elements
  152. * representing feasible breaks between syllables.
  153. *
  154. * @param oldList the elements to replace
  155. * @param alignment the desired text alignment
  156. * @return the updated list of KnuthElements
  157. */
  158. List getChangedKnuthElements(List oldList, int alignment);
  159. /**
  160. * Whether the FO handled by this layout manager has a descendant (including itself)
  161. * that will generate a line-area.
  162. *
  163. * @return {@code true} if a descendant line-area will be generated, {@code false} otherwise
  164. */
  165. boolean hasLineAreaDescendant();
  166. /**
  167. * Returns the position of the dominant-baseline of this FO's first descendant
  168. * line-area. <p>The behavior of this method is undefined if this FO has no descendant
  169. * line-area, and an exception may be thrown. See {@link #hasLineAreaDescendant()}</p>
  170. *
  171. * @return this FO's space-before plus the distance from the before-edge of its
  172. * allocation-rectangle to the dominant-baseline of the first line-area descendant
  173. * @see #hasLineAreaDescendant()
  174. */
  175. int getBaselineOffset();
  176. /**
  177. * Returns the IPD of the content area
  178. * @return the IPD of the content area
  179. */
  180. int getContentAreaIPD();
  181. /**
  182. * Returns the BPD of the content area
  183. * @return the BPD of the content area
  184. */
  185. int getContentAreaBPD();
  186. /**
  187. * Returns an indication if the layout manager generates a reference area.
  188. * @return True if the layout manager generates a reference area
  189. */
  190. boolean getGeneratesReferenceArea();
  191. /**
  192. * Returns an indication if the layout manager generates a block area.
  193. * @return True if the layout manager generates a block area
  194. */
  195. boolean getGeneratesBlockArea();
  196. /**
  197. * Returns an indication if the layout manager generates a line area.
  198. * @return True if the layout manager generates a line area
  199. */
  200. boolean getGeneratesLineArea();
  201. /**
  202. * Returns the fo this layout manager is associated with.
  203. * @return The fo for this layout manager or null.
  204. */
  205. FObj getFObj();
  206. /**
  207. * Adds a Position to the Position participating in the first|last determination by assigning
  208. * it a unique position index.
  209. * @param pos the Position
  210. * @return the same Position but with a position index
  211. */
  212. Position notifyPos(Position pos);
  213. /**
  214. * Re-initializes this layout manager in order to re-generate its Knuth
  215. * elements according to a new IPD value.
  216. */
  217. void reset();
  218. /**
  219. * Returns {@code true} if this layout manager is able to re-generate its
  220. * Knuth elements after an IPD change.
  221. *
  222. * @return {@code true} if this layout manager can be restarted after an IPD
  223. * change
  224. */
  225. boolean isRestartable();
  226. /**
  227. * Returns an updated list of Knuth elements corresponding to this layout
  228. * manager, after a change of IPD has been detected.
  229. *
  230. * @param context the layout context
  231. * @param alignment the alignment
  232. * @param lmStack the stack of LMs that are active at the IPD change
  233. * @param positionAtIPDChange the position corresponding to the element
  234. * finishing the page before the IPD change
  235. * @param restartAtLM if not null, the layout manager from which to restart.
  236. * That is, the IPD change occurs between two block elements and not inside
  237. * a paragraph
  238. * @return an updated list of elements, taking the new IPD into account
  239. */
  240. List getNextKnuthElements(LayoutContext context, int alignment, Stack lmStack,
  241. Position positionAtIPDChange, LayoutManager restartAtLM);
  242. boolean isFromFootnote();
  243. void setFromFootnote(boolean fromFootnote);
  244. }