From 04fdaa1afed8687a3b15226ddebcb798c94ddac5 Mon Sep 17 00:00:00 2001 From: "reed@google.com" Date: Wed, 21 Nov 2012 15:48:20 +0000 Subject: [PATCH] use direction from isRect in strokeRect, and only stroke if it is closed 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 | 15 ++++++++------- src/core/SkStroke.h | 12 ++++++------ 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/core/SkStroke.cpp b/src/core/SkStroke.cpp index fbf995bfaf..6d3b4fd4bc 100644 --- a/src/core/SkStroke.cpp +++ b/src/core/SkStroke.cpp @@ -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; } diff --git a/src/core/SkStroke.h b/src/core/SkStroke.h index 5f0b475cf1..48805165cb 100644 --- a/src/core/SkStroke.h +++ b/src/core/SkStroke.h @@ -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; //////////////////////////////////////////////////////////////// -- 2.34.1