Changeset 64949 in webkit


Ignore:
Timestamp:
Aug 8, 2010 9:10:48 AM (14 years ago)
Author:
krit@webkit.org
Message:

2010-08-08 Dirk Schulze <krit@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):
Location:
trunk/WebCore
Files:
2 added
18 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/Android.mk

    r64909 r64949  
    890890        svg/SVGPathSegListBuilder.cpp \
    891891        svg/SVGPathSegMoveto.cpp \
     892        svg/SVGPathStringBuilder.cpp \
    892893        svg/SVGPathStringSource.cpp \
    893894        svg/SVGPatternElement.cpp \
  • trunk/WebCore/ChangeLog

    r64947 r64949  
     12010-08-08  Dirk Schulze  <krit@webkit.org>
     2
     3        Reviewed by Nikolas Zimmermann.
     4
     5        Add missing String builder for SVGPathParser
     6        https://bugs.webkit.org/show_bug.cgi?id=43682
     7
     8        Introduces SVGPathStringBuilder. SVGPathParser clients, like normalized and unaltered
     9        SVGPathSegLists or SVGPathByteStreams, can be parsed and transformed to a string.
     10        StringBuilder can create a string of individual strings, seperated by spaces now.
     11        Share more code in SVGPathParserFactory and use a common general concept to manage SVG path
     12        data parsing.
     13
     14        Doesn't affect any tests.
     15
     16        * Android.mk:
     17        * GNUmakefile.am:
     18        * WebCore.gypi:
     19        * WebCore.pro:
     20        * WebCore.vcproj/WebCore.vcproj:
     21        * WebCore.xcodeproj/project.pbxproj:
     22        * platform/text/StringBuilder.cpp:
     23        (WebCore::StringBuilder::toString): Added possibility to use a space between individual strings.
     24        * platform/text/StringBuilder.h: Cleanup according to WebKit style.
     25        (WebCore::):
     26        (WebCore::StringBuilder::StringBuilder):
     27        (WebCore::StringBuilder::setNonNull):
     28        (WebCore::StringBuilder::isNull):
     29        * svg/SVGAllInOne.cpp:
     30        * svg/SVGPathBuilder.h:
     31        (WebCore::SVGPathBuilder::cleanup): Clear all references.
     32        * svg/SVGPathByteStreamBuilder.h:
     33        (WebCore::SVGPathByteStreamBuilder::cleanup): dito.
     34        * svg/SVGPathConsumer.h:
     35        * svg/SVGPathParser.cpp:
     36        (WebCore::SVGPathParser::cleanup): dito.
     37        * svg/SVGPathParser.h:
     38        * svg/SVGPathParserFactory.cpp: Cleanup of factory. More code get shared.
     39        (WebCore::globalSVGPathBuilder):
     40        (WebCore::globalSVGPathSegListBuilder):
     41        (WebCore::globalSVGPathByteStreamBuilder):
     42        (WebCore::globalSVGPathStringBuilder):
     43        (WebCore::globalSVGPathParser):
     44        (WebCore::SVGPathParserFactory::buildPathFromString):
     45        (WebCore::SVGPathParserFactory::buildPathFromByteStream):
     46        (WebCore::SVGPathParserFactory::buildSVGPathSegListFromString):
     47        (WebCore::SVGPathParserFactory::buildSVGPathSegListFromByteStream):
     48        (WebCore::SVGPathParserFactory::buildStringFromByteStream):
     49        (WebCore::SVGPathParserFactory::buildSVGPathByteStreamFromString):
     50        * svg/SVGPathParserFactory.h:
     51        * svg/SVGPathSegListBuilder.h:
     52        (WebCore::SVGPathSegListBuilder::cleanup):
     53        * svg/SVGPathStringBuilder.cpp: Added. Build string from parsed SVG data.
     54        (WebCore::SVGPathStringBuilder::SVGPathStringBuilder):
     55        (WebCore::SVGPathStringBuilder::moveTo):
     56        (WebCore::SVGPathStringBuilder::lineTo):
     57        (WebCore::SVGPathStringBuilder::lineToHorizontal):
     58        (WebCore::SVGPathStringBuilder::lineToVertical):
     59        (WebCore::SVGPathStringBuilder::curveToCubic):
     60        (WebCore::SVGPathStringBuilder::curveToCubicSmooth):
     61        (WebCore::SVGPathStringBuilder::curveToQuadratic):
     62        (WebCore::SVGPathStringBuilder::curveToQuadraticSmooth):
     63        (WebCore::SVGPathStringBuilder::arcTo):
     64        (WebCore::SVGPathStringBuilder::closePath):
     65        * svg/SVGPathStringBuilder.h: Added.
     66        (WebCore::SVGPathStringBuilder::cleanup):
     67        (WebCore::SVGPathStringBuilder::result):
     68
    1692010-08-08  Adam Barth  <abarth@webkit.org>
    270
  • trunk/WebCore/GNUmakefile.am

    r64909 r64949  
    41144114        WebCore/svg/SVGPathSegMoveto.h \
    41154115        WebCore/svg/SVGPathSource.h \
     4116        WebCore/svg/SVGPathStringBuilder.cpp \
     4117        WebCore/svg/SVGPathStringBuilder.h \
    41164118        WebCore/svg/SVGPathStringSource.cpp \
    41174119        WebCore/svg/SVGPathStringSource.h \
  • trunk/WebCore/WebCore.gypi

    r64909 r64949  
    38683868            'svg/SVGPathSegMoveto.h',
    38693869            'svg/SVGPathSource.h',
     3870            'svg/SVGPathStringBuilder.cpp',
     3871            'svg/SVGPathStringBuilder.h',
    38703872            'svg/SVGPathStringSource.cpp',
    38713873            'svg/SVGPathStringSource.h',
  • trunk/WebCore/WebCore.pro

    r64909 r64949  
    28722872        svg/SVGPathSegListBuilder.cpp \
    28732873        svg/SVGPathSegMoveto.cpp \
     2874        svg/SVGPathStringBuilder.cpp \
    28742875        svg/SVGPathStringSource.cpp \
    28752876        svg/SVGPatternElement.cpp \
  • trunk/WebCore/WebCore.vcproj/WebCore.vcproj

    r64909 r64949  
    4952649526                        </File>
    4952749527                        <File
     49528                                RelativePath="..\svg\SVGPathStringBuilder.h"
     49529                                >
     49530                        </File>
     49531                        <File
    4952849532                                RelativePath="..\svg\SVGPathStringSource.h"
    4952949533                                >
  • trunk/WebCore/WebCore.xcodeproj/project.pbxproj

    r64915 r64949  
    14361436                8419D2AC120D92FC00141F8F /* SVGPathByteStreamSource.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 8419D2AA120D92FC00141F8F /* SVGPathByteStreamSource.cpp */; };
    14371437                8419D2AD120D92FC00141F8F /* SVGPathByteStreamSource.h in Headers */ = {isa = PBXBuildFile; fileRef = 8419D2AB120D92FC00141F8F /* SVGPathByteStreamSource.h */; };
     1438                8419D2B9120E0C7600141F8F /* SVGPathStringBuilder.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 8419D2B7120E0C7600141F8F /* SVGPathStringBuilder.cpp */; };
     1439                8419D2BA120E0C7600141F8F /* SVGPathStringBuilder.h in Headers */ = {isa = PBXBuildFile; fileRef = 8419D2B8120E0C7600141F8F /* SVGPathStringBuilder.h */; };
    14381440                841FDC261178C9BE00F8AC9B /* RenderSVGResourceFilter.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 841FDC241178C9BE00F8AC9B /* RenderSVGResourceFilter.cpp */; };
    14391441                841FDC271178C9BE00F8AC9B /* RenderSVGResourceFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 841FDC251178C9BE00F8AC9B /* RenderSVGResourceFilter.h */; };
     
    72697271                8419D2AA120D92FC00141F8F /* SVGPathByteStreamSource.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SVGPathByteStreamSource.cpp; sourceTree = "<group>"; };
    72707272                8419D2AB120D92FC00141F8F /* SVGPathByteStreamSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SVGPathByteStreamSource.h; sourceTree = "<group>"; };
     7273                8419D2B7120E0C7600141F8F /* SVGPathStringBuilder.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SVGPathStringBuilder.cpp; sourceTree = "<group>"; };
     7274                8419D2B8120E0C7600141F8F /* SVGPathStringBuilder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SVGPathStringBuilder.h; sourceTree = "<group>"; };
    72717275                841FDC241178C9BE00F8AC9B /* RenderSVGResourceFilter.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RenderSVGResourceFilter.cpp; sourceTree = "<group>"; };
    72727276                841FDC251178C9BE00F8AC9B /* RenderSVGResourceFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RenderSVGResourceFilter.h; sourceTree = "<group>"; };
     
    1536915373                                B22278F00D00BF210071B782 /* SVGPathSegMovetoRel.idl */,
    1537015374                                84300BD7120C9AD40021954A /* SVGPathSource.h */,
     15375                                8419D2B7120E0C7600141F8F /* SVGPathStringBuilder.cpp */,
     15376                                8419D2B8120E0C7600141F8F /* SVGPathStringBuilder.h */,
    1537115377                                84300BD9120C9AED0021954A /* SVGPathStringSource.cpp */,
    1537215378                                84300BD5120C9AAC0021954A /* SVGPathStringSource.h */,
     
    1984219848                                B2227A840D00BF220071B782 /* SVGPathSegMoveto.h in Headers */,
    1984319849                                84300BD8120C9AD40021954A /* SVGPathSource.h in Headers */,
     19850                                8419D2BA120E0C7600141F8F /* SVGPathStringBuilder.h in Headers */,
    1984419851                                84300BD6120C9AAC0021954A /* SVGPathStringSource.h in Headers */,
    1984519852                                B2227A880D00BF220071B782 /* SVGPatternElement.h in Headers */,
     
    2230522312                                8476C9E511DF6A0B00555B02 /* SVGPathSegListBuilder.cpp in Sources */,
    2230622313                                B2227A830D00BF220071B782 /* SVGPathSegMoveto.cpp in Sources */,
     22314                                8419D2B9120E0C7600141F8F /* SVGPathStringBuilder.cpp in Sources */,
    2230722315                                84300BDA120C9AED0021954A /* SVGPathStringSource.cpp in Sources */,
    2230822316                                B2227A870D00BF220071B782 /* SVGPatternElement.cpp in Sources */,
  • trunk/WebCore/platform/text/StringBuilder.cpp

    r52268 r64949  
    11/*
    22 * Copyright (C) 2008 Apple Inc. All rights reserved.
     3 * Copyright (C) Research In Motion Limited 2010. All rights reserved.
    34 *
    45 * Redistribution and use in source and binary forms, with or without
     
    6869}
    6970
    70 String StringBuilder::toString() const
     71String StringBuilder::toString(ConcatMode mode) const
    7172{
    7273    if (isNull())
     
    8182
    8283    UChar* buffer;
    83     String result = String::createUninitialized(m_totalLength, buffer);
     84    unsigned totalLength = m_totalLength;
     85    if (mode == ConcatAddingSpacesBetweenIndividualStrings)
     86        totalLength += count - 1;
     87    String result = String::createUninitialized(totalLength, buffer);
    8488
    8589    UChar* p = buffer;
    86     for (unsigned i = 0; i < count; ++i) {
    87         StringImpl* string = m_strings[i].impl();
    88         unsigned length = string->length();
    89         memcpy(p, string->characters(), length * 2);
    90         p += length;
     90
     91    // We could handle both Concat modes in a single for loop, not doing that for performance reasons.
     92    if (mode == ConcatUnaltered) {
     93        for (unsigned i = 0; i < count; ++i) {
     94            StringImpl* string = m_strings[i].impl();
     95            unsigned length = string->length();
     96            memcpy(p, string->characters(), length * 2);
     97            p += length;
     98        }
     99    } else {
     100        ASSERT(mode == ConcatAddingSpacesBetweenIndividualStrings);
     101        for (unsigned i = 0; i < count; ++i) {
     102            StringImpl* string = m_strings[i].impl();
     103            unsigned length = string->length();
     104            memcpy(p, string->characters(), length * 2);
     105            p += length;
     106
     107            // Add space after string before the start of the next string, if we're not processing the last string.
     108            if (i < count - 1) {
     109                *p = ' ';
     110                ++p;
     111            }
     112        }
    91113    }
    92 
    93     ASSERT(p == m_totalLength + buffer);
     114    ASSERT(p == totalLength + buffer);
    94115
    95116    return result;
  • trunk/WebCore/platform/text/StringBuilder.h

    r52268 r64949  
    3434namespace WebCore {
    3535
    36     class StringBuilder {
    37     public:
    38         StringBuilder() : m_totalLength(UINT_MAX) {}
     36enum ConcatMode {
     37    ConcatUnaltered,
     38    ConcatAddingSpacesBetweenIndividualStrings
     39};
    3940
    40         void setNonNull() { if (m_totalLength == UINT_MAX) m_totalLength = 0; }
     41class StringBuilder {
     42public:
     43    StringBuilder() : m_totalLength(UINT_MAX) {}
    4144
    42         void append(const String&);
    43         void append(UChar);
    44         void append(char);
    45        
    46         void clear();
    47         unsigned length() const;
     45    void setNonNull()
     46    {
     47        if (m_totalLength == UINT_MAX)
     48            m_totalLength = 0;
     49    }
    4850
    49         String toString() const;
     51    void append(const String&);
     52    void append(UChar);
     53    void append(char);
     54   
     55    void clear();
     56    unsigned length() const;
    5057
    51     private:
    52         bool isNull() const { return m_totalLength == UINT_MAX; }
     58    String toString(ConcatMode mode = ConcatUnaltered) const;
    5359
    54         unsigned m_totalLength;
    55         Vector<String, 16> m_strings;
    56     };
     60private:
     61    bool isNull() const { return m_totalLength == UINT_MAX; }
     62
     63    unsigned m_totalLength;
     64    Vector<String, 16> m_strings;
     65};
    5766
    5867}
  • trunk/WebCore/svg/SVGAllInOne.cpp

    r64909 r64949  
    127127#include "SVGPathSegListBuilder.cpp"
    128128#include "SVGPathSegMoveto.cpp"
     129#include "SVGPathStringBuilder.cpp"
    129130#include "SVGPathStringSource.cpp"
    130131#include "SVGPatternElement.cpp"
  • trunk/WebCore/svg/SVGPathBuilder.h

    r64898 r64949  
    3737
    3838    void setCurrentPath(Path* path) { m_path = path; }
     39    virtual void cleanup() { m_path = 0; }
    3940
    4041private:
  • trunk/WebCore/svg/SVGPathByteStreamBuilder.h

    r64909 r64949  
    3535
    3636    void setCurrentByteStream(SVGPathByteStream* byteStream) { m_byteStream = byteStream; }
     37    virtual void cleanup() { m_byteStream = 0; }
    3738
    3839private:
  • trunk/WebCore/svg/SVGPathConsumer.h

    r64898 r64949  
    4343class SVGPathConsumer : public Noncopyable {
    4444public:
     45    virtual void cleanup() = 0;
     46
     47public:
    4548    // Used in UnalteredParisng/NormalizedParsing modes.
    4649    virtual void moveTo(const FloatPoint&, bool closed, PathCoordinateMode) = 0;
  • trunk/WebCore/svg/SVGPathParser.cpp

    r64898 r64949  
    426426}
    427427
     428void SVGPathParser::cleanup()
     429{
     430    ASSERT(m_source);
     431    ASSERT(m_consumer);
     432
     433    m_consumer->cleanup();
     434    m_source = 0;
     435    m_consumer = 0;
     436}
     437
    428438// This works by converting the SVG arc to "simple" beziers.
    429439// Partly adapted from Niko's code in kdelibs/kdecore/svgicons.
  • trunk/WebCore/svg/SVGPathParser.h

    r64898 r64949  
    4343    void setCurrentConsumer(SVGPathConsumer* consumer) { m_consumer = consumer; }
    4444    void setCurrentSource(SVGPathSource* source) { m_source = source; }
     45    void cleanup();
    4546
    4647private:
  • trunk/WebCore/svg/SVGPathParserFactory.cpp

    r64911 r64949  
    2323#include "SVGPathParserFactory.h"
    2424
     25#include "StringBuilder.h"
    2526#include "SVGPathBuilder.h"
    2627#include "SVGPathByteStreamBuilder.h"
    2728#include "SVGPathByteStreamSource.h"
     29#include "SVGPathStringBuilder.h"
    2830#include "SVGPathParser.h"
    2931#include "SVGPathSegListBuilder.h"
     
    3234namespace WebCore {
    3335
    34 static SVGPathBuilder* globalSVGPathBuilder()
     36static SVGPathBuilder* globalSVGPathBuilder(Path& result)
    3537{
    3638    static SVGPathBuilder* s_builder = 0;
     
    3840        s_builder = new SVGPathBuilder;
    3941
     42    s_builder->setCurrentPath(&result);
    4043    return s_builder;
    4144}
    4245
    43 static SVGPathSegListBuilder* globalSVGPathSegListBuilder()
     46static SVGPathSegListBuilder* globalSVGPathSegListBuilder(SVGPathSegList* result)
    4447{
    4548    static SVGPathSegListBuilder* s_builder = 0;
     
    4750        s_builder = new SVGPathSegListBuilder;
    4851
     52    s_builder->setCurrentSVGPathSegList(result);
    4953    return s_builder;
    5054}
    5155
    52 static SVGPathByteStreamBuilder* globalSVGPathByteStreamBuilder()
     56static SVGPathByteStreamBuilder* globalSVGPathByteStreamBuilder(SVGPathByteStream* result)
    5357{
    5458    static SVGPathByteStreamBuilder* s_builder = 0;
     
    5660        s_builder = new SVGPathByteStreamBuilder;
    5761
     62    s_builder->setCurrentByteStream(result);
    5863    return s_builder;
    5964}
    6065
    61 static SVGPathParser* globalSVGPathParser()
     66static SVGPathStringBuilder* globalSVGPathStringBuilder()
     67{
     68    static SVGPathStringBuilder* s_builder = 0;
     69    if (!s_builder)
     70        s_builder = new SVGPathStringBuilder;
     71
     72    return s_builder;
     73}
     74
     75static SVGPathParser* globalSVGPathParser(SVGPathSource* source, SVGPathConsumer* consumer)
    6276{
    6377    static SVGPathParser* s_parser = 0;
     
    6579        s_parser = new SVGPathParser;
    6680
     81    s_parser->setCurrentSource(source);
     82    s_parser->setCurrentConsumer(consumer);
    6783    return s_parser;
    6884}
     
    90106        return false;
    91107
    92     SVGPathBuilder* builder = globalSVGPathBuilder();
    93     builder->setCurrentPath(&result);
    94 
    95     SVGPathParser* parser = globalSVGPathParser();
    96     parser->setCurrentConsumer(builder);
     108    SVGPathBuilder* builder = globalSVGPathBuilder(result);
    97109
    98110    OwnPtr<SVGPathStringSource> source = SVGPathStringSource::create(d);
    99     parser->setCurrentSource(source.get());
    100 
     111    SVGPathParser* parser = globalSVGPathParser(source.get(), builder);
    101112    bool ok = parser->parsePathDataFromSource(NormalizedParsing);
    102     parser->setCurrentConsumer(0);
    103     parser->setCurrentSource(0);
    104     builder->setCurrentPath(0);
     113    parser->cleanup();
    105114    return ok;
    106115}
     
    112121        return false;
    113122
    114     SVGPathBuilder* builder = globalSVGPathBuilder();
    115     builder->setCurrentPath(&result);
    116 
    117     SVGPathParser* parser = globalSVGPathParser();
    118     parser->setCurrentConsumer(builder);
     123    SVGPathBuilder* builder = globalSVGPathBuilder(result);
    119124
    120125    OwnPtr<SVGPathByteStreamSource> source = SVGPathByteStreamSource::create(stream);
    121     parser->setCurrentSource(source.get());
    122 
     126    SVGPathParser* parser = globalSVGPathParser(source.get(), builder);
    123127    bool ok = parser->parsePathDataFromSource(NormalizedParsing);
    124     parser->setCurrentConsumer(0);
    125     parser->setCurrentSource(0);
    126     builder->setCurrentPath(0);
     128    parser->cleanup();
    127129    return ok;
    128130}
     
    134136        return false;
    135137
    136     SVGPathSegListBuilder* builder = globalSVGPathSegListBuilder();
    137     builder->setCurrentSVGPathSegList(result);
    138 
    139     SVGPathParser* parser = globalSVGPathParser();
    140     parser->setCurrentConsumer(builder);
     138    SVGPathSegListBuilder* builder = globalSVGPathSegListBuilder(result);
    141139
    142140    OwnPtr<SVGPathStringSource> source = SVGPathStringSource::create(d);
    143     parser->setCurrentSource(source.get());
    144 
     141    SVGPathParser* parser = globalSVGPathParser(source.get(), builder);
    145142    bool ok = parser->parsePathDataFromSource(parsingMode);
    146     parser->setCurrentConsumer(0);
    147     parser->setCurrentSource(0);
    148     builder->setCurrentSVGPathSegList(0);
     143    parser->cleanup();
    149144    return ok;
    150145}
     
    157152        return false;
    158153
    159     SVGPathSegListBuilder* builder = globalSVGPathSegListBuilder();
    160     builder->setCurrentSVGPathSegList(result);
    161 
    162     SVGPathParser* parser = globalSVGPathParser();
    163     parser->setCurrentConsumer(builder);
     154    SVGPathSegListBuilder* builder = globalSVGPathSegListBuilder(result);
    164155
    165156    OwnPtr<SVGPathByteStreamSource> source = SVGPathByteStreamSource::create(stream);
    166     parser->setCurrentSource(source.get());
    167 
     157    SVGPathParser* parser = globalSVGPathParser(source.get(), builder);
    168158    bool ok = parser->parsePathDataFromSource(parsingMode);
    169     parser->setCurrentConsumer(0);
    170     parser->setCurrentSource(0);
    171     builder->setCurrentSVGPathSegList(0);
     159    parser->cleanup();
    172160    return ok;
    173161}
    174162
    175 PassOwnPtr<SVGPathByteStream> SVGPathParserFactory::createSVGPathByteStreamFromString(const String& d, PathParsingMode parsingMode, bool& ok)
     163bool SVGPathParserFactory::buildStringFromByteStream(SVGPathByteStream* stream, String& result, PathParsingMode parsingMode)
    176164{
    177     if (d.isEmpty()) {
    178         ok = false;
    179         return PassOwnPtr<SVGPathByteStream>();
    180     }
     165    ASSERT(stream);
     166    if (stream->isEmpty())
     167        return false;
    181168
    182     SVGPathByteStreamBuilder* builder = globalSVGPathByteStreamBuilder();
     169    SVGPathStringBuilder* builder = globalSVGPathStringBuilder();
     170
     171    OwnPtr<SVGPathByteStreamSource> source = SVGPathByteStreamSource::create(stream);
     172    SVGPathParser* parser = globalSVGPathParser(source.get(), builder);
     173    bool ok = parser->parsePathDataFromSource(parsingMode);
     174    parser->cleanup();
     175    result = builder->result();
     176    return ok;
     177}
     178
     179bool SVGPathParserFactory::buildSVGPathByteStreamFromString(const String& d, OwnPtr<SVGPathByteStream>& result, PathParsingMode parsingMode)
     180{
     181    if (d.isEmpty())
     182        return false;
     183
    183184    OwnPtr<SVGPathByteStream> stream = SVGPathByteStream::create();
    184     builder->setCurrentByteStream(stream.get());
    185 
    186     SVGPathParser* parser = globalSVGPathParser();
    187     parser->setCurrentConsumer(builder);
     185    SVGPathByteStreamBuilder* builder = globalSVGPathByteStreamBuilder(stream.get());
    188186
    189187    OwnPtr<SVGPathStringSource> source = SVGPathStringSource::create(d);
    190     parser->setCurrentSource(source.get());
    191 
    192     ok = parser->parsePathDataFromSource(parsingMode);
    193     parser->setCurrentConsumer(0);
    194     parser->setCurrentSource(0);
    195     builder->setCurrentByteStream(0);
    196     return stream.release();
     188    SVGPathParser* parser = globalSVGPathParser(source.get(), builder);
     189    bool ok = parser->parsePathDataFromSource(parsingMode);
     190    result = stream.release();
     191    parser->cleanup();
     192    return ok;
    197193}
    198194
  • trunk/WebCore/svg/SVGPathParserFactory.h

    r64911 r64949  
    2727#include "SVGPathSegList.h"
    2828#include "SVGPathByteStream.h"
    29 #include <wtf/PassOwnPtr.h>
     29#include <wtf/OwnPtr.h>
    3030
    3131namespace WebCore {
     
    4141    bool buildSVGPathSegListFromByteStream(SVGPathByteStream*, SVGPathSegList*, PathParsingMode);
    4242
    43     PassOwnPtr<SVGPathByteStream> createSVGPathByteStreamFromString(const String&, PathParsingMode, bool& ok);
     43    bool buildStringFromByteStream(SVGPathByteStream*, String&, PathParsingMode);
     44
     45    bool buildSVGPathByteStreamFromString(const String&, OwnPtr<SVGPathByteStream>&, PathParsingMode);
    4446
    4547private:
  • trunk/WebCore/svg/SVGPathSegListBuilder.h

    r64898 r64949  
    3737
    3838    void setCurrentSVGPathSegList(SVGPathSegList* pathSegList) { m_pathSegList = pathSegList; }
     39    virtual void cleanup() { m_pathSegList = 0; }
    3940
    4041private:
Note: See TracChangeset for help on using the changeset viewer.