| 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/SkPathTypes.h" |
| 13 |
#include "include/core/SkScalar.h" |
| 14 |
#include "include/private/base/SkAssert.h" |
| 15 |
#include "include/private/base/SkDebug.h" |
| 16 |
#include "include/private/base/SkTo.h" |
| 17 |
|
| 18 |
#include <cmath> |
| 19 |
#include <cstdint> |
| 20 |
|
| 21 |
class SkPath; |
| 22 |
class SkPathBuilder; |
| 23 |
struct SkRect; |
| 24 |
|
| 25 |
#ifdef SK_DEBUG |
| 26 |
extern bool gDebugStrokerErrorSet; |
| 27 |
extern SkScalar gDebugStrokerError; |
| 28 |
extern int gMaxRecursion[]; |
| 29 |
#endif |
| 30 |
|
| 31 |
/** \class SkStroke |
| 32 |
SkStroke is the utility class that constructs paths by stroking |
| 33 |
geometries (lines, rects, ovals, roundrects, paths). This is |
| 34 |
invoked when a geometry or text is drawn in a canvas with the |
| 35 |
kStroke_Mask bit set in the paint. |
| 36 |
*/ |
| 37 |
class SkStroke { |
| 38 |
public: |
| 39 |
SkStroke(); |
| 40 |
explicit SkStroke(const SkPaint&); |
| 41 |
SkStroke(const SkPaint&, SkScalar width); // width overrides paint.getStrokeWidth() |
| 42 |
|
| 43 |
SkPaint::Cap getCap() const { return (SkPaint::Cap)fCap; } |
| 44 |
void setCap(SkPaint::Cap); |
| 45 |
|
| 46 |
SkPaint::Join getJoin() const { return (SkPaint::Join)fJoin; } |
| 47 |
void setJoin(SkPaint::Join); |
| 48 |
|
| 49 |
void setMiterLimit(SkScalar); |
| 50 |
void setWidth(SkScalar); |
| 51 |
|
| 52 |
bool getDoFill() const { return SkToBool(fDoFill); } |
| 53 |
void setDoFill(bool doFill) { fDoFill = SkToU8(doFill); } |
| 54 |
|
| 55 |
/** |
| 56 |
* ResScale is the "intended" resolution for the output. |
| 57 |
* Default is 1.0. |
| 58 |
* Larger values (res > 1) indicate that the result should be more precise, since it will |
| 59 |
* be zoomed up, and small errors will be magnified. |
| 60 |
* Smaller values (0 < res < 1) indicate that the result can be less precise, since it will |
| 61 |
* be zoomed down, and small errors may be invisible. |
| 62 |
*/ |
| 63 |
SkScalar getResScale() const { return fResScale; } |
| 64 |
void setResScale(SkScalar rs) { |
| 65 |
SkASSERT(rs > 0 && std::isfinite(rs)); |
| 66 |
fResScale = rs; |
| 67 |
} |
| 68 |
|
| 69 |
/** |
| 70 |
* Stroke the specified rect, winding it in the specified direction.. |
| 71 |
*/ |
| 72 |
void strokeRect(const SkRect& rect, SkPathBuilder* result, |
| 73 |
SkPathDirection = SkPathDirection::kCW) const; |
| 74 |
void strokePath(const SkPath& path, SkPathBuilder*) const; |
| 75 |
|
| 76 |
//////////////////////////////////////////////////////////////// |
| 77 |
|
| 78 |
private: |
| 79 |
SkScalar fWidth, fMiterLimit; |
| 80 |
SkScalar fResScale; |
| 81 |
uint8_t fCap, fJoin; |
| 82 |
bool fDoFill; |
| 83 |
|
| 84 |
friend class SkPaint; |
| 85 |
}; |
| 86 |
|
| 87 |
#endif |