1 17 18 19 20 package org.apache.fop.layoutmgr; 21 22 import java.util.LinkedList ; 23 import java.util.List ; 24 import java.util.ListIterator ; 25 26 import org.apache.commons.logging.Log; 27 import org.apache.commons.logging.LogFactory; 28 import org.apache.fop.area.RegionReference; 29 import org.apache.fop.area.Area; 30 import org.apache.fop.area.Block; 31 import org.apache.fop.fo.FONode; 32 import org.apache.fop.fo.pagination.PageSequence; 33 import org.apache.fop.fo.pagination.SideRegion; 34 import org.apache.fop.fo.pagination.StaticContent; 35 import org.apache.fop.layoutmgr.inline.InlineLevelLayoutManager; 36 import org.apache.fop.layoutmgr.inline.TextLayoutManager; 37 import org.apache.fop.traits.MinOptMax; 38 39 45 public class StaticContentLayoutManager extends BlockStackingLayoutManager { 46 47 50 private static Log log = LogFactory.getLog(StaticContentLayoutManager.class); 51 52 private RegionReference targetRegion; 53 private Block targetBlock; 54 private SideRegion regionFO; 55 56 private int contentAreaIPD = 0; 57 private int contentAreaBPD = -1; 58 59 65 public StaticContentLayoutManager(PageSequenceLayoutManager pslm, 66 StaticContent node, SideRegion reg) { 67 super(node); 68 setParent(pslm); 69 regionFO = reg; 70 targetRegion = getCurrentPV().getRegionReference(regionFO.getNameId()); 71 } 72 73 79 public StaticContentLayoutManager(PageSequenceLayoutManager pslm, 80 StaticContent node, Block block) { 81 super(node); 82 setParent(pslm); 83 targetBlock = block; 84 } 85 86 87 public LinkedList getNextKnuthElements(LayoutContext context, int alignment) { 88 if (true) { 89 throw new UnsupportedOperationException ( 90 "Shouldn't this method be emptied because it's never called at all?"); 91 } 92 setContentAreaIPD(context.getRefIPD()); 95 setContentAreaBPD(context.getStackLimit().opt); 96 97 BlockLevelLayoutManager curLM; 100 BlockLevelLayoutManager prevLM = null; 101 MinOptMax stackSize = new MinOptMax(); 102 LinkedList returnedList; 103 LinkedList returnList = new LinkedList (); 104 105 while ((curLM = ((BlockLevelLayoutManager) getChildLM())) != null) { 106 if (curLM instanceof InlineLevelLayoutManager) { 107 log.error("inline area not allowed under flow - ignoring"); 108 curLM.setFinished(true); 109 continue; 110 } 111 112 MinOptMax bpd = context.getStackLimit(); 114 115 LayoutContext childLC = new LayoutContext(0); 116 childLC.setStackLimit(MinOptMax.subtract(bpd, stackSize)); 117 childLC.setRefIPD(context.getRefIPD()); 118 119 returnedList = curLM.getNextKnuthElements(childLC, alignment); 121 124 LinkedList tempList = returnedList; 126 KnuthElement tempElement; 127 returnedList = new LinkedList (); 128 ListIterator listIter = tempList.listIterator(); 129 while (listIter.hasNext()) { 130 tempElement = (KnuthElement)listIter.next(); 131 tempElement.setPosition(new NonLeafPosition(this, tempElement.getPosition())); 132 returnedList.add(tempElement); 133 } 134 135 if (returnedList.size() == 1 136 && ((KnuthElement)returnedList.getFirst()).isPenalty() 137 && ((KnuthPenalty)returnedList.getFirst()).getP() == -KnuthElement.INFINITE) { 138 returnList.addAll(returnedList); 140 return returnList; 141 } else { 142 if (returnList.size() > 0) { 143 if (prevLM.mustKeepWithNext() 145 || curLM.mustKeepWithPrevious()) { 146 returnList.add(new KnuthPenalty(0, 148 KnuthElement.INFINITE, false, 149 new Position(this), false)); 150 } else if (!((KnuthElement) returnList.getLast()).isGlue()) { 151 returnList.add(new KnuthPenalty(0, 0, false, new Position(this), false)); 153 } 154 } 155 if (returnedList.size() > 0) { returnList.addAll(returnedList); 157 if (((KnuthElement)returnedList.getLast()).isPenalty() 158 && ((KnuthPenalty)returnedList.getLast()).getP() 159 == -KnuthElement.INFINITE) { 160 return returnList; 163 } 164 } 165 } 166 prevLM = curLM; 167 } 168 169 setFinished(true); 170 171 if (returnList.size() > 0) { 172 return returnList; 173 } else { 174 return null; 175 } 176 } 177 178 181 public void addAreas(PositionIterator parentIter, LayoutContext layoutContext) { 182 AreaAdditionUtil.addAreas(this, parentIter, layoutContext); 183 184 flush(); 185 targetRegion = null; 186 } 187 188 189 195 public void addChildArea(Area childArea) { 196 if (getStaticContentFO().getFlowName().equals("xsl-footnote-separator")) { 197 targetBlock.addBlock((Block)childArea); 198 } else { 199 targetRegion.addBlock((Block)childArea); 200 } 201 } 202 203 206 public Area getParentArea(Area childArea) { 207 if (getStaticContentFO().getFlowName().equals("xsl-footnote-separator")) { 208 return targetBlock; 209 } else { 210 return targetRegion; 211 } 212 } 213 214 217 public void doLayout() { 218 int targetIPD = 0; 219 int targetBPD = 0; 220 int targetAlign = EN_AUTO; 221 boolean autoHeight = false; 222 StaticContentBreaker breaker; 223 224 if (getStaticContentFO().getFlowName().equals("xsl-footnote-separator")) { 225 targetIPD = targetBlock.getIPD(); 226 targetBPD = targetBlock.getBPD(); 227 if (targetBPD == 0) { 228 autoHeight = true; 229 } 230 targetAlign = EN_BEFORE; 231 } else { 232 targetIPD = targetRegion.getIPD(); 233 targetBPD = targetRegion.getBPD(); 234 targetAlign = regionFO.getDisplayAlign(); 235 } 236 setContentAreaIPD(targetIPD); 237 setContentAreaBPD(targetBPD); 238 breaker = new StaticContentBreaker(this, targetIPD, targetAlign); 239 breaker.doLayout(targetBPD, autoHeight); 240 if (breaker.isOverflow()) { 241 if (!autoHeight) { 242 if (regionFO.getOverflow() == EN_ERROR_IF_OVERFLOW) { 244 } 246 log.warn(FONode.decorateWithContextInfo( 247 "static-content overflows the available area.", fobj)); 248 } 249 } 250 } 251 252 256 protected StaticContent getStaticContentFO() { 257 return (StaticContent) fobj; 258 } 259 260 private class StaticContentBreaker extends AbstractBreaker { 261 private StaticContentLayoutManager lm; 262 private int displayAlign; 263 private int ipd; 264 private boolean overflow = false; 265 266 public StaticContentBreaker(StaticContentLayoutManager lm, int ipd, 267 int displayAlign) { 268 this.lm = lm; 269 this.ipd = ipd; 270 this.displayAlign = displayAlign; 271 } 272 273 274 protected void observeElementList(List elementList) { 275 String elementListID = getStaticContentFO().getFlowName(); 276 String pageSequenceID = ((PageSequence)lm.getParent().getFObj()).getId(); 277 if (pageSequenceID != null && pageSequenceID.length() > 0) { 278 elementListID += "-" + pageSequenceID; 279 } 280 ElementListObserver.observe(elementList, "static-content", elementListID); 281 } 282 283 284 protected boolean isPartOverflowRecoveryActivated() { 285 return false; 287 } 288 289 public boolean isOverflow() { 290 return this.overflow; 291 } 292 293 protected LayoutManager getTopLevelLM() { 294 return lm; 295 } 296 297 protected LayoutContext createLayoutContext() { 298 LayoutContext lc = super.createLayoutContext(); 299 lc.setRefIPD(ipd); 300 return lc; 301 } 302 303 protected LinkedList getNextKnuthElements(LayoutContext context, int alignment) { 304 LayoutManager curLM; LinkedList returnList = new LinkedList (); 306 307 while ((curLM = getChildLM()) != null) { 308 LayoutContext childLC = new LayoutContext(0); 309 childLC.setStackLimit(context.getStackLimit()); 310 childLC.setRefIPD(context.getRefIPD()); 311 childLC.setWritingMode(context.getWritingMode()); 312 313 LinkedList returnedList = null; 314 boolean ignore = curLM instanceof TextLayoutManager; 316 if (!curLM.isFinished()) { 317 returnedList = curLM.getNextKnuthElements(childLC, alignment); 318 } 319 if (returnedList != null && !ignore) { 320 lm.wrapPositionElements(returnedList, returnList); 321 } 322 } 323 SpaceResolver.resolveElementList(returnList); 324 setFinished(true); 325 return returnList; 326 } 327 328 protected int getCurrentDisplayAlign() { 329 return displayAlign; 330 } 331 332 protected boolean hasMoreContent() { 333 return !lm.isFinished(); 334 } 335 336 protected void addAreas(PositionIterator posIter, LayoutContext context) { 337 AreaAdditionUtil.addAreas(lm, posIter, context); 338 } 339 340 protected void doPhase3(PageBreakingAlgorithm alg, int partCount, 341 BlockSequence originalList, BlockSequence effectiveList) { 342 this.addAreas(alg, partCount, originalList, effectiveList); 344 if (partCount > 1) { 345 overflow = true; 346 } 347 } 348 349 protected void finishPart(PageBreakingAlgorithm alg, PageBreakPosition pbp) { 350 } 352 353 protected LayoutManager getCurrentChildLM() { 354 return null; } 356 } 357 358 362 public int getContentAreaIPD() { 363 return contentAreaIPD; 364 } 365 366 367 protected void setContentAreaIPD(int contentAreaIPD) { 368 this.contentAreaIPD = contentAreaIPD; 369 } 370 371 375 public int getContentAreaBPD() { 376 return contentAreaBPD; 377 } 378 379 private void setContentAreaBPD(int contentAreaBPD) { 380 this.contentAreaBPD = contentAreaBPD; 381 } 382 383 } 384 385 | Popular Tags |