Changeset 251877 in webkit


Ignore:
Timestamp:
Oct 31, 2019 2:08:59 PM (4 years ago)
Author:
commit-queue@webkit.org
Message:

SVGGeometryElement.getPointAtLength should clamp its argument to [0, length]
https://bugs.webkit.org/show_bug.cgi?id=203687

Patch by Said Abou-Hallawa <sabouhallawa@apple.com> on 2019-10-31
Reviewed by Simon Fraser.

LayoutTests/imported/w3c:

  • web-platform-tests/svg/types/scripted/SVGGeometryElement.getPointAtLength-01-expected.txt:

Source/WebCore:

The spec link is:

https://svgwg.org/svg2-draft/types.html#__svg__SVGGeometryElement__getPointAtLength

-- Fix the SVGGeometryElement.idl to match the specs.
-- Fix the path utility functions to return zeros in case of an error.

The callers never used the return values.

  • rendering/svg/RenderSVGShape.cpp:

(WebCore::RenderSVGShape::getPointAtLength const):

  • rendering/svg/RenderSVGShape.h:
  • svg/SVGGeometryElement.cpp:

(WebCore::SVGGeometryElement::getPointAtLength const):

  • svg/SVGGeometryElement.h:
  • svg/SVGGeometryElement.idl:
  • svg/SVGPathElement.cpp:

(WebCore::SVGPathElement::getTotalLength const):
(WebCore::SVGPathElement::getPointAtLength const):
(WebCore::SVGPathElement::getPathSegAtLength const):

  • svg/SVGPathElement.h:
  • svg/SVGPathUtilities.cpp:

(WebCore::getSVGPathSegAtLengthFromSVGPathByteStream):
(WebCore::getTotalLengthOfSVGPathByteStream):
(WebCore::getPointAtLengthOfSVGPathByteStream):

  • svg/SVGPathUtilities.h:
