Changeset 49481 in webkit


Ignore:
Timestamp:
Oct 12, 2009 4:05:21 PM (14 years ago)
Author:
eric@webkit.org
Message:

2009-10-12 Dirk Schulze <krit@webkit.org>

Reviewed by Nikolas Zimmermann.

Three old test results give back the absolute position instead of the realtive position.
The new test will check the correct behavior of gradients in userSpaceOnUse mode and
values in percentage.

  • platform/mac/svg/custom/gradient-attr-update-expected.txt:
  • platform/mac/svg/custom/gradient-deep-referencing-expected.txt:
  • platform/mac/svg/custom/gradient-userSpaceOnUse-with-percentage-expected.checksum: Added.
  • platform/mac/svg/custom/gradient-userSpaceOnUse-with-percentage-expected.png: Added.
  • platform/mac/svg/custom/gradient-userSpaceOnUse-with-percentage-expected.txt: Added.
  • platform/mac/svg/custom/text-gradient-no-content-expected.txt:
  • svg/custom/gradient-userSpaceOnUse-with-percentage.svg: Added.

2009-10-12 Dirk Schulze <krit@webkit.org>

Reviewed by Nikolas Zimmermann.

SVG Gradients can't handle percentage values in userSpaceOnUse mode
https://bugs.webkit.org/show_bug.cgi?id=30286

Fixed *GradientAttributes to take SVGLength instead of double. This casues
the problem, that we can't calculate the correct size of a gradient on
userSpaceOnUse mode with percentage values.

Test: svg/custom/gradient-userSpaceOnUse-with-percentage.svg

  • svg/LinearGradientAttributes.h: (WebCore::LinearGradientAttributes::LinearGradientAttributes): (WebCore::LinearGradientAttributes::x1): (WebCore::LinearGradientAttributes::y1): (WebCore::LinearGradientAttributes::x2): (WebCore::LinearGradientAttributes::y2): (WebCore::LinearGradientAttributes::setX1): (WebCore::LinearGradientAttributes::setY1): (WebCore::LinearGradientAttributes::setX2): (WebCore::LinearGradientAttributes::setY2):
  • svg/RadialGradientAttributes.h: (WebCore::RadialGradientAttributes::RadialGradientAttributes): (WebCore::RadialGradientAttributes::cx): (WebCore::RadialGradientAttributes::cy): (WebCore::RadialGradientAttributes::r): (WebCore::RadialGradientAttributes::fx): (WebCore::RadialGradientAttributes::fy): (WebCore::RadialGradientAttributes::setCx): (WebCore::RadialGradientAttributes::setCy): (WebCore::RadialGradientAttributes::setR): (WebCore::RadialGradientAttributes::setFx): (WebCore::RadialGradientAttributes::setFy):
  • svg/SVGLinearGradientElement.cpp: (WebCore::SVGLinearGradientElement::buildGradient): (WebCore::SVGLinearGradientElement::collectGradientProperties):
  • svg/SVGRadialGradientElement.cpp: (WebCore::SVGRadialGradientElement::buildGradient): (WebCore::SVGRadialGradientElement::collectGradientProperties):
