From: Jeremias Maerki Date: Mon, 8 Aug 2005 09:38:32 +0000 (+0000) Subject: Deal with a mix of KnuthSequences of KnuthSequences and KnuthSequences of KnuthElemen... X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=eef5f84436300cea03023e234bccd0ca2e77dca6;p=xmlgraphics-fop.git Deal with a mix of KnuthSequences of KnuthSequences and KnuthSequences of KnuthElements to allow for fewer container classes. InlineLM instead of InlineStackingLM for inline part of footnote. Supposedly fixed a bug in addALetterSpace. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/inlineblock@230779 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/java/org/apache/fop/layoutmgr/inline/FootnoteLayoutManager.java b/src/java/org/apache/fop/layoutmgr/inline/FootnoteLayoutManager.java index e39292f62..779c4c587 100644 --- a/src/java/org/apache/fop/layoutmgr/inline/FootnoteLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/inline/FootnoteLayoutManager.java @@ -26,6 +26,7 @@ import org.apache.fop.fo.flow.Footnote; import org.apache.fop.layoutmgr.AbstractLayoutManager; import org.apache.fop.layoutmgr.FootnoteBodyLayoutManager; import org.apache.fop.layoutmgr.KnuthElement; +import org.apache.fop.layoutmgr.KnuthSequence; import org.apache.fop.layoutmgr.LayoutContext; import org.apache.fop.layoutmgr.Position; @@ -45,7 +46,7 @@ public class FootnoteLayoutManager extends AbstractLayoutManager footnote = node; // create an InlineStackingLM handling the fo:inline child of fo:footnote - citationLM = new InlineStackingLayoutManager(footnote.getFootnoteCitation()); + citationLM = new InlineLayoutManager(footnote.getFootnoteCitation()); // create a FootnoteBodyLM handling the fo:footnote-body child of fo:footnote bodyLM = new FootnoteBodyLayoutManager(footnote.getFootnoteBody()); @@ -85,12 +86,24 @@ public class FootnoteLayoutManager extends AbstractLayoutManager private void addAnchor(LinkedList citationList) { // find the last box in the sequence, and add a reference // to the FootnoteBodyLM - ListIterator citationIterator = citationList.listIterator(citationList.size()); KnuthInlineBox lastBox = null; + ListIterator citationIterator = citationList.listIterator(citationList.size()); while (citationIterator.hasPrevious() && lastBox == null) { - KnuthElement element = (KnuthElement) citationIterator.previous(); - if (element instanceof KnuthInlineBox) { - lastBox = (KnuthInlineBox) element; + Object obj = citationIterator.previous(); + if (obj instanceof KnuthElement) { + KnuthElement element = (KnuthElement)obj; + if (element instanceof KnuthInlineBox) { + lastBox = (KnuthInlineBox) element; + } + } else { + KnuthSequence seq = (KnuthSequence)obj; + ListIterator nestedIterator = seq.listIterator(seq.size()); + while (nestedIterator.hasPrevious() && lastBox == null) { + KnuthElement element = (KnuthElement)nestedIterator.previous(); + if (element instanceof KnuthInlineBox) { + lastBox = (KnuthInlineBox) element; + } + } } } if (lastBox != null) { diff --git a/src/java/org/apache/fop/layoutmgr/inline/LineLayoutManager.java b/src/java/org/apache/fop/layoutmgr/inline/LineLayoutManager.java index df647fcaf..4a551d320 100644 --- a/src/java/org/apache/fop/layoutmgr/inline/LineLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/inline/LineLayoutManager.java @@ -288,7 +288,7 @@ public class LineLayoutManager extends InlineStackingLayoutManager // while the other elements are not changed oldList.add(prevBox); // TODO check if this is the correct place; merge was not correct - oldList.addFirst((KnuthBox) removeLast()); + // already done by above call???? oldList.addFirst((KnuthBox) removeLast()); oldList.addFirst((KnuthGlue) removeLast()); oldList.addFirst((KnuthPenalty) removeLast()); } @@ -644,25 +644,45 @@ public class LineLayoutManager extends InlineStackingLayoutManager } // does the first element of the first paragraph add to an existing word? if (lastPar != null) { - KnuthSequence firstSeq = (KnuthSequence) returnedList.getFirst(); - if (!firstSeq.isInlineSequence()) { - log.error("Expect inline sequence as first sequence when last paragraph is not null"); + Object obj = returnedList.getFirst(); + KnuthElement thisElement; + if (obj instanceof KnuthElement) { + thisElement = (KnuthElement)obj; + } else { + KnuthSequence firstSeq = (KnuthSequence) obj; + if (!firstSeq.isInlineSequence()) { + log.error("Expect inline sequence as first sequence when last paragraph is not null"); + } + thisElement = (KnuthElement) firstSeq.get(0); } - KnuthElement thisElement = (KnuthElement) firstSeq.get(0); if (thisElement.isBox() && !thisElement.isAuxiliary() && bPrevWasKnuthBox) { lastPar.addALetterSpace(); } } - // loop over the KnuthSequences in returnedList + // loop over the KnuthSequences (and single KnuthElements) in returnedList + // (LeafNodeLM descendants may also skip wrapping elements in KnuthSequences + // to cause fewer container structures) ListIterator iter = returnedList.listIterator(); while (iter.hasNext()) { - KnuthSequence sequence = (KnuthSequence) iter.next(); + Object obj = iter.next(); + KnuthElement singleElement = null; + KnuthSequence sequence = null; + if (obj instanceof KnuthElement) { + singleElement = (KnuthElement)obj; + } else { + sequence = (KnuthSequence)obj; + } // the sequence contains inline Knuth elements - if (sequence.isInlineSequence()) { + if (singleElement != null || sequence.isInlineSequence()) { // look at the last element - KnuthElement lastElement = (KnuthElement) sequence.getLast(); + KnuthElement lastElement; + if (singleElement != null) { + lastElement = singleElement; + } else { + lastElement = (KnuthElement) sequence.getLast(); + } bPrevWasKnuthBox = lastElement.isBox(); // if last paragraph is open, add the new elements to the paragraph @@ -680,7 +700,11 @@ public class LineLayoutManager extends InlineStackingLayoutManager trace.append(" +"); } } - lastPar.addAll(sequence); + if (singleElement != null) { + lastPar.add(singleElement); + } else { + lastPar.addAll(sequence); + } if (log.isTraceEnabled()) { trace.append(" I"); }