1 17 18 19 20 package org.apache.fop.layoutmgr.inline; 21 22 import java.util.LinkedList ; 23 import java.util.List ; 24 25 import org.apache.commons.logging.Log; 26 import org.apache.commons.logging.LogFactory; 27 import org.apache.fop.area.Area; 28 import org.apache.fop.area.inline.InlineArea; 29 import org.apache.fop.fo.FObj; 30 import org.apache.fop.fo.properties.CommonBorderPaddingBackground; 31 import org.apache.fop.layoutmgr.AbstractLayoutManager; 32 import org.apache.fop.layoutmgr.InlineKnuthSequence; 33 import org.apache.fop.layoutmgr.KnuthGlue; 34 import org.apache.fop.layoutmgr.KnuthPenalty; 35 import org.apache.fop.layoutmgr.KnuthSequence; 36 import org.apache.fop.layoutmgr.LayoutContext; 37 import org.apache.fop.layoutmgr.LeafPosition; 38 import org.apache.fop.layoutmgr.Position; 39 import org.apache.fop.layoutmgr.PositionIterator; 40 import org.apache.fop.layoutmgr.TraitSetter; 41 import org.apache.fop.traits.MinOptMax; 42 43 44 51 public abstract class LeafNodeLayoutManager extends AbstractLayoutManager 52 implements InlineLevelLayoutManager { 53 54 57 private static Log log = LogFactory.getLog(LeafNodeLayoutManager.class); 58 59 62 protected InlineArea curArea = null; 63 64 protected CommonBorderPaddingBackground commonBorderPaddingBackground = null; 65 66 protected AlignmentContext alignmentContext = null; 67 68 private MinOptMax ipd; 69 70 71 protected boolean isSomethingChanged = false; 72 73 protected AreaInfo areaInfo = null; 74 75 78 protected class AreaInfo { 79 protected short iLScount; 80 protected MinOptMax ipdArea; 81 protected boolean bHyphenated; 82 protected AlignmentContext alignmentContext; 83 84 public AreaInfo(short iLS, MinOptMax ipd, boolean bHyph, 85 AlignmentContext alignmentContext) { 86 iLScount = iLS; 87 ipdArea = ipd; 88 bHyphenated = bHyph; 89 this.alignmentContext = alignmentContext; 90 } 91 92 } 93 94 95 99 public LeafNodeLayoutManager(FObj node) { 100 super(node); 101 } 102 103 106 public LeafNodeLayoutManager() { 107 } 108 109 114 public InlineArea get(LayoutContext context) { 115 return curArea; 116 } 117 118 124 public boolean resolved() { 125 return false; 126 } 127 128 132 public void setCurrentArea(InlineArea ia) { 133 curArea = ia; 134 } 135 136 140 public void addChildArea(Area childArea) { 141 } 142 143 148 public Area getParentArea(Area childArea) { 149 return null; 150 } 151 152 156 protected void setCommonBorderPaddingBackground( 157 CommonBorderPaddingBackground commonBorderPaddingBackground) { 158 this.commonBorderPaddingBackground = commonBorderPaddingBackground; 159 } 160 161 167 protected MinOptMax getAllocationIPD(int refIPD) { 168 return new MinOptMax(curArea.getIPD()); 169 } 170 171 177 public void addAreas(PositionIterator posIter, LayoutContext context) { 178 addId(); 179 180 InlineArea area = getEffectiveArea(); 181 if (area.getAllocIPD() > 0 || area.getAllocBPD() > 0) { 182 offsetArea(area, context); 183 widthAdjustArea(area, context); 184 if (commonBorderPaddingBackground != null) { 185 TraitSetter.setBorderPaddingTraits(area, 187 commonBorderPaddingBackground, 188 false, false, this); 189 TraitSetter.addBackground(area, commonBorderPaddingBackground, this); 190 } 191 parentLM.addChildArea(area); 192 } 193 194 while (posIter.hasNext()) { 195 posIter.next(); 196 } 197 } 198 199 203 protected InlineArea getEffectiveArea() { 204 return curArea; 205 } 206 207 211 protected void addId() { 212 } 214 215 224 protected void offsetArea(InlineArea area, LayoutContext context) { 225 area.setOffset(alignmentContext.getOffset()); 226 } 227 228 236 protected AlignmentContext makeAlignmentContext(LayoutContext context) { 237 return context.getAlignmentContext(); 238 } 239 240 247 protected void widthAdjustArea(InlineArea area, LayoutContext context) { 248 double dAdjust = context.getIPDAdjust(); 249 int width = areaInfo.ipdArea.opt; 250 if (dAdjust < 0) { 251 width = (int) (width + dAdjust * (areaInfo.ipdArea.opt 252 - areaInfo.ipdArea.min)); 253 } else if (dAdjust > 0) { 254 width = (int) (width + dAdjust * (areaInfo.ipdArea.max 255 - areaInfo.ipdArea.opt)); 256 } 257 area.setIPD(width); 258 area.setAdjustment(width - areaInfo.ipdArea.opt); 259 } 260 261 262 public LinkedList getNextKnuthElements(LayoutContext context, int alignment) { 263 curArea = get(context); 264 265 if (curArea == null) { 266 setFinished(true); 267 return null; 268 } 269 270 alignmentContext = makeAlignmentContext(context); 271 272 MinOptMax ipd = getAllocationIPD(context.getRefIPD()); 273 274 areaInfo = new AreaInfo((short) 0, ipd, false, alignmentContext); 276 277 KnuthSequence seq = new InlineKnuthSequence(); 280 281 addKnuthElementsForBorderPaddingStart(seq); 282 283 seq.add(new KnuthInlineBox(areaInfo.ipdArea.opt, alignmentContext, 284 notifyPos(new LeafPosition(this, 0)), false)); 285 286 addKnuthElementsForBorderPaddingEnd(seq); 287 288 LinkedList returnList = new LinkedList (); 289 290 returnList.add(seq); 291 setFinished(true); 292 return returnList; 293 } 294 295 296 public List addALetterSpaceTo(List oldList) { 297 return oldList; 299 } 300 301 306 public void removeWordSpace(List oldList) { 307 log.warn(this.getClass().getName() + " should not receive a call to removeWordSpace(list)"); 309 } 310 311 312 public void getWordChars(StringBuffer sbChars, Position pos) { 313 } 314 315 316 public void hyphenate(Position pos, HyphContext hc) { 317 } 318 319 320 public boolean applyChanges(List oldList) { 321 setFinished(false); 322 return false; 323 } 324 325 326 public LinkedList getChangedKnuthElements(List oldList, 327 int alignment) { 328 if (isFinished()) { 329 return null; 330 } 331 332 LinkedList returnList = new LinkedList (); 333 334 addKnuthElementsForBorderPaddingStart(returnList); 335 336 returnList.add(new KnuthInlineBox(areaInfo.ipdArea.opt, areaInfo.alignmentContext, 339 notifyPos(new LeafPosition(this, 0)), true)); 340 341 addKnuthElementsForBorderPaddingEnd(returnList); 342 343 setFinished(true); 344 return returnList; 345 } 346 347 351 protected void addKnuthElementsForBorderPaddingStart(List returnList) { 352 if (commonBorderPaddingBackground != null) { 354 int ipStart = commonBorderPaddingBackground.getBorderStartWidth(false) 355 + commonBorderPaddingBackground.getPaddingStart(false, this); 356 if (ipStart > 0) { 357 returnList.add(new KnuthPenalty(0, KnuthPenalty.INFINITE, 359 false, new LeafPosition(this, -1), true)); 360 returnList.add(new KnuthGlue(ipStart, 0, 0, new LeafPosition(this, -1), true)); 361 } 362 } 363 } 364 365 369 protected void addKnuthElementsForBorderPaddingEnd(List returnList) { 370 if (commonBorderPaddingBackground != null) { 372 int ipEnd = commonBorderPaddingBackground.getBorderEndWidth(false) 373 + commonBorderPaddingBackground.getPaddingEnd(false, this); 374 if (ipEnd > 0) { 375 returnList.add(new KnuthPenalty(0, KnuthPenalty.INFINITE, 377 false, new LeafPosition(this, -1), true)); 378 returnList.add(new KnuthGlue(ipEnd, 0, 0, new LeafPosition(this, -1), true)); 379 } 380 } 381 } 382 383 } 384 385 | Popular Tags |