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.

ListItem.java 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /*
  2. * $Id$
  3. * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
  4. * For details on use and redistribution please refer to the
  5. * LICENSE file included with these sources.
  6. */
  7. package org.apache.fop.fo.flow;
  8. // FOP
  9. import org.apache.fop.fo.*;
  10. import org.apache.fop.fo.properties.*;
  11. import org.apache.fop.layout.*;
  12. import org.apache.fop.layout.BlockArea;
  13. import org.apache.fop.layout.FontState;
  14. import org.apache.fop.apps.FOPException;
  15. // Java
  16. import java.util.Iterator;
  17. public class ListItem extends FObj {
  18. int align;
  19. int alignLast;
  20. int breakBefore;
  21. int breakAfter;
  22. int lineHeight;
  23. int startIndent;
  24. int endIndent;
  25. int spaceBefore;
  26. int spaceAfter;
  27. String id;
  28. BlockArea blockArea;
  29. public ListItem(FONode parent) {
  30. super(parent);
  31. }
  32. public Status layout(Area area) throws FOPException {
  33. if (this.marker == START) {
  34. // Common Accessibility Properties
  35. AccessibilityProps mAccProps = propMgr.getAccessibilityProps();
  36. // Common Aural Properties
  37. AuralProps mAurProps = propMgr.getAuralProps();
  38. // Common Border, Padding, and Background Properties
  39. BorderAndPadding bap = propMgr.getBorderAndPadding();
  40. BackgroundProps bProps = propMgr.getBackgroundProps();
  41. // Common Margin Properties-Block
  42. MarginProps mProps = propMgr.getMarginProps();
  43. // Common Relative Position Properties
  44. RelativePositionProps mRelProps = propMgr.getRelativePositionProps();
  45. // this.properties.get("break-after");
  46. // this.properties.get("break-before");
  47. // this.properties.get("id");
  48. // this.properties.get("keep-together");
  49. // this.properties.get("keep-with-next");
  50. // this.properties.get("keep-with-previous");
  51. // this.properties.get("relative-align");
  52. this.align = this.properties.get("text-align").getEnum();
  53. this.alignLast = this.properties.get("text-align-last").getEnum();
  54. this.lineHeight =
  55. this.properties.get("line-height").getLength().mvalue();
  56. this.spaceBefore =
  57. this.properties.get("space-before.optimum").getLength().mvalue();
  58. this.spaceAfter =
  59. this.properties.get("space-after.optimum").getLength().mvalue();
  60. this.id = this.properties.get("id").getString();
  61. area.getIDReferences().createID(id);
  62. this.marker = 0;
  63. }
  64. /* not sure this is needed given we know area is from list block */
  65. if (area instanceof BlockArea) {
  66. area.end();
  67. }
  68. if (spaceBefore != 0) {
  69. area.addDisplaySpace(spaceBefore);
  70. }
  71. this.blockArea =
  72. new BlockArea(propMgr.getFontState(area.getFontInfo()),
  73. area.getAllocationWidth(), area.spaceLeft(), 0, 0,
  74. 0, align, alignLast, lineHeight);
  75. this.blockArea.setGeneratedBy(this);
  76. this.areasGenerated++;
  77. if (this.areasGenerated == 1)
  78. this.blockArea.isFirst(true);
  79. // for normal areas this should be the only pair
  80. this.blockArea.addLineagePair(this, this.areasGenerated);
  81. // markers
  82. //if (this.hasMarkers())
  83. //this.blockArea.addMarkers(this.getMarkers());
  84. blockArea.setPage(area.getPage());
  85. blockArea.start();
  86. blockArea.setAbsoluteHeight(area.getAbsoluteHeight());
  87. blockArea.setIDReferences(area.getIDReferences());
  88. int numChildren = this.children.size();
  89. if (numChildren != 2) {
  90. throw new FOPException("list-item must have exactly two children");
  91. }
  92. ListItemLabel label = (ListItemLabel)children.get(0);
  93. ListItemBody body = (ListItemBody)children.get(1);
  94. Status status;
  95. // what follows doesn't yet take into account whether the
  96. // body failed completely or only got some text in
  97. if (this.marker == 0) {
  98. // configure id
  99. area.getIDReferences().configureID(id, area);
  100. status = label.layout(blockArea);
  101. if (status.isIncomplete()) {
  102. return status;
  103. }
  104. }
  105. status = body.layout(blockArea);
  106. if (status.isIncomplete()) {
  107. blockArea.end();
  108. area.addChild(blockArea);
  109. area.increaseHeight(blockArea.getHeight());
  110. area.setAbsoluteHeight(blockArea.getAbsoluteHeight());
  111. this.marker = 1;
  112. return status;
  113. }
  114. blockArea.end();
  115. area.addChild(blockArea);
  116. area.increaseHeight(blockArea.getHeight());
  117. area.setAbsoluteHeight(blockArea.getAbsoluteHeight());
  118. if (spaceAfter != 0) {
  119. area.addDisplaySpace(spaceAfter);
  120. }
  121. /* not sure this is needed given we know area is from list block */
  122. if (area instanceof BlockArea) {
  123. area.start();
  124. }
  125. this.blockArea.isLast(true);
  126. return new Status(Status.OK);
  127. }
  128. /**
  129. * Return the content width of the boxes generated by this FO.
  130. */
  131. public int getContentWidth() {
  132. if (blockArea != null)
  133. return blockArea.getContentWidth(); // getAllocationWidth()??
  134. else
  135. return 0; // not laid out yet
  136. }
  137. public boolean generatesInlineAreas() {
  138. return false;
  139. }
  140. }