tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

SkPathMeasure.cpp (2352B)


      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_SUPPORT_MUTABLE_PATHEFFECT
     64 bool SkPathMeasure::getSegment(SkScalar startD, SkScalar stopD, SkPath* dst,
     65                               bool startWithMoveTo) {
     66    SkPathBuilder builder;
     67    if (this->getSegment(startD, stopD, &builder, startWithMoveTo)) {
     68        *dst = builder.detach();
     69        return true;
     70    }
     71    return false;
     72 }
     73 #endif
     74 
     75 #ifdef SK_DEBUG
     76 void SkPathMeasure::dump() {}
     77 #endif
     78 
     79 /////
     80 
     81 size_t SkPathMeasurePriv::CountSegments(const SkPathMeasure& meas) {
     82    if (auto cntr = meas.currentMeasure()) {
     83        return cntr->fSegments.size();
     84    }
     85    return 0;
     86 }