2 * Copyright (C) 2012 Google, Inc.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
20 #ifndef SVGSubpathData_h
21 #define SVGSubpathData_h
23 #include "platform/graphics/Path.h"
24 #include "wtf/Vector.h"
28 class SVGSubpathData {
30 SVGSubpathData(Vector<FloatPoint>& zeroLengthSubpathLocations)
31 : m_zeroLengthSubpathLocations(zeroLengthSubpathLocations)
32 , m_haveSeenMoveOnly(true)
33 , m_pathIsZeroLength(true)
35 m_lastPoint.set(0, 0);
36 m_movePoint.set(0, 0);
39 static void updateFromPathElement(void* info, const PathElement* element)
41 SVGSubpathData* subpathFinder = static_cast<SVGSubpathData*>(info);
42 switch (element->type) {
43 case PathElementMoveToPoint:
44 if (subpathFinder->m_pathIsZeroLength && !subpathFinder->m_haveSeenMoveOnly)
45 subpathFinder->m_zeroLengthSubpathLocations.append(subpathFinder->m_lastPoint);
46 subpathFinder->m_lastPoint = subpathFinder->m_movePoint = element->points[0];
47 subpathFinder->m_haveSeenMoveOnly = true;
48 subpathFinder->m_pathIsZeroLength = true;
50 case PathElementAddLineToPoint:
51 if (subpathFinder->m_lastPoint != element->points[0]) {
52 subpathFinder->m_pathIsZeroLength = false;
53 subpathFinder->m_lastPoint = element->points[0];
55 subpathFinder->m_haveSeenMoveOnly = false;
57 case PathElementAddQuadCurveToPoint:
58 if (subpathFinder->m_lastPoint != element->points[0] || element->points[0] != element->points[1]) {
59 subpathFinder->m_pathIsZeroLength = false;
60 subpathFinder->m_lastPoint = element->points[1];
62 subpathFinder->m_haveSeenMoveOnly = false;
64 case PathElementAddCurveToPoint:
65 if (subpathFinder->m_lastPoint != element->points[0] || element->points[0] != element->points[1] || element->points[1] != element->points[2]) {
66 subpathFinder->m_pathIsZeroLength = false;
67 subpathFinder->m_lastPoint = element->points[2];
69 subpathFinder->m_haveSeenMoveOnly = false;
71 case PathElementCloseSubpath:
72 if (subpathFinder->m_pathIsZeroLength)
73 subpathFinder->m_zeroLengthSubpathLocations.append(subpathFinder->m_lastPoint);
74 subpathFinder->m_haveSeenMoveOnly = true; // This is an implicit move for the next element
75 subpathFinder->m_pathIsZeroLength = true; // A new sub-path also starts here
76 subpathFinder->m_lastPoint = subpathFinder->m_movePoint;
83 if (m_pathIsZeroLength && !m_haveSeenMoveOnly)
84 m_zeroLengthSubpathLocations.append(m_lastPoint);
88 Vector<FloatPoint>& m_zeroLengthSubpathLocations;
89 FloatPoint m_lastPoint;
90 FloatPoint m_movePoint;
91 bool m_haveSeenMoveOnly;
92 bool m_pathIsZeroLength;
97 #endif // SVGSubpathData_h