Location:
trunk
Files:
4 added
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r49472 r49481  
     12009-10-12  Dirk Schulze  <krit@webkit.org>
     2
     3        Reviewed by Nikolas Zimmermann.
     4
     5        Three old test results give back the absolute position instead of the realtive position.
     6        The new test will check the correct behavior of gradients in userSpaceOnUse mode and
     7        values in percentage.
     8
     9        * platform/mac/svg/custom/gradient-attr-update-expected.txt:
     10        * platform/mac/svg/custom/gradient-deep-referencing-expected.txt:
     11        * platform/mac/svg/custom/gradient-userSpaceOnUse-with-percentage-expected.checksum: Added.
     12        * platform/mac/svg/custom/gradient-userSpaceOnUse-with-percentage-expected.png: Added.
     13        * platform/mac/svg/custom/gradient-userSpaceOnUse-with-percentage-expected.txt: Added.
     14        * platform/mac/svg/custom/text-gradient-no-content-expected.txt:
     15        * svg/custom/gradient-userSpaceOnUse-with-percentage.svg: Added.
     16
    1172009-10-12  Dirk Schulze  <krit@webkit.org>
    218
  • trunk/LayoutTests/platform/mac/svg/custom/gradient-attr-update-expected.txt

    r38794 r49481  
    1 KRenderingPaintServer {id="gradient1" [type=RADIAL-GRADIENT] [stops=[(0.00,#008000), (1.00,#008000)]][method=REFLECT] [bounding box mode=0] [center=(0.45,0.48)] [focal=(0.50,0.52)] [radius=200.00]}
     1KRenderingPaintServer {id="gradient1" [type=RADIAL-GRADIENT] [stops=[(0.00,#008000), (1.00,#008000)]][method=REFLECT] [bounding box mode=0] [center=(360,288)] [focal=(400,312)] [radius=200.00]}
    22layer at (0,0) size 800x600
    33  RenderView at (0,0) size 800x600
     
    88        RenderSVGGradientStop {stop} at (0,0) size 0x0
    99        RenderSVGGradientStop {stop} at (0,0) size 0x0
    10     RenderPath {rect} at (0,0) size 100x100 [fill={[type=RADIAL-GRADIENT] [stops=[(0.00,#008000), (1.00,#008000)]][method=REFLECT] [bounding box mode=0] [center=(0.45,0.48)] [focal=(0.50,0.52)] [radius=200.00]}] [data="M0.00,0.00 L100.00,0.00 L100.00,100.00 L0.00,100.00 Z"]
     10    RenderPath {rect} at (0,0) size 100x100 [fill={[type=RADIAL-GRADIENT] [stops=[(0.00,#008000), (1.00,#008000)]][method=REFLECT] [bounding box mode=0] [center=(360,288)] [focal=(400,312)] [radius=200.00]}] [data="M0.00,0.00 L100.00,0.00 L100.00,100.00 L0.00,100.00 Z"]
  • trunk/LayoutTests/platform/mac/svg/custom/gradient-deep-referencing-expected.txt

    r38794 r49481  
    22KRenderingPaintServer {id="gradient1e" [type=LINEAR-GRADIENT] [stops=[(0.00,#FF0000), (1.00,#0000FF)]] [bounding box mode=0] [start=(0,100)] [end=(100,0)]}
    33KRenderingPaintServer {id="gradient1d" [type=LINEAR-GRADIENT] [stops=[(0.00,#FF0000), (1.00,#0000FF)]] [bounding box mode=0] [start=(0,100)] [end=(100,0)]}
    4 KRenderingPaintServer {id="gradient1c" [type=RADIAL-GRADIENT] [stops=[(0.00,#FF0000), (1.00,#0000FF)]] [bounding box mode=0] [center=(0.50,0.50)] [focal=(0.50,0.50)] [radius=0.50]}
     4KRenderingPaintServer {id="gradient1c" [type=RADIAL-GRADIENT] [stops=[(0.00,#FF0000), (1.00,#0000FF)]] [bounding box mode=0] [center=(400,400)] [focal=(400,400)] [radius=400.00]}
    55KRenderingPaintServer {id="gradient1b" [type=LINEAR-GRADIENT] [stops=[]] [start=(0,0)] [end=(0,0)]}
    66KRenderingPaintServer {id="gradient1a" [type=LINEAR-GRADIENT] [stops=[]] [start=(0,0)] [end=(0,0)]}
  • trunk/LayoutTests/platform/mac/svg/custom/text-gradient-no-content-expected.txt

    r38794 r49481  
    1 KRenderingPaintServer {id="Gradient" [type=LINEAR-GRADIENT] [stops=[(0.00,#FF0000), (1.00,#FF0000)]] [bounding box mode=0] [start=(0,0)] [end=(1,0)]}
     1KRenderingPaintServer {id="Gradient" [type=LINEAR-GRADIENT] [stops=[(0.00,#FF0000), (1.00,#FF0000)]] [bounding box mode=0] [start=(0,0)] [end=(800,0)]}
    22layer at (0,0) size 800x600
    33  RenderView at (0,0) size 800x600
  • trunk/WebCore/ChangeLog

    r49479 r49481  
     12009-10-12  Dirk Schulze  <krit@webkit.org>
     2
     3        Reviewed by Nikolas Zimmermann.
     4
     5        SVG Gradients can't handle percentage values in userSpaceOnUse mode
     6        [https://bugs.webkit.org/show_bug.cgi?id=30286]
     7
     8        Fixed *GradientAttributes to take SVGLength instead of double. This casues
     9        the problem, that we can't calculate the correct size of a gradient on
     10        userSpaceOnUse mode with percentage values.
     11
     12        Test: svg/custom/gradient-userSpaceOnUse-with-percentage.svg
     13
     14        * svg/LinearGradientAttributes.h:
     15        (WebCore::LinearGradientAttributes::LinearGradientAttributes):
     16        (WebCore::LinearGradientAttributes::x1):
     17        (WebCore::LinearGradientAttributes::y1):
     18        (WebCore::LinearGradientAttributes::x2):
     19        (WebCore::LinearGradientAttributes::y2):
     20        (WebCore::LinearGradientAttributes::setX1):
     21        (WebCore::LinearGradientAttributes::setY1):
     22        (WebCore::LinearGradientAttributes::setX2):
     23        (WebCore::LinearGradientAttributes::setY2):
     24        * svg/RadialGradientAttributes.h:
     25        (WebCore::RadialGradientAttributes::RadialGradientAttributes):
     26        (WebCore::RadialGradientAttributes::cx):
     27        (WebCore::RadialGradientAttributes::cy):
     28        (WebCore::RadialGradientAttributes::r):
     29        (WebCore::RadialGradientAttributes::fx):
     30        (WebCore::RadialGradientAttributes::fy):
     31        (WebCore::RadialGradientAttributes::setCx):
     32        (WebCore::RadialGradientAttributes::setCy):
     33        (WebCore::RadialGradientAttributes::setR):
     34        (WebCore::RadialGradientAttributes::setFx):
     35        (WebCore::RadialGradientAttributes::setFy):
     36        * svg/SVGLinearGradientElement.cpp:
     37        (WebCore::SVGLinearGradientElement::buildGradient):
     38        (WebCore::SVGLinearGradientElement::collectGradientProperties):
     39        * svg/SVGRadialGradientElement.cpp:
     40        (WebCore::SVGRadialGradientElement::buildGradient):
     41        (WebCore::SVGRadialGradientElement::collectGradientProperties):
     42
    1432009-10-12  Brian Weinstein  <bweinstein@apple.com>
    244
  • trunk/WebCore/svg/LinearGradientAttributes.h

    r45747 r49481  
    3030    struct LinearGradientAttributes : GradientAttributes {
    3131        LinearGradientAttributes()
    32             : m_x1(0.0)
    33             , m_y1(0.0)
    34             , m_x2(1.0)
    35             , m_y2(0.0)
     32            : m_x1()
     33            , m_y1()
     34            , m_x2(LengthModeWidth, "100%")
     35            , m_y2()
    3636            , m_x1Set(false)
    3737            , m_y1Set(false)
     
    4141        }
    4242
    43         double x1() const { return m_x1; }
    44         double y1() const { return m_y1; }
    45         double x2() const { return m_x2; }
    46         double y2() const { return m_y2; }
     43        SVGLength x1() const { return m_x1; }
     44        SVGLength y1() const { return m_y1; }
     45        SVGLength x2() const { return m_x2; }
     46        SVGLength y2() const { return m_y2; }
    4747
    48         void setX1(double value) { m_x1 = value; m_x1Set = true; }
    49         void setY1(double value) { m_y1 = value; m_y1Set = true; }
    50         void setX2(double value) { m_x2 = value; m_x2Set = true; }
    51         void setY2(double value) { m_y2 = value; m_y2Set = true; }
     48        void setX1(const SVGLength& value) { m_x1 = value; m_x1Set = true; }
     49        void setY1(const SVGLength& value) { m_y1 = value; m_y1Set = true; }
     50        void setX2(const SVGLength& value) { m_x2 = value; m_x2Set = true; }
     51        void setY2(const SVGLength& value) { m_y2 = value; m_y2Set = true; }
    5252
    5353        bool hasX1() const { return m_x1Set; }
     
    5858    private:
    5959        // Properties
    60         double m_x1;
    61         double m_y1;
    62         double m_x2;
    63         double m_y2;
     60        SVGLength m_x1;
     61        SVGLength m_y1;
     62        SVGLength m_x2;
     63        SVGLength m_y2;
    6464
    6565        // Property states
  • trunk/WebCore/svg/RadialGradientAttributes.h

    r45747 r49481  
    3030    struct RadialGradientAttributes : GradientAttributes {
    3131        RadialGradientAttributes()
    32             : m_cx(0.5)
    33             , m_cy(0.5)
    34             , m_r(0.5)
    35             , m_fx(0.0)
    36             , m_fy(0.0)
     32            : m_cx(LengthModeWidth, "50%")
     33            , m_cy(LengthModeWidth, "50%")
     34            , m_r(LengthModeWidth, "50%")
     35            , m_fx()
     36            , m_fy()
    3737            , m_cxSet(false)
    3838            , m_cySet(false)
     
    4343        }
    4444
    45         double cx() const { return m_cx; }
    46         double cy() const { return m_cy; }
    47         double r() const { return m_r; }
    48         double fx() const { return m_fx; }
    49         double fy() const { return m_fy; }
     45        SVGLength cx() const { return m_cx; }
     46        SVGLength cy() const { return m_cy; }
     47        SVGLength r() const { return m_r; }
     48        SVGLength fx() const { return m_fx; }
     49        SVGLength fy() const { return m_fy; }
    5050
    51         void setCx(double value) { m_cx = value; m_cxSet = true; }
    52         void setCy(double value) { m_cy = value; m_cySet = true; }
    53         void setR(double value) { m_r = value; m_rSet = true; }
    54         void setFx(double value) { m_fx = value; m_fxSet = true; }
    55         void setFy(double value) { m_fy = value; m_fySet = true; }
     51        void setCx(const SVGLength& value) { m_cx = value; m_cxSet = true; }
     52        void setCy(const SVGLength& value) { m_cy = value; m_cySet = true; }
     53        void setR(const SVGLength& value) { m_r = value; m_rSet = true; }
     54        void setFx(const SVGLength& value) { m_fx = value; m_fxSet = true; }
     55        void setFy(const SVGLength& value) { m_fy = value; m_fySet = true; }
    5656
    5757        bool hasCx() const { return m_cxSet; }
     
    6363    private:
    6464        // Properties
    65         double m_cx;
    66         double m_cy;
    67         double m_r;
    68         double m_fx;
    69         double m_fy;
     65        SVGLength m_cx;
     66        SVGLength m_cy;
     67        SVGLength m_r;
     68        SVGLength m_fx;
     69        SVGLength m_fy;
    7070
    7171        // Property states
  • trunk/WebCore/svg/SVGLinearGradientElement.cpp

    r43187 r49481  
    8585    RefPtr<SVGPaintServerLinearGradient> linearGradient = WTF::static_pointer_cast<SVGPaintServerLinearGradient>(m_resource);
    8686
    87     FloatPoint startPoint = FloatPoint::narrowPrecision(attributes.x1(), attributes.y1());
    88     FloatPoint endPoint = FloatPoint::narrowPrecision(attributes.x2(), attributes.y2());
     87    FloatPoint startPoint;
     88    FloatPoint endPoint;
     89    if (attributes.boundingBoxMode()) {
     90        startPoint = FloatPoint(attributes.x1().valueAsPercentage(), attributes.y1().valueAsPercentage());
     91        endPoint = FloatPoint(attributes.x2().valueAsPercentage(), attributes.y2().valueAsPercentage());
     92    } else {
     93        startPoint = FloatPoint(attributes.x1().value(this), attributes.y1().value(this));
     94        endPoint = FloatPoint(attributes.x2().value(this), attributes.y2().value(this));
     95    }
    8996
    9097    RefPtr<Gradient> gradient = Gradient::create(startPoint, endPoint);
     
    143150
    144151            if (!attributes.hasX1() && current->hasAttribute(SVGNames::x1Attr))
    145                 attributes.setX1(linear->x1().valueAsPercentage());
     152                attributes.setX1(linear->x1());
    146153
    147154            if (!attributes.hasY1() && current->hasAttribute(SVGNames::y1Attr))
    148                 attributes.setY1(linear->y1().valueAsPercentage());
     155                attributes.setY1(linear->y1());
    149156
    150157            if (!attributes.hasX2() && current->hasAttribute(SVGNames::x2Attr))
    151                 attributes.setX2(linear->x2().valueAsPercentage());
     158                attributes.setX2(linear->x2());
    152159
    153160            if (!attributes.hasY2() && current->hasAttribute(SVGNames::y2Attr))
    154                 attributes.setY2(linear->y2().valueAsPercentage());
     161                attributes.setY2(linear->y2());
    155162        }
    156163
  • trunk/WebCore/svg/SVGRadialGradientElement.cpp

    r43187 r49481  
    9393    RefPtr<SVGPaintServerRadialGradient> radialGradient = WTF::static_pointer_cast<SVGPaintServerRadialGradient>(m_resource);
    9494
    95     double adjustedFocusX = attributes.fx();
    96     double adjustedFocusY = attributes.fy();
    97 
    98     double fdx = attributes.fx() - attributes.cx();
    99     double fdy = attributes.fy() - attributes.cy();
     95    FloatPoint focalPoint;
     96    FloatPoint centerPoint;
     97    float radius;
     98    if (attributes.boundingBoxMode()) {
     99        focalPoint = FloatPoint(attributes.fx().valueAsPercentage(), attributes.fy().valueAsPercentage());
     100        centerPoint = FloatPoint(attributes.cx().valueAsPercentage(), attributes.cy().valueAsPercentage());
     101        radius = attributes.r().valueAsPercentage();
     102    } else {
     103        focalPoint = FloatPoint(attributes.fx().value(this), attributes.fy().value(this));
     104        centerPoint = FloatPoint(attributes.cx().value(this), attributes.cy().value(this));
     105        radius = attributes.r().value(this);
     106    }
     107
     108    float adjustedFocusX = focalPoint.x();
     109    float adjustedFocusY = focalPoint.y();
     110
     111    float fdx = focalPoint.x() - centerPoint.x();
     112    float fdy = focalPoint.y() - centerPoint.y();
    100113
    101114    // Spec: If (fx, fy) lies outside the circle defined by (cx, cy) and
    102115    // r, set (fx, fy) to the point of intersection of the line through
    103116    // (fx, fy) and the circle.
    104     if (sqrt(fdx * fdx + fdy * fdy) > attributes.r()) {
    105         double angle = atan2(attributes.fy() * 100.0, attributes.fx() * 100.0);
    106         adjustedFocusX = cos(angle) * attributes.r();
    107         adjustedFocusY = sin(angle) * attributes.r();
    108     }
    109 
    110     FloatPoint focalPoint = FloatPoint::narrowPrecision(attributes.fx(), attributes.fy());
    111     FloatPoint centerPoint = FloatPoint::narrowPrecision(attributes.cx(), attributes.cy());
     117    if (sqrt(fdx * fdx + fdy * fdy) > radius) {
     118        float angle = atan2f(focalPoint.y() * 100.0f, focalPoint.x() * 100.0f);
     119        adjustedFocusX = cosf(angle) * radius;
     120        adjustedFocusY = sinf(angle) * radius;
     121    }
    112122
    113123    RefPtr<Gradient> gradient = Gradient::create(
    114         FloatPoint::narrowPrecision(adjustedFocusX, adjustedFocusY),
     124        FloatPoint(adjustedFocusX, adjustedFocusY),
    115125        0.f, // SVG does not support a "focus radius"
    116126        centerPoint,
    117         narrowPrecisionToFloat(attributes.r()));
     127        radius);
    118128    gradient->setSpreadMethod(attributes.spreadMethod());
    119129
     
    135145    radialGradient->setGradientCenter(centerPoint);
    136146    radialGradient->setGradientFocal(focalPoint);
    137     radialGradient->setGradientRadius(narrowPrecisionToFloat(attributes.r()));
     147    radialGradient->setGradientRadius(radius);
    138148    radialGradient->setGradientStops(attributes.stops());
    139149}
     
    167177
    168178            if (!attributes.hasCx() && current->hasAttribute(SVGNames::cxAttr))
    169                 attributes.setCx(radial->cx().valueAsPercentage());
     179                attributes.setCx(radial->cx());
    170180
    171181            if (!attributes.hasCy() && current->hasAttribute(SVGNames::cyAttr))
    172                 attributes.setCy(radial->cy().valueAsPercentage());
     182                attributes.setCy(radial->cy());
    173183
    174184            if (!attributes.hasR() && current->hasAttribute(SVGNames::rAttr))
    175                 attributes.setR(radial->r().valueAsPercentage());
     185                attributes.setR(radial->r());
    176186
    177187            if (!attributes.hasFx() && current->hasAttribute(SVGNames::fxAttr))
    178                 attributes.setFx(radial->fx().valueAsPercentage());
     188                attributes.setFx(radial->fx());
    179189
    180190            if (!attributes.hasFy() && current->hasAttribute(SVGNames::fyAttr))
    181                 attributes.setFy(radial->fy().valueAsPercentage());
     191                attributes.setFy(radial->fy());
    182192        }
    183193
Note: See TracChangeset for help on using the changeset viewer.