You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ListItemLayoutManager.java 26KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702
  1. /*
  2. * Copyright 1999-2005 The Apache Software Foundation.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. /* $Id$ */
  17. package org.apache.fop.layoutmgr.list;
  18. import org.apache.fop.fo.flow.ListItem;
  19. import org.apache.fop.fo.flow.ListItemBody;
  20. import org.apache.fop.fo.flow.ListItemLabel;
  21. import org.apache.fop.layoutmgr.BlockLevelLayoutManager;
  22. import org.apache.fop.layoutmgr.BlockStackingLayoutManager;
  23. import org.apache.fop.layoutmgr.BreakElement;
  24. import org.apache.fop.layoutmgr.ConditionalElementListener;
  25. import org.apache.fop.layoutmgr.ElementListObserver;
  26. import org.apache.fop.layoutmgr.ElementListUtils;
  27. import org.apache.fop.layoutmgr.LayoutManager;
  28. import org.apache.fop.layoutmgr.LayoutContext;
  29. import org.apache.fop.layoutmgr.PositionIterator;
  30. import org.apache.fop.layoutmgr.Position;
  31. import org.apache.fop.layoutmgr.NonLeafPosition;
  32. import org.apache.fop.layoutmgr.RelSide;
  33. import org.apache.fop.layoutmgr.SpaceResolver;
  34. import org.apache.fop.layoutmgr.TraitSetter;
  35. import org.apache.fop.layoutmgr.KnuthElement;
  36. import org.apache.fop.layoutmgr.KnuthBox;
  37. import org.apache.fop.layoutmgr.KnuthPenalty;
  38. import org.apache.fop.layoutmgr.KnuthPossPosIter;
  39. import org.apache.fop.area.Area;
  40. import org.apache.fop.area.Block;
  41. import org.apache.fop.traits.MinOptMax;
  42. import org.apache.fop.traits.SpaceVal;
  43. import java.util.ArrayList;
  44. import java.util.List;
  45. import java.util.LinkedList;
  46. import java.util.ListIterator;
  47. /**
  48. * LayoutManager for a list-item FO.
  49. * The list item contains a list item label and a list item body.
  50. */
  51. public class ListItemLayoutManager extends BlockStackingLayoutManager
  52. implements ConditionalElementListener {
  53. private ListItemContentLayoutManager label;
  54. private ListItemContentLayoutManager body;
  55. private Block curBlockArea = null;
  56. private LinkedList labelList = null;
  57. private LinkedList bodyList = null;
  58. private int listItemHeight;
  59. private boolean discardBorderBefore;
  60. private boolean discardBorderAfter;
  61. private boolean discardPaddingBefore;
  62. private boolean discardPaddingAfter;
  63. private MinOptMax effSpaceBefore;
  64. private MinOptMax effSpaceAfter;
  65. private boolean keepWithNextPendingOnLabel;
  66. private boolean keepWithNextPendingOnBody;
  67. private class ListItemPosition extends Position {
  68. private int iLabelFirstIndex;
  69. private int iLabelLastIndex;
  70. private int iBodyFirstIndex;
  71. private int iBodyLastIndex;
  72. public ListItemPosition(LayoutManager lm, int labelFirst, int labelLast,
  73. int bodyFirst, int bodyLast) {
  74. super(lm);
  75. iLabelFirstIndex = labelFirst;
  76. iLabelLastIndex = labelLast;
  77. iBodyFirstIndex = bodyFirst;
  78. iBodyLastIndex = bodyLast;
  79. }
  80. public int getLabelFirstIndex() {
  81. return iLabelFirstIndex;
  82. }
  83. public int getLabelLastIndex() {
  84. return iLabelLastIndex;
  85. }
  86. public int getBodyFirstIndex() {
  87. return iBodyFirstIndex;
  88. }
  89. public int getBodyLastIndex() {
  90. return iBodyLastIndex;
  91. }
  92. /** @see java.lang.Object#toString() */
  93. public String toString() {
  94. StringBuffer sb = new StringBuffer("ListItemPosition:");
  95. sb.append(getIndex()).append("(");
  96. sb.append("label:").append(iLabelFirstIndex).append("-").append(iLabelLastIndex);
  97. sb.append(" body:").append(iBodyFirstIndex).append("-").append(iBodyLastIndex);
  98. sb.append(")");
  99. return sb.toString();
  100. }
  101. }
  102. /**
  103. * Create a new list item layout manager.
  104. * @param node list-item to create the layout manager for
  105. */
  106. public ListItemLayoutManager(ListItem node) {
  107. super(node);
  108. setLabel(node.getLabel());
  109. setBody(node.getBody());
  110. }
  111. /**
  112. * Convenience method.
  113. * @return the ListBlock node
  114. */
  115. protected ListItem getListItemFO() {
  116. return (ListItem)fobj;
  117. }
  118. /**
  119. * Create a LM for the fo:list-item-label object
  120. * @param node the fo:list-item-label FO
  121. */
  122. public void setLabel(ListItemLabel node) {
  123. label = new ListItemContentLayoutManager(node);
  124. label.setParent(this);
  125. }
  126. /**
  127. * Create a LM for the fo:list-item-body object
  128. * @param node the fo:list-item-body FO
  129. */
  130. public void setBody(ListItemBody node) {
  131. body = new ListItemContentLayoutManager(node);
  132. body.setParent(this);
  133. }
  134. /** @see org.apache.fop.layoutmgr.LayoutManager#initialize() */
  135. public void initialize() {
  136. foSpaceBefore = new SpaceVal(
  137. getListItemFO().getCommonMarginBlock().spaceBefore, this).getSpace();
  138. foSpaceAfter = new SpaceVal(
  139. getListItemFO().getCommonMarginBlock().spaceAfter, this).getSpace();
  140. }
  141. private void resetSpaces() {
  142. this.discardBorderBefore = false;
  143. this.discardBorderAfter = false;
  144. this.discardPaddingBefore = false;
  145. this.discardPaddingAfter = false;
  146. this.effSpaceBefore = foSpaceBefore;
  147. this.effSpaceAfter = foSpaceAfter;
  148. }
  149. private int getIPIndents() {
  150. int iIndents = 0;
  151. iIndents += getListItemFO().getCommonMarginBlock().startIndent.getValue(this);
  152. iIndents += getListItemFO().getCommonMarginBlock().endIndent.getValue(this);
  153. return iIndents;
  154. }
  155. /** @see org.apache.fop.layoutmgr.LayoutManager */
  156. public LinkedList getNextKnuthElements(LayoutContext context, int alignment) {
  157. referenceIPD = context.getRefIPD();
  158. LayoutContext childLC;
  159. LinkedList returnList = new LinkedList();
  160. if (!bSpaceBeforeServed) {
  161. addKnuthElementsForSpaceBefore(returnList, alignment);
  162. bSpaceBeforeServed = true;
  163. }
  164. //Spaces, border and padding to be repeated at each break
  165. addPendingMarks(context);
  166. // label
  167. childLC = new LayoutContext(0);
  168. childLC.setRefIPD(context.getRefIPD());
  169. label.initialize();
  170. labelList = label.getNextKnuthElements(childLC, alignment);
  171. //Space resolution as if the contents were placed in a new reference area
  172. //(see 6.8.3, XSL 1.0, section on Constraints, last paragraph)
  173. SpaceResolver.resolveElementList(labelList);
  174. ElementListObserver.observe(labelList, "list-item-label", label.getPartFO().getId());
  175. if (childLC.isKeepWithPreviousPending()) {
  176. context.setFlags(LayoutContext.KEEP_WITH_PREVIOUS_PENDING);
  177. }
  178. this.keepWithNextPendingOnLabel = childLC.isKeepWithNextPending();
  179. // body
  180. childLC = new LayoutContext(0);
  181. childLC.setRefIPD(context.getRefIPD());
  182. body.initialize();
  183. bodyList = body.getNextKnuthElements(childLC, alignment);
  184. //Space resolution as if the contents were placed in a new reference area
  185. //(see 6.8.3, XSL 1.0, section on Constraints, last paragraph)
  186. SpaceResolver.resolveElementList(bodyList);
  187. ElementListObserver.observe(bodyList, "list-item-body", body.getPartFO().getId());
  188. if (childLC.isKeepWithPreviousPending()) {
  189. context.setFlags(LayoutContext.KEEP_WITH_PREVIOUS_PENDING);
  190. }
  191. this.keepWithNextPendingOnBody = childLC.isKeepWithNextPending();
  192. // create a combined list
  193. LinkedList returnedList = getCombinedKnuthElementsForListItem(labelList, bodyList, context);
  194. // "wrap" the Position inside each element
  195. wrapPositionElements(returnedList, returnList, true);
  196. addKnuthElementsForSpaceAfter(returnList, alignment);
  197. if (keepWithNextPendingOnLabel || keepWithNextPendingOnBody || mustKeepWithNext()) {
  198. context.setFlags(LayoutContext.KEEP_WITH_NEXT_PENDING);
  199. }
  200. if (mustKeepWithPrevious()) {
  201. context.setFlags(LayoutContext.KEEP_WITH_PREVIOUS_PENDING);
  202. }
  203. setFinished(true);
  204. resetSpaces();
  205. return returnList;
  206. }
  207. private LinkedList getCombinedKnuthElementsForListItem(LinkedList labelElements,
  208. LinkedList bodyElements,
  209. LayoutContext context) {
  210. //Copy elements to array lists to improve element access performance
  211. List[] elementLists = {new ArrayList(labelElements),
  212. new ArrayList(bodyElements)};
  213. int[] fullHeights = {ElementListUtils.calcContentLength(elementLists[0]),
  214. ElementListUtils.calcContentLength(elementLists[1])};
  215. int[] partialHeights = {0, 0};
  216. int[] start = {-1, -1};
  217. int[] end = {-1, -1};
  218. int totalHeight = Math.max(fullHeights[0], fullHeights[1]);
  219. int step;
  220. int addedBoxHeight = 0;
  221. boolean keepWithNextActive = false;
  222. LinkedList returnList = new LinkedList();
  223. while ((step = getNextStep(elementLists, start, end, partialHeights))
  224. > 0) {
  225. if (end[0] + 1 == elementLists[0].size()) {
  226. if (keepWithNextPendingOnLabel) {
  227. keepWithNextActive = true;
  228. }
  229. }
  230. if (end[1] + 1 == elementLists[1].size()) {
  231. if (keepWithNextPendingOnBody) {
  232. keepWithNextActive = true;
  233. }
  234. }
  235. // compute penalty height and box height
  236. int penaltyHeight = step
  237. + getMaxRemainingHeight(fullHeights, partialHeights)
  238. - totalHeight;
  239. int boxHeight = step - addedBoxHeight - penaltyHeight;
  240. // add the new elements
  241. addedBoxHeight += boxHeight;
  242. ListItemPosition stepPosition = new ListItemPosition(this,
  243. start[0], end[0], start[1], end[1]);
  244. returnList.add(new KnuthBox(boxHeight, stepPosition, false));
  245. if (addedBoxHeight < totalHeight) {
  246. int p = 0;
  247. if (keepWithNextActive || mustKeepTogether()) {
  248. p = KnuthPenalty.INFINITE;
  249. }
  250. //returnList.add(new KnuthPenalty(penaltyHeight, p, false, stepPosition, false));
  251. returnList.add(new BreakElement(stepPosition, penaltyHeight, p, 0, context));
  252. }
  253. }
  254. return returnList;
  255. }
  256. private int getNextStep(List[] elementLists, int[] start, int[] end, int[] partialHeights) {
  257. // backup of partial heights
  258. int[] backupHeights = {partialHeights[0], partialHeights[1]};
  259. // set starting points
  260. start[0] = end[0] + 1;
  261. start[1] = end[1] + 1;
  262. // get next possible sequence for label and body
  263. int seqCount = 0;
  264. for (int i = 0; i < start.length; i++) {
  265. while (end[i] + 1 < elementLists[i].size()) {
  266. end[i]++;
  267. KnuthElement el = (KnuthElement)elementLists[i].get(end[i]);
  268. if (el.isPenalty()) {
  269. if (el.getP() < KnuthElement.INFINITE) {
  270. //First legal break point
  271. break;
  272. }
  273. } else if (el.isGlue()) {
  274. if (end[i] > 0) {
  275. KnuthElement prev = (KnuthElement)elementLists[i].get(end[i] - 1);
  276. if (prev.isBox()) {
  277. //Second legal break point
  278. break;
  279. }
  280. }
  281. partialHeights[i] += el.getW();
  282. } else {
  283. partialHeights[i] += el.getW();
  284. }
  285. }
  286. if (end[i] < start[i]) {
  287. partialHeights[i] = backupHeights[i];
  288. } else {
  289. seqCount++;
  290. }
  291. }
  292. if (seqCount == 0) {
  293. return 0;
  294. }
  295. // determine next step
  296. int step;
  297. if (backupHeights[0] == 0 && backupHeights[1] == 0) {
  298. // this is the first step: choose the maximum increase, so that
  299. // the smallest area in the first page will contain at least
  300. // a label area and a body area
  301. step = Math.max((end[0] >= start[0] ? partialHeights[0] : Integer.MIN_VALUE),
  302. (end[1] >= start[1] ? partialHeights[1] : Integer.MIN_VALUE));
  303. } else {
  304. // this is not the first step: choose the minimum increase
  305. step = Math.min((end[0] >= start[0] ? partialHeights[0] : Integer.MAX_VALUE),
  306. (end[1] >= start[1] ? partialHeights[1] : Integer.MAX_VALUE));
  307. }
  308. // reset bigger-than-step sequences
  309. for (int i = 0; i < partialHeights.length; i++) {
  310. if (partialHeights[i] > step) {
  311. partialHeights[i] = backupHeights[i];
  312. end[i] = start[i] - 1;
  313. }
  314. }
  315. return step;
  316. }
  317. private int getMaxRemainingHeight(int[] fullHeights, int[] partialHeights) {
  318. return Math.max(fullHeights[0] - partialHeights[0],
  319. fullHeights[1] - partialHeights[1]);
  320. }
  321. /**
  322. * @see org.apache.fop.layoutmgr.LayoutManager#getChangedKnuthElements(java.util.List, int)
  323. */
  324. public LinkedList getChangedKnuthElements(List oldList, int alignment) {
  325. //log.debug(" LILM.getChanged> label");
  326. // label
  327. labelList = label.getChangedKnuthElements(labelList, alignment);
  328. //log.debug(" LILM.getChanged> body");
  329. // body
  330. // "unwrap" the Positions stored in the elements
  331. ListIterator oldListIterator = oldList.listIterator();
  332. KnuthElement oldElement = null;
  333. while (oldListIterator.hasNext()) {
  334. oldElement = (KnuthElement)oldListIterator.next();
  335. Position innerPosition = ((NonLeafPosition) oldElement.getPosition()).getPosition();
  336. //System.out.println(" BLM> unwrapping: " + (oldElement.isBox()
  337. // ? "box " : (oldElement.isGlue() ? "glue " : "penalty"))
  338. // + " creato da " + oldElement.getLayoutManager().getClass().getName());
  339. //System.out.println(" BLM> unwrapping: "
  340. // + oldElement.getPosition().getClass().getName());
  341. if (innerPosition != null) {
  342. // oldElement was created by a descendant of this BlockLM
  343. oldElement.setPosition(innerPosition);
  344. } else {
  345. // thisElement was created by this BlockLM
  346. // modify its position in order to recognize it was not created
  347. // by a child
  348. oldElement.setPosition(new Position(this));
  349. }
  350. }
  351. LinkedList returnedList = body.getChangedKnuthElements(oldList, alignment);
  352. // "wrap" the Position inside each element
  353. LinkedList tempList = returnedList;
  354. KnuthElement tempElement;
  355. returnedList = new LinkedList();
  356. ListIterator listIter = tempList.listIterator();
  357. while (listIter.hasNext()) {
  358. tempElement = (KnuthElement)listIter.next();
  359. tempElement.setPosition(new NonLeafPosition(this, tempElement.getPosition()));
  360. returnedList.add(tempElement);
  361. }
  362. return returnedList;
  363. }
  364. /**
  365. * Add the areas for the break points.
  366. * This sets the offset of each cell as it is added.
  367. *
  368. * @param parentIter the position iterator
  369. * @param layoutContext the layout context for adding areas
  370. */
  371. public void addAreas(PositionIterator parentIter,
  372. LayoutContext layoutContext) {
  373. getParentArea(null);
  374. // if adjusted space before
  375. //double adjust = layoutContext.getSpaceAdjust();
  376. //addBlockSpacing(adjust, foSpaceBefore);
  377. //addBlockSpacing(adjust, effSpaceBefore);
  378. //foSpaceBefore = null;
  379. getPSLM().addIDToPage(getListItemFO().getId());
  380. LayoutContext lc = new LayoutContext(0);
  381. Position firstPos = null;
  382. Position lastPos = null;
  383. // "unwrap" the NonLeafPositions stored in parentIter
  384. LinkedList positionList = new LinkedList();
  385. Position pos;
  386. while (parentIter.hasNext()) {
  387. pos = (Position) parentIter.next();
  388. if (pos.getIndex() >= 0) {
  389. if (firstPos == null) {
  390. firstPos = pos;
  391. }
  392. lastPos = pos;
  393. }
  394. if (pos instanceof NonLeafPosition && pos.getPosition() != null) {
  395. // pos contains a ListItemPosition created by this ListBlockLM
  396. positionList.add(((NonLeafPosition) pos).getPosition());
  397. }
  398. }
  399. if (markers != null) {
  400. getCurrentPV().addMarkers(markers, true, isFirst(firstPos), isLast(lastPos));
  401. }
  402. // use the first and the last ListItemPosition to determine the
  403. // corresponding indexes in the original labelList and bodyList
  404. int labelFirstIndex = ((ListItemPosition) positionList.getFirst()).getLabelFirstIndex();
  405. int labelLastIndex = ((ListItemPosition) positionList.getLast()).getLabelLastIndex();
  406. int bodyFirstIndex = ((ListItemPosition) positionList.getFirst()).getBodyFirstIndex();
  407. int bodyLastIndex = ((ListItemPosition) positionList.getLast()).getBodyLastIndex();
  408. int lastBreak;
  409. //Determine last break if any
  410. lastBreak = labelFirstIndex - 1;
  411. while (lastBreak >= 0) {
  412. KnuthElement el = (KnuthElement)labelList.get(lastBreak);
  413. if (el.isPenalty() && el.getP() < KnuthElement.INFINITE) {
  414. break;
  415. }
  416. lastBreak--;
  417. }
  418. SpaceResolver.performConditionalsNotification(labelList,
  419. labelFirstIndex, labelLastIndex, lastBreak);
  420. //Determine last break if any
  421. lastBreak = bodyFirstIndex - 1;
  422. while (lastBreak >= 0) {
  423. KnuthElement el = (KnuthElement)bodyList.get(lastBreak);
  424. if (el.isPenalty() && el.getP() < KnuthElement.INFINITE) {
  425. break;
  426. }
  427. lastBreak--;
  428. }
  429. SpaceResolver.performConditionalsNotification(bodyList,
  430. bodyFirstIndex, bodyLastIndex, lastBreak);
  431. // add label areas
  432. if (labelFirstIndex <= labelLastIndex) {
  433. KnuthPossPosIter labelIter = new KnuthPossPosIter(labelList,
  434. labelFirstIndex, labelLastIndex + 1);
  435. lc.setFlags(LayoutContext.FIRST_AREA, layoutContext.isFirstArea());
  436. lc.setFlags(LayoutContext.LAST_AREA, layoutContext.isLastArea());
  437. // set the space adjustment ratio
  438. lc.setSpaceAdjust(layoutContext.getSpaceAdjust());
  439. // TO DO: use the right stack limit for the label
  440. lc.setStackLimit(layoutContext.getStackLimit());
  441. label.addAreas(labelIter, lc);
  442. }
  443. // reset the area bpd after adding the label areas and before adding the body areas
  444. int savedBPD = 0;
  445. if (labelFirstIndex <= labelLastIndex
  446. && bodyFirstIndex <= bodyLastIndex) {
  447. savedBPD = curBlockArea.getBPD();
  448. curBlockArea.setBPD(0);
  449. }
  450. // add body areas
  451. if (bodyFirstIndex <= bodyLastIndex) {
  452. KnuthPossPosIter bodyIter = new KnuthPossPosIter(bodyList,
  453. bodyFirstIndex, bodyLastIndex + 1);
  454. lc.setFlags(LayoutContext.FIRST_AREA, layoutContext.isFirstArea());
  455. lc.setFlags(LayoutContext.LAST_AREA, layoutContext.isLastArea());
  456. // set the space adjustment ratio
  457. lc.setSpaceAdjust(layoutContext.getSpaceAdjust());
  458. // TO DO: use the right stack limit for the body
  459. lc.setStackLimit(layoutContext.getStackLimit());
  460. body.addAreas(bodyIter, lc);
  461. }
  462. // after adding body areas, set the maximum area bpd
  463. if (curBlockArea.getBPD() < savedBPD) {
  464. curBlockArea.setBPD(savedBPD);
  465. }
  466. if (markers != null) {
  467. getCurrentPV().addMarkers(markers, false, isFirst(firstPos), isLast(lastPos));
  468. }
  469. // We are done with this area add the background
  470. TraitSetter.addBackground(curBlockArea,
  471. getListItemFO().getCommonBorderPaddingBackground(),
  472. this);
  473. TraitSetter.addSpaceBeforeAfter(curBlockArea, layoutContext.getSpaceAdjust(),
  474. effSpaceBefore, effSpaceAfter);
  475. flush();
  476. // if adjusted space after
  477. //addBlockSpacing(adjust, foSpaceAfter);
  478. //addBlockSpacing(adjust, effSpaceAfter);
  479. curBlockArea = null;
  480. resetSpaces();
  481. }
  482. /**
  483. * Get the height of the list item after adjusting.
  484. * Should only be called after adding the list item areas.
  485. *
  486. * @return the height of this list item after adjustment
  487. */
  488. public int getListItemHeight() {
  489. return listItemHeight;
  490. }
  491. /**
  492. * Return an Area which can contain the passed childArea. The childArea
  493. * may not yet have any content, but it has essential traits set.
  494. * In general, if the LayoutManager already has an Area it simply returns
  495. * it. Otherwise, it makes a new Area of the appropriate class.
  496. * It gets a parent area for its area by calling its parent LM.
  497. * Finally, based on the dimensions of the parent area, it initializes
  498. * its own area. This includes setting the content IPD and the maximum
  499. * BPD.
  500. *
  501. * @param childArea the child area
  502. * @return the parent are for the child
  503. */
  504. public Area getParentArea(Area childArea) {
  505. if (curBlockArea == null) {
  506. curBlockArea = new Block();
  507. // Set up dimensions
  508. /*Area parentArea =*/ parentLM.getParentArea(curBlockArea);
  509. // set traits
  510. TraitSetter.setProducerID(curBlockArea, getListItemFO().getId());
  511. TraitSetter.addBorders(curBlockArea,
  512. getListItemFO().getCommonBorderPaddingBackground(),
  513. discardBorderBefore, discardBorderAfter, false, false, this);
  514. TraitSetter.addPadding(curBlockArea,
  515. getListItemFO().getCommonBorderPaddingBackground(),
  516. discardPaddingBefore, discardPaddingAfter, false, false, this);
  517. TraitSetter.addMargins(curBlockArea,
  518. getListItemFO().getCommonBorderPaddingBackground(),
  519. getListItemFO().getCommonMarginBlock(), this);
  520. TraitSetter.addBreaks(curBlockArea,
  521. getListItemFO().getBreakBefore(),
  522. getListItemFO().getBreakAfter());
  523. int contentIPD = referenceIPD - getIPIndents();
  524. curBlockArea.setIPD(contentIPD);
  525. setCurrentArea(curBlockArea);
  526. }
  527. return curBlockArea;
  528. }
  529. /**
  530. * Add the child.
  531. * Rows return the areas returned by the child elements.
  532. * This simply adds the area to the parent layout manager.
  533. *
  534. * @param childArea the child area
  535. */
  536. public void addChildArea(Area childArea) {
  537. if (curBlockArea != null) {
  538. curBlockArea.addBlock((Block) childArea);
  539. }
  540. }
  541. /**
  542. * Reset the position of this layout manager.
  543. *
  544. * @param resetPos the position to reset to
  545. */
  546. public void resetPosition(Position resetPos) {
  547. if (resetPos == null) {
  548. reset(null);
  549. }
  550. }
  551. /** @see org.apache.fop.layoutmgr.BlockLevelLayoutManager#mustKeepTogether() */
  552. public boolean mustKeepTogether() {
  553. //TODO Keeps will have to be more sophisticated sooner or later
  554. return ((BlockLevelLayoutManager)getParent()).mustKeepTogether()
  555. || !getListItemFO().getKeepTogether().getWithinPage().isAuto()
  556. || !getListItemFO().getKeepTogether().getWithinColumn().isAuto();
  557. }
  558. /** @see org.apache.fop.layoutmgr.BlockLevelLayoutManager#mustKeepWithPrevious() */
  559. public boolean mustKeepWithPrevious() {
  560. return !getListItemFO().getKeepWithPrevious().getWithinPage().isAuto()
  561. || !getListItemFO().getKeepWithPrevious().getWithinColumn().isAuto();
  562. }
  563. /** @see org.apache.fop.layoutmgr.BlockLevelLayoutManager#mustKeepWithNext() */
  564. public boolean mustKeepWithNext() {
  565. return !getListItemFO().getKeepWithNext().getWithinPage().isAuto()
  566. || !getListItemFO().getKeepWithNext().getWithinColumn().isAuto();
  567. }
  568. /** @see org.apache.fop.layoutmgr.ConditionalElementListener */
  569. public void notifySpace(RelSide side, MinOptMax effectiveLength) {
  570. if (RelSide.BEFORE == side) {
  571. if (log.isDebugEnabled()) {
  572. log.debug(this + ": Space " + side + ", "
  573. + this.effSpaceBefore + "-> " + effectiveLength);
  574. }
  575. this.effSpaceBefore = effectiveLength;
  576. } else {
  577. if (log.isDebugEnabled()) {
  578. log.debug(this + ": Space " + side + ", "
  579. + this.effSpaceAfter + "-> " + effectiveLength);
  580. }
  581. this.effSpaceAfter = effectiveLength;
  582. }
  583. }
  584. /** @see org.apache.fop.layoutmgr.ConditionalElementListener */
  585. public void notifyBorder(RelSide side, MinOptMax effectiveLength) {
  586. if (effectiveLength == null) {
  587. if (RelSide.BEFORE == side) {
  588. this.discardBorderBefore = true;
  589. } else {
  590. this.discardBorderAfter = true;
  591. }
  592. }
  593. if (log.isDebugEnabled()) {
  594. log.debug(this + ": Border " + side + " -> " + effectiveLength);
  595. }
  596. }
  597. /** @see org.apache.fop.layoutmgr.ConditionalElementListener */
  598. public void notifyPadding(RelSide side, MinOptMax effectiveLength) {
  599. if (effectiveLength == null) {
  600. if (RelSide.BEFORE == side) {
  601. this.discardPaddingBefore = true;
  602. } else {
  603. this.discardPaddingAfter = true;
  604. }
  605. }
  606. if (log.isDebugEnabled()) {
  607. log.debug(this + ": Padding " + side + " -> " + effectiveLength);
  608. }
  609. }
  610. }