| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (C) 2012 Google, Inc. | |
| 3 * | |
| 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. | |
| 8 * | |
| 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. | |
| 13 * | |
| 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. | |
| 18 */ | |
| 19 | |
| 20 #ifndef SVGSubpathData_h | |
| 21 #define SVGSubpathData_h | |
| 22 | |
| 23 #include "platform/graphics/Path.h" | |
| 24 #include "wtf/Allocator.h" | |
| 25 #include "wtf/Vector.h" | |
| 26 | |
| 27 namespace blink { | |
| 28 | |
| 29 class SVGSubpathData { | |
| 30 STACK_ALLOCATED(); | |
| 31 public: | |
| 32 SVGSubpathData(Vector<FloatPoint>& zeroLengthSubpathLocations) | |
| 33 : m_zeroLengthSubpathLocations(zeroLengthSubpathLocations) | |
| 34 , m_haveSeenMoveOnly(true) | |
| 35 , m_pathIsZeroLength(true) | |
| 36 { | |
| 37 m_lastPoint.set(0, 0); | |
| 38 m_movePoint.set(0, 0); | |
| 39 } | |
| 40 | |
| 41 static void updateFromPathElement(void* info, const PathElement* element) | |
| 42 { | |
| 43 SVGSubpathData* subpathFinder = static_cast<SVGSubpathData*>(info); | |
| 44 switch (element->type) { | |
| 45 case PathElementMoveToPoint: | |
| 46 if (subpathFinder->m_pathIsZeroLength && !subpathFinder->m_haveSeenM
oveOnly) | |
| 47 subpathFinder->m_zeroLengthSubpathLocations.append(subpathFinder
->m_lastPoint); | |
| 48 subpathFinder->m_lastPoint = subpathFinder->m_movePoint = element->p
oints[0]; | |
| 49 subpathFinder->m_haveSeenMoveOnly = true; | |
| 50 subpathFinder->m_pathIsZeroLength = true; | |
| 51 break; | |
| 52 case PathElementAddLineToPoint: | |
| 53 if (subpathFinder->m_lastPoint != element->points[0]) { | |
| 54 subpathFinder->m_pathIsZeroLength = false; | |
| 55 subpathFinder->m_lastPoint = element->points[0]; | |
| 56 } | |
| 57 subpathFinder->m_haveSeenMoveOnly = false; | |
| 58 break; | |
| 59 case PathElementAddQuadCurveToPoint: | |
| 60 if (subpathFinder->m_lastPoint != element->points[0] || element->poi
nts[0] != element->points[1]) { | |
| 61 subpathFinder->m_pathIsZeroLength = false; | |
| 62 subpathFinder->m_lastPoint = element->points[1]; | |
| 63 } | |
| 64 subpathFinder->m_haveSeenMoveOnly = false; | |
| 65 break; | |
| 66 case PathElementAddCurveToPoint: | |
| 67 if (subpathFinder->m_lastPoint != element->points[0] || element->poi
nts[0] != element->points[1] || element->points[1] != element->points[2]) { | |
| 68 subpathFinder->m_pathIsZeroLength = false; | |
| 69 subpathFinder->m_lastPoint = element->points[2]; | |
| 70 } | |
| 71 subpathFinder->m_haveSeenMoveOnly = false; | |
| 72 break; | |
| 73 case PathElementCloseSubpath: | |
| 74 if (subpathFinder->m_pathIsZeroLength) | |
| 75 subpathFinder->m_zeroLengthSubpathLocations.append(subpathFinder
->m_lastPoint); | |
| 76 subpathFinder->m_haveSeenMoveOnly = true; // This is an implicit mov
e for the next element | |
| 77 subpathFinder->m_pathIsZeroLength = true; // A new sub-path also sta
rts here | |
| 78 subpathFinder->m_lastPoint = subpathFinder->m_movePoint; | |
| 79 break; | |
| 80 } | |
| 81 } | |
| 82 | |
| 83 void pathIsDone() | |
| 84 { | |
| 85 if (m_pathIsZeroLength && !m_haveSeenMoveOnly) | |
| 86 m_zeroLengthSubpathLocations.append(m_lastPoint); | |
| 87 } | |
| 88 | |
| 89 private: | |
| 90 Vector<FloatPoint>& m_zeroLengthSubpathLocations; | |
| 91 FloatPoint m_lastPoint; | |
| 92 FloatPoint m_movePoint; | |
| 93 bool m_haveSeenMoveOnly; | |
| 94 bool m_pathIsZeroLength; | |
| 95 }; | |
| 96 | |
| 97 } | |
| 98 | |
| 99 #endif // SVGSubpathData_h | |
| OLD | NEW |