[SCM] WebKit Debian packaging branch, debian/experimental, updated. upstream/1.3.3-9427-gc2be6fc

krit at webkit.org krit at webkit.org
Wed Dec 22 12:17:33 UTC 2010


The following commit has been merged in the debian/experimental branch:
commit fe4451ac410781e0ff88e68e6d7e3db607e78b41
Author: krit at webkit.org <krit at webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Wed Aug 18 13:20:51 2010 +0000

    2010-08-18  Dirk Schulze  <krit at webkit.org>
    
            Reviewed by Nikolas Zimmermann.
    
            Use SVGPathParser logic to traverse states of a Path
            https://bugs.webkit.org/show_bug.cgi?id=44009
    
            Move the getPathSegAtLength logic from SVGPathSegList into a new SVGPathConsumer
            class: SVGPathTraversalStateBuilder.
            This allows us to get a SVGPathSeg at a given length for SVGPathByteStreams and SVGPathSegLists.
            It is also possible to use unaltered SVG path data, instead of just normalized path data.
            This is the final preparation to provide normalized and unaltered SVGPathSegLists
            on SVGPathElement.
    
            * Android.mk:
            * CMakeLists.txt:
            * GNUmakefile.am:
            * WebCore.gypi:
            * WebCore.pro:
            * WebCore.vcproj/WebCore.vcproj:
            * WebCore.xcodeproj/project.pbxproj:
            * svg/SVGAllInOne.cpp:
            * svg/SVGPathBuilder.h:
            (WebCore::SVGPathBuilder::nextPathSegment):
            (WebCore::SVGPathBuilder::quitEarlier):
            * svg/SVGPathByteStreamBuilder.h:
            (WebCore::SVGPathByteStreamBuilder::nextPathSegment):
            (WebCore::SVGPathByteStreamBuilder::quitEarlier):
            * svg/SVGPathConsumer.h:
            * svg/SVGPathElement.cpp:
            (WebCore::SVGPathElement::getPathSegAtLength):
            * svg/SVGPathElement.h:
            * svg/SVGPathElement.idl:
            * svg/SVGPathParser.cpp:
            (WebCore::SVGPathParser::parsePathDataFromSource):
            * svg/SVGPathParserFactory.cpp:
            (WebCore::globalSVGPathTraversalStateBuilder):
            (WebCore::SVGPathParserFactory::getSVGPathSegAtLengthFromSVGPathSegList):
            * svg/SVGPathParserFactory.h:
            * svg/SVGPathSegList.cpp:
            * svg/SVGPathSegList.h:
            * svg/SVGPathSegListBuilder.h:
            (WebCore::SVGPathSegListBuilder::nextPathSegment):
            (WebCore::SVGPathSegListBuilder::quitEarlier):
            * svg/SVGPathStringBuilder.h:
            (WebCore::SVGPathStringBuilder::nextPathSegment):
            (WebCore::SVGPathStringBuilder::quitEarlier):
            * svg/SVGPathTraversalStateBuilder.cpp: Added. New Consumer for SVGPathParser.
            (WebCore::SVGPathTraversalStateBuilder::SVGPathTraversalStateBuilder):
            (WebCore::SVGPathTraversalStateBuilder::moveTo):
            (WebCore::SVGPathTraversalStateBuilder::lineTo):
            (WebCore::SVGPathTraversalStateBuilder::curveToCubic):
            (WebCore::SVGPathTraversalStateBuilder::closePath):
            (WebCore::SVGPathTraversalStateBuilder::setDesiredLength):
            (WebCore::SVGPathTraversalStateBuilder::quitEarlier):
            (WebCore::SVGPathTraversalStateBuilder::nextPathSegment):
            (WebCore::SVGPathTraversalStateBuilder::pathSegmentIndex):
            * svg/SVGPathTraversalStateBuilder.h: Added.
            (WebCore::SVGPathTraversalStateBuilder::setCurrentTraversalState):
            (WebCore::SVGPathTraversalStateBuilder::cleanup):
            (WebCore::SVGPathTraversalStateBuilder::lineToHorizontal):
            (WebCore::SVGPathTraversalStateBuilder::lineToVertical):
            (WebCore::SVGPathTraversalStateBuilder::curveToCubicSmooth):
            (WebCore::SVGPathTraversalStateBuilder::curveToQuadratic):
            (WebCore::SVGPathTraversalStateBuilder::curveToQuadraticSmooth):
            (WebCore::SVGPathTraversalStateBuilder::arcTo):
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@65605 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebCore/Android.mk b/WebCore/Android.mk
index 66f6c0b..159b420 100644
--- a/WebCore/Android.mk
+++ b/WebCore/Android.mk
@@ -898,6 +898,7 @@ LOCAL_SRC_FILES := $(LOCAL_SRC_FILES) \
 	svg/SVGPathSegMoveto.cpp \
 	svg/SVGPathStringBuilder.cpp \
 	svg/SVGPathStringSource.cpp \
