Changeset 65065 in webkit


Ignore:
Timestamp:
Aug 10, 2010 4:12:09 AM (14 years ago)
Author:
krit@webkit.org
Message:

2010-08-10 Dirk Schulze <krit@webkit.org>

Reviewed by Nikolas Zimmermann.

Use SVGPathParser to create SVG paths and to perform path animations
https://bugs.webkit.org/show_bug.cgi?id=43696

Removed toString() functions in all SVGPathSeg* objects as well as toPath() in SVGPathSegList.
These hacks were used to create a SVG path data string or a platform path from a SVGPathSegList.
Use the new SVGPathParser instead.

Doesn't affect any tests.

  • svg/SVGAnimateElement.cpp: (WebCore::SVGAnimateElement::applyResultsToTarget):
  • svg/SVGPathElement.cpp: (WebCore::SVGPathElement::toPathData):
  • svg/SVGPathParserFactory.cpp: (WebCore::SVGPathParserFactory::buildPathFromSVGPathSegList): (WebCore::SVGPathParserFactory::buildStringFromByteStream): (WebCore::SVGPathParserFactory::buildStringFromSVGPathSegList):
  • svg/SVGPathParserFactory.h:
  • svg/SVGPathSeg.cpp:
  • svg/SVGPathSeg.h:
  • svg/SVGPathSegArc.cpp:
  • svg/SVGPathSegArc.h:
  • svg/SVGPathSegClosePath.h: (WebCore::SVGPathSegClosePath::pathSegTypeAsLetter):
  • svg/SVGPathSegCurvetoCubic.h:
  • svg/SVGPathSegCurvetoCubicSmooth.h:
  • svg/SVGPathSegCurvetoQuadratic.h:
  • svg/SVGPathSegLinetoHorizontal.h:
  • svg/SVGPathSegLinetoVertical.h:
  • svg/SVGPathSegList.cpp: (WebCore::SVGPathSegList::getPathSegAtLength):
  • svg/SVGPathSegList.h:
