[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 11:49:31 UTC 2010


The following commit has been merged in the debian/experimental branch:
commit 1379a3fe22b91ef1612fa710960aacbe1f80e460
Author: krit at webkit.org <krit at webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Sun Aug 8 16:10:48 2010 +0000

    2010-08-08  Dirk Schulze  <krit at webkit.org>
    
            Reviewed by Nikolas Zimmermann.
    
            Add missing String builder for SVGPathParser
            https://bugs.webkit.org/show_bug.cgi?id=43682
    
            Introduces SVGPathStringBuilder. SVGPathParser clients, like normalized and unaltered
            SVGPathSegLists or SVGPathByteStreams, can be parsed and transformed to a string.
            StringBuilder can create a string of individual strings, seperated by spaces now.
            Share more code in SVGPathParserFactory and use a common general concept to manage SVG path
            data parsing.
    
            Doesn't affect any tests.
    
            * Android.mk:
            * GNUmakefile.am:
            * WebCore.gypi:
            * WebCore.pro:
            * WebCore.vcproj/WebCore.vcproj:
            * WebCore.xcodeproj/project.pbxproj:
            * platform/text/StringBuilder.cpp:
            (WebCore::StringBuilder::toString): Added possibility to use a space between individual strings.
            * platform/text/StringBuilder.h: Cleanup according to WebKit style.
            (WebCore::):
            (WebCore::StringBuilder::StringBuilder):
            (WebCore::StringBuilder::setNonNull):
            (WebCore::StringBuilder::isNull):
            * svg/SVGAllInOne.cpp:
            * svg/SVGPathBuilder.h:
            (WebCore::SVGPathBuilder::cleanup): Clear all references.
            * svg/SVGPathByteStreamBuilder.h:
            (WebCore::SVGPathByteStreamBuilder::cleanup): dito.
            * svg/SVGPathConsumer.h:
            * svg/SVGPathParser.cpp:
            (WebCore::SVGPathParser::cleanup): dito.
            * svg/SVGPathParser.h:
            * svg/SVGPathParserFactory.cpp: Cleanup of factory. More code get shared.
            (WebCore::globalSVGPathBuilder):
            (WebCore::globalSVGPathSegListBuilder):
            (WebCore::globalSVGPathByteStreamBuilder):
            (WebCore::globalSVGPathStringBuilder):
            (WebCore::globalSVGPathParser):
            (WebCore::SVGPathParserFactory::buildPathFromString):
            (WebCore::SVGPathParserFactory::buildPathFromByteStream):
            (WebCore::SVGPathParserFactory::buildSVGPathSegListFromString):
            (WebCore::SVGPathParserFactory::buildSVGPathSegListFromByteStream):
            (WebCore::SVGPathParserFactory::buildStringFromByteStream):
            (WebCore::SVGPathParserFactory::buildSVGPathByteStreamFromString):
            * svg/SVGPathParserFactory.h:
            * svg/SVGPathSegListBuilder.h:
            (WebCore::SVGPathSegListBuilder::cleanup):
            * svg/SVGPathStringBuilder.cpp: Added. Build string from parsed SVG data.
            (WebCore::SVGPathStringBuilder::SVGPathStringBuilder):
            (WebCore::SVGPathStringBuilder::moveTo):
            (WebCore::SVGPathStringBuilder::lineTo):
            (WebCore::SVGPathStringBuilder::lineToHorizontal):
            (WebCore::SVGPathStringBuilder::lineToVertical):
            (WebCore::SVGPathStringBuilder::curveToCubic):
            (WebCore::SVGPathStringBuilder::curveToCubicSmooth):
            (WebCore::SVGPathStringBuilder::curveToQuadratic):
            (WebCore::SVGPathStringBuilder::curveToQuadraticSmooth):
            (WebCore::SVGPathStringBuilder::arcTo):
            (WebCore::SVGPathStringBuilder::closePath):
            * svg/SVGPathStringBuilder.h: Added.
            (WebCore::SVGPathStringBuilder::cleanup):
            (WebCore::SVGPathStringBuilder::result):
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@64949 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebCore/Android.mk b/WebCore/Android.mk
index 29a91cc..4b55a46 100644
--- a/WebCore/Android.mk
+++ b/WebCore/Android.mk
@@ -889,6 +889,7 @@ LOCAL_SRC_FILES := $(LOCAL_SRC_FILES) \
 	svg/SVGPathSegList.cpp \
 	svg/SVGPathSegListBuilder.cpp \
 	svg/SVGPathSegMoveto.cpp \
+	svg/SVGPathStringBuilder.cpp \
 	svg/SVGPathStringSource.cpp \
 	svg/SVGPatternElement.cpp \
 	svg/SVGPointList.cpp \
diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index 7a921c1..40e8b97 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -1,3 +1,71 @@
+2010-08-08  Dirk Schulze  <krit at webkit.org>
+
+        Reviewed by Nikolas Zimmermann.
+
+        Add missing String builder for SVGPathParser
+        https://bugs.webkit.org/show_bug.cgi?id=43682
+
+        Introduces SVGPathStringBuilder. SVGPathParser clients, like normalized and unaltered
+        SVGPathSegLists or SVGPathByteStreams, can be parsed and transformed to a string.
+        StringBuilder can create a string of individual strings, seperated by spaces now.
+        Share more code in SVGPathParserFactory and use a common general concept to manage SVG path
+        data parsing.
+
+        Doesn't affect any tests.
+
+        * Android.mk:
+        * GNUmakefile.am:
+        * WebCore.gypi:
+        * WebCore.pro:
+        * WebCore.vcproj/WebCore.vcproj:
+        * WebCore.xcodeproj/project.pbxproj:
+        * platform/text/StringBuilder.cpp:
+        (WebCore::StringBuilder::toString): Added possibility to use a space between individual strings. 
+        * platform/text/StringBuilder.h: Cleanup according to WebKit style.
+        (WebCore::):
+        (WebCore::StringBuilder::StringBuilder):
+        (WebCore::StringBuilder::setNonNull):
+        (WebCore::StringBuilder::isNull):
+        * svg/SVGAllInOne.cpp:
+        * svg/SVGPathBuilder.h:
+        (WebCore::SVGPathBuilder::cleanup): Clear all references.
+        * svg/SVGPathByteStreamBuilder.h:
+        (WebCore::SVGPathByteStreamBuilder::cleanup): dito.
+        * svg/SVGPathConsumer.h:
+        * svg/SVGPathParser.cpp:
+        (WebCore::SVGPathParser::cleanup): dito.
+        * svg/SVGPathParser.h:
+        * svg/SVGPathParserFactory.cpp: Cleanup of factory. More code get shared.
+        (WebCore::globalSVGPathBuilder):
+        (WebCore::globalSVGPathSegListBuilder):
+        (WebCore::globalSVGPathByteStreamBuilder):
+        (WebCore::globalSVGPathStringBuilder):
+        (WebCore::globalSVGPathParser):
+        (WebCore::SVGPathParserFactory::buildPathFromString):
+        (WebCore::SVGPathParserFactory::buildPathFromByteStream):
+        (WebCore::SVGPathParserFactory::buildSVGPathSegListFromString):
+        (WebCore::SVGPathParserFactory::buildSVGPathSegListFromByteStream):
+        (WebCore::SVGPathParserFactory::buildStringFromByteStream):
+        (WebCore::SVGPathParserFactory::buildSVGPathByteStreamFromString):
+        * svg/SVGPathParserFactory.h:
+        * svg/SVGPathSegListBuilder.h:
+        (WebCore::SVGPathSegListBuilder::cleanup):
+        * svg/SVGPathStringBuilder.cpp: Added. Build string from parsed SVG data.
+        (WebCore::SVGPathStringBuilder::SVGPathStringBuilder):
+        (WebCore::SVGPathStringBuilder::moveTo):
+        (WebCore::SVGPathStringBuilder::lineTo):
+        (WebCore::SVGPathStringBuilder::lineToHorizontal):
+        (WebCore::SVGPathStringBuilder::lineToVertical):
+        (WebCore::SVGPathStringBuilder::curveToCubic):
+        (WebCore::SVGPathStringBuilder::curveToCubicSmooth):
+        (WebCore::SVGPathStringBuilder::curveToQuadratic):
+        (WebCore::SVGPathStringBuilder::curveToQuadraticSmooth):
+        (WebCore::SVGPathStringBuilder::arcTo):
+        (WebCore::SVGPathStringBuilder::closePath):
+        * svg/SVGPathStringBuilder.h: Added.
+        (WebCore::SVGPathStringBuilder::cleanup):
+        (WebCore::SVGPathStringBuilder::result):
+
 2010-08-08  Adam Barth  <abarth at webkit.org>
 
         Reviewed by Eric Seidel.
diff --git a/WebCore/GNUmakefile.am b/WebCore/GNUmakefile.am
index 44f626f..af3fc22 100644
--- a/WebCore/GNUmakefile.am
+++ b/WebCore/GNUmakefile.am
@@ -4113,6 +4113,8 @@ webcore_sources += \
 	WebCore/svg/SVGPathSegMoveto.cpp \
 	WebCore/svg/SVGPathSegMoveto.h \
 	WebCore/svg/SVGPathSource.h \
+	WebCore/svg/SVGPathStringBuilder.cpp \
+	WebCore/svg/SVGPathStringBuilder.h \
 	WebCore/svg/SVGPathStringSource.cpp \
 	WebCore/svg/SVGPathStringSource.h \
 	WebCore/svg/SVGPatternElement.cpp \
diff --git a/WebCore/WebCore.gypi b/WebCore/WebCore.gypi
index a9659b1..b9814b7 100644
--- a/WebCore/WebCore.gypi
+++ b/WebCore/WebCore.gypi
@@ -3867,6 +3867,8 @@
             'svg/SVGPathSegMoveto.cpp',
             'svg/SVGPathSegMoveto.h',
             'svg/SVGPathSource.h',
+            'svg/SVGPathStringBuilder.cpp',
+            'svg/SVGPathStringBuilder.h',
             'svg/SVGPathStringSource.cpp',
             'svg/SVGPathStringSource.h',
             'svg/SVGPatternElement.cpp',
diff --git a/WebCore/WebCore.pro b/WebCore/WebCore.pro
index df06ec9..04815ce 100644
--- a/WebCore/WebCore.pro
+++ b/WebCore/WebCore.pro
@@ -2871,6 +2871,7 @@ contains(DEFINES, ENABLE_SVG=1) {
         svg/SVGPathSegList.cpp \
         svg/SVGPathSegListBuilder.cpp \
         svg/SVGPathSegMoveto.cpp \
+        svg/SVGPathStringBuilder.cpp \
         svg/SVGPathStringSource.cpp \
         svg/SVGPatternElement.cpp \
         svg/SVGPointList.cpp \
diff --git a/WebCore/WebCore.vcproj/WebCore.vcproj b/WebCore/WebCore.vcproj/WebCore.vcproj
index 5b5ae8e..f811295 100644
--- a/WebCore/WebCore.vcproj/WebCore.vcproj
+++ b/WebCore/WebCore.vcproj/WebCore.vcproj
@@ -49525,6 +49525,10 @@
 				>
 			</File>
 			<File
+				RelativePath="..\svg\SVGPathStringBuilder.h"
+				>
+			</File>
+			<File
 				RelativePath="..\svg\SVGPathStringSource.h"
 				>
 			</File>
diff --git a/WebCore/WebCore.xcodeproj/project.pbxproj b/WebCore/WebCore.xcodeproj/project.pbxproj
index 1c6d0f6..67c9d6b 100644
--- a/WebCore/WebCore.xcodeproj/project.pbxproj
+++ b/WebCore/WebCore.xcodeproj/project.pbxproj
@@ -1435,6 +1435,8 @@
 		8419D2A9120D92D000141F8F /* SVGPathByteStreamBuilder.h in Headers */ = {isa = PBXBuildFile; fileRef = 8419D2A6120D92D000141F8F /* SVGPathByteStreamBuilder.h */; };
 		8419D2AC120D92FC00141F8F /* SVGPathByteStreamSource.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 8419D2AA120D92FC00141F8F /* SVGPathByteStreamSource.cpp */; };
 		8419D2AD120D92FC00141F8F /* SVGPathByteStreamSource.h in Headers */ = {isa = PBXBuildFile; fileRef = 8419D2AB120D92FC00141F8F /* SVGPathByteStreamSource.h */; };
+		8419D2B9120E0C7600141F8F /* SVGPathStringBuilder.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 8419D2B7120E0C7600141F8F /* SVGPathStringBuilder.cpp */; };
+		8419D2BA120E0C7600141F8F /* SVGPathStringBuilder.h in Headers */ = {isa = PBXBuildFile; fileRef = 8419D2B8120E0C7600141F8F /* SVGPathStringBuilder.h */; };
 		841FDC261178C9BE00F8AC9B /* RenderSVGResourceFilter.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 841FDC241178C9BE00F8AC9B /* RenderSVGResourceFilter.cpp */; };
 		841FDC271178C9BE00F8AC9B /* RenderSVGResourceFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 841FDC251178C9BE00F8AC9B /* RenderSVGResourceFilter.h */; };
 		84224183107E77F400766A87 /* JSSVGFEMorphologyElement.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 84224181107E77F400766A87 /* JSSVGFEMorphologyElement.cpp */; };