+	svg/SVGPathTraversalStateBuilder.cpp \
 	svg/SVGPatternElement.cpp \
 	svg/SVGPointList.cpp \
 	svg/SVGPolyElement.cpp \
diff --git a/WebCore/CMakeLists.txt b/WebCore/CMakeLists.txt
index a085110..2940015 100644
--- a/WebCore/CMakeLists.txt
+++ b/WebCore/CMakeLists.txt
@@ -1728,6 +1728,7 @@ IF (ENABLE_SVG)
         svg/SVGPathSegMoveto.cpp
         svg/SVGPathStringBuilder.cpp
         svg/SVGPathStringSource.cpp
+        svg/SVGPathTraversalStateBuilder.cpp
         svg/SVGPatternElement.cpp
         svg/SVGPointList.cpp
         svg/SVGPolyElement.cpp
diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index 21a2598..6c1ce2b 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -1,3 +1,70 @@
+2010-08-18  Dirk Schulze  <krit at webkit.org>
+
+        Reviewed by Nikolas Zimmermann.
+
+        Use SVGPathParser logic to traverse states of a Path
+        https://bugs.webkit.org/show_bug.cgi?id=44009
+
+        Move the getPathSegAtLength logic from SVGPathSegList into a new SVGPathConsumer
+        class: SVGPathTraversalStateBuilder.
+        This allows us to get a SVGPathSeg at a given length for SVGPathByteStreams and SVGPathSegLists.
+        It is also possible to use unaltered SVG path data, instead of just normalized path data.
+        This is the final preparation to provide normalized and unaltered SVGPathSegLists
+        on SVGPathElement.
+
+        * Android.mk:
+        * CMakeLists.txt:
+        * GNUmakefile.am:
+        * WebCore.gypi:
+        * WebCore.pro:
+        * WebCore.vcproj/WebCore.vcproj:
+        * WebCore.xcodeproj/project.pbxproj:
+        * svg/SVGAllInOne.cpp:
+        * svg/SVGPathBuilder.h:
+        (WebCore::SVGPathBuilder::nextPathSegment):
+        (WebCore::SVGPathBuilder::quitEarlier):
+        * svg/SVGPathByteStreamBuilder.h:
+        (WebCore::SVGPathByteStreamBuilder::nextPathSegment):
+        (WebCore::SVGPathByteStreamBuilder::quitEarlier):
+        * svg/SVGPathConsumer.h:
+        * svg/SVGPathElement.cpp:
+        (WebCore::SVGPathElement::getPathSegAtLength):
+        * svg/SVGPathElement.h:
+        * svg/SVGPathElement.idl:
+        * svg/SVGPathParser.cpp:
+        (WebCore::SVGPathParser::parsePathDataFromSource):
+        * svg/SVGPathParserFactory.cpp:
+        (WebCore::globalSVGPathTraversalStateBuilder):
+        (WebCore::SVGPathParserFactory::getSVGPathSegAtLengthFromSVGPathSegList):
+        * svg/SVGPathParserFactory.h:
+        * svg/SVGPathSegList.cpp:
+        * svg/SVGPathSegList.h:
+        * svg/SVGPathSegListBuilder.h:
+        (WebCore::SVGPathSegListBuilder::nextPathSegment):
+        (WebCore::SVGPathSegListBuilder::quitEarlier):
+        * svg/SVGPathStringBuilder.h:
+        (WebCore::SVGPathStringBuilder::nextPathSegment):
+        (WebCore::SVGPathStringBuilder::quitEarlier):
+        * svg/SVGPathTraversalStateBuilder.cpp: Added. New Consumer for SVGPathParser.
+        (WebCore::SVGPathTraversalStateBuilder::SVGPathTraversalStateBuilder):
+        (WebCore::SVGPathTraversalStateBuilder::moveTo):
+        (WebCore::SVGPathTraversalStateBuilder::lineTo):
+        (WebCore::SVGPathTraversalStateBuilder::curveToCubic):
+        (WebCore::SVGPathTraversalStateBuilder::closePath):
+        (WebCore::SVGPathTraversalStateBuilder::setDesiredLength):
+        (WebCore::SVGPathTraversalStateBuilder::quitEarlier):
+        (WebCore::SVGPathTraversalStateBuilder::nextPathSegment):
+        (WebCore::SVGPathTraversalStateBuilder::pathSegmentIndex):
+        * svg/SVGPathTraversalStateBuilder.h: Added.
+        (WebCore::SVGPathTraversalStateBuilder::setCurrentTraversalState):
+        (WebCore::SVGPathTraversalStateBuilder::cleanup):
+        (WebCore::SVGPathTraversalStateBuilder::lineToHorizontal):
+        (WebCore::SVGPathTraversalStateBuilder::lineToVertical):
+        (WebCore::SVGPathTraversalStateBuilder::curveToCubicSmooth):
+        (WebCore::SVGPathTraversalStateBuilder::curveToQuadratic):
+        (WebCore::SVGPathTraversalStateBuilder::curveToQuadraticSmooth):
+        (WebCore::SVGPathTraversalStateBuilder::arcTo):
+
 2010-08-18  Mahesh Kulkarni  <mahesh.kulkarni at nokia.com>
 
         Reviewed by Steve Block.
