1 17 18 19 20 package org.apache.fop.layoutmgr.inline; 21 22 import java.util.LinkedList ; 23 import java.util.Iterator ; 24 import java.util.List ; 25 import java.util.ListIterator ; 26 import java.util.HashMap ; 27 28 import org.apache.fop.fo.FObj; 29 import org.apache.fop.fo.properties.SpaceProperty; 30 import org.apache.fop.layoutmgr.AbstractLayoutManager; 31 import org.apache.fop.layoutmgr.KnuthElement; 32 import org.apache.fop.layoutmgr.LayoutContext; 33 import org.apache.fop.layoutmgr.LayoutManager; 34 import org.apache.fop.layoutmgr.NonLeafPosition; 35 import org.apache.fop.layoutmgr.Position; 36 import org.apache.fop.layoutmgr.PositionIterator; 37 import org.apache.fop.area.Area; 38 import org.apache.fop.area.inline.Space; 39 import org.apache.fop.traits.MinOptMax; 40 41 46 public class InlineStackingLayoutManager extends AbstractLayoutManager 47 implements InlineLevelLayoutManager { 48 49 50 protected static class StackingIter extends PositionIterator { 51 52 StackingIter(Iterator parentIter) { 53 super(parentIter); 54 } 55 56 protected LayoutManager getLM(Object nextObj) { 57 return ((Position) nextObj).getLM(); 58 } 59 60 protected Position getPos(Object nextObj) { 61 return ((Position) nextObj); 62 } 63 } 64 65 66 69 private MinOptMax allocIPD = new MinOptMax(0); 70 71 74 protected MinOptMax extraBPD; 75 76 private Area currentArea; 78 80 81 protected LayoutContext childLC; 82 83 private boolean bAreaCreated = false; 84 85 87 88 private HashMap hmPrevIPD = new HashMap (); 89 90 97 protected InlineStackingLayoutManager(FObj node) { 98 super(node); 99 extraBPD = new MinOptMax(0); 100 } 101 102 107 public void setLMiter(ListIterator iter) { 108 childLMiter = iter; 109 } 110 111 118 protected MinOptMax getExtraIPD(boolean bNotFirst, boolean bNotLast) { 119 return new MinOptMax(0); 120 } 121 122 123 128 protected boolean hasLeadingFence(boolean bNotFirst) { 129 return false; 130 } 131 132 137 protected boolean hasTrailingFence(boolean bNotLast) { 138 return false; 139 } 140 141 145 protected SpaceProperty getSpaceStart() { 146 return null; 147 } 148 149 153 protected SpaceProperty getSpaceEnd() { 154 return null; 155 } 156 157 162 public void resetPosition(Position prevPos) { 163 if (prevPos != null) { 164 if (prevPos.getLM() != this) { 166 } 170 Position childPos = prevPos.getPosition(); 172 reset(childPos); 173 180 } else { 181 reset(prevPos); 185 bAreaCreated = false; 187 } 188 } 191 192 197 protected MinOptMax getPrevIPD(LayoutManager lm) { 198 return (MinOptMax) hmPrevIPD.get(lm); 199 } 200 201 204 protected void clearPrevIPD() { 205 hmPrevIPD.clear(); 206 } 207 208 212 protected void addId() { 213 } 215 216 220 protected Area getCurrentArea() { 221 return currentArea; 222 } 223 224 228 protected void setCurrentArea(Area area) { 229 currentArea = area; 230 } 231 232 237 protected void setTraits(boolean bNotFirst, boolean bNotLast) { 238 } 239 240 244 protected void setChildContext(LayoutContext lc) { 245 childLC = lc; 246 } 247 248 252 protected LayoutContext getContext() { 253 return childLC; 254 } 255 256 262 protected void addSpace(Area parentArea, MinOptMax spaceRange, 263 double dSpaceAdjust) { 264 if (spaceRange != null) { 265 int iAdjust = spaceRange.opt; 266 if (dSpaceAdjust > 0.0) { 267 iAdjust += (int) ((double) (spaceRange.max 269 - spaceRange.opt) * dSpaceAdjust); 270 } else if (dSpaceAdjust < 0.0) { 271 iAdjust += (int) ((double) (spaceRange.opt 273 - spaceRange.min) * dSpaceAdjust); 274 } 275 if (iAdjust != 0) { 276 Space ls = new Space(); 278 ls.setIPD(iAdjust); 279 parentArea.addChildArea(ls); 280 } 281 } 282 } 283 284 285 public List addALetterSpaceTo(List oldList) { 286 288 ListIterator oldListIterator = oldList.listIterator(); 289 KnuthElement element = null; 290 while (oldListIterator.hasNext()) { 292 element = (KnuthElement) oldListIterator.next(); 293 element.setPosition(((NonLeafPosition)element.getPosition()).getPosition()); 294 } 295 296 InlineLevelLayoutManager LM = 299 (InlineLevelLayoutManager) element.getLayoutManager(); 300 if (LM != null) { 301 oldList = LM.addALetterSpaceTo(oldList); 302 } 303 oldListIterator = oldList.listIterator(); 305 while (oldListIterator.hasNext()) { 306 element = (KnuthElement) oldListIterator.next(); 307 element.setPosition(notifyPos(new NonLeafPosition(this, element.getPosition()))); 308 } 309 310 return oldList; 311 } 312 313 320 public void removeWordSpace(List oldList) { 321 ListIterator oldListIterator = oldList.listIterator(); 322 KnuthElement element = null; 323 while (oldListIterator.hasNext()) { 325 element = (KnuthElement) oldListIterator.next(); 326 element.setPosition(((NonLeafPosition)element.getPosition()).getPosition()); 327 } 328 329 ((InlineLevelLayoutManager) 330 element.getLayoutManager()).removeWordSpace(oldList); 331 332 } 333 334 335 public void getWordChars(StringBuffer sbChars, Position pos) { 336 Position newPos = ((NonLeafPosition) pos).getPosition(); 337 ((InlineLevelLayoutManager) 338 newPos.getLM()).getWordChars(sbChars, newPos); 339 } 340 341 342 public void hyphenate(Position pos, HyphContext hc) { 343 Position newPos = ((NonLeafPosition) pos).getPosition(); 344 ((InlineLevelLayoutManager) 345 newPos.getLM()).hyphenate(newPos, hc); 346 } 347 348 349 public boolean applyChanges(List oldList) { 350 ListIterator oldListIterator = oldList.listIterator(); 352 KnuthElement oldElement; 353 while (oldListIterator.hasNext()) { 354 oldElement = (KnuthElement) oldListIterator.next(); 355 oldElement.setPosition 356 (((NonLeafPosition) oldElement.getPosition()).getPosition()); 357 } 358 oldListIterator = oldList.listIterator(); 360 361 InlineLevelLayoutManager prevLM = null; 362 InlineLevelLayoutManager currLM; 363 int fromIndex = 0; 364 365 boolean bSomethingChanged = false; 366 while (oldListIterator.hasNext()) { 367 oldElement = (KnuthElement) oldListIterator.next(); 368 currLM = (InlineLevelLayoutManager) oldElement.getLayoutManager(); 369 if (prevLM == null) { 371 prevLM = currLM; 372 } 373 374 if (currLM != prevLM || !oldListIterator.hasNext()) { 375 if (prevLM == this || currLM == this) { 376 prevLM = currLM; 377 } else if (oldListIterator.hasNext()) { 378 bSomethingChanged 379 = prevLM.applyChanges(oldList.subList(fromIndex 380 , oldListIterator.previousIndex())) 381 || bSomethingChanged; 382 prevLM = currLM; 383 fromIndex = oldListIterator.previousIndex(); 384 } else if (currLM == prevLM) { 385 bSomethingChanged 386 = prevLM.applyChanges(oldList.subList(fromIndex, oldList.size())) 387 || bSomethingChanged; 388 } else { 389 bSomethingChanged 390 = prevLM.applyChanges(oldList.subList(fromIndex 391 , oldListIterator.previousIndex())) 392 || bSomethingChanged; 393 if (currLM != null) { 394 bSomethingChanged 395 = currLM.applyChanges(oldList.subList(oldListIterator.previousIndex() 396 , oldList.size())) 397 || bSomethingChanged; 398 } 399 } 400 } 401 } 402 403 oldListIterator = oldList.listIterator(); 405 while (oldListIterator.hasNext()) { 406 oldElement = (KnuthElement) oldListIterator.next(); 407 oldElement.setPosition 408 (notifyPos(new NonLeafPosition(this, oldElement.getPosition()))); 409 } 410 return bSomethingChanged; 411 } 412 413 416 public LinkedList getChangedKnuthElements(List oldList, int alignment) { 417 ListIterator oldListIterator = oldList.listIterator(); 419 KnuthElement oldElement; 420 while (oldListIterator.hasNext()) { 421 oldElement = (KnuthElement) oldListIterator.next(); 422 oldElement.setPosition 423 (((NonLeafPosition) oldElement.getPosition()).getPosition()); 424 } 425 oldListIterator = oldList.listIterator(); 427 428 KnuthElement returnedElement; 429 LinkedList returnedList = new LinkedList (); 430 LinkedList returnList = new LinkedList (); 431 InlineLevelLayoutManager prevLM = null; 432 InlineLevelLayoutManager currLM; 433 int fromIndex = 0; 434 435 while (oldListIterator.hasNext()) { 436 oldElement = (KnuthElement) oldListIterator.next(); 437 currLM = (InlineLevelLayoutManager) oldElement.getLayoutManager(); 438 if (prevLM == null) { 439 prevLM = currLM; 440 } 441 442 if (currLM != prevLM || !oldListIterator.hasNext()) { 443 if (oldListIterator.hasNext()) { 444 returnedList.addAll 445 (prevLM.getChangedKnuthElements 446 (oldList.subList(fromIndex, 447 oldListIterator.previousIndex()), 448 alignment)); 449 prevLM = currLM; 450 fromIndex = oldListIterator.previousIndex(); 451 } else if (currLM == prevLM) { 452 returnedList.addAll 453 (prevLM.getChangedKnuthElements 454 (oldList.subList(fromIndex, oldList.size()), 455 alignment)); 456 } else { 457 returnedList.addAll 458 (prevLM.getChangedKnuthElements 459 (oldList.subList(fromIndex, 460 oldListIterator.previousIndex()), 461 alignment)); 462 if (currLM != null) { 463 returnedList.addAll 464 (currLM.getChangedKnuthElements 465 (oldList.subList(oldListIterator.previousIndex(), 466 oldList.size()), 467 alignment)); 468 } 469 } 470 } 471 } 472 473 ListIterator listIter = returnedList.listIterator(); 475 while (listIter.hasNext()) { 476 returnedElement = (KnuthElement) listIter.next(); 477 returnedElement.setPosition 478 (notifyPos(new NonLeafPosition(this, returnedElement.getPosition()))); 479 returnList.add(returnedElement); 480 } 481 return returnList; 482 } 483 } 484 | Popular Tags |