@@ -7268,6 +7270,8 @@
 		8419D2A6120D92D000141F8F /* SVGPathByteStreamBuilder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SVGPathByteStreamBuilder.h; sourceTree = "<group>"; };
 		8419D2AA120D92FC00141F8F /* SVGPathByteStreamSource.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SVGPathByteStreamSource.cpp; sourceTree = "<group>"; };
 		8419D2AB120D92FC00141F8F /* SVGPathByteStreamSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SVGPathByteStreamSource.h; sourceTree = "<group>"; };
+		8419D2B7120E0C7600141F8F /* SVGPathStringBuilder.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SVGPathStringBuilder.cpp; sourceTree = "<group>"; };
+		8419D2B8120E0C7600141F8F /* SVGPathStringBuilder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SVGPathStringBuilder.h; sourceTree = "<group>"; };
 		841FDC241178C9BE00F8AC9B /* RenderSVGResourceFilter.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RenderSVGResourceFilter.cpp; sourceTree = "<group>"; };
 		841FDC251178C9BE00F8AC9B /* RenderSVGResourceFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RenderSVGResourceFilter.h; sourceTree = "<group>"; };
 		84224181107E77F400766A87 /* JSSVGFEMorphologyElement.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSSVGFEMorphologyElement.cpp; sourceTree = "<group>"; };
@@ -15368,6 +15372,8 @@
 				B22278EF0D00BF210071B782 /* SVGPathSegMovetoAbs.idl */,
 				B22278F00D00BF210071B782 /* SVGPathSegMovetoRel.idl */,
 				84300BD7120C9AD40021954A /* SVGPathSource.h */,
