]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
Deal with a mix of KnuthSequences of KnuthSequences and KnuthSequences of KnuthElemen...
authorJeremias Maerki <jeremias@apache.org>
Mon, 8 Aug 2005 09:38:32 +0000 (09:38 +0000)
committerJeremias Maerki <jeremias@apache.org>
Mon, 8 Aug 2005 09:38:32 +0000 (09:38 +0000)
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

src/java/org/apache/fop/layoutmgr/inline/FootnoteLayoutManager.java
src/java/org/apache/fop/layoutmgr/inline/LineLayoutManager.java

index e39292f62b975538557b11e4aa4f4c11ec89d4ff..779c4c5879715b4fed756bec238a6aa99ccdf649 100644 (file)
@@ -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) {
index df647fcaf9215647f3d96c530e1e36728e3f6b6d..4a551d3205d505791af074d2b484adb2ccc6c63d 100644 (file)
@@ -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");
                         }