Location:
trunk/WebCore
Files:
17 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r65064 r65065  
     12010-08-10  Dirk Schulze  <krit@webkit.org>
     2
     3        Reviewed by Nikolas Zimmermann.
     4
     5        Use SVGPathParser to create SVG paths and to perform path animations
     6        https://bugs.webkit.org/show_bug.cgi?id=43696
     7
     8        Removed toString() functions in all SVGPathSeg* objects as well as toPath() in SVGPathSegList.
     9        These hacks were used to create a SVG path data string or a platform path from a SVGPathSegList.
     10        Use the new SVGPathParser instead.
     11
     12        Doesn't affect any tests.
     13
     14        * svg/SVGAnimateElement.cpp:
     15        (WebCore::SVGAnimateElement::applyResultsToTarget):
     16        * svg/SVGPathElement.cpp:
     17        (WebCore::SVGPathElement::toPathData):
     18        * svg/SVGPathParserFactory.cpp:
     19        (WebCore::SVGPathParserFactory::buildPathFromSVGPathSegList):
     20        (WebCore::SVGPathParserFactory::buildStringFromByteStream):
     21        (WebCore::SVGPathParserFactory::buildStringFromSVGPathSegList):
     22        * svg/SVGPathParserFactory.h:
     23        * svg/SVGPathSeg.cpp:
     24        * svg/SVGPathSeg.h:
     25        * svg/SVGPathSegArc.cpp:
     26        * svg/SVGPathSegArc.h:
     27        * svg/SVGPathSegClosePath.h:
     28        (WebCore::SVGPathSegClosePath::pathSegTypeAsLetter):
     29        * svg/SVGPathSegCurvetoCubic.h:
     30        * svg/SVGPathSegCurvetoCubicSmooth.h:
     31        * svg/SVGPathSegCurvetoQuadratic.h:
     32        * svg/SVGPathSegLinetoHorizontal.h:
     33        * svg/SVGPathSegLinetoVertical.h:
     34        * svg/SVGPathSegList.cpp:
     35        (WebCore::SVGPathSegList::getPathSegAtLength):
     36        * svg/SVGPathSegList.h:
     37
    1382010-08-10  Sheriff Bot  <webkit.review.bot@gmail.com>
    239
  • trunk/WebCore/svg/SVGAnimateElement.cpp

    r64898 r65065  
    280280            // morphing needs to be done with unprocessed paths.
    281281            // FIXME: This could be optimized if paths were not processed at parse time.
    282             unsigned itemCount = m_animatedPath->numberOfItems();
    283             ExceptionCode ec;
    284             for (unsigned n = 0; n < itemCount; ++n) {
    285                 RefPtr<SVGPathSeg> segment = m_animatedPath->getItem(n, ec);
    286                 valueToApply.append(segment->toString() + " ");
    287             }
     282            SVGPathParserFactory* factory = SVGPathParserFactory::self();
     283            factory->buildStringFromSVGPathSegList(m_animatedPath.get(), valueToApply, UnalteredParsing);
    288284        }
    289285    } else if (m_propertyType == PointsProperty) {
  • trunk/WebCore/svg/SVGPathElement.cpp

    r64898 r65065  
    264264Path SVGPathElement::toPathData() const
    265265{
    266     return pathSegList()->toPathData();
     266    Path result;
     267    SVGPathParserFactory* factory = SVGPathParserFactory::self();
     268    factory->buildPathFromSVGPathSegList(pathSegList(), result);
     269    return result;
    267270}
    268271
  • trunk/WebCore/svg/SVGPathParserFactory.cpp

    r64949 r65065  
    2727#include "SVGPathByteStreamBuilder.h"
    2828#include "SVGPathByteStreamSource.h"
    29 #include "SVGPathStringBuilder.h"
    3029#include "SVGPathParser.h"
    3130#include "SVGPathSegListBuilder.h"
     31#include "SVGPathSegListSource.h"
     32#include "SVGPathStringBuilder.h"
    3233#include "SVGPathStringSource.h"
    3334
     
    124125
    125126    OwnPtr<SVGPathByteStreamSource> source = SVGPathByteStreamSource::create(stream);
     127    SVGPathParser* parser = globalSVGPathParser(source.get(), builder);
     128    bool ok = parser->parsePathDataFromSource(NormalizedParsing);
     129    parser->cleanup();
     130    return ok;
     131}
     132
     133bool SVGPathParserFactory::buildPathFromSVGPathSegList(SVGPathSegList* pathSegList, Path& result)
     134{
     135    ASSERT(pathSegList);
     136    if (!pathSegList->numberOfItems())
     137        return false;
     138
     139    SVGPathBuilder* builder = globalSVGPathBuilder(result);
     140
     141    OwnPtr<SVGPathSegListSource> source = SVGPathSegListSource::create(pathSegList);
    126142    SVGPathParser* parser = globalSVGPathParser(source.get(), builder);
    127143    bool ok = parser->parsePathDataFromSource(NormalizedParsing);
     
    172188    SVGPathParser* parser = globalSVGPathParser(source.get(), builder);
    173189    bool ok = parser->parsePathDataFromSource(parsingMode);
    174     parser->cleanup();
    175190    result = builder->result();
     191    parser->cleanup();
     192    return ok;
     193}
     194
     195bool SVGPathParserFactory::buildStringFromSVGPathSegList(SVGPathSegList* pathSegList, String& result, PathParsingMode parsingMode)
     196{
     197    ASSERT(pathSegList);
     198    if (!pathSegList->numberOfItems())
     199        return false;
     200
     201    SVGPathStringBuilder* builder = globalSVGPathStringBuilder();
     202
     203    OwnPtr<SVGPathSegListSource> source = SVGPathSegListSource::create(pathSegList);
     204    SVGPathParser* parser = globalSVGPathParser(source.get(), builder);
     205    bool ok = parser->parsePathDataFromSource(parsingMode);
     206    result = builder->result();
     207    parser->cleanup();
    176208    return ok;
    177209}
  • trunk/WebCore/svg/SVGPathParserFactory.h

    r64949 r65065  
    3636
    3737    bool buildPathFromString(const String&, Path&);
    38     bool buildPathFromByteStream(SVGPathByteStream*, Path& result);
     38    bool buildPathFromByteStream(SVGPathByteStream*, Path&);
     39    bool buildPathFromSVGPathSegList(SVGPathSegList*, Path&);
    3940
    4041    bool buildSVGPathSegListFromString(const String&, SVGPathSegList*, PathParsingMode);
     
    4243
    4344    bool buildStringFromByteStream(SVGPathByteStream*, String&, PathParsingMode);
     45    bool buildStringFromSVGPathSegList(SVGPathSegList*, String&, PathParsingMode);
    4446
    4547    bool buildSVGPathByteStreamFromString(const String&, OwnPtr<SVGPathByteStream>&, PathParsingMode);
  • trunk/WebCore/svg/SVGPathSeg.cpp

    r64807 r65065  
    4646}
    4747
    48 String SVGPathSeg::toString() const
    49 {
    50     return "";
    51 }
    52 
    5348const QualifiedName& SVGPathSeg::associatedAttributeName() const
    5449{
     
    5651}
    5752
    58 String SVGPathSegSingleCoord::toString() const
    59 {
    60     return pathSegTypeAsLetter() + String::format(" %.6lg %.6lg", m_x, m_y);
    61 }
    62 
    6353} // namespace WebCore
    6454#endif // ENABLE(SVG)
  • trunk/WebCore/svg/SVGPathSeg.h

    r65021 r65065  
    8686    virtual unsigned short pathSegType() const;
    8787    virtual String pathSegTypeAsLetter() const;
    88     virtual String toString() const;
    8988
    9089    const QualifiedName& associatedAttributeName() const;
     
    108107    float y() const { return m_y; }
    109108
    110     virtual String toString() const;
    111 
    112109private:
    113110    float m_x;
  • trunk/WebCore/svg/SVGPathSegArc.cpp

    r64793 r65065  
    2626namespace WebCore {
    2727
    28 String SVGPathSegArc::toString() const
    29 {
    30     return pathSegTypeAsLetter() + String::format(" %.6lg %.6lg %.6lg %d %d %.6lg %.6lg", m_r1, m_r2, m_angle, m_largeArcFlag, m_sweepFlag, m_x, m_y);
    31 }
    32 
    3328SVGPathSegArcAbs::SVGPathSegArcAbs(float x, float y, float r1, float r2, float angle, bool largeArcFlag, bool sweepFlag)
    3429    : SVGPathSegArc(x, y, r1, r2, angle, largeArcFlag, sweepFlag)
  • trunk/WebCore/svg/SVGPathSegArc.h

    r64793 r65065  
    4141        {
    4242        }
    43 
    44         virtual String toString() const;
    4543
    4644        void setX(float x) { m_x = x; }
  • trunk/WebCore/svg/SVGPathSegClosePath.h

    r64793 r65065  
    3636    virtual unsigned short pathSegType() const { return PATHSEG_CLOSEPATH; }
    3737    virtual String pathSegTypeAsLetter() const { return "Z"; }
    38     virtual String toString() const { return "Z"; }
    3938
    4039private:
  • trunk/WebCore/svg/SVGPathSegCurvetoCubic.h

    r64793 r65065  
    3232    public:
    3333        SVGPathSegCurvetoCubic(float x, float y, float x1, float y1, float x2, float y2) : SVGPathSeg() , m_x(x) , m_y(y) , m_x1(x1) , m_y1(y1) , m_x2(x2) , m_y2(y2) {}
    34 
    35         virtual String toString() const { return pathSegTypeAsLetter() + String::format(" %.6lg %.6lg %.6lg %.6lg %.6lg %.6lg", m_x1, m_y1, m_x2, m_y2, m_x, m_y); }
    3634
    3735        void setX(float x) { m_x = x; }
  • trunk/WebCore/svg/SVGPathSegCurvetoCubicSmooth.h

    r64793 r65065  
    3333        SVGPathSegCurvetoCubicSmooth(float x, float y, float x2, float y2)
    3434        : m_x(x), m_y(y), m_x2(x2), m_y2(y2) { }
    35 
    36         virtual String toString() const { return pathSegTypeAsLetter() + String::format(" %.6lg %.6lg %.6lg %.6lg", m_x2, m_y2, m_x, m_y); }
    3735
    3836        void setX(float x) { m_x = x; }
  • trunk/WebCore/svg/SVGPathSegCurvetoQuadratic.h

    r64793 r65065  
    3333        SVGPathSegCurvetoQuadratic(float x, float y, float x1, float y1)
    3434        : SVGPathSeg(), m_x(x), m_y(y), m_x1(x1), m_y1(y1) {}
    35 
    36         virtual String toString() const { return pathSegTypeAsLetter() + String::format(" %.6lg %.6lg %.6lg %.6lg", m_x1, m_y1, m_x, m_y); }
    3735
    3836        void setX(float x) { m_x = x; }
  • trunk/WebCore/svg/SVGPathSegLinetoHorizontal.h

    r64793 r65065  
    3232    public:
    3333        SVGPathSegLinetoHorizontal(float x) : SVGPathSeg(), m_x(x) {}
    34 
    35         virtual String toString() const { return pathSegTypeAsLetter() + String::format(" %.6lg", m_x); }
    3634
    3735        void setX(float x) { m_x = x; }
  • trunk/WebCore/svg/SVGPathSegLinetoVertical.h

    r64793 r65065  
    3232    public:
    3333        SVGPathSegLinetoVertical(float y) : SVGPathSeg(), m_y(y) {}
    34 
    35         virtual String toString() const { return pathSegTypeAsLetter() + String::format(" %.6lg", m_y); }
    3634
    3735        void setY(float y) { m_y = y; }
  • trunk/WebCore/svg/SVGPathSegList.cpp

    r64898 r65065  
    104104    return traversalState.m_segmentIndex ? traversalState.m_segmentIndex - 1 : 0;
    105105}
    106 
    107 Path SVGPathSegList::toPathData()
    108 {
    109     // FIXME : This should also support non-normalized PathSegLists
    110     Path pathData;
    111     int len = numberOfItems();
    112     ExceptionCode ec = 0;
    113     FloatPoint previousEndPoint(0, 0);
    114     for (int i = 0; i < len; ++i) {
    115         SVGPathSeg* segment = getItem(i, ec).get();
    116         if (ec)
    117             return Path();
    118         switch (segment->pathSegType()) {
    119         case PathSegMoveToAbs: {
    120             SVGPathSegMovetoAbs* moveTo = static_cast<SVGPathSegMovetoAbs*>(segment);
    121             FloatPoint endPoint(moveTo->x(), moveTo->y());
    122             pathData.moveTo(endPoint);
    123             previousEndPoint = endPoint;
    124             break;
    125         }
    126         case PathSegLineToAbs: {
    127             SVGPathSegLinetoAbs* lineTo = static_cast<SVGPathSegLinetoAbs*>(segment);
    128             FloatPoint endPoint(lineTo->x(), lineTo->y());
    129             pathData.addLineTo(endPoint);
    130             previousEndPoint = endPoint;
    131             break;
    132         }
    133         case PathSegCurveToCubicAbs: {
    134             SVGPathSegCurvetoCubicAbs* curveTo = static_cast<SVGPathSegCurvetoCubicAbs*>(segment);
    135             FloatPoint endPoint(curveTo->x(), curveTo->y());
    136             pathData.addBezierCurveTo(FloatPoint(curveTo->x1(), curveTo->y1()),
    137                                       FloatPoint(curveTo->x2(), curveTo->y2()),
    138                                       endPoint);
    139             previousEndPoint = endPoint;
    140             break;
    141         }
    142         case PathSegCurveToCubicRel: {
    143             SVGPathSegCurvetoCubicRel* curveTo = static_cast<SVGPathSegCurvetoCubicRel*>(segment);
    144             FloatSize endPoint(curveTo->x(), curveTo->y());
    145             pathData.addBezierCurveTo(previousEndPoint + FloatSize(curveTo->x1(), curveTo->y1()),
    146                                       previousEndPoint + FloatSize(curveTo->x2(), curveTo->y2()),
    147                                       previousEndPoint + endPoint);
    148             previousEndPoint += endPoint;
    149             break;
    150         }
    151         case PathSegClosePath:
    152             pathData.closeSubpath();
    153             break;
    154         default:
    155             ASSERT(false); // FIXME: This only works with normalized/processed path data.
    156             break;
    157         }
    158     }
    159    
    160     return pathData;
    161 }
    162106   
    163107float adjustAnimatedValue(float from, float to, float progress)
  • trunk/WebCore/svg/SVGPathSegList.h

    r64579 r65065  
    3636
    3737        unsigned getPathSegAtLength(double, ExceptionCode&);
    38         Path toPathData();
    3938       
    4039        static PassRefPtr<SVGPathSegList> createAnimated(const SVGPathSegList* fromList, const SVGPathSegList* toList, float progress);
Note: See TracChangeset for help on using the changeset viewer.