+				8419D2B7120E0C7600141F8F /* SVGPathStringBuilder.cpp */,
+				8419D2B8120E0C7600141F8F /* SVGPathStringBuilder.h */,
 				84300BD9120C9AED0021954A /* SVGPathStringSource.cpp */,
 				84300BD5120C9AAC0021954A /* SVGPathStringSource.h */,
 				B22278F10D00BF210071B782 /* SVGPatternElement.cpp */,
@@ -19841,6 +19847,7 @@
 				8476C9E611DF6A0B00555B02 /* SVGPathSegListBuilder.h in Headers */,
 				B2227A840D00BF220071B782 /* SVGPathSegMoveto.h in Headers */,
 				84300BD8120C9AD40021954A /* SVGPathSource.h in Headers */,
+				8419D2BA120E0C7600141F8F /* SVGPathStringBuilder.h in Headers */,
 				84300BD6120C9AAC0021954A /* SVGPathStringSource.h in Headers */,
 				B2227A880D00BF220071B782 /* SVGPatternElement.h in Headers */,
 				B25599950D00D8BA00BB825C /* SVGPointLightSource.h in Headers */,
@@ -22304,6 +22311,7 @@
 				B2227A800D00BF220071B782 /* SVGPathSegList.cpp in Sources */,
 				8476C9E511DF6A0B00555B02 /* SVGPathSegListBuilder.cpp in Sources */,
 				B2227A830D00BF220071B782 /* SVGPathSegMoveto.cpp in Sources */,
