Reviewed by Eric.
authorrwlbuis@webkit.org <rwlbuis@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 26 Dec 2007 08:40:55 +0000 (08:40 +0000)
committerrwlbuis@webkit.org <rwlbuis@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 26 Dec 2007 08:40:55 +0000 (08:40 +0000)
        http://bugs.webkit.org/show_bug.cgi?id=15514
        <clipPath> with <use> not respected
        http://bugs.webkit.org/show_bug.cgi?id=16557
        SVG circle elements have been clipped away completely, instead of partially.

        Add toClipPath to get clip path data for the clipping paths. Implement it for <use>, thereby allowing clip paths using use.

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

14 files changed:
LayoutTests/ChangeLog
LayoutTests/svg/custom/clip-path-referencing-use-expected.checksum [new file with mode: 0644]
LayoutTests/svg/custom/clip-path-referencing-use-expected.png [new file with mode: 0644]
LayoutTests/svg/custom/clip-path-referencing-use-expected.txt [new file with mode: 0644]
LayoutTests/svg/custom/clip-path-referencing-use.svg [new file with mode: 0644]
LayoutTests/svg/custom/clip-path-referencing-use2-expected.checksum [new file with mode: 0644]
LayoutTests/svg/custom/clip-path-referencing-use2-expected.png [new file with mode: 0644]
LayoutTests/svg/custom/clip-path-referencing-use2-expected.txt [new file with mode: 0644]
LayoutTests/svg/custom/clip-path-referencing-use2.svg [new file with mode: 0644]
WebCore/ChangeLog
WebCore/svg/SVGClipPathElement.cpp
WebCore/svg/SVGStyledTransformableElement.h
WebCore/svg/SVGUseElement.cpp
WebCore/svg/SVGUseElement.h

index af7558e32530e953c58817b36a7e329d1bb424d2..f51bce1534b7ee4418c30e2f1b9ab62024d3ba0b 100644 (file)
@@ -1,3 +1,22 @@
+2007-12-25  Rob Buis  <buis@kde.org>
+
+        Reviewed by Eric.
+
+        Testcases for:
+        http://bugs.webkit.org/show_bug.cgi?id=15514
+        <clipPath> with <use> not respected
+        http://bugs.webkit.org/show_bug.cgi?id=16557
+        SVG circle elements have been clipped away completely, instead of partially.
+
+        * svg/custom/clip-path-referencing-use-expected.checksum: Added.
+        * svg/custom/clip-path-referencing-use-expected.png: Added.
+        * svg/custom/clip-path-referencing-use-expected.txt: Added.
+        * svg/custom/clip-path-referencing-use.svg: Added.
+        * svg/custom/clip-path-referencing-use2-expected.checksum: Added.
+        * svg/custom/clip-path-referencing-use2-expected.png: Added.
+        * svg/custom/clip-path-referencing-use2-expected.txt: Added.
+        * svg/custom/clip-path-referencing-use2.svg: Added.
+
 2007-12-25  David Smith  <catfish.man@gmail.com> and Sam Weinig  <sam@webkit.org>
 
         Reviewed by Oliver.
