Changeset 190849 in webkit


Ignore:
Timestamp:
Oct 11, 2015 8:34:08 PM (8 years ago)
Author:
Simon Fraser
Message:

Cleanup and simplification of SVG path-related classes
https://bugs.webkit.org/show_bug.cgi?id=150011

Reviewed by Zalan Bujtas.

Many SVG path-related subclasses were stateful, but only because code in
SVGPathUtilities kept global copies around for no reason. A microbenchmark
showed that there was no benefit to keeping global singletons of SVGPathBuilder,
SVGPathSegListBuilder, SVGPathByteStreamBuilder, SVGPathStringBuilder,
SVGPathTraversalStateBuilder, SVGPathParser and SVGPathBlender.

Making these classes not be re-usable makes the code much simpler, allowing
their SVGPathSources, SVGPathConsumers, SVGPathByteStream etc. to be stored
by reference, and eliminating the cleanup() function which created annoying
ordering issues.

Code that uses SVGPathParser and SVGPathBlender is further simplified by having
these classes expose only static functions, hiding any internal statefulness.

  • svg/SVGPathBlender.cpp: Remove the m_progress member variable and instead

pass progress to the various blend functions, as we do for other blend functions.
Expose two only static functions. Pointers to references.
(WebCore::SVGPathBlender::addAnimatedPath):
(WebCore::SVGPathBlender::blendAnimatedPath):
(WebCore::SVGPathBlender::SVGPathBlender):
(WebCore::SVGPathBlender::blendAnimatedDimensonalFloat):
(WebCore::SVGPathBlender::blendAnimatedFloatPoint):
(WebCore::SVGPathBlender::blendMoveToSegment):
(WebCore::SVGPathBlender::blendLineToSegment):
(WebCore::SVGPathBlender::blendLineToHorizontalSegment):
(WebCore::SVGPathBlender::blendLineToVerticalSegment):
(WebCore::SVGPathBlender::blendCurveToCubicSegment):
(WebCore::SVGPathBlender::blendCurveToCubicSmoothSegment):
(WebCore::SVGPathBlender::blendCurveToQuadraticSegment):
(WebCore::SVGPathBlender::blendCurveToQuadraticSmoothSegment):
(WebCore::SVGPathBlender::blendArcToSegment):
(WebCore::SVGPathBlender::cleanup): Deleted.

  • svg/SVGPathBlender.h: Make the constructor take a ref to the destination Path,

which is stored by reference.

  • svg/SVGPathBuilder.cpp:

(WebCore::SVGPathBuilder::SVGPathBuilder):
(WebCore::SVGPathBuilder::moveTo):
(WebCore::SVGPathBuilder::lineTo):
(WebCore::SVGPathBuilder::curveToCubic):
(WebCore::SVGPathBuilder::closePath):

  • svg/SVGPathBuilder.h:

(WebCore::SVGPathBuilder::setCurrentPath): Deleted.

  • svg/SVGPathByteStreamBuilder.cpp: References, assertions removed.

(WebCore::SVGPathByteStreamBuilder::SVGPathByteStreamBuilder):

  • svg/SVGPathByteStreamBuilder.h:

(WebCore::SVGPathByteStreamBuilder::writeType):
(WebCore::SVGPathByteStreamBuilder::setCurrentByteStream): Deleted.

  • svg/SVGPathConsumer.h:
  • svg/SVGPathElement.cpp:
  • svg/SVGPathParser.cpp: Expose some static helper functions for parsing

to byte streams and strings. References.
(WebCore::SVGPathParser::parse):
(WebCore::SVGPathParser::parseToByteStream):
(WebCore::SVGPathParser::parseToString):
(WebCore::SVGPathParser::SVGPathParser):
(WebCore::SVGPathParser::parseClosePathSegment):
(WebCore::SVGPathParser::parseMoveToSegment):
(WebCore::SVGPathParser::parseLineToSegment):
(WebCore::SVGPathParser::parseLineToHorizontalSegment):
(WebCore::SVGPathParser::parseLineToVerticalSegment):
(WebCore::SVGPathParser::parseCurveToCubicSegment):
(WebCore::SVGPathParser::parseCurveToCubicSmoothSegment):
(WebCore::SVGPathParser::parseCurveToQuadraticSegment):
(WebCore::SVGPathParser::parseCurveToQuadraticSmoothSegment):
(WebCore::SVGPathParser::parseArcToSegment):
(WebCore::SVGPathParser::parsePathData):
(WebCore::SVGPathParser::decomposeArcToCubic):
(WebCore::SVGPathParser::parsePathDataFromSource): Deleted.
(WebCore::SVGPathParser::cleanup): Deleted.

  • svg/SVGPathParser.h:

(WebCore::SVGPathParser::setCurrentConsumer): Deleted.
(WebCore::SVGPathParser::setCurrentSource): Deleted.

  • svg/SVGPathSegListBuilder.cpp:

(WebCore::SVGPathSegListBuilder::SVGPathSegListBuilder):
(WebCore::SVGPathSegListBuilder::moveTo):
(WebCore::SVGPathSegListBuilder::lineTo):
(WebCore::SVGPathSegListBuilder::lineToHorizontal):
(WebCore::SVGPathSegListBuilder::lineToVertical):
(WebCore::SVGPathSegListBuilder::curveToCubic):
(WebCore::SVGPathSegListBuilder::curveToCubicSmooth):
(WebCore::SVGPathSegListBuilder::curveToQuadratic):
(WebCore::SVGPathSegListBuilder::curveToQuadraticSmooth):
(WebCore::SVGPathSegListBuilder::arcTo):
(WebCore::SVGPathSegListBuilder::closePath):

  • svg/SVGPathSegListBuilder.h:

(WebCore::SVGPathSegListBuilder::setCurrentSVGPathElement): Deleted.
(WebCore::SVGPathSegListBuilder::setCurrentSVGPathSegList): Deleted.
(WebCore::SVGPathSegListBuilder::setCurrentSVGPathSegRole): Deleted.

  • svg/SVGPathStringBuilder.cpp:

(WebCore::SVGPathStringBuilder::cleanup): Deleted.

  • svg/SVGPathStringBuilder.h:
  • svg/SVGPathTraversalStateBuilder.cpp:

(WebCore::SVGPathTraversalStateBuilder::SVGPathTraversalStateBuilder):
(WebCore::SVGPathTraversalStateBuilder::moveTo):
(WebCore::SVGPathTraversalStateBuilder::lineTo):
(WebCore::SVGPathTraversalStateBuilder::curveToCubic):
(WebCore::SVGPathTraversalStateBuilder::closePath):
(WebCore::SVGPathTraversalStateBuilder::continueConsuming):
(WebCore::SVGPathTraversalStateBuilder::totalLength):
(WebCore::SVGPathTraversalStateBuilder::currentPoint):
(WebCore::SVGPathTraversalStateBuilder::setDesiredLength): Deleted.

  • svg/SVGPathTraversalStateBuilder.h:

(WebCore::SVGPathTraversalStateBuilder::pathSegmentIndex):
(WebCore::SVGPathTraversalStateBuilder::setCurrentTraversalState): Deleted.

  • svg/SVGPathUtilities.cpp: Remove globals accessors, making things on the stack

instead. Use SVGPathParser helper functions where possible.
(WebCore::buildPathFromString):
(WebCore::buildSVGPathByteStreamFromSVGPathSegList):
(WebCore::appendSVGPathByteStreamFromSVGPathSeg):
(WebCore::buildPathFromByteStream):
(WebCore::buildSVGPathSegListFromByteStream):
(WebCore::buildStringFromByteStream):
(WebCore::buildStringFromSVGPathSegList):
(WebCore::buildSVGPathByteStreamFromString):
(WebCore::buildAnimatedSVGPathByteStream):
(WebCore::addToSVGPathByteStream):
(WebCore::getSVGPathSegAtLengthFromSVGPathByteStream):
(WebCore::getTotalLengthOfSVGPathByteStream):
(WebCore::getPointAtLengthOfSVGPathByteStream):
(WebCore::buildStringFromPath):
(WebCore::globalSVGPathBuilder): Deleted.
(WebCore::globalSVGPathSegListBuilder): Deleted.
(WebCore::globalSVGPathByteStreamBuilder): Deleted.
(WebCore::globalSVGPathStringBuilder): Deleted.
(WebCore::globalSVGPathTraversalStateBuilder): Deleted.
(WebCore::globalSVGPathParser): Deleted.
(WebCore::globalSVGPathBlender): Deleted.

  • svg/SVGPathUtilities.h:
  • svg/SVGToOTFFontConversion.cpp: CFFBuilder no longer inherits from SVGPathBuilder.

It did nothing with the Path, re-implemented all the functions, and only made use of
the m_current member var, so just make it inherit from SVGPathConsumer, and have
its own m_current.
(WebCore::SVGToOTFFontConverter::transcodeGlyphPaths):

