選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

FlowLayoutManager.java 5.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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 org.apache.fop.fo.flow.Marker;
  19. import org.apache.fop.area.Area;
  20. import org.apache.fop.area.BlockParent;
  21. import java.util.ArrayList;
  22. import java.util.List;
  23. import org.apache.fop.traits.MinOptMax;
  24. /**
  25. * LayoutManager for an fo:flow object.
  26. * Its parent LM is the PageLayoutManager.
  27. * This LM is responsible for getting columns of the appropriate size
  28. * and filling them with block-level areas generated by its children.
  29. */
  30. public class FlowLayoutManager extends BlockStackingLayoutManager {
  31. /** List of break possibilities */
  32. protected List blockBreaks = new ArrayList();
  33. /** Array of areas currently being filled stored by area class */
  34. private BlockParent[] currentAreas = new BlockParent[Area.CLASS_MAX];
  35. private int iStartPos = 0;
  36. /**
  37. * This is the top level layout manager.
  38. * It is created by the PageSequence FO.
  39. */
  40. public FlowLayoutManager() {
  41. }
  42. /**
  43. * @see org.apache.fop.layoutmgr.LayoutProcessor#getNextBreakPoss(LayoutContext)
  44. */
  45. public BreakPoss getNextBreakPoss(LayoutContext context) {
  46. // currently active LM
  47. LayoutProcessor curLM;
  48. MinOptMax stackSize = new MinOptMax();
  49. while ((curLM = getChildLM()) != null) {
  50. if (curLM.generatesInlineAreas()) {
  51. getLogger().error("inline area not allowed under flow - ignoring");
  52. curLM.setFinished(true);
  53. continue;
  54. }
  55. // Make break positions and return page break
  56. // Set up a LayoutContext
  57. MinOptMax bpd = context.getStackLimit();
  58. BreakPoss bp;
  59. LayoutContext childLC = new LayoutContext(0);
  60. boolean breakPage = false;
  61. childLC.setStackLimit(MinOptMax.subtract(bpd, stackSize));
  62. childLC.setRefIPD(context.getRefIPD());
  63. if (!curLM.isFinished()) {
  64. if ((bp = curLM.getNextBreakPoss(childLC)) != null) {
  65. stackSize.add(bp.getStackingSize());
  66. blockBreaks.add(bp);
  67. // set stackLimit for remaining space
  68. childLC.setStackLimit(MinOptMax.subtract(bpd, stackSize));
  69. if (bp.isForcedBreak() || bp.nextBreakOverflows()) {
  70. breakPage = true;
  71. }
  72. }
  73. }
  74. // check the stack bpd and if greater than available
  75. // height then go to the last best break and return
  76. // break position
  77. if (stackSize.opt > context.getStackLimit().opt) {
  78. breakPage = true;
  79. }
  80. if (breakPage) {
  81. return new BreakPoss(
  82. new LeafPosition(this, blockBreaks.size() - 1));
  83. }
  84. }
  85. setFinished(true);
  86. if (blockBreaks.size() > 0) {
  87. return new BreakPoss(
  88. new LeafPosition(this, blockBreaks.size() - 1));
  89. }
  90. return null;
  91. }
  92. /**
  93. * @see org.apache.fop.layoutmgr.LayoutProcessor#addAreas(PositionIterator, LayoutContext)
  94. */
  95. public void addAreas(PositionIterator parentIter, LayoutContext layoutContext) {
  96. LayoutProcessor childLM;
  97. LayoutContext lc = new LayoutContext(0);
  98. while (parentIter.hasNext()) {
  99. LeafPosition lfp = (LeafPosition) parentIter.next();
  100. // Add the block areas to Area
  101. PositionIterator breakPosIter =
  102. new BreakPossPosIter(blockBreaks, iStartPos,
  103. lfp.getLeafPos() + 1);
  104. iStartPos = lfp.getLeafPos() + 1;
  105. while ((childLM = breakPosIter.getNextChildLM()) != null) {
  106. childLM.addAreas(breakPosIter, lc);
  107. }
  108. }
  109. flush();
  110. }
  111. /**
  112. * Add child area to a the correct container, depending on its
  113. * area class. A Flow can fill at most one area container of any class
  114. * at any one time. The actual work is done by BlockStackingLM.
  115. * @param childArea child area to add
  116. */
  117. public void addChild(Area childArea) {
  118. addChildToArea(childArea,
  119. this.currentAreas[childArea.getAreaClass()]);
  120. }
  121. /**
  122. * @see org.apache.fop.layoutmgr.LayoutProcessor#getParentArea(Area)
  123. */
  124. public Area getParentArea(Area childArea) {
  125. // Get an area from the Page
  126. BlockParent parentArea =
  127. (BlockParent) parentLM.getParentArea(childArea);
  128. this.currentAreas[parentArea.getAreaClass()] = parentArea;
  129. setCurrentArea(parentArea);
  130. return parentArea;
  131. }
  132. /**
  133. * @see org.apache.fop.layoutmgr.LayoutProcessor#resetPosition(Position)
  134. */
  135. public void resetPosition(Position resetPos) {
  136. if (resetPos == null) {
  137. reset(null);
  138. }
  139. }
  140. /**
  141. * Retrieve marker is not allowed in the flow so this reports an
  142. * error and returns null.
  143. *
  144. * @see org.apache.fop.layoutmgr.LayoutManager
  145. */
  146. public Marker retrieveMarker(String name, int pos, int boundary) {
  147. // error cannot retrieve markers in flow
  148. getLogger().error("Cannot retrieve a marker from the flow");
  149. return null;
  150. }
  151. }