1 17 18 19 20 package org.apache.fop.layoutmgr; 21 22 import java.util.Iterator ; 23 import java.util.LinkedList ; 24 25 import org.apache.fop.layoutmgr.SpaceResolver.SpaceHandlingBreakPosition; 26 27 30 public class AreaAdditionUtil { 31 32 private static class StackingIter extends PositionIterator { 33 StackingIter(Iterator parentIter) { 34 super(parentIter); 35 } 36 37 protected LayoutManager getLM(Object nextObj) { 38 return ((Position) nextObj).getLM(); 39 } 40 41 protected Position getPos(Object nextObj) { 42 return ((Position) nextObj); 43 } 44 } 45 46 52 public static void addAreas(BlockStackingLayoutManager bslm, 53 PositionIterator parentIter, LayoutContext layoutContext) { 54 LayoutManager childLM = null; 55 LayoutContext lc = new LayoutContext(0); 56 LayoutManager firstLM = null; 57 LayoutManager lastLM = null; 58 Position firstPos = null; 59 Position lastPos = null; 60 61 LinkedList positionList = new LinkedList (); 64 Position pos; 65 while (parentIter.hasNext()) { 66 pos = (Position)parentIter.next(); 67 if (pos == null) { 68 continue; 69 } 70 if (pos.getIndex() >= 0) { 71 if (firstPos == null) { 72 firstPos = pos; 73 } 74 lastPos = pos; 75 } 76 if (pos instanceof NonLeafPosition) { 77 positionList.add(((NonLeafPosition) pos).getPosition()); 79 lastLM = ((NonLeafPosition) pos).getPosition().getLM(); 80 if (firstLM == null) { 81 firstLM = lastLM; 82 } 83 } else if (pos instanceof SpaceHandlingBreakPosition) { 84 positionList.add(pos); 85 } else { 86 } 88 } 89 if (firstPos == null) { 90 return; } 96 97 if (bslm != null && bslm.markers != null) { 98 bslm.getCurrentPV().addMarkers(bslm.markers, true, 99 bslm.isFirst(firstPos), bslm.isLast(lastPos)); 100 } 101 102 StackingIter childPosIter = new StackingIter(positionList.listIterator()); 103 while ((childLM = childPosIter.getNextChildLM()) != null) { 104 lc.setFlags(LayoutContext.FIRST_AREA, childLM == firstLM); 106 lc.setFlags(LayoutContext.LAST_AREA, childLM == lastLM); 107 lc.setSpaceAdjust(layoutContext.getSpaceAdjust()); 109 lc.setSpaceBefore((childLM == firstLM ? layoutContext.getSpaceBefore() : 0)); 112 lc.setSpaceAfter(layoutContext.getSpaceAfter()); 115 lc.setStackLimit(layoutContext.getStackLimit()); 116 childLM.addAreas(childPosIter, lc); 117 } 118 if (bslm != null && bslm.markers != null) { 119 bslm.getCurrentPV().addMarkers(bslm.markers, false, 120 bslm.isFirst(firstPos), bslm.isLast(lastPos)); 121 } 122 123 } 124 125 } 126 | Popular Tags |