Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

TableCaptionLayoutManager.java 8.0KB

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