1 51 package org.apache.fop.fo.flow; 52 53 import org.apache.fop.fo.*; 55 import org.apache.fop.layout.*; 56 import org.apache.fop.apps.FOPException; 57 58 72 73 public class Block extends FObjMixed { 74 75 public static class Maker extends FObj.Maker { 76 public FObj make(FObj parent, PropertyList propertyList, 77 String systemId, int line, int column) 78 throws FOPException { 79 return new Block(parent, propertyList, systemId, line, column); 80 } 81 82 } 83 84 public static FObj.Maker maker() { 85 return new Block.Maker(); 86 } 87 88 int align; 89 int alignLast; 90 int breakAfter; 91 int lineHeight; 92 int startIndent; 93 int endIndent; 94 int spaceBefore; 95 int spaceAfter; 96 int textIndent; 97 int keepWithNext; 98 99 int areaHeight = 0; 100 int contentWidth = 0; 101 int infLoopThreshhold = 50; 102 103 String id; 104 int span; 105 boolean breakStatusBeforeChecked = false; 106 107 boolean anythingLaidOut = false; 109 int noLayoutCount = 0; 111 112 public Block(FObj parent, PropertyList propertyList, 113 String systemId, int line, int column) 114 throws FOPException { 115 super(parent, propertyList, systemId, line, column); 116 this.span = this.properties.get("span").getEnum(); 117 } 118 119 public String getName() { 120 return "fo:block"; 121 } 122 123 public int layout(Area area) throws FOPException { 124 if (!breakStatusBeforeChecked) { 125 breakStatusBeforeChecked = true; 126 int breakBeforeStatus = propMgr.checkBreakBefore(area); 129 if (breakBeforeStatus != Status.OK) { 130 return breakBeforeStatus; 131 } 132 } 133 134 BlockArea blockArea; 135 136 if (!anythingLaidOut) { 137 noLayoutCount++; 138 } 139 if (noLayoutCount > infLoopThreshhold) { 140 throw new FOPException( 141 "No meaningful layout in block after many attempts. "+ 142 "Infinite loop is assumed. Processing halted.", 143 systemId, line, column); 144 } 145 146 148 if (this.marker == BREAK_AFTER) { 149 return Status.OK; 150 } 151 152 if (this.marker == START) { 153 noLayoutCount=0; 155 AccessibilityProps mAccProps = propMgr.getAccessibilityProps(); 157 158 AuralProps mAurProps = propMgr.getAuralProps(); 160 161 BorderAndPadding bap = propMgr.getBorderAndPadding(); 163 BackgroundProps bProps = propMgr.getBackgroundProps(); 164 165 168 HyphenationProps mHyphProps = propMgr.getHyphenationProps(); 170 171 MarginProps mProps = propMgr.getMarginProps(); 173 174 RelativePositionProps mRelProps = propMgr.getRelativePositionProps(); 176 177 this.align = this.properties.get("text-align").getEnum(); 178 this.alignLast = this.properties.get("text-align-last").getEnum(); 179 this.breakAfter = this.properties.get("break-after").getEnum(); 180 this.lineHeight = 181 this.properties.get("line-height").getLength().mvalue(); 182 this.startIndent = 183 this.properties.get("start-indent").getLength().mvalue(); 184 this.endIndent = 185 this.properties.get("end-indent").getLength().mvalue(); 186 this.spaceBefore = 187 this.properties.get("space-before.optimum").getLength().mvalue(); 188 this.spaceAfter = 189 this.properties.get("space-after.optimum").getLength().mvalue(); 190 this.textIndent = 191 this.properties.get("text-indent").getLength().mvalue(); 192 this.keepWithNext = 193 this.properties.get("keep-with-next").getEnum(); 194 195 this.id = this.properties.get("id").getString(); 196 197 if (area instanceof BlockArea) { 198 area.end(); 199 } 200 201 if (area.getIDReferences() != null) { 202 try { 203 area.getIDReferences().createID(id); 204 } 205 catch(FOPException e) { 206 if (!e.isLocationSet()) { 207 e.setLocation(systemId, line, column); 208 } 209 throw e; 210 } 211 } 212 213 this.marker = 0; 214 } 215 216 if ((spaceBefore != 0) && (this.marker == 0)) { 217 area.addDisplaySpace(spaceBefore); 218 } 219 220 if (anythingLaidOut) { 221 this.textIndent = 0; 222 } 223 224 if (marker == 0 && area.getIDReferences() != null) { 225 area.getIDReferences().configureID(id, area); 226 } 227 228 int spaceLeft = area.spaceLeft(); 229 blockArea = 230 new BlockArea(propMgr.getFontState(area.getFontInfo()), 231 area.getAllocationWidth(), area.spaceLeft(), 232 startIndent, endIndent, textIndent, align, 233 alignLast, lineHeight); 234 blockArea.setGeneratedBy(this); 235 this.areasGenerated++; 236 if (this.areasGenerated == 1) 237 blockArea.isFirst(true); 238 242 blockArea.setParent(area); blockArea.setPage(area.getPage()); 244 blockArea.setBackground(propMgr.getBackgroundProps()); 245 blockArea.setBorderAndPadding(propMgr.getBorderAndPadding()); 246 blockArea.setHyphenation(propMgr.getHyphenationProps()); 247 blockArea.start(); 248 249 blockArea.setAbsoluteHeight(area.getAbsoluteHeight()); 250 blockArea.setIDReferences(area.getIDReferences()); 251 252 blockArea.setTableCellXOffset(area.getTableCellXOffset()); 253 254 int numChildren = this.children.size(); 255 for (int i = this.marker; i < numChildren; i++) { 256 FONode fo = (FONode)children.get(i); 257 int status = fo.layout(blockArea); 258 if (Status.isIncomplete(status)) { 259 this.marker = i; 260 if (status == Status.AREA_FULL_NONE) { 261 if (i == 0) { 262 anythingLaidOut = false; 264 return status; 265 } else { 266 area.addChild(blockArea); 268 area.setMaxHeight(area.getMaxHeight() - spaceLeft 269 + blockArea.getMaxHeight()); 270 area.increaseHeight(blockArea.getHeight()); 271 anythingLaidOut = true; 272 return Status.AREA_FULL_SOME; 273 } 274 } 275 area.addChild(blockArea); 277 area.setMaxHeight(area.getMaxHeight() - spaceLeft 278 + blockArea.getMaxHeight()); 279 area.increaseHeight(blockArea.getHeight()); 280 anythingLaidOut = true; 281 return status; 282 } 283 anythingLaidOut = true; 284 } 285 286 blockArea.end(); 287 blockArea.isLast(true); 288 area.addChild(blockArea); 289 area.setMaxHeight(area.getMaxHeight() - spaceLeft 290 + blockArea.getMaxHeight()); 291 area.increaseHeight(blockArea.getHeight()); 292 293 if (spaceAfter != 0) { 294 area.addDisplaySpace(spaceAfter); 295 } 296 297 if (area instanceof BlockArea) { 298 area.start(); 299 } 300 areaHeight= blockArea.getHeight(); 301 contentWidth= blockArea.getContentWidth(); 302 303 int breakAfterStatus = propMgr.checkBreakAfter(area); 306 if (breakAfterStatus != Status.OK) { 307 this.marker = BREAK_AFTER; 308 blockArea = null; 309 return breakAfterStatus; 310 } 311 if (keepWithNext != 0) { 312 return Status.KEEP_WITH_NEXT; 313 } 314 return Status.OK; 315 } 316 317 public int getAreaHeight() { 318 return areaHeight; 319 } 320 321 322 325 public int getContentWidth() { 326 return contentWidth; } 328 329 330 public int getSpan() { 331 return this.span; 332 } 333 334 public void resetMarker() { 335 anythingLaidOut = false; 336 super.resetMarker(); 337 } 338 339 } 340 | Popular Tags |