Index: trunk/src/org/openstreetmap/josm/gui/mappaint/AreaElemStyle.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/mappaint/AreaElemStyle.java	(revision 4271)
+++ trunk/src/org/openstreetmap/josm/gui/mappaint/AreaElemStyle.java	(revision 4272)
@@ -45,8 +45,8 @@
         IconReference iconRef = c.get("fill-image", null, IconReference.class);
         if (iconRef != null) {
-            ImageIcon icon = MapPaintStyles.getIcon(iconRef, false);
+            ImageIcon icon = MapPaintStyles.getIcon(iconRef, -1, -1, false);
             if (icon != null) {
                 if (!(icon.getImage() instanceof BufferedImage)) {
-                    icon = MapPaintStyles.getIcon(iconRef, true);
+                    icon = MapPaintStyles.getIcon(iconRef, -1, -1, true);
                 }
                 if (!(icon.getImage() instanceof BufferedImage))
Index: trunk/src/org/openstreetmap/josm/gui/mappaint/LinePatternElemStyle.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/mappaint/LinePatternElemStyle.java	(revision 4271)
+++ trunk/src/org/openstreetmap/josm/gui/mappaint/LinePatternElemStyle.java	(revision 4272)
@@ -28,5 +28,5 @@
         if (iconRef == null)
             return null;
-        ImageIcon icon = MapPaintStyles.getIcon(iconRef, false);
+        ImageIcon icon = MapPaintStyles.getIcon(iconRef, -1, -1, false);
         if (icon == null)
             return null;
Index: trunk/src/org/openstreetmap/josm/gui/mappaint/MapPaintStyles.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/mappaint/MapPaintStyles.java	(revision 4271)
+++ trunk/src/org/openstreetmap/josm/gui/mappaint/MapPaintStyles.java	(revision 4272)
@@ -4,4 +4,5 @@
 import static org.openstreetmap.josm.tools.I18n.tr;
 
+import java.awt.Dimension;
 import java.io.IOException;
 import java.io.InputStream;
@@ -63,4 +64,11 @@
     }
 
+    /**
+     * IconReference is used to remember the associated style source for
+     * each icon URL. 
+     * This is necessary because image URLs can be paths relative
+     * to the source file and we have cascading of properties from different 
+     * source files.
+     */
     public static class IconReference {
 
@@ -79,7 +87,7 @@
     }
 
-    public static ImageIcon getIcon(IconReference ref, boolean sanitize) {
-        String namespace = ref.source.getPrefName();
-        ImageIcon i = ImageProvider.getIfAvailable(getIconSourceDirs(ref.source), "mappaint."+namespace, null, ref.iconName, ref.source.zipIcons, sanitize);
+    public static ImageIcon getIcon(IconReference ref, int width, int height, boolean sanitize) {
+        final String namespace = ref.source.getPrefName();
+        ImageIcon i = ImageProvider.getIfAvailable(getIconSourceDirs(ref.source), "mappaint."+namespace, null, ref.iconName, ref.source.zipIcons, width == -1 && height == -1 ? null : new Dimension(width, height), sanitize);
         if(i == null)
         {
Index: trunk/src/org/openstreetmap/josm/gui/mappaint/NodeElemStyle.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/mappaint/NodeElemStyle.java	(revision 4271)
+++ trunk/src/org/openstreetmap/josm/gui/mappaint/NodeElemStyle.java	(revision 4272)
@@ -6,4 +6,5 @@
 import java.awt.BasicStroke;
 import java.awt.Color;
+import java.awt.Dimension;
 import java.awt.Image;
 import java.awt.Stroke;
@@ -221,42 +222,29 @@
             return null;
 
-        ImageIcon icon = null;
-        int iconAlpha = 0;
-
-        icon = MapPaintStyles.getIcon(iconRef, false);
+        Float widthOnDefault = c_def.get("icon-width", null, Float.class);
+        if (widthOnDefault != null && widthOnDefault <= 0) {
+            widthOnDefault = null;
+        }
+        Float widthF = getWidth(c, "icon-width", widthOnDefault);
+
+        Float heightOnDefault = c_def.get("icon-height", null, Float.class);
+        if (heightOnDefault != null && heightOnDefault <= 0) {
+            heightOnDefault = null;
+        }
+        Float heightF = getWidth(c, "icon-height", heightOnDefault);
+
+        int width = widthF == null ? -1 : Math.round(widthF);
+        int height = heightF == null ? -1 : Math.round(heightF);
+
+        ImageIcon icon = MapPaintStyles.getIcon(iconRef, width, height, false);
         if (icon == null)
             return new Pair<ImageIcon, Integer>(MapPaintStyles.getNoIcon_Icon(iconRef.source, false), 255);
-        else {
-            Float sizeOnDefault = c_def.get("icon-size", null, Float.class);
-            if (sizeOnDefault != null && sizeOnDefault <= 0) {
-                sizeOnDefault = null;
-            }
-            Float sizeF = getWidth(c, "icon-size", sizeOnDefault);
-
-            if (sizeF != null) {
-                if (sizeF <= 0)
-                    return null;
-                int size = Math.round(sizeF);
-                int width = icon.getIconWidth();
-                int height = icon.getIconHeight();
-                if (Math.max(width, height) != size) {
-                    if (width >= height) {
-                        width = size;
-                        height = -1;
-                    } else {
-                        width = -1;
-                        height = size;
-                    }
-                    icon.setImage(icon.getImage().getScaledInstance(width, height, Image.SCALE_SMOOTH));
-                }
-            }
-            iconAlpha = Math.min(255, Math.max(0, Integer.valueOf(Main.pref.getInteger("mappaint.icon-image-alpha", 255))));
-            Integer pAlpha = Utils.color_float2int(c.get("icon-opacity", null, float.class));
-            if (pAlpha != null) {
-                iconAlpha = pAlpha;
-            }
-
-            return new Pair<ImageIcon, Integer>(icon, iconAlpha);
-        }
+        int iconAlpha = Math.min(255, Math.max(0, Integer.valueOf(Main.pref.getInteger("mappaint.icon-image-alpha", 255))));
+        Integer pAlpha = Utils.color_float2int(c.get("icon-opacity", null, float.class));
+        if (pAlpha != null) {
+            iconAlpha = pAlpha;
+        }
+
+        return new Pair<ImageIcon, Integer>(icon, iconAlpha);
     }
 
Index: trunk/src/org/openstreetmap/josm/gui/mappaint/StyleSource.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/mappaint/StyleSource.java	(revision 4271)
+++ trunk/src/org/openstreetmap/josm/gui/mappaint/StyleSource.java	(revision 4272)
@@ -74,5 +74,5 @@
         if (imageIcon == null) {
             if (icon != null) {
-                imageIcon = MapPaintStyles.getIcon(new IconReference(icon, this), false);
+                imageIcon = MapPaintStyles.getIcon(new IconReference(icon, this), -1, -1, false);
             }
             if (imageIcon == null) {
Index: trunk/src/org/openstreetmap/josm/tools/Pair.java
===================================================================
--- trunk/src/org/openstreetmap/josm/tools/Pair.java	(revision 4271)
+++ trunk/src/org/openstreetmap/josm/tools/Pair.java	(revision 4272)
@@ -48,4 +48,7 @@
     }
 
-
+    /* convenience constructor method */
+    public static <U,V> Pair<U,V> create(U u, V v) {
+        return new Pair<U,V>(u,v);
+    }
 }
Index: trunk/src/org/openstreetmap/josm/tools/Utils.java
===================================================================
--- trunk/src/org/openstreetmap/josm/tools/Utils.java	(revision 4271)
+++ trunk/src/org/openstreetmap/josm/tools/Utils.java	(revision 4272)
@@ -258,3 +258,9 @@
         }
     }
+
+    private final static double EPSILION = 1e-11;
+
+    public static boolean equalsEpsilon(double a, double b) {
+        return Math.abs(a - b) <= EPSILION;
+    }
 }