+				8419D2B9120E0C7600141F8F /* SVGPathStringBuilder.cpp in Sources */,
 				84300BDA120C9AED0021954A /* SVGPathStringSource.cpp in Sources */,
 				B2227A870D00BF220071B782 /* SVGPatternElement.cpp in Sources */,
 				B2227A8B0D00BF220071B782 /* SVGPointList.cpp in Sources */,
diff --git a/WebCore/platform/text/StringBuilder.cpp b/WebCore/platform/text/StringBuilder.cpp
index 3e34981..213daab 100644
--- a/WebCore/platform/text/StringBuilder.cpp
+++ b/WebCore/platform/text/StringBuilder.cpp
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 2008 Apple Inc. All rights reserved.
+ * Copyright (C) Research In Motion Limited 2010. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -67,7 +68,7 @@ void StringBuilder::append(char c)
     m_strings.append(String(&c, 1));
 }
 
-String StringBuilder::toString() const
+String StringBuilder::toString(ConcatMode mode) const
 {
     if (isNull())
         return String();
@@ -80,17 +81,37 @@ String StringBuilder::toString() const
         return m_strings[0];
 
     UChar* buffer;
-    String result = String::createUninitialized(m_totalLength, buffer);
+    unsigned totalLength = m_totalLength;
+    if (mode == ConcatAddingSpacesBetweenIndividualStrings)
+        totalLength += count - 1;
+    String result = String::createUninitialized(totalLength, buffer);
 
     UChar* p = buffer;
-    for (unsigned i = 0; i < count; ++i) {
-        StringImpl* string = m_strings[i].impl();
-        unsigned length = string->length(); 
-        memcpy(p, string->characters(), length * 2);
-        p += length;
-    }
 
-    ASSERT(p == m_totalLength + buffer);
+    // We could handle both Concat modes in a single for loop, not doing that for performance reasons.
+    if (mode == ConcatUnaltered) {
+        for (unsigned i = 0; i < count; ++i) {
+            StringImpl* string = m_strings[i].impl();
+            unsigned length = string->length(); 
+            memcpy(p, string->characters(), length * 2);
+            p += length;
+        }
+    } else {
+        ASSERT(mode == ConcatAddingSpacesBetweenIndividualStrings);
+        for (unsigned i = 0; i < count; ++i) {
+            StringImpl* string = m_strings[i].impl();
+            unsigned length = string->length(); 
+            memcpy(p, string->characters(), length * 2);
+            p += length;
+
+            // Add space after string before the start of the next string, if we're not processing the last string.
+            if (i < count - 1) {
+                *p = ' ';
+                ++p;
+            }
+        }
+    }
+    ASSERT(p == totalLength + buffer);
 
     return result;
 }
diff --git a/WebCore/platform/text/StringBuilder.h b/WebCore/platform/text/StringBuilder.h
index 7f72fbf..72adfa7 100644
--- a/WebCore/platform/text/StringBuilder.h
+++ b/WebCore/platform/text/StringBuilder.h
@@ -33,27 +33,36 @@
 
 namespace WebCore {
 
-    class StringBuilder {
-    public:
-        StringBuilder() : m_totalLength(UINT_MAX) {}
+enum ConcatMode {
+    ConcatUnaltered,
+    ConcatAddingSpacesBetweenIndividualStrings
+};
 
-        void setNonNull() { if (m_totalLength == UINT_MAX) m_totalLength = 0; }
+class StringBuilder {
+public:
+    StringBuilder() : m_totalLength(UINT_MAX) {}
 
-        void append(const String&);
-        void append(UChar);
-        void append(char);
-        
-        void clear();
-        unsigned length() const;
+    void setNonNull()
+    {
+        if (m_totalLength == UINT_MAX)
+            m_totalLength = 0;
+    }
 
-        String toString() const;
+    void append(const String&);
+    void append(UChar);
+    void append(char);
+    
+    void clear();
+    unsigned length() const;
 
-    private:
-        bool isNull() const { return m_totalLength == UINT_MAX; }
+    String toString(ConcatMode mode = ConcatUnaltered) const;
 
-        unsigned m_totalLength;
-        Vector<String, 16> m_strings;
-    };
+private:
+    bool isNull() const { return m_totalLength == UINT_MAX; }
+
+    unsigned m_totalLength;
+    Vector<String, 16> m_strings;
+};
 
 }
 
diff --git a/WebCore/svg/SVGAllInOne.cpp b/WebCore/svg/SVGAllInOne.cpp
index 43563b2..3207a41 100644
--- a/WebCore/svg/SVGAllInOne.cpp
+++ b/WebCore/svg/SVGAllInOne.cpp
@@ -126,6 +126,7 @@
 #include "SVGPathSegList.cpp"
 #include "SVGPathSegListBuilder.cpp"
 #include "SVGPathSegMoveto.cpp"
+#include "SVGPathStringBuilder.cpp"
 #include "SVGPathStringSource.cpp"
 #include "SVGPatternElement.cpp"
 #include "SVGPointList.cpp"
