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.

FONode.java 7.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. /*-- $Id$ --
  2. ============================================================================
  3. The Apache Software License, Version 1.1
  4. ============================================================================
  5. Copyright (C) 1999 The Apache Software Foundation. All rights reserved.
  6. Redistribution and use in source and binary forms, with or without modifica-
  7. tion, are permitted provided that the following conditions are met:
  8. 1. Redistributions of source code must retain the above copyright notice,
  9. this list of conditions and the following disclaimer.
  10. 2. Redistributions in binary form must reproduce the above copyright notice,
  11. this list of conditions and the following disclaimer in the documentation
  12. and/or other materials provided with the distribution.
  13. 3. The end-user documentation included with the redistribution, if any, must
  14. include the following acknowledgment: "This product includes software
  15. developed by the Apache Software Foundation (http://www.apache.org/)."
  16. Alternately, this acknowledgment may appear in the software itself, if
  17. and wherever such third-party acknowledgments normally appear.
  18. 4. The names "FOP" and "Apache Software Foundation" must not be used to
  19. endorse or promote products derived from this software without prior
  20. written permission. For written permission, please contact
  21. apache@apache.org.
  22. 5. Products derived from this software may not be called "Apache", nor may
  23. "Apache" appear in their name, without prior written permission of the
  24. Apache Software Foundation.
  25. THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  26. INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  27. FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  28. APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  29. INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
  30. DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  31. OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  32. ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  33. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  34. THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  35. This software consists of voluntary contributions made by many individuals
  36. on behalf of the Apache Software Foundation and was originally created by
  37. James Tauber <jtauber@jtauber.com>. For more information on the Apache
  38. Software Foundation, please see <http://www.apache.org/>.
  39. */
  40. package org.apache.fop.fo;
  41. // FOP
  42. import org.apache.fop.apps.FOPException;
  43. import org.apache.fop.layout.Area;
  44. import org.apache.fop.layout.LinkSet;
  45. // Java
  46. import java.util.Vector;
  47. /**
  48. * base class for nodes in the formatting object tree
  49. */
  50. abstract public class FONode {
  51. protected FObj parent;
  52. public Vector children = new Vector(); // made public for searching for id's
  53. /** value of marker before layout begins */
  54. public final static int START = -1000;
  55. /** value of marker after break-after */
  56. public final static int BREAK_AFTER = -1001;
  57. /**
  58. * where the layout was up to.
  59. * for FObjs it is the child number
  60. * for FOText it is the character number
  61. */
  62. protected int marker = START;
  63. protected boolean isInTableCell = false;
  64. protected int forcedStartOffset = 0;
  65. protected int forcedWidth = 0;
  66. protected int widows = 0;
  67. protected int orphans = 0;
  68. protected LinkSet linkSet;
  69. protected FONode(FObj parent) {
  70. this.parent = parent;
  71. }
  72. public void setIsInTableCell() {
  73. this.isInTableCell = true;
  74. // made recursive by Eric Schaeffer
  75. for (int i = 0; i < this.children.size(); i++) {
  76. FONode child = (FONode) this.children.elementAt(i);
  77. child.setIsInTableCell();
  78. }
  79. }
  80. public void forceStartOffset(int offset) {
  81. this.forcedStartOffset = offset;
  82. // made recursive by Eric Schaeffer
  83. for (int i = 0; i < this.children.size(); i++) {
  84. FONode child = (FONode) this.children.elementAt(i);
  85. child.forceStartOffset(offset);
  86. }
  87. }
  88. public void forceWidth(int width) {
  89. this.forcedWidth = width;
  90. // made recursive by Eric Schaeffer
  91. for (int i = 0; i < this.children.size(); i++) {
  92. FONode child = (FONode) this.children.elementAt(i);
  93. child.forceWidth(width);
  94. }
  95. }
  96. public void resetMarker() {
  97. this.marker = START;
  98. int numChildren = this.children.size();
  99. for (int i = 0; i < numChildren; i++) {
  100. ((FONode) children.elementAt(i)).resetMarker();
  101. }
  102. }
  103. public void setWidows(int wid)
  104. {
  105. widows = wid;
  106. }
  107. public void setOrphans(int orph)
  108. {
  109. orphans = orph;
  110. }
  111. public void removeAreas() {
  112. // still to do
  113. }
  114. protected void addChild(FONode child) {
  115. children.addElement(child);
  116. }
  117. public FObj getParent() {
  118. return this.parent;
  119. }
  120. public void setLinkSet(LinkSet linkSet) {
  121. this.linkSet = linkSet;
  122. for (int i = 0; i < this.children.size(); i++) {
  123. FONode child = (FONode) this.children.elementAt(i);
  124. child.setLinkSet(linkSet);
  125. }
  126. }
  127. public LinkSet getLinkSet() {
  128. return this.linkSet;
  129. }
  130. abstract public Status layout(Area area)
  131. throws FOPException;
  132. /**
  133. * lets outside sources access the property list
  134. * first used by PageNumberCitation to find the "id" property
  135. * returns null by default, overide this function when there is a property list
  136. *@param name - the name of the desired property to obtain
  137. * @returns the property
  138. */
  139. public Property getProperty(String name)
  140. {
  141. return(null);
  142. }
  143. /**
  144. * At the start of a new span area layout may be partway through a
  145. * nested FO, and balancing requires rollback to this known point.
  146. * The snapshot records exactly where layout is at.
  147. * @param snapshot a Vector of markers (Integer)
  148. * @returns the updated Vector of markers (Integers)
  149. */
  150. public Vector getMarkerSnapshot(Vector snapshot)
  151. {
  152. snapshot.addElement(new Integer(this.marker));
  153. // terminate if no kids or child not yet accessed
  154. if (this.marker < 0)
  155. return snapshot;
  156. else if (children.isEmpty())
  157. return snapshot;
  158. else
  159. return ((FONode) children.elementAt(this.marker)).getMarkerSnapshot(snapshot);
  160. }
  161. /**
  162. * When balancing occurs, the flow layout() method restarts at the
  163. * point specified by the current marker snapshot, which is retrieved
  164. * and restored using this method.
  165. * @param snapshot the Vector of saved markers (Integers)
  166. */
  167. public void rollback(Vector snapshot)
  168. {
  169. this.marker = ((Integer)snapshot.elementAt(0)).intValue();
  170. snapshot.removeElementAt(0);
  171. if (this.marker == START)
  172. {
  173. // make sure all the children of this FO are also reset
  174. resetMarker();
  175. return;
  176. }
  177. else if ((this.marker == -1) || children.isEmpty())
  178. return;
  179. int numChildren = this.children.size();
  180. for (int i = this.marker + 1; i < numChildren; i++) {
  181. FONode fo = (FONode) children.elementAt(i);
  182. fo.resetMarker();
  183. }
  184. ((FONode) children.elementAt(this.marker)).rollback(snapshot);
  185. }
  186. }