xref: /aosp_15_r20/external/skia/src/core/SkPathMeasure.cpp (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
1 /*
2  * Copyright 2008 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 #include "include/core/SkPathMeasure.h"
9 
10 #include "include/core/SkContourMeasure.h"
11 #include "include/core/SkPath.h"
12 #include "include/core/SkRefCnt.h"
13 #include "include/core/SkScalar.h"
14 #include "include/private/base/SkTDArray.h"
15 #include "src/core/SkPathMeasurePriv.h"
16 
17 #include <cstddef>
18 
19 class SkMatrix;
20 
SkPathMeasure()21 SkPathMeasure::SkPathMeasure() {}
22 
SkPathMeasure(const SkPath & path,bool forceClosed,SkScalar resScale)23 SkPathMeasure::SkPathMeasure(const SkPath& path, bool forceClosed, SkScalar resScale)
24     : fIter(path, forceClosed, resScale)
25 {
26     fContour = fIter.next();
27 }
28 
~SkPathMeasure()29 SkPathMeasure::~SkPathMeasure() {}
30 
setPath(const SkPath * path,bool forceClosed)31 void SkPathMeasure::setPath(const SkPath* path, bool forceClosed) {
32     fIter.reset(path ? *path : SkPath(), forceClosed);
33     fContour = fIter.next();
34 }
35 
getLength()36 SkScalar SkPathMeasure::getLength() {
37     return fContour ? fContour->length() : 0;
38 }
39 
getPosTan(SkScalar distance,SkPoint * position,SkVector * tangent)40 bool SkPathMeasure::getPosTan(SkScalar distance, SkPoint* position, SkVector* tangent) {
41     return fContour && fContour->getPosTan(distance, position, tangent);
42 }
43 
getMatrix(SkScalar distance,SkMatrix * matrix,MatrixFlags flags)44 bool SkPathMeasure::getMatrix(SkScalar distance, SkMatrix* matrix, MatrixFlags flags) {
45     return fContour && fContour->getMatrix(distance, matrix, (SkContourMeasure::MatrixFlags)flags);
46 }
47 
getSegment(SkScalar startD,SkScalar stopD,SkPath * dst,bool startWithMoveTo)48 bool SkPathMeasure::getSegment(SkScalar startD, SkScalar stopD, SkPath* dst, bool startWithMoveTo) {
49     return fContour && fContour->getSegment(startD, stopD, dst, startWithMoveTo);
50 }
51 
isClosed()52 bool SkPathMeasure::isClosed() {
53     return fContour && fContour->isClosed();
54 }
55 
nextContour()56 bool SkPathMeasure::nextContour() {
57     fContour = fIter.next();
58     return !!fContour;
59 }
60 
61 #ifdef SK_DEBUG
dump()62 void SkPathMeasure::dump() {}
63 #endif
64 
65 /////
66 
CountSegments(const SkPathMeasure & meas)67 size_t SkPathMeasurePriv::CountSegments(const SkPathMeasure& meas) {
68     if (auto cntr = meas.currentMeasure()) {
69         return cntr->fSegments.size();
70     }
71     return 0;
72 }
73