2006-12-26 Eric Seidel <eric@webkit.org>
authoreseidel <eseidel@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 26 Dec 2006 16:26:32 +0000 (16:26 +0000)
committereseidel <eseidel@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 26 Dec 2006 16:26:32 +0000 (16:26 +0000)
        Reviewed by rwlbuis.

        Replace bogus SVGLength::isFraction() method with valueAsPercentage() to fix:
        http://bugs.webkit.org/show_bug.cgi?id=11973

        * ksvg2/svg/SVGLength.cpp:
        (WebCore::SVGLength::valueInSpecifiedUnits): remove extra spaces
        (WebCore::SVGLength::valueAsPercentage): new method
        * ksvg2/svg/SVGLength.h:
        * ksvg2/svg/SVGLinearGradientElement.cpp:
        (WebCore::SVGLinearGradientElement::buildGradient): use valueAsPercentage()
        * ksvg2/svg/SVGPatternElement.cpp:
        (WebCore::SVGPatternElement::drawPatternContentIntoTile): return if malloc fails
        * ksvg2/svg/SVGRadialGradientElement.cpp:
        (WebCore::SVGRadialGradientElement::buildGradient): use valueAsPercentage()
        * platform/graphics/cg/GraphicsContextCG.cpp:
        (WebCore::GraphicsContext::createImageBuffer): return 0 if malloc fails
        * platform/graphics/svg/cg/SVGPaintServerGradientCg.cpp:
        (WebCore::SVGPaintServerGradient::setup): return if malloc fails
        * platform/graphics/svg/cg/SVGResourceMaskerCg.mm:
        (WebCore::SVGResourceMasker::applyMask): add comment about possible crash

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@18421 268f45cc-cd09-0410-ab3c-d52691b4dbfc

22 files changed:
LayoutTests/ChangeLog
LayoutTests/svg/custom/js-late-gradient-and-object-creation-expected.checksum
LayoutTests/svg/custom/js-late-gradient-and-object-creation-expected.png
LayoutTests/svg/custom/js-late-gradient-and-object-creation-expected.txt
LayoutTests/svg/custom/js-late-gradient-and-object-creation.svg
LayoutTests/svg/custom/js-late-gradient-creation-expected.checksum
LayoutTests/svg/custom/js-late-gradient-creation-expected.png
LayoutTests/svg/custom/js-late-gradient-creation-expected.txt
LayoutTests/svg/custom/js-late-gradient-creation.svg
LayoutTests/svg/custom/large-bounding-box-percents-expected.checksum [new file with mode: 0644]
LayoutTests/svg/custom/large-bounding-box-percents-expected.png [new file with mode: 0644]
LayoutTests/svg/custom/large-bounding-box-percents-expected.txt [new file with mode: 0644]
LayoutTests/svg/custom/large-bounding-box-percents.svg [new file with mode: 0644]
WebCore/ChangeLog
WebCore/ksvg2/svg/SVGLength.cpp
WebCore/ksvg2/svg/SVGLength.h
WebCore/ksvg2/svg/SVGLinearGradientElement.cpp
WebCore/ksvg2/svg/SVGPatternElement.cpp
WebCore/ksvg2/svg/SVGRadialGradientElement.cpp
WebCore/platform/graphics/cg/GraphicsContextCG.cpp
WebCore/platform/graphics/svg/cg/SVGPaintServerGradientCg.cpp
WebCore/platform/graphics/svg/cg/SVGResourceMaskerCg.mm

