use direction from isRect in strokeRect, and only stroke if it is closed
authorreed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Wed, 21 Nov 2012 15:48:20 +0000 (15:48 +0000)
committerreed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Wed, 21 Nov 2012 15:48:20 +0000 (15:48 +0000)
Review URL: https://codereview.appspot.com/6846086

git-svn-id: http://skia.googlecode.com/svn/trunk@6528 2bbb7eff-a529-9590-31e7-b0007b416f81

src/core/SkStroke.cpp
src/core/SkStroke.h

index fbf995bfaf6105fea7fd97bc3a06e7664e93baa2..6d3b4fd4bc2bd150b25f81fffb03a2b5adc479cb 100644 (file)
@@ -610,9 +610,10 @@ void SkStroke::strokePath(const SkPath& src, SkPath* dst) const {
     // If src is really a rect, call our specialty strokeRect() method
 #ifndef SK_IGNORE_NEW_STROKERECT
     {
-        SkRect rect;
-        if (src.isRect(&rect)) {
-            this->strokeRect(rect, dst);
+        bool isClosed;
+        SkPath::Direction dir;
+        if (src.isRect(&isClosed, &dir) && isClosed) {
+            this->strokeRect(src.getBounds(), dst, dir);
             // our answer should preserve the inverseness of the src
             if (src.isInverseFillType()) {
                 SkASSERT(!dst->isInverseFillType());
@@ -746,7 +747,8 @@ static void addBevel(SkPath* path, const SkRect& r, const SkRect& outer, SkPath:
     path->addPoly(pts, 8, true);
 }
 
-void SkStroke::strokeRect(const SkRect& origRect, SkPath* dst) const {
+void SkStroke::strokeRect(const SkRect& origRect, SkPath* dst,
+                          SkPath::Direction dir) const {
     SkASSERT(dst != NULL);
     dst->reset();
 
@@ -755,11 +757,10 @@ void SkStroke::strokeRect(const SkRect& origRect, SkPath* dst) const {
         return;
     }
 
-    SkPath::Direction dir = SkPath::kCW_Direction;
     SkScalar rw = origRect.width();
     SkScalar rh = origRect.height();
     if ((rw < 0) ^ (rh < 0)) {
-        dir = SkPath::kCCW_Direction;
+        dir = reverse_direction(dir);
     }
     SkRect rect(origRect);
     rect.sort();
@@ -783,7 +784,7 @@ void SkStroke::strokeRect(const SkRect& origRect, SkPath* dst) const {
             addBevel(dst, rect, r, dir);
             break;
         case SkPaint::kRound_Join:
-            dst->addRoundRect(r, radius, radius);
+            dst->addRoundRect(r, radius, radius, dir);
             break;
     }
 
index 5f0b475cf102ef770b3cef109a8f2a16c9c6710f..48805165cbc73f56daf52587c021e0ffca0c31eb 100644 (file)
@@ -1,4 +1,3 @@
-
 /*
  * Copyright 2006 The Android Open Source Project
  *
@@ -6,16 +5,13 @@
  * found in the LICENSE file.
  */
 
-
 #ifndef SkStroke_DEFINED
 #define SkStroke_DEFINED
 
+#include "SkPath.h"
 #include "SkPoint.h"
 #include "SkPaint.h"
 
-struct SkRect;
-class SkPath;
-
 /** \class SkStroke
     SkStroke is the utility class that constructs paths by stroking
     geometries (lines, rects, ovals, roundrects, paths). This is
@@ -40,7 +36,11 @@ public:
     bool    getDoFill() const { return SkToBool(fDoFill); }
     void    setDoFill(bool doFill) { fDoFill = SkToU8(doFill); }
 
-    void    strokeRect(const SkRect&, SkPath*) const;
+    /**
+     *  Stroke the specified rect, winding it in the specified direction..
+     */
+    void    strokeRect(const SkRect& rect, SkPath* result,
+                       SkPath::Direction = SkPath::kCW_Direction) const;
     void    strokePath(const SkPath& path, SkPath*) const;
 
     ////////////////////////////////////////////////////////////////