Coverage Report

Created: 2018-09-25 14:53

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