don't add circles on chopped cubics
authorreed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Fri, 13 Jul 2012 15:55:15 +0000 (15:55 +0000)
committerreed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Fri, 13 Jul 2012 15:55:15 +0000 (15:55 +0000)
git-svn-id: http://skia.googlecode.com/svn/trunk@4600 2bbb7eff-a529-9590-31e7-b0007b416f81

gm/dashcubics.cpp [new file with mode: 0644]
gyp/gmslides.gypi
src/core/SkStroke.cpp

diff --git a/gm/dashcubics.cpp b/gm/dashcubics.cpp
new file mode 100644 (file)
index 0000000..d245070
--- /dev/null
@@ -0,0 +1,74 @@
+/*
+ * Copyright 2012 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "gm.h"
+#include "SkCanvas.h"
+#include "SkPath.h"
+#include "SkParsePath.h"
+#include "SkDashPathEffect.h"
+
+/*
+ *  Inspired by http://code.google.com/p/chromium/issues/detail?id=112145
+ */
+
+class DashCubicsGM : public skiagm::GM {
+public:
+    DashCubicsGM() {}
+
+protected:
+    virtual SkString onShortName() {
+        return SkString("dashcubics");
+    }
+
+    virtual SkISize onISize() {
+        return SkISize::Make(640, 480);
+    }
+
+    virtual void onDraw(SkCanvas* canvas) {
+        SkPath path;
+        const char* d = "M 337,98 C 250,141 250,212 250,212 C 250,212 250,212 250,212"
+        "C 250,212 250,212 250,212 C 250,212 250,141 163,98 C 156,195 217,231 217,231"
+        "C 217,231 217,231 217,231 C 217,231 217,231 217,231 C 217,231 156,195 75,250"
+        "C 156,305 217,269 217,269 C 217,269 217,269 217,269 C 217,269 217,269 217,269"
+        "C 217,269 156,305 163,402 C 250,359 250,288 250,288 C 250,288 250,288 250,288"
+        "C 250,288 250,288 250,288 C 250,288 250,359 338,402 C 345,305 283,269 283,269"
+        "C 283,269 283,269 283,269 C 283,269 283,269 283,269 C 283,269 345,305 425,250"
+        "C 344,195 283,231 283,231 C 283,231 283,231 283,231 C 283,231 283,231 283,231"
+        "C 283,231 344,195 338,98";
+
+        SkParsePath::FromSVGString(d, &path);
+        
+        SkScalar intervals[] = { 5, 10 };
+        SkPathEffect* pe = new SkDashPathEffect(intervals, 2, 0);
+
+        SkPaint paint;
+        paint.setAntiAlias(true);
+        paint.setStyle(SkPaint::kStroke_Style);
+
+        paint.setStrokeWidth(42);
+        canvas->drawPath(path, paint);
+
+        paint.setColor(SK_ColorRED);
+        paint.setStrokeWidth(21);
+        paint.setPathEffect(pe)->unref();
+        canvas->drawPath(path, paint);
+
+        paint.setColor(SK_ColorGREEN);
+        paint.setPathEffect(NULL);
+        paint.setStrokeWidth(0);
+        canvas->drawPath(path, paint);
+    }
+
+private:
+    typedef GM INHERITED;
+};
+
+//////////////////////////////////////////////////////////////////////////////
+
+static skiagm::GM* MyFactory(void*) { return new DashCubicsGM; }
+static skiagm::GMRegistry reg(MyFactory);
+
index e600d04..fa4d2bb 100644 (file)
@@ -18,6 +18,7 @@
     '../gm/cubicpaths.cpp',
     '../gm/cmykjpeg.cpp',
     '../gm/degeneratesegments.cpp',
+    '../gm/dashcubics.cpp',
     '../gm/dashing.cpp',
     '../gm/drawbitmaprect.cpp',
     '../gm/extractbitmap.cpp',
index 0084965..107a691 100644 (file)
@@ -462,6 +462,15 @@ void SkPathStroker::cubicTo(const SkPoint& pt1, const SkPoint& pt2,
 
         }
 
+#if 0
+        /*
+         *  Why was this code here? It caused us to draw circles where we didn't
+         *  want them. See http://code.google.com/p/chromium/issues/detail?id=112145
+         *  and gm/dashcubics.cpp
+         *
+         *  Simply removing this code seemed to fix the problem (no more circles).
+         *  Wish I had a repro case earlier when I added this check/hack...
+         */
         // check for too pinchy
         for (i = 1; i < count; i++) {
             SkPoint p;
@@ -476,7 +485,7 @@ void SkPathStroker::cubicTo(const SkPoint& pt1, const SkPoint& pt2,
                 fExtra.addCircle(p.fX, p.fY, fRadius, SkPath::kCW_Direction);
             }
         }
-
+#endif
     }
 
     this->postJoinTo(pt3, normalCD, unitCD);