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 9.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. /*
  2. * $Id$
  3. * ============================================================================
  4. * The Apache Software License, Version 1.1
  5. * ============================================================================
  6. *
  7. * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
  8. *
  9. * Redistribution and use in source and binary forms, with or without modifica-
  10. * tion, are permitted provided that the following conditions are met:
  11. *
  12. * 1. Redistributions of source code must retain the above copyright notice,
  13. * this list of conditions and the following disclaimer.
  14. *
  15. * 2. Redistributions in binary form must reproduce the above copyright notice,
  16. * this list of conditions and the following disclaimer in the documentation
  17. * and/or other materials provided with the distribution.
  18. *
  19. * 3. The end-user documentation included with the redistribution, if any, must
  20. * include the following acknowledgment: "This product includes software
  21. * developed by the Apache Software Foundation (http://www.apache.org/)."
  22. * Alternately, this acknowledgment may appear in the software itself, if
  23. * and wherever such third-party acknowledgments normally appear.
  24. *
  25. * 4. The names "FOP" and "Apache Software Foundation" must not be used to
  26. * endorse or promote products derived from this software without prior
  27. * written permission. For written permission, please contact
  28. * apache@apache.org.
  29. *
  30. * 5. Products derived from this software may not be called "Apache", nor may
  31. * "Apache" appear in their name, without prior written permission of the
  32. * Apache Software Foundation.
  33. *
  34. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  35. * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  36. * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  37. * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  38. * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
  39. * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  40. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  41. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  42. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  43. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  44. * ============================================================================
  45. *
  46. * This software consists of voluntary contributions made by many individuals
  47. * on behalf of the Apache Software Foundation and was originally created by
  48. * James Tauber <jtauber@jtauber.com>. For more information on the Apache
  49. * Software Foundation, please see <http://www.apache.org/>.
  50. */
  51. package org.apache.fop.fo.flow;
  52. // FOP
  53. import org.apache.fop.fo.FObj;
  54. import org.apache.fop.fo.PropertyList;
  55. import org.apache.fop.fo.Status;
  56. import org.apache.fop.layout.Area;
  57. import org.apache.fop.layout.AccessibilityProps;
  58. import org.apache.fop.layout.AuralProps;
  59. import org.apache.fop.layout.BorderAndPadding;
  60. import org.apache.fop.layout.BackgroundProps;
  61. import org.apache.fop.layout.MarginProps;
  62. import org.apache.fop.layout.RelativePositionProps;
  63. import org.apache.fop.layout.BlockArea;
  64. import org.apache.fop.apps.FOPException;
  65. public class ListItem extends FObj {
  66. public static class Maker extends FObj.Maker {
  67. public FObj make(FObj parent, PropertyList propertyList,
  68. String systemId, int line, int column)
  69. throws FOPException {
  70. return new ListItem(parent, propertyList, systemId, line, column);
  71. }
  72. }
  73. public static FObj.Maker maker() {
  74. return new ListItem.Maker();
  75. }
  76. int align;
  77. int alignLast;
  78. int breakBefore;
  79. int breakAfter;
  80. int lineHeight;
  81. int startIndent;
  82. int endIndent;
  83. int spaceBefore;
  84. int spaceAfter;
  85. String id;
  86. BlockArea blockArea;
  87. public ListItem(FObj parent, PropertyList propertyList,
  88. String systemId, int line, int column) {
  89. super(parent, propertyList, systemId, line, column);
  90. }
  91. public String getName() {
  92. return "fo:list-item";
  93. }
  94. public int layout(Area area) throws FOPException {
  95. if (this.marker == START) {
  96. // Common Accessibility Properties
  97. AccessibilityProps mAccProps = propMgr.getAccessibilityProps();
  98. // Common Aural Properties
  99. AuralProps mAurProps = propMgr.getAuralProps();
  100. // Common Border, Padding, and Background Properties
  101. BorderAndPadding bap = propMgr.getBorderAndPadding();
  102. BackgroundProps bProps = propMgr.getBackgroundProps();
  103. // Common Margin Properties-Block
  104. MarginProps mProps = propMgr.getMarginProps();
  105. // Common Relative Position Properties
  106. RelativePositionProps mRelProps = propMgr.getRelativePositionProps();
  107. // this.properties.get("break-after");
  108. // this.properties.get("break-before");
  109. // this.properties.get("id");
  110. // this.properties.get("keep-together");
  111. // this.properties.get("keep-with-next");
  112. // this.properties.get("keep-with-previous");
  113. // this.properties.get("relative-align");
  114. this.align = this.properties.get("text-align").getEnum();
  115. this.alignLast = this.properties.get("text-align-last").getEnum();
  116. this.lineHeight =
  117. this.properties.get("line-height").getLength().mvalue();
  118. this.spaceBefore =
  119. this.properties.get("space-before.optimum").getLength().mvalue();
  120. this.spaceAfter =
  121. this.properties.get("space-after.optimum").getLength().mvalue();
  122. this.id = this.properties.get("id").getString();
  123. try {
  124. area.getIDReferences().createID(id);
  125. }
  126. catch(FOPException e) {
  127. if (!e.isLocationSet()) {
  128. e.setLocation(systemId, line, column);
  129. }
  130. throw e;
  131. }
  132. this.marker = 0;
  133. }
  134. /* not sure this is needed given we know area is from list block */
  135. if (area instanceof BlockArea) {
  136. area.end();
  137. }
  138. if (spaceBefore != 0) {
  139. area.addDisplaySpace(spaceBefore);
  140. }
  141. this.blockArea =
  142. new BlockArea(propMgr.getFontState(area.getFontInfo()),
  143. area.getAllocationWidth(), area.spaceLeft(), 0, 0,
  144. 0, align, alignLast, lineHeight);
  145. // Fix links in lists in tables problem
  146. blockArea.setTableCellXOffset(area.getTableCellXOffset());
  147. this.blockArea.setGeneratedBy(this);
  148. this.areasGenerated++;
  149. if (this.areasGenerated == 1)
  150. this.blockArea.isFirst(true);
  151. // for normal areas this should be the only pair
  152. // this.blockArea.addLineagePair(this, this.areasGenerated);
  153. // markers
  154. // if (this.hasMarkers())
  155. // this.blockArea.addMarkers(this.getMarkers());
  156. blockArea.setParent(area);
  157. blockArea.setPage(area.getPage());
  158. blockArea.start();
  159. blockArea.setAbsoluteHeight(area.getAbsoluteHeight());
  160. blockArea.setIDReferences(area.getIDReferences());
  161. int numChildren = this.children.size();
  162. if (numChildren != 2) {
  163. throw new FOPException("list-item must have exactly two children",
  164. systemId, line, column);
  165. }
  166. ListItemLabel label = (ListItemLabel)children.get(0);
  167. ListItemBody body = (ListItemBody)children.get(1);
  168. int status;
  169. // what follows doesn't yet take into account whether the
  170. // body failed completely or only got some text in
  171. if (this.marker == 0) {
  172. // configure id
  173. area.getIDReferences().configureID(id, area);
  174. status = label.layout(blockArea);
  175. if (Status.isIncomplete(status)) {
  176. return status;
  177. }
  178. }
  179. status = body.layout(blockArea);
  180. if (Status.isIncomplete(status)) {
  181. blockArea.end();
  182. area.addChild(blockArea);
  183. area.increaseHeight(blockArea.getHeight());
  184. this.marker = 1;
  185. return status;
  186. }
  187. blockArea.end();
  188. area.addChild(blockArea);
  189. area.increaseHeight(blockArea.getHeight());
  190. if (spaceAfter != 0) {
  191. area.addDisplaySpace(spaceAfter);
  192. }
  193. /* not sure this is needed given we know area is from list block */
  194. if (area instanceof BlockArea) {
  195. area.start();
  196. }
  197. this.blockArea.isLast(true);
  198. return Status.OK;
  199. }
  200. /**
  201. * Return the content width of the boxes generated by this FO.
  202. */
  203. public int getContentWidth() {
  204. if (blockArea != null)
  205. return blockArea.getContentWidth(); // getAllocationWidth()??
  206. else
  207. return 0; // not laid out yet
  208. }
  209. }