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