2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2001-12-12 10:59:31 +03:00
|
|
|
|
2020-07-15 02:40:05 +03:00
|
|
|
#ifndef DOM_SVG_SVGPATHDATAPARSER_H_
|
|
|
|
#define DOM_SVG_SVGPATHDATAPARSER_H_
|
2001-12-12 10:59:31 +03:00
|
|
|
|
2013-05-30 00:43:41 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2013-10-24 16:46:38 +04:00
|
|
|
#include "mozilla/gfx/Point.h"
|
2018-12-21 23:19:15 +03:00
|
|
|
#include "SVGDataParser.h"
|
2001-12-12 10:59:31 +03:00
|
|
|
|
2010-11-08 18:07:00 +03:00
|
|
|
namespace mozilla {
|
|
|
|
class SVGPathData;
|
|
|
|
|
2001-12-12 10:59:31 +03:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
2018-12-21 23:19:15 +03:00
|
|
|
// SVGPathDataParser: a simple recursive descent parser that builds
|
2012-12-23 08:54:22 +04:00
|
|
|
// DOMSVGPathSegs from path data strings. The grammar for path data
|
2001-12-12 10:59:31 +03:00
|
|
|
// can be found in SVG CR 20001102, chapter 8.
|
|
|
|
|
2018-12-21 23:19:15 +03:00
|
|
|
class SVGPathDataParser : public SVGDataParser {
|
2013-10-29 21:15:39 +04:00
|
|
|
public:
|
2018-12-21 23:19:15 +03:00
|
|
|
SVGPathDataParser(const nsAString& aValue, mozilla::SVGPathData* aList)
|
|
|
|
: SVGDataParser(aValue), mPathSegList(aList) {
|
2013-10-29 21:15:39 +04:00
|
|
|
MOZ_ASSERT(aList, "null path data");
|
|
|
|
}
|
2001-12-12 10:59:31 +03:00
|
|
|
|
2013-10-29 21:15:39 +04:00
|
|
|
bool Parse();
|
2001-12-12 10:59:31 +03:00
|
|
|
|
2013-10-29 21:15:39 +04:00
|
|
|
private:
|
|
|
|
bool ParseCoordPair(float& aX, float& aY);
|
|
|
|
bool ParseFlag(bool& aFlag);
|
2001-12-12 10:59:31 +03:00
|
|
|
|
2013-10-29 21:15:39 +04:00
|
|
|
bool ParsePath();
|
|
|
|
bool IsStartOfSubPath() const;
|
|
|
|
bool ParseSubPath();
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2013-10-29 21:15:39 +04:00
|
|
|
bool ParseSubPathElements();
|
2014-01-04 19:02:17 +04:00
|
|
|
bool ParseSubPathElement(char16_t aCommandType, bool aAbsCoords);
|
2013-10-29 21:15:39 +04:00
|
|
|
|
|
|
|
bool ParseMoveto();
|
|
|
|
bool ParseClosePath();
|
|
|
|
bool ParseLineto(bool aAbsCoords);
|
|
|
|
bool ParseHorizontalLineto(bool aAbsCoords);
|
|
|
|
bool ParseVerticalLineto(bool aAbsCoords);
|
|
|
|
bool ParseCurveto(bool aAbsCoords);
|
|
|
|
bool ParseSmoothCurveto(bool aAbsCoords);
|
|
|
|
bool ParseQuadBezierCurveto(bool aAbsCoords);
|
|
|
|
bool ParseSmoothQuadBezierCurveto(bool aAbsCoords);
|
|
|
|
bool ParseEllipticalArc(bool aAbsCoords);
|
|
|
|
|
|
|
|
mozilla::SVGPathData* const mPathSegList;
|
|
|
|
};
|
2006-05-03 21:01:28 +04:00
|
|
|
|
2018-12-21 23:19:15 +03:00
|
|
|
class SVGArcConverter {
|
2020-07-15 13:37:55 +03:00
|
|
|
using Point = mozilla::gfx::Point;
|
2013-10-24 16:46:38 +04:00
|
|
|
|
2006-05-03 21:01:28 +04:00
|
|
|
public:
|
2018-12-21 23:19:15 +03:00
|
|
|
SVGArcConverter(const Point& from, const Point& to, const Point& radii,
|
|
|
|
double angle, bool largeArcFlag, bool sweepFlag);
|
2013-10-24 16:46:38 +04:00
|
|
|
bool GetNextSegment(Point* cp1, Point* cp2, Point* to);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2006-05-03 21:01:28 +04:00
|
|
|
protected:
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t mNumSegs, mSegIndex;
|
2010-11-08 18:07:00 +03:00
|
|
|
double mTheta, mDelta, mT;
|
|
|
|
double mSinPhi, mCosPhi;
|
|
|
|
double mRx, mRy;
|
2013-10-24 16:46:38 +04:00
|
|
|
Point mFrom, mC;
|
2006-05-03 21:01:28 +04:00
|
|
|
};
|
|
|
|
|
2018-12-21 23:19:15 +03:00
|
|
|
} // namespace mozilla
|
|
|
|
|
2020-07-15 02:40:05 +03:00
|
|
|
#endif // DOM_SVG_SVGPATHDATAPARSER_H_
|