index 6630aaeac4f79882a56b6ade9229c42b200ab669..7d011734ea5a77c8f5aeda0ffcccfd030c52bbab 100644 (file)
@@ -1,3 +1,24 @@
+2006-12-26  Eric Seidel  <eric@webkit.org>
+
+        Reviewed by rwlbuis.
+        
+        Updated tests (and test results) after fixing:
+        WebKit does not respect boundingbox percentages larger than 100%
+        http://bugs.webkit.org/show_bug.cgi?id=11973
+
+        * svg/custom/js-late-gradient-and-object-creation-expected.checksum:
+        * svg/custom/js-late-gradient-and-object-creation-expected.png:
+        * svg/custom/js-late-gradient-and-object-creation-expected.txt:
+        * svg/custom/js-late-gradient-and-object-creation.svg:
+        * svg/custom/js-late-gradient-creation-expected.checksum:
+        * svg/custom/js-late-gradient-creation-expected.png:
+        * svg/custom/js-late-gradient-creation-expected.txt:
+        * svg/custom/js-late-gradient-creation.svg:
+        * svg/custom/large-bounding-box-percents-expected.checksum: Added.
+        * svg/custom/large-bounding-box-percents-expected.png: Added.
+        * svg/custom/large-bounding-box-percents-expected.txt: Added.
+        * svg/custom/large-bounding-box-percents.svg: Added.
+
 2006-12-26  Nikolas Zimmermann  <zimmermann@kde.org>
 
         Reviewed by Oliver.
