1 17 18 19 20 package org.apache.fop.layoutmgr; 21 22 import java.util.LinkedList ; 23 import java.util.List ; 24 25 import org.apache.fop.layoutmgr.inline.InlineLevelLayoutManager; 26 import org.apache.fop.layoutmgr.inline.KnuthInlineBox; 27 28 29 33 public class InlineKnuthSequence extends KnuthSequence { 34 35 private boolean isClosed = false; 36 37 40 public InlineKnuthSequence() { 41 super(); 42 } 43 44 48 public InlineKnuthSequence(List list) { 49 super(list); 50 } 51 52 56 public boolean isInlineSequence() { 57 return true; 58 } 59 60 63 public boolean canAppendSequence(KnuthSequence sequence) { 64 return sequence.isInlineSequence() && !isClosed; 65 } 66 67 70 public boolean appendSequence(KnuthSequence sequence) { 71 if (!canAppendSequence(sequence)) { 72 return false; 73 } 74 ListElement lastOldElement, firstNewElement; 76 lastOldElement = getLast(); 77 firstNewElement = sequence.getElement(0); 78 if (firstNewElement.isBox() && !((KnuthElement) firstNewElement).isAuxiliary() 79 && lastOldElement.isBox() && ((KnuthElement) lastOldElement).getW() != 0) { 80 addALetterSpace(); 81 } 82 addAll(sequence); 83 return true; 84 } 85 86 89 public boolean appendSequence(KnuthSequence sequence, boolean keepTogether, 90 BreakElement breakElement) { 91 return appendSequence(sequence); 92 } 93 94 95 98 public KnuthSequence endSequence() { 99 if (!isClosed) { 100 add(new KnuthPenalty(0, -KnuthElement.INFINITE, false, null, false)); 101 isClosed = true; 102 } 103 return this; 104 } 105 106 public void addALetterSpace() { 107 KnuthBox prevBox = (KnuthBox) getLast(); 108 if (prevBox.isAuxiliary() 109 && (size() < 4 110 || !getElement(size() - 2).isGlue() 111 || !getElement(size() - 3).isPenalty() 112 || !getElement(size() - 4).isBox() 113 ) 114 ) { 115 return; 117 } 118 removeLast(); 119 LinkedList oldList = new LinkedList (); 120 if (!prevBox.isAuxiliary()) { 124 oldList.add(prevBox); 127 } else { 128 oldList.add(prevBox); 134 oldList.addFirst((KnuthGlue) removeLast()); 135 oldList.addFirst((KnuthPenalty) removeLast()); 136 oldList.addFirst((KnuthBox) removeLast()); 137 } 138 addAll(((InlineLevelLayoutManager) 142 prevBox.getLayoutManager()) 143 .addALetterSpaceTo(oldList)); 144 if ( prevBox instanceof KnuthInlineBox && ((KnuthInlineBox) prevBox).isAnchor()) { 147 KnuthInlineBox newBox = (KnuthInlineBox) getLast(); 150 newBox.setFootnoteBodyLM(((KnuthInlineBox) prevBox).getFootnoteBodyLM()); 151 } 152 } 153 154 } 155 | Popular Tags |