1 17 18 19 20 package org.apache.fop.layoutmgr.inline; 21 22 import org.apache.fop.fo.flow.Character; 23 import org.apache.fop.fonts.Font; 24 import org.apache.fop.layoutmgr.InlineKnuthSequence; 25 import org.apache.fop.layoutmgr.KnuthElement; 26 import org.apache.fop.layoutmgr.KnuthGlue; 27 import org.apache.fop.layoutmgr.KnuthPenalty; 28 import org.apache.fop.layoutmgr.KnuthSequence; 29 import org.apache.fop.layoutmgr.LayoutContext; 30 import org.apache.fop.layoutmgr.LeafPosition; 31 import org.apache.fop.layoutmgr.Position; 32 import org.apache.fop.layoutmgr.TraitSetter; 33 import org.apache.fop.area.Trait; 34 import org.apache.fop.traits.MinOptMax; 35 import org.apache.fop.traits.SpaceVal; 36 import org.apache.fop.util.CharUtilities; 37 38 import java.util.List ; 39 import java.util.LinkedList ; 40 import org.apache.fop.fo.properties.CommonBorderPaddingBackground; 41 import org.apache.fop.layoutmgr.inline.AlignmentContext; 42 43 46 public class CharacterLayoutManager extends LeafNodeLayoutManager { 47 private Character fobj; 48 private MinOptMax letterSpaceIPD; 49 private int hyphIPD; 50 private Font font; 51 private CommonBorderPaddingBackground borderProps = null; 52 53 58 public CharacterLayoutManager(Character node) { 59 super(node); 61 fobj = node; 62 } 63 64 65 public void initialize() { 66 font = fobj.getCommonFont().getFontState(fobj.getFOEventHandler().getFontInfo(), this); 67 SpaceVal ls = SpaceVal.makeLetterSpacing(fobj.getLetterSpacing()); 68 letterSpaceIPD = ls.getSpace(); 69 hyphIPD = font.getCharWidth(fobj.getCommonHyphenation().hyphenationCharacter); 70 borderProps = fobj.getCommonBorderPaddingBackground(); 71 setCommonBorderPaddingBackground(borderProps); 72 org.apache.fop.area.inline.TextArea chArea = getCharacterInlineArea(fobj); 73 chArea.setBaselineOffset(font.getAscender()); 74 setCurrentArea(chArea); 75 } 76 77 private org.apache.fop.area.inline.TextArea getCharacterInlineArea(Character node) { 78 org.apache.fop.area.inline.TextArea text 79 = new org.apache.fop.area.inline.TextArea(); 80 char ch = node.getCharacter(); 81 if (CharUtilities.isAnySpace(ch)) { 82 text.addSpace(ch, 0, CharUtilities.isAdjustableSpace(ch)); 83 } else { 84 text.addWord(String.valueOf(ch), 0); 85 } 86 TraitSetter.setProducerID(text, node.getId()); 87 TraitSetter.addTextDecoration(text, fobj.getTextDecoration()); 88 return text; 89 } 90 91 92 public LinkedList getNextKnuthElements(LayoutContext context, int alignment) { 93 MinOptMax ipd; 94 curArea = get(context); 95 KnuthSequence seq = new InlineKnuthSequence(); 96 97 if (curArea == null) { 98 setFinished(true); 99 return null; 100 } 101 102 ipd = new MinOptMax(font.getCharWidth(fobj.getCharacter())); 103 104 curArea.setIPD(ipd.opt); 105 curArea.setBPD(font.getAscender() - font.getDescender()); 106 107 TraitSetter.addFontTraits(curArea, font); 108 curArea.addTrait(Trait.COLOR, fobj.getColor()); 109 110 alignmentContext = new AlignmentContext(font 112 , font.getFontSize() 113 , fobj.getAlignmentAdjust() 114 , fobj.getAlignmentBaseline() 115 , fobj.getBaselineShift() 116 , fobj.getDominantBaseline() 117 , context.getAlignmentContext()); 118 119 addKnuthElementsForBorderPaddingStart(seq); 120 121 areaInfo = new AreaInfo((short) 0, ipd, false, alignmentContext); 123 124 if (letterSpaceIPD.min == letterSpaceIPD.max) { 126 seq.add(new KnuthInlineBox(areaInfo.ipdArea.opt, areaInfo.alignmentContext, 128 notifyPos(new LeafPosition(this, 0)), false)); 129 } else { 130 seq.add(new KnuthInlineBox(areaInfo.ipdArea.opt, areaInfo.alignmentContext, 135 notifyPos(new LeafPosition(this, 0)), false)); 136 seq.add(new KnuthPenalty(0, KnuthElement.INFINITE, false, 137 new LeafPosition(this, -1), true)); 138 seq.add(new KnuthGlue(0, 0, 0, 139 new LeafPosition(this, -1), true)); 140 seq.add(new KnuthInlineBox(0, null, 141 notifyPos(new LeafPosition(this, -1)), true)); 142 } 143 144 addKnuthElementsForBorderPaddingEnd(seq); 145 146 LinkedList returnList = new LinkedList (); 147 returnList.add(seq); 148 setFinished(true); 149 return returnList; 150 } 151 152 153 public void getWordChars(StringBuffer sbChars, Position bp) { 154 sbChars.append 155 (((org.apache.fop.area.inline.TextArea) curArea).getText()); 156 } 157 158 159 public void hyphenate(Position pos, HyphContext hc) { 160 if (hc.getNextHyphPoint() == 1) { 161 areaInfo.bHyphenated = true; 163 isSomethingChanged = true; 164 } else { 165 } 169 hc.updateOffset(1); 170 } 171 172 173 public boolean applyChanges(List oldList) { 174 setFinished(false); 175 if (isSomethingChanged) { 176 return true; 180 } else { 181 return false; 182 } 183 } 184 185 186 public LinkedList getChangedKnuthElements(List oldList, int alignment) { 187 if (isFinished()) { 188 return null; 189 } 190 191 LinkedList returnList = new LinkedList (); 192 193 addKnuthElementsForBorderPaddingStart(returnList); 194 195 if (letterSpaceIPD.min == letterSpaceIPD.max 196 || areaInfo.iLScount == 0) { 197 returnList.add(new KnuthInlineBox(areaInfo.ipdArea.opt, 199 areaInfo.alignmentContext, 200 notifyPos(new LeafPosition(this, 0)), false)); 201 if (areaInfo.bHyphenated) { 202 returnList.add 203 (new KnuthPenalty(hyphIPD, KnuthPenalty.FLAGGED_PENALTY, true, 204 new LeafPosition(this, -1), false)); 205 } 206 } else { 207 returnList.add 209 (new KnuthInlineBox(areaInfo.ipdArea.opt 210 - areaInfo.iLScount * letterSpaceIPD.opt, 211 areaInfo.alignmentContext, 212 notifyPos(new LeafPosition(this, 0)), false)); 213 returnList.add(new KnuthPenalty(0, KnuthElement.INFINITE, false, 214 new LeafPosition(this, -1), true)); 215 returnList.add 216 (new KnuthGlue(areaInfo.iLScount * letterSpaceIPD.opt, 217 areaInfo.iLScount * letterSpaceIPD.max - letterSpaceIPD.opt, 218 areaInfo.iLScount * letterSpaceIPD.opt - letterSpaceIPD.min, 219 new LeafPosition(this, -1), true)); 220 returnList.add(new KnuthInlineBox(0, null, 221 notifyPos(new LeafPosition(this, -1)), true)); 222 if (areaInfo.bHyphenated) { 223 returnList.add 224 (new KnuthPenalty(hyphIPD, KnuthPenalty.FLAGGED_PENALTY, true, 225 new LeafPosition(this, -1), false)); 226 } 227 } 228 229 addKnuthElementsForBorderPaddingEnd(returnList); 230 231 setFinished(true); 232 return returnList; 233 } 234 235 236 protected void addId() { 237 getPSLM().addIDToPage(fobj.getId()); 238 } 239 240 } 241 242 | Popular Tags |