Location:
trunk/Source/WebCore
Files:
20 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r190845 r190849  
     12015-10-11  Simon Fraser  <simon.fraser@apple.com>
     2
     3        Cleanup and simplification of SVG path-related classes
     4        https://bugs.webkit.org/show_bug.cgi?id=150011
     5
     6        Reviewed by Zalan Bujtas.
     7
     8        Many SVG path-related subclasses were stateful, but only because code in
     9        SVGPathUtilities kept global copies around for no reason. A microbenchmark
     10        showed that there was no benefit to keeping global singletons of SVGPathBuilder,
     11        SVGPathSegListBuilder, SVGPathByteStreamBuilder, SVGPathStringBuilder,
     12        SVGPathTraversalStateBuilder, SVGPathParser and SVGPathBlender.
     13       
     14        Making these classes not be re-usable makes the code much simpler, allowing
     15        their SVGPathSources, SVGPathConsumers, SVGPathByteStream etc. to be stored
     16        by reference, and eliminating the cleanup() function which created annoying
     17        ordering issues.
     18       
     19        Code that uses SVGPathParser and SVGPathBlender is further simplified by having
     20        these classes expose only static functions, hiding any internal statefulness.
     21
     22        * svg/SVGPathBlender.cpp: Remove the m_progress member variable and instead
     23        pass progress to the various blend functions, as we do for other blend functions.
     24        Expose two only static functions. Pointers to references.
     25        (WebCore::SVGPathBlender::addAnimatedPath):
     26        (WebCore::SVGPathBlender::blendAnimatedPath):
     27        (WebCore::SVGPathBlender::SVGPathBlender):
     28        (WebCore::SVGPathBlender::blendAnimatedDimensonalFloat):
     29        (WebCore::SVGPathBlender::blendAnimatedFloatPoint):
     30        (WebCore::SVGPathBlender::blendMoveToSegment):
     31        (WebCore::SVGPathBlender::blendLineToSegment):
     32        (WebCore::SVGPathBlender::blendLineToHorizontalSegment):
     33        (WebCore::SVGPathBlender::blendLineToVerticalSegment):
     34        (WebCore::SVGPathBlender::blendCurveToCubicSegment):
     35        (WebCore::SVGPathBlender::blendCurveToCubicSmoothSegment):
     36        (WebCore::SVGPathBlender::blendCurveToQuadraticSegment):
     37        (WebCore::SVGPathBlender::blendCurveToQuadraticSmoothSegment):
     38        (WebCore::SVGPathBlender::blendArcToSegment):
     39        (WebCore::SVGPathBlender::cleanup): Deleted.
     40        * svg/SVGPathBlender.h: Make the constructor take a ref to the destination Path,
     41        which is stored by reference.
     42        * svg/SVGPathBuilder.cpp:
     43        (WebCore::SVGPathBuilder::SVGPathBuilder):
     44        (WebCore::SVGPathBuilder::moveTo):
     45        (WebCore::SVGPathBuilder::lineTo):
     46        (WebCore::SVGPathBuilder::curveToCubic):
     47        (WebCore::SVGPathBuilder::closePath):
     48        * svg/SVGPathBuilder.h:
     49        (WebCore::SVGPathBuilder::setCurrentPath): Deleted.
     50        * svg/SVGPathByteStreamBuilder.cpp: References, assertions removed.
     51        (WebCore::SVGPathByteStreamBuilder::SVGPathByteStreamBuilder):
     52        * svg/SVGPathByteStreamBuilder.h:
     53        (WebCore::SVGPathByteStreamBuilder::writeType):
     54        (WebCore::SVGPathByteStreamBuilder::setCurrentByteStream): Deleted.
     55        * svg/SVGPathConsumer.h:
     56        * svg/SVGPathElement.cpp:
     57        * svg/SVGPathParser.cpp: Expose some static helper functions for parsing
     58        to byte streams and strings. References.
     59        (WebCore::SVGPathParser::parse):
     60        (WebCore::SVGPathParser::parseToByteStream):
     61        (WebCore::SVGPathParser::parseToString):
     62        (WebCore::SVGPathParser::SVGPathParser):
     63        (WebCore::SVGPathParser::parseClosePathSegment):
     64        (WebCore::SVGPathParser::parseMoveToSegment):
     65        (WebCore::SVGPathParser::parseLineToSegment):
     66        (WebCore::SVGPathParser::parseLineToHorizontalSegment):
     67        (WebCore::SVGPathParser::parseLineToVerticalSegment):
     68        (WebCore::SVGPathParser::parseCurveToCubicSegment):
     69        (WebCore::SVGPathParser::parseCurveToCubicSmoothSegment):
     70        (WebCore::SVGPathParser::parseCurveToQuadraticSegment):
     71        (WebCore::SVGPathParser::parseCurveToQuadraticSmoothSegment):
     72        (WebCore::SVGPathParser::parseArcToSegment):
     73        (WebCore::SVGPathParser::parsePathData):
     74        (WebCore::SVGPathParser::decomposeArcToCubic):
     75        (WebCore::SVGPathParser::parsePathDataFromSource): Deleted.
     76        (WebCore::SVGPathParser::cleanup): Deleted.
     77        * svg/SVGPathParser.h:
     78        (WebCore::SVGPathParser::setCurrentConsumer): Deleted.
     79        (WebCore::SVGPathParser::setCurrentSource): Deleted.
     80        * svg/SVGPathSegListBuilder.cpp:
     81        (WebCore::SVGPathSegListBuilder::SVGPathSegListBuilder):
     82        (WebCore::SVGPathSegListBuilder::moveTo):
     83        (WebCore::SVGPathSegListBuilder::lineTo):
     84        (WebCore::SVGPathSegListBuilder::lineToHorizontal):
     85        (WebCore::SVGPathSegListBuilder::lineToVertical):
     86        (WebCore::SVGPathSegListBuilder::curveToCubic):
     87        (WebCore::SVGPathSegListBuilder::curveToCubicSmooth):
     88        (WebCore::SVGPathSegListBuilder::curveToQuadratic):
     89        (WebCore::SVGPathSegListBuilder::curveToQuadraticSmooth):
     90        (WebCore::SVGPathSegListBuilder::arcTo):
     91        (WebCore::SVGPathSegListBuilder::closePath):
     92        * svg/SVGPathSegListBuilder.h:
     93        (WebCore::SVGPathSegListBuilder::setCurrentSVGPathElement): Deleted.
     94        (WebCore::SVGPathSegListBuilder::setCurrentSVGPathSegList): Deleted.
     95        (WebCore::SVGPathSegListBuilder::setCurrentSVGPathSegRole): Deleted.
     96        * svg/SVGPathStringBuilder.cpp:
     97        (WebCore::SVGPathStringBuilder::cleanup): Deleted.
     98        * svg/SVGPathStringBuilder.h:
     99        * svg/SVGPathTraversalStateBuilder.cpp:
     100        (WebCore::SVGPathTraversalStateBuilder::SVGPathTraversalStateBuilder):
     101        (WebCore::SVGPathTraversalStateBuilder::moveTo):
     102        (WebCore::SVGPathTraversalStateBuilder::lineTo):
     103        (WebCore::SVGPathTraversalStateBuilder::curveToCubic):
     104        (WebCore::SVGPathTraversalStateBuilder::closePath):
     105        (WebCore::SVGPathTraversalStateBuilder::continueConsuming):
     106        (WebCore::SVGPathTraversalStateBuilder::totalLength):
     107        (WebCore::SVGPathTraversalStateBuilder::currentPoint):
     108        (WebCore::SVGPathTraversalStateBuilder::setDesiredLength): Deleted.
     109        * svg/SVGPathTraversalStateBuilder.h:
     110        (WebCore::SVGPathTraversalStateBuilder::pathSegmentIndex):
     111        (WebCore::SVGPathTraversalStateBuilder::setCurrentTraversalState): Deleted.
     112        * svg/SVGPathUtilities.cpp: Remove globals accessors, making things on the stack
     113        instead. Use SVGPathParser helper functions where possible.
     114        (WebCore::buildPathFromString):
     115        (WebCore::buildSVGPathByteStreamFromSVGPathSegList):
     116        (WebCore::appendSVGPathByteStreamFromSVGPathSeg):
     117        (WebCore::buildPathFromByteStream):
     118        (WebCore::buildSVGPathSegListFromByteStream):
     119        (WebCore::buildStringFromByteStream):
     120        (WebCore::buildStringFromSVGPathSegList):
     121        (WebCore::buildSVGPathByteStreamFromString):
     122        (WebCore::buildAnimatedSVGPathByteStream):
     123        (WebCore::addToSVGPathByteStream):
     124        (WebCore::getSVGPathSegAtLengthFromSVGPathByteStream):
     125        (WebCore::getTotalLengthOfSVGPathByteStream):
     126        (WebCore::getPointAtLengthOfSVGPathByteStream):
     127        (WebCore::buildStringFromPath):
     128        (WebCore::globalSVGPathBuilder): Deleted.
     129        (WebCore::globalSVGPathSegListBuilder): Deleted.
     130        (WebCore::globalSVGPathByteStreamBuilder): Deleted.
     131        (WebCore::globalSVGPathStringBuilder): Deleted.
     132        (WebCore::globalSVGPathTraversalStateBuilder): Deleted.
     133        (WebCore::globalSVGPathParser): Deleted.
     134        (WebCore::globalSVGPathBlender): Deleted.
     135        * svg/SVGPathUtilities.h:
     136        * svg/SVGToOTFFontConversion.cpp: CFFBuilder no longer inherits from SVGPathBuilder.
     137        It did nothing with the Path, re-implemented all the functions, and only made use of
     138        the m_current member var, so just make it inherit from SVGPathConsumer, and have
     139        its own m_current.
     140        (WebCore::SVGToOTFFontConverter::transcodeGlyphPaths):
     141
    11422015-10-10  Antti Koivisto  <antti@apple.com>
    2143
  • trunk/Source/WebCore/svg/SVGPathBlender.cpp

    r184852 r190849  
    11/*
    22 * Copyright (C) Research In Motion Limited 2010, 2011. All rights reserved.
     3 * Copyright (C) 2015 Apple Inc. All rights reserved.
    34 *
    45 * This library is free software; you can redistribute it and/or
     
    2829namespace WebCore {
    2930
    30 SVGPathBlender::SVGPathBlender()
    31     : m_fromSource(nullptr)
    32     , m_toSource(nullptr)
    33     , m_consumer(nullptr)
    34     , m_progress(0)
    35     , m_addTypesCount(0)
    36     , m_isInFirstHalfOfAnimation(false)
     31bool SVGPathBlender::addAnimatedPath(SVGPathSource& fromSource, SVGPathSource& toSource, SVGPathConsumer& consumer, unsigned repeatCount)
     32{
     33    SVGPathBlender blender(fromSource, toSource, consumer);
     34    return blender.addAnimatedPath(repeatCount);
     35}
     36
     37bool SVGPathBlender::blendAnimatedPath(SVGPathSource& fromSource, SVGPathSource& toSource, SVGPathConsumer& consumer, float progress)
     38{
     39    SVGPathBlender blender(fromSource, toSource, consumer);
     40    return blender.blendAnimatedPath(progress);
     41}
     42
     43SVGPathBlender::SVGPathBlender(SVGPathSource& fromSource, SVGPathSource& toSource, SVGPathConsumer& consumer)
     44    : m_fromSource(fromSource)
     45    , m_toSource(toSource)
     46    , m_consumer(consumer)
    3747{
    3848}
     
    4454}
    4555
    46 float SVGPathBlender::blendAnimatedDimensonalFloat(float from, float to, FloatBlendMode blendMode)
     56float SVGPathBlender::blendAnimatedDimensonalFloat(float from, float to, FloatBlendMode blendMode, float progress)
    4757{
    4858    if (m_addTypesCount) {
     
    5262
    5363    if (m_fromMode == m_toMode)
    54         return blend(from, to, m_progress);
     64        return blend(from, to, progress);
    5565   
    5666    float fromValue = blendMode == BlendHorizontal ? m_fromCurrentPoint.x() : m_fromCurrentPoint.y();
     
    5868
    5969    // Transform toY to the coordinate mode of fromY
    60     float animValue = blend(from, m_fromMode == AbsoluteCoordinates ? to + toValue : to - toValue, m_progress);
     70    float animValue = blend(from, m_fromMode == AbsoluteCoordinates ? to + toValue : to - toValue, progress);
    6171   
    6272    if (m_isInFirstHalfOfAnimation)
     
    6474   
    6575    // Transform the animated point to the coordinate mode, needed for the current progress.
    66     float currentValue = blend(fromValue, toValue, m_progress);
     76    float currentValue = blend(fromValue, toValue, progress);
    6777    return m_toMode == AbsoluteCoordinates ? animValue + currentValue : animValue - currentValue;
    6878}
    6979
    70 FloatPoint SVGPathBlender::blendAnimatedFloatPoint(const FloatPoint& fromPoint, const FloatPoint& toPoint)
     80FloatPoint SVGPathBlender::blendAnimatedFloatPoint(const FloatPoint& fromPoint, const FloatPoint& toPoint, float progress)
    7181{
    7282    if (m_addTypesCount) {
     
    7888
    7989    if (m_fromMode == m_toMode)
    80         return blendFloatPoint(fromPoint, toPoint, m_progress);
     90        return blendFloatPoint(fromPoint, toPoint, progress);
    8191
    8292    // Transform toPoint to the coordinate mode of fromPoint
     
    8797        animatedPoint.move(-m_toCurrentPoint.x(), -m_toCurrentPoint.y());
    8898
    89     animatedPoint = blendFloatPoint(fromPoint, animatedPoint, m_progress);
     99    animatedPoint = blendFloatPoint(fromPoint, animatedPoint, progress);
    90100
    91101    if (m_isInFirstHalfOfAnimation)
     
    93103
    94104    // Transform the animated point to the coordinate mode, needed for the current progress.
    95     FloatPoint currentPoint = blendFloatPoint(m_fromCurrentPoint, m_toCurrentPoint, m_progress);
     105    FloatPoint currentPoint = blendFloatPoint(m_fromCurrentPoint, m_toCurrentPoint, progress);
    96106    if (m_toMode == AbsoluteCoordinates)
    97107        return animatedPoint + currentPoint;
     
    101111}
    102112
    103 bool SVGPathBlender::blendMoveToSegment()
    104 {
    105     FloatPoint fromTargetPoint;
    106     FloatPoint toTargetPoint;
    107     if ((m_fromSource->hasMoreData() && !m_fromSource->parseMoveToSegment(fromTargetPoint))
    108         || !m_toSource->parseMoveToSegment(toTargetPoint))
    109         return false;
    110 
    111     m_consumer->moveTo(blendAnimatedFloatPoint(fromTargetPoint, toTargetPoint), false, m_isInFirstHalfOfAnimation ? m_fromMode : m_toMode);
    112     m_fromCurrentPoint = m_fromMode == AbsoluteCoordinates ? fromTargetPoint : m_fromCurrentPoint + fromTargetPoint;
    113     m_toCurrentPoint = m_toMode == AbsoluteCoordinates ? toTargetPoint : m_toCurrentPoint + toTargetPoint;
    114     return true;
    115 }
    116 
    117 bool SVGPathBlender::blendLineToSegment()
    118 {
    119     FloatPoint fromTargetPoint;
    120     FloatPoint toTargetPoint;
    121     if ((m_fromSource->hasMoreData() && !m_fromSource->parseLineToSegment(fromTargetPoint))
    122         || !m_toSource->parseLineToSegment(toTargetPoint))
    123         return false;
    124 
    125     m_consumer->lineTo(blendAnimatedFloatPoint(fromTargetPoint, toTargetPoint), m_isInFirstHalfOfAnimation ? m_fromMode : m_toMode);
    126     m_fromCurrentPoint = m_fromMode == AbsoluteCoordinates ? fromTargetPoint : m_fromCurrentPoint + fromTargetPoint;
    127     m_toCurrentPoint = m_toMode == AbsoluteCoordinates ? toTargetPoint : m_toCurrentPoint + toTargetPoint;
    128     return true;
    129 }
    130 
    131 bool SVGPathBlender::blendLineToHorizontalSegment()
     113bool SVGPathBlender::blendMoveToSegment(float progress)
     114{
     115    FloatPoint fromTargetPoint;
     116    FloatPoint toTargetPoint;
     117    if ((m_fromSource.hasMoreData() && !m_fromSource.parseMoveToSegment(fromTargetPoint))
     118        || !m_toSource.parseMoveToSegment(toTargetPoint))
     119        return false;
     120
     121    m_consumer.moveTo(blendAnimatedFloatPoint(fromTargetPoint, toTargetPoint, progress), false, m_isInFirstHalfOfAnimation ? m_fromMode : m_toMode);
     122    m_fromCurrentPoint = m_fromMode == AbsoluteCoordinates ? fromTargetPoint : m_fromCurrentPoint + fromTargetPoint;
     123    m_toCurrentPoint = m_toMode == AbsoluteCoordinates ? toTargetPoint : m_toCurrentPoint + toTargetPoint;
     124    return true;
     125}
     126
     127bool SVGPathBlender::blendLineToSegment(float progress)
     128{
     129    FloatPoint fromTargetPoint;
     130    FloatPoint toTargetPoint;
     131    if ((m_fromSource.hasMoreData() && !m_fromSource.parseLineToSegment(fromTargetPoint))
     132        || !m_toSource.parseLineToSegment(toTargetPoint))
     133        return false;
     134
     135    m_consumer.lineTo(blendAnimatedFloatPoint(fromTargetPoint, toTargetPoint, progress), m_isInFirstHalfOfAnimation ? m_fromMode : m_toMode);
     136    m_fromCurrentPoint = m_fromMode == AbsoluteCoordinates ? fromTargetPoint : m_fromCurrentPoint + fromTargetPoint;
     137    m_toCurrentPoint = m_toMode == AbsoluteCoordinates ? toTargetPoint : m_toCurrentPoint + toTargetPoint;
     138    return true;
     139}
     140
     141bool SVGPathBlender::blendLineToHorizontalSegment(float progress)
    132142{
    133143    float fromX = 0;
    134144    float toX = 0;
    135     if ((m_fromSource->hasMoreData() && !m_fromSource->parseLineToHorizontalSegment(fromX))
    136         || !m_toSource->parseLineToHorizontalSegment(toX))
    137         return false;
    138 
    139     m_consumer->lineToHorizontal(blendAnimatedDimensonalFloat(fromX, toX, BlendHorizontal), m_isInFirstHalfOfAnimation ? m_fromMode : m_toMode);
     145    if ((m_fromSource.hasMoreData() && !m_fromSource.parseLineToHorizontalSegment(fromX))
     146        || !m_toSource.parseLineToHorizontalSegment(toX))
     147        return false;
     148
     149    m_consumer.lineToHorizontal(blendAnimatedDimensonalFloat(fromX, toX, BlendHorizontal, progress), m_isInFirstHalfOfAnimation ? m_fromMode : m_toMode);
    140150    m_fromCurrentPoint.setX(m_fromMode == AbsoluteCoordinates ? fromX : m_fromCurrentPoint.x() + fromX);
    141151    m_toCurrentPoint.setX(m_toMode == AbsoluteCoordinates ? toX : m_toCurrentPoint.x() + toX);
     
    143153}
    144154
    145 bool SVGPathBlender::blendLineToVerticalSegment()
     155bool SVGPathBlender::blendLineToVerticalSegment(float progress)
    146156{
    147157    float fromY = 0;
    148158    float toY = 0;
    149     if ((m_fromSource->hasMoreData() && !m_fromSource->parseLineToVerticalSegment(fromY))
    150         || !m_toSource->parseLineToVerticalSegment(toY))
    151         return false;
    152 
    153     m_consumer->lineToVertical(blendAnimatedDimensonalFloat(fromY, toY, BlendVertical), m_isInFirstHalfOfAnimation ? m_fromMode : m_toMode);
     159    if ((m_fromSource.hasMoreData() && !m_fromSource.parseLineToVerticalSegment(fromY))
     160        || !m_toSource.parseLineToVerticalSegment(toY))
     161        return false;
     162
     163    m_consumer.lineToVertical(blendAnimatedDimensonalFloat(fromY, toY, BlendVertical, progress), m_isInFirstHalfOfAnimation ? m_fromMode : m_toMode);
    154164    m_fromCurrentPoint.setY(m_fromMode == AbsoluteCoordinates ? fromY : m_fromCurrentPoint.y() + fromY);
    155165    m_toCurrentPoint.setY(m_toMode == AbsoluteCoordinates ? toY : m_toCurrentPoint.y() + toY);
     
    157167}
    158168
    159 bool SVGPathBlender::blendCurveToCubicSegment()
     169bool SVGPathBlender::blendCurveToCubicSegment(float progress)
    160170{
    161171    FloatPoint fromTargetPoint;
     
    165175    FloatPoint toPoint1;
    166176    FloatPoint toPoint2;
    167     if ((m_fromSource->hasMoreData() && !m_fromSource->parseCurveToCubicSegment(fromPoint1, fromPoint2, fromTargetPoint))
    168         || !m_toSource->parseCurveToCubicSegment(toPoint1, toPoint2, toTargetPoint))
    169         return false;
    170 
    171     m_consumer->curveToCubic(blendAnimatedFloatPoint(fromPoint1, toPoint1),
    172                              blendAnimatedFloatPoint(fromPoint2, toPoint2),
    173                              blendAnimatedFloatPoint(fromTargetPoint, toTargetPoint),
    174                              m_isInFirstHalfOfAnimation ? m_fromMode : m_toMode);
    175     m_fromCurrentPoint = m_fromMode == AbsoluteCoordinates ? fromTargetPoint : m_fromCurrentPoint + fromTargetPoint;
    176     m_toCurrentPoint = m_toMode == AbsoluteCoordinates ? toTargetPoint : m_toCurrentPoint + toTargetPoint;
    177     return true;
    178 }
    179 
    180 bool SVGPathBlender::blendCurveToCubicSmoothSegment()
     177    if ((m_fromSource.hasMoreData() && !m_fromSource.parseCurveToCubicSegment(fromPoint1, fromPoint2, fromTargetPoint))
     178        || !m_toSource.parseCurveToCubicSegment(toPoint1, toPoint2, toTargetPoint))
     179        return false;
     180
     181    m_consumer.curveToCubic(blendAnimatedFloatPoint(fromPoint1, toPoint1, progress),
     182        blendAnimatedFloatPoint(fromPoint2, toPoint2, progress),
     183        blendAnimatedFloatPoint(fromTargetPoint, toTargetPoint, progress),
     184        m_isInFirstHalfOfAnimation ? m_fromMode : m_toMode);
     185    m_fromCurrentPoint = m_fromMode == AbsoluteCoordinates ? fromTargetPoint : m_fromCurrentPoint + fromTargetPoint;
     186    m_toCurrentPoint = m_toMode == AbsoluteCoordinates ? toTargetPoint : m_toCurrentPoint + toTargetPoint;
     187    return true;
     188}
     189
     190bool SVGPathBlender::blendCurveToCubicSmoothSegment(float progress)
    181191{
    182192    FloatPoint fromTargetPoint;
     
    184194    FloatPoint toTargetPoint;
    185195    FloatPoint toPoint2;
    186     if ((m_fromSource->hasMoreData() && !m_fromSource->parseCurveToCubicSmoothSegment(fromPoint2, fromTargetPoint))
    187         || !m_toSource->parseCurveToCubicSmoothSegment(toPoint2, toTargetPoint))
    188         return false;
    189 
    190     m_consumer->curveToCubicSmooth(blendAnimatedFloatPoint(fromPoint2, toPoint2),
    191                                    blendAnimatedFloatPoint(fromTargetPoint, toTargetPoint),
    192                                    m_isInFirstHalfOfAnimation ? m_fromMode : m_toMode);
    193     m_fromCurrentPoint = m_fromMode == AbsoluteCoordinates ? fromTargetPoint : m_fromCurrentPoint + fromTargetPoint;
    194     m_toCurrentPoint = m_toMode == AbsoluteCoordinates ? toTargetPoint : m_toCurrentPoint + toTargetPoint;
    195     return true;
    196 }
    197 
    198 bool SVGPathBlender::blendCurveToQuadraticSegment()
     196    if ((m_fromSource.hasMoreData() && !m_fromSource.parseCurveToCubicSmoothSegment(fromPoint2, fromTargetPoint))
     197        || !m_toSource.parseCurveToCubicSmoothSegment(toPoint2, toTargetPoint))
     198        return false;
     199
     200    m_consumer.curveToCubicSmooth(blendAnimatedFloatPoint(fromPoint2, toPoint2, progress),
     201        blendAnimatedFloatPoint(fromTargetPoint, toTargetPoint, progress),
     202        m_isInFirstHalfOfAnimation ? m_fromMode : m_toMode);
     203    m_fromCurrentPoint = m_fromMode == AbsoluteCoordinates ? fromTargetPoint : m_fromCurrentPoint + fromTargetPoint;
     204    m_toCurrentPoint = m_toMode == AbsoluteCoordinates ? toTargetPoint : m_toCurrentPoint + toTargetPoint;
     205    return true;
     206}
     207
     208bool SVGPathBlender::blendCurveToQuadraticSegment(float progress)
    199209{
    200210    FloatPoint fromTargetPoint;
     
    202212    FloatPoint toTargetPoint;
    203213    FloatPoint toPoint1;
    204     if ((m_fromSource->hasMoreData() && !m_fromSource->parseCurveToQuadraticSegment(fromPoint1, fromTargetPoint))
    205         || !m_toSource->parseCurveToQuadraticSegment(toPoint1, toTargetPoint))
    206         return false;
    207 
    208     m_consumer->curveToQuadratic(blendAnimatedFloatPoint(fromPoint1, toPoint1),
    209                                  blendAnimatedFloatPoint(fromTargetPoint, toTargetPoint),
    210                                  m_isInFirstHalfOfAnimation ? m_fromMode : m_toMode);
    211     m_fromCurrentPoint = m_fromMode == AbsoluteCoordinates ? fromTargetPoint : m_fromCurrentPoint + fromTargetPoint;
    212     m_toCurrentPoint = m_toMode == AbsoluteCoordinates ? toTargetPoint : m_toCurrentPoint + toTargetPoint;
    213     return true;
    214 }
    215 
    216 bool SVGPathBlender::blendCurveToQuadraticSmoothSegment()
    217 {
    218     FloatPoint fromTargetPoint;
    219     FloatPoint toTargetPoint;
    220     if ((m_fromSource->hasMoreData() && !m_fromSource->parseCurveToQuadraticSmoothSegment(fromTargetPoint))
    221         || !m_toSource->parseCurveToQuadraticSmoothSegment(toTargetPoint))
    222         return false;
    223 
    224     m_consumer->curveToQuadraticSmooth(blendAnimatedFloatPoint(fromTargetPoint, toTargetPoint), m_isInFirstHalfOfAnimation ? m_fromMode : m_toMode);
    225     m_fromCurrentPoint = m_fromMode == AbsoluteCoordinates ? fromTargetPoint : m_fromCurrentPoint + fromTargetPoint;
    226     m_toCurrentPoint = m_toMode == AbsoluteCoordinates ? toTargetPoint : m_toCurrentPoint + toTargetPoint;
    227     return true;
    228 }
    229 
    230 bool SVGPathBlender::blendArcToSegment()
     214    if ((m_fromSource.hasMoreData() && !m_fromSource.parseCurveToQuadraticSegment(fromPoint1, fromTargetPoint))
     215        || !m_toSource.parseCurveToQuadraticSegment(toPoint1, toTargetPoint))
     216        return false;
     217
     218    m_consumer.curveToQuadratic(blendAnimatedFloatPoint(fromPoint1, toPoint1, progress),
     219        blendAnimatedFloatPoint(fromTargetPoint, toTargetPoint, progress),
     220        m_isInFirstHalfOfAnimation ? m_fromMode : m_toMode);
     221    m_fromCurrentPoint = m_fromMode == AbsoluteCoordinates ? fromTargetPoint : m_fromCurrentPoint + fromTargetPoint;
     222    m_toCurrentPoint = m_toMode == AbsoluteCoordinates ? toTargetPoint : m_toCurrentPoint + toTargetPoint;
     223    return true;
     224}
     225
     226bool SVGPathBlender::blendCurveToQuadraticSmoothSegment(float progress)
     227{
     228    FloatPoint fromTargetPoint;
     229    FloatPoint toTargetPoint;
     230    if ((m_fromSource.hasMoreData() && !m_fromSource.parseCurveToQuadraticSmoothSegment(fromTargetPoint))
     231        || !m_toSource.parseCurveToQuadraticSmoothSegment(toTargetPoint))
     232        return false;
     233
     234    m_consumer.curveToQuadraticSmooth(blendAnimatedFloatPoint(fromTargetPoint, toTargetPoint, progress), m_isInFirstHalfOfAnimation ? m_fromMode : m_toMode);
     235    m_fromCurrentPoint = m_fromMode == AbsoluteCoordinates ? fromTargetPoint : m_fromCurrentPoint + fromTargetPoint;
     236    m_toCurrentPoint = m_toMode == AbsoluteCoordinates ? toTargetPoint : m_toCurrentPoint + toTargetPoint;
     237    return true;
     238}
     239
     240bool SVGPathBlender::blendArcToSegment(float progress)
    231241{
    232242    float fromRx = 0;
     
    242252    bool toSweep = false;
    243253    FloatPoint toTargetPoint;
    244     if ((m_fromSource->hasMoreData() && !m_fromSource->parseArcToSegment(fromRx, fromRy, fromAngle, fromLargeArc, fromSweep, fromTargetPoint))
    245         || !m_toSource->parseArcToSegment(toRx, toRy, toAngle, toLargeArc, toSweep, toTargetPoint))
     254    if ((m_fromSource.hasMoreData() && !m_fromSource.parseArcToSegment(fromRx, fromRy, fromAngle, fromLargeArc, fromSweep, fromTargetPoint))
     255        || !m_toSource.parseArcToSegment(toRx, toRy, toAngle, toLargeArc, toSweep, toTargetPoint))
    246256        return false;
    247257
     
    250260        FloatPoint scaledToTargetPoint = toTargetPoint;
    251261        scaledToTargetPoint.scale(m_addTypesCount, m_addTypesCount);
    252         m_consumer->arcTo(fromRx + toRx * m_addTypesCount,
    253                           fromRy + toRy * m_addTypesCount,
    254                           fromAngle + toAngle * m_addTypesCount,
    255                           fromLargeArc || toLargeArc,
    256                           fromSweep || toSweep,
    257                           fromTargetPoint + scaledToTargetPoint,
    258                           m_fromMode);
     262        m_consumer.arcTo(fromRx + toRx * m_addTypesCount,
     263            fromRy + toRy * m_addTypesCount,
     264            fromAngle + toAngle * m_addTypesCount,
     265            fromLargeArc || toLargeArc,
     266            fromSweep || toSweep,
     267            fromTargetPoint + scaledToTargetPoint,
     268            m_fromMode);
    259269    } else {
    260         m_consumer->arcTo(blend(fromRx, toRx, m_progress),
    261                           blend(fromRy, toRy, m_progress),
    262                           blend(fromAngle, toAngle, m_progress),
    263                           m_isInFirstHalfOfAnimation ? fromLargeArc : toLargeArc,
    264                           m_isInFirstHalfOfAnimation ? fromSweep : toSweep,
    265                           blendAnimatedFloatPoint(fromTargetPoint, toTargetPoint),
    266                           m_isInFirstHalfOfAnimation ? m_fromMode : m_toMode);
     270        m_consumer.arcTo(blend(fromRx, toRx, progress),
     271            blend(fromRy, toRy, progress),
     272            blend(fromAngle, toAngle, progress),
     273            m_isInFirstHalfOfAnimation ? fromLargeArc : toLargeArc,
     274            m_isInFirstHalfOfAnimation ? fromSweep : toSweep,
     275            blendAnimatedFloatPoint(fromTargetPoint, toTargetPoint, progress),
     276            m_isInFirstHalfOfAnimation ? m_fromMode : m_toMode);
    267277    }
    268278    m_fromCurrentPoint = m_fromMode == AbsoluteCoordinates ? fromTargetPoint : m_fromCurrentPoint + fromTargetPoint;
     
    297307}
    298308
    299 bool SVGPathBlender::addAnimatedPath(SVGPathSource* fromSource, SVGPathSource* toSource, SVGPathConsumer* consumer, unsigned repeatCount)
     309bool SVGPathBlender::addAnimatedPath(unsigned repeatCount)
    300310{
    301311    TemporaryChange<unsigned> change(m_addTypesCount, repeatCount);
    302     return blendAnimatedPath(0, fromSource, toSource, consumer);
    303 }
    304 
    305 bool SVGPathBlender::blendAnimatedPath(float progress, SVGPathSource* fromSource, SVGPathSource* toSource, SVGPathConsumer* consumer)
    306 {
    307     ASSERT(fromSource);
    308     ASSERT(toSource);
    309     ASSERT(consumer);
    310     m_fromSource = fromSource;
    311     m_toSource = toSource;
    312     m_consumer = consumer;
     312    return blendAnimatedPath(0);
     313}
     314
     315bool SVGPathBlender::blendAnimatedPath(float progress)
     316{
    313317    m_isInFirstHalfOfAnimation = progress < 0.5f;
    314     m_progress = progress;
    315 
    316     bool fromSourceHadData = m_fromSource->hasMoreData();
    317     while (m_toSource->hasMoreData()) {
     318
     319    bool fromSourceHadData = m_fromSource.hasMoreData();
     320    while (m_toSource.hasMoreData()) {
    318321        SVGPathSegType fromCommand;
    319322        SVGPathSegType toCommand;
    320         if ((fromSourceHadData && !m_fromSource->parseSVGSegmentType(fromCommand)) || !m_toSource->parseSVGSegmentType(toCommand))
     323        if ((fromSourceHadData && !m_fromSource.parseSVGSegmentType(fromCommand)) || !m_toSource.parseSVGSegmentType(toCommand))
    321324            return false;
    322325
     
    332335        case PathSegMoveToRel:
    333336        case PathSegMoveToAbs:
    334             if (!blendMoveToSegment())
     337            if (!blendMoveToSegment(progress))
    335338                return false;
    336339            break;
    337340        case PathSegLineToRel:
    338341        case PathSegLineToAbs:
    339             if (!blendLineToSegment())
     342            if (!blendLineToSegment(progress))
    340343                return false;
    341344            break;
    342345        case PathSegLineToHorizontalRel:
    343346        case PathSegLineToHorizontalAbs:
    344             if (!blendLineToHorizontalSegment())
     347            if (!blendLineToHorizontalSegment(progress))
    345348                return false;
    346349            break;
    347350        case PathSegLineToVerticalRel:
    348351        case PathSegLineToVerticalAbs:
    349             if (!blendLineToVerticalSegment())
     352            if (!blendLineToVerticalSegment(progress))
    350353                return false;
    351354            break;
    352355        case PathSegClosePath:
    353             m_consumer->closePath();
     356            m_consumer.closePath();
    354357            break;
    355358        case PathSegCurveToCubicRel:
    356359        case PathSegCurveToCubicAbs:
    357             if (!blendCurveToCubicSegment())
     360            if (!blendCurveToCubicSegment(progress))
    358361                return false;
    359362            break;
    360363        case PathSegCurveToCubicSmoothRel:
    361364        case PathSegCurveToCubicSmoothAbs:
    362             if (!blendCurveToCubicSmoothSegment())
     365            if (!blendCurveToCubicSmoothSegment(progress))
    363366                return false;
    364367            break;
    365368        case PathSegCurveToQuadraticRel:
    366369        case PathSegCurveToQuadraticAbs:
    367             if (!blendCurveToQuadraticSegment())
     370            if (!blendCurveToQuadraticSegment(progress))
    368371                return false;
    369372            break;
    370373        case PathSegCurveToQuadraticSmoothRel:
    371374        case PathSegCurveToQuadraticSmoothAbs:
    372             if (!blendCurveToQuadraticSmoothSegment())
     375            if (!blendCurveToQuadraticSmoothSegment(progress))
    373376                return false;
    374377            break;
    375378        case PathSegArcRel:
    376379        case PathSegArcAbs:
    377             if (!blendArcToSegment())
     380            if (!blendArcToSegment(progress))
    378381                return false;
    379382            break;
     
    384387        if (!fromSourceHadData)
    385388            continue;
    386         if (m_fromSource->hasMoreData() != m_toSource->hasMoreData())
    387             return false;
    388         if (!m_fromSource->hasMoreData() || !m_toSource->hasMoreData())
     389        if (m_fromSource.hasMoreData() != m_toSource.hasMoreData())
     390            return false;
     391        if (!m_fromSource.hasMoreData() || !m_toSource.hasMoreData())
    389392            return true;
    390393    }
     
    393396}
    394397
    395 void SVGPathBlender::cleanup()
    396 {
    397     ASSERT(m_toSource);
    398     ASSERT(m_fromSource);
    399     ASSERT(m_consumer);
    400 
    401     m_consumer->cleanup();
    402     m_toSource = nullptr;
    403     m_fromSource = nullptr;
    404     m_consumer = nullptr;
    405     m_fromCurrentPoint = FloatPoint();
    406     m_toCurrentPoint = FloatPoint();
    407 }
    408 
    409 }
     398}
  • trunk/Source/WebCore/svg/SVGPathBlender.h

    r163440 r190849  
    11/*
    22 * Copyright (C) Research In Motion Limited 2010. All rights reserved.
     3 * Copyright (C) 2015 Apple Inc. All rights reserved.
    34 *
    45 * This library is free software; you can redistribute it and/or
     
    3536    WTF_MAKE_NONCOPYABLE(SVGPathBlender); WTF_MAKE_FAST_ALLOCATED;
    3637public:
    37     SVGPathBlender();
    3838
    39     bool addAnimatedPath(SVGPathSource*, SVGPathSource*, SVGPathConsumer*, unsigned repeatCount);
    40     bool blendAnimatedPath(float, SVGPathSource*, SVGPathSource*, SVGPathConsumer*);
    41     void cleanup();
     39    static bool addAnimatedPath(SVGPathSource& from, SVGPathSource& to, SVGPathConsumer&, unsigned repeatCount);
     40    static bool blendAnimatedPath(SVGPathSource& from, SVGPathSource& to, SVGPathConsumer&, float);
    4241
    4342private:
    44     bool blendMoveToSegment();
    45     bool blendLineToSegment();
    46     bool blendLineToHorizontalSegment();
    47     bool blendLineToVerticalSegment();
    48     bool blendCurveToCubicSegment();
    49     bool blendCurveToCubicSmoothSegment();
    50     bool blendCurveToQuadraticSegment();
    51     bool blendCurveToQuadraticSmoothSegment();
    52     bool blendArcToSegment();
     43    SVGPathBlender(SVGPathSource&, SVGPathSource&, SVGPathConsumer&);
    5344
    54     float blendAnimatedDimensonalFloat(float, float, FloatBlendMode);
    55     FloatPoint blendAnimatedFloatPoint(const FloatPoint& from, const FloatPoint& to);
     45    bool addAnimatedPath(unsigned repeatCount);
     46    bool blendAnimatedPath(float progress);
    5647
    57     SVGPathSource* m_fromSource;
    58     SVGPathSource* m_toSource;
    59     SVGPathConsumer* m_consumer;
     48    bool blendMoveToSegment(float progress);
     49    bool blendLineToSegment(float progress);
     50    bool blendLineToHorizontalSegment(float progress);
     51    bool blendLineToVerticalSegment(float progress);
     52    bool blendCurveToCubicSegment(float progress);
     53    bool blendCurveToCubicSmoothSegment(float progress);
     54    bool blendCurveToQuadraticSegment(float progress);
     55    bool blendCurveToQuadraticSmoothSegment(float progress);
     56    bool blendArcToSegment(float progress);
     57
     58    float blendAnimatedDimensonalFloat(float from, float to, FloatBlendMode, float progress);
     59    FloatPoint blendAnimatedFloatPoint(const FloatPoint& from, const FloatPoint& to, float progress);
     60
     61    SVGPathSource& m_fromSource;
     62    SVGPathSource& m_toSource;
     63    SVGPathConsumer& m_consumer;
    6064
    6165    FloatPoint m_fromCurrentPoint;
    6266    FloatPoint m_toCurrentPoint;
    6367   
    64     PathCoordinateMode m_fromMode;
    65     PathCoordinateMode m_toMode;
    66     float m_progress;
    67     unsigned m_addTypesCount;
    68     bool m_isInFirstHalfOfAnimation;
     68    PathCoordinateMode m_fromMode { AbsoluteCoordinates };
     69    PathCoordinateMode m_toMode { AbsoluteCoordinates };
     70    unsigned m_addTypesCount { 0 };
     71    bool m_isInFirstHalfOfAnimation { false };
    6972};
    7073
  • trunk/Source/WebCore/svg/SVGPathBuilder.cpp

    r184852 r190849  
    33 * Copyright (C) 2006 Alexander Kellett <lypanov@kde.org>
    44 * Copyright (C) 2006, 2007 Rob Buis <buis@kde.org>
    5  * Copyright (C) 2007, 2009 Apple Inc. All rights reserved.
     5 * Copyright (C) 2007, 2009, 2015 Apple Inc. All rights reserved.
    66 * Copyright (C) Research In Motion Limited 2010. All rights reserved.
    77 *
     
    2929namespace WebCore {
    3030
    31 SVGPathBuilder::SVGPathBuilder()
    32     : m_path(nullptr)
     31SVGPathBuilder::SVGPathBuilder(Path& path)
     32    : m_path(path)
    3333{
    3434}
     
    3636void SVGPathBuilder::moveTo(const FloatPoint& targetPoint, bool closed, PathCoordinateMode mode)
    3737{
    38     ASSERT(m_path);
    3938    m_current = mode == AbsoluteCoordinates ? targetPoint : m_current + targetPoint;
    40     if (closed && !m_path->isEmpty())
    41         m_path->closeSubpath();
    42     m_path->moveTo(m_current);
     39    if (closed && !m_path.isEmpty())
     40        m_path.closeSubpath();
     41    m_path.moveTo(m_current);
    4342}
    4443
    4544void SVGPathBuilder::lineTo(const FloatPoint& targetPoint, PathCoordinateMode mode)
    4645{
    47     ASSERT(m_path);
    4846    m_current = mode == AbsoluteCoordinates ? targetPoint : m_current + targetPoint;
    49     m_path->addLineTo(m_current);
     47    m_path.addLineTo(m_current);
    5048}
    5149
    5250void SVGPathBuilder::curveToCubic(const FloatPoint& point1, const FloatPoint& point2, const FloatPoint& targetPoint, PathCoordinateMode mode)
    5351{
    54     ASSERT(m_path);
    5552    if (mode == RelativeCoordinates) {
    56         m_path->addBezierCurveTo(m_current + point1, m_current + point2, m_current + targetPoint);
     53        m_path.addBezierCurveTo(m_current + point1, m_current + point2, m_current + targetPoint);
    5754        m_current += targetPoint;
    5855    } else {
    5956        m_current = targetPoint;
    60         m_path->addBezierCurveTo(point1, point2, m_current);
     57        m_path.addBezierCurveTo(point1, point2, m_current);
    6158    }   
    6259}
     
    6461void SVGPathBuilder::closePath()
    6562{
    66     ASSERT(m_path);
    67     m_path->closeSubpath();
     63    m_path.closeSubpath();
    6864}
    6965
  • trunk/Source/WebCore/svg/SVGPathBuilder.h

    r184852 r190849  
    33 * Copyright (C) 2006 Alexander Kellett <lypanov@kde.org>
    44 * Copyright (C) 2006, 2007 Rob Buis <buis@kde.org>
    5  * Copyright (C) 2007, 2009 Apple Inc. All rights reserved.
     5 * Copyright (C) 2007, 2009, 2015 Apple Inc. All rights reserved.
    66 * Copyright (C) Research In Motion Limited 2010. All rights reserved.
    77 *
     
    3434class SVGPathBuilder : public SVGPathConsumer {
    3535public:
    36     SVGPathBuilder();
    37 
    38     void setCurrentPath(Path* path) { m_path = path; }
    39 
    40 protected:
    41     FloatPoint m_current;
     36    SVGPathBuilder(Path&);
    4237
    4338private:
    4439    virtual void incrementPathSegmentCount() override { }
    4540    virtual bool continueConsuming() override { return true; }
    46     virtual void cleanup() override { m_path = nullptr; }
    4741
    4842    // Used in UnalteredParsing/NormalizedParsing modes.
     
    6054    virtual void arcTo(float, float, float, bool, bool, const FloatPoint&, PathCoordinateMode) override { ASSERT_NOT_REACHED(); }
    6155
    62     Path* m_path;
     56    Path& m_path;
     57    FloatPoint m_current;
    6358};
    6459
  • trunk/Source/WebCore/svg/SVGPathByteStreamBuilder.cpp

    r184852 r190849  
    11/*
    22 * Copyright (C) Research In Motion Limited 2010. All rights reserved.
     3 * Copyright (C) 2015 Apple Inc. All rights reserved.
    34 *
    45 * This library is free software; you can redistribute it and/or
     
    2122#include "SVGPathByteStreamBuilder.h"
    2223
    23 #include "SVGPathParser.h"
    2424#include "SVGPathSeg.h"
    2525#include "SVGPathStringSource.h"
     
    2727namespace WebCore {
    2828
    29 SVGPathByteStreamBuilder::SVGPathByteStreamBuilder()
    30     : m_byteStream(nullptr)
     29SVGPathByteStreamBuilder::SVGPathByteStreamBuilder(SVGPathByteStream& byteStream)
     30    : m_byteStream(byteStream)
    3131{
    3232}
     
    3434void SVGPathByteStreamBuilder::moveTo(const FloatPoint& targetPoint, bool, PathCoordinateMode mode)
    3535{
    36     ASSERT(m_byteStream);
    3736    writeSegmentType(mode == RelativeCoordinates ?  PathSegMoveToRel : PathSegMoveToAbs);
    3837    writeFloatPoint(targetPoint);
     
    4140void SVGPathByteStreamBuilder::lineTo(const FloatPoint& targetPoint, PathCoordinateMode mode)
    4241{
    43     ASSERT(m_byteStream);
    4442    writeSegmentType(mode == RelativeCoordinates ? PathSegLineToRel : PathSegLineToAbs);
    4543    writeFloatPoint(targetPoint);
     
    4846void SVGPathByteStreamBuilder::lineToHorizontal(float x, PathCoordinateMode mode)
    4947{
    50     ASSERT(m_byteStream);
    5148    writeSegmentType(mode == RelativeCoordinates ? PathSegLineToHorizontalRel : PathSegLineToHorizontalAbs);
    5249    writeFloat(x);
     
    5552void SVGPathByteStreamBuilder::lineToVertical(float y, PathCoordinateMode mode)
    5653{
    57     ASSERT(m_byteStream);
    5854    writeSegmentType(mode == RelativeCoordinates ? PathSegLineToVerticalRel : PathSegLineToVerticalAbs);
    5955    writeFloat(y);
     
    6258void SVGPathByteStreamBuilder::curveToCubic(const FloatPoint& point1, const FloatPoint& point2, const FloatPoint& targetPoint, PathCoordinateMode mode)
    6359{
    64     ASSERT(m_byteStream);
    6560    writeSegmentType(mode == RelativeCoordinates ? PathSegCurveToCubicRel : PathSegCurveToCubicAbs);
    6661    writeFloatPoint(point1);
     
    7166void SVGPathByteStreamBuilder::curveToCubicSmooth(const FloatPoint& point2, const FloatPoint& targetPoint, PathCoordinateMode mode)
    7267{
    73     ASSERT(m_byteStream);
    7468    writeSegmentType(mode == RelativeCoordinates ? PathSegCurveToCubicSmoothRel : PathSegCurveToCubicSmoothAbs);
    7569    writeFloatPoint(point2);
     
    7973void SVGPathByteStreamBuilder::curveToQuadratic(const FloatPoint& point1, const FloatPoint& targetPoint, PathCoordinateMode mode)
    8074{
    81     ASSERT(m_byteStream);
    8275    writeSegmentType(mode == RelativeCoordinates ? PathSegCurveToQuadraticRel : PathSegCurveToQuadraticAbs);
    8376    writeFloatPoint(point1);
     
    8780void SVGPathByteStreamBuilder::curveToQuadraticSmooth(const FloatPoint& targetPoint, PathCoordinateMode mode)
    8881{
    89     ASSERT(m_byteStream);
    9082    writeSegmentType(mode == RelativeCoordinates ? PathSegCurveToQuadraticSmoothRel : PathSegCurveToQuadraticSmoothAbs);
    9183    writeFloatPoint(targetPoint);
     
    9486void SVGPathByteStreamBuilder::arcTo(float r1, float r2, float angle, bool largeArcFlag, bool sweepFlag, const FloatPoint& targetPoint, PathCoordinateMode mode)
    9587{
    96     ASSERT(m_byteStream);
    9788    writeSegmentType(mode == RelativeCoordinates ? PathSegArcRel : PathSegArcAbs);
    9889    writeFloat(r1);
     
    10697void SVGPathByteStreamBuilder::closePath()
    10798{
    108     ASSERT(m_byteStream);
    10999    writeSegmentType(PathSegClosePath);
    110100}
  • trunk/Source/WebCore/svg/SVGPathByteStreamBuilder.h

    r184852 r190849  
    11/*
    22 * Copyright (C) Research In Motion Limited 2010. All rights reserved.
     3 * Copyright (C) 2015 Apple Inc. All rights reserved.
    34 *
    45 * This library is free software; you can redistribute it and/or
     
    3031class SVGPathByteStreamBuilder : public SVGPathConsumer {
    3132public:
    32     SVGPathByteStreamBuilder();
    33 
    34     void setCurrentByteStream(SVGPathByteStream* byteStream) { m_byteStream = byteStream; }
     33    SVGPathByteStreamBuilder(SVGPathByteStream&);
    3534
    3635private:
    3736    virtual void incrementPathSegmentCount() override { }
    3837    virtual bool continueConsuming() override { return true; }
    39     virtual void cleanup() override { m_byteStream = nullptr; }
    4038
    4139    // Used in UnalteredParsing/NormalizedParsing modes.
     
    5856        size_t typeSize = sizeof(ByteType);
    5957        for (size_t i = 0; i < typeSize; ++i)
    60             m_byteStream->append(type.bytes[i]);
     58            m_byteStream.append(type.bytes[i]);
    6159    }
    6260
     
    8886    }
    8987
    90     SVGPathByteStream* m_byteStream;
     88    SVGPathByteStream& m_byteStream;
    9189};
    9290
  • trunk/Source/WebCore/svg/SVGPathConsumer.h

    r163440 r190849  
    33 * Copyright (C) 2006 Alexander Kellett <lypanov@kde.org>
    44 * Copyright (C) 2006, 2007 Rob Buis <buis@kde.org>
    5  * Copyright (C) 2007, 2009 Apple Inc. All rights reserved.
     5 * Copyright (C) 2007, 2009, 2015 Apple Inc. All rights reserved.
    66 * Copyright (C) Research In Motion Limited 2010. All rights reserved.
    77 *
     
    4747    virtual void incrementPathSegmentCount() = 0;
    4848    virtual bool continueConsuming() = 0;
    49     virtual void cleanup() = 0;
    5049
    5150    // Used in UnalteredParsing/NormalizedParsing modes.
  • trunk/Source/WebCore/svg/SVGPathElement.cpp

    r190844 r190849  
    4444#include "SVGPathSegLinetoVerticalRel.h"
    4545#include "SVGPathSegList.h"
    46 #include "SVGPathSegListBuilder.h"
    4746#include "SVGPathSegListPropertyTearOff.h"
    4847#include "SVGPathSegMovetoAbs.h"
  • trunk/Source/WebCore/svg/SVGPathParser.cpp

    r184852 r190849  
    33 * Copyright (C) 2006 Alexander Kellett <lypanov@kde.org>
    44 * Copyright (C) 2006, 2007 Rob Buis <buis@kde.org>
    5  * Copyright (C) 2007, 2009 Apple Inc. All rights reserved.
     5 * Copyright (C) 2007, 2009, 2015 Apple Inc. All rights reserved.
    66 * Copyright (C) Research In Motion Limited 2010. All rights reserved.
    77 *
     
    2626
    2727#include "AffineTransform.h"
     28#include "SVGPathByteStreamBuilder.h"
    2829#include "SVGPathSource.h"
     30#include "SVGPathStringBuilder.h"
    2931#include <wtf/MathExtras.h>
    3032
     
    3335namespace WebCore {
    3436
    35 SVGPathParser::SVGPathParser()
    36     : m_consumer(nullptr)
     37bool SVGPathParser::parse(SVGPathSource& source, SVGPathConsumer& consumer, PathParsingMode mode, bool checkForInitialMoveTo)
     38{
     39    SVGPathParser parser(consumer, source, mode);
     40    return parser.parsePathData(checkForInitialMoveTo);
     41}
     42
     43bool SVGPathParser::parseToByteStream(SVGPathSource& source, SVGPathByteStream& byteStream, PathParsingMode mode, bool checkForInitialMoveTo)
     44{
     45    SVGPathByteStreamBuilder builder(byteStream);
     46    return parse(source, builder, mode, checkForInitialMoveTo);
     47}
     48
     49bool SVGPathParser::parseToString(SVGPathSource& source, String& result, PathParsingMode mode, bool checkForInitialMoveTo)
     50{
     51    SVGPathStringBuilder builder;
     52    SVGPathParser parser(builder, source, mode);
     53    bool ok = parser.parsePathData(checkForInitialMoveTo);
     54    result = builder.result();
     55    return ok;
     56}
     57
     58SVGPathParser::SVGPathParser(SVGPathConsumer& consumer, SVGPathSource& source, PathParsingMode parsingMode)
     59    : m_source(source)
     60    , m_consumer(consumer)
     61    , m_pathParsingMode(parsingMode)
    3762{
    3863}
     
    4469        m_currentPoint = m_subPathPoint;
    4570    m_closePath = true;
    46     m_consumer->closePath();
     71    m_consumer.closePath();
    4772}
    4873
     
    5075{
    5176    FloatPoint targetPoint;
    52     if (!m_source->parseMoveToSegment(targetPoint))
     77    if (!m_source.parseMoveToSegment(targetPoint))
    5378        return false;
    5479
     
    5984            m_currentPoint = targetPoint;
    6085        m_subPathPoint = m_currentPoint;
    61         m_consumer->moveTo(m_currentPoint, m_closePath, AbsoluteCoordinates);
    62     } else
    63         m_consumer->moveTo(targetPoint, m_closePath, m_mode);
     86        m_consumer.moveTo(m_currentPoint, m_closePath, AbsoluteCoordinates);
     87    } else
     88        m_consumer.moveTo(targetPoint, m_closePath, m_mode);
    6489    m_closePath = false;
    6590    return true;
     
    6994{
    7095    FloatPoint targetPoint;
    71     if (!m_source->parseLineToSegment(targetPoint))
     96    if (!m_source.parseLineToSegment(targetPoint))
    7297        return false;
    7398
     
    77102        else
    78103            m_currentPoint = targetPoint;
    79         m_consumer->lineTo(m_currentPoint, AbsoluteCoordinates);
    80     } else
    81         m_consumer->lineTo(targetPoint, m_mode);
     104        m_consumer.lineTo(m_currentPoint, AbsoluteCoordinates);
     105    } else
     106        m_consumer.lineTo(targetPoint, m_mode);
    82107    return true;
    83108}
     
    86111{
    87112    float toX;
    88     if (!m_source->parseLineToHorizontalSegment(toX))
     113    if (!m_source.parseLineToHorizontalSegment(toX))
    89114        return false;
    90115
     
    94119        else
    95120            m_currentPoint.setX(toX);
    96         m_consumer->lineTo(m_currentPoint, AbsoluteCoordinates);
    97     } else
    98         m_consumer->lineToHorizontal(toX, m_mode);
     121        m_consumer.lineTo(m_currentPoint, AbsoluteCoordinates);
     122    } else
     123        m_consumer.lineToHorizontal(toX, m_mode);
    99124    return true;
    100125}
     
    103128{
    104129    float toY;
    105     if (!m_source->parseLineToVerticalSegment(toY))
     130    if (!m_source.parseLineToVerticalSegment(toY))
    106131        return false;
    107132
     
    111136        else
    112137            m_currentPoint.setY(toY);
    113         m_consumer->lineTo(m_currentPoint, AbsoluteCoordinates);
    114     } else
    115         m_consumer->lineToVertical(toY, m_mode);
     138        m_consumer.lineTo(m_currentPoint, AbsoluteCoordinates);
     139    } else
     140        m_consumer.lineToVertical(toY, m_mode);
    116141    return true;
    117142}
     
    122147    FloatPoint point2;
    123148    FloatPoint targetPoint;
    124     if (!m_source->parseCurveToCubicSegment(point1, point2, targetPoint))
     149    if (!m_source.parseCurveToCubicSegment(point1, point2, targetPoint))
    125150        return false;
    126151
     
    131156            targetPoint += m_currentPoint;
    132157        }
    133         m_consumer->curveToCubic(point1, point2, targetPoint, AbsoluteCoordinates);
     158        m_consumer.curveToCubic(point1, point2, targetPoint, AbsoluteCoordinates);
    134159
    135160        m_controlPoint = point2;
    136161        m_currentPoint = targetPoint;
    137162    } else
    138         m_consumer->curveToCubic(point1, point2, targetPoint, m_mode);
     163        m_consumer.curveToCubic(point1, point2, targetPoint, m_mode);
    139164    return true;
    140165}
     
    144169    FloatPoint point2;
    145170    FloatPoint targetPoint;
    146     if (!m_source->parseCurveToCubicSmoothSegment(point2, targetPoint))
     171    if (!m_source.parseCurveToCubicSmoothSegment(point2, targetPoint))
    147172        return false;
    148173
     
    162187        }
    163188
    164         m_consumer->curveToCubic(point1, point2, targetPoint, AbsoluteCoordinates);
     189        m_consumer.curveToCubic(point1, point2, targetPoint, AbsoluteCoordinates);
    165190
    166191        m_controlPoint = point2;
    167192        m_currentPoint = targetPoint;
    168193    } else
    169         m_consumer->curveToCubicSmooth(point2, targetPoint, m_mode);
     194        m_consumer.curveToCubicSmooth(point2, targetPoint, m_mode);
    170195    return true;
    171196}
     
    175200    FloatPoint point1;
    176201    FloatPoint targetPoint;
    177     if (!m_source->parseCurveToQuadraticSegment(point1, targetPoint))
     202    if (!m_source.parseCurveToQuadraticSegment(point1, targetPoint))
    178203        return false;
    179204
     
    191216        point2.scale(gOneOverThree, gOneOverThree);
    192217
    193         m_consumer->curveToCubic(point1, point2, targetPoint, AbsoluteCoordinates);
     218        m_consumer.curveToCubic(point1, point2, targetPoint, AbsoluteCoordinates);
    194219
    195220        if (m_mode == RelativeCoordinates)
     
    197222        m_currentPoint = targetPoint;
    198223    } else
    199         m_consumer->curveToQuadratic(point1, targetPoint, m_mode);
     224        m_consumer.curveToQuadratic(point1, targetPoint, m_mode);
    200225    return true;
    201226}
     
    204229{
    205230    FloatPoint targetPoint;
    206     if (!m_source->parseCurveToQuadraticSmoothSegment(targetPoint))
     231    if (!m_source.parseCurveToQuadraticSmoothSegment(targetPoint))
    207232        return false;
    208233
     
    226251        point2.scale(gOneOverThree, gOneOverThree);
    227252
    228         m_consumer->curveToCubic(point1, point2, targetPoint, AbsoluteCoordinates);
     253        m_consumer.curveToCubic(point1, point2, targetPoint, AbsoluteCoordinates);
    229254
    230255        m_controlPoint = cubicPoint;
    231256        m_currentPoint = targetPoint;
    232257    } else
    233         m_consumer->curveToQuadraticSmooth(targetPoint, m_mode);
     258        m_consumer.curveToQuadraticSmooth(targetPoint, m_mode);
    234259    return true;
    235260}
     
    243268    bool sweep;
    244269    FloatPoint targetPoint;
    245     if (!m_source->parseArcToSegment(rx, ry, angle, largeArc, sweep, targetPoint))
     270    if (!m_source.parseArcToSegment(rx, ry, angle, largeArc, sweep, targetPoint))
    246271        return false;
    247272
     
    265290            else
    266291                m_currentPoint = targetPoint;
    267             m_consumer->lineTo(m_currentPoint, AbsoluteCoordinates);
     292            m_consumer.lineTo(m_currentPoint, AbsoluteCoordinates);
    268293        } else
    269             m_consumer->lineTo(targetPoint, m_mode);
     294            m_consumer.lineTo(targetPoint, m_mode);
    270295        return true;
    271296    }
     
    278303        return decomposeArcToCubic(angle, rx, ry, point1, targetPoint, largeArc, sweep);
    279304    }
    280     m_consumer->arcTo(rx, ry, angle, largeArc, sweep, targetPoint, m_mode);
    281     return true;
    282 }
    283 
    284 bool SVGPathParser::parsePathDataFromSource(PathParsingMode pathParsingMode, bool checkForInitialMoveTo)
    285 {
    286     ASSERT(m_source);
    287     ASSERT(m_consumer);
    288 
    289     m_pathParsingMode = pathParsingMode;
    290 
    291     m_controlPoint = FloatPoint();
    292     m_currentPoint = FloatPoint();
    293     m_subPathPoint = FloatPoint();
    294     m_closePath = true;
    295 
     305    m_consumer.arcTo(rx, ry, angle, largeArc, sweep, targetPoint, m_mode);
     306    return true;
     307}
     308
     309bool SVGPathParser::parsePathData(bool checkForInitialMoveTo)
     310{
    296311    // Skip any leading spaces.
    297     if (!m_source->moveToNextToken())
     312    if (!m_source.moveToNextToken())
    298313        return true;
    299314
    300315    SVGPathSegType command;
    301     m_source->parseSVGSegmentType(command);
    302     m_lastCommand = PathSegUnknown;
     316    m_source.parseSVGSegmentType(command);
    303317
    304318    // Path must start with moveto.
     
    308322    while (true) {
    309323        // Skip spaces between command and first coordinate.
    310         m_source->moveToNextToken();
     324        m_source.moveToNextToken();
    311325        m_mode = AbsoluteCoordinates;
    312326        switch (command) {
     
    380394            return false;
    381395        }
    382         if (!m_consumer->continueConsuming())
     396        if (!m_consumer.continueConsuming())
    383397            return true;
    384398
    385399        m_lastCommand = command;
    386400
    387         if (!m_source->hasMoreData())
     401        if (!m_source.hasMoreData())
    388402            return true;
    389403
    390         command = m_source->nextCommand(command);
     404        command = m_source.nextCommand(command);
    391405
    392406        if (m_lastCommand != PathSegCurveToCubicAbs
     
    400414            m_controlPoint = m_currentPoint;
    401415
    402         m_consumer->incrementPathSegmentCount();
     416        m_consumer.incrementPathSegmentCount();
    403417    }
    404418
    405419    return false;
    406 }
    407 
    408 void SVGPathParser::cleanup()
    409 {
    410     ASSERT(m_source);
    411     ASSERT(m_consumer);
    412 
    413     m_consumer->cleanup();
    414     m_source = nullptr;
    415     m_consumer = nullptr;
    416420}
    417421
     
    496500        point2.move(t * sinEndTheta, -t * cosEndTheta);
    497501
    498         m_consumer->curveToCubic(pointTransform.mapPoint(point1), pointTransform.mapPoint(point2),
     502        m_consumer.curveToCubic(pointTransform.mapPoint(point1), pointTransform.mapPoint(point2),
    499503                                 pointTransform.mapPoint(targetPoint), AbsoluteCoordinates);
    500504    }
  • trunk/Source/WebCore/svg/SVGPathParser.h

    r163440 r190849  
    33 * Copyright (C) 2006 Alexander Kellett <lypanov@kde.org>
    44 * Copyright (C) 2006, 2007 Rob Buis <buis@kde.org>
    5  * Copyright (C) 2007, 2009 Apple Inc. All rights reserved.
     5 * Copyright (C) 2007, 2009, 2015 Apple Inc. All rights reserved.
    66 * Copyright (C) Research In Motion Limited 2010. All rights reserved.
    77 *
     
    3131namespace WebCore {
    3232
     33class SVGPathByteStream;
    3334class SVGPathSource;
    3435
    3536class SVGPathParser {
    36     WTF_MAKE_NONCOPYABLE(SVGPathParser); WTF_MAKE_FAST_ALLOCATED;
    3737public:
    38     SVGPathParser();
     38    static bool parse(SVGPathSource&, SVGPathConsumer&, PathParsingMode = NormalizedParsing, bool checkForInitialMoveTo = true);
    3939
    40     bool parsePathDataFromSource(PathParsingMode, bool checkForInitialMoveTo = true);
    41     void setCurrentConsumer(SVGPathConsumer* consumer) { m_consumer = consumer; }
    42     void setCurrentSource(SVGPathSource* source) { m_source = source; }
    43     void cleanup();
     40    static bool parseToByteStream(SVGPathSource&, SVGPathByteStream&, PathParsingMode = NormalizedParsing, bool checkForInitialMoveTo = true);
     41    static bool parseToString(SVGPathSource&, String& result, PathParsingMode = NormalizedParsing, bool checkForInitialMoveTo = true);
    4442
    4543private:
    46     bool decomposeArcToCubic(float, float, float, FloatPoint&, FloatPoint&, bool largeArcFlag, bool sweepFlag);
     44    SVGPathParser(SVGPathConsumer&, SVGPathSource&, PathParsingMode);
     45    bool parsePathData(bool checkForInitialMoveTo);
     46
     47    bool decomposeArcToCubic(float angle, float rx, float ry, FloatPoint&, FloatPoint&, bool largeArcFlag, bool sweepFlag);
    4748    void parseClosePathSegment();
    4849    bool parseMoveToSegment();
     
    5657    bool parseArcToSegment();
    5758
    58     SVGPathSource* m_source;
    59     SVGPathConsumer* m_consumer;
    60     PathCoordinateMode m_mode;
    61     PathParsingMode m_pathParsingMode;
    62     SVGPathSegType m_lastCommand;
    63     bool m_closePath;
     59    SVGPathSource& m_source;
     60    SVGPathConsumer& m_consumer;
    6461    FloatPoint m_controlPoint;
    6562    FloatPoint m_currentPoint;
    6663    FloatPoint m_subPathPoint;
     64    PathCoordinateMode m_mode { AbsoluteCoordinates };
     65    const PathParsingMode m_pathParsingMode { NormalizedParsing };
     66    SVGPathSegType m_lastCommand { PathSegUnknown };
     67    bool m_closePath { true };
    6768};
    6869
  • trunk/Source/WebCore/svg/SVGPathSegListBuilder.cpp

    r184852 r190849  
    33 * Copyright (C) 2006 Alexander Kellett <lypanov@kde.org>
    44 * Copyright (C) 2006, 2007 Rob Buis <buis@kde.org>
    5  * Copyright (C) 2007, 2009 Apple Inc. All rights reserved.
     5 * Copyright (C) 2007, 2009, 2015 Apple Inc. All rights reserved.
    66 * Copyright (C) Research In Motion Limited 2010. All rights reserved.
    77 *
     
    2525#include "SVGPathSegListBuilder.h"
    2626
    27 #include "ExceptionCode.h"
    2827#include "SVGPathElement.h"
    2928#include "SVGPathSegArcAbs.h"
     
    5049namespace WebCore {
    5150
    52 SVGPathSegListBuilder::SVGPathSegListBuilder()
    53     : m_pathElement(nullptr)
    54     , m_pathSegList(nullptr)
    55     , m_pathSegRole(PathSegUndefinedRole)
     51SVGPathSegListBuilder::SVGPathSegListBuilder(SVGPathElement& pathElement, SVGPathSegList& pathSegList, SVGPathSegRole role)
     52    : m_pathElement(pathElement)
     53    , m_pathSegList(pathSegList)
     54    , m_pathSegRole(role)
    5655{
    5756}
     
    5958void SVGPathSegListBuilder::moveTo(const FloatPoint& targetPoint, bool, PathCoordinateMode mode)
    6059{
    61     ASSERT(m_pathElement);
    62     ASSERT(m_pathSegList);
    6360    if (mode == AbsoluteCoordinates)
    64         m_pathSegList->append(m_pathElement->createSVGPathSegMovetoAbs(targetPoint.x(), targetPoint.y(), m_pathSegRole));
     61        m_pathSegList.append(m_pathElement.createSVGPathSegMovetoAbs(targetPoint.x(), targetPoint.y(), m_pathSegRole));
    6562    else
    66         m_pathSegList->append(m_pathElement->createSVGPathSegMovetoRel(targetPoint.x(), targetPoint.y(), m_pathSegRole));
     63        m_pathSegList.append(m_pathElement.createSVGPathSegMovetoRel(targetPoint.x(), targetPoint.y(), m_pathSegRole));
    6764}
    6865
    6966void SVGPathSegListBuilder::lineTo(const FloatPoint& targetPoint, PathCoordinateMode mode)
    7067{
    71     ASSERT(m_pathElement);
    72     ASSERT(m_pathSegList);
    7368    if (mode == AbsoluteCoordinates)
    74         m_pathSegList->append(m_pathElement->createSVGPathSegLinetoAbs(targetPoint.x(), targetPoint.y(), m_pathSegRole));
     69        m_pathSegList.append(m_pathElement.createSVGPathSegLinetoAbs(targetPoint.x(), targetPoint.y(), m_pathSegRole));
    7570    else
    76         m_pathSegList->append(m_pathElement->createSVGPathSegLinetoRel(targetPoint.x(), targetPoint.y(), m_pathSegRole));
     71        m_pathSegList.append(m_pathElement.createSVGPathSegLinetoRel(targetPoint.x(), targetPoint.y(), m_pathSegRole));
    7772}
    7873
    7974void SVGPathSegListBuilder::lineToHorizontal(float x, PathCoordinateMode mode)
    8075{
    81     ASSERT(m_pathElement);
    82     ASSERT(m_pathSegList);
    8376    if (mode == AbsoluteCoordinates)
    84         m_pathSegList->append(m_pathElement->createSVGPathSegLinetoHorizontalAbs(x, m_pathSegRole));
     77        m_pathSegList.append(m_pathElement.createSVGPathSegLinetoHorizontalAbs(x, m_pathSegRole));
    8578    else
    86         m_pathSegList->append(m_pathElement->createSVGPathSegLinetoHorizontalRel(x, m_pathSegRole));
     79        m_pathSegList.append(m_pathElement.createSVGPathSegLinetoHorizontalRel(x, m_pathSegRole));
    8780}
    8881
    8982void SVGPathSegListBuilder::lineToVertical(float y, PathCoordinateMode mode)
    9083{
    91     ASSERT(m_pathElement);
    92     ASSERT(m_pathSegList);
    9384    if (mode == AbsoluteCoordinates)
    94         m_pathSegList->append(m_pathElement->createSVGPathSegLinetoVerticalAbs(y, m_pathSegRole));
     85        m_pathSegList.append(m_pathElement.createSVGPathSegLinetoVerticalAbs(y, m_pathSegRole));
    9586    else
    96         m_pathSegList->append(m_pathElement->createSVGPathSegLinetoVerticalRel(y, m_pathSegRole));
     87        m_pathSegList.append(m_pathElement.createSVGPathSegLinetoVerticalRel(y, m_pathSegRole));
    9788}
    9889
    9990void SVGPathSegListBuilder::curveToCubic(const FloatPoint& point1, const FloatPoint& point2, const FloatPoint& targetPoint, PathCoordinateMode mode)
    10091{
    101     ASSERT(m_pathElement);
    102     ASSERT(m_pathSegList);
    10392    if (mode == AbsoluteCoordinates)
    104         m_pathSegList->append(m_pathElement->createSVGPathSegCurvetoCubicAbs(targetPoint.x(), targetPoint.y(), point1.x(), point1.y(), point2.x(), point2.y(), m_pathSegRole));
     93        m_pathSegList.append(m_pathElement.createSVGPathSegCurvetoCubicAbs(targetPoint.x(), targetPoint.y(), point1.x(), point1.y(), point2.x(), point2.y(), m_pathSegRole));
    10594    else
    106         m_pathSegList->append(m_pathElement->createSVGPathSegCurvetoCubicRel(targetPoint.x(), targetPoint.y(), point1.x(), point1.y(), point2.x(), point2.y(), m_pathSegRole));
     95        m_pathSegList.append(m_pathElement.createSVGPathSegCurvetoCubicRel(targetPoint.x(), targetPoint.y(), point1.x(), point1.y(), point2.x(), point2.y(), m_pathSegRole));
    10796}
    10897
    10998void SVGPathSegListBuilder::curveToCubicSmooth(const FloatPoint& point2, const FloatPoint& targetPoint, PathCoordinateMode mode)
    11099{
    111     ASSERT(m_pathElement);
    112     ASSERT(m_pathSegList);
    113100    if (mode == AbsoluteCoordinates)
    114         m_pathSegList->append(m_pathElement->createSVGPathSegCurvetoCubicSmoothAbs(targetPoint.x(), targetPoint.y(), point2.x(), point2.y(), m_pathSegRole));
     101        m_pathSegList.append(m_pathElement.createSVGPathSegCurvetoCubicSmoothAbs(targetPoint.x(), targetPoint.y(), point2.x(), point2.y(), m_pathSegRole));
    115102    else
    116         m_pathSegList->append(m_pathElement->createSVGPathSegCurvetoCubicSmoothRel(targetPoint.x(), targetPoint.y(), point2.x(), point2.y(), m_pathSegRole));
     103        m_pathSegList.append(m_pathElement.createSVGPathSegCurvetoCubicSmoothRel(targetPoint.x(), targetPoint.y(), point2.x(), point2.y(), m_pathSegRole));
    117104}
    118105
    119106void SVGPathSegListBuilder::curveToQuadratic(const FloatPoint& point1, const FloatPoint& targetPoint, PathCoordinateMode mode)
    120107{
    121     ASSERT(m_pathElement);
    122     ASSERT(m_pathSegList);
    123108    if (mode == AbsoluteCoordinates)
    124         m_pathSegList->append(m_pathElement->createSVGPathSegCurvetoQuadraticAbs(targetPoint.x(), targetPoint.y(), point1.x(), point1.y(), m_pathSegRole));
     109        m_pathSegList.append(m_pathElement.createSVGPathSegCurvetoQuadraticAbs(targetPoint.x(), targetPoint.y(), point1.x(), point1.y(), m_pathSegRole));
    125110    else
    126         m_pathSegList->append(m_pathElement->createSVGPathSegCurvetoQuadraticRel(targetPoint.x(), targetPoint.y(), point1.x(), point1.y(), m_pathSegRole));
     111        m_pathSegList.append(m_pathElement.createSVGPathSegCurvetoQuadraticRel(targetPoint.x(), targetPoint.y(), point1.x(), point1.y(), m_pathSegRole));
    127112}
    128113
    129114void SVGPathSegListBuilder::curveToQuadraticSmooth(const FloatPoint& targetPoint, PathCoordinateMode mode)
    130115{
    131     ASSERT(m_pathElement);
    132     ASSERT(m_pathSegList);
    133116    if (mode == AbsoluteCoordinates)
    134         m_pathSegList->append(m_pathElement->createSVGPathSegCurvetoQuadraticSmoothAbs(targetPoint.x(), targetPoint.y(), m_pathSegRole));
     117        m_pathSegList.append(m_pathElement.createSVGPathSegCurvetoQuadraticSmoothAbs(targetPoint.x(), targetPoint.y(), m_pathSegRole));
    135118    else
    136         m_pathSegList->append(m_pathElement->createSVGPathSegCurvetoQuadraticSmoothRel(targetPoint.x(), targetPoint.y(), m_pathSegRole));
     119        m_pathSegList.append(m_pathElement.createSVGPathSegCurvetoQuadraticSmoothRel(targetPoint.x(), targetPoint.y(), m_pathSegRole));
    137120}
    138121
    139122void SVGPathSegListBuilder::arcTo(float r1, float r2, float angle, bool largeArcFlag, bool sweepFlag, const FloatPoint& targetPoint, PathCoordinateMode mode)
    140123{
    141     ASSERT(m_pathElement);
    142     ASSERT(m_pathSegList);
    143124    if (mode == AbsoluteCoordinates)
    144         m_pathSegList->append(m_pathElement->createSVGPathSegArcAbs(targetPoint.x(), targetPoint.y(), r1, r2, angle, largeArcFlag, sweepFlag, m_pathSegRole));
     125        m_pathSegList.append(m_pathElement.createSVGPathSegArcAbs(targetPoint.x(), targetPoint.y(), r1, r2, angle, largeArcFlag, sweepFlag, m_pathSegRole));
    145126    else
    146         m_pathSegList->append(m_pathElement->createSVGPathSegArcRel(targetPoint.x(), targetPoint.y(), r1, r2, angle, largeArcFlag, sweepFlag, m_pathSegRole));
     127        m_pathSegList.append(m_pathElement.createSVGPathSegArcRel(targetPoint.x(), targetPoint.y(), r1, r2, angle, largeArcFlag, sweepFlag, m_pathSegRole));
    147128}
    148129
    149130void SVGPathSegListBuilder::closePath()
    150131{
    151     ASSERT(m_pathElement);
    152     ASSERT(m_pathSegList);
    153     m_pathSegList->append(m_pathElement->createSVGPathSegClosePath(m_pathSegRole));
     132    m_pathSegList.append(m_pathElement.createSVGPathSegClosePath(m_pathSegRole));
    154133}
    155134
  • trunk/Source/WebCore/svg/SVGPathSegListBuilder.h

    r184852 r190849  
    33 * Copyright (C) 2006 Alexander Kellett <lypanov@kde.org>
    44 * Copyright (C) 2006, 2007 Rob Buis <buis@kde.org>
    5  * Copyright (C) 2007, 2009 Apple Inc. All rights reserved.
     5 * Copyright (C) 2007, 2009, 2015 Apple Inc. All rights reserved.
    66 * Copyright (C) Research In Motion Limited 2010. All rights reserved.
    77 *
     
    3535class SVGPathSegListBuilder : public SVGPathConsumer {
    3636public:
    37     SVGPathSegListBuilder();
    38 
    39     void setCurrentSVGPathElement(SVGPathElement* pathElement) { m_pathElement = pathElement; }
    40     void setCurrentSVGPathSegList(SVGPathSegList& pathSegList) { m_pathSegList = &pathSegList; }
    41     void setCurrentSVGPathSegRole(SVGPathSegRole pathSegRole) { m_pathSegRole = pathSegRole; }
     37    SVGPathSegListBuilder(SVGPathElement&, SVGPathSegList&, SVGPathSegRole);
    4238
    4339private:
    4440    virtual void incrementPathSegmentCount() override { }
    4541    virtual bool continueConsuming() override { return true; }
    46     virtual void cleanup() override
    47     {
    48         m_pathElement = nullptr;
    49         m_pathSegList = nullptr;
    50         m_pathSegRole = PathSegUndefinedRole;
    51     }
    5242
    5343    // Used in UnalteredParsing/NormalizedParsing modes.
     
    6555    virtual void arcTo(float, float, float, bool largeArcFlag, bool sweepFlag, const FloatPoint&, PathCoordinateMode) override;
    6656
    67     SVGPathElement* m_pathElement;
    68     SVGPathSegList* m_pathSegList;
    69     SVGPathSegRole m_pathSegRole;
     57    SVGPathElement& m_pathElement;
     58    SVGPathSegList& m_pathSegList;
     59    SVGPathSegRole m_pathSegRole { PathSegUndefinedRole };
    7060};
    7161
  • trunk/Source/WebCore/svg/SVGPathStringBuilder.cpp

    r163440 r190849  
    11/*
    22 * Copyright (C) Research In Motion Limited 2010-2011. All rights reserved.
     3 * Copyright (C) 2015 Apple Inc. All rights reserved.
    34 *
    45 * This library is free software; you can redistribute it and/or
     
    4243    m_stringBuilder.resize(size - 1);
    4344    return m_stringBuilder.toString();
    44 }
    45 
    46 void SVGPathStringBuilder::cleanup()
    47 {
    48     m_stringBuilder.clear();
    4945}
    5046
  • trunk/Source/WebCore/svg/SVGPathStringBuilder.h

    r163440 r190849  
    11/*
    22 * Copyright (C) Research In Motion Limited 2010. All rights reserved.
     3 * Copyright (C) 2015 Apple Inc. All rights reserved.
    34 *
    45 * This library is free software; you can redistribute it and/or
     
    3435
    3536private:
    36     virtual void cleanup() override;
    3737    virtual void incrementPathSegmentCount() override;
    3838    virtual bool continueConsuming() override;
  • trunk/Source/WebCore/svg/SVGPathTraversalStateBuilder.cpp

    r184852 r190849  
    33 * Copyright (C) 2004, 2005 Rob Buis <buis@kde.org>
    44 * Copyright (C) 2007 Eric Seidel <eric@webkit.org>
     5 * Copyright (C) 2015 Apple Inc. All rights reserved.
    56 * Copyright (C) Research In Motion Limited 2010. All rights reserved.
    67 *
     
    2829namespace WebCore {
    2930
    30 SVGPathTraversalStateBuilder::SVGPathTraversalStateBuilder()
    31     : m_traversalState(nullptr)
    32     , m_segmentIndex(0)
     31SVGPathTraversalStateBuilder::SVGPathTraversalStateBuilder(PathTraversalState& state, float desiredLength)
     32    : m_traversalState(state)
    3333{
     34    m_traversalState.setDesiredLength(desiredLength);
    3435}
    3536
    3637void SVGPathTraversalStateBuilder::moveTo(const FloatPoint& targetPoint, bool, PathCoordinateMode)
    3738{
    38     ASSERT(m_traversalState);
    39     m_traversalState->processPathElement(PathElementMoveToPoint, &targetPoint);
     39    m_traversalState.processPathElement(PathElementMoveToPoint, &targetPoint);
    4040}
    4141
    4242void SVGPathTraversalStateBuilder::lineTo(const FloatPoint& targetPoint, PathCoordinateMode)
    4343{
    44     ASSERT(m_traversalState);
    45     m_traversalState->processPathElement(PathElementAddLineToPoint, &targetPoint);
     44    m_traversalState.processPathElement(PathElementAddLineToPoint, &targetPoint);
    4645}
    4746
     
    4948{
    5049    FloatPoint points[] = { point1, point2, targetPoint };
    51     ASSERT(m_traversalState);
    52     m_traversalState->processPathElement(PathElementAddCurveToPoint, points);
     50
     51    m_traversalState.processPathElement(PathElementAddCurveToPoint, points);
    5352}
    5453
    5554void SVGPathTraversalStateBuilder::closePath()
    5655{
    57     ASSERT(m_traversalState);
    58     m_traversalState->processPathElement(PathElementCloseSubpath, nullptr);
    59 }
    60 
    61 void SVGPathTraversalStateBuilder::setDesiredLength(float desiredLength)
    62 {
    63     ASSERT(m_traversalState);
    64     m_traversalState->setDesiredLength(desiredLength);
     56    m_traversalState.processPathElement(PathElementCloseSubpath, nullptr);
    6557}
    6658
    6759bool SVGPathTraversalStateBuilder::continueConsuming()
    6860{
    69     ASSERT(m_traversalState);   
    70     return !m_traversalState->success();
     61    return !m_traversalState.success();
    7162}
    7263
    73 float SVGPathTraversalStateBuilder::totalLength()
     64float SVGPathTraversalStateBuilder::totalLength() const
    7465{
    75     ASSERT(m_traversalState);
    76     return m_traversalState->totalLength();
     66    return m_traversalState.totalLength();
    7767}
    7868
    79 SVGPoint SVGPathTraversalStateBuilder::currentPoint()
     69SVGPoint SVGPathTraversalStateBuilder::currentPoint() const
    8070{
    81     ASSERT(m_traversalState);
    82     return m_traversalState->current();
     71    return m_traversalState.current();
    8372}
    8473
  • trunk/Source/WebCore/svg/SVGPathTraversalStateBuilder.h

    r182828 r190849  
    22 * Copyright (C) 2007 Eric Seidel <eric@webkit.org>
    33 * Copyright (C) Research In Motion Limited 2010. All rights reserved.
     4 * Copyright (C) 2015 Apple Inc. All rights reserved.
    45 *
    56 * This library is free software; you can redistribute it and/or
     
    3132class SVGPathTraversalStateBuilder : public SVGPathConsumer {
    3233public:
    33     SVGPathTraversalStateBuilder();
     34    SVGPathTraversalStateBuilder(PathTraversalState&, float desiredLength = 0);
    3435
    35     unsigned pathSegmentIndex() { return m_segmentIndex; }
    36     float totalLength();
    37     SVGPoint currentPoint();
     36    unsigned pathSegmentIndex() const { return m_segmentIndex; }
     37    float totalLength() const;
     38    SVGPoint currentPoint() const;
    3839
    39     void setCurrentTraversalState(PathTraversalState* traversalState) { m_traversalState = traversalState; }
    40     void setDesiredLength(float);
    4140    virtual void incrementPathSegmentCount() override { ++m_segmentIndex; }
    4241    virtual bool continueConsuming() override;
    43     virtual void cleanup() override { m_traversalState = nullptr, m_segmentIndex = 0; }
    4442
    4543private:
     
    5957    virtual void arcTo(float, float, float, bool, bool, const FloatPoint&, PathCoordinateMode) override { ASSERT_NOT_REACHED(); }
    6058
    61     PathTraversalState* m_traversalState;
    62     unsigned m_segmentIndex;
     59    PathTraversalState& m_traversalState;
     60    unsigned m_segmentIndex { 0 };
    6361};
    6462
  • trunk/Source/WebCore/svg/SVGPathUtilities.cpp

    r190844 r190849  
    11/*
    22 * Copyright (C) Research In Motion Limited 2010, 2012. All rights reserved.
     3 * Copyright (C) 2015 Apple Inc. All rights reserved.
    34 *
    45 * This library is free software; you can redistribute it and/or
     
    3839namespace WebCore {
    3940
    40 // FIXME: are all these globals warranted? Why not just make them on the stack?
    41 static SVGPathBuilder& globalSVGPathBuilder(Path& result)
    42 {
    43     static NeverDestroyed<SVGPathBuilder> s_builder;
    44     s_builder.get().setCurrentPath(&result);
    45     return s_builder.get();
    46 }
    47 
    48 static SVGPathSegListBuilder& globalSVGPathSegListBuilder(SVGPathElement& element, SVGPathSegRole role, SVGPathSegList& result)
    49 {
    50     static NeverDestroyed<SVGPathSegListBuilder> s_builder;
    51 
    52     s_builder.get().setCurrentSVGPathElement(&element);
    53     s_builder.get().setCurrentSVGPathSegList(result);
    54     s_builder.get().setCurrentSVGPathSegRole(role);
    55     return s_builder.get();
    56 }
    57 
    58 static SVGPathByteStreamBuilder& globalSVGPathByteStreamBuilder(SVGPathByteStream& result)
    59 {
    60     static NeverDestroyed<SVGPathByteStreamBuilder> s_builder;
    61     s_builder.get().setCurrentByteStream(&result);
    62     return s_builder.get();
    63 }
    64 
    65 static SVGPathStringBuilder& globalSVGPathStringBuilder()
    66 {
    67     static NeverDestroyed<SVGPathStringBuilder> s_builder;
    68     return s_builder.get();
    69 }
    70 
    71 static SVGPathTraversalStateBuilder& globalSVGPathTraversalStateBuilder(PathTraversalState& traversalState, float length)
    72 {
    73     static NeverDestroyed<SVGPathTraversalStateBuilder> s_parser;
    74 
    75     s_parser.get().setCurrentTraversalState(&traversalState);
    76     s_parser.get().setDesiredLength(length);
    77     return s_parser.get();
    78 }
    79 
    80 // FIXME: why bother keeping a singleton around? Is it slow to allocate?
    81 static SVGPathParser& globalSVGPathParser(SVGPathSource& source, SVGPathConsumer& consumer)
    82 {
    83     static NeverDestroyed<SVGPathParser> s_parser;
    84 
    85     s_parser.get().setCurrentSource(&source);
    86     s_parser.get().setCurrentConsumer(&consumer);
    87     return s_parser.get();
    88 }
    89 
    90 static SVGPathBlender& globalSVGPathBlender()
    91 {
    92     static NeverDestroyed<SVGPathBlender> s_blender;
    93     return s_blender.get();
    94 }
    95 
    9641bool buildPathFromString(const String& d, Path& result)
    9742{
     
    9944        return true;
    10045
    101     SVGPathBuilder& builder = globalSVGPathBuilder(result);
    102 
     46    SVGPathBuilder builder(result);
    10347    SVGPathStringSource source(d);
    104     SVGPathParser& parser = globalSVGPathParser(source, builder);
    105     bool ok = parser.parsePathDataFromSource(NormalizedParsing);
    106     parser.cleanup();
    107     return ok;
     48    return SVGPathParser::parse(source, builder);
    10849}
    10950
     
    11455        return true;
    11556
    116     SVGPathByteStreamBuilder& builder = globalSVGPathByteStreamBuilder(result);
    117 
    11857    SVGPathSegListSource source(list);
    119     SVGPathParser& parser = globalSVGPathParser(source, builder);
    120     bool ok = parser.parsePathDataFromSource(parsingMode);
    121     parser.cleanup();
    122     return ok;
     58    return SVGPathParser::parseToByteStream(source, result, parsingMode);
    12359}
    12460
     
    13268
    13369    SVGPathByteStream appendedByteStream;
    134     SVGPathByteStreamBuilder& builder = globalSVGPathByteStreamBuilder(appendedByteStream);
    13570    SVGPathSegListSource source(appendedItemList);
    136     SVGPathParser& parser = globalSVGPathParser(source, builder);
    137     bool ok = parser.parsePathDataFromSource(parsingMode, false);
    138     parser.cleanup();
     71    bool ok = SVGPathParser::parseToByteStream(source, result, parsingMode, false);
    13972
    14073    if (ok)
     
    14982        return true;
    15083
    151     SVGPathBuilder& builder = globalSVGPathBuilder(result);
    152 
    153     SVGPathByteStreamSource source(stream);
    154     SVGPathParser& parser = globalSVGPathParser(source, builder);
    155     bool ok = parser.parsePathDataFromSource(NormalizedParsing);
    156     parser.cleanup();
    157     return ok;
     84    SVGPathBuilder builder(result);
     85    SVGPathByteStreamSource source(stream);
     86    return SVGPathParser::parse(source, builder);
    15887}
    15988
     
    16392        return true;
    16493
    165     SVGPathSegListBuilder& builder = globalSVGPathSegListBuilder(element, parsingMode == NormalizedParsing ? PathSegNormalizedRole : PathSegUnalteredRole, result);
    166 
    167     SVGPathByteStreamSource source(stream);
    168     SVGPathParser& parser = globalSVGPathParser(source, builder);
    169     bool ok = parser.parsePathDataFromSource(parsingMode);
    170     parser.cleanup();
    171     return ok;
     94    SVGPathSegListBuilder builder(element, result, parsingMode == NormalizedParsing ? PathSegNormalizedRole : PathSegUnalteredRole);
     95    SVGPathByteStreamSource source(stream);
     96    return SVGPathParser::parse(source, builder, parsingMode);
    17297}
    17398
     
    177102        return true;
    178103
    179     SVGPathStringBuilder& builder = globalSVGPathStringBuilder();
    180 
    181     SVGPathByteStreamSource source(stream);
    182     SVGPathParser& parser = globalSVGPathParser(source, builder);
    183     bool ok = parser.parsePathDataFromSource(parsingMode);
    184     result = builder.result();
    185     parser.cleanup();
    186     return ok;
     104    SVGPathByteStreamSource source(stream);
     105    return SVGPathParser::parseToString(source, result, parsingMode);
    187106}
    188107
     
    193112        return true;
    194113
    195     SVGPathStringBuilder& builder = globalSVGPathStringBuilder();
    196 
    197114    SVGPathSegListSource source(list);
    198     SVGPathParser& parser = globalSVGPathParser(source, builder);
    199     bool ok = parser.parsePathDataFromSource(parsingMode);
    200     result = builder.result();
    201     parser.cleanup();
    202     return ok;
     115    return SVGPathParser::parseToString(source, result, parsingMode);
    203116}
    204117
     
    209122        return true;
    210123
    211     SVGPathByteStreamBuilder& builder = globalSVGPathByteStreamBuilder(result);
    212 
    213124    SVGPathStringSource source(d);
    214     SVGPathParser& parser = globalSVGPathParser(source, builder);
    215     bool ok = parser.parsePathDataFromSource(parsingMode);
    216     parser.cleanup();
    217     return ok;
     125    return SVGPathParser::parseToByteStream(source, result, parsingMode);
    218126}
    219127
     
    225133        return true;
    226134
    227     SVGPathByteStreamBuilder& builder = globalSVGPathByteStreamBuilder(result);
     135    SVGPathByteStreamBuilder builder(result);
    228136
    229137    SVGPathByteStreamSource fromSource(fromStream);
    230138    SVGPathByteStreamSource toSource(toStream);
    231     SVGPathBlender& blender = globalSVGPathBlender();
    232     bool ok = blender.blendAnimatedPath(progress, &fromSource, &toSource, &builder);
    233     blender.cleanup();
    234     return ok;
     139    return SVGPathBlender::blendAnimatedPath(fromSource, toSource, builder, progress);
    235140}
    236141
     
    242147
    243148    // Is it OK to make the SVGPathByteStreamBuilder from a stream, and then clear that stream?
    244     SVGPathByteStreamBuilder& builder = globalSVGPathByteStreamBuilder(streamToAppendTo);
     149    SVGPathByteStreamBuilder builder(streamToAppendTo);
    245150
    246151    SVGPathByteStream fromStreamCopy = streamToAppendTo;
     
    249154    SVGPathByteStreamSource fromSource(fromStreamCopy);
    250155    SVGPathByteStreamSource bySource(byStream);
    251     SVGPathBlender& blender = globalSVGPathBlender();
    252     bool ok = blender.addAnimatedPath(&fromSource, &bySource, &builder, repeatCount);
    253     blender.cleanup();
    254     return ok;
     156    return SVGPathBlender::addAnimatedPath(fromSource, bySource, builder, repeatCount);
    255157}
    256158
     
    261163
    262164    PathTraversalState traversalState(PathTraversalState::Action::SegmentAtLength);
    263     SVGPathTraversalStateBuilder& builder = globalSVGPathTraversalStateBuilder(traversalState, length);
    264 
    265     SVGPathByteStreamSource source(stream);
    266     SVGPathParser& parser = globalSVGPathParser(source, builder);
    267     bool ok = parser.parsePathDataFromSource(NormalizedParsing);
     165    SVGPathTraversalStateBuilder builder(traversalState, length);
     166
     167    SVGPathByteStreamSource source(stream);
     168    bool ok = SVGPathParser::parse(source, builder);
    268169    pathSeg = builder.pathSegmentIndex();
    269     parser.cleanup();
    270170    return ok;
    271171}
     
    277177
    278178    PathTraversalState traversalState(PathTraversalState::Action::TotalLength);
    279     SVGPathTraversalStateBuilder& builder = globalSVGPathTraversalStateBuilder(traversalState, 0);
    280 
    281     SVGPathByteStreamSource source(stream);
    282     SVGPathParser& parser = globalSVGPathParser(source, builder);
    283     bool ok = parser.parsePathDataFromSource(NormalizedParsing);
     179
     180    SVGPathTraversalStateBuilder builder(traversalState);
     181
     182    SVGPathByteStreamSource source(stream);
     183    bool ok = SVGPathParser::parse(source, builder);
    284184    totalLength = builder.totalLength();
    285     parser.cleanup();
    286185    return ok;
    287186}
     
    293192
    294193    PathTraversalState traversalState(PathTraversalState::Action::VectorAtLength);
    295     SVGPathTraversalStateBuilder& builder = globalSVGPathTraversalStateBuilder(traversalState, length);
    296 
    297     SVGPathByteStreamSource source(stream);
    298     SVGPathParser& parser = globalSVGPathParser(source, builder);
    299     bool ok = parser.parsePathDataFromSource(NormalizedParsing);
     194
     195    SVGPathTraversalStateBuilder builder(traversalState, length);
     196
     197    SVGPathByteStreamSource source(stream);
     198    bool ok = SVGPathParser::parse(source, builder);
    300199    point = builder.currentPoint();
    301     parser.cleanup();
    302200    return ok;
    303201}
     
    333231    // a path, only apply a function to all path elements at once.
    334232
    335     SVGPathStringBuilder& builder = globalSVGPathStringBuilder();
     233    SVGPathStringBuilder builder;
    336234    path.apply([&builder](const PathElement& pathElement) {
    337235        pathIteratorForBuildingString(builder, pathElement);
    338236    });
    339237    string = builder.result();
    340     static_cast<SVGPathConsumer&>(builder).cleanup(); // Wat?
    341238
    342239    return true;
  • trunk/Source/WebCore/svg/SVGPathUtilities.h

    r190844 r190849  
    11/*
    22 * Copyright (C) Research In Motion Limited 2010, 2012. All rights reserved.
     3 * Copyright (C) 2015 Apple Inc. All rights reserved.
    34 *
    45 * This library is free software; you can redistribute it and/or
  • trunk/Source/WebCore/svg/SVGToOTFFontConversion.cpp

    r190841 r190849  
    11/*
    2  * Copyright (C) 2014 Apple Inc. All rights reserved.
     2 * Copyright (C) 2014-2015 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    3434#include "SVGHKernElement.h"
    3535#include "SVGMissingGlyphElement.h"
    36 #include "SVGPathBuilder.h"
    3736#include "SVGPathParser.h"
    3837#include "SVGPathStringSource.h"
     
    11271126static const char rMoveTo = 0x15;
    11281127
    1129 class CFFBuilder : public SVGPathBuilder {
     1128class CFFBuilder : public SVGPathConsumer {
    11301129public:
    11311130    CFFBuilder(Vector<char>& cffData, float width, FloatPoint origin)
    11321131        : m_cffData(cffData)
    1133         , m_hasBoundingBox(false)
    11341132    {
    11351133        writeCFFEncodedNumber(m_cffData, width);
     
    12101208    }
    12111209
     1210    virtual void incrementPathSegmentCount() override { }
     1211    virtual bool continueConsuming() override { return true; }
     1212
     1213    virtual void lineToHorizontal(float, PathCoordinateMode) override { ASSERT_NOT_REACHED(); }
     1214    virtual void lineToVertical(float, PathCoordinateMode) override { ASSERT_NOT_REACHED(); }
     1215    virtual void curveToCubicSmooth(const FloatPoint&, const FloatPoint&, PathCoordinateMode) override { ASSERT_NOT_REACHED(); }
     1216    virtual void curveToQuadratic(const FloatPoint&, const FloatPoint&, PathCoordinateMode) override { ASSERT_NOT_REACHED(); }
     1217    virtual void curveToQuadraticSmooth(const FloatPoint&, PathCoordinateMode) override { ASSERT_NOT_REACHED(); }
     1218    virtual void arcTo(float, float, float, bool, bool, const FloatPoint&, PathCoordinateMode) override { ASSERT_NOT_REACHED(); }
     1219
    12121220    Vector<char>& m_cffData;
    12131221    FloatPoint m_startingPoint;
     1222    FloatPoint m_current;
    12141223    FloatRect m_boundingBox;
    1215     bool m_hasBoundingBox;
     1224    bool m_hasBoundingBox { false };
    12161225};
    12171226
     
    12421251    SVGPathStringSource source(dAttribute);
    12431252
    1244     SVGPathParser parser;
    1245     parser.setCurrentSource(&source);
    1246     parser.setCurrentConsumer(&builder);
    1247 
    1248     ok = parser.parsePathDataFromSource(NormalizedParsing);
    1249     parser.cleanup();
    1250 
     1253    ok = SVGPathParser::parse(source, builder);
    12511254    if (!ok)
    12521255        result.clear();
Note: See TracChangeset for help on using the changeset viewer.