diff --git a/WebCore/svg/SVGPathBuilder.h b/WebCore/svg/SVGPathBuilder.h
index 6a0669a..3a1088d 100644
--- a/WebCore/svg/SVGPathBuilder.h
+++ b/WebCore/svg/SVGPathBuilder.h
@@ -36,6 +36,7 @@ public:
     SVGPathBuilder();
 
     void setCurrentPath(Path* path) { m_path = path; }
+    virtual void cleanup() { m_path = 0; }
 
 private:
     // Used in UnalteredParisng/NormalizedParsing modes.
diff --git a/WebCore/svg/SVGPathByteStreamBuilder.h b/WebCore/svg/SVGPathByteStreamBuilder.h
index 13a08b7..f1e7524 100644
--- a/WebCore/svg/SVGPathByteStreamBuilder.h
+++ b/WebCore/svg/SVGPathByteStreamBuilder.h
@@ -34,6 +34,7 @@ public:
     SVGPathByteStreamBuilder();
 
     void setCurrentByteStream(SVGPathByteStream* byteStream) { m_byteStream = byteStream; }
+    virtual void cleanup() { m_byteStream = 0; }
 
 private:
     // Used in UnalteredParsing/NormalizedParsing modes.
diff --git a/WebCore/svg/SVGPathConsumer.h b/WebCore/svg/SVGPathConsumer.h
index fc7ba38..b0deb52 100644
--- a/WebCore/svg/SVGPathConsumer.h
+++ b/WebCore/svg/SVGPathConsumer.h
@@ -42,6 +42,9 @@ enum PathParsingMode {
 
 class SVGPathConsumer : public Noncopyable {
 public:
+    virtual void cleanup() = 0;
+
+public:
     // Used in UnalteredParisng/NormalizedParsing modes.
     virtual void moveTo(const FloatPoint&, bool closed, PathCoordinateMode) = 0;
     virtual void lineTo(const FloatPoint&, PathCoordinateMode) = 0;
diff --git a/WebCore/svg/SVGPathParser.cpp b/WebCore/svg/SVGPathParser.cpp
index 94b7c43..ed381db 100644
--- a/WebCore/svg/SVGPathParser.cpp
+++ b/WebCore/svg/SVGPathParser.cpp
@@ -425,6 +425,16 @@ bool SVGPathParser::parsePathDataFromSource(PathParsingMode pathParsingMode)
     return false;
 }
 
+void SVGPathParser::cleanup()
+{
+    ASSERT(m_source);
+    ASSERT(m_consumer);
+
+    m_consumer->cleanup();
+    m_source = 0;
+    m_consumer = 0;
+}
+
 // This works by converting the SVG arc to "simple" beziers.
 // Partly adapted from Niko's code in kdelibs/kdecore/svgicons.
 // See also SVG implementation notes: http://www.w3.org/TR/SVG/implnote.html#ArcConversionEndpointToCenter
diff --git a/WebCore/svg/SVGPathParser.h b/WebCore/svg/SVGPathParser.h
index 9e02a14..5393fc2 100644
--- a/WebCore/svg/SVGPathParser.h
+++ b/WebCore/svg/SVGPathParser.h
@@ -42,6 +42,7 @@ public:
     bool parsePathDataFromSource(PathParsingMode pathParsingMode);
     void setCurrentConsumer(SVGPathConsumer* consumer) { m_consumer = consumer; }
     void setCurrentSource(SVGPathSource* source) { m_source = source; }
+    void cleanup();
 
 private:
     bool decomposeArcToCubic(float, float, float, FloatPoint&, FloatPoint&, bool largeArcFlag, bool sweepFlag);
diff --git a/WebCore/svg/SVGPathParserFactory.cpp b/WebCore/svg/SVGPathParserFactory.cpp
index 4adb279..6d17abc 100644
--- a/WebCore/svg/SVGPathParserFactory.cpp
+++ b/WebCore/svg/SVGPathParserFactory.cpp
@@ -22,48 +22,64 @@
 #if ENABLE(SVG)
 #include "SVGPathParserFactory.h"
 
+#include "StringBuilder.h"
 #include "SVGPathBuilder.h"
 #include "SVGPathByteStreamBuilder.h"
 #include "SVGPathByteStreamSource.h"
+#include "SVGPathStringBuilder.h"
 #include "SVGPathParser.h"
 #include "SVGPathSegListBuilder.h"
 #include "SVGPathStringSource.h"
 
 namespace WebCore {
 
-static SVGPathBuilder* globalSVGPathBuilder()
+static SVGPathBuilder* globalSVGPathBuilder(Path& result)
 {
     static SVGPathBuilder* s_builder = 0;
     if (!s_builder)
         s_builder = new SVGPathBuilder;
 
+    s_builder->setCurrentPath(&result);
     return s_builder;
 }
 
-static SVGPathSegListBuilder* globalSVGPathSegListBuilder()
+static SVGPathSegListBuilder* globalSVGPathSegListBuilder(SVGPathSegList* result)
 {
     static SVGPathSegListBuilder* s_builder = 0;
     if (!s_builder)
         s_builder = new SVGPathSegListBuilder;
 
+    s_builder->setCurrentSVGPathSegList(result);
     return s_builder;
 }
 
-static SVGPathByteStreamBuilder* globalSVGPathByteStreamBuilder()
+static SVGPathByteStreamBuilder* globalSVGPathByteStreamBuilder(SVGPathByteStream* result)
 {
     static SVGPathByteStreamBuilder* s_builder = 0;
     if (!s_builder)
         s_builder = new SVGPathByteStreamBuilder;
 
+    s_builder->setCurrentByteStream(result);
     return s_builder;
 }
 
-static SVGPathParser* globalSVGPathParser()
+static SVGPathStringBuilder* globalSVGPathStringBuilder()
+{
+    static SVGPathStringBuilder* s_builder = 0;
+    if (!s_builder)
+        s_builder = new SVGPathStringBuilder;
+
+    return s_builder;
+}
+
+static SVGPathParser* globalSVGPathParser(SVGPathSource* source, SVGPathConsumer* consumer)
 {
     static SVGPathParser* s_parser = 0;
     if (!s_parser)
         s_parser = new SVGPathParser;
 
+    s_parser->setCurrentSource(source);
+    s_parser->setCurrentConsumer(consumer);
     return s_parser;
 }
 
@@ -89,19 +105,12 @@ bool SVGPathParserFactory::buildPathFromString(const String& d, Path& result)
     if (d.isEmpty())
         return false;
 
-    SVGPathBuilder* builder = globalSVGPathBuilder();
-    builder->setCurrentPath(&result);
-
-    SVGPathParser* parser = globalSVGPathParser();
-    parser->setCurrentConsumer(builder);
+    SVGPathBuilder* builder = globalSVGPathBuilder(result);
 
     OwnPtr<SVGPathStringSource> source = SVGPathStringSource::create(d);
-    parser->setCurrentSource(source.get());
-
+    SVGPathParser* parser = globalSVGPathParser(source.get(), builder);
     bool ok = parser->parsePathDataFromSource(NormalizedParsing);
-    parser->setCurrentConsumer(0);
-    parser->setCurrentSource(0);
-    builder->setCurrentPath(0);
+    parser->cleanup();
     return ok;
 }
 
@@ -111,19 +120,12 @@ bool SVGPathParserFactory::buildPathFromByteStream(SVGPathByteStream* stream, Pa
     if (stream->isEmpty())
         return false;
 
-    SVGPathBuilder* builder = globalSVGPathBuilder();
-    builder->setCurrentPath(&result);
-
-    SVGPathParser* parser = globalSVGPathParser();
-    parser->setCurrentConsumer(builder);
+    SVGPathBuilder* builder = globalSVGPathBuilder(result);
 
     OwnPtr<SVGPathByteStreamSource> source = SVGPathByteStreamSource::create(stream);
-    parser->setCurrentSource(source.get());
-
+    SVGPathParser* parser = globalSVGPathParser(source.get(), builder);
     bool ok = parser->parsePathDataFromSource(NormalizedParsing);
-    parser->setCurrentConsumer(0);
-    parser->setCurrentSource(0);
-    builder->setCurrentPath(0);
+    parser->cleanup();
     return ok;
 }
 
@@ -133,19 +135,12 @@ bool SVGPathParserFactory::buildSVGPathSegListFromString(const String& d, SVGPat
     if (d.isEmpty())
         return false;
 
-    SVGPathSegListBuilder* builder = globalSVGPathSegListBuilder();
-    builder->setCurrentSVGPathSegList(result);
-
-    SVGPathParser* parser = globalSVGPathParser();
-    parser->setCurrentConsumer(builder);
+    SVGPathSegListBuilder* builder = globalSVGPathSegListBuilder(result);
 
     OwnPtr<SVGPathStringSource> source = SVGPathStringSource::create(d);
-    parser->setCurrentSource(source.get());
-
+    SVGPathParser* parser = globalSVGPathParser(source.get(), builder);
     bool ok = parser->parsePathDataFromSource(parsingMode);
-    parser->setCurrentConsumer(0);
-    parser->setCurrentSource(0);
-    builder->setCurrentSVGPathSegList(0);
+    parser->cleanup();
     return ok;
 }
 
@@ -156,44 +151,45 @@ bool SVGPathParserFactory::buildSVGPathSegListFromByteStream(SVGPathByteStream*
     if (stream->isEmpty())
         return false; 
 
-    SVGPathSegListBuilder* builder = globalSVGPathSegListBuilder();
-    builder->setCurrentSVGPathSegList(result);
-
-    SVGPathParser* parser = globalSVGPathParser();
-    parser->setCurrentConsumer(builder);
+    SVGPathSegListBuilder* builder = globalSVGPathSegListBuilder(result);
 
     OwnPtr<SVGPathByteStreamSource> source = SVGPathByteStreamSource::create(stream);
-    parser->setCurrentSource(source.get());
+    SVGPathParser* parser = globalSVGPathParser(source.get(), builder);
+    bool ok = parser->parsePathDataFromSource(parsingMode);
+    parser->cleanup();
+    return ok;
+}
+
+bool SVGPathParserFactory::buildStringFromByteStream(SVGPathByteStream* stream, String& result, PathParsingMode parsingMode)
+{
+    ASSERT(stream);
+    if (stream->isEmpty())
+        return false; 
+
+    SVGPathStringBuilder* builder = globalSVGPathStringBuilder();
 
+    OwnPtr<SVGPathByteStreamSource> source = SVGPathByteStreamSource::create(stream);
+    SVGPathParser* parser = globalSVGPathParser(source.get(), builder);
     bool ok = parser->parsePathDataFromSource(parsingMode);
-    parser->setCurrentConsumer(0);
-    parser->setCurrentSource(0);
-    builder->setCurrentSVGPathSegList(0);
+    parser->cleanup();
+    result = builder->result();
     return ok;
 }
 
-PassOwnPtr<SVGPathByteStream> SVGPathParserFactory::createSVGPathByteStreamFromString(const String& d, PathParsingMode parsingMode, bool& ok)
+bool SVGPathParserFactory::buildSVGPathByteStreamFromString(const String& d, OwnPtr<SVGPathByteStream>& result, PathParsingMode parsingMode)
 {
-    if (d.isEmpty()) {
-        ok = false;
-        return PassOwnPtr<SVGPathByteStream>();
-    }
+    if (d.isEmpty())
+        return false;
 
-    SVGPathByteStreamBuilder* builder = globalSVGPathByteStreamBuilder();
     OwnPtr<SVGPathByteStream> stream = SVGPathByteStream::create();
-    builder->setCurrentByteStream(stream.get());
-
-    SVGPathParser* parser = globalSVGPathParser();
-    parser->setCurrentConsumer(builder);
+    SVGPathByteStreamBuilder* builder = globalSVGPathByteStreamBuilder(stream.get());
 
     OwnPtr<SVGPathStringSource> source = SVGPathStringSource::create(d);
-    parser->setCurrentSource(source.get());
-
-    ok = parser->parsePathDataFromSource(parsingMode);
-    parser->setCurrentConsumer(0);
-    parser->setCurrentSource(0);
-    builder->setCurrentByteStream(0);
-    return stream.release();
+    SVGPathParser* parser = globalSVGPathParser(source.get(), builder);
+    bool ok = parser->parsePathDataFromSource(parsingMode);
+    result = stream.release();
+    parser->cleanup();
+    return ok;
 }
 
 }
