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.

TableCell.java 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. /*
  2. * $Id$
  3. * Copyright (C) 2001-2002 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.apps.FOPException;
  13. import org.apache.fop.datatypes.*;
  14. import org.apache.fop.layoutmgr.table.Cell;
  15. import org.xml.sax.Attributes;
  16. import java.util.List;
  17. public class TableCell extends FObj {
  18. // int spaceBefore;
  19. // int spaceAfter;
  20. ColorType backgroundColor;
  21. int numColumnsSpanned;
  22. int numRowsSpanned;
  23. int iColNumber = -1; // uninitialized
  24. /**
  25. * Offset of content rectangle in inline-progression-direction,
  26. * relative to table.
  27. */
  28. protected int startOffset;
  29. /**
  30. * Dimension of allocation rectangle in inline-progression-direction,
  31. * determined by the width of the column(s) occupied by the cell
  32. */
  33. protected int width;
  34. /**
  35. * Offset of content rectangle, in block-progression-direction,
  36. * relative to the row.
  37. */
  38. protected int beforeOffset = 0;
  39. /**
  40. * Offset of content rectangle, in inline-progression-direction,
  41. * relative to the column start edge.
  42. */
  43. protected int startAdjust = 0;
  44. /**
  45. * Adjust to theoretical column width to obtain content width
  46. * relative to the column start edge.
  47. */
  48. protected int widthAdjust = 0;
  49. /* For collapsed border style */
  50. protected int borderHeight = 0;
  51. /**
  52. * Minimum ontent height of cell.
  53. */
  54. protected int minCellHeight = 0;
  55. protected int height = 0;
  56. protected int top; // Ypos of cell ???
  57. protected int verticalAlign;
  58. protected boolean bRelativeAlign = false;
  59. // boolean setup = false;
  60. boolean bSepBorders = true;
  61. /**
  62. * Set to true if all content completely laid out.
  63. */
  64. boolean bDone=false;
  65. /**
  66. * Border separation value in the block-progression dimension.
  67. * Used in calculating cells height.
  68. */
  69. int m_borderSeparation = 0;
  70. public TableCell(FONode parent) {
  71. super(parent);
  72. }
  73. public void handleAttrs(Attributes attlist) throws FOPException {
  74. super.handleAttrs(attlist);
  75. doSetup(); // init some basic property values
  76. }
  77. /**
  78. */
  79. public void addLayoutManager(List list) {
  80. Cell clm = new Cell(this);
  81. list.add(clm);
  82. }
  83. // Set position relative to table (set by body?)
  84. public void setStartOffset(int offset) {
  85. startOffset = offset;
  86. }
  87. // Initially same as the column width containg this cell or the
  88. // sum of the spanned columns if numColumnsSpanned > 1
  89. public void setWidth(int width) {
  90. this.width = width;
  91. }
  92. public int getColumnNumber() {
  93. return iColNumber;
  94. }
  95. public int getNumColumnsSpanned() {
  96. return numColumnsSpanned;
  97. }
  98. public int getNumRowsSpanned() {
  99. return numRowsSpanned;
  100. }
  101. public void doSetup() // throws FOPException
  102. {
  103. // Common Accessibility Properties
  104. AccessibilityProps mAccProps = propMgr.getAccessibilityProps();
  105. // Common Aural Properties
  106. AuralProps mAurProps = propMgr.getAuralProps();
  107. // Common Border, Padding, and Background Properties
  108. BorderAndPadding bap = propMgr.getBorderAndPadding();
  109. BackgroundProps bProps = propMgr.getBackgroundProps();
  110. // Common Relative Position Properties
  111. RelativePositionProps mRelProps = propMgr.getRelativePositionProps();
  112. // this.properties.get("border-after-precedence");
  113. // this.properties.get("border-before-precendence");
  114. // this.properties.get("border-end-precendence");
  115. // this.properties.get("border-start-precendence");
  116. // this.properties.get("block-progression-dimension");
  117. // this.properties.get("column-number");
  118. // this.properties.get("display-align");
  119. // this.properties.get("relative-align");
  120. // this.properties.get("empty-cells");
  121. // this.properties.get("ends-row");
  122. // this.properties.get("height");
  123. setupID();
  124. // this.properties.get("number-columns-spanned");
  125. // this.properties.get("number-rows-spanned");
  126. // this.properties.get("starts-row");
  127. // this.properties.get("width");
  128. this.iColNumber =
  129. properties.get("column-number").getNumber().intValue();
  130. if (iColNumber < 0) {
  131. iColNumber = 0;
  132. }
  133. this.numColumnsSpanned =
  134. this.properties.get("number-columns-spanned").getNumber().intValue();
  135. if (numColumnsSpanned < 1) {
  136. numColumnsSpanned = 1;
  137. }
  138. this.numRowsSpanned =
  139. this.properties.get("number-rows-spanned").getNumber().intValue();
  140. if (numRowsSpanned < 1) {
  141. numRowsSpanned = 1;
  142. }
  143. this.backgroundColor =
  144. this.properties.get("background-color").getColorType();
  145. bSepBorders = (this.properties.get("border-collapse").getEnum()
  146. == BorderCollapse.SEPARATE);
  147. calcBorders(propMgr.getBorderAndPadding());
  148. // Vertical cell alignment
  149. verticalAlign = this.properties.get("display-align").getEnum();
  150. if (verticalAlign == DisplayAlign.AUTO) {
  151. // Depends on all cells starting in row
  152. bRelativeAlign = true;
  153. verticalAlign = this.properties.get("relative-align").getEnum();
  154. } else {
  155. bRelativeAlign = false; // Align on a per-cell basis
  156. }
  157. this.minCellHeight =
  158. this.properties.get("height").getLength().mvalue();
  159. }
  160. /**
  161. * Calculate cell border and padding, including offset of content
  162. * rectangle from the theoretical grid position.
  163. */
  164. private void calcBorders(BorderAndPadding bp) {
  165. if (this.bSepBorders) {
  166. /*
  167. * Easy case.
  168. * Cell border is the property specified directly on cell.
  169. * Offset content rect by half the border-separation value,
  170. * in addition to the border and padding values. Note:
  171. * border-separate should only be specified on the table object,
  172. * but it inherits.
  173. */
  174. int iSep =
  175. properties.get("border-separation.inline-progression-direction").getLength().mvalue();
  176. this.startAdjust = iSep / 2 + bp.getBorderLeftWidth(false)
  177. + bp.getPaddingLeft(false);
  178. /*
  179. * int contentOffset = iSep + bp.getBorderStartWidth(false) +
  180. * bp.getPaddingStart(false);
  181. */
  182. this.widthAdjust = startAdjust + iSep - iSep / 2
  183. + bp.getBorderRightWidth(false)
  184. + bp.getPaddingRight(false);
  185. // bp.getBorderEndWidth(false) + bp.getPaddingEnd(false);
  186. // Offset of content rectangle in the block-progression direction
  187. m_borderSeparation =
  188. properties.get("border-separation.block-progression-direction").getLength().mvalue();
  189. this.beforeOffset = m_borderSeparation / 2
  190. + bp.getBorderTopWidth(false)
  191. + bp.getPaddingTop(false);
  192. // bp.getBorderBeforeWidth(false) + bp.getPaddingBefore(false);
  193. } else {
  194. // System.err.println("Collapse borders");
  195. /*
  196. * Hard case.
  197. * Cell border is combination of other cell borders, or table
  198. * border for edge cells. Also seems to border values specified
  199. * on row and column FO in the table (if I read CR correclty.)
  200. */
  201. // Set up before and after borders, taking into account row
  202. // and table border properties.
  203. // ??? What about table-body, header,footer
  204. /*
  205. * We can't calculate before and after because we aren't sure
  206. * whether this row will be the first or last in its area, due
  207. * to redoing break decisions (at least in the "new" architecture.)
  208. * So in the general case, we will calculate two possible values:
  209. * the first/last one and the "middle" one.
  210. * Example: border-before
  211. * 1. If the cell is in the first row in the first table body, it
  212. * will combine with the last row of the header, or with the
  213. * top (before) table border if there is no header.
  214. * 2. Otherwise there are two cases:
  215. * a. the row is first in its (non-first) Area.
  216. * The border can combine with either:
  217. * i. the last row of table-header and its cells, or
  218. * ii. the table before border (no table-header or it is
  219. * omitted on non-first Areas).
  220. * b. the row isn't first in its Area.
  221. * The border combines with the border of the previous
  222. * row and the cells which end in that row.
  223. */
  224. /*
  225. * if-first
  226. * Calculate the effective border of the cell before-border,
  227. * it's parent row before-border, the last header row after-border,
  228. * the after border of the cell(s) which end in the last header
  229. * row.
  230. */
  231. /*
  232. * if-not-first
  233. * Calculate the effective border of the cell before-border,
  234. * it's parent row before-border, the previous row after-border,
  235. * the after border of the cell(s) which end in the previous
  236. * row.
  237. */
  238. /* ivan demakov */
  239. int borderStart = bp.getBorderLeftWidth(false);
  240. int borderEnd = bp.getBorderRightWidth(false);
  241. int borderBefore = bp.getBorderTopWidth(false);
  242. int borderAfter = bp.getBorderBottomWidth(false);
  243. this.startAdjust = borderStart / 2 + bp.getPaddingLeft(false);
  244. this.widthAdjust = startAdjust + borderEnd / 2
  245. + bp.getPaddingRight(false);
  246. this.beforeOffset = borderBefore / 2 + bp.getPaddingTop(false);
  247. // Half border height to fix overestimate of area size!
  248. this.borderHeight = (borderBefore + borderAfter) / 2;
  249. }
  250. }
  251. }