add support for horizontal span in HTML tables

Signed-off-by: Florian Thienel <florian@thienel.org>
diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/TableCell.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/TableCell.java
index 938532f..9c4c155 100644
--- a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/TableCell.java
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/TableCell.java
@@ -31,6 +31,7 @@
 	private String columnName;
 	private String startColumnName;
 	private String endColumnName;
+	private int horizontalSpan = 1;
 	private int verticalSpan = 1;
 
 	private GridArea gridArea;
@@ -149,6 +150,14 @@
 		this.endColumnName = endColumnName;
 	}
 
+	public int getHorizontalSpan() {
+		return horizontalSpan;
+	}
+
+	public void setHorizontalSpan(final int horizontalSpan) {
+		this.horizontalSpan = horizontalSpan;
+	}
+
 	public int getVerticalSpan() {
 		return verticalSpan;
 	}
diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/TableLayoutGrid.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/TableLayoutGrid.java
index cd40f5f..6f99e57 100644
--- a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/TableLayoutGrid.java
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/TableLayoutGrid.java
@@ -125,6 +125,7 @@
 		currentRow = rows.size();
 		row.setRowIndex(currentRow);
 		nextColumn = 1;
+		updateNextColumn();
 		return currentRow;
 	}
 
@@ -141,7 +142,7 @@
 	}
 
 	private void addNextCellOnCurrentRow(final TableCell cell) {
-		final GridArea area = new GridArea(currentRow, nextColumn, currentRow + cell.getVerticalSpan() - 1, nextColumn);
+		final GridArea area = new GridArea(currentRow, nextColumn, currentRow + cell.getVerticalSpan() - 1, nextColumn + cell.getHorizontalSpan() - 1);
 		occupy(area, cell);
 		cell.setGridArea(area);
 		cell.setLayoutGrid(this);
diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/visualization/CssBasedBoxModelBuilder.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/visualization/CssBasedBoxModelBuilder.java
index 14c2d24..9ccc2b5 100644
--- a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/visualization/CssBasedBoxModelBuilder.java
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/visualization/CssBasedBoxModelBuilder.java
@@ -282,7 +282,7 @@
 
 		if ("colspec".equals(element.getLocalName())) {
 			name = toString(element.getAttribute("colname"));
-			startIndex = toInt(element.getAttribute("colnum"));
+			startIndex = toInt(element.getAttribute("colnum"), 0);
 			endIndex = startIndex;
 			startName = null;
 			endName = null;
@@ -338,7 +338,7 @@
 		if ("entry".equals(element.getLocalName())) {
 			configureCALSCell(element, cell);
 		} else if ("th".equals(element.getLocalName()) || "td".equals(element.getLocalName())) {
-			// TODO HTML table
+			configureHTMLCell(element, cell);
 		}
 
 		return wrapWithNodeReference(element, childrenResults, cell);
@@ -361,17 +361,25 @@
 		}
 
 		final IAttribute moreRows = element.getAttribute("morerows");
-		cell.setVerticalSpan(1 + toInt(moreRows));
+		cell.setVerticalSpan(1 + toInt(moreRows, 0));
 	}
 
-	private static int toInt(final IAttribute attribute) {
+	private static void configureHTMLCell(final IElement element, final TableCell cell) {
+		final IAttribute colSpan = element.getAttribute("colspan");
+		cell.setHorizontalSpan(toInt(colSpan, 1));
+
+		final IAttribute rowSpan = element.getAttribute("rowspan");
+		cell.setVerticalSpan(toInt(rowSpan, 1));
+	}
+
+	private static int toInt(final IAttribute attribute, final int defaultValue) {
 		if (attribute == null) {
-			return 0;
+			return defaultValue;
 		}
 		try {
 			return Integer.parseInt(attribute.getValue());
 		} catch (final NumberFormatException e) {
-			return 0;
+			return defaultValue;
 		}
 	}