2011-05-20 Dirk Schulze <krit@webkit.org>
authorkrit@webkit.org <krit@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 21 May 2011 06:44:01 +0000 (06:44 +0000)
committerkrit@webkit.org <krit@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 21 May 2011 06:44:01 +0000 (06:44 +0000)
        Reviewed by Nikolas Zimmermann.

        Share more code in PathTraversalState
        https://bugs.webkit.org/show_bug.cgi?id=61238

        Share more code between SVGPathTraversalStateBuilder and Path in PathTraversalState.

        No change in functionality, so no new tests.

        * platform/graphics/Path.cpp:
        (WebCore::pathLengthApplierFunction):
        * platform/graphics/PathTraversalState.cpp:
        (WebCore::PathTraversalState::processSegment):
        * platform/graphics/PathTraversalState.h:
        * svg/SVGPathTraversalStateBuilder.cpp:
        (WebCore::SVGPathTraversalStateBuilder::continueConsuming):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@87011 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/platform/graphics/Path.cpp
Source/WebCore/platform/graphics/PathTraversalState.cpp
Source/WebCore/platform/graphics/PathTraversalState.h
Source/WebCore/svg/SVGPathTraversalStateBuilder.cpp

index a6cafc2..48545c9 100644 (file)
@@ -1,3 +1,22 @@
+2011-05-20  Dirk Schulze  <krit@webkit.org>
+
+        Reviewed by Nikolas Zimmermann.
+
+        Share more code in PathTraversalState
+        https://bugs.webkit.org/show_bug.cgi?id=61238
+
+        Share more code between SVGPathTraversalStateBuilder and Path in PathTraversalState.
+
+        No change in functionality, so no new tests.
+
+        * platform/graphics/Path.cpp:
+        (WebCore::pathLengthApplierFunction):
+        * platform/graphics/PathTraversalState.cpp:
+        (WebCore::PathTraversalState::processSegment):
+        * platform/graphics/PathTraversalState.h:
+        * svg/SVGPathTraversalStateBuilder.cpp:
+        (WebCore::SVGPathTraversalStateBuilder::continueConsuming):
+
 2011-05-21  Nikolas Zimmermann  <nzimmermann@rim.com>
 
         Reviewed by Rob Buis.
index da09c76..4e7a848 100644 (file)
@@ -46,7 +46,6 @@ static void pathLengthApplierFunction(void* info, const PathElement* element)
     PathTraversalState& traversalState = *static_cast<PathTraversalState*>(info);
     if (traversalState.m_success)
         return;
-    traversalState.m_previous = traversalState.m_current;
     FloatPoint* points = element->points;
     float segmentLength = 0;
     switch (element->type) {
@@ -67,20 +66,7 @@ static void pathLengthApplierFunction(void* info, const PathElement* element)
             break;
     }
     traversalState.m_totalLength += segmentLength; 
-    if ((traversalState.m_action == PathTraversalState::TraversalPointAtLength || 
-         traversalState.m_action == PathTraversalState::TraversalNormalAngleAtLength) &&
-        (traversalState.m_totalLength >= traversalState.m_desiredLength)) {
-        FloatSize change = traversalState.m_current - traversalState.m_previous;
-        float slope = atan2f(change.height(), change.width());
-
-        if (traversalState.m_action == PathTraversalState::TraversalPointAtLength) {
-            float offset = traversalState.m_desiredLength - traversalState.m_totalLength;
-            traversalState.m_current.move(offset * cosf(slope), offset * sinf(slope));
-        } else
-            traversalState.m_normalAngle = rad2deg(slope);
-
-        traversalState.m_success = true;
-    }
+    traversalState.processSegment();
 }
 
 float Path::length() const
index 95769d0..139c5ad 100644 (file)
@@ -203,5 +203,23 @@ float PathTraversalState::cubicBezierTo(const FloatPoint& newControl1, const Flo
     return distance;
 }
 
+void PathTraversalState::processSegment()
+{
+    if (m_action == TraversalSegmentAtLength && m_totalLength >= m_desiredLength)
+        m_success = true;
+        
+    if ((m_action == TraversalPointAtLength || m_action == TraversalNormalAngleAtLength) && m_totalLength >= m_desiredLength) {
+        FloatSize change = m_current - m_previous;
+        float slope = atan2f(change.height(), change.width());
+        if (m_action == TraversalPointAtLength) {
+            float offset = m_desiredLength - m_totalLength;
+            m_current.move(offset * cosf(slope), offset * sinf(slope));
+        } else
+            m_normalAngle = rad2deg(slope);
+        m_success = true;
+    }
+    m_previous = m_current;
+}
+
 }
 
index 08e38a1..6a29dcd 100644 (file)
@@ -46,6 +46,8 @@ public:
     float lineTo(const FloatPoint&);
     float quadraticBezierTo(const FloatPoint& newControl, const FloatPoint& newEnd);
     float cubicBezierTo(const FloatPoint& newControl1, const FloatPoint& newControl2, const FloatPoint& newEnd);
+    
+    void processSegment();
 
 public:
     PathTraversalAction m_action;
index 314e335..2bca5a2 100644 (file)
@@ -66,24 +66,7 @@ void SVGPathTraversalStateBuilder::setDesiredLength(float desiredLength)
 bool SVGPathTraversalStateBuilder::continueConsuming()
 {
     ASSERT(m_traversalState);    
-    if (m_traversalState->m_action == PathTraversalState::TraversalSegmentAtLength
-        && m_traversalState->m_totalLength >= m_traversalState->m_desiredLength)
-        m_traversalState->m_success = true;
-    
-    if ((m_traversalState->m_action == PathTraversalState::TraversalPointAtLength
-         || m_traversalState->m_action == PathTraversalState::TraversalNormalAngleAtLength)
-        && m_traversalState->m_totalLength >= m_traversalState->m_desiredLength) {
-        FloatSize change = m_traversalState->m_current - m_traversalState->m_previous;
-        float slope = atan2f(change.height(), change.width());
-        if (m_traversalState->m_action == PathTraversalState::TraversalPointAtLength) {
-            float offset = m_traversalState->m_desiredLength - m_traversalState->m_totalLength;
-            m_traversalState->m_current.move(offset * cosf(slope), offset * sinf(slope));
-        } else
-            m_traversalState->m_normalAngle = rad2deg(slope);
-        m_traversalState->m_success = true;
-    }
-    m_traversalState->m_previous = m_traversalState->m_current;
-
+    m_traversalState->processSegment();
     return !m_traversalState->m_success;
 }