diff --git a/WebCore/GNUmakefile.am b/WebCore/GNUmakefile.am
index f79c130..9558fd3 100644
--- a/WebCore/GNUmakefile.am
+++ b/WebCore/GNUmakefile.am
@@ -4188,6 +4188,8 @@ webcore_sources += \
 	WebCore/svg/SVGPathStringBuilder.h \
 	WebCore/svg/SVGPathStringSource.cpp \
 	WebCore/svg/SVGPathStringSource.h \
+	WebCore/svg/SVGPathTraversalStateBuilder.cpp \
+	WebCore/svg/SVGPathTraversalStateBuilder.h \
 	WebCore/svg/SVGPatternElement.cpp \
 	WebCore/svg/SVGPatternElement.h \
 	WebCore/svg/SVGPointList.cpp \
diff --git a/WebCore/WebCore.gypi b/WebCore/WebCore.gypi
index c223bd4..8f0cba9 100644
--- a/WebCore/WebCore.gypi
+++ b/WebCore/WebCore.gypi
@@ -3933,6 +3933,8 @@
             'svg/SVGPathStringBuilder.h',
             'svg/SVGPathStringSource.cpp',
             'svg/SVGPathStringSource.h',
+            'svg/SVGPathTraversalStateBuilder.cpp',
+            'svg/SVGPathTraversalStateBuilder.h',
             'svg/SVGPatternElement.cpp',
             'svg/SVGPatternElement.h',
             'svg/SVGPointList.cpp',
diff --git a/WebCore/WebCore.pro b/WebCore/WebCore.pro
index e434a4e..529afb5 100644
--- a/WebCore/WebCore.pro
+++ b/WebCore/WebCore.pro
@@ -2926,6 +2926,7 @@ contains(DEFINES, ENABLE_SVG=1) {
         svg/SVGPathSegMoveto.cpp \
         svg/SVGPathStringBuilder.cpp \
         svg/SVGPathStringSource.cpp \
+        svg/SVGPathTraversalStateBuilder.cpp \
         svg/SVGPatternElement.cpp \
         svg/SVGPointList.cpp \
         svg/SVGPolyElement.cpp \
diff --git a/WebCore/WebCore.vcproj/WebCore.vcproj b/WebCore/WebCore.vcproj/WebCore.vcproj
index f20fd00..d51cb40 100644
--- a/WebCore/WebCore.vcproj/WebCore.vcproj
+++ b/WebCore/WebCore.vcproj/WebCore.vcproj
@@ -50161,6 +50161,10 @@
 				>
 			</File>
 			<File
+				RelativePath="..\svg\SVGPathTraversalStateBuilder.h"
+				>
+			</File>
+			<File
 				RelativePath="..\svg\SVGPatternElement.h"
 				>
 			</File>
diff --git a/WebCore/WebCore.xcodeproj/project.pbxproj b/WebCore/WebCore.xcodeproj/project.pbxproj
index 58a26f2..0038cf4 100644
--- a/WebCore/WebCore.xcodeproj/project.pbxproj
+++ b/WebCore/WebCore.xcodeproj/project.pbxproj
@@ -1503,6 +1503,8 @@
 		84B6B978120F13E500B8EFAF /* SVGPathSegListSource.h in Headers */ = {isa = PBXBuildFile; fileRef = 84B6B976120F13E500B8EFAF /* SVGPathSegListSource.h */; };
 		84BDA16B11358D2A00DBF64C /* RenderSVGResourceClipper.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 84BDA16911358D2A00DBF64C /* RenderSVGResourceClipper.cpp */; };
 		84BDA16C11358D2A00DBF64C /* RenderSVGResourceClipper.h in Headers */ = {isa = PBXBuildFile; fileRef = 84BDA16A11358D2A00DBF64C /* RenderSVGResourceClipper.h */; };
+		84C5B2FA1216DC810088B53A /* SVGPathTraversalStateBuilder.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 84C5B2F81216DC810088B53A /* SVGPathTraversalStateBuilder.cpp */; };
+		84C5B2FB1216DC810088B53A /* SVGPathTraversalStateBuilder.h in Headers */ = {isa = PBXBuildFile; fileRef = 84C5B2F91216DC810088B53A /* SVGPathTraversalStateBuilder.h */; };
 		84C6784C1214814700A92902 /* SVGPathBlender.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 84C6784A1214814700A92902 /* SVGPathBlender.cpp */; };
 		84C6784D1214814700A92902 /* SVGPathBlender.h in Headers */ = {isa = PBXBuildFile; fileRef = 84C6784B1214814700A92902 /* SVGPathBlender.h */; };
 		84D0C4041115F1D40018AA34 /* AffineTransform.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 84D0C4031115F1D40018AA34 /* AffineTransform.cpp */; };
