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