1 17 18 19 20 package org.apache.fop.layoutmgr.inline; 21 22 import java.util.LinkedList ; 23 import java.util.List ; 24 import java.util.ListIterator ; 25 26 import org.apache.commons.logging.Log; 27 import org.apache.commons.logging.LogFactory; 28 import org.apache.fop.fo.flow.Footnote; 29 import org.apache.fop.layoutmgr.AbstractLayoutManager; 30 import org.apache.fop.layoutmgr.FootnoteBodyLayoutManager; 31 import org.apache.fop.layoutmgr.InlineKnuthSequence; 32 import org.apache.fop.layoutmgr.KnuthElement; 33 import org.apache.fop.layoutmgr.KnuthSequence; 34 import org.apache.fop.layoutmgr.LayoutContext; 35 import org.apache.fop.layoutmgr.Position; 36 37 40 public class FootnoteLayoutManager extends AbstractLayoutManager 41 implements InlineLevelLayoutManager { 42 43 46 private static Log log = LogFactory.getLog(FootnoteLayoutManager.class); 47 48 private Footnote footnote; 49 private InlineStackingLayoutManager citationLM; 50 private FootnoteBodyLayoutManager bodyLM; 51 52 private KnuthElement forcedAnchor; 53 54 58 public FootnoteLayoutManager(Footnote node) { 59 super(node); 60 footnote = node; 61 } 62 63 64 public void initialize() { 65 citationLM = new InlineLayoutManager(footnote.getFootnoteCitation()); 67 68 bodyLM = new FootnoteBodyLayoutManager(footnote.getFootnoteBody()); 70 } 71 72 73 public LinkedList getNextKnuthElements(LayoutContext context, 74 int alignment) { 75 80 citationLM.setParent(getParent()); 82 citationLM.initialize(); 83 bodyLM.setParent(this); 84 bodyLM.initialize(); 85 86 LinkedList returnedList = new LinkedList (); 88 while (!citationLM.isFinished()) { 89 LinkedList partialList = citationLM.getNextKnuthElements(context, alignment); 90 if (partialList != null) { 91 returnedList.addAll(partialList); 92 } 93 } 94 if (returnedList.size() == 0) { 95 KnuthSequence seq = new InlineKnuthSequence(); 98 forcedAnchor = new KnuthInlineBox(0, null, null, true); 100 seq.add(forcedAnchor); 101 returnedList.add(seq); 102 } 103 setFinished(true); 104 105 addAnchor(returnedList); 106 107 return returnedList; 108 } 109 110 private void addAnchor(LinkedList citationList) { 111 KnuthInlineBox lastBox = null; 114 ListIterator citationIterator = citationList.listIterator(citationList.size()); 115 while (citationIterator.hasPrevious() && lastBox == null) { 116 Object obj = citationIterator.previous(); 117 if (obj instanceof KnuthElement) { 118 KnuthElement element = (KnuthElement)obj; 119 if (element instanceof KnuthInlineBox) { 120 lastBox = (KnuthInlineBox) element; 121 } 122 } else { 123 KnuthSequence seq = (KnuthSequence)obj; 124 ListIterator nestedIterator = seq.listIterator(seq.size()); 125 while (nestedIterator.hasPrevious() && lastBox == null) { 126 KnuthElement element = (KnuthElement)nestedIterator.previous(); 127 if (element instanceof KnuthInlineBox && !element.isAuxiliary() 128 || element == forcedAnchor) { 129 lastBox = (KnuthInlineBox) element; 130 } 131 } 132 } 133 } 134 if (lastBox != null) { 135 lastBox.setFootnoteBodyLM(bodyLM); 136 } else { 137 } 139 } 140 141 142 public List addALetterSpaceTo(List oldList) { 143 log.warn("null implementation of addALetterSpaceTo() called!"); 144 return oldList; 145 } 146 147 152 public void removeWordSpace(List oldList) { 153 log.warn(this.getClass().getName() + " should not receive a call to removeWordSpace(list)"); 155 } 156 157 158 public void getWordChars(StringBuffer sbChars, Position pos) { 159 log.warn("null implementation of getWordChars() called!"); 160 } 161 162 163 public void hyphenate(Position pos, HyphContext hc) { 164 log.warn("null implementation of hyphenate called!"); 165 } 166 167 168 public boolean applyChanges(List oldList) { 169 log.warn("null implementation of applyChanges() called!"); 170 return false; 171 } 172 173 176 public LinkedList getChangedKnuthElements(List oldList, 177 int alignment) { 178 log.warn("null implementation of getChangeKnuthElement() called!"); 179 return null; 180 } 181 } 182 | Popular Tags |