blob: 66edf3d92f062e109933a726cdd78c51568b2acf [file] [log] [blame]
reed@android.com8a1c16f2008-12-17 15:59:43 +00001/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00002 * Copyright 2006 The Android Open Source Project
reed@android.com8a1c16f2008-12-17 15:59:43 +00003 *
epoger@google.comec3ed6a2011-07-28 14:26:00 +00004 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
reed@android.com8a1c16f2008-12-17 15:59:43 +00006 */
7
reed@android.com8a1c16f2008-12-17 15:59:43 +00008#ifndef SkStroke_DEFINED
9#define SkStroke_DEFINED
10
Mike Kleinc0bd9f92019-04-23 12:05:21 -050011#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"
caryclarkfeff7d22014-10-09 05:36:03 -070016
caryclarka76b7a3b2015-05-22 06:26:52 -070017#ifdef SK_DEBUG
caryclarkfeff7d22014-10-09 05:36:03 -070018extern bool gDebugStrokerErrorSet;
19extern SkScalar gDebugStrokerError;
caryclarkfeff7d22014-10-09 05:36:03 -070020extern int gMaxRecursion[];
21#endif
reed@android.com8a1c16f2008-12-17 15:59:43 +000022
reed@android.com8a1c16f2008-12-17 15:59:43 +000023/** \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*/
29class SkStroke {
30public:
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.com04fdaa12012-11-21 15:48:20 +000047 /**
reed05d90442015-02-12 13:35:52 -080048 * 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.com04fdaa12012-11-21 15:48:20 +000062 * 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.com8a1c16f2008-12-17 15:59:43 +000066 void strokePath(const SkPath& path, SkPath*) const;
67
68 ////////////////////////////////////////////////////////////////
69
70private:
71 SkScalar fWidth, fMiterLimit;
reed05d90442015-02-12 13:35:52 -080072 SkScalar fResScale;
reed@android.com8a1c16f2008-12-17 15:59:43 +000073 uint8_t fCap, fJoin;
Ben Wagnercee46e52018-06-12 16:30:29 -040074 bool fDoFill;
reed@android.com8a1c16f2008-12-17 15:59:43 +000075
76 friend class SkPaint;
77};
78
79#endif