SkStroke.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. #ifndef SkStroke_DEFINED
  8. #define SkStroke_DEFINED
  9. #include "include/core/SkPaint.h"
  10. #include "include/core/SkPath.h"
  11. #include "include/core/SkPoint.h"
  12. #include "include/private/SkTo.h"
  13. #include "src/core/SkStrokerPriv.h"
  14. #ifdef SK_DEBUG
  15. extern bool gDebugStrokerErrorSet;
  16. extern SkScalar gDebugStrokerError;
  17. extern int gMaxRecursion[];
  18. #endif
  19. /** \class SkStroke
  20. SkStroke is the utility class that constructs paths by stroking
  21. geometries (lines, rects, ovals, roundrects, paths). This is
  22. invoked when a geometry or text is drawn in a canvas with the
  23. kStroke_Mask bit set in the paint.
  24. */
  25. class SkStroke {
  26. public:
  27. SkStroke();
  28. SkStroke(const SkPaint&);
  29. SkStroke(const SkPaint&, SkScalar width); // width overrides paint.getStrokeWidth()
  30. SkPaint::Cap getCap() const { return (SkPaint::Cap)fCap; }
  31. void setCap(SkPaint::Cap);
  32. SkPaint::Join getJoin() const { return (SkPaint::Join)fJoin; }
  33. void setJoin(SkPaint::Join);
  34. void setMiterLimit(SkScalar);
  35. void setWidth(SkScalar);
  36. bool getDoFill() const { return SkToBool(fDoFill); }
  37. void setDoFill(bool doFill) { fDoFill = SkToU8(doFill); }
  38. /**
  39. * ResScale is the "intended" resolution for the output.
  40. * Default is 1.0.
  41. * Larger values (res > 1) indicate that the result should be more precise, since it will
  42. * be zoomed up, and small errors will be magnified.
  43. * Smaller values (0 < res < 1) indicate that the result can be less precise, since it will
  44. * be zoomed down, and small errors may be invisible.
  45. */
  46. SkScalar getResScale() const { return fResScale; }
  47. void setResScale(SkScalar rs) {
  48. SkASSERT(rs > 0 && SkScalarIsFinite(rs));
  49. fResScale = rs;
  50. }
  51. /**
  52. * Stroke the specified rect, winding it in the specified direction..
  53. */
  54. void strokeRect(const SkRect& rect, SkPath* result,
  55. SkPath::Direction = SkPath::kCW_Direction) const;
  56. void strokePath(const SkPath& path, SkPath*) const;
  57. ////////////////////////////////////////////////////////////////
  58. private:
  59. SkScalar fWidth, fMiterLimit;
  60. SkScalar fResScale;
  61. uint8_t fCap, fJoin;
  62. bool fDoFill;
  63. friend class SkPaint;
  64. };
  65. #endif