nsSVGPathDataParser.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /* -*- Mode: C++; tab-width: 8; 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. #ifndef __NS_SVGPATHDATAPARSER_H__
  6. #define __NS_SVGPATHDATAPARSER_H__
  7. #include "mozilla/Attributes.h"
  8. #include "mozilla/gfx/Point.h"
  9. #include "nsSVGDataParser.h"
  10. namespace mozilla {
  11. class SVGPathData;
  12. } // namespace mozilla
  13. ////////////////////////////////////////////////////////////////////////
  14. // nsSVGPathDataParser: a simple recursive descent parser that builds
  15. // DOMSVGPathSegs from path data strings. The grammar for path data
  16. // can be found in SVG CR 20001102, chapter 8.
  17. class nsSVGPathDataParser : public nsSVGDataParser
  18. {
  19. public:
  20. nsSVGPathDataParser(const nsAString& aValue,
  21. mozilla::SVGPathData* aList)
  22. : nsSVGDataParser(aValue),
  23. mPathSegList(aList)
  24. {
  25. MOZ_ASSERT(aList, "null path data");
  26. }
  27. bool Parse();
  28. private:
  29. bool ParseCoordPair(float& aX, float& aY);
  30. bool ParseFlag(bool& aFlag);
  31. bool ParsePath();
  32. bool IsStartOfSubPath() const;
  33. bool ParseSubPath();
  34. bool ParseSubPathElements();
  35. bool ParseSubPathElement(char16_t aCommandType,
  36. bool aAbsCoords);
  37. bool ParseMoveto();
  38. bool ParseClosePath();
  39. bool ParseLineto(bool aAbsCoords);
  40. bool ParseHorizontalLineto(bool aAbsCoords);
  41. bool ParseVerticalLineto(bool aAbsCoords);
  42. bool ParseCurveto(bool aAbsCoords);
  43. bool ParseSmoothCurveto(bool aAbsCoords);
  44. bool ParseQuadBezierCurveto(bool aAbsCoords);
  45. bool ParseSmoothQuadBezierCurveto(bool aAbsCoords);
  46. bool ParseEllipticalArc(bool aAbsCoords);
  47. mozilla::SVGPathData * const mPathSegList;
  48. };
  49. class nsSVGArcConverter
  50. {
  51. typedef mozilla::gfx::Point Point;
  52. public:
  53. nsSVGArcConverter(const Point& from,
  54. const Point& to,
  55. const Point& radii,
  56. double angle,
  57. bool largeArcFlag,
  58. bool sweepFlag);
  59. bool GetNextSegment(Point* cp1, Point* cp2, Point* to);
  60. protected:
  61. int32_t mNumSegs, mSegIndex;
  62. double mTheta, mDelta, mT;
  63. double mSinPhi, mCosPhi;
  64. double mRx, mRy;
  65. Point mFrom, mC;
  66. };
  67. #endif // __NS_SVGPATHDATAPARSER_H__