1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/2d/PathAnalysis.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,57 @@ 1.4 +/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- 1.5 + * This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#include "2D.h" 1.10 +#include <vector> 1.11 + 1.12 +namespace mozilla { 1.13 +namespace gfx { 1.14 + 1.15 +struct FlatPathOp 1.16 +{ 1.17 + enum OpType { 1.18 + OP_MOVETO, 1.19 + OP_LINETO, 1.20 + }; 1.21 + 1.22 + OpType mType; 1.23 + Point mPoint; 1.24 +}; 1.25 + 1.26 +class FlattenedPath : public PathSink 1.27 +{ 1.28 +public: 1.29 + MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FlattenedPath) 1.30 + FlattenedPath() : mCachedLength(0) 1.31 + , mCalculatedLength(false) 1.32 + { 1.33 + } 1.34 + 1.35 + virtual void MoveTo(const Point &aPoint); 1.36 + virtual void LineTo(const Point &aPoint); 1.37 + virtual void BezierTo(const Point &aCP1, 1.38 + const Point &aCP2, 1.39 + const Point &aCP3); 1.40 + virtual void QuadraticBezierTo(const Point &aCP1, 1.41 + const Point &aCP2); 1.42 + virtual void Close(); 1.43 + virtual void Arc(const Point &aOrigin, float aRadius, float aStartAngle, 1.44 + float aEndAngle, bool aAntiClockwise = false); 1.45 + 1.46 + virtual Point CurrentPoint() const { return mPathOps.empty() ? Point() : mPathOps[mPathOps.size() - 1].mPoint; } 1.47 + 1.48 + Float ComputeLength(); 1.49 + Point ComputePointAtLength(Float aLength, Point *aTangent); 1.50 + 1.51 +private: 1.52 + Float mCachedLength; 1.53 + bool mCalculatedLength; 1.54 + Point mLastMove; 1.55 + 1.56 + std::vector<FlatPathOp> mPathOps; 1.57 +}; 1.58 + 1.59 +} 1.60 +}