Index: /trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/StyledMapRenderer.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/StyledMapRenderer.java	(revision 5811)
+++ /trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/StyledMapRenderer.java	(revision 5812)
@@ -598,5 +598,5 @@
     @Deprecated
     public void drawLinePattern(Way way, Image pattern) {
-        drawRepeatImage(way, pattern, 0f, 0f, LineImageAlignment.TOP);
+        drawRepeatImage(way, pattern, 0f, 0f, 0f, LineImageAlignment.TOP);
     }
 
@@ -608,8 +608,9 @@
      * @param offset offset from the way
      * @param spacing spacing between two images
+     * @param phase initial spacing
      * @param align alignment of the image. The top, center or bottom edge
      * can be aligned with the way.
      */
-    public void drawRepeatImage(Way way, Image pattern, float offset, float spacing, LineImageAlignment align) {
+    public void drawRepeatImage(Way way, Image pattern, float offset, float spacing, float phase, LineImageAlignment align) {
         final int imgWidth = pattern.getWidth(null);
         final double repeat = imgWidth + spacing;
@@ -617,5 +618,8 @@
 
         Point lastP = null;
-        double currentWayLength = 0;
+        double currentWayLength = phase % repeat;
+        if (currentWayLength < 0) {
+            currentWayLength += repeat;
+        }
 
         int dy1, dy2;
@@ -647,5 +651,7 @@
                 final double dy = thisP.y - lastP.y;
 
-                double pos = currentWayLength == 0 ? 0 : repeat - (currentWayLength % repeat);
+                // pos is the position from the beginning of the current segment
+                // where an image should be painted
+                double pos = repeat - (currentWayLength % repeat);
 
                 AffineTransform saveTransform = g.getTransform();
@@ -656,6 +662,14 @@
                 // is cut off
                 if (pos > spacing) {
-                    g.drawImage(pattern, 0, dy1, (int) (pos - spacing), dy2,
-                            (int) (imgWidth + spacing - pos), 0, imgWidth, imgHeight, null);
+                    // segment is too short for a complete image
+                    if (pos > segmentLength + spacing) {
+                        g.drawImage(pattern, 0, dy1, (int) segmentLength, dy2,
+                                (int) (repeat - pos), 0,
+                                (int) (repeat - pos + segmentLength), imgHeight, null);
+                    // rest of the image fits fully on the current segment
+                    } else {
+                        g.drawImage(pattern, 0, dy1, (int) (pos - spacing), dy2,
+                                (int) (repeat - pos), 0, imgWidth, imgHeight, null);
+                    }
                 }
                 // draw remaining images for this segment
Index: /trunk/src/org/openstreetmap/josm/gui/mappaint/NodeElemStyle.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/gui/mappaint/NodeElemStyle.java	(revision 5811)
+++ /trunk/src/org/openstreetmap/josm/gui/mappaint/NodeElemStyle.java	(revision 5812)
@@ -118,5 +118,5 @@
     }
 
-    public static MapImage createIcon(Environment env, String[] keys) {
+    public static MapImage createIcon(final Environment env, final String[] keys) {
         Cascade c = env.mc.getCascade(env.layer);
 
Index: /trunk/src/org/openstreetmap/josm/gui/mappaint/RepeatImageElemStyle.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/gui/mappaint/RepeatImageElemStyle.java	(revision 5811)
+++ /trunk/src/org/openstreetmap/josm/gui/mappaint/RepeatImageElemStyle.java	(revision 5812)
@@ -17,7 +17,8 @@
     public float offset;
     public float spacing;
+    public float phase;
     public LineImageAlignment align;
 
-    public RepeatImageElemStyle(Cascade c, MapImage pattern, float offset, float spacing, LineImageAlignment align) {
+    public RepeatImageElemStyle(Cascade c, MapImage pattern, float offset, float spacing, float phase, LineImageAlignment align) {
         super(c, 2.9f);
         CheckParameterUtil.ensureParameterNotNull(pattern);
@@ -26,4 +27,5 @@
         this.offset = offset;
         this.spacing = spacing;
+        this.phase = phase;
         this.align = align;
     }
@@ -34,6 +36,7 @@
             return null;
         Cascade c = env.mc.getCascade(env.layer);
-        Float offset = c.get(REPEAT_IMAGE_OFFSET, 0f, Float.class);
-        Float spacing = c.get(REPEAT_IMAGE_SPACING, 0f, Float.class);
+        float offset = c.get(REPEAT_IMAGE_OFFSET, 0f, Float.class);
+        float spacing = c.get(REPEAT_IMAGE_SPACING, 0f, Float.class);
+        float phase = - c.get(REPEAT_IMAGE_PHASE, 0f, Float.class);
 
         LineImageAlignment align = LineImageAlignment.CENTER;
@@ -45,11 +48,11 @@
         }
 
-        return new RepeatImageElemStyle(c, pattern, offset, spacing, align);
+        return new RepeatImageElemStyle(c, pattern, offset, spacing, phase, align);
     }
 
     @Override
     public void paintPrimitive(OsmPrimitive primitive, MapPaintSettings paintSettings, StyledMapRenderer painter, boolean selected, boolean member) {
-        Way w = (Way)primitive;
-        painter.drawRepeatImage(w, pattern.getImage(), offset, spacing, align);
+        Way w = (Way) primitive;
+        painter.drawRepeatImage(w, pattern.getImage(), offset, spacing, phase, align);
     }
 
@@ -69,4 +72,5 @@
         if (this.offset != other.offset) return false;
         if (this.spacing != other.spacing) return false;
+        if (this.phase != other.phase) return false;
         if (this.align != other.align) return false;
         return true;
@@ -79,4 +83,5 @@
         hash = 83 * hash + Float.floatToIntBits(this.offset);
         hash = 83 * hash + Float.floatToIntBits(this.spacing);
+        hash = 83 * hash + Float.floatToIntBits(this.phase);
         hash = 83 * hash + this.align.hashCode();
         return hash;
@@ -86,5 +91,6 @@
     public String toString() {
         return "RepeatImageStyle{" + super.toString() + "pattern=[" + pattern +
-                "], offset=" + offset + ", spacing=" + spacing + ", align=" + align + "}";
+                "], offset=" + offset + ", spacing=" + spacing +
+                ", phase=" + (-phase) + ", align=" + align + "}";
     }
 }
Index: /trunk/src/org/openstreetmap/josm/gui/mappaint/StyleKeys.java
===================================================================
--- /trunk/src/org/openstreetmap/josm/gui/mappaint/StyleKeys.java	(revision 5811)
+++ /trunk/src/org/openstreetmap/josm/gui/mappaint/StyleKeys.java	(revision 5812)
@@ -25,4 +25,5 @@
     String REPEAT_IMAGE_OFFSET = "repeat-image-offset";
     String REPEAT_IMAGE_SPACING = "repeat-image-spacing";
+    String REPEAT_IMAGE_PHASE = "repeat-image-phase";
     String REPEAT_IMAGE_ALIGN = "repeat-image-align";
 
