reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 2 | * Copyright 2006 The Android Open Source Project |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 3 | * |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 8 | #ifndef SkStroke_DEFINED |
| 9 | #define SkStroke_DEFINED |
| 10 | |
reed@google.com | 04fdaa1 | 2012-11-21 15:48:20 +0000 | [diff] [blame] | 11 | #include "SkPath.h" |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 12 | #include "SkPoint.h" |
| 13 | #include "SkPaint.h" |
caryclark | feff7d2 | 2014-10-09 05:36:03 -0700 | [diff] [blame] | 14 | #include "SkStrokerPriv.h" |
| 15 | |
caryclark | a76b7a3b | 2015-05-22 06:26:52 -0700 | [diff] [blame] | 16 | #ifdef SK_DEBUG |
caryclark | feff7d2 | 2014-10-09 05:36:03 -0700 | [diff] [blame] | 17 | extern bool gDebugStrokerErrorSet; |
| 18 | extern SkScalar gDebugStrokerError; |
caryclark | feff7d2 | 2014-10-09 05:36:03 -0700 | [diff] [blame] | 19 | extern int gMaxRecursion[]; |
| 20 | #endif |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 21 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 22 | /** \class SkStroke |
| 23 | SkStroke is the utility class that constructs paths by stroking |
| 24 | geometries (lines, rects, ovals, roundrects, paths). This is |
| 25 | invoked when a geometry or text is drawn in a canvas with the |
| 26 | kStroke_Mask bit set in the paint. |
| 27 | */ |
| 28 | class SkStroke { |
| 29 | public: |
| 30 | SkStroke(); |
| 31 | SkStroke(const SkPaint&); |
| 32 | SkStroke(const SkPaint&, SkScalar width); // width overrides paint.getStrokeWidth() |
| 33 | |
| 34 | SkPaint::Cap getCap() const { return (SkPaint::Cap)fCap; } |
| 35 | void setCap(SkPaint::Cap); |
| 36 | |
| 37 | SkPaint::Join getJoin() const { return (SkPaint::Join)fJoin; } |
| 38 | void setJoin(SkPaint::Join); |
| 39 | |
| 40 | void setMiterLimit(SkScalar); |
| 41 | void setWidth(SkScalar); |
| 42 | |
| 43 | bool getDoFill() const { return SkToBool(fDoFill); } |
| 44 | void setDoFill(bool doFill) { fDoFill = SkToU8(doFill); } |
| 45 | |
reed@google.com | 04fdaa1 | 2012-11-21 15:48:20 +0000 | [diff] [blame] | 46 | /** |
reed | 05d9044 | 2015-02-12 13:35:52 -0800 | [diff] [blame] | 47 | * ResScale is the "intended" resolution for the output. |
| 48 | * Default is 1.0. |
| 49 | * Larger values (res > 1) indicate that the result should be more precise, since it will |
| 50 | * be zoomed up, and small errors will be magnified. |
| 51 | * Smaller values (0 < res < 1) indicate that the result can be less precise, since it will |
| 52 | * be zoomed down, and small errors may be invisible. |
| 53 | */ |
| 54 | SkScalar getResScale() const { return fResScale; } |
| 55 | void setResScale(SkScalar rs) { |
| 56 | SkASSERT(rs > 0 && SkScalarIsFinite(rs)); |
| 57 | fResScale = rs; |
| 58 | } |
| 59 | |
| 60 | /** |
reed@google.com | 04fdaa1 | 2012-11-21 15:48:20 +0000 | [diff] [blame] | 61 | * Stroke the specified rect, winding it in the specified direction.. |
| 62 | */ |
| 63 | void strokeRect(const SkRect& rect, SkPath* result, |
| 64 | SkPath::Direction = SkPath::kCW_Direction) const; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 65 | void strokePath(const SkPath& path, SkPath*) const; |
| 66 | |
| 67 | //////////////////////////////////////////////////////////////// |
| 68 | |
| 69 | private: |
| 70 | SkScalar fWidth, fMiterLimit; |
reed | 05d9044 | 2015-02-12 13:35:52 -0800 | [diff] [blame] | 71 | SkScalar fResScale; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 72 | uint8_t fCap, fJoin; |
| 73 | SkBool8 fDoFill; |
| 74 | |
| 75 | friend class SkPaint; |
| 76 | }; |
| 77 | |
| 78 | #endif |