1 /*
2  * Copyright 2006 The Android Open Source Project
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7 
8 #ifndef SkStroke_DEFINED
9 #define SkStroke_DEFINED
10 
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"
16 
17 #ifdef SK_DEBUG
18 extern bool gDebugStrokerErrorSet;
19 extern SkScalar gDebugStrokerError;
20 extern int gMaxRecursion[];
21 #endif
22 
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 
getCap()35     SkPaint::Cap    getCap() const { return (SkPaint::Cap)fCap; }
36     void        setCap(SkPaint::Cap);
37 
getJoin()38     SkPaint::Join   getJoin() const { return (SkPaint::Join)fJoin; }
39     void        setJoin(SkPaint::Join);
40 
41     void    setMiterLimit(SkScalar);
42     void    setWidth(SkScalar);
43 
getDoFill()44     bool    getDoFill() const { return SkToBool(fDoFill); }
setDoFill(bool doFill)45     void    setDoFill(bool doFill) { fDoFill = SkToU8(doFill); }
46 
47     /**
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      */
getResScale()55     SkScalar getResScale() const { return fResScale; }
setResScale(SkScalar rs)56     void setResScale(SkScalar rs) {
57         SkASSERT(rs > 0 && SkScalarIsFinite(rs));
58         fResScale = rs;
59     }
60 
61     /**
62      *  Stroke the specified rect, winding it in the specified direction..
63      */
64     void    strokeRect(const SkRect& rect, SkPath* result,
65                        SkPathDirection = SkPathDirection::kCW) const;
66     void    strokePath(const SkPath& path, SkPath*) const;
67 
68     ////////////////////////////////////////////////////////////////
69 
70 private:
71     SkScalar    fWidth, fMiterLimit;
72     SkScalar    fResScale;
73     uint8_t     fCap, fJoin;
74     bool        fDoFill;
75 
76     friend class SkPaint;
77 };
78 
79 #endif
80