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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. /*
  2. * Copyright 1999-2004 The Apache Software Foundation.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. /* $Id$ */
  17. package org.apache.fop.layoutmgr;
  18. import java.util.LinkedList;
  19. import java.util.List;
  20. import java.util.Map;
  21. import org.apache.fop.fo.flow.Marker;
  22. import org.apache.fop.area.Area;
  23. import org.apache.fop.area.Resolvable;
  24. import org.apache.fop.area.PageViewport;
  25. import org.apache.fop.fo.FObj;
  26. /**
  27. * The interface for all LayoutManagers.
  28. */
  29. public interface LayoutManager {
  30. /**
  31. * Set the FO object for this layout manager.
  32. * For layout managers that are created without an FO
  33. * this may not be called.
  34. *
  35. * @param obj the FO object for this layout manager
  36. */
  37. void setFObj(FObj obj);
  38. /**
  39. * Set the parent layout manager.
  40. * The parent layout manager is required for adding areas.
  41. *
  42. * @param lm the parent layout manager
  43. */
  44. void setParent(LayoutManager lm);
  45. /**
  46. * Get the parent layout manager.
  47. * @return the parent layout manager.
  48. */
  49. LayoutManager getParent();
  50. /**
  51. * Initialize this layout manager.
  52. */
  53. void initialize();
  54. /**
  55. * Generates inline areas.
  56. * This is used to check if the layout manager generates inline
  57. * areas.
  58. *
  59. * @return true if the layout manager generates inline areas
  60. */
  61. boolean generatesInlineAreas();
  62. /**
  63. * Return true if the next area which would be generated by this
  64. * LayoutManager could start a new line (or flow for block-level FO).
  65. *
  66. * @param lc the layout context
  67. * @return true if can break before
  68. */
  69. boolean canBreakBefore(LayoutContext lc);
  70. /**
  71. * Generate and return the next break possibility.
  72. *
  73. * @param context The layout context contains information about pending
  74. * space specifiers from ancestor areas or previous areas, reference
  75. * area inline-progression-dimension and various other layout-related
  76. * information.
  77. * @return the next break position
  78. */
  79. BreakPoss getNextBreakPoss(LayoutContext context);
  80. /**
  81. * Reset to the position.
  82. *
  83. * @param position
  84. */
  85. void resetPosition(Position position);
  86. /**
  87. * Get the word chars between two positions and
  88. * append to the string buffer. The positions could
  89. * span multiple layout managers.
  90. *
  91. * @param sbChars the string buffer to append the word chars
  92. * @param bp1 the start position
  93. * @param bp2 the end position
  94. */
  95. void getWordChars(StringBuffer sbChars, Position bp1,
  96. Position bp2);
  97. /**
  98. * Return a value indicating whether this LayoutManager has laid out
  99. * all its content (or generated BreakPossibilities for all content.)
  100. *
  101. * @return true if this layout manager is finished
  102. */
  103. boolean isFinished();
  104. /**
  105. * Set a flag indicating whether the LayoutManager has laid out all
  106. * its content. This is generally called by the LM itself, but can
  107. * be called by a parentLM when backtracking.
  108. *
  109. * @param isFinished the value to set the finished flag to
  110. */
  111. void setFinished(boolean isFinished);
  112. /**
  113. * Get the parent area for an area.
  114. * This should get the parent depending on the class of the
  115. * area passed in.
  116. *
  117. * @param childArea the child area to get the parent for
  118. * @return the parent Area
  119. */
  120. Area getParentArea(Area childArea);
  121. /**
  122. * Add the area as a child of the current area.
  123. * This is called by child layout managers to add their
  124. * areas as children of the current area.
  125. *
  126. * @param childArea the child area to add
  127. */
  128. void addChild(Area childArea);
  129. /**
  130. * Tell the layout manager to add all the child areas implied
  131. * by Position objects which will be returned by the
  132. * Iterator.
  133. *
  134. * @param posIter the position iterator
  135. * @param context the context
  136. */
  137. void addAreas(PositionIterator posIter, LayoutContext context);
  138. /**
  139. * Get the string of the current page number.
  140. *
  141. * @return the string for the current page number
  142. */
  143. String getCurrentPageNumber();
  144. /**
  145. * Resolve the id reference.
  146. * This is called by an area looking for an id reference.
  147. * If the id reference is not found then it should add a resolvable object.
  148. *
  149. * @param ref the id reference
  150. * @return the page containing the id reference or null if not found
  151. */
  152. PageViewport resolveRefID(String ref);
  153. /**
  154. * Add an id to the page.
  155. * (todo) add the location of the area on the page
  156. *
  157. * @param id the id reference to add.
  158. */
  159. void addIDToPage(String id);
  160. /**
  161. * Add an unresolved area.
  162. * The is used to add a resolvable object to the page for a given id.
  163. *
  164. * @param id the id reference this object needs for resolving
  165. * @param res the resolvable object
  166. */
  167. void addUnresolvedArea(String id, Resolvable res);
  168. /**
  169. * Add the marker.
  170. * A number of formatting objects may contain markers. This
  171. * method is used to add those markers to the page.
  172. *
  173. * @param name the marker class name
  174. * @param start true if the formatting object is starting false is finishing
  175. * @param isfirst a flag for is first
  176. */
  177. void addMarkerMap(Map marks, boolean start, boolean isfirst);
  178. /**
  179. * Retrieve a marker.
  180. * This method is used when retrieve a marker.
  181. *
  182. * @param name the class name of the marker
  183. * @param pos the retrieve position
  184. * @param boundary the boundary for retrieving the marker
  185. * @return the layout manaager of the retrieved marker if any
  186. */
  187. Marker retrieveMarker(String name, int pos, int boundary);
  188. /**
  189. * Load next child LMs, up to child LM index pos
  190. * @param pos index up to which child LMs are requested
  191. * @return if requested index does exist
  192. */
  193. boolean preLoadNext(int pos);
  194. /**
  195. * @return the list of child LMs
  196. */
  197. List getChildLMs();
  198. /**
  199. * Add the LM in the argument to the list of child LMs;
  200. * set this LM as the parent;
  201. * initialize the LM.
  202. * @param lm the LM to be added
  203. */
  204. void addChildLM(LayoutManager lm);
  205. /**
  206. * Add the LMs in the argument to the list of child LMs;
  207. * @param newLMs the list of LMs to be added
  208. */
  209. void addChildLMs(List newLMs);
  210. LinkedList getNextKnuthElements(LayoutContext context, int alignment);
  211. KnuthElement addALetterSpaceTo(KnuthElement element);
  212. void getWordChars(StringBuffer sbChars, Position pos);
  213. void hyphenate(Position pos, HyphContext hc);
  214. boolean applyChanges(List oldList);
  215. LinkedList getChangedKnuthElements(List oldList, int flaggedPenalty,
  216. int alignment);
  217. int getWordSpaceIPD();
  218. }