gfx/skia/trunk/include/core/SkPathMeasure.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/skia/trunk/include/core/SkPathMeasure.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,109 @@
     1.4 +/*
     1.5 + * Copyright 2006 The Android Open Source Project
     1.6 + *
     1.7 + * Use of this source code is governed by a BSD-style license that can be
     1.8 + * found in the LICENSE file.
     1.9 + */
    1.10 +
    1.11 +#ifndef SkPathMeasure_DEFINED
    1.12 +#define SkPathMeasure_DEFINED
    1.13 +
    1.14 +#include "SkPath.h"
    1.15 +#include "SkTDArray.h"
    1.16 +
    1.17 +class SK_API SkPathMeasure : SkNoncopyable {
    1.18 +public:
    1.19 +    SkPathMeasure();
    1.20 +    /** Initialize the pathmeasure with the specified path. The path must remain valid
    1.21 +        for the lifetime of the measure object, or until setPath() is called with
    1.22 +        a different path (or null), since the measure object keeps a pointer to the
    1.23 +        path object (does not copy its data).
    1.24 +    */
    1.25 +    SkPathMeasure(const SkPath& path, bool forceClosed);
    1.26 +    ~SkPathMeasure();
    1.27 +
    1.28 +    /** Reset the pathmeasure with the specified path. The path must remain valid
    1.29 +        for the lifetime of the measure object, or until setPath() is called with
    1.30 +        a different path (or null), since the measure object keeps a pointer to the
    1.31 +        path object (does not copy its data).
    1.32 +    */
    1.33 +    void setPath(const SkPath*, bool forceClosed);
    1.34 +
    1.35 +    /** Return the total length of the current contour, or 0 if no path
    1.36 +        is associated (e.g. resetPath(null))
    1.37 +    */
    1.38 +    SkScalar getLength();
    1.39 +
    1.40 +    /** Pins distance to 0 <= distance <= getLength(), and then computes
    1.41 +        the corresponding position and tangent.
    1.42 +        Returns false if there is no path, or a zero-length path was specified, in which case
    1.43 +        position and tangent are unchanged.
    1.44 +    */
    1.45 +    bool SK_WARN_UNUSED_RESULT getPosTan(SkScalar distance, SkPoint* position,
    1.46 +                                         SkVector* tangent);
    1.47 +
    1.48 +    enum MatrixFlags {
    1.49 +        kGetPosition_MatrixFlag     = 0x01,
    1.50 +        kGetTangent_MatrixFlag      = 0x02,
    1.51 +        kGetPosAndTan_MatrixFlag    = kGetPosition_MatrixFlag | kGetTangent_MatrixFlag
    1.52 +    };
    1.53 +
    1.54 +    /** Pins distance to 0 <= distance <= getLength(), and then computes
    1.55 +        the corresponding matrix (by calling getPosTan).
    1.56 +        Returns false if there is no path, or a zero-length path was specified, in which case
    1.57 +        matrix is unchanged.
    1.58 +    */
    1.59 +    bool SK_WARN_UNUSED_RESULT getMatrix(SkScalar distance, SkMatrix* matrix,
    1.60 +                                  MatrixFlags flags = kGetPosAndTan_MatrixFlag);
    1.61 +
    1.62 +    /** Given a start and stop distance, return in dst the intervening segment(s).
    1.63 +        If the segment is zero-length, return false, else return true.
    1.64 +        startD and stopD are pinned to legal values (0..getLength()). If startD <= stopD
    1.65 +        then return false (and leave dst untouched).
    1.66 +        Begin the segment with a moveTo if startWithMoveTo is true
    1.67 +    */
    1.68 +    bool getSegment(SkScalar startD, SkScalar stopD, SkPath* dst, bool startWithMoveTo);
    1.69 +
    1.70 +    /** Return true if the current contour is closed()
    1.71 +    */
    1.72 +    bool isClosed();
    1.73 +
    1.74 +    /** Move to the next contour in the path. Return true if one exists, or false if
    1.75 +        we're done with the path.
    1.76 +    */
    1.77 +    bool nextContour();
    1.78 +
    1.79 +#ifdef SK_DEBUG
    1.80 +    void    dump();
    1.81 +#endif
    1.82 +
    1.83 +private:
    1.84 +    SkPath::Iter    fIter;
    1.85 +    const SkPath*   fPath;
    1.86 +    SkScalar        fLength;            // relative to the current contour
    1.87 +    int             fFirstPtIndex;      // relative to the current contour
    1.88 +    bool            fIsClosed;          // relative to the current contour
    1.89 +    bool            fForceClosed;
    1.90 +
    1.91 +    struct Segment {
    1.92 +        SkScalar    fDistance;  // total distance up to this point
    1.93 +        unsigned    fPtIndex : 15; // index into the fPts array
    1.94 +        unsigned    fTValue : 15;
    1.95 +        unsigned    fType : 2;
    1.96 +
    1.97 +        SkScalar getScalarT() const;
    1.98 +    };
    1.99 +    SkTDArray<Segment>  fSegments;
   1.100 +    SkTDArray<SkPoint>  fPts; // Points used to define the segments
   1.101 +
   1.102 +    static const Segment* NextSegment(const Segment*);
   1.103 +
   1.104 +    void     buildSegments();
   1.105 +    SkScalar compute_quad_segs(const SkPoint pts[3], SkScalar distance,
   1.106 +                                int mint, int maxt, int ptIndex);
   1.107 +    SkScalar compute_cubic_segs(const SkPoint pts[3], SkScalar distance,
   1.108 +                                int mint, int maxt, int ptIndex);
   1.109 +    const Segment* distanceToSegment(SkScalar distance, SkScalar* t);
   1.110 +};
   1.111 +
   1.112 +#endif

mercurial