Debian Codegraph @

include/core/SkPathMeasure.h

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