summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMohamadou Nassourou2010-08-05 14:27:49 (EDT)
committer Florian Thienel2010-08-05 14:27:49 (EDT)
commit59ebe5261c32697f5cfce9621a83ff6c7044a553 (patch)
tree50d0327b6bcdd045d8cbcd1b953b3c752bfbaab1
parentec444ae812043f33e0478b0de75298e02f0f0262 (diff)
downloadorg.eclipse.mylyn.docs.vex-59ebe5261c32697f5cfce9621a83ff6c7044a553.zip
org.eclipse.mylyn.docs.vex-59ebe5261c32697f5cfce9621a83ff6c7044a553.tar.gz
org.eclipse.mylyn.docs.vex-59ebe5261c32697f5cfce9621a83ff6c7044a553.tar.bz2
Bug 298912: applied changes described in https://bugs.eclipse.org/bugs/attachment.cgi?id=175944
Signed-off-by: Florian Thienel <florian@thienel.org>
-rw-r--r--sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/core/Graphics.java7
-rw-r--r--sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/HeightProperty.java28
-rw-r--r--sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/StyleSheet.java6
-rw-r--r--sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/Styles.java15
-rw-r--r--sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/WidthProperty.java28
-rw-r--r--sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/layout/BlockElementBox.java44
-rw-r--r--sourceediting/plugins/org.eclipse.wst.xml.vex.ui/src/org/eclipse/wst/xml/vex/ui/internal/swt/SwtGraphics.java8
-rw-r--r--sourceediting/tests/org.eclipse.wst.xml.vex.core.tests/src/org/eclipse/wst/xml/vex/core/internal/layout/FakeGraphics.java7
8 files changed, 136 insertions, 7 deletions
diff --git a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/core/Graphics.java b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/core/Graphics.java
index d8adabd..733fcd5 100644
--- a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/core/Graphics.java
+++ b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/core/Graphics.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2004, 2008 John Krasnay and others.
+ * Copyright (c) 2004, 2010 John Krasnay and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -7,9 +7,12 @@
*
* Contributors:
* John Krasnay - initial API and implementation
+ * Mohamadou Nassourou - Bug 298912 - rudimentary support for images
*******************************************************************************/
package org.eclipse.wst.xml.vex.core.internal.core;
+import org.eclipse.swt.graphics.Image;
+
/**
* Interface through which Vex performs graphics operations. Implemented by
* adapters to the java.awt.Graphics and org.eclipse.swt.graphics.GC classes.
@@ -48,6 +51,8 @@ public interface Graphics {
public void drawRect(int x, int y, int width, int height);
+ public void drawImage(Image image, int x, int y, int width, int height); // TODO this introduces a dependency to SWT. 'Image' should be encapsulated like FontMetrics
+
public void fillOval(int x, int y, int width, int height);
public void fillRect(int x, int y, int width, int height);
diff --git a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/HeightProperty.java b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/HeightProperty.java
new file mode 100644
index 0000000..65a7c43
--- /dev/null
+++ b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/HeightProperty.java
@@ -0,0 +1,28 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Mohamadou Nassourou and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Mohamadou Nassourou - Bug 298912 - rudimentary support for images
+ *******************************************************************************/
+package org.eclipse.wst.xml.vex.core.internal.css;
+
+import org.w3c.css.sac.LexicalUnit;
+
+public class HeightProperty extends AbstractProperty {
+
+ public static final float DEFAULT_HEIGHT = 50.0f;
+
+ public HeightProperty() {
+ super(CSS.HEIGHT);
+ }
+
+ public Object calculate(final LexicalUnit lexicalUnit, final Styles parentStyles, final Styles styles) {
+ if (lexicalUnit != null)
+ return new Float(Math.max(DEFAULT_HEIGHT, lexicalUnit.getFloatValue()));
+ return DEFAULT_HEIGHT;
+ }
+} \ No newline at end of file
diff --git a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/StyleSheet.java b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/StyleSheet.java
index eda172a..64600ce 100644
--- a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/StyleSheet.java
+++ b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/StyleSheet.java
@@ -13,6 +13,7 @@
* Travis Haagen - bug 260806 - enhanced support for 'content' CSS property
* Florian Thienel - bug 306639 - remove serializability from StyleSheet
* and dependend classes
+ * Mohamadou Nassourou - Bug 298912 - rudimentary support for images
*******************************************************************************/
package org.eclipse.wst.xml.vex.core.internal.css;
@@ -96,7 +97,10 @@ public class StyleSheet implements Serializable {
new BorderWidthProperty(CSS.BORDER_RIGHT_WIDTH,
CSS.BORDER_RIGHT_STYLE, IProperty.AXIS_HORIZONTAL),
new BorderWidthProperty(CSS.BORDER_TOP_WIDTH, CSS.BORDER_TOP_STYLE,
- IProperty.AXIS_VERTICAL), new BorderSpacingProperty(), };
+ IProperty.AXIS_VERTICAL), new BorderSpacingProperty(),
+ new HeightProperty(),
+ new WidthProperty()
+ };
/**
* The rules that comprise the stylesheet.
diff --git a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/Styles.java b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/Styles.java
index abe4d5f..c30a0da 100644
--- a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/Styles.java
+++ b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/Styles.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2004, 2008 John Krasnay and others.
+ * Copyright (c) 2004, 2010 John Krasnay and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -8,6 +8,7 @@
* Contributors:
* John Krasnay - initial API and implementation
* Dave Holroyd - Implement text decoration
+ * Mohamadou Nassourou - Bug 298912 - rudimentary support for images
*******************************************************************************/
package org.eclipse.wst.xml.vex.core.internal.css;
@@ -255,6 +256,18 @@ public class Styles {
this.font = font;
}
+ public float getElementWidth() {
+ if (this.values.get(CSS.WIDTH) != null)
+ return ((Float) this.values.get(CSS.WIDTH)).floatValue();
+ return WidthProperty.DEFAULT_WIDTH;
+ }
+
+ public float getElementHeight() {
+ if (this.values.get(CSS.HEIGHT) != null)
+ return ((Float) this.values.get(CSS.HEIGHT)).floatValue();
+ return HeightProperty.DEFAULT_HEIGHT;
+ }
+
/**
* @return the value of border-bottom-width
*/
diff --git a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/WidthProperty.java b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/WidthProperty.java
new file mode 100644
index 0000000..5f4eb2d
--- /dev/null
+++ b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/css/WidthProperty.java
@@ -0,0 +1,28 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Mohamadou Nassourou and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Mohamadou Nassourou - Bug 298912 - rudimentary support for images
+ *******************************************************************************/
+package org.eclipse.wst.xml.vex.core.internal.css;
+
+import org.w3c.css.sac.LexicalUnit;
+
+public class WidthProperty extends AbstractProperty {
+
+ public static final float DEFAULT_WIDTH = 50.0f;
+
+ public WidthProperty() {
+ super(CSS.WIDTH);
+ }
+
+ public Object calculate(final LexicalUnit lexicalUnit, final Styles parentStyles, final Styles styles) {
+ if (lexicalUnit != null)
+ return new Float(Math.max(DEFAULT_WIDTH, lexicalUnit.getFloatValue()));
+ return DEFAULT_WIDTH;
+ }
+} \ No newline at end of file
diff --git a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/layout/BlockElementBox.java b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/layout/BlockElementBox.java
index e364099..e5853b9 100644
--- a/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/layout/BlockElementBox.java
+++ b/sourceediting/plugins/org.eclipse.wst.xml.vex.core/src/org/eclipse/wst/xml/vex/core/internal/layout/BlockElementBox.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2004, 2008 John Krasnay and others.
+ * Copyright (c) 2004, 2010 John Krasnay and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -8,12 +8,15 @@
* Contributors:
* John Krasnay - initial API and implementation
* Igor Jacy Lino Campista - Java 5 warnings fixed (bug 311325)
+ * Mohamadou Nassourou - Bug 298912 - rudimentary support for images
*******************************************************************************/
package org.eclipse.wst.xml.vex.core.internal.layout;
import java.util.ArrayList;
import java.util.List;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Display;
import org.eclipse.wst.xml.vex.core.internal.VEXCorePlugin;
import org.eclipse.wst.xml.vex.core.internal.core.Drawable;
import org.eclipse.wst.xml.vex.core.internal.core.Graphics;
@@ -179,7 +182,7 @@ public class BlockElementBox extends AbstractBlockBox {
childList.add(afterBlock);
}
- Styles styles = context.getStyleSheet().getStyles(this.getElement());
+ final Styles styles = context.getStyleSheet().getStyles(this.getElement());
if (styles.getDisplay().equals(CSS.LIST_ITEM)
&& !styles.getListStyleType().equals(CSS.NONE)) {
this.createListMarker(context);
@@ -194,9 +197,46 @@ public class BlockElementBox extends AbstractBlockBox {
}
}
+ if (this.getElement().getName().equals("graphic") // TODO this is specific for the Docbook DTD
+ && !styles.getDisplay().equalsIgnoreCase(CSS.NONE)) {
+ if (this.getElement() != null) {
+ this.callDrawImage(context, this.getElement(), styles);
+ }
+ }
+
return childList;
}
+ private void callDrawImage(LayoutContext context, VEXElement element,
+ Styles styles) {
+ final String filename = element.getAttribute("url"); // TODO this is specific for the Docbook DTD
+ if (filename == null)
+ return;
+
+ final InlineBox markerInline = drawImage(element, styles, filename);
+ this.beforeMarker = ParagraphBox.create(context, this.getElement(),
+ new InlineBox[] { markerInline }, Integer.MAX_VALUE);
+ }
+
+ private static InlineBox drawImage(final VEXElement element, Styles styles,
+ final String filename) {
+ final int width = (int) styles.getElementWidth();
+ final int height = (int) styles.getElementHeight();
+ final int offset = 5;
+ final Drawable drawable = new Drawable() {
+ public Rectangle getBounds() {
+ return new Rectangle(0, -height, width, height);
+ }
+
+ public void draw(final Graphics g, final int x, final int y) {
+ final Image image = new Image(Display.getDefault(), filename); // TODO this introduces a dependency to SWT, should be encapsulated
+ g.drawImage(image, g.getClipBounds().getX() + offset, g
+ .getClipBounds().getY() - height, width, height);
+ }
+ };
+ return new DrawableBox(drawable, element);
+ }
+
/**
* Creates a marker box for this primary box and puts it in the beforeMarker
* field.
diff --git a/sourceediting/plugins/org.eclipse.wst.xml.vex.ui/src/org/eclipse/wst/xml/vex/ui/internal/swt/SwtGraphics.java b/sourceediting/plugins/org.eclipse.wst.xml.vex.ui/src/org/eclipse/wst/xml/vex/ui/internal/swt/SwtGraphics.java
index 7a07ba0..9d925a2 100644
--- a/sourceediting/plugins/org.eclipse.wst.xml.vex.ui/src/org/eclipse/wst/xml/vex/ui/internal/swt/SwtGraphics.java
+++ b/sourceediting/plugins/org.eclipse.wst.xml.vex.ui/src/org/eclipse/wst/xml/vex/ui/internal/swt/SwtGraphics.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2004, 2008 John Krasnay and others.
+ * Copyright (c) 2004, 2010 John Krasnay and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -7,12 +7,14 @@
*
* Contributors:
* John Krasnay - initial API and implementation
+ * Mohamadou Nassourou - Bug 298912 - rudimentary support for images
*******************************************************************************/
package org.eclipse.wst.xml.vex.ui.internal.swt;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.graphics.GC;
+import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Display;
import org.eclipse.wst.xml.vex.core.internal.core.Color;
import org.eclipse.wst.xml.vex.core.internal.core.ColorResource;
@@ -78,6 +80,10 @@ public class SwtGraphics implements Graphics {
this.gc.drawString(s, x + originX, y + originY, true);
}
+ public void drawImage(Image image, int x, int y, int width, int height) {
+ gc.drawImage(image, x + originX, y + originY);
+ }
+
/**
* Fills the given oval with the <em>foreground</em> color. This overrides
* the default SWT behaviour to be more like Swing.
diff --git a/sourceediting/tests/org.eclipse.wst.xml.vex.core.tests/src/org/eclipse/wst/xml/vex/core/internal/layout/FakeGraphics.java b/sourceediting/tests/org.eclipse.wst.xml.vex.core.tests/src/org/eclipse/wst/xml/vex/core/internal/layout/FakeGraphics.java
index 2044115..5cf9a41 100644
--- a/sourceediting/tests/org.eclipse.wst.xml.vex.core.tests/src/org/eclipse/wst/xml/vex/core/internal/layout/FakeGraphics.java
+++ b/sourceediting/tests/org.eclipse.wst.xml.vex.core.tests/src/org/eclipse/wst/xml/vex/core/internal/layout/FakeGraphics.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2004, 2008 John Krasnay and others.
+ * Copyright (c) 2004, 2010 John Krasnay and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -7,9 +7,11 @@
*
* Contributors:
* John Krasnay - initial API and implementation
+ * Mohamadou Nassourou - Bug 298912 - rudimentary support for images
*******************************************************************************/
package org.eclipse.wst.xml.vex.core.internal.layout;
+import org.eclipse.swt.graphics.Image;
import org.eclipse.wst.xml.vex.core.internal.core.Color;
import org.eclipse.wst.xml.vex.core.internal.core.ColorResource;
import org.eclipse.wst.xml.vex.core.internal.core.DisplayDevice;
@@ -91,6 +93,9 @@ public class FakeGraphics implements Graphics {
public void drawRect(int x, int y, int width, int height) {
}
+
+ public void drawImage(Image image, int x, int y, int width, int height) {
+ }
public void fillOval(int x, int y, int width, int height) {
}