diff --git a/LayoutTests/svg/custom/clip-path-referencing-use-expected.checksum b/LayoutTests/svg/custom/clip-path-referencing-use-expected.checksum
new file mode 100644 (file)
index 0000000..f30737f
--- /dev/null
@@ -0,0 +1 @@
+ac0cbe8c013197ab31e32dae7bd897ce
\ No newline at end of file
diff --git a/LayoutTests/svg/custom/clip-path-referencing-use-expected.png b/LayoutTests/svg/custom/clip-path-referencing-use-expected.png
new file mode 100644 (file)
index 0000000..76356a5
Binary files /dev/null and b/LayoutTests/svg/custom/clip-path-referencing-use-expected.png differ
diff --git a/LayoutTests/svg/custom/clip-path-referencing-use-expected.txt b/LayoutTests/svg/custom/clip-path-referencing-use-expected.txt
new file mode 100644 (file)
index 0000000..b228750
--- /dev/null
@@ -0,0 +1,16 @@
+KCanvasResource {id="clip" [type=CLIPPER] [clip data=[[winding=NON-ZERO] [path=M0.00,0.00L100.00,0.00L100.00,100.00L0.00,100.00]]]}
+layer at (0,0) size 800x600
+  RenderView at (0,0) size 800x600
+layer at (0,0) size 800x600
+  RenderSVGRoot {svg} at (0,0) size 602x200
+    RenderSVGHiddenContainer {defs} at (0,0) size 0x0
+      RenderPath {rect} at (0,0) size 100x100 [fill={[type=SOLID] [color=#000000]}] [data="M0.00,0.00L100.00,0.00L100.00,100.00L0.00,100.00"]
+    RenderSVGContainer {g} at (0,0) size 200x200 [clip path="#clip"]
+      RenderPath {rect} at (0,0) size 200x200 [fill={[type=SOLID] [color=#FF0000]}] [data="M0.00,0.00L200.00,0.00L200.00,200.00L0.00,200.00"]
+      RenderPath {rect} at (0,0) size 100x100 [fill={[type=SOLID] [color=#008000]}] [data="M0.00,0.00L100.00,0.00L100.00,100.00L0.00,100.00"]
+    RenderSVGText {text} at (10,120) size 489x18 contains 1 chunk(s)
+      RenderSVGInlineText {#text} at (0,-14) size 489x18
+        chunk 1 text run 1 at (10.00,120.00) startOffset 0 endOffset 76 width 489.00: "The graphic above uses a 100x100 clipPath referencing a rectangle using use."
+    RenderSVGText {text} at (10,140) size 592x18 contains 1 chunk(s)
+      RenderSVGInlineText {#text} at (0,-14) size 592x18
+        chunk 1 text run 1 at (10.00,140.00) startOffset 0 endOffset 92 width 592.00: "It should clip the 200x200 red rectangle out and leave a 100x100 green rectangle. Bug 16557."
diff --git a/LayoutTests/svg/custom/clip-path-referencing-use.svg b/LayoutTests/svg/custom/clip-path-referencing-use.svg
new file mode 100644 (file)
index 0000000..8d5c3dc
--- /dev/null
@@ -0,0 +1,17 @@
+<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
+  <defs>
+    <rect id="rect" width="100" height="100" />
+    <clipPath id="clip">
+      <use xlink:href="#rect" />
+    </clipPath>
+  </defs>
+
+  <g clip-path="url(#clip)">
+    <rect width="200" height="200" fill="red" />
+    <rect width="100" height="100" fill="green" />
+  </g>
+
+  <text x="10" y="120">The graphic above uses a 100x100 clipPath referencing a rectangle using use.</text>
+   <text x="10" y="140">It should clip the 200x200 red rectangle out and leave a 100x100 green rectangle. Bug 16557. </text>
+</svg>
+
diff --git a/LayoutTests/svg/custom/clip-path-referencing-use2-expected.checksum b/LayoutTests/svg/custom/clip-path-referencing-use2-expected.checksum
new file mode 100644 (file)
index 0000000..2aa9a64
--- /dev/null
@@ -0,0 +1 @@
+029d25db037c3b869bab36b95c245ec1
\ No newline at end of file
diff --git a/LayoutTests/svg/custom/clip-path-referencing-use2-expected.png b/LayoutTests/svg/custom/clip-path-referencing-use2-expected.png
new file mode 100644 (file)
index 0000000..70f3435
Binary files /dev/null and b/LayoutTests/svg/custom/clip-path-referencing-use2-expected.png differ
diff --git a/LayoutTests/svg/custom/clip-path-referencing-use2-expected.txt b/LayoutTests/svg/custom/clip-path-referencing-use2-expected.txt
new file mode 100644 (file)
index 0000000..06f2347
--- /dev/null
@@ -0,0 +1,21 @@
+CONSOLE MESSAGE: line 1: Error: Not allowed to use indirect reference in <clip-path>
+CONSOLE MESSAGE: line 1: Error: Not allowed to use indirect reference in <clip-path>
+KCanvasResource {id="clip" [type=CLIPPER] [clip data=[[winding=EVEN-ODD] [path=M0.00,0.00L0.00,0.00L0.00,0.00L0.00,0.00]]]}
+layer at (0,0) size 800x600
+  RenderView at (0,0) size 800x600
+layer at (0,0) size 800x600
+  RenderSVGRoot {svg} at (0,0) size 598x144
+    RenderSVGHiddenContainer {defs} at (0,0) size 0x0
+      RenderPath {rect} at (0,0) size 50x50 [fill={[type=SOLID] [color=#000000]}] [data="M0.00,0.00L50.00,0.00L50.00,50.00L0.00,50.00"]
+      RenderSVGContainer {use} at (0,0) size 50x50
+        RenderSVGContainer {g} at (0,0) size 50x50
+          RenderPath {rect} at (0,0) size 50x50 [fill={[type=SOLID] [color=#000000]}] [data="M0.00,0.00L50.00,0.00L50.00,50.00L0.00,50.00"]
+    RenderPath {rect} at (0,0) size 100x100 [fill={[type=SOLID] [color=#008000]}] [data="M0.00,0.00L100.00,0.00L100.00,100.00L0.00,100.00"]
+    RenderSVGContainer {g} at (0,0) size 100x100 [clip path="#clip"]
+      RenderPath {rect} at (0,0) size 100x100 [fill={[type=SOLID] [color=#FF0000]}] [data="M0.00,0.00L100.00,0.00L100.00,100.00L0.00,100.00"]
+    RenderSVGText {text} at (10,120) size 377x18 contains 1 chunk(s)
+      RenderSVGInlineText {#text} at (0,-14) size 377x18
+        chunk 1 text run 1 at (10.00,120.00) startOffset 0 endOffset 56 width 377.00: "The graphic above should show a 100x100 green rectangle."
+    RenderSVGText {text} at (10,140) size 588x18 contains 1 chunk(s)
+      RenderSVGInlineText {#text} at (0,-14) size 588x18
+        chunk 1 text run 1 at (10.00,140.00) startOffset 0 endOffset 96 width 588.00: "The red rectangle should not show since it uses a clipping path that uses an indirect reference."
diff --git a/LayoutTests/svg/custom/clip-path-referencing-use2.svg b/LayoutTests/svg/custom/clip-path-referencing-use2.svg
new file mode 100644 (file)
index 0000000..505df21
--- /dev/null
@@ -0,0 +1,18 @@
+<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
+  <defs>
+    <rect width="50" height="50" id="rect"/>
+    <use id="use" xlink:href="#rect"/>
+    <clipPath id="clip">
+      <use xlink:href="#use" />
+    </clipPath>
+  </defs>
+
+  <rect width="100" height="100" fill="green" />
+  <g clip-path="url(#clip)">
+    <rect width="100" height="100" fill="red" />
+  </g>
+
+  <text x="10" y="120">The graphic above should show a 100x100 green rectangle.</text>
+   <text x="10" y="140">The red rectangle should not show since it uses a clipping path that uses an indirect reference.</text>
+</svg>
+
index c1274e072399ac1f5023edfa94285f9b83b02fa9..fabd5aef703b7b52ae7e7dd682b97f472418c405 100644 (file)
@@ -1,3 +1,23 @@
+2007-12-25  Rob Buis  <buis@kde.org>
+
+        Reviewed by Eric.
+
+        http://bugs.webkit.org/show_bug.cgi?id=15514
+        <clipPath> with <use> not respected
+        http://bugs.webkit.org/show_bug.cgi?id=16557
+        SVG circle elements have been clipped away completely, instead of partially.
+
+        Add toClipPath to get clip path data for the clipping paths. Implement it for <use>, thereby allowing clip paths using use.
+
+        * svg/SVGClipPathElement.cpp:
+        (WebCore::SVGClipPathElement::canvasResource):
+        * svg/SVGStyledTransformableElement.h:
+        (WebCore::SVGStyledTransformableElement::toClipPath):
+        * svg/SVGUseElement.cpp:
+        (WebCore::isDirectReference):
+        (WebCore::SVGUseElement::toClipPath):
+        * svg/SVGUseElement.h:
+
 2007-12-25  Sam Weinig  <sam@webkit.org>
 
         Reviewed by Eric Seidel.
index fd6cd3030d3e8797b3e88f3e6d04ab032f17f265..a0058e7aa2ee12979199d0a4a6caceb3ff34d77f 100644 (file)
@@ -80,7 +80,7 @@ SVGResource* SVGClipPathElement::canvasResource()
         if (n->isSVGElement() && static_cast<SVGElement*>(n)->isStyledTransformable()) {
             SVGStyledTransformableElement* styled = static_cast<SVGStyledTransformableElement*>(n);
             RenderStyle* pathStyle = document()->styleSelector()->styleForElement(styled, clipPathStyle);
-            Path pathData = styled->toPathData();
+            Path pathData = styled->toClipPath();
             // FIXME: How do we know the element has done a layout?
             pathData.transform(styled->animatedLocalTransform());
             if (!pathData.isEmpty())
index 71485729ae759c433dc1e88e5e5ea095b94ba3a8..1637cb2a848f8bc02e6cc263cc671d7c70e8cf42 100644 (file)
@@ -1,6 +1,6 @@
 /*
     Copyright (C) 2004, 2005 Nikolas Zimmermann <wildfox@kde.org>
-                  2004, 2005, 2006 Rob Buis <buis@kde.org>
+                  2004, 2005, 2006, 2007 Rob Buis <buis@kde.org>
 
     This file is part of the KDE project
 
@@ -53,11 +53,12 @@ namespace WebCore {
         virtual FloatRect getBBox() const;
 
         virtual void parseMappedAttribute(MappedAttribute*);
-        
+
         // "base class" methods for all the elements which render as paths
         virtual Path toPathData() const { return Path(); }
+        virtual Path toClipPath() const { return toPathData(); }
         virtual RenderObject* createRenderer(RenderArena*, RenderStyle*);
-        
+
         virtual void notifyAttributeChange() const;
 
     protected:
index 19ce8648d858061572141c813f75b0629455bc7c..192571e24c8c037a4228509fe65f5239be035d1f 100644 (file)
@@ -377,6 +377,34 @@ void SVGUseElement::detach()
         m_shadowTreeRootElement->detach();
 }
 
+static bool isDirectReference(Node* n)
+{
+    return n->hasTagName(SVGNames::pathTag) ||
+           n->hasTagName(SVGNames::rectTag) ||
+           n->hasTagName(SVGNames::circleTag) ||
+           n->hasTagName(SVGNames::ellipseTag) ||
+           n->hasTagName(SVGNames::polygonTag) ||
+           n->hasTagName(SVGNames::polylineTag) ||
+           n->hasTagName(SVGNames::textTag);
+}
+
+Path SVGUseElement::toClipPath() const
+{
+    if (!m_shadowTreeRootElement)
+        const_cast<SVGUseElement*>(this)->buildPendingResource();
+
+    Node* n = m_shadowTreeRootElement->firstChild();
+    if (n->isSVGElement() && static_cast<SVGElement*>(n)->isStyledTransformable()) {
+        if (!isDirectReference(n))
+            // Spec: Indirect references are an error (14.3.5)
+            document()->accessSVGExtensions()->reportError("Not allowed to use indirect reference in <clip-path>");
+        else
+            return static_cast<SVGStyledTransformableElement*>(n)->toClipPath();
+    }
+
+    return Path();
+}
+
 void SVGUseElement::buildInstanceTree(SVGElement* target, SVGElementInstance* targetInstance, bool& foundProblem)
 {
     ASSERT(target);
index 1070a1b4a76513a2d4eb437a7c8f01caec6c15d1..f045d69529f1756c8df2399371691aa5c1ff4041 100644 (file)
@@ -67,6 +67,8 @@ namespace WebCore
         virtual void attach();
         virtual void detach();
 
+        virtual Path toClipPath() const;
+
     protected:
         virtual const SVGElement* contextElement() const { return this; }