Line data Source code
1 : /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 : * This Source Code Form is subject to the terms of the Mozilla Public
3 : * License, v. 2.0. If a copy of the MPL was not distributed with this
4 : * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 :
6 : #include "2D.h"
7 : #include <vector>
8 :
9 : namespace mozilla {
10 : namespace gfx {
11 :
12 0 : struct FlatPathOp
13 : {
14 : enum OpType {
15 : OP_MOVETO,
16 : OP_LINETO,
17 : };
18 :
19 : OpType mType;
20 : Point mPoint;
21 : };
22 :
23 0 : class FlattenedPath : public PathSink
24 : {
25 : public:
26 0 : MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FlattenedPath)
27 0 : FlattenedPath() : mCachedLength(0)
28 0 : , mCalculatedLength(false)
29 : {
30 0 : }
31 :
32 : virtual void MoveTo(const Point &aPoint);
33 : virtual void LineTo(const Point &aPoint);
34 : virtual void BezierTo(const Point &aCP1,
35 : const Point &aCP2,
36 : const Point &aCP3);
37 : virtual void QuadraticBezierTo(const Point &aCP1,
38 : const Point &aCP2);
39 : virtual void Close();
40 : virtual void Arc(const Point &aOrigin, float aRadius, float aStartAngle,
41 : float aEndAngle, bool aAntiClockwise = false);
42 :
43 0 : virtual Point CurrentPoint() const { return mPathOps.empty() ? Point() : mPathOps[mPathOps.size() - 1].mPoint; }
44 :
45 : Float ComputeLength();
46 : Point ComputePointAtLength(Float aLength, Point *aTangent);
47 :
48 : private:
49 : Float mCachedLength;
50 : bool mCalculatedLength;
51 : Point mLastMove;
52 :
53 : std::vector<FlatPathOp> mPathOps;
54 : };
55 :
56 : } // namespace gfx
57 : } // namespace mozilla
|