Home | History | Annotate | Download | only in core
      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 "SkPath.h"
     12 #include "SkPoint.h"
     13 #include "SkPaint.h"
     14 #include "SkStrokerPriv.h"
     15 
     16 #ifdef SK_DEBUG
     17 extern bool gDebugStrokerErrorSet;
     18 extern SkScalar gDebugStrokerError;
     19 extern int gMaxRecursion[];
     20 #endif
     21 
     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 
     46     /**
     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     /**
     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;
     65     void    strokePath(const SkPath& path, SkPath*) const;
     66 
     67     ////////////////////////////////////////////////////////////////
     68 
     69 private:
     70     SkScalar    fWidth, fMiterLimit;
     71     SkScalar    fResScale;
     72     uint8_t     fCap, fJoin;
     73     SkBool8     fDoFill;
     74 
     75     friend class SkPaint;
     76 };
     77 
     78 #endif
     79