@@ -7404,6 +7406,8 @@
 		84B6B976120F13E500B8EFAF /* SVGPathSegListSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SVGPathSegListSource.h; sourceTree = "<group>"; };
 		84BDA16911358D2A00DBF64C /* RenderSVGResourceClipper.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RenderSVGResourceClipper.cpp; sourceTree = "<group>"; };
 		84BDA16A11358D2A00DBF64C /* RenderSVGResourceClipper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RenderSVGResourceClipper.h; sourceTree = "<group>"; };
+		84C5B2F81216DC810088B53A /* SVGPathTraversalStateBuilder.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SVGPathTraversalStateBuilder.cpp; sourceTree = "<group>"; };
+		84C5B2F91216DC810088B53A /* SVGPathTraversalStateBuilder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SVGPathTraversalStateBuilder.h; sourceTree = "<group>"; };
 		84C6784A1214814700A92902 /* SVGPathBlender.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SVGPathBlender.cpp; sourceTree = "<group>"; };
 		84C6784B1214814700A92902 /* SVGPathBlender.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SVGPathBlender.h; sourceTree = "<group>"; };
 		84D0C4031115F1D40018AA34 /* AffineTransform.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = AffineTransform.cpp; path = transforms/AffineTransform.cpp; sourceTree = "<group>"; };
@@ -15528,6 +15532,8 @@
 				8419D2B8120E0C7600141F8F /* SVGPathStringBuilder.h */,
 				84300BD9120C9AED0021954A /* SVGPathStringSource.cpp */,
 				84300BD5120C9AAC0021954A /* SVGPathStringSource.h */,
+				84C5B2F81216DC810088B53A /* SVGPathTraversalStateBuilder.cpp */,
+				84C5B2F91216DC810088B53A /* SVGPathTraversalStateBuilder.h */,
 				B22278F10D00BF210071B782 /* SVGPatternElement.cpp */,
 				B22278F20D00BF210071B782 /* SVGPatternElement.h */,
 				B22278F30D00BF210071B782 /* SVGPatternElement.idl */,
@@ -20006,6 +20012,7 @@
 				84300BD8120C9AD40021954A /* SVGPathSource.h in Headers */,
 				8419D2BA120E0C7600141F8F /* SVGPathStringBuilder.h in Headers */,
 				84300BD6120C9AAC0021954A /* SVGPathStringSource.h in Headers */,
+				84C5B2FB1216DC810088B53A /* SVGPathTraversalStateBuilder.h in Headers */,
 				B2227A880D00BF220071B782 /* SVGPatternElement.h in Headers */,
 				B25599950D00D8BA00BB825C /* SVGPointLightSource.h in Headers */,
 				B2227A8C0D00BF220071B782 /* SVGPointList.h in Headers */,
@@ -22505,6 +22512,7 @@
 				B2227A830D00BF220071B782 /* SVGPathSegMoveto.cpp in Sources */,
 				8419D2B9120E0C7600141F8F /* SVGPathStringBuilder.cpp in Sources */,
 				84300BDA120C9AED0021954A /* SVGPathStringSource.cpp in Sources */,
+				84C5B2FA1216DC810088B53A /* SVGPathTraversalStateBuilder.cpp in Sources */,
 				B2227A870D00BF220071B782 /* SVGPatternElement.cpp in Sources */,
 				B2227A8B0D00BF220071B782 /* SVGPointList.cpp in Sources */,
 				B2227A8E0D00BF220071B782 /* SVGPolyElement.cpp in Sources */,
diff --git a/WebCore/svg/SVGAllInOne.cpp b/WebCore/svg/SVGAllInOne.cpp
index df8b916..2cb63af 100644
--- a/WebCore/svg/SVGAllInOne.cpp
+++ b/WebCore/svg/SVGAllInOne.cpp
@@ -130,6 +130,7 @@
 #include "SVGPathSegMoveto.cpp"
 #include "SVGPathStringBuilder.cpp"
 #include "SVGPathStringSource.cpp"
+#include "SVGPathTraversalStateBuilder.cpp"
 #include "SVGPatternElement.cpp"
 #include "SVGPointList.cpp"
 #include "SVGPolyElement.cpp"
diff --git a/WebCore/svg/SVGPathBuilder.h b/WebCore/svg/SVGPathBuilder.h
index 3a1088d..38eabd4 100644
--- a/WebCore/svg/SVGPathBuilder.h
+++ b/WebCore/svg/SVGPathBuilder.h
@@ -36,6 +36,8 @@ public:
     SVGPathBuilder();
 
     void setCurrentPath(Path* path) { m_path = path; }
+    virtual void incrementPathSegmentCount() { }
+    virtual bool continueConsuming() { return true; }
     virtual void cleanup() { m_path = 0; }
 
 private:
