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.

TableCaptionLayoutManager.java 7.6KB

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