您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

AbstractFlow.java 8.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. /*
  2. * $Id$
  3. * ============================================================================
  4. * The Apache Software License, Version 1.1
  5. * ============================================================================
  6. *
  7. * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
  8. *
  9. * Redistribution and use in source and binary forms, with or without modifica-
  10. * tion, are permitted provided that the following conditions are met:
  11. *
  12. * 1. Redistributions of source code must retain the above copyright notice,
  13. * this list of conditions and the following disclaimer.
  14. *
  15. * 2. Redistributions in binary form must reproduce the above copyright notice,
  16. * this list of conditions and the following disclaimer in the documentation
  17. * and/or other materials provided with the distribution.
  18. *
  19. * 3. The end-user documentation included with the redistribution, if any, must
  20. * include the following acknowledgment: "This product includes software
  21. * developed by the Apache Software Foundation (http://www.apache.org/)."
  22. * Alternately, this acknowledgment may appear in the software itself, if
  23. * and wherever such third-party acknowledgments normally appear.
  24. *
  25. * 4. The names "FOP" and "Apache Software Foundation" must not be used to
  26. * endorse or promote products derived from this software without prior
  27. * written permission. For written permission, please contact
  28. * apache@apache.org.
  29. *
  30. * 5. Products derived from this software may not be called "Apache", nor may
  31. * "Apache" appear in their name, without prior written permission of the
  32. * Apache Software Foundation.
  33. *
  34. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  35. * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  36. * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  37. * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  38. * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
  39. * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  40. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  41. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  42. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  43. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  44. * ============================================================================
  45. *
  46. * This software consists of voluntary contributions made by many individuals
  47. * on behalf of the Apache Software Foundation and was originally created by
  48. * James Tauber <jtauber@jtauber.com>. For more information on the Apache
  49. * Software Foundation, please see <http://www.apache.org/>.
  50. */
  51. package org.apache.fop.fo.flow;
  52. // FOP
  53. import org.apache.fop.fo.FObj;
  54. import org.apache.fop.fo.PropertyList;
  55. import org.apache.fop.fo.Status;
  56. import org.apache.fop.fo.pagination.PageSequence;
  57. import org.apache.fop.fo.pagination.Region;
  58. import org.apache.fop.layout.Area;
  59. import org.apache.fop.layout.BodyAreaContainer;
  60. import org.apache.fop.apps.FOPException;
  61. // Java
  62. import java.util.ArrayList;
  63. public abstract class AbstractFlow extends FObj {
  64. /**
  65. * PageSequence container
  66. */
  67. protected PageSequence pageSequence;
  68. /**
  69. * Area in which we lay out our kids
  70. */
  71. private Area area;
  72. /**
  73. * ArrayList to store snapshot
  74. */
  75. private ArrayList markerSnapshot;
  76. /**
  77. * flow-name attribute
  78. */
  79. protected String _flowName;
  80. /**
  81. * Content-width of current column area during layout
  82. */
  83. private int contentWidth;
  84. private int _status = Status.AREA_FULL_NONE;
  85. protected AbstractFlow(FObj parent, PropertyList propertyList,
  86. String systemId, int line, int column) throws FOPException {
  87. super(parent, propertyList, systemId, line, column);
  88. if (parent.getName().equals("fo:page-sequence")) {
  89. this.pageSequence = (PageSequence)parent;
  90. } else {
  91. throw new FOPException("flow must be child of page-sequence, not "
  92. + parent.getName(), systemId, line, column);
  93. }
  94. }
  95. public String getFlowName() {
  96. return _flowName;
  97. }
  98. public int layout(Area area) throws FOPException {
  99. return layout(area, null);
  100. }
  101. public int layout(Area area, Region region) throws FOPException {
  102. if (this.marker == START) {
  103. this.marker = 0;
  104. }
  105. // flow is *always* laid out into a BodyAreaContainer
  106. BodyAreaContainer bac = (BodyAreaContainer)area;
  107. boolean prevChildMustKeepWithNext = false;
  108. ArrayList pageMarker = this.getMarkerSnapshot(new ArrayList());
  109. int numChildren = this.children.size();
  110. if (numChildren == 0) {
  111. throw new FOPException("fo:flow must contain block-level children",
  112. systemId, line, column);
  113. }
  114. for (int i = this.marker; i < numChildren; i++) {
  115. FObj fo = (FObj)children.get(i);
  116. if (bac.isBalancingRequired(fo)) {
  117. // reset the the just-done span area in preparation
  118. // for a backtrack for balancing
  119. bac.resetSpanArea();
  120. this.rollback(markerSnapshot);
  121. // one less because of the "continue"
  122. i = this.marker - 1;
  123. continue;
  124. }
  125. // current column area
  126. Area currentArea = bac.getNextArea(fo);
  127. // temporary hack for IDReferences
  128. currentArea.setIDReferences(bac.getIDReferences());
  129. if (bac.isNewSpanArea()) {
  130. this.marker = i;
  131. markerSnapshot = this.getMarkerSnapshot(new ArrayList());
  132. }
  133. // Set current content width for percent-based lengths in children
  134. setContentWidth(currentArea.getContentWidth());
  135. _status = fo.layout(currentArea);
  136. /*
  137. * if((_status.isPageBreak() || i == numChildren - 1) && bac.needsFootnoteAdjusting()) {
  138. * bac.adjustFootnoteArea();
  139. * this.rollback(pageMarker);
  140. * i = this.marker - 1;
  141. * Area mainReferenceArea = bac.getMainReferenceArea();
  142. * // remove areas
  143. * continue;
  144. * }
  145. */
  146. if (Status.isIncomplete(_status)) {
  147. if ((prevChildMustKeepWithNext) && (Status.laidOutNone(_status))) {
  148. this.marker = i - 1;
  149. FObj prevChild = (FObj)children.get(this.marker);
  150. prevChild.removeAreas();
  151. prevChild.resetMarker();
  152. prevChild.removeID(area.getIDReferences());
  153. _status = Status.AREA_FULL_SOME;
  154. return _status;
  155. // should probably return AREA_FULL_NONE if first
  156. // or perhaps an entirely new status code
  157. }
  158. if (bac.isLastColumn())
  159. if (_status == Status.FORCE_COLUMN_BREAK) {
  160. this.marker = i;
  161. _status = Status.FORCE_PAGE_BREAK; // same thing
  162. return _status;
  163. } else {
  164. this.marker = i;
  165. return _status;
  166. }
  167. else {
  168. // not the last column, but could be page breaks
  169. if (Status.isPageBreak(_status)) {
  170. this.marker = i;
  171. return _status;
  172. }
  173. // I don't much like exposing this. (AHS 001217)
  174. ((org.apache.fop.layout.ColumnArea)currentArea).incrementSpanIndex();
  175. i--;
  176. }
  177. }
  178. if (_status == Status.KEEP_WITH_NEXT) {
  179. prevChildMustKeepWithNext = true;
  180. } else {
  181. prevChildMustKeepWithNext = false;
  182. }
  183. }
  184. return _status;
  185. }
  186. protected void setContentWidth(int contentWidth) {
  187. this.contentWidth = contentWidth;
  188. }
  189. /**
  190. * Return the content width of this flow (really of the region
  191. * in which it is flowing).
  192. */
  193. public int getContentWidth() {
  194. return this.contentWidth;
  195. }
  196. public int getStatus() {
  197. return _status;
  198. }
  199. public boolean generatesReferenceAreas() {
  200. return true;
  201. }
  202. }