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