diff --git a/WebCore/svg/SVGPathParserFactory.h b/WebCore/svg/SVGPathParserFactory.h
index dc61c66..0aa3c99 100644
--- a/WebCore/svg/SVGPathParserFactory.h
+++ b/WebCore/svg/SVGPathParserFactory.h
@@ -26,7 +26,7 @@
 #include "SVGPathConsumer.h"
 #include "SVGPathSegList.h"
 #include "SVGPathByteStream.h"
-#include <wtf/PassOwnPtr.h>
+#include <wtf/OwnPtr.h>
 
 namespace WebCore {
 
@@ -40,7 +40,9 @@ public:
     bool buildSVGPathSegListFromString(const String&, SVGPathSegList*, PathParsingMode);
     bool buildSVGPathSegListFromByteStream(SVGPathByteStream*, SVGPathSegList*, PathParsingMode);
 
-    PassOwnPtr<SVGPathByteStream> createSVGPathByteStreamFromString(const String&, PathParsingMode, bool& ok);
+    bool buildStringFromByteStream(SVGPathByteStream*, String&, PathParsingMode);
+
+    bool buildSVGPathByteStreamFromString(const String&, OwnPtr<SVGPathByteStream>&, PathParsingMode);
 
 private:
     SVGPathParserFactory();
diff --git a/WebCore/svg/SVGPathSegListBuilder.h b/WebCore/svg/SVGPathSegListBuilder.h
index ab0cdf2..aa4a782 100644
--- a/WebCore/svg/SVGPathSegListBuilder.h
+++ b/WebCore/svg/SVGPathSegListBuilder.h
@@ -36,6 +36,7 @@ public:
     SVGPathSegListBuilder();
 
     void setCurrentSVGPathSegList(SVGPathSegList* pathSegList) { m_pathSegList = pathSegList; }
+    virtual void cleanup() { m_pathSegList = 0; }
 
 private:
     // Used in UnalteredParisng/NormalizedParsing modes.
diff --git a/WebCore/svg/SVGPathStringBuilder.cpp b/WebCore/svg/SVGPathStringBuilder.cpp
new file mode 100644
index 0000000..0a166ad
--- /dev/null
+++ b/WebCore/svg/SVGPathStringBuilder.cpp
@@ -0,0 +1,110 @@
+/*
+ * 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 "SVGPathStringBuilder.h"
+
+namespace WebCore {
+
+SVGPathStringBuilder::SVGPathStringBuilder()
+{
+}
+
+void SVGPathStringBuilder::moveTo(const FloatPoint& targetPoint, bool, PathCoordinateMode mode)
+{
+    if (mode == AbsoluteCoordinates)
+        m_stringBuilder.append(String::format("M %.6lg %.6lg", targetPoint.x(), targetPoint.y()));
+    else
+        m_stringBuilder.append(String::format("m %.6lg %.6lg", targetPoint.x(), targetPoint.y()));
+}
+
+void SVGPathStringBuilder::lineTo(const FloatPoint& targetPoint, PathCoordinateMode mode)
+{
+    if (mode == AbsoluteCoordinates)
+        m_stringBuilder.append(String::format("L %.6lg %.6lg", targetPoint.x(), targetPoint.y()));
+    else
+        m_stringBuilder.append(String::format("l %.6lg %.6lg", targetPoint.x(), targetPoint.y()));
+}
+
+void SVGPathStringBuilder::lineToHorizontal(float x, PathCoordinateMode mode)
+{
+    if (mode == AbsoluteCoordinates)
+        m_stringBuilder.append(String::format("H %.6lg", x));
+    else
+        m_stringBuilder.append(String::format("h %.6lg", x));
+}
+
+void SVGPathStringBuilder::lineToVertical(float y, PathCoordinateMode mode)
+{
+    if (mode == AbsoluteCoordinates)
+        m_stringBuilder.append(String::format("V %.6lg", y));
+    else
+        m_stringBuilder.append(String::format("v %.6lg", y));
+}
+
+void SVGPathStringBuilder::curveToCubic(const FloatPoint& point1, const FloatPoint& point2, const FloatPoint& targetPoint, PathCoordinateMode mode)
+{
+    if (mode == AbsoluteCoordinates)
+        m_stringBuilder.append(String::format("C %.6lg %.6lg %.6lg %.6lg %.6lg %.6lg", point1.x(), point1.y(), point2.x(), point2.y(), targetPoint.x(), targetPoint.y()));
+    else
+        m_stringBuilder.append(String::format("c %.6lg %.6lg %.6lg %.6lg %.6lg %.6lg", point1.x(), point1.y(), point2.x(), point2.y(), targetPoint.x(), targetPoint.y()));
+}
+
+void SVGPathStringBuilder::curveToCubicSmooth(const FloatPoint& point2, const FloatPoint& targetPoint, PathCoordinateMode mode)
+{
+    if (mode == AbsoluteCoordinates)
+        m_stringBuilder.append(String::format("S %.6lg %.6lg %.6lg %.6lg", point2.x(), point2.y(), targetPoint.x(), targetPoint.y()));
+    else
+        m_stringBuilder.append(String::format("s %.6lg %.6lg %.6lg %.6lg", point2.x(), point2.y(), targetPoint.x(), targetPoint.y()));
+}
+
+void SVGPathStringBuilder::curveToQuadratic(const FloatPoint& point1, const FloatPoint& targetPoint, PathCoordinateMode mode)
+{
+    if (mode == AbsoluteCoordinates)
+        m_stringBuilder.append(String::format("Q %.6lg %.6lg %.6lg %.6lg", point1.x(), point1.y(), targetPoint.x(), targetPoint.y()));
+    else
+        m_stringBuilder.append(String::format("q %.6lg %.6lg %.6lg %.6lg", point1.x(), point1.y(), targetPoint.x(), targetPoint.y()));
+}
+
+void SVGPathStringBuilder::curveToQuadraticSmooth(const FloatPoint& targetPoint, PathCoordinateMode mode)
+{
+    if (mode == AbsoluteCoordinates)
+        m_stringBuilder.append(String::format("T %.6lg %.6lg", targetPoint.x(), targetPoint.y()));
+    else
+        m_stringBuilder.append(String::format("t %.6lg %.6lg", targetPoint.x(), targetPoint.y()));
+}
+
+void SVGPathStringBuilder::arcTo(float r1, float r2, float angle, bool largeArcFlag, bool sweepFlag, const FloatPoint& targetPoint, PathCoordinateMode mode)
+{
+    if (mode == AbsoluteCoordinates)
+        m_stringBuilder.append(String::format("A %.6lg %.6lg %.6lg %d %d %.6lg %.6lg", r1, r2, angle, largeArcFlag, sweepFlag, targetPoint.x(), targetPoint.y()));
+    else
+        m_stringBuilder.append(String::format("a %.6lg %.6lg %.6lg %d %d %.6lg %.6lg", r1, r2, angle, largeArcFlag, sweepFlag, targetPoint.x(), targetPoint.y()));
+}
+
+void SVGPathStringBuilder::closePath()
+{
+    m_stringBuilder.append("Z");
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(SVG)
diff --git a/WebCore/svg/SVGPathStringBuilder.h b/WebCore/svg/SVGPathStringBuilder.h
new file mode 100644
index 0000000..f25f791
--- /dev/null
+++ b/WebCore/svg/SVGPathStringBuilder.h
@@ -0,0 +1,59 @@
+/*
+ * 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 SVGPathStringBuilder_h
+#define SVGPathStringBuilder_h
+
+#if ENABLE(SVG)
+#include "FloatPoint.h"
+#include "SVGPathConsumer.h"
+#include "StringBuilder.h"
+
+namespace WebCore {
+
+class SVGPathStringBuilder : public SVGPathConsumer {
+public:
+    SVGPathStringBuilder();
+
+    virtual void cleanup() { m_stringBuilder.clear(); }
+    String result() { return m_stringBuilder.toString(ConcatAddingSpacesBetweenIndividualStrings); }
+
+private:
+    // Used in UnalteredParsing/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:
+    // Only used in UnalteredParsing mode.
+    virtual void lineToHorizontal(float, PathCoordinateMode);
+    virtual void lineToVertical(float, PathCoordinateMode);
+    virtual void curveToCubicSmooth(const FloatPoint&, const FloatPoint&, PathCoordinateMode);
+    virtual void curveToQuadratic(const FloatPoint&, const FloatPoint&, PathCoordinateMode);
+    virtual void curveToQuadraticSmooth(const FloatPoint&, PathCoordinateMode);
+    virtual void arcTo(float, float, float, bool largeArcFlag, bool sweepFlag, const FloatPoint&, PathCoordinateMode);
+
+    StringBuilder m_stringBuilder;
+};
+
+} // namespace WebCore
+
+#endif // ENABLE(SVG)
+#endif // SVGPathStringBuilder_h

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list