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 7.5KB

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