no bug - Import translations from android-l10n r=release a=l10n CLOSED TREE
[gecko.git] / gfx / 2d / PathAnalysis.h
blob5821b8839eea84ed1fdeaa1c382be38b2fb21b50
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "2D.h"
8 #include <vector>
10 namespace mozilla {
11 namespace gfx {
13 struct FlatPathOp {
14 enum OpType {
15 OP_MOVETO,
16 OP_LINETO,
19 OpType mType;
20 Point mPoint;
23 class FlattenedPath : public PathSink {
24 public:
25 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FlattenedPath, override)
27 virtual void MoveTo(const Point& aPoint) override;
28 virtual void LineTo(const Point& aPoint) override;
29 virtual void BezierTo(const Point& aCP1, const Point& aCP2,
30 const Point& aCP3) override;
31 virtual void QuadraticBezierTo(const Point& aCP1, const Point& aCP2) override;
32 virtual void Close() override;
33 virtual void Arc(const Point& aOrigin, float aRadius, float aStartAngle,
34 float aEndAngle, bool aAntiClockwise = false) override;
36 virtual Point CurrentPoint() const override {
37 return mPathOps.empty() ? Point() : mPathOps[mPathOps.size() - 1].mPoint;
40 Float ComputeLength();
41 Point ComputePointAtLength(Float aLength, Point* aTangent);
43 private:
44 Float mCachedLength = 0.0f;
45 bool mCalculatedLength = false;
47 std::vector<FlatPathOp> mPathOps;
49 // Used to accelerate ComputePointAtLength for the common case of iterating
50 // forward along the path.
51 struct {
52 uint32_t mIndex = 0;
53 Float mLength = 0.0f;
54 Point mCurrentPoint;
55 Point mLastPointSinceMove;
57 void Reset() {
58 mIndex = 0;
59 mLength = 0.0f;
60 mCurrentPoint = Point();
61 mLastPointSinceMove = Point();
63 } mCursor;
66 } // namespace gfx
67 } // namespace mozilla