diff --git a/WebCore/svg/SVGPathByteStreamBuilder.h b/WebCore/svg/SVGPathByteStreamBuilder.h
index f1e7524..c89856f 100644
--- a/WebCore/svg/SVGPathByteStreamBuilder.h
+++ b/WebCore/svg/SVGPathByteStreamBuilder.h
@@ -34,6 +34,8 @@ public:
     SVGPathByteStreamBuilder();
 
     void setCurrentByteStream(SVGPathByteStream* byteStream) { m_byteStream = byteStream; }
+    virtual void incrementPathSegmentCount() { }
+    virtual bool continueConsuming() { return true; }
     virtual void cleanup() { m_byteStream = 0; }
 
 private:
diff --git a/WebCore/svg/SVGPathConsumer.h b/WebCore/svg/SVGPathConsumer.h
index b0deb52..629c1bf 100644
--- a/WebCore/svg/SVGPathConsumer.h
+++ b/WebCore/svg/SVGPathConsumer.h
@@ -42,6 +42,8 @@ enum PathParsingMode {
 
 class SVGPathConsumer : public Noncopyable {
 public:
+    virtual void incrementPathSegmentCount() = 0;
+    virtual bool continueConsuming() = 0;
     virtual void cleanup() = 0;
 
 public:
diff --git a/WebCore/svg/SVGPathElement.cpp b/WebCore/svg/SVGPathElement.cpp
index 2adc05f..6d801fb 100644
--- a/WebCore/svg/SVGPathElement.cpp
+++ b/WebCore/svg/SVGPathElement.cpp
@@ -69,9 +69,12 @@ FloatPoint SVGPathElement::getPointAtLength(float length)
     return toPathData().pointAtLength(length, ok);
 }
 
-unsigned long SVGPathElement::getPathSegAtLength(float length, ExceptionCode& ec)
+unsigned long SVGPathElement::getPathSegAtLength(float length)
 {
-    return pathSegList()->getPathSegAtLength(length, ec);
+    SVGPathParserFactory* factory = SVGPathParserFactory::self();
+    unsigned long pathSeg = 0;
+    factory->getSVGPathSegAtLengthFromSVGPathSegList(pathSegList(), length, pathSeg);
+    return pathSeg;
 }
 
 PassRefPtr<SVGPathSegClosePath> SVGPathElement::createSVGPathSegClosePath()
diff --git a/WebCore/svg/SVGPathElement.h b/WebCore/svg/SVGPathElement.h
index 718f05b..07612c6 100644
--- a/WebCore/svg/SVGPathElement.h
+++ b/WebCore/svg/SVGPathElement.h
@@ -62,7 +62,7 @@ namespace WebCore {
         virtual bool isValid() const { return SVGTests::isValid(); }
         float getTotalLength();
         FloatPoint getPointAtLength(float distance);
-        unsigned long getPathSegAtLength(float distance, ExceptionCode&);
+        unsigned long getPathSegAtLength(float distance);
 
         static PassRefPtr<SVGPathSegClosePath> createSVGPathSegClosePath();
         static PassRefPtr<SVGPathSegMovetoAbs> createSVGPathSegMovetoAbs(float x, float y);
diff --git a/WebCore/svg/SVGPathElement.idl b/WebCore/svg/SVGPathElement.idl
index 8506225..1c1dca7 100644
--- a/WebCore/svg/SVGPathElement.idl
+++ b/WebCore/svg/SVGPathElement.idl
@@ -37,8 +37,7 @@ module svg {
 
         float getTotalLength();
         SVGPoint getPointAtLength(in float distance);
-        unsigned long getPathSegAtLength(in float distance)
-            raises(DOMException, SVGException);
+        unsigned long getPathSegAtLength(in float distance);
 
         SVGPathSegClosePath createSVGPathSegClosePath();
 
diff --git a/WebCore/svg/SVGPathParser.cpp b/WebCore/svg/SVGPathParser.cpp
index c729dfb..66bd00f 100644
--- a/WebCore/svg/SVGPathParser.cpp
+++ b/WebCore/svg/SVGPathParser.cpp
@@ -366,6 +366,9 @@ bool SVGPathParser::parsePathDataFromSource(PathParsingMode pathParsingMode)
         default:
             return false;
         }
+        if (!m_consumer->continueConsuming())
+            return true;
+
         m_lastCommand = command;
 
         if (!m_source->hasMoreData())
@@ -382,6 +385,8 @@ bool SVGPathParser::parsePathDataFromSource(PathParsingMode pathParsingMode)
             && m_lastCommand != PathSegCurveToQuadraticSmoothAbs
             && m_lastCommand != PathSegCurveToQuadraticSmoothRel)
             m_controlPoint = m_currentPoint;
+
+        m_consumer->incrementPathSegmentCount();
     }
 
     return false;
diff --git a/WebCore/svg/SVGPathParserFactory.cpp b/WebCore/svg/SVGPathParserFactory.cpp
index 737e529..b251ec4 100644
--- a/WebCore/svg/SVGPathParserFactory.cpp
+++ b/WebCore/svg/SVGPathParserFactory.cpp
@@ -22,6 +22,7 @@
 #if ENABLE(SVG)
 #include "SVGPathParserFactory.h"
 
