1 17 18 19 20 package org.apache.fop.layoutmgr.inline; 21 22 import org.apache.commons.logging.Log; 23 import org.apache.commons.logging.LogFactory; 24 import org.apache.fop.apps.FOUserAgent; 25 import org.apache.fop.fo.Constants; 26 import org.apache.fop.fo.pagination.Title; 27 import org.apache.fop.layoutmgr.AbstractBaseLayoutManager; 28 import org.apache.fop.layoutmgr.KnuthElement; 29 import org.apache.fop.layoutmgr.KnuthPossPosIter; 30 import org.apache.fop.layoutmgr.KnuthSequence; 31 import org.apache.fop.layoutmgr.LayoutContext; 32 import org.apache.fop.layoutmgr.LayoutManager; 33 import org.apache.fop.layoutmgr.PageSequenceLayoutManager; 34 import org.apache.fop.layoutmgr.Position; 35 import org.apache.fop.layoutmgr.PositionIterator; 36 import org.apache.fop.layoutmgr.SpaceSpecifier; 37 import org.apache.fop.area.Area; 38 import org.apache.fop.area.LineArea; 39 import org.apache.fop.area.inline.InlineArea; 40 41 import java.util.LinkedList ; 42 import java.util.List ; 43 import java.util.ListIterator ; 44 import java.util.ArrayList ; 45 import java.util.Iterator ; 46 import org.apache.fop.traits.MinOptMax; 47 48 import org.apache.fop.area.Block; 49 50 55 public class ContentLayoutManager extends AbstractBaseLayoutManager 56 implements InlineLevelLayoutManager { 57 58 61 private static Log log = LogFactory.getLog(ContentLayoutManager.class); 62 63 private FOUserAgent userAgent; 64 private Area holder; 65 private int stackSize; 66 private LayoutManager parentLM; 67 private InlineLevelLayoutManager childLM = null; 68 69 74 public ContentLayoutManager(Area area, LayoutManager parentLM) { 75 holder = area; 76 this.parentLM = parentLM; 77 } 78 79 87 public ContentLayoutManager(PageSequenceLayoutManager pslm, Title foTitle) { 88 this.parentLM = pslm; 90 holder = new LineArea(); 91 92 94 try { 97 LayoutManager lm = pslm.getLayoutManagerMaker().makeLayoutManager(foTitle); 98 addChildLM(lm); 99 fillArea(lm); 100 } catch (IllegalStateException e) { 101 log.warn("Title has no content"); 102 throw e; 103 } 104 } 105 106 public void initialize() { 107 } 109 110 public void fillArea(LayoutManager curLM) { 111 112 int ipd = 1000000; 113 114 LayoutContext childLC = new LayoutContext(LayoutContext.NEW_AREA); 115 childLC.setLeadingSpace(new SpaceSpecifier(false)); 116 childLC.setTrailingSpace(new SpaceSpecifier(false)); 117 childLC.setStackLimit(new MinOptMax(ipd)); 119 childLC.setRefIPD(ipd); 120 121 int lineHeight = 14000; 122 int lead = 12000; 123 int follow = 2000; 124 125 int halfLeading = (lineHeight - lead - follow) / 2; 126 int lineLead = lead + halfLeading; 128 int maxtb = follow + halfLeading; 130 int middlefollow = maxtb; 132 133 stackSize = 0; 134 135 LinkedList contentList = 136 getNextKnuthElements(childLC, Constants.EN_START); 137 ListIterator contentIter = contentList.listIterator(); 138 while (contentIter.hasNext()) { 139 KnuthElement element = (KnuthElement) contentIter.next(); 140 if (element instanceof KnuthInlineBox) { 141 KnuthInlineBox box = (KnuthInlineBox) element; 142 } 144 } 145 146 if (maxtb - lineLead > middlefollow) { 147 middlefollow = maxtb - lineLead; 148 } 149 150 LayoutContext lc = new LayoutContext(0); 151 152 lc.setFlags(LayoutContext.RESOLVE_LEADING_SPACE, true); 153 lc.setLeadingSpace(new SpaceSpecifier(false)); 154 lc.setTrailingSpace(new SpaceSpecifier(false)); 155 KnuthPossPosIter contentPosIter = 156 new KnuthPossPosIter(contentList, 0, contentList.size()); 157 curLM.addAreas(contentPosIter, lc); 158 } 159 160 public void addAreas(PositionIterator posIter, LayoutContext context) { 161 int savedIPD = ((InlineArea)holder).getIPD(); 165 LayoutContext childContext = new LayoutContext(context); 168 childContext.setIPDAdjust(0.0); 169 childLM.addAreas(posIter, childContext); 170 ((InlineArea)holder).setIPD(savedIPD); 171 } 172 173 public int getStackingSize() { 174 return stackSize; 175 } 176 177 178 public Area getParentArea(Area childArea) { 179 return holder; 180 } 181 182 185 public void addChildArea(Area childArea) { 186 holder.addChildArea(childArea); 187 } 188 189 192 public void setParent(LayoutManager lm) { 193 parentLM = lm; 194 } 195 196 197 public LayoutManager getParent() { 198 return this.parentLM; 199 } 200 201 204 public boolean isFinished() { 205 return false; 206 } 207 208 211 public void setFinished(boolean isFinished) { 212 } 214 215 218 public void resetPosition(Position position) { 219 } 221 222 225 public boolean createNextChildLMs(int pos) { 226 return false; 227 } 228 229 232 public List getChildLMs() { 233 List childLMs = new ArrayList (1); 234 childLMs.add(childLM); 235 return childLMs; 236 } 237 238 241 public void addChildLM(LayoutManager lm) { 242 if (lm == null) { 243 return; 244 } 245 lm.setParent(this); 246 childLM = (InlineLevelLayoutManager)lm; 247 log.trace(this.getClass().getName() 248 + ": Adding child LM " + lm.getClass().getName()); 249 } 250 251 254 public void addChildLMs(List newLMs) { 255 if (newLMs == null || newLMs.size() == 0) { 256 return; 257 } 258 ListIterator iter = newLMs.listIterator(); 259 while (iter.hasNext()) { 260 LayoutManager lm = (LayoutManager) iter.next(); 261 addChildLM(lm); 262 } 263 } 264 265 public LinkedList getNextKnuthElements(LayoutContext context, int alignment) { 266 LinkedList contentList = new LinkedList (); 267 LinkedList returnedList; 268 269 childLM.initialize(); 270 while (!childLM.isFinished()) { 271 returnedList = childLM.getNextKnuthElements(context, alignment); 273 274 if (returnedList != null) { 275 KnuthElement contentElement; 277 while (returnedList.size() > 0) { 278 Object obj = returnedList.removeFirst(); 279 if (obj instanceof KnuthSequence) { 280 KnuthSequence ks = (KnuthSequence)obj; 281 for (Iterator it = ks.iterator(); it.hasNext(); ) { 282 contentElement = (KnuthElement)it.next(); 283 stackSize += contentElement.getW(); 284 contentList.add(contentElement); 285 } 286 } else { 287 contentElement = (KnuthElement)obj; 288 stackSize += contentElement.getW(); 289 contentList.add(contentElement); 290 } 291 } 292 } 293 } 294 295 setFinished(true); 296 return contentList; 297 } 298 299 public List addALetterSpaceTo(List oldList) { 300 return oldList; 301 } 302 303 308 public void removeWordSpace(List oldList) { 309 log.warn(this.getClass().getName() + " should not receive a call to removeWordSpace(list)"); 311 } 312 313 public void getWordChars(StringBuffer sbChars, Position pos) { 314 } 315 316 public void hyphenate(Position pos, HyphContext hc) { 317 } 318 319 public boolean applyChanges(List oldList) { 320 return false; 321 } 322 323 public LinkedList getChangedKnuthElements(List oldList, 324 325 int alignment) { 326 return null; 327 } 328 329 public PageSequenceLayoutManager getPSLM() { 330 return parentLM.getPSLM(); 331 } 332 333 335 339 public int getContentAreaIPD() { 340 return holder.getIPD(); 341 } 342 343 347 public int getContentAreaBPD() { 348 return holder.getBPD(); 349 } 350 351 354 public boolean getGeneratesReferenceArea() { 355 return false; 356 } 357 358 361 public boolean getGeneratesBlockArea() { 362 return getGeneratesLineArea() || holder instanceof Block; 363 } 364 365 368 public boolean getGeneratesLineArea() { 369 return holder instanceof LineArea; 370 } 371 372 375 public Position notifyPos(Position pos) { 376 return pos; 377 } 378 379 } 380 381 | Popular Tags |