index 20848614c9e47857018471b6b02debee4cb29b4e..2576160f85bb4b5e0119bcb6f49dc30ceab2d0b9 100644 (file)
@@ -1 +1 @@
-1d6f00f06bf2678713807225983e4ce2
\ No newline at end of file
+d48e9aada5dbc9b9a4a2d5a27c1de4b7
\ No newline at end of file
index b7ee67fbfacadfe40e27096b7564ce03e2d036e8..ce5ffcd672b2b223e19249b5d846edb7f831dfa0 100644 (file)
Binary files a/LayoutTests/svg/custom/js-late-gradient-and-object-creation-expected.png and b/LayoutTests/svg/custom/js-late-gradient-and-object-creation-expected.png differ
index 4e39cdcda3e710dc534720b3b7f7e031bf7899b4..873f48e9a578103333c5b4683cf68a0a3e23cc6c 100644 (file)
@@ -1,5 +1,5 @@
-KRenderingPaintServer {id="fillLinearGradient" [type=LINEAR-GRADIENT] [stops=[(0.00,#0000FF), (1.00,#FF0000)]] [start=(10,10)] [end=(440,0)]}
-KRenderingPaintServer {id="strokeLinearGradient" [type=LINEAR-GRADIENT] [stops=[(1.00,#008000)]] [start=(10,10)] [end=(440,0)]}
+KRenderingPaintServer {id="fillLinearGradient" [type=LINEAR-GRADIENT] [stops=[(0.00,#0000FF), (1.00,#FF0000)]] [start=(0,0)] [end=(100,0)]}
+KRenderingPaintServer {id="strokeLinearGradient" [type=LINEAR-GRADIENT] [stops=[(1.00,#008000)]] [start=(0,0)] [end=(100,0)]}
 layer at (0,0) size 800x600
   RenderView at (0,0) size 800x600
     RenderSVGContainer {svg} at (-250,15) size 1008.33x363.33
index edb4746582c07c12222551aa921f101597008948..44154187ae2c61091d5df25e7024828da8491603 100644 (file)
                // Setup "fillLinearGradient"
                var gradient1 = document.createElement("linearGradient");
                gradient1.setAttribute("id", "fillLinearGradient");
-               gradient1.setAttribute("x1", "10");
-               gradient1.setAttribute("y1", "10");
-               gradient1.setAttribute("x2", "440");
-               gradient1.setAttribute("xy", "10");
+               gradient1.setAttribute("x1", "0");
+               gradient1.setAttribute("x2", "1");
 
                var stop11 = document.createElement("stop");
                stop11.setAttribute("stop-color", "blue");
                // Setup "strokeLinearGradient"
                var gradient2 = document.createElement("linearGradient");
                gradient2.setAttribute("id", "strokeLinearGradient");
-               gradient2.setAttribute("x1", "10");
-               gradient2.setAttribute("y1", "10");
-               gradient2.setAttribute("x2", "440");
-               gradient2.setAttribute("xy", "10");
+               gradient2.setAttribute("x1", "0");
+               gradient2.setAttribute("x2", "1");
 
                var stop22 = document.createElement("stop");
                stop22.setAttribute("stop-color", "yellow");
index aa594fc19ffba68e16855e85f67ecffc8cc12194..b4f83b8164d573ff0454d1663a71a6cc25b6a9da 100644 (file)
@@ -1 +1 @@
-ce98110035a3e810643a85660f989bf6
\ No newline at end of file
+23d2f1db55637003a57f111d6e057472
\ No newline at end of file
index 1f5dd874c770be28e5b304cf68d22183bd713943..becef7c18223384a5a452d6e1b8b7646792a6dc7 100644 (file)
Binary files a/LayoutTests/svg/custom/js-late-gradient-creation-expected.png and b/LayoutTests/svg/custom/js-late-gradient-creation-expected.png differ
index 3a75230b9f28bfac6f0c0bfa665ac6cf1f582e61..090ca0f66f97e383df04840892af41a619490e25 100644 (file)
@@ -1,4 +1,4 @@
-KRenderingPaintServer {id="dynGrad" [type=LINEAR-GRADIENT] [stops=[(0.00,#0000FF), (1.00,#FF0000)]] [start=(10,10)] [end=(440,0)]}
+KRenderingPaintServer {id="dynGrad" [type=LINEAR-GRADIENT] [stops=[(0.00,#0000FF), (1.00,#FF0000)]] [start=(0,0)] [end=(100,0)]}
 layer at (0,0) size 800x600
   RenderView at (0,0) size 800x600
     RenderSVGContainer {svg} at (33.33,22.50) size 700x195
index c3b8330582545c9786b37d81ba8c9f039be5d9fe..20f7656de6963c46274f78ab40309abd1df8ad93 100644 (file)
        {
                var gradient = document.createElement("linearGradient");
                gradient.setAttribute("id", "dynGrad");
-               gradient.setAttribute("x1", "10");
-               gradient.setAttribute("y1", "10");
-               gradient.setAttribute("x2", "440");
-               gradient.setAttribute("xy", "10");
+               gradient.setAttribute("x1", "0");
+               gradient.setAttribute("x2", "1");
 
                var stop1 = document.createElement("stop");
                stop1.setAttribute("stop-color", "blue");
diff --git a/LayoutTests/svg/custom/large-bounding-box-percents-expected.checksum b/LayoutTests/svg/custom/large-bounding-box-percents-expected.checksum
new file mode 100644 (file)
index 0000000..92984fd
--- /dev/null
@@ -0,0 +1 @@
+ab26223b261bf32598417729f5423581
\ No newline at end of file
diff --git a/LayoutTests/svg/custom/large-bounding-box-percents-expected.png b/LayoutTests/svg/custom/large-bounding-box-percents-expected.png
new file mode 100644 (file)
index 0000000..23b92bf
Binary files /dev/null and b/LayoutTests/svg/custom/large-bounding-box-percents-expected.png differ
diff --git a/LayoutTests/svg/custom/large-bounding-box-percents-expected.txt b/LayoutTests/svg/custom/large-bounding-box-percents-expected.txt
new file mode 100644 (file)
index 0000000..0017321
--- /dev/null
@@ -0,0 +1,5 @@
+KRenderingPaintServer {id="myradial" [type=RADIAL-GRADIENT] [stops=[(0.00,#008000), (1.00,#FF0000)]] [center=(50,50)] [focal=(50,50)] [radius=500.00]}
+layer at (0,0) size 800x600
+  RenderView at (0,0) size 800x600
+    RenderSVGContainer {svg} at (0,0) size 100x100
+      RenderPath {rect} at (0,0) size 100x100 [fill={[type=RADIAL-GRADIENT] [stops=[(0.00,#008000), (1.00,#FF0000)]] [center=(50,50)] [focal=(50,50)] [radius=500.00]}] [data="M0.00,0.00L100.00,0.00L100.00,100.00L0.00,100.00"]
diff --git a/LayoutTests/svg/custom/large-bounding-box-percents.svg b/LayoutTests/svg/custom/large-bounding-box-percents.svg
new file mode 100644 (file)
index 0000000..5376e82
--- /dev/null
@@ -0,0 +1,7 @@
+<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
+    <radialGradient id="myradial" r="5">
+        <stop offset="0" style="stop-color: green"/>
+        <stop offset="1" style="stop-color: red"/>
+    </radialGradient>
+  <rect x='0' y='0' width='100' height='100' style="fill:url(#myradial)"/>
+</svg>
index 8d2088286833610f73c19f85951a02d4f046edb1..9002bc3c07f82ac136e3a02e569b5566a97f83b3 100644 (file)
@@ -1,3 +1,27 @@
+2006-12-26  Eric Seidel  <eric@webkit.org>
+
+        Reviewed by rwlbuis.
+
+        Replace bogus SVGLength::isFraction() method with valueAsPercentage() to fix:
+        http://bugs.webkit.org/show_bug.cgi?id=11973
+        
+        * ksvg2/svg/SVGLength.cpp:
+        (WebCore::SVGLength::valueInSpecifiedUnits): remove extra spaces
+        (WebCore::SVGLength::valueAsPercentage): new method
+        * ksvg2/svg/SVGLength.h:
+        * ksvg2/svg/SVGLinearGradientElement.cpp:
+        (WebCore::SVGLinearGradientElement::buildGradient): use valueAsPercentage()
+        * ksvg2/svg/SVGPatternElement.cpp:
+        (WebCore::SVGPatternElement::drawPatternContentIntoTile): return if malloc fails
+        * ksvg2/svg/SVGRadialGradientElement.cpp:
+        (WebCore::SVGRadialGradientElement::buildGradient): use valueAsPercentage()
+        * platform/graphics/cg/GraphicsContextCG.cpp:
+        (WebCore::GraphicsContext::createImageBuffer): return 0 if malloc fails
+        * platform/graphics/svg/cg/SVGPaintServerGradientCg.cpp:
+        (WebCore::SVGPaintServerGradient::setup): return if malloc fails
+        * platform/graphics/svg/cg/SVGResourceMaskerCg.mm:
+        (WebCore::SVGResourceMasker::applyMask): add comment about possible crash
+
 2006-12-26  Nikolas Zimmermann  <zimmermann@kde.org>
 
         Reviewed by Oliver.
index a9ca6dc8358283982e0fd505be0e6a002c158d72..cca5a10148c4096038efc0a75d13f73acc93f5e2 100644 (file)
@@ -227,7 +227,15 @@ void SVGLength::setValueInSpecifiedUnits(float value)
 float SVGLength::valueInSpecifiedUnits() const
 {
     return m_valueInSpecifiedUnits;
-}                                                
+}
+
+float SVGLength::valueAsPercentage() const
+{
+    // 100% = 100.0 instead of 1.0 for historical reasons, this could eventually be changed
+    if (extractType(m_unit) == LengthTypePercentage)
+        return valueInSpecifiedUnits();
+    return valueInSpecifiedUnits() * 100.f;
+}
 
 void SVGLength::setValueAsString(const String& s)
 {
@@ -265,11 +273,6 @@ void SVGLength::convertToSpecifiedUnits(unsigned short type)
     setValue(valueInUserUnits);
 }
 
-bool SVGLength::isFraction(const SVGLength& length)
-{
-    return (length.unitType() == LengthTypeNumber && length.value() >= 0 && length.value() <= 1);
-}
-
 double SVGLength::dpi() const
 {
     /* FIXME: DPI detection
index 4204ae5544c0d5c977d05299e00a33bbf72fac53..42787effb6fb5008ceb8899a3de5076bfb9b46c0 100644 (file)
@@ -78,6 +78,8 @@ namespace WebCore {
 
         float valueInSpecifiedUnits() const;
         void setValueInSpecifiedUnits(float);
+        
+        float valueAsPercentage() const;
 
         String valueAsString() const;
         void setValueAsString(const String&);
@@ -86,7 +88,6 @@ namespace WebCore {
         void convertToSpecifiedUnits(unsigned short);
 
         // Helper functions
-        static bool isFraction(const SVGLength&);
         static float PercentageOfViewport(float value, const SVGStyledElement*, SVGLengthMode);
 
     private:
index 19728ce7109d26bc6d44d4219c42c45a48383aef..5fb8a03dfea62d37810f283b726228caf0238692 100644 (file)
@@ -78,21 +78,10 @@ void SVGLinearGradientElement::buildGradient(PassRefPtr<SVGPaintServerGradient>
     float _x1, _y1, _x2, _y2;
 
     if (bbox) {
-        _x1 = x1().valueInSpecifiedUnits();
-        if (SVGLength::isFraction(x1()))
-            _x1 *= 100.0;
-
-        _y1 = y1().valueInSpecifiedUnits();
-        if (SVGLength::isFraction(y1()))
-            _y1 *= 100.0;
-
-        _x2 = x2().valueInSpecifiedUnits();
-        if (SVGLength::isFraction(x2()))
-            _x2 *= 100.0;
-
-        _y2 = y2().valueInSpecifiedUnits();
-        if (SVGLength::isFraction(y2()))
-            _y2 *= 100.0;
+        _x1 = x1().valueAsPercentage();
+        _y1 = y1().valueAsPercentage();
+        _x2 = x2().valueAsPercentage();
+        _y2 = y2().valueAsPercentage();
     } else {
         _x1 = x1().value();
         _y1 = y1().value();
@@ -105,8 +94,7 @@ void SVGLinearGradientElement::buildGradient(PassRefPtr<SVGPaintServerGradient>
     if (gradientTransform()->numberOfItems() > 0)
         mat = gradientTransform()->consolidate()->matrix();
 
-    DeprecatedString ref = href().deprecatedString();
-    RefPtr<SVGPaintServer> pserver = getPaintServerById(document(), ref.mid(1));
+    RefPtr<SVGPaintServer> pserver = getPaintServerById(document(), href().substring(1));
 
     if (pserver && (pserver->type() == RadialGradientPaintServer || pserver->type() == LinearGradientPaintServer)) {
         bool isLinear = pserver->type() == LinearGradientPaintServer;
index 477b3706c06f9421f30f35f74320f239e987aa7b..39900492e6cf6f035413675178d217dc31d83ee5 100644 (file)
@@ -158,21 +158,10 @@ void SVGPatternElement::drawPatternContentIntoTile(const SVGPatternElement* targ
 
     float _x, _y, w, h;
     if (bbox) {
-        _x = x().valueInSpecifiedUnits();
-        if (SVGLength::isFraction(x()))
-            _x *= 100.0;
-
-        _y = y().valueInSpecifiedUnits();
-        if (SVGLength::isFraction(y()))
-            _y *= 100.0;
-
-        w = width().valueInSpecifiedUnits();
-        if (SVGLength::isFraction(width()))
-            w *= 100.0;
-
-        h = height().valueInSpecifiedUnits();
-        if (SVGLength::isFraction(height()))
-            h *= 100.0;
+        _x = x().valueAsPercentage();
+        _y = y().valueAsPercentage();
+        w = width().valueAsPercentage();
+        h = height().valueAsPercentage();
     } else {
         _x = x().value();
         _y = y().value();
@@ -180,7 +169,7 @@ void SVGPatternElement::drawPatternContentIntoTile(const SVGPatternElement* targ
         h = height().value();
     }
 
-    ImageBuffer* patternImage(GraphicsContext::createImageBuffer(IntSize(lroundf(w), lroundf(h)), false));
+    ImageBuffer* patternImage = GraphicsContext::createImageBuffer(IntSize(lroundf(w), lroundf(h)), false);
     if (!patternImage)
         return;
 
index 0fab2a731c0dabb2c46b44a7d65fb326362ed0eb..1441fde81c8afdf1369f068bf9cb0283c9e895ac 100644 (file)
@@ -87,31 +87,11 @@ void SVGRadialGradientElement::buildGradient(PassRefPtr<SVGPaintServerGradient>
     float _cx, _cy, _r, _fx, _fy;
 
     if (bbox) {
-        _cx = cx().valueInSpecifiedUnits();
-        if (SVGLength::isFraction(cx()))
-            _cx *= 100.0;
-
-        _cy = cy().valueInSpecifiedUnits();
-        if (SVGLength::isFraction(cy()))
-            _cy *= 100.0;
-
-        _r = r().valueInSpecifiedUnits();
-        if (SVGLength::isFraction(r()))
-            _r *= 100.0;
-
-        if (fxSet) {
-            _fx = fx().valueInSpecifiedUnits();
-            if (SVGLength::isFraction(fx()))
-                _fx *= 100.0;
-        } else
-            _fx = _cx;
-        
-        if (fySet) {
-            _fy = fy().valueInSpecifiedUnits();
-            if (SVGLength::isFraction(fy()))
-                _fy *= 100.0;
-        } else
-            _fy = _cy;
+        _cx = cx().valueAsPercentage();
+        _cy = cy().valueAsPercentage();
+        _r = r().valueAsPercentage();
+        _fx = fxSet ? (fx().valueAsPercentage()) : _cx;
+        _fy = fySet ? (fy().valueAsPercentage()) : _cy;
     } else {
         _cx = cx().value();
         _cy = cy().value();
@@ -125,8 +105,7 @@ void SVGRadialGradientElement::buildGradient(PassRefPtr<SVGPaintServerGradient>
     if (gradientTransform()->numberOfItems() > 0)
         mat = gradientTransform()->consolidate()->matrix();
 
-    DeprecatedString ref = href().deprecatedString();
-    RefPtr<SVGPaintServer> pserver = getPaintServerById(document(), ref.mid(1));
+    RefPtr<SVGPaintServer> pserver = getPaintServerById(document(), href().substring(1));
 
     if (pserver && (pserver->type() == RadialGradientPaintServer || pserver->type() == LinearGradientPaintServer)) {
         bool isRadial = pserver->type() == RadialGradientPaintServer;
index 34c2d4ac193f5379e1d6c7744897586657c5667c..3e0d069fe65c927e9a790fa5ede322bd2beed262 100644 (file)
@@ -779,6 +779,8 @@ ImageBuffer* GraphicsContext::createImageBuffer(const IntSize& size, bool graySc
         bytesPerRow *= 4;
 
     void* imageBuffer = fastMalloc(bytesPerRow * size.height());
+    if (!imageBuffer)
+        return 0;
     memset(imageBuffer, 0, bytesPerRow * size.height());
 
     CGColorSpaceRef colorSpace = grayScale ? CGColorSpaceCreateDeviceGray() : CGColorSpaceCreateDeviceRGB();
index a991abe180c9e80748cf1f4b04ad8412cb88adb7..8289bec34eabae7098e37005708ee7eb58e63f7e 100644 (file)
@@ -267,7 +267,8 @@ bool SVGPaintServerGradient::setup(GraphicsContext*& context, const RenderObject
             IntRect maskRect = const_cast<RenderObject*>(object)->absoluteBoundingBoxRect();
             maskRect = object->absoluteTransform().inverse().mapRect(maskRect);
 
-            ImageBuffer* maskImage(GraphicsContext::createImageBuffer(IntSize(maskRect.width(), maskRect.height()), false));
+            ImageBuffer* maskImage = GraphicsContext::createImageBuffer(IntSize(maskRect.width(), maskRect.height()), false);
+            // FIXME: maskImage could be NULL
             GraphicsContext* maskImageContext = maskImage->context();
 
             maskImageContext->save();
index 34b8fe32e42c0eb81387d50df4420938d1830b2a..4ff4bd18ce403a609229845d812fda716bdffdae 100644 (file)
@@ -101,6 +101,8 @@ void SVGResourceMasker::applyMask(GraphicsContext* context, const FloatRect& bou
 
     // Create new graphics context in gray scale mode for image rendering
     OwnPtr<ImageBuffer> grayScaleImage(GraphicsContext::createImageBuffer(maskSize, true));
+    if (!grayScaleImage)
+        return;
     CGContextRef grayScaleContext = grayScaleImage->context()->platformContext();
 
     // Wrap CG context in CI context