+#include "PathTraversalState.h"
 #include "SVGPathBlender.h"
 #include "SVGPathBuilder.h"
 #include "SVGPathByteStreamBuilder.h"
@@ -31,6 +32,7 @@
 #include "SVGPathSegListSource.h"
 #include "SVGPathStringBuilder.h"
 #include "SVGPathStringSource.h"
+#include "SVGPathTraversalStateBuilder.h"
 #include "StringBuilder.h"
 
 namespace WebCore {
@@ -74,6 +76,17 @@ static SVGPathStringBuilder* globalSVGPathStringBuilder()
     return s_builder;
 }
 
+static SVGPathTraversalStateBuilder* globalSVGPathTraversalStateBuilder(PathTraversalState& traversalState, float length)
+{
+    static SVGPathTraversalStateBuilder* s_builder = 0;
+    if (!s_builder)
+        s_builder = new SVGPathTraversalStateBuilder;
+
+    s_builder->setCurrentTraversalState(&traversalState);
+    s_builder->setDesiredLength(length);
+    return s_builder;
+}
+
 static SVGPathParser* globalSVGPathParser(SVGPathSource* source, SVGPathConsumer* consumer)
 {
     static SVGPathParser* s_parser = 0;
@@ -253,6 +266,23 @@ bool SVGPathParserFactory::buildAnimatedSVGPathByteStream(SVGPathByteStream* fro
     return ok;
 }
 
+bool SVGPathParserFactory::getSVGPathSegAtLengthFromSVGPathSegList(SVGPathSegList* pathSegList, float length, unsigned long& pathSeg)
+{
+    ASSERT(pathSegList);
+    if (!pathSegList->numberOfItems())
+        return false; 
+
+    PathTraversalState traversalState(PathTraversalState::TraversalSegmentAtLength);
+    SVGPathTraversalStateBuilder* builder = globalSVGPathTraversalStateBuilder(traversalState, length);
+
+    OwnPtr<SVGPathSegListSource> source = SVGPathSegListSource::create(pathSegList);
+    SVGPathParser* parser = globalSVGPathParser(source.get(), builder);
+    bool ok = parser->parsePathDataFromSource(NormalizedParsing);
+    pathSeg = builder->pathSegmentIndex();
+    parser->cleanup();
+    return ok;
+}
+
 }
 
 #endif
diff --git a/WebCore/svg/SVGPathParserFactory.h b/WebCore/svg/SVGPathParserFactory.h
index 64131c0..b8a2dd5 100644
--- a/WebCore/svg/SVGPathParserFactory.h
+++ b/WebCore/svg/SVGPathParserFactory.h
@@ -48,6 +48,8 @@ public:
 
     bool buildAnimatedSVGPathByteStream(SVGPathByteStream*, SVGPathByteStream*, OwnPtr<SVGPathByteStream>&, float);
 
+    bool getSVGPathSegAtLengthFromSVGPathSegList(SVGPathSegList*, float, unsigned long&);
+
 private:
     SVGPathParserFactory();
     ~SVGPathParserFactory();
diff --git a/WebCore/svg/SVGPathSegList.cpp b/WebCore/svg/SVGPathSegList.cpp
index b1397ba..3b86f55 100644
--- a/WebCore/svg/SVGPathSegList.cpp
+++ b/WebCore/svg/SVGPathSegList.cpp
@@ -2,6 +2,7 @@
  * Copyright (C) 2004, 2005, 2006, 2007, 2008 Nikolas Zimmermann <zimmermann at kde.org>
  * Copyright (C) 2004, 2005 Rob Buis <buis at kde.org>
  * Copyright (C) 2007 Eric Seidel <eric at webkit.org>
+ * Copyright (C) Research In Motion Limited 2010. All rights reserved.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -24,14 +25,6 @@
 #if ENABLE(SVG)
 #include "SVGPathSegList.h"
 