Location:
trunk
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/imported/w3c/ChangeLog

    r251840 r251877  
     12019-10-31  Said Abou-Hallawa  <sabouhallawa@apple.com>
     2
     3        SVGGeometryElement.getPointAtLength should clamp its argument to [0, length]
     4        https://bugs.webkit.org/show_bug.cgi?id=203687
     5
     6        Reviewed by Simon Fraser.
     7
     8        * web-platform-tests/svg/types/scripted/SVGGeometryElement.getPointAtLength-01-expected.txt:
     9
    1102019-10-31  Antoine Quint  <graouts@apple.com>
    211
  • trunk/LayoutTests/imported/w3c/web-platform-tests/svg/types/scripted/SVGGeometryElement.getPointAtLength-01-expected.txt

    r251777 r251877  
    11
    2 FAIL SVGGeometryElement.prototype.getPointAtLength clamps its argument to [0, length], less than zero (SVGLineElement). assert_equals: starting x expected 50 but got 40
    3 FAIL SVGGeometryElement.prototype.getPointAtLength clamps its argument to [0, length], less than zero (SVGPathElement). assert_equals: starting x expected 40 but got 30
     2PASS SVGGeometryElement.prototype.getPointAtLength clamps its argument to [0, length], less than zero (SVGLineElement).
     3PASS SVGGeometryElement.prototype.getPointAtLength clamps its argument to [0, length], less than zero (SVGPathElement).
    44PASS SVGGeometryElement.prototype.getPointAtLength clamps its argument to [0, length], greater than 'length' (SVGLineElement).
    55PASS SVGGeometryElement.prototype.getPointAtLength clamps its argument to [0, length], greater than 'length' (SVGPathElement).
  • trunk/Source/WebCore/ChangeLog

    r251874 r251877  
     12019-10-31  Said Abou-Hallawa  <sabouhallawa@apple.com>
     2
     3        SVGGeometryElement.getPointAtLength should clamp its argument to [0, length]
     4        https://bugs.webkit.org/show_bug.cgi?id=203687
     5
     6        Reviewed by Simon Fraser.
     7
     8        The spec link is:
     9            https://svgwg.org/svg2-draft/types.html#__svg__SVGGeometryElement__getPointAtLength
     10
     11        -- Fix the SVGGeometryElement.idl to match the specs.
     12        -- Fix the path utility functions to return zeros in case of an error.
     13           The callers never used the return values.
     14
     15        * rendering/svg/RenderSVGShape.cpp:
     16        (WebCore::RenderSVGShape::getPointAtLength const):
     17        * rendering/svg/RenderSVGShape.h:
     18        * svg/SVGGeometryElement.cpp:
     19        (WebCore::SVGGeometryElement::getPointAtLength const):
     20        * svg/SVGGeometryElement.h:
     21        * svg/SVGGeometryElement.idl:
     22        * svg/SVGPathElement.cpp:
     23        (WebCore::SVGPathElement::getTotalLength const):
     24        (WebCore::SVGPathElement::getPointAtLength const):
     25        (WebCore::SVGPathElement::getPathSegAtLength const):
     26        * svg/SVGPathElement.h:
     27        * svg/SVGPathUtilities.cpp:
     28        (WebCore::getSVGPathSegAtLengthFromSVGPathByteStream):
     29        (WebCore::getTotalLengthOfSVGPathByteStream):
     30        (WebCore::getPointAtLengthOfSVGPathByteStream):
     31        * svg/SVGPathUtilities.h:
     32
    1332019-10-31  Zan Dobersek  <zdobersek@igalia.com>  and  Chris Lord  <clord@igalia.com>
    234
  • trunk/Source/WebCore/rendering/svg/RenderSVGShape.cpp

    r251444 r251877  
    354354}
    355355
    356 void RenderSVGShape::getPointAtLength(FloatPoint& point, float distance) const
     356FloatPoint RenderSVGShape::getPointAtLength(float distance) const
    357357{
    358358    if (!m_path)
    359         return;
     359        return { };
    360360
    361361    bool isValid;
    362     point = m_path->pointAtLength(distance, isValid);
     362    return m_path->pointAtLength(distance, isValid);
    363363}
    364364
  • trunk/Source/WebCore/rendering/svg/RenderSVGShape.h

    r238071 r251877  
    6767
    6868    float getTotalLength() const;
    69     void getPointAtLength(FloatPoint&, float distance) const;
     69    FloatPoint getPointAtLength(float distance) const;
    7070
    7171    bool hasPath() const { return m_path.get(); }
  • trunk/Source/WebCore/svg/SVGGeometryElement.cpp

    r246490 r251877  
    5656}
    5757
    58 Ref<SVGPoint> SVGGeometryElement::getPointAtLength(float distance) const
     58ExceptionOr<Ref<SVGPoint>> SVGGeometryElement::getPointAtLength(float distance) const
    5959{
    60     FloatPoint point { };
    61 
    6260    document().updateLayoutIgnorePendingStylesheets();
    6361
    6462    auto* renderer = downcast<RenderSVGShape>(this->renderer());
    65     if (renderer)
    66         renderer->getPointAtLength(point, distance);
     63   
     64    // Spec: If current element is a non-rendered element, throw an InvalidStateError.
     65    if (!renderer)
     66        return Exception { InvalidStateError };
     67   
     68    // Spec: Clamp distance to [0, length].
     69    distance = clampTo<float>(distance, 0, getTotalLength());
    6770
    68     return SVGPoint::create(point);
     71    // Spec: Return a newly created, detached SVGPoint object.
     72    return SVGPoint::create(renderer->getPointAtLength(distance));
    6973}
    7074
  • trunk/Source/WebCore/svg/SVGGeometryElement.h

    r246490 r251877  
    3636public:
    3737    virtual float getTotalLength() const;
    38     virtual Ref<SVGPoint> getPointAtLength(float distance) const;
     38    virtual ExceptionOr<Ref<SVGPoint>> getPointAtLength(float distance) const;
    3939
    4040    bool isPointInFill(DOMPointInit&&);
  • trunk/Source/WebCore/svg/SVGGeometryElement.idl

    r231739 r251877  
    2626// [Exposed=Window]
    2727interface SVGGeometryElement : SVGGraphicsElement {
    28     readonly attribute SVGAnimatedNumber pathLength; // FIXME: Should be [SameObject].
     28    [SameObject] readonly attribute SVGAnimatedNumber pathLength;
    2929
    3030    boolean isPointInFill(optional DOMPointInit point);
    3131    boolean isPointInStroke(optional DOMPointInit point);
    3232    unrestricted float getTotalLength();
    33     [NewObject] SVGPoint getPointAtLength(float distance);
     33    [NewObject, MayThrowException] SVGPoint getPointAtLength(float distance);
    3434};
  • trunk/Source/WebCore/svg/SVGPathElement.cpp

    r251318 r251877  
    107107float SVGPathElement::getTotalLength() const
    108108{
    109     float totalLength = 0;
    110     getTotalLengthOfSVGPathByteStream(pathByteStream(), totalLength);
    111     return totalLength;
     109    return getTotalLengthOfSVGPathByteStream(pathByteStream());
    112110}
    113111
    114 Ref<SVGPoint> SVGPathElement::getPointAtLength(float length) const
     112ExceptionOr<Ref<SVGPoint>> SVGPathElement::getPointAtLength(float distance) const
    115113{
    116     FloatPoint point;
    117     getPointAtLengthOfSVGPathByteStream(pathByteStream(), length, point);
    118     return SVGPoint::create(point);
     114    // Spec: Clamp distance to [0, length].
     115    distance = clampTo<float>(distance, 0, getTotalLength());
     116
     117    // Spec: Return a newly created, detached SVGPoint object.
     118    return SVGPoint::create(getPointAtLengthOfSVGPathByteStream(pathByteStream(), distance));
    119119}
    120120
    121121unsigned SVGPathElement::getPathSegAtLength(float length) const
    122122{
    123     unsigned pathSeg = 0;
    124     getSVGPathSegAtLengthFromSVGPathByteStream(pathByteStream(), length, pathSeg);
    125     return pathSeg;
     123    return getSVGPathSegAtLengthFromSVGPathByteStream(pathByteStream(), length);
    126124}
    127125
  • trunk/Source/WebCore/svg/SVGPathElement.h

    r251318 r251877  
    8989
    9090    float getTotalLength() const final;
    91     Ref<SVGPoint> getPointAtLength(float distance) const final;
     91    ExceptionOr<Ref<SVGPoint>> getPointAtLength(float distance) const final;
    9292    unsigned getPathSegAtLength(float distance) const;
    9393
  • trunk/Source/WebCore/svg/SVGPathUtilities.cpp

    r246034 r251877  
    194194}
    195195
    196 bool getSVGPathSegAtLengthFromSVGPathByteStream(const SVGPathByteStream& stream, float length, unsigned& pathSeg)
    197 {
    198     if (stream.isEmpty())
    199         return false;
     196unsigned getSVGPathSegAtLengthFromSVGPathByteStream(const SVGPathByteStream& stream, float length)
     197{
     198    if (stream.isEmpty())
     199        return 0;
    200200
    201201    PathTraversalState traversalState(PathTraversalState::Action::SegmentAtLength);
     
    203203
    204204    SVGPathByteStreamSource source(stream);
    205     bool ok = SVGPathParser::parse(source, builder);
    206     pathSeg = builder.pathSegmentIndex();
    207     return ok;
    208 }
    209 
    210 bool getTotalLengthOfSVGPathByteStream(const SVGPathByteStream& stream, float& totalLength)
    211 {
    212     if (stream.isEmpty())
    213         return false;
     205    SVGPathParser::parse(source, builder);
     206    return builder.pathSegmentIndex();
     207}
     208
     209float getTotalLengthOfSVGPathByteStream(const SVGPathByteStream& stream)
     210{
     211    if (stream.isEmpty())
     212        return 0;
    214213
    215214    PathTraversalState traversalState(PathTraversalState::Action::TotalLength);
     
    218217
    219218    SVGPathByteStreamSource source(stream);
    220     bool ok = SVGPathParser::parse(source, builder);
    221     totalLength = builder.totalLength();
    222     return ok;
    223 }
    224 
    225 bool getPointAtLengthOfSVGPathByteStream(const SVGPathByteStream& stream, float length, FloatPoint& point)
    226 {
    227     if (stream.isEmpty())
    228         return false;
     219    SVGPathParser::parse(source, builder);
     220    return builder.totalLength();
     221}
     222
     223FloatPoint getPointAtLengthOfSVGPathByteStream(const SVGPathByteStream& stream, float length)
     224{
     225    if (stream.isEmpty())
     226        return { };
    229227
    230228    PathTraversalState traversalState(PathTraversalState::Action::VectorAtLength);
     
    233231
    234232    SVGPathByteStreamSource source(stream);
    235     bool ok = SVGPathParser::parse(source, builder);
    236     point = builder.currentPoint();
    237     return ok;
    238 }
    239 
    240 }
     233    SVGPathParser::parse(source, builder);
     234    return builder.currentPoint();
     235}
     236
     237}
  • trunk/Source/WebCore/svg/SVGPathUtilities.h

    r243555 r251877  
    5454bool addToSVGPathByteStream(SVGPathByteStream& streamToAppendTo, const SVGPathByteStream& from, unsigned repeatCount = 1);
    5555
    56 bool getSVGPathSegAtLengthFromSVGPathByteStream(const SVGPathByteStream&, float length, unsigned& pathSeg);
    57 bool getTotalLengthOfSVGPathByteStream(const SVGPathByteStream&, float& totalLength);
    58 bool getPointAtLengthOfSVGPathByteStream(const SVGPathByteStream&, float length, FloatPoint&);
     56unsigned getSVGPathSegAtLengthFromSVGPathByteStream(const SVGPathByteStream&, float length);
     57float getTotalLengthOfSVGPathByteStream(const SVGPathByteStream&);
     58FloatPoint getPointAtLengthOfSVGPathByteStream(const SVGPathByteStream&, float length);
    5959
    6060} // namespace WebCore
Note: See TracChangeset for help on using the changeset viewer.