PathAnalysis.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. #include "2D.h"
  6. #include <vector>
  7. namespace mozilla {
  8. namespace gfx {
  9. struct FlatPathOp
  10. {
  11. enum OpType {
  12. OP_MOVETO,
  13. OP_LINETO,
  14. };
  15. OpType mType;
  16. Point mPoint;
  17. };
  18. class FlattenedPath : public PathSink
  19. {
  20. public:
  21. MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FlattenedPath)
  22. FlattenedPath() : mCachedLength(0)
  23. , mCalculatedLength(false)
  24. {
  25. }
  26. virtual void MoveTo(const Point &aPoint);
  27. virtual void LineTo(const Point &aPoint);
  28. virtual void BezierTo(const Point &aCP1,
  29. const Point &aCP2,
  30. const Point &aCP3);
  31. virtual void QuadraticBezierTo(const Point &aCP1,
  32. const Point &aCP2);
  33. virtual void Close();
  34. virtual void Arc(const Point &aOrigin, float aRadius, float aStartAngle,
  35. float aEndAngle, bool aAntiClockwise = false);
  36. virtual Point CurrentPoint() const { return mPathOps.empty() ? Point() : mPathOps[mPathOps.size() - 1].mPoint; }
  37. Float ComputeLength();
  38. Point ComputePointAtLength(Float aLength, Point *aTangent);
  39. private:
  40. Float mCachedLength;
  41. bool mCalculatedLength;
  42. Point mLastMove;
  43. std::vector<FlatPathOp> mPathOps;
  44. };
  45. } // namespace gfx
  46. } // namespace mozilla