-#include "FloatConversion.h"
-#include "FloatPoint.h"
-#include "PathTraversalState.h"
-#include "SVGPathSegClosePath.h"
-#include "SVGPathSegMoveto.h"
-#include "SVGPathSegLineto.h"
-#include "SVGPathSegCurvetoCubic.h"
-
 namespace WebCore {
 
 SVGPathSegList::SVGPathSegList(const QualifiedName& attributeName)
@@ -43,59 +36,6 @@ SVGPathSegList::~SVGPathSegList()
 {
 }
 
-unsigned SVGPathSegList::getPathSegAtLength(double length, ExceptionCode& ec)
-{
-    // FIXME : to be useful this will need to support non-normalized SVGPathSegLists
-    int len = numberOfItems();
-    // FIXME: Eventually this will likely move to a "path applier"-like model, until then PathTraversalState is less useful as we could just use locals
-    PathTraversalState traversalState(PathTraversalState::TraversalSegmentAtLength);
-    traversalState.m_desiredLength = narrowPrecisionToFloat(length);
-    for (int i = 0; i < len; ++i) {
-        SVGPathSeg* segment = getItem(i, ec).get();
-        if (ec)
-            return 0;
-        float segmentLength = 0;
-        switch (segment->pathSegType()) {
-        case PathSegMoveToAbs:
-        {
-            SVGPathSegMovetoAbs* moveTo = static_cast<SVGPathSegMovetoAbs*>(segment);
-            segmentLength = traversalState.moveTo(FloatPoint(moveTo->x(), moveTo->y()));
-            break;
-        }
-        case PathSegLineToAbs:
-        {
-            SVGPathSegLinetoAbs* lineTo = static_cast<SVGPathSegLinetoAbs*>(segment);
-            segmentLength = traversalState.lineTo(FloatPoint(lineTo->x(), lineTo->y()));
-            break;
-        }
-        case PathSegCurveToCubicAbs:
-        {
-            SVGPathSegCurvetoCubicAbs* curveTo = static_cast<SVGPathSegCurvetoCubicAbs*>(segment);
-            segmentLength = traversalState.cubicBezierTo(FloatPoint(curveTo->x1(), curveTo->y1()),
-                                      FloatPoint(curveTo->x2(), curveTo->y2()),
-                                      FloatPoint(curveTo->x(), curveTo->y()));
-            break;
-        }
-        case PathSegClosePath:
-            segmentLength = traversalState.closeSubpath();
-            break;
-        default:
-            ASSERT(false); // FIXME: This only works with normalized/processed path data.
-            break;
-        }
-        traversalState.m_totalLength += segmentLength;
-        if ((traversalState.m_action == PathTraversalState::TraversalSegmentAtLength)
-            && (traversalState.m_totalLength >= traversalState.m_desiredLength)) {
-            return traversalState.m_segmentIndex;
-        }
-        traversalState.m_segmentIndex++;
-    }
-
-    // The SVG spec is unclear as to what to return when the distance is not on the path.
-    // WebKit/Opera/FF all return the last path segment if the distance exceeds the actual path length:
-    return traversalState.m_segmentIndex ? traversalState.m_segmentIndex - 1 : 0;
-}
-
 }
 
 #endif // ENABLE(SVG)
diff --git a/WebCore/svg/SVGPathSegList.h b/WebCore/svg/SVGPathSegList.h
index d3be215..f27c653 100644
--- a/WebCore/svg/SVGPathSegList.h
+++ b/WebCore/svg/SVGPathSegList.h
@@ -33,8 +33,6 @@ public:
     static PassRefPtr<SVGPathSegList> create(const QualifiedName& attributeName) { return adoptRef(new SVGPathSegList(attributeName)); }
     virtual ~SVGPathSegList();
 
-    unsigned getPathSegAtLength(double, ExceptionCode&);
-
 private:
     SVGPathSegList(const QualifiedName&);
 };
diff --git a/WebCore/svg/SVGPathSegListBuilder.h b/WebCore/svg/SVGPathSegListBuilder.h
index aa4a782..2fd2667 100644
--- a/WebCore/svg/SVGPathSegListBuilder.h
+++ b/WebCore/svg/SVGPathSegListBuilder.h
@@ -36,6 +36,8 @@ public:
     SVGPathSegListBuilder();
 
     void setCurrentSVGPathSegList(SVGPathSegList* pathSegList) { m_pathSegList = pathSegList; }
+    virtual void incrementPathSegmentCount() { }
+    virtual bool continueConsuming() { return true; }
     virtual void cleanup() { m_pathSegList = 0; }
 
 private:
diff --git a/WebCore/svg/SVGPathStringBuilder.h b/WebCore/svg/SVGPathStringBuilder.h
index f25f791..ebb8596 100644
--- a/WebCore/svg/SVGPathStringBuilder.h
+++ b/WebCore/svg/SVGPathStringBuilder.h
@@ -32,6 +32,8 @@ public:
     SVGPathStringBuilder();
 
     virtual void cleanup() { m_stringBuilder.clear(); }
+    virtual void incrementPathSegmentCount() { }
+    virtual bool continueConsuming() { return true; }
     String result() { return m_stringBuilder.toString(ConcatAddingSpacesBetweenIndividualStrings); }
 
 private:
