changeset 6410:a5bf93565444

Fix RT-35452: Canvas does not allow missing initial movetos Reviewed by: Martin
author flar <James.Graham@oracle.com>
date Mon, 03 Mar 2014 15:05:41 -0800
parents e164a77392b6
children 7fac01b6f9b8
files modules/graphics/src/main/java/javafx/scene/canvas/GraphicsContext.java modules/graphics/src/test/java/javafx/scene/canvas/CanvasTest.java
diffstat 2 files changed, 42 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/modules/graphics/src/main/java/javafx/scene/canvas/GraphicsContext.java	Mon Mar 03 17:33:51 2014 -0500
+++ b/modules/graphics/src/main/java/javafx/scene/canvas/GraphicsContext.java	Mon Mar 03 15:05:41 2014 -0800
@@ -1127,6 +1127,9 @@
         coords[0] = (float) x1;
         coords[1] = (float) y1;
         curState.transform.transform(coords, 0, coords, 0, 1);
+        if (path.getNumCommands() == 0) {
+            path.moveTo(coords[0], coords[1]);
+        }
         path.lineTo(coords[0], coords[1]);
         markPathDirty();
     }
@@ -1145,6 +1148,9 @@
         coords[2] = (float) x1;
         coords[3] = (float) y1;
         curState.transform.transform(coords, 0, coords, 0, 2);
+        if (path.getNumCommands() == 0) {
+            path.moveTo(coords[0], coords[1]);
+        }
         path.quadTo(coords[0], coords[1], coords[2], coords[3]);
         markPathDirty();
     }
@@ -1167,6 +1173,9 @@
         coords[4] = (float) x1;
         coords[5] = (float) y1;
         curState.transform.transform(coords, 0, coords, 0, 3);
+        if (path.getNumCommands() == 0) {
+            path.moveTo(coords[0], coords[1]);
+        }
         path.curveTo(coords[0], coords[1], coords[2], coords[3], coords[4], coords[5]);
         markPathDirty();
     }
@@ -1464,8 +1473,10 @@
      * Closes the path.
      */
     public void closePath() {
-        path.closePath();
-        markPathDirty();
+        if (path.getNumCommands() > 0) {
+            path.closePath();
+            markPathDirty();
+        }
     }
 
     /**
--- a/modules/graphics/src/test/java/javafx/scene/canvas/CanvasTest.java	Mon Mar 03 17:33:51 2014 -0500
+++ b/modules/graphics/src/test/java/javafx/scene/canvas/CanvasTest.java	Mon Mar 03 15:05:41 2014 -0800
@@ -174,9 +174,35 @@
         gc.stroke();
         gc.fill();
     }
-    
-    
-    
+
+    @Test public void testGCPath_LineTo_NoMoveto() throws Exception {
+        gc.lineTo(10, 10);
+    }
+
+    @Test public void testGCPath_QuadraticCurveTo_NoMoveto() throws Exception {
+        gc.quadraticCurveTo(10, 10, 20, 20);
+    }
+
+    @Test public void testGCPath_BezierCurveTo_NoMoveto() throws Exception {
+        gc.bezierCurveTo(10, 10, 20, 20, 30, 30);
+    }
+
+    @Test public void testGCPath_ArcTo_NoMoveto() throws Exception {
+        gc.arcTo(10, 10, 20, 20, 30);
+    }
+
+    @Test public void testGCPath_Arc_NoMoveto() throws Exception {
+        gc.arc(10, 10, 20, 20, 30, 30);
+    }
+
+    @Test public void testGCPath_ClosePath_NoMoveto() throws Exception {
+        gc.closePath();
+    }
+
+    @Test public void testGCPath_Rect_NoMoveto() throws Exception {
+        gc.rect(10, 10, 20, 20);
+    }
+
     @Test public void testGCState_Translate() throws Exception {
         gc.translate(50, 50);
         Affine result = gc.getTransform();