Make shrink-wrapping test a ref-test instead of pixel-test
[WebKit-https.git] / Source / WebCore / svg / SVGPathUtilities.cpp
index 79cac32..c41fa13 100644 (file)
@@ -26,6 +26,7 @@
 #include "SVGPathBuilder.h"
 #include "SVGPathByteStreamBuilder.h"
 #include "SVGPathByteStreamSource.h"
+#include "SVGPathConsumer.h"
 #include "SVGPathElement.h"
 #include "SVGPathParser.h"
 #include "SVGPathSegListBuilder.h"
@@ -330,4 +331,44 @@ bool getPointAtLengthOfSVGPathByteStream(SVGPathByteStream* stream, float length
     return ok;
 }
 
+static void pathIteratorForBuildingString(void* info, const PathElement* pathElement)
+{
+    SVGPathConsumer* consumer = static_cast<SVGPathConsumer*>(info);
+
+    switch (pathElement->type) {
+    case PathElementMoveToPoint:
+        consumer->moveTo(pathElement->points[0], false, AbsoluteCoordinates);
+        break;
+    case PathElementAddLineToPoint:
+        consumer->lineTo(pathElement->points[0], AbsoluteCoordinates);
+        break;
+    case PathElementAddQuadCurveToPoint:
+        consumer->curveToQuadratic(pathElement->points[0], pathElement->points[1], AbsoluteCoordinates);
+        break;
+    case PathElementAddCurveToPoint:
+        consumer->curveToCubic(pathElement->points[0], pathElement->points[1], pathElement->points[2], AbsoluteCoordinates);
+        break;
+    case PathElementCloseSubpath:
+        consumer->closePath();
+        break;
+
+    default:
+        ASSERT_NOT_REACHED();
+        break;
+    }
+}
+
+bool buildStringFromPath(const Path& path, String& string)
+{
+    // Ideally we would have a SVGPathPlatformPathSource, but it's not possible to manually iterate
+    // a path, only apply a function to all path elements at once.
+
+    SVGPathStringBuilder* builder = globalSVGPathStringBuilder();
+    path.apply(builder, &pathIteratorForBuildingString);
+    string = builder->result();
+    static_cast<SVGPathConsumer*>(builder)->cleanup();
+
+    return true;
+}
+
 }