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.

TableAndCaptionLayoutManager.java 7.7KB

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.table;
  19. import org.apache.fop.area.Area;
  20. import org.apache.fop.area.Block;
  21. import org.apache.fop.fo.flow.table.TableAndCaption;
  22. import org.apache.fop.layoutmgr.BlockStackingLayoutManager;
  23. import org.apache.fop.layoutmgr.Keep;
  24. import org.apache.fop.layoutmgr.LayoutContext;
  25. import org.apache.fop.layoutmgr.PositionIterator;
  26. /**
  27. * LayoutManager for a table-and-caption FO.
  28. * A table and caption consists of a table and a caption.
  29. * The caption contains blocks that are positioned next to the
  30. * table on the caption side.
  31. * The caption blocks have an implicit keep with the table.
  32. * @todo Implement getNextKnuthElements()
  33. */
  34. public class TableAndCaptionLayoutManager extends BlockStackingLayoutManager {
  35. private Block curBlockArea;
  36. //private List childBreaks = new java.util.ArrayList();
  37. /**
  38. * Create a new table and caption layout manager.
  39. * @param node table-and-caption FO
  40. */
  41. public TableAndCaptionLayoutManager(TableAndCaption node) {
  42. super(node);
  43. }
  44. /**
  45. * Returns the table-and-caption formatting object.
  46. * @return the table-and-caption formatting object
  47. */
  48. public TableAndCaption getTableAndCaptionFO() {
  49. return (TableAndCaption)this.fobj;
  50. }
  51. /**
  52. * Get the next break possibility.
  53. *
  54. * @param context the layout context for getting breaks
  55. * @return the next break possibility
  56. */
  57. /*
  58. public BreakPoss getNextBreakPoss(LayoutContext context) {
  59. LayoutManager curLM; // currently active LM
  60. MinOptMax stackSize = new MinOptMax();
  61. // if starting add space before
  62. // stackSize.add(spaceBefore);
  63. BreakPoss lastPos = null;
  64. // if there is a caption then get the side and work out when
  65. // to handle it
  66. while ((curLM = getChildLM()) != null) {
  67. // Make break positions and return blocks!
  68. // Set up a LayoutContext
  69. int ipd = context.getRefIPD();
  70. BreakPoss bp;
  71. LayoutContext childLC = new LayoutContext(0);
  72. // if line layout manager then set stack limit to ipd
  73. // line LM actually generates a LineArea which is a block
  74. childLC.setStackLimit(
  75. MinOptMax.subtract(context.getStackLimit(),
  76. stackSize));
  77. childLC.setRefIPD(ipd);
  78. boolean over = false;
  79. while (!curLM.isFinished()) {
  80. if ((bp = curLM.getNextBreakPoss(childLC)) != null) {
  81. if (stackSize.opt + bp.getStackingSize().opt > context.getStackLimit().max) {
  82. // reset to last break
  83. if (lastPos != null) {
  84. LayoutManager lm = lastPos.getLayoutManager();
  85. lm.resetPosition(lastPos.getPosition());
  86. if (lm != curLM) {
  87. curLM.resetPosition(null);
  88. }
  89. } else {
  90. curLM.resetPosition(null);
  91. }
  92. over = true;
  93. break;
  94. }
  95. stackSize.add(bp.getStackingSize());
  96. lastPos = bp;
  97. childBreaks.add(bp);
  98. if (bp.nextBreakOverflows()) {
  99. over = true;
  100. break;
  101. }
  102. childLC.setStackLimit(MinOptMax.subtract(
  103. context.getStackLimit(), stackSize));
  104. }
  105. }
  106. BreakPoss breakPoss = new BreakPoss(
  107. new LeafPosition(this, childBreaks.size() - 1));
  108. if (over) {
  109. breakPoss.setFlag(BreakPoss.NEXT_OVERFLOWS, true);
  110. }
  111. breakPoss.setStackingSize(stackSize);
  112. return breakPoss;
  113. }
  114. setFinished(true);
  115. return null;
  116. }*/
  117. /**
  118. * Add the areas.
  119. *
  120. * @param parentIter the position iterator
  121. * @param layoutContext the layout context for adding areas
  122. */
  123. public void addAreas(PositionIterator parentIter,
  124. LayoutContext layoutContext) {
  125. getParentArea(null);
  126. addId();
  127. /* TODO: Reimplement using Knuth approach
  128. LayoutManager childLM;
  129. int iStartPos = 0;
  130. LayoutContext lc = new LayoutContext(0);
  131. while (parentIter.hasNext()) {
  132. LeafPosition lfp = (LeafPosition) parentIter.next();
  133. // Add the block areas to Area
  134. PositionIterator breakPosIter = new BreakPossPosIter(
  135. childBreaks, iStartPos, lfp.getLeafPos() + 1);
  136. iStartPos = lfp.getLeafPos() + 1;
  137. while ((childLM = breakPosIter.getNextChildLM()) != null) {
  138. childLM.addAreas(breakPosIter, lc);
  139. }
  140. }*/
  141. flush();
  142. //childBreaks.clear();
  143. curBlockArea = null;
  144. }
  145. /**
  146. * Return an Area which can contain the passed childArea. The childArea
  147. * may not yet have any content, but it has essential traits set.
  148. * In general, if the LayoutManager already has an Area it simply returns
  149. * it. Otherwise, it makes a new Area of the appropriate class.
  150. * It gets a parent area for its area by calling its parent LM.
  151. * Finally, based on the dimensions of the parent area, it initializes
  152. * its own area. This includes setting the content IPD and the maximum
  153. * BPD.
  154. *
  155. * @param childArea the child area to locate the parent
  156. * @return the area for this table and caption
  157. */
  158. public Area getParentArea(Area childArea) {
  159. if (curBlockArea == null) {
  160. curBlockArea = new Block();
  161. // Set up dimensions
  162. // Must get dimensions from parent area
  163. Area parentArea = parentLM.getParentArea(curBlockArea);
  164. int referenceIPD = parentArea.getIPD();
  165. curBlockArea.setIPD(referenceIPD);
  166. // Get reference IPD from parentArea
  167. setCurrentArea(curBlockArea); // ??? for generic operations
  168. }
  169. return curBlockArea;
  170. }
  171. /**
  172. * Add the child to the current area.
  173. *
  174. * @param childArea the area to add
  175. */
  176. public void addChildArea(Area childArea) {
  177. if (curBlockArea != null) {
  178. curBlockArea.addBlock((Block) childArea);
  179. }
  180. }
  181. /** {@inheritDoc} */
  182. public Keep getKeepWithNext() {
  183. return Keep.KEEP_AUTO;
  184. /* TODO Complete me!
  185. return KeepUtil.getCombinedBlockLevelKeepStrength(
  186. getTableAndCaptionFO().getKeepWithNext());
  187. */
  188. }
  189. /** {@inheritDoc} */
  190. public Keep getKeepWithPrevious() {
  191. return Keep.KEEP_AUTO;
  192. /* TODO Complete me!
  193. return KeepUtil.getCombinedBlockLevelKeepStrength(
  194. getTableAndCaptionFO().getKeepWithPrevious());
  195. */
  196. }
  197. }