add support for relative values for the margin property

Signed-off-by: Florian Thienel <florian@thienel.org>
diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/InlineFrame.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/InlineFrame.java
index bf18ac9..3056763 100644
--- a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/InlineFrame.java
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/InlineFrame.java
@@ -165,19 +165,19 @@
 	}
 
 	private int topFrame(final int componentHeight) {
-		return margin.top + border.top + padding.top.get(componentHeight);
+		return margin.top.get(componentHeight) + border.top + padding.top.get(componentHeight);
 	}
 
 	private int leftFrame(final int componentWidth) {
-		return margin.left + border.left + padding.left.get(componentWidth);
+		return margin.left.get(componentWidth) + border.left + padding.left.get(componentWidth);
 	}
 
 	private int bottomFrame(final int componentHeight) {
-		return margin.bottom + border.bottom + padding.bottom.get(componentHeight);
+		return margin.bottom.get(componentHeight) + border.bottom + padding.bottom.get(componentHeight);
 	}
 
 	private int rightFrame(final int componentWidth) {
-		return margin.right + border.right + padding.right.get(componentWidth);
+		return margin.right.get(componentWidth) + border.right + padding.right.get(componentWidth);
 	}
 
 	@Override
@@ -190,10 +190,15 @@
 		final ColorResource colorResource = graphics.getColor(Color.BLACK); // TODO store border color
 		graphics.setColor(colorResource);
 