diff --git a/WebCore/svg/SVGPathTraversalStateBuilder.cpp b/WebCore/svg/SVGPathTraversalStateBuilder.cpp
new file mode 100644
index 0000000..a4ef2fb
--- /dev/null
+++ b/WebCore/svg/SVGPathTraversalStateBuilder.cpp
@@ -0,0 +1,87 @@
+/*
+ * Copyright (C) 2004, 2005, 2006, 2007, 2008 Nikolas Zimmermann <zimmermann at kde.org>
+ * Copyright (C) 2004, 2005 Rob Buis <buis at kde.org>
+ * Copyright (C) 2007 Eric Seidel <eric at webkit.org>
+ * Copyright (C) Research In Motion Limited 2010. All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "config.h"
+
+#if ENABLE(SVG)
+#include "SVGPathTraversalStateBuilder.h"
+
+namespace WebCore {
+
+SVGPathTraversalStateBuilder::SVGPathTraversalStateBuilder()
+    : m_traversalState(0)
+    , m_desiredLength(0)
+{
+}
+
+void SVGPathTraversalStateBuilder::moveTo(const FloatPoint& targetPoint, bool, PathCoordinateMode)
+{
+    ASSERT(m_traversalState);
+    m_traversalState->m_totalLength += m_traversalState->moveTo(targetPoint);
+}
+
+void SVGPathTraversalStateBuilder::lineTo(const FloatPoint& targetPoint, PathCoordinateMode)
+{
+    ASSERT(m_traversalState);
+    m_traversalState->m_totalLength += m_traversalState->lineTo(targetPoint);
+}
+
+void SVGPathTraversalStateBuilder::curveToCubic(const FloatPoint& point1, const FloatPoint& point2, const FloatPoint& targetPoint, PathCoordinateMode)
+{
+    ASSERT(m_traversalState);
+    m_traversalState->m_totalLength += m_traversalState->cubicBezierTo(point1, point2, targetPoint);
+}
+
+void SVGPathTraversalStateBuilder::closePath()
+{
+    ASSERT(m_traversalState);
+    m_traversalState->m_totalLength += m_traversalState->closeSubpath();
+}
+
+void SVGPathTraversalStateBuilder::setDesiredLength(float desiredLength)
+{
+    ASSERT(m_traversalState);
+    m_traversalState->m_desiredLength = desiredLength;
+}
+
+bool SVGPathTraversalStateBuilder::continueConsuming()
+{
+    ASSERT(m_traversalState);
+    ASSERT(m_traversalState->m_action == PathTraversalState::TraversalSegmentAtLength);
+    return m_traversalState->m_totalLength < m_traversalState->m_desiredLength;
+}
+
+void SVGPathTraversalStateBuilder::incrementPathSegmentCount()
+{
+    ASSERT(m_traversalState);
+    ++m_traversalState->m_segmentIndex;
+}
+
+unsigned long SVGPathTraversalStateBuilder::pathSegmentIndex()
+{
+    ASSERT(m_traversalState);
+    return m_traversalState->m_segmentIndex;
+}
+
+}
+
+#endif // ENABLE(SVG)
diff --git a/WebCore/svg/SVGPathTraversalStateBuilder.h b/WebCore/svg/SVGPathTraversalStateBuilder.h
new file mode 100644
index 0000000..a5f3f79
--- /dev/null
+++ b/WebCore/svg/SVGPathTraversalStateBuilder.h
@@ -0,0 +1,65 @@
+/*
+ * Copyright (C) 2007 Eric Seidel <eric at webkit.org>
+ * Copyright (C) Research In Motion Limited 2010. All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef SVGPathTraversalStateBuilder_h
+#define SVGPathTraversalStateBuilder_h
+
+#if ENABLE(SVG)
+#include "FloatPoint.h"
+#include "PathTraversalState.h"
+#include "SVGPathConsumer.h"
+
+namespace WebCore {
+
+class SVGPathTraversalStateBuilder : public SVGPathConsumer {
+public:
+    SVGPathTraversalStateBuilder();
+
+    unsigned long pathSegmentIndex();
+    void setCurrentTraversalState(PathTraversalState* traversalState) { m_traversalState = traversalState; }
+    void setDesiredLength(float);
+    virtual void incrementPathSegmentCount();
+    virtual bool continueConsuming();
+    virtual void cleanup() { m_traversalState = 0; }
+
+private:
+    // Used in UnalteredParisng/NormalizedParsing modes.
+    virtual void moveTo(const FloatPoint&, bool closed, PathCoordinateMode);
+    virtual void lineTo(const FloatPoint&, PathCoordinateMode);
+    virtual void curveToCubic(const FloatPoint&, const FloatPoint&, const FloatPoint&, PathCoordinateMode);
+    virtual void closePath();
+
+private:
+    // Not used for PathTraversalState.
+    virtual void lineToHorizontal(float, PathCoordinateMode) { ASSERT_NOT_REACHED(); }
+    virtual void lineToVertical(float, PathCoordinateMode) { ASSERT_NOT_REACHED(); }
+    virtual void curveToCubicSmooth(const FloatPoint&, const FloatPoint&, PathCoordinateMode) { ASSERT_NOT_REACHED(); }
+    virtual void curveToQuadratic(const FloatPoint&, const FloatPoint&, PathCoordinateMode) { ASSERT_NOT_REACHED(); }
+    virtual void curveToQuadraticSmooth(const FloatPoint&, PathCoordinateMode) { ASSERT_NOT_REACHED(); }
+    virtual void arcTo(float, float, float, bool, bool, const FloatPoint&, PathCoordinateMode) { ASSERT_NOT_REACHED(); }
+
+    PathTraversalState* m_traversalState;
+    float m_desiredLength;
+};
+
+} // namespace WebCore
+
+#endif // ENABLE(SVG)
+#endif // SVGPathTraversalStateBuilder_h

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list