Modified: xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/layoutmgr/AbstractBreaker.java URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/layoutmgr/AbstractBreaker.java?rev=1309921&r1=1309920&r2=1309921&view=diff ============================================================================== --- xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/layoutmgr/AbstractBreaker.java (original) +++ xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/layoutmgr/AbstractBreaker.java Thu Apr 5 16:19:19 2012 @@ -199,10 +199,10 @@ public abstract class AbstractBreaker { } - /** blockListIndex of the current BlockSequence in blockLists */ - private int blockListIndex = 0; + // used by doLayout and getNextBlockList* + private List<BlockSequence> blockLists; - private List blockLists = null; + private boolean empty = true; /** desired text alignment */ protected int alignment; @@ -277,7 +277,8 @@ public abstract class AbstractBreaker { * @param alignment the desired text alignment * @return the list of KnuthElements */ - protected abstract List getNextKnuthElements(LayoutContext context, int alignment); + protected abstract List<KnuthElement> getNextKnuthElements(LayoutContext context, + int alignment); /** * Get a sequence of KnuthElements representing the content @@ -290,14 +291,14 @@ public abstract class AbstractBreaker { * change occurs between two LMs * @return the list of KnuthElements */ - protected List getNextKnuthElements(LayoutContext context, int alignment, + protected List<KnuthElement> getNextKnuthElements(LayoutContext context, int alignment, Position positionAtIPDChange, LayoutManager restartAtLM) { throw new UnsupportedOperationException("TODO: implement acceptable fallback"); } /** @return true if there's no content that could be handled. */ public boolean isEmpty() { - return (this.blockLists.isEmpty()); + return empty; } /** @@ -374,21 +375,22 @@ public abstract class AbstractBreaker { childLC.setBPAlignment(alignment); BlockSequence blockList; - this.blockLists = new java.util.ArrayList(); + blockLists = new java.util.ArrayList<BlockSequence>(); log.debug("PLM> flow BPD =" + flowBPD); - //*** Phase 1: Get Knuth elements *** int nextSequenceStartsOn = Constants.EN_ANY; while (hasMoreContent()) { blockLists.clear(); + //*** Phase 1: Get Knuth elements *** nextSequenceStartsOn = getNextBlockList(childLC, nextSequenceStartsOn); + empty = empty && blockLists.size() == 0; - //*** Phase 2: Alignment and breaking *** + //*** Phases 2 and 3 *** log.debug("PLM> blockLists.size() = " + blockLists.size()); - for (blockListIndex = 0; blockListIndex < blockLists.size(); blockListIndex++) { - blockList = (BlockSequence) blockLists.get(blockListIndex); + for (int blockListIndex = 0; blockListIndex < blockLists.size(); blockListIndex++) { + blockList = blockLists.get(blockListIndex); //debug code start if (log.isDebugEnabled()) { @@ -398,12 +400,13 @@ public abstract class AbstractBreaker { observeElementList(blockList); //debug code end + //*** Phase 2: Alignment and breaking *** log.debug("PLM> start of algorithm (" + this.getClass().getName() + "), flow BPD =" + flowBPD); PageBreakingAlgorithm alg = new PageBreakingAlgorithm(getTopLevelLM(), - getPageProvider(), createLayoutListener(), - alignment, alignmentLast, footnoteSeparatorLength, - isPartOverflowRecoveryActivated(), autoHeight, isSinglePartFavored()); + getPageProvider(), createLayoutListener(), + alignment, alignmentLast, footnoteSeparatorLength, + isPartOverflowRecoveryActivated(), autoHeight, isSinglePartFavored()); BlockSequence effectiveList; if (getCurrentDisplayAlign() == Constants.EN_X_FILL) { @@ -418,89 +421,25 @@ public abstract class AbstractBreaker { int optimalPageCount = alg.findBreakingPoints(effectiveList, 1, true, BreakingAlgorithm.ALL_BREAKS); if (alg.getIPDdifference() != 0) { - KnuthNode optimalBreak = alg.getBestNodeBeforeIPDChange(); - int positionIndex = optimalBreak.position; - KnuthElement elementAtBreak = alg.getElement(positionIndex); - Position positionAtBreak = elementAtBreak.getPosition(); - if (!(positionAtBreak instanceof SpaceResolver.SpaceHandlingBreakPosition)) { - throw new UnsupportedOperationException( - "Don't know how to restart at position" + positionAtBreak); - } - /* Retrieve the original position wrapped into this space position */ - positionAtBreak = positionAtBreak.getPosition(); - LayoutManager restartAtLM = null; - List firstElements = Collections.EMPTY_LIST; - if (containsNonRestartableLM(positionAtBreak)) { - if (alg.getIPDdifference() > 0) { - EventBroadcaster eventBroadcaster = getCurrentChildLM().getFObj() - .getUserAgent().getEventBroadcaster(); - BlockLevelEventProducer eventProducer - = BlockLevelEventProducer.Provider.get(eventBroadcaster); - eventProducer.nonRestartableContentFlowingToNarrowerPage(this); - } - firstElements = new LinkedList(); - boolean boxFound = false; - Iterator iter = effectiveList.listIterator(positionIndex + 1); - Position position = null; - while (iter.hasNext() - && (position == null || containsNonRestartableLM(position))) { - positionIndex++; - KnuthElement element = (KnuthElement) iter.next(); - position = element.getPosition(); - if (element.isBox()) { - boxFound = true; - firstElements.add(element); - } else if (boxFound) { - firstElements.add(element); - } - } - if (position instanceof SpaceResolver.SpaceHandlingBreakPosition) { - /* Retrieve the original position wrapped into this space position */ - positionAtBreak = position.getPosition(); - } else { - positionAtBreak = null; - } - } - if (positionAtBreak != null && positionAtBreak.getIndex() == -1) { - /* - * This is an indication that we are between two blocks - * (possibly surrounded by another block), not inside a - * paragraph. - */ - Position position; - Iterator iter = effectiveList.listIterator(positionIndex + 1); - do { - KnuthElement nextElement = (KnuthElement) iter.next(); - position = nextElement.getPosition(); - } while (position == null - || position instanceof SpaceResolver.SpaceHandlingPosition - || position instanceof SpaceResolver.SpaceHandlingBreakPosition - && position.getPosition().getIndex() == -1); - LayoutManager surroundingLM = positionAtBreak.getLM(); - while (position.getLM() != surroundingLM) { - position = position.getPosition(); - } - restartAtLM = position.getPosition().getLM(); - } - log.trace("IPD changes after page " + optimalPageCount + " at index " - + optimalBreak.position); addAreas(alg, optimalPageCount, blockList, effectiveList); - + // *** redo Phase 1 *** + log.trace("IPD changes after page " + optimalPageCount); blockLists.clear(); + nextSequenceStartsOn = getNextBlockListChangedIPD(childLC, alg, + effectiveList); blockListIndex = -1; - nextSequenceStartsOn = getNextBlockList(childLC, Constants.EN_COLUMN, - positionAtBreak, restartAtLM, firstElements); } else { - log.debug("PLM> iOptPageCount= " + optimalPageCount + log.debug("PLM> optimalPageCount= " + optimalPageCount + " pageBreaks.size()= " + alg.getPageBreaks().size()); - //*** Phase 3: Add areas *** doPhase3(alg, optimalPageCount, blockList, effectiveList); } } } + // done + blockLists = null; } /** @@ -516,11 +455,7 @@ public abstract class AbstractBreaker { return true; } else { Position subPosition = position.getPosition(); - if (subPosition == null) { - return false; - } else { - return containsNonRestartableLM(subPosition); - } + return subPosition != null && containsNonRestartableLM(subPosition); } } @@ -558,12 +493,11 @@ public abstract class AbstractBreaker { BlockSequence originalList, BlockSequence effectiveList) { LayoutContext childLC; // add areas - ListIterator effectiveListIterator = effectiveList.listIterator(); int startElementIndex = 0; int endElementIndex = 0; int lastBreak = -1; for (int p = startPart; p < startPart + partCount; p++) { - PageBreakPosition pbp = (PageBreakPosition) alg.getPageBreaks().get(p); + PageBreakPosition pbp = alg.getPageBreaks().get(p); //Check the last break position for forced breaks int lastBreakClass; @@ -616,11 +550,10 @@ public abstract class AbstractBreaker { // ignore KnuthGlue and KnuthPenalty objects // at the beginning of the line - effectiveListIterator = effectiveList - .listIterator(startElementIndex); + ListIterator<KnuthElement> effectiveListIterator + = effectiveList.listIterator(startElementIndex); while (effectiveListIterator.hasNext() - && !((KnuthElement) effectiveListIterator.next()) - .isBox()) { + && !(effectiveListIterator.next()).isBox()) { startElementIndex++; } @@ -643,10 +576,9 @@ public abstract class AbstractBreaker { && p < (partCount - 1)) { // count the boxes whose width is not 0 int boxCount = 0; - effectiveListIterator = effectiveList - .listIterator(startElementIndex); + effectiveListIterator = effectiveList.listIterator(startElementIndex); while (effectiveListIterator.nextIndex() <= endElementIndex) { - KnuthElement tempEl = (KnuthElement)effectiveListIterator.next(); + KnuthElement tempEl = effectiveListIterator.next(); if (tempEl.isBox() && tempEl.getWidth() > 0) { boxCount++; } @@ -710,8 +642,7 @@ public abstract class AbstractBreaker { * @param nextSequenceStartsOn indicates on what page the next sequence should start * @return the page on which the next content should appear after a hard break */ - protected int getNextBlockList(LayoutContext childLC, - int nextSequenceStartsOn) { + protected int getNextBlockList(LayoutContext childLC, int nextSequenceStartsOn) { return getNextBlockList(childLC, nextSequenceStartsOn, null, null, null); } @@ -730,13 +661,14 @@ public abstract class AbstractBreaker { * break */ protected int getNextBlockList(LayoutContext childLC, int nextSequenceStartsOn, - Position positionAtIPDChange, LayoutManager restartAtLM, List firstElements) { + Position positionAtIPDChange, LayoutManager restartAtLM, + List<KnuthElement> firstElements) { updateLayoutContext(childLC); //Make sure the span change signal is reset childLC.signalSpanChange(Constants.NOT_SET); BlockSequence blockList; - List returnedList; + List<KnuthElement> returnedList; if (firstElements == null) { returnedList = getNextKnuthElements(childLC, alignment); } else if (positionAtIPDChange == null) { @@ -798,9 +730,89 @@ public abstract class AbstractBreaker { BlockSequence seq; seq = blockList.endBlockSequence(breakPosition); if (seq != null) { - this.blockLists.add(seq); + blockLists.add(seq); + } + } + return nextSequenceStartsOn; + } + + /** + * @param childLC LayoutContext to use + * @param alg the pagebreaking algorithm + * @param effectiveList the list of Knuth elements to be reused + * @return the page on which the next content should appear after a hard break + */ + private int getNextBlockListChangedIPD(LayoutContext childLC, PageBreakingAlgorithm alg, + BlockSequence effectiveList) { + int nextSequenceStartsOn; + KnuthNode optimalBreak = alg.getBestNodeBeforeIPDChange(); + int positionIndex = optimalBreak.position; + log.trace("IPD changes at index " + positionIndex); + KnuthElement elementAtBreak = alg.getElement(positionIndex); + Position positionAtBreak = elementAtBreak.getPosition(); + if (!(positionAtBreak instanceof SpaceResolver.SpaceHandlingBreakPosition)) { + throw new UnsupportedOperationException( + "Don't know how to restart at position" + positionAtBreak); + } + /* Retrieve the original position wrapped into this space position */ + positionAtBreak = positionAtBreak.getPosition(); + LayoutManager restartAtLM = null; + List<KnuthElement> firstElements = Collections.emptyList(); + if (containsNonRestartableLM(positionAtBreak)) { + if (alg.getIPDdifference() > 0) { + EventBroadcaster eventBroadcaster = getCurrentChildLM().getFObj() + .getUserAgent().getEventBroadcaster(); + BlockLevelEventProducer eventProducer + = BlockLevelEventProducer.Provider.get(eventBroadcaster); + eventProducer.nonRestartableContentFlowingToNarrowerPage(this); + } + firstElements = new LinkedList<KnuthElement>(); + boolean boxFound = false; + Iterator<KnuthElement> iter = effectiveList.listIterator(positionIndex + 1); + Position position = null; + while (iter.hasNext() + && (position == null || containsNonRestartableLM(position))) { + positionIndex++; + KnuthElement element = iter.next(); + position = element.getPosition(); + if (element.isBox()) { + boxFound = true; + firstElements.add(element); + } else if (boxFound) { + firstElements.add(element); + } + } + if (position instanceof SpaceResolver.SpaceHandlingBreakPosition) { + /* Retrieve the original position wrapped into this space position */ + positionAtBreak = position.getPosition(); + } else { + positionAtBreak = null; + } + } + if (positionAtBreak != null && positionAtBreak.getIndex() == -1) { + /* + * This is an indication that we are between two blocks + * (possibly surrounded by another block), not inside a + * paragraph. + */ + Position position; + Iterator<KnuthElement> iter = effectiveList.listIterator(positionIndex + 1); + do { + KnuthElement nextElement = iter.next(); + position = nextElement.getPosition(); + } while (position == null + || position instanceof SpaceResolver.SpaceHandlingPosition + || position instanceof SpaceResolver.SpaceHandlingBreakPosition + && position.getPosition().getIndex() == -1); + LayoutManager surroundingLM = positionAtBreak.getLM(); + while (position.getLM() != surroundingLM) { + position = position.getPosition(); } + restartAtLM = position.getPosition().getLM(); } + + nextSequenceStartsOn = getNextBlockList(childLC, Constants.EN_COLUMN, + positionAtBreak, restartAtLM, firstElements); return nextSequenceStartsOn; } @@ -813,15 +825,14 @@ public abstract class AbstractBreaker { */ private int optimizeLineLength(KnuthSequence effectiveList, int startElementIndex, int endElementIndex) { - ListIterator effectiveListIterator; + ListIterator<KnuthElement> effectiveListIterator; // optimize line length int boxCount = 0; int accumulatedLineLength = 0; int greatestMinimumLength = 0; - effectiveListIterator = effectiveList - .listIterator(startElementIndex); + effectiveListIterator = effectiveList.listIterator(startElementIndex); while (effectiveListIterator.nextIndex() <= endElementIndex) { - KnuthElement tempEl = (KnuthElement) effectiveListIterator + KnuthElement tempEl = effectiveListIterator .next(); if (tempEl instanceof KnuthBlockBox) { KnuthBlockBox blockBox = (KnuthBlockBox) tempEl; @@ -860,30 +871,27 @@ public abstract class AbstractBreaker { */ private BlockSequence justifyBoxes // CSOK: MethodLength (BlockSequence blockList, PageBreakingAlgorithm alg, int availableBPD) { - int iOptPageNumber; + int optimalPageCount; alg.setConstantLineWidth(availableBPD); - iOptPageNumber = alg.findBreakingPoints(blockList, /*availableBPD,*/ + optimalPageCount = alg.findBreakingPoints(blockList, /*availableBPD,*/ 1, true, BreakingAlgorithm.ALL_BREAKS); - log.debug("PLM> iOptPageNumber= " + iOptPageNumber); + log.debug("PLM> optimalPageCount= " + optimalPageCount); // - ListIterator sequenceIterator = blockList.listIterator(); - ListIterator breakIterator = alg.getPageBreaks().listIterator(); + ListIterator<KnuthElement> sequenceIterator = blockList.listIterator(); + ListIterator<PageBreakPosition> breakIterator = alg.getPageBreaks().listIterator(); KnuthElement thisElement = null; PageBreakPosition thisBreak; - int accumulatedS; // accumulated stretch or shrink int adjustedDiff; // difference already adjusted - int firstElementIndex; while (breakIterator.hasNext()) { - thisBreak = (PageBreakPosition) breakIterator.next(); + thisBreak = breakIterator.next(); if (log.isDebugEnabled()) { log.debug("| first page: break= " + thisBreak.getLeafPos() + " difference= " + thisBreak.difference + " ratio= " + thisBreak.bpdAdjust); } - accumulatedS = 0; adjustedDiff = 0; // glue and penalty items at the beginning of the page must @@ -892,8 +900,8 @@ public abstract class AbstractBreaker { // inside the // while loop must be a box KnuthElement firstElement; - while ( sequenceIterator.hasNext() ) { - firstElement = (KnuthElement) sequenceIterator.next(); + while (sequenceIterator.hasNext()) { + firstElement = sequenceIterator.next(); if ( !firstElement.isBox() ) { log.debug("PLM> ignoring glue or penalty element " + "at the beginning of the sequence"); @@ -906,41 +914,39 @@ public abstract class AbstractBreaker { break; } } - firstElementIndex = sequenceIterator.previousIndex(); sequenceIterator.previous(); // scan the sub-sequence representing a page, // collecting information about potential adjustments MinOptMax lineNumberMaxAdjustment = MinOptMax.ZERO; MinOptMax spaceMaxAdjustment = MinOptMax.ZERO; - double spaceAdjustmentRatio = 0.0; - LinkedList blockSpacesList = new LinkedList(); - LinkedList unconfirmedList = new LinkedList(); - LinkedList adjustableLinesList = new LinkedList(); + LinkedList<KnuthGlue> blockSpacesList = new LinkedList<KnuthGlue>(); + LinkedList<KnuthGlue> unconfirmedList = new LinkedList<KnuthGlue>(); + LinkedList<KnuthGlue> adjustableLinesList = new LinkedList<KnuthGlue>(); boolean bBoxSeen = false; while (sequenceIterator.hasNext() - && sequenceIterator.nextIndex() <= thisBreak - .getLeafPos()) { - thisElement = (KnuthElement) sequenceIterator.next(); + && sequenceIterator.nextIndex() <= thisBreak.getLeafPos()) { + thisElement = sequenceIterator.next(); if (thisElement.isGlue()) { // glue elements are used to represent adjustable // lines // and adjustable spaces between blocks - Adjustment adjustment = ((KnuthGlue) thisElement).getAdjustmentClass(); + KnuthGlue thisGlue = (KnuthGlue) thisElement; + Adjustment adjustment = thisGlue.getAdjustmentClass(); if (adjustment.equals(Adjustment.SPACE_BEFORE_ADJUSTMENT) || adjustment.equals(Adjustment.SPACE_AFTER_ADJUSTMENT)) { // potential space adjustment // glue items before the first box or after the // last one // must be ignored - unconfirmedList.add(thisElement); + unconfirmedList.add(thisGlue); } else if (adjustment.equals(Adjustment.LINE_NUMBER_ADJUSTMENT)) { // potential line number adjustment lineNumberMaxAdjustment = lineNumberMaxAdjustment.plusMax(thisElement.getStretch()); lineNumberMaxAdjustment = lineNumberMaxAdjustment.minusMin(thisElement.getShrink()); - adjustableLinesList.add(thisElement); + adjustableLinesList.add(thisGlue); } else if (adjustment.equals(Adjustment.LINE_HEIGHT_ADJUSTMENT)) { // potential line height adjustment } @@ -954,8 +960,7 @@ public abstract class AbstractBreaker { // the last box // in this page; they must be added to // blockSpaceList - KnuthGlue blockSpace = (KnuthGlue) unconfirmedList - .removeFirst(); + KnuthGlue blockSpace = unconfirmedList.removeFirst(); spaceMaxAdjustment = spaceMaxAdjustment.plusMax(blockSpace.getStretch()); spaceMaxAdjustment @@ -983,9 +988,6 @@ public abstract class AbstractBreaker { || (thisBreak.difference < 0 && thisBreak.difference >= spaceMaxAdjustment .getMin())) { // modify only the spaces between blocks - spaceAdjustmentRatio = ((double) thisBreak.difference / (thisBreak.difference > 0 - ? spaceMaxAdjustment.getMax() - : spaceMaxAdjustment.getMin())); adjustedDiff += adjustBlockSpaces( blockSpacesList, thisBreak.difference, @@ -1032,16 +1034,16 @@ public abstract class AbstractBreaker { return effectiveList; } - private int adjustBlockSpaces(LinkedList spaceList, int difference, int total) { + private int adjustBlockSpaces(LinkedList<KnuthGlue> spaceList, int difference, int total) { if (log.isDebugEnabled()) { log.debug("AdjustBlockSpaces: difference " + difference + " / " + total + " on " + spaceList.size() + " spaces in block"); } - ListIterator spaceListIterator = spaceList.listIterator(); + ListIterator<KnuthGlue> spaceListIterator = spaceList.listIterator(); int adjustedDiff = 0; int partial = 0; while (spaceListIterator.hasNext()) { - KnuthGlue blockSpace = (KnuthGlue)spaceListIterator.next(); + KnuthGlue blockSpace = spaceListIterator.next(); partial += (difference > 0 ? blockSpace.getStretch() : blockSpace.getShrink()); if (log.isDebugEnabled()) { log.debug("available = " + partial + " / " + total); @@ -1057,7 +1059,7 @@ public abstract class AbstractBreaker { return adjustedDiff; } - private int adjustLineNumbers(LinkedList lineList, int difference, int total) { + private int adjustLineNumbers(LinkedList<KnuthGlue> lineList, int difference, int total) { if (log.isDebugEnabled()) { log.debug("AdjustLineNumbers: difference " + difference @@ -1068,11 +1070,11 @@ public abstract class AbstractBreaker { + " elements"); } - ListIterator lineListIterator = lineList.listIterator(); + ListIterator<KnuthGlue> lineListIterator = lineList.listIterator(); int adjustedDiff = 0; int partial = 0; while (lineListIterator.hasNext()) { - KnuthGlue line = (KnuthGlue)lineListIterator.next(); + KnuthGlue line = lineListIterator.next(); partial += (difference > 0 ? line.getStretch() : line.getShrink()); int newAdjust = ((BlockLevelLayoutManager) line.getLayoutManager()) .negotiateBPDAdjustment
Modified: xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/layoutmgr/AbstractLayoutManager.java URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/layoutmgr/AbstractLayoutManager.java?rev=1309921&r1=1309920&r2=1309921&view=diff ============================================================================== --- xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/layoutmgr/AbstractLayoutManager.java (original) +++ xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/layoutmgr/AbstractLayoutManager.java Thu Apr 5 16:19:19 2012 @@ -20,7 +20,6 @@ package org.apache.fop.layoutmgr; import java.util.ArrayList; -import java.util.Iterator; import java.util.List; import java.util.ListIterator; import java.util.Map; @@ -28,33 +27,34 @@ import java.util.Map; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.apache.xmlgraphics.util.QName; + import org.apache.fop.area.Area; import org.apache.fop.area.AreaTreeObject; import org.apache.fop.area.PageViewport; import org.apache.fop.fo.Constants; import org.apache.fop.fo.FONode; import org.apache.fop.fo.FObj; +import org.apache.fop.fo.flow.Marker; import org.apache.fop.fo.flow.RetrieveMarker; /** * The base class for most LayoutManagers. */ public abstract class AbstractLayoutManager extends AbstractBaseLayoutManager - implements Constants { + implements Constants { - /** - * logging instance - */ + /** logging instance */ private static Log log = LogFactory.getLog(AbstractLayoutManager.class); /** Parent LayoutManager for this LayoutManager */ protected LayoutManager parentLayoutManager; /** List of child LayoutManagers */ - protected List childLMs; + protected List<LayoutManager> childLMs; /** Iterator for child LayoutManagers */ protected ListIterator fobjIter; /** Marker map for markers related to this LayoutManager */ - private Map markers; + private Map<String, Marker> markers; /** True if this LayoutManager has handled all of its content. */ private boolean isFinished; @@ -63,7 +63,7 @@ public abstract class AbstractLayoutMana protected LayoutManager curChildLM; /** child LM iterator during getNextKnuthElement phase */ - protected ListIterator childLMiter; + protected ListIterator<LayoutManager> childLMiter; private int lastGeneratedPosition = -1; private int smallestPosNumberChecked = Integer.MAX_VALUE; @@ -116,7 +116,7 @@ public abstract class AbstractLayoutMana return curChildLM; } if (childLMiter.hasNext()) { - curChildLM = (LayoutManager) childLMiter.next(); + curChildLM = childLMiter.next(); curChildLM.initialize(); return curChildLM; } @@ -131,7 +131,7 @@ public abstract class AbstractLayoutMana curChildLM = childLM; childLMiter = new LMiter(this); do { - curChildLM = (LayoutManager) childLMiter.next(); + curChildLM = childLMiter.next(); } while (curChildLM != childLM); } @@ -165,16 +165,14 @@ public abstract class AbstractLayoutMana } /** {@inheritDoc} */ - public List getNextKnuthElements(LayoutContext context, - int alignment) { + public List getNextKnuthElements(LayoutContext context, int alignment) { log.warn("null implementation of getNextKnuthElements() called!"); setFinished(true); return null; } /** {@inheritDoc} */ - public List getChangedKnuthElements(List oldList, - int alignment) { + public List getChangedKnuthElements(List oldList, int alignment) { log.warn("null implementation of getChangeKnuthElement() called!"); return null; } @@ -210,11 +208,11 @@ public abstract class AbstractLayoutMana * @param size the requested number of child LMs * @return the list with the preloaded child LMs */ - protected List createChildLMs(int size) { + protected List<LayoutManager> createChildLMs(int size) { if (fobjIter == null) { return null; } - List newLMs = new ArrayList(size); + List<LayoutManager> newLMs = new ArrayList<LayoutManager>(size); while (fobjIter.hasNext() && newLMs.size() < size ) { Object theobj = fobjIter.next(); if (theobj instanceof FONode) { @@ -224,8 +222,8 @@ public abstract class AbstractLayoutMana (RetrieveMarker) foNode); } if (foNode != null) { - getPSLM().getLayoutManagerMaker(). - makeLayoutManagers(foNode, newLMs); + getPSLM().getLayoutManagerMaker() + .makeLayoutManagers(foNode, newLMs); } } } @@ -250,35 +248,29 @@ public abstract class AbstractLayoutMana return getPSLM().getCurrentPage().getPageViewport(); } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ public boolean createNextChildLMs(int pos) { - List newLMs = createChildLMs(pos + 1 - childLMs.size()); + List<LayoutManager> newLMs = createChildLMs(pos + 1 - childLMs.size()); addChildLMs(newLMs); return pos < childLMs.size(); } - /** - * {@inheritDoc} - */ - public List getChildLMs() { + /** {@inheritDoc} */ + public List<LayoutManager> getChildLMs() { if (childLMs == null) { - childLMs = new java.util.ArrayList(10); + childLMs = new java.util.ArrayList<LayoutManager>(10); } return childLMs; } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ public void addChildLM(LayoutManager lm) { if (lm == null) { return; } lm.setParent(this); if (childLMs == null) { - childLMs = new java.util.ArrayList(10); + childLMs = new java.util.ArrayList<LayoutManager>(10); } childLMs.add(lm); if (log.isTraceEnabled()) { @@ -287,17 +279,14 @@ public abstract class AbstractLayoutMana } } - /** - * {@inheritDoc} - */ + /** {@inheritDoc} */ public void addChildLMs(List newLMs) { if (newLMs == null || newLMs.size() == 0) { return; } - ListIterator iter = newLMs.listIterator(); + ListIterator<LayoutManager> iter = newLMs.listIterator(); while (iter.hasNext()) { - LayoutManager lm = (LayoutManager) iter.next(); - addChildLM(lm); + addChildLM(iter.next()); } } @@ -312,8 +301,7 @@ public abstract class AbstractLayoutMana throw new IllegalStateException("Position already got its index"); } - lastGeneratedPosition++; - pos.setIndex(lastGeneratedPosition); + pos.setIndex(++lastGeneratedPosition); return pos; } @@ -358,7 +346,7 @@ public abstract class AbstractLayoutMana * @param targetArea the area to set the attributes on */ protected void transferForeignAttributes(AreaTreeObject targetArea) { - Map atts = fobj.getForeignAttributes(); + Map<QName, String> atts = fobj.getForeignAttributes(); targetArea.setForeignAttributes(atts); } @@ -459,18 +447,20 @@ public abstract class AbstractLayoutMana } /** {@inheritDoc} */ + @Override public String toString() { - return (super.toString() + (fobj != null ? "[fobj=" + fobj.toString() + "]" : "")); + return (super.toString() + (fobj != null ? "{fobj = " + fobj.toString() + "}" : "")); } /** {@inheritDoc} */ + @Override public void reset() { isFinished = false; curChildLM = null; childLMiter = new LMiter(this); /* Reset all the children LM that have been created so far. */ - for (Iterator iter = getChildLMs().iterator(); iter.hasNext();) { - ((LayoutManager) iter.next()).reset(); + for (LayoutManager childLM : getChildLMs()) { + childLM.reset(); } if (fobj != null) { markers = fobj.getMarkers(); Modified: xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/layoutmgr/AbstractPageSequenceLayoutManager.java URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/layoutmgr/AbstractPageSequenceLayoutManager.java?rev=1309921&r1=1309920&r2=1309921&view=diff ============================================================================== --- xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/layoutmgr/AbstractPageSequenceLayoutManager.java (original) +++ xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/layoutmgr/AbstractPageSequenceLayoutManager.java Thu Apr 5 16:19:19 2012 @@ -276,10 +276,9 @@ public abstract class AbstractPageSequen * Makes a new page * * @param isBlank whether this page is blank or not - * @param isLast whether this page is the last page or not * @return a new page */ - protected Page makeNewPage(boolean isBlank, boolean isLast) { + protected Page makeNewPage(boolean isBlank) { if (curPage != null) { finishPage(); } @@ -293,6 +292,7 @@ public abstract class AbstractPageSequen + (isBlank ? "*" : "") + "]"); } + addIDToPage(pageSeq.getRoot().getId()); addIDToPage(pageSeq.getId()); return curPage; } @@ -359,19 +359,19 @@ public abstract class AbstractPageSequen if (forcePageCount == Constants.EN_EVEN) { if ((currentPageNum - startPageNum + 1) % 2 != 0) { // we have an odd number of pages - curPage = makeNewPage(true, false); + curPage = makeNewPage(true); } } else if (forcePageCount == Constants.EN_ODD) { if ((currentPageNum - startPageNum + 1) % 2 == 0) { // we have an even number of pages - curPage = makeNewPage(true, false); + curPage = makeNewPage(true); } } else if (forcePageCount == Constants.EN_END_ON_EVEN) { if (currentPageNum % 2 != 0) { // we are now on an odd page - curPage = makeNewPage(true, false); + curPage = makeNewPage(true); } } else if (forcePageCount == Constants.EN_END_ON_ODD) { if (currentPageNum % 2 == 0) { // we are now on an even page - curPage = makeNewPage(true, false); + curPage = makeNewPage(true); } } else if (forcePageCount == Constants.EN_NO_FORCE) { // i hope: nothing special at all Modified: xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/layoutmgr/AreaAdditionUtil.java URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/layoutmgr/AreaAdditionUtil.java?rev=1309921&r1=1309920&r2=1309921&view=diff ============================================================================== --- xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/layoutmgr/AreaAdditionUtil.java (original) +++ xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/layoutmgr/AreaAdditionUtil.java Thu Apr 5 16:19:19 2012 @@ -19,7 +19,6 @@ package org.apache.fop.layoutmgr; -import java.util.Iterator; import java.util.LinkedList; import org.apache.fop.layoutmgr.SpaceResolver.SpaceHandlingBreakPosition; @@ -32,20 +31,6 @@ public final class AreaAdditionUtil { private AreaAdditionUtil() { } - private static class StackingIter extends PositionIterator { - StackingIter(Iterator parentIter) { - super(parentIter); - } - - protected LayoutManager getLM(Object nextObj) { - return ((Position) nextObj).getLM(); - } - - protected Position getPos(Object nextObj) { - return ((Position) nextObj); - } - } - /** * Creates the child areas for the given layout manager. * @param bslm the BlockStackingLayoutManager instance for which "addAreas" is performed. @@ -54,19 +39,23 @@ public final class AreaAdditionUtil { */ public static void addAreas(BlockStackingLayoutManager bslm, PositionIterator parentIter, LayoutContext layoutContext) { - LayoutManager childLM = null; + LayoutManager childLM; LayoutContext lc = new LayoutContext(0); LayoutManager firstLM = null; LayoutManager lastLM = null; Position firstPos = null; Position lastPos = null; + if (bslm != null) { + bslm.addId(); + } + // "unwrap" the NonLeafPositions stored in parentIter // and put them in a new list; - LinkedList positionList = new LinkedList(); + LinkedList<Position> positionList = new LinkedList<Position>(); Position pos; while (parentIter.hasNext()) { - pos = (Position)parentIter.next(); + pos = parentIter.next(); if (pos == null) { continue; } @@ -78,8 +67,8 @@ public final class AreaAdditionUtil { } if (pos instanceof NonLeafPosition) { // pos was created by a child of this FlowLM - positionList.add(((NonLeafPosition) pos).getPosition()); - lastLM = ((NonLeafPosition) pos).getPosition().getLM(); + positionList.add(pos.getPosition()); + lastLM = (pos.getPosition().getLM()); if (firstLM == null) { firstLM = lastLM; } @@ -104,7 +93,7 @@ public final class AreaAdditionUtil { bslm.isLast(lastPos)); } - StackingIter childPosIter = new StackingIter(positionList.listIterator()); + PositionIterator childPosIter = new PositionIterator(positionList.listIterator()); while ((childLM = childPosIter.getNextChildLM()) != null) { // TODO vh: the test above might be problematic in some cases. See comment in @@ -129,6 +118,7 @@ public final class AreaAdditionUtil { false, bslm.isFirst(firstPos), bslm.isLast(lastPos)); + bslm.checkEndOfLayout(lastPos); } Modified: xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/layoutmgr/BalancingColumnBreakingAlgorithm.java URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/layoutmgr/BalancingColumnBreakingAlgorithm.java?rev=1309921&r1=1309920&r2=1309921&view=diff ============================================================================== --- xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/layoutmgr/BalancingColumnBreakingAlgorithm.java (original) +++ xmlgraphics/fop/branches/Temp_TrueTypeInPostScript/src/java/org/apache/fop/layoutmgr/BalancingColumnBreakingAlgorithm.java Thu Apr 5 16:19:19 2012 @@ -22,7 +22,6 @@ package org.apache.fop.layoutmgr; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.apache.fop.fo.Constants; import org.apache.fop.traits.MinOptMax; /** --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
