blob: f93efdee0fd1e03f28f8a2899aeef41f1c5c1477 [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
reed@google.com04fdaa12012-11-21 15:48:20 +000011#include "SkPath.h"
reed@android.com8a1c16f2008-12-17 15:59:43 +000012#include "SkPoint.h"
13#include "SkPaint.h"
caryclarkfeff7d22014-10-09 05:36:03 -070014#include "SkStrokerPriv.h"
15
caryclarka76b7a3b2015-05-22 06:26:52 -070016#ifdef SK_DEBUG
caryclarkfeff7d22014-10-09 05:36:03 -070017extern bool gDebugStrokerErrorSet;
18extern SkScalar gDebugStrokerError;
caryclarkfeff7d22014-10-09 05:36:03 -070019extern int gMaxRecursion[];
20#endif
reed@android.com8a1c16f2008-12-17 15:59:43 +000021
reed@android.com8a1c16f2008-12-17 15:59:43 +000022/** \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*/
28class SkStroke {
29public:
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.com04fdaa12012-11-21 15:48:20 +000046 /**
reed05d90442015-02-12 13:35:52 -080047 * 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.com04fdaa12012-11-21 15:48:20 +000061 * 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.com8a1c16f2008-12-17 15:59:43 +000065 void strokePath(const SkPath& path, SkPath*) const;
66
67 ////////////////////////////////////////////////////////////////
68
69private:
70 SkScalar fWidth, fMiterLimit;
reed05d90442015-02-12 13:35:52 -080071 SkScalar fResScale;
reed@android.com8a1c16f2008-12-17 15:59:43 +000072 uint8_t fCap, fJoin;
73 SkBool8 fDoFill;
74
75 friend class SkPaint;
76};
77
78#endif