1 51 package org.apache.fop.fo.flow; 52 53 import org.apache.fop.fo.*; 55 import org.apache.fop.fo.pagination.*; 56 import org.apache.fop.layout.Area; 57 import org.apache.fop.layout.BodyAreaContainer; 58 import org.apache.fop.apps.FOPException; 59 60 import java.util.ArrayList ; 62 63 public abstract class AbstractFlow extends FObj { 64 65 68 protected PageSequence pageSequence; 69 70 73 private Area area; 74 75 78 private ArrayList markerSnapshot; 79 80 83 protected String _flowName; 84 85 88 private int contentWidth; 89 90 private int _status = Status.AREA_FULL_NONE; 91 92 93 protected AbstractFlow(FObj parent, PropertyList propertyList, 94 String systemId, int line, int column) throws FOPException { 95 super(parent, propertyList, systemId, line, column); 96 97 if (parent.getName().equals("fo:page-sequence")) { 98 this.pageSequence = (PageSequence)parent; 99 } else { 100 throw new FOPException("flow must be child of page-sequence, not " 101 + parent.getName(), systemId, line, column); 102 } 103 } 104 105 public String getFlowName() { 106 return _flowName; 107 } 108 109 public int layout(Area area) throws FOPException { 110 return layout(area, null); 111 112 } 113 114 public int layout(Area area, Region region) throws FOPException { 115 if (this.marker == START) { 116 this.marker = 0; 117 } 118 119 BodyAreaContainer bac = (BodyAreaContainer)area; 121 122 boolean prevChildMustKeepWithNext = false; 123 ArrayList pageMarker = this.getMarkerSnapshot(new ArrayList ()); 124 125 int numChildren = this.children.size(); 126 if (numChildren == 0) { 127 throw new FOPException("fo:flow must contain block-level children", 128 systemId, line, column); 129 } 130 for (int i = this.marker; i < numChildren; i++) { 131 FObj fo = (FObj)children.get(i); 132 133 if (bac.isBalancingRequired(fo)) { 134 bac.resetSpanArea(); 137 138 this.rollback(markerSnapshot); 139 i = this.marker - 1; 141 continue; 142 } 143 Area currentArea = bac.getNextArea(fo); 145 currentArea.setIDReferences(bac.getIDReferences()); 147 if (bac.isNewSpanArea()) { 148 this.marker = i; 149 markerSnapshot = this.getMarkerSnapshot(new ArrayList ()); 150 } 151 setContentWidth(currentArea.getContentWidth()); 153 154 _status = fo.layout(currentArea); 155 156 166 if (Status.isIncomplete(_status)) { 167 if ((prevChildMustKeepWithNext) && (Status.laidOutNone(_status))) { 168 this.marker = i - 1; 169 FObj prevChild = (FObj)children.get(this.marker); 170 prevChild.removeAreas(); 171 prevChild.resetMarker(); 172 prevChild.removeID(area.getIDReferences()); 173 _status = Status.AREA_FULL_SOME; 174 return _status; 175 } 178 if (bac.isLastColumn()) 179 if (_status == Status.FORCE_COLUMN_BREAK) { 180 this.marker = i; 181 _status = Status.FORCE_PAGE_BREAK; return _status; 183 } else { 184 this.marker = i; 185 return _status; 186 } 187 else { 188 if (Status.isPageBreak(_status)) { 190 this.marker = i; 191 return _status; 192 } 193 ((org.apache.fop.layout.ColumnArea)currentArea).incrementSpanIndex(); 195 i--; 196 } 197 } 198 if (_status == Status.KEEP_WITH_NEXT) { 199 prevChildMustKeepWithNext = true; 200 } else { 201 prevChildMustKeepWithNext = false; 202 } 203 } 204 return _status; 205 } 206 207 protected void setContentWidth(int contentWidth) { 208 this.contentWidth = contentWidth; 209 } 210 214 public int getContentWidth() { 215 return this.contentWidth; 216 } 217 218 public int getStatus() { 219 return _status; 220 } 221 222 223 public boolean generatesReferenceAreas() { 224 return true; 225 } 226 227 } 228 | Popular Tags |