25 #include "wtf/Platform.h"
39 SVGPathSegList::SVGPathSegList(
const QualifiedName& attributeName)
40 : SVGList<RefPtr<SVGPathSeg> >(attributeName)
44 SVGPathSegList::~SVGPathSegList()
48 unsigned SVGPathSegList::getPathSegAtLength(
double)
52 int len = numberOfItems();
54 PathTraversalState traversalState(PathTraversalState::TraversalSegmentAtLength);
55 for (
int i = 0; i < len; ++i) {
56 SVGPathSeg* segment =
getItem(i, ec).get();
57 float segmentLength = 0;
58 switch (segment->pathSegType()) {
59 case SVGPathSeg::PATHSEG_MOVETO_ABS:
61 SVGPathSegMovetoAbs* moveTo =
static_cast<SVGPathSegMovetoAbs*
>(segment);
62 segmentLength = traversalState.moveTo(FloatPoint(moveTo->x(), moveTo->y()));
65 case SVGPathSeg::PATHSEG_LINETO_ABS:
67 SVGPathSegLinetoAbs* lineTo =
static_cast<SVGPathSegLinetoAbs*
>(segment);
68 segmentLength = traversalState.lineTo(FloatPoint(lineTo->x(), lineTo->y()));
71 case SVGPathSeg::PATHSEG_CURVETO_CUBIC_ABS:
73 SVGPathSegCurvetoCubicAbs* curveTo =
static_cast<SVGPathSegCurvetoCubicAbs*
>(segment);
74 segmentLength = traversalState.cubicBezierTo(FloatPoint(curveTo->x1(), curveTo->y1()),
75 FloatPoint(curveTo->x2(), curveTo->y2()),
76 FloatPoint(curveTo->x(), curveTo->y()));
79 case SVGPathSeg::PATHSEG_CLOSEPATH:
80 segmentLength = traversalState.closeSubpath();
86 traversalState.m_totalLength += segmentLength;
87 if ((traversalState.m_action == PathTraversalState::TraversalSegmentAtLength)
88 && (traversalState.m_totalLength > traversalState.m_desiredLength)) {
89 return traversalState.m_segmentIndex;
91 traversalState.m_segmentIndex++;
101 ExceptionCode ec = 0;
102 int len = numberOfItems();
103 for (
int i = 0; i < len; ++i) {
104 SVGPathSeg* segment =
getItem(i, ec).get();
105 switch (segment->pathSegType())
107 case SVGPathSeg::PATHSEG_MOVETO_ABS:
109 SVGPathSegMovetoAbs* moveTo =
static_cast<SVGPathSegMovetoAbs*
>(segment);
110 pathData.moveTo(FloatPoint(moveTo->x(), moveTo->y()));
113 case SVGPathSeg::PATHSEG_LINETO_ABS:
115 SVGPathSegLinetoAbs* lineTo =
static_cast<SVGPathSegLinetoAbs*
>(segment);
116 pathData.addLineTo(FloatPoint(lineTo->x(), lineTo->y()));
119 case SVGPathSeg::PATHSEG_CURVETO_CUBIC_ABS:
121 SVGPathSegCurvetoCubicAbs* curveTo =
static_cast<SVGPathSegCurvetoCubicAbs*
>(segment);
122 pathData.addBezierCurveTo(FloatPoint(curveTo->x1(), curveTo->y1()),
123 FloatPoint(curveTo->x2(), curveTo->y2()),
124 FloatPoint(curveTo->x(), curveTo->y()));
127 case SVGPathSeg::PATHSEG_CLOSEPATH:
128 pathData.closeSubpath();
141 #endif // ENABLE(SVG)