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.

BlockLayoutManager.java 6.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. /*
  2. * $Id$
  3. * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
  4. * For details on use and redistribution please refer to the
  5. * LICENSE file included with these sources.
  6. */
  7. package org.apache.fop.layoutmgr;
  8. import org.apache.fop.fo.FObj;
  9. import org.apache.fop.fo.TextInfo;
  10. import org.apache.fop.area.Area;
  11. import org.apache.fop.area.BlockParent;
  12. import org.apache.fop.area.Block;
  13. import org.apache.fop.area.LineArea;
  14. import org.apache.fop.area.MinOptMax;
  15. import java.util.ListIterator;
  16. import java.util.ArrayList;
  17. /**
  18. * LayoutManager for a block FO.
  19. */
  20. public class BlockLayoutManager extends BlockStackingLayoutManager {
  21. private Block curBlockArea;
  22. int lead = 12000;
  23. int lineHeight = 14000;
  24. int follow = 2000;
  25. public BlockLayoutManager(FObj fobj) {
  26. super(fobj);
  27. }
  28. public void setBlockTextInfo(TextInfo ti) {
  29. lead = ti.fs.getAscender();
  30. follow = ti.fs.getDescender();
  31. lineHeight = ti.lineHeight;
  32. }
  33. /**
  34. * Called by child layout manager to get the available space for
  35. * content in the inline progression direction.
  36. * Note that a manager may need to ask its parent for this.
  37. * For a block area, available IPD is determined by indents.
  38. */
  39. public int getContentIPD() {
  40. // adjust for side floats and indents
  41. getParentArea(null); // make if not existing
  42. return curBlockArea.getIPD();
  43. }
  44. /**
  45. * Generate areas by tellings all layout managers for its FO's
  46. * children to generate areas.
  47. */
  48. public boolean generateAreas() {
  49. ArrayList lms = new ArrayList();
  50. LayoutManager lm = null;
  51. FObj curFobj = fobj;
  52. if (fobj != null) {
  53. ListIterator children = fobj.getChildren();
  54. while (children.hasNext()) {
  55. FObj childFO = (FObj) children.next();
  56. childFO.addLayoutManager(lms);
  57. }
  58. fobj = null;
  59. }
  60. for (int count = 0; count < lms.size(); count++) {
  61. lm = (LayoutManager) lms.get(count);
  62. if (lm.generatesInlineAreas()) {
  63. ArrayList inlines = new ArrayList();
  64. inlines.add(lm);
  65. //lms.remove(count);
  66. while (count + 1 < lms.size()) {
  67. lm = (LayoutManager) lms.get(count + 1);
  68. if (lm.generatesInlineAreas()) {
  69. inlines.add(lm);
  70. lms.remove(count + 1);
  71. } else {
  72. break;
  73. }
  74. }
  75. lm = new LineLayoutManager(curFobj, inlines, lineHeight, lead,
  76. follow);
  77. // !!!! To test BreakPoss Line LayoutManager, uncomment!
  78. /*
  79. lm = new LineBPLayoutManager(curFobj, inlines, lineHeight,
  80. lead, follow);
  81. */
  82. lms.set(count, lm);
  83. }
  84. lm.setParentLM(this);
  85. if (lm.generateAreas()) {
  86. if (flush()) {
  87. return true;
  88. }
  89. }
  90. }
  91. return flush(); // Add last area to parent
  92. }
  93. /**
  94. * Return an Area which can contain the passed childArea. The childArea
  95. * may not yet have any content, but it has essential traits set.
  96. * In general, if the LayoutManager already has an Area it simply returns
  97. * it. Otherwise, it makes a new Area of the appropriate class.
  98. * It gets a parent area for its area by calling its parent LM.
  99. * Finally, based on the dimensions of the parent area, it initializes
  100. * its own area. This includes setting the content IPD and the maximum
  101. * BPD.
  102. */
  103. public Area getParentArea(Area childArea) {
  104. if (curBlockArea == null) {
  105. curBlockArea = new Block();
  106. // Set up dimensions
  107. // Must get dimensions from parent area
  108. Area parentArea = parentLM.getParentArea(curBlockArea);
  109. int referenceIPD = parentArea.getIPD();
  110. curBlockArea.setIPD(referenceIPD);
  111. // Get reference IPD from parentArea
  112. setCurrentArea(curBlockArea); // ??? for generic operations
  113. }
  114. return curBlockArea;
  115. }
  116. public boolean addChild(Area childArea) {
  117. if (curBlockArea != null) {
  118. if (childArea instanceof LineArea) {
  119. // Something about widows and orphans
  120. // Position the line area and calculate size...
  121. curBlockArea.addLineArea((LineArea) childArea);
  122. MinOptMax targetDim = parentArea.getAvailBPD();
  123. MinOptMax currentDim = curBlockArea.getContentBPD();
  124. //if(currentDim.min > targetDim.max) {
  125. // return true;
  126. //}
  127. return false;
  128. } else {
  129. curBlockArea.addBlock((Block) childArea);
  130. //return super.addChild(childArea);
  131. return false;
  132. }
  133. }
  134. return false;
  135. }
  136. // /**
  137. // * Called by child LayoutManager when it has filled one of its areas.
  138. // * If no current container, make one.
  139. // * See if the area will fit in the current container.
  140. // * If so, add it.
  141. // * @param childArea the area to add: will either be a LineArea or
  142. // * a BlockArea.
  143. // */
  144. // public void addChild(Area childArea) {
  145. // /* If the childArea fits entirely in the maximum available BPD
  146. // * add it and return an OK status.
  147. // * If it doesn't all fit, overrun or ask for split?
  148. // * Might as well just add it since the page layout process
  149. // * may need to make other adjustments, resulting in changing
  150. // * split point.
  151. // */
  152. // // Things like breaks on child area can cause premature
  153. // // termination of the current area.
  154. // /* We go past the theoretical maximum to be able to handle things
  155. // * like widows.
  156. // */
  157. // // WARNING: this doesn't take into account space-specifier
  158. // // adujstment between childArea and last content of blockArea!
  159. // if (blockArea.getContentBPD().min + childArea.getAllocationBPD().min
  160. // > blockArea.getAvailBPD().max) {
  161. // if (++extraLines <= iWidows) {
  162. // blockArea.add(childArea);
  163. // }
  164. // else {
  165. // blockArea.setIsLast(false);
  166. // parentLM.addChildArea(blockArea);
  167. // // Make a new one for this area
  168. // blockArea = makeAreaForChild(childArea);
  169. // extraLines = 0; // Count potential widows
  170. // blockArea.add(childArea);
  171. // }
  172. // }
  173. // else {
  174. // blockArea.add(childArea);
  175. // }
  176. // }
  177. }