SkPathMeasure.h 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 SkPathMeasure_DEFINED
  8. #define SkPathMeasure_DEFINED
  9. #include "include/core/SkContourMeasure.h"
  10. #include "include/core/SkPath.h"
  11. #include "include/private/SkTDArray.h"
  12. class SK_API SkPathMeasure {
  13. public:
  14. SkPathMeasure();
  15. /** Initialize the pathmeasure with the specified path. The parts of the path that are needed
  16. * are copied, so the client is free to modify/delete the path after this call.
  17. *
  18. * resScale controls the precision of the measure. values > 1 increase the
  19. * precision (and possible slow down the computation).
  20. */
  21. SkPathMeasure(const SkPath& path, bool forceClosed, SkScalar resScale = 1);
  22. ~SkPathMeasure();
  23. /** Reset the pathmeasure with the specified path. The parts of the path that are needed
  24. * are copied, so the client is free to modify/delete the path after this call..
  25. */
  26. void setPath(const SkPath*, bool forceClosed);
  27. /** Return the total length of the current contour, or 0 if no path
  28. is associated (e.g. resetPath(null))
  29. */
  30. SkScalar getLength();
  31. /** Pins distance to 0 <= distance <= getLength(), and then computes
  32. the corresponding position and tangent.
  33. Returns false if there is no path, or a zero-length path was specified, in which case
  34. position and tangent are unchanged.
  35. */
  36. bool SK_WARN_UNUSED_RESULT getPosTan(SkScalar distance, SkPoint* position,
  37. SkVector* tangent);
  38. enum MatrixFlags {
  39. kGetPosition_MatrixFlag = 0x01,
  40. kGetTangent_MatrixFlag = 0x02,
  41. kGetPosAndTan_MatrixFlag = kGetPosition_MatrixFlag | kGetTangent_MatrixFlag
  42. };
  43. /** Pins distance to 0 <= distance <= getLength(), and then computes
  44. the corresponding matrix (by calling getPosTan).
  45. Returns false if there is no path, or a zero-length path was specified, in which case
  46. matrix is unchanged.
  47. */
  48. bool SK_WARN_UNUSED_RESULT getMatrix(SkScalar distance, SkMatrix* matrix,
  49. MatrixFlags flags = kGetPosAndTan_MatrixFlag);
  50. /** Given a start and stop distance, return in dst the intervening segment(s).
  51. If the segment is zero-length, return false, else return true.
  52. startD and stopD are pinned to legal values (0..getLength()). If startD > stopD
  53. then return false (and leave dst untouched).
  54. Begin the segment with a moveTo if startWithMoveTo is true
  55. */
  56. bool getSegment(SkScalar startD, SkScalar stopD, SkPath* dst, bool startWithMoveTo);
  57. /** Return true if the current contour is closed()
  58. */
  59. bool isClosed();
  60. /** Move to the next contour in the path. Return true if one exists, or false if
  61. we're done with the path.
  62. */
  63. bool nextContour();
  64. #ifdef SK_DEBUG
  65. void dump();
  66. #endif
  67. private:
  68. SkContourMeasureIter fIter;
  69. sk_sp<SkContourMeasure> fContour;
  70. SkPathMeasure(const SkPathMeasure&) = delete;
  71. SkPathMeasure& operator=(const SkPathMeasure&) = delete;
  72. };
  73. #endif