Index: src/java/org/apache/fop/layoutmgr/inline/InlineLayoutManager.java =================================================================== --- src/java/org/apache/fop/layoutmgr/inline/InlineLayoutManager.java (revision 1050409) +++ src/java/org/apache/fop/layoutmgr/inline/InlineLayoutManager.java (working copy) @@ -48,6 +48,7 @@ import org.apache.fop.layoutmgr.BreakElement; import org.apache.fop.layoutmgr.InlineKnuthSequence; import org.apache.fop.layoutmgr.KnuthBox; +import org.apache.fop.layoutmgr.KnuthElement; import org.apache.fop.layoutmgr.KnuthSequence; import org.apache.fop.layoutmgr.LayoutContext; import org.apache.fop.layoutmgr.LayoutManager; @@ -74,7 +75,6 @@ private CommonMarginInline inlineProps = null; private CommonBorderPaddingBackground borderProps = null; - private boolean areaCreated = false; private LayoutManager lastChildLM = null; // Set when return last breakposs; private Position auxiliaryPosition; @@ -96,6 +96,8 @@ private AlignmentContext alignmentContext = null; + private KnuthElement firstKnuthElement = null; + /** * Create an inline layout manager. * This is used for fo's that create areas that @@ -396,9 +398,30 @@ } } - return returnList.isEmpty() ? null : returnList; + boolean isEmpty = returnList.isEmpty(); + + if (!isEmpty) { + storeFirstKnuthElement((List)returnList.get(0)); + } + + return isEmpty ? null : returnList; } + private void storeFirstKnuthElement(List knuthSequence) { + firstKnuthElement = knuthSequence.isEmpty() ? null : (KnuthElement)knuthSequence.get(0); + } + + private boolean isDescendantPosition(KnuthElement ke, Position position) { + Position pos = ke.getPosition(); + while (pos instanceof NonLeafPosition && pos != null) { + if (pos == position) { + return true; + } + pos = pos.getPosition(); + } + return false; + } + /** * Generate and add areas to parent area. * Set size of each area. This should only create and return one @@ -415,18 +438,8 @@ setChildContext(new LayoutContext(context)); // Store current value - // If this LM has fence, make a new leading space specifier. - if (hasLeadingFence(areaCreated)) { - getContext().setLeadingSpace(new SpaceSpecifier(false)); - getContext().setFlags(LayoutContext.RESOLVE_LEADING_SPACE, true); - } else { - getContext().setFlags(LayoutContext.RESOLVE_LEADING_SPACE, false); - } + boolean areaCreated = firstKnuthElement != null; - if (getSpaceStart() != null) { - context.getLeadingSpace().addSpace(new SpaceVal(getSpaceStart(), this)); - } - // "Unwrap" the NonLeafPositions stored in parentIter and put // them in a new list. Set lastLM to be the LayoutManager // which created the last Position: if the LAST_AREA flag is @@ -434,17 +447,35 @@ // layout context given to lastLM, but must be cleared in the // layout context given to the other LMs. List positionList = new LinkedList(); - NonLeafPosition pos; + Position pos; LayoutManager lastLM = null; // last child LM in this iterator Position lastPos = null; while (parentIter.hasNext()) { - pos = (NonLeafPosition) parentIter.next(); + if ((parentIter.peekNext() instanceof KnuthElement + && parentIter.peekNext() == firstKnuthElement) + || (parentIter.peekNext() instanceof Position) + && isDescendantPosition(firstKnuthElement, (Position)parentIter.peekNext())) + areaCreated = false; + pos = (Position) parentIter.next(); if (pos != null && pos.getPosition() != null) { positionList.add(pos.getPosition()); lastLM = pos.getPosition().getLM(); lastPos = pos; } } + + // If this LM has fence, make a new leading space specifier. + if (hasLeadingFence(areaCreated)) { + getContext().setLeadingSpace(new SpaceSpecifier(false)); + getContext().setFlags(LayoutContext.RESOLVE_LEADING_SPACE, true); + } else { + getContext().setFlags(LayoutContext.RESOLVE_LEADING_SPACE, false); + } + + if (getSpaceStart() != null) { + context.getLeadingSpace().addSpace(new SpaceVal(getSpaceStart(), this)); + } + /*if (pos != null) { lastLM = pos.getPosition().getLM(); }*/ @@ -537,6 +568,7 @@ addKnuthElementsForBorderPaddingStart(returnedList); returnedList.addAll(super.getChangedKnuthElements(oldList, alignment)); addKnuthElementsForBorderPaddingEnd(returnedList); + storeFirstKnuthElement(returnedList); return returnedList; }