-		drawBorderLine(graphics, border.top, margin.top, margin.left - border.left / 2, margin.top, width - margin.right + border.right / 2);
-		drawBorderLine(graphics, border.left, margin.top - border.top / 2, margin.left, height - margin.bottom + border.bottom / 2, margin.left);
-		drawBorderLine(graphics, border.bottom, height - margin.bottom, margin.left - border.left / 2, height - margin.bottom, width - margin.right + border.right / 2);
-		drawBorderLine(graphics, border.right, margin.top - border.top / 2, width - margin.right, height - margin.bottom + border.bottom / 2, width - margin.right);
+		final int rectTop = margin.top.get(component.getHeight());
+		final int rectLeft = margin.left.get(component.getWidth());
+		final int rectBottom = height - margin.bottom.get(component.getHeight());
+		final int rectRight = width - margin.right.get(component.getWidth());
+
+		drawBorderLine(graphics, border.top, rectTop, rectLeft - border.left / 2, rectTop, rectRight + border.right / 2);
+		drawBorderLine(graphics, border.left, rectTop - border.top / 2, rectLeft, rectBottom + border.bottom / 2, rectLeft);
+		drawBorderLine(graphics, border.bottom, rectBottom, rectLeft - border.left / 2, rectBottom, rectRight + border.right / 2);
+		drawBorderLine(graphics, border.right, rectTop - border.top / 2, rectRight, rectBottom + border.bottom / 2, rectRight);
 	}
 
 	private void drawBorderLine(final Graphics graphics, final int lineWidth, final int top, final int left, final int bottom, final int right) {
diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/Margin.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/Margin.java
index d1af208..42ad39c 100644
--- a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/Margin.java
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/Margin.java
@@ -10,6 +10,8 @@
  *******************************************************************************/
 package org.eclipse.vex.core.internal.boxes;
 
+import org.eclipse.vex.core.internal.core.Length;
+
 /**
  * @author Florian Thienel
  */
@@ -17,10 +19,10 @@
 
 	public static final Margin NULL = new Margin(0);
 
-	public final int top;
-	public final int left;
-	public final int bottom;
-	public final int right;
+	public final Length top;
+	public final Length left;
+	public final Length bottom;
+	public final Length right;
 
 	public Margin(final int size) {
 		this(size, size, size, size);
@@ -31,6 +33,10 @@
 	}
 
 	public Margin(final int top, final int left, final int bottom, final int right) {
+		this(Length.absolute(top), Length.absolute(left), Length.absolute(bottom), Length.absolute(right));
+	}
+
+	public Margin(final Length top, final Length left, final Length bottom, final Length right) {
 		this.top = top;
 		this.left = left;
 		this.bottom = bottom;
@@ -41,10 +47,10 @@
 	public int hashCode() {
 		final int prime = 31;
 		int result = 1;
-		result = prime * result + bottom;
-		result = prime * result + left;
-		result = prime * result + right;
-		result = prime * result + top;
+		result = prime * result + (bottom == null ? 0 : bottom.hashCode());
+		result = prime * result + (left == null ? 0 : left.hashCode());
+		result = prime * result + (right == null ? 0 : right.hashCode());
+		result = prime * result + (top == null ? 0 : top.hashCode());
 		return result;
 	}
 
@@ -60,16 +66,32 @@
 			return false;
 		}
 		final Margin other = (Margin) obj;
-		if (bottom != other.bottom) {
+		if (bottom == null) {
+			if (other.bottom != null) {
+				return false;
+			}
+		} else if (!bottom.equals(other.bottom)) {
 			return false;
 		}
-		if (left != other.left) {
+		if (left == null) {
+			if (other.left != null) {
+				return false;
+			}
+		} else if (!left.equals(other.left)) {
 			return false;
 		}
-		if (right != other.right) {
+		if (right == null) {
+			if (other.right != null) {
+				return false;
+			}
+		} else if (!right.equals(other.right)) {
 			return false;
 		}
-		if (top != other.top) {
+		if (top == null) {
+			if (other.top != null) {
+				return false;
+			}
+		} else if (!top.equals(other.top)) {
 			return false;
 		}
 		return true;
@@ -79,5 +101,4 @@
 	public String toString() {
 		return "Margin [top=" + top + ", left=" + left + ", bottom=" + bottom + ", right=" + right + "]";
 	}
-
 }
diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/StructuralFrame.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/StructuralFrame.java
index fc55e6a..b57dcfa 100644
--- a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/StructuralFrame.java
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/boxes/StructuralFrame.java
@@ -155,19 +155,19 @@
 	}
 
 	private int topFrame(final int componentHeight) {
-		return margin.top + border.top + padding.top.get(componentHeight);
+		return margin.top.get(componentHeight) + border.top + padding.top.get(componentHeight);
 	}
 
 	private int leftFrame() {
-		return margin.left + border.left + padding.left.get(width);
+		return margin.left.get(width) + border.left + padding.left.get(width);
 	}
 
 	private int bottomFrame(final int componentHeight) {
-		return margin.bottom + border.bottom + padding.bottom.get(componentHeight);
+		return margin.bottom.get(componentHeight) + border.bottom + padding.bottom.get(componentHeight);
 	}
 
 	private int rightFrame() {
-		return margin.right + border.right + padding.right.get(width);
+		return margin.right.get(width) + border.right + padding.right.get(width);
 	}
 
 	@Override
@@ -191,10 +191,15 @@
 		final ColorResource colorResource = graphics.getColor(Color.BLACK); // TODO store border color
 		graphics.setColor(colorResource);
 
-		drawBorderLine(graphics, border.top, margin.top, margin.left - border.left / 2, margin.top, width - margin.right + border.right / 2);
-		drawBorderLine(graphics, border.left, margin.top - border.top / 2, margin.left, height - margin.bottom + border.bottom / 2, margin.left);
-		drawBorderLine(graphics, border.bottom, height - margin.bottom, margin.left - border.left / 2, height - margin.bottom, width - margin.right + border.right / 2);
-		drawBorderLine(graphics, border.right, margin.top - border.top / 2, width - margin.right, height - margin.bottom + border.bottom / 2, width - margin.right);
+		final int rectTop = margin.top.get(component.getHeight());
+		final int rectLeft = margin.left.get(width);
+		final int rectBottom = height - margin.bottom.get(component.getHeight());
+		final int rectRight = width - margin.right.get(width);
+
+		drawBorderLine(graphics, border.top, rectTop, rectLeft - border.left / 2, rectTop, rectRight + border.right / 2);
+		drawBorderLine(graphics, border.left, rectTop - border.top / 2, rectLeft, rectBottom + border.bottom / 2, rectLeft);
+		drawBorderLine(graphics, border.bottom, rectBottom, rectLeft - border.left / 2, rectBottom, rectRight + border.right / 2);
+		drawBorderLine(graphics, border.right, rectTop - border.top / 2, rectRight, rectBottom + border.bottom / 2, rectRight);
 	}
 
 	private void drawBorderLine(final Graphics graphics, final int lineWidth, final int top, final int left, final int bottom, final int right) {
diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/visualization/CssBoxFactory.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/visualization/CssBoxFactory.java
index 5055955..8059a49 100644
--- a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/visualization/CssBoxFactory.java
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/visualization/CssBoxFactory.java
@@ -59,12 +59,7 @@
 	}
 
 	public static Margin margin(final Styles styles) {
-		final int top = styles.getMarginTop().get(1);
-		final int left = styles.getMarginLeft().get(1);
-		final int bottom = styles.getMarginBottom().get(1);
-		final int right = styles.getMarginRight().get(1);
-
-		return new Margin(top, left, bottom, right);
+		return new Margin(styles.getMarginTop(), styles.getMarginLeft(), styles.getMarginBottom(), styles.getMarginRight());
 	}
 
 	public static Border border(final Styles styles) {