Fix painting of SVG <image> when the image must be scaled to retain aspect ratio
authoroliver@apple.com <oliver@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 8 Jan 2008 02:20:55 +0000 (02:20 +0000)
committeroliver@apple.com <oliver@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 8 Jan 2008 02:20:55 +0000 (02:20 +0000)
Reviewed by Niko

Also added new layout test for this bug, and corrected old expected output

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

19 files changed:
LayoutTests/ChangeLog
LayoutTests/platform/mac/svg/W3C-SVG-1.1/animate-elem-30-t-expected.checksum
LayoutTests/platform/mac/svg/W3C-SVG-1.1/animate-elem-30-t-expected.png
LayoutTests/platform/mac/svg/W3C-SVG-1.1/animate-elem-36-t-expected.checksum
LayoutTests/platform/mac/svg/W3C-SVG-1.1/animate-elem-36-t-expected.png
LayoutTests/platform/mac/svg/W3C-SVG-1.1/animate-elem-39-t-expected.checksum
LayoutTests/platform/mac/svg/W3C-SVG-1.1/animate-elem-39-t-expected.png
LayoutTests/platform/mac/svg/carto.net/selectionlist-expected.checksum
LayoutTests/platform/mac/svg/carto.net/selectionlist-expected.png
LayoutTests/platform/mac/svg/custom/image-with-aspect-ratio-stretch-expected.checksum [new file with mode: 0644]
LayoutTests/platform/mac/svg/custom/image-with-aspect-ratio-stretch-expected.png [new file with mode: 0644]
LayoutTests/platform/mac/svg/custom/image-with-aspect-ratio-stretch-expected.txt [new file with mode: 0644]
LayoutTests/platform/mac/svg/custom/pointer-events-image-expected.checksum
LayoutTests/platform/mac/svg/custom/pointer-events-image-expected.png
LayoutTests/platform/mac/svg/custom/text-image-opacity-expected.checksum
LayoutTests/platform/mac/svg/custom/text-image-opacity-expected.png
LayoutTests/svg/custom/image-with-aspect-ratio-stretch.svg [new file with mode: 0644]
WebCore/ChangeLog
WebCore/rendering/RenderSVGImage.cpp

index 39b4e8d..1943615 100644 (file)
@@ -1,3 +1,28 @@
+2008-01-07  Oliver Hunt  <oliver@apple.com>
+
+        Reviewed by Niko.
+
+        Add test case for <image> with a transformation to retain aspect ratio
+
+        * platform/mac/svg/custom/image-with-aspect-ratio-stretch-expected.checksum: Added.
+        * platform/mac/svg/custom/image-with-aspect-ratio-stretch-expected.png: Added.
+        * platform/mac/svg/custom/image-with-aspect-ratio-stretch-expected.txt: Added.
+        * svg/custom/image-with-aspect-ratio-stretch.svg: Added.
+        
+        Fixed expected output:
+        * platform/mac/svg/W3C-SVG-1.1/animate-elem-30-t-expected.checksum:
+        * platform/mac/svg/W3C-SVG-1.1/animate-elem-30-t-expected.png:
+        * platform/mac/svg/W3C-SVG-1.1/animate-elem-36-t-expected.checksum:
+        * platform/mac/svg/W3C-SVG-1.1/animate-elem-36-t-expected.png:
+        * platform/mac/svg/W3C-SVG-1.1/animate-elem-39-t-expected.checksum:
+        * platform/mac/svg/W3C-SVG-1.1/animate-elem-39-t-expected.png:
+        * platform/mac/svg/carto.net/selectionlist-expected.checksum:
+        * platform/mac/svg/carto.net/selectionlist-expected.png:
+        * platform/mac/svg/custom/pointer-events-image-expected.checksum:
+        * platform/mac/svg/custom/pointer-events-image-expected.png:
+        * platform/mac/svg/custom/text-image-opacity-expected.checksum:
+        * platform/mac/svg/custom/text-image-opacity-expected.png:
+
 2008-01-07  Adam Barth  <hk9565@gmail.com>
 
         Reviewed by Sam Weinig.
index 97c29b4..f8deb85 100644 (file)
Binary files a/LayoutTests/platform/mac/svg/W3C-SVG-1.1/animate-elem-30-t-expected.png and b/LayoutTests/platform/mac/svg/W3C-SVG-1.1/animate-elem-30-t-expected.png differ
index f03ef6d..098da88 100644 (file)
Binary files a/LayoutTests/platform/mac/svg/W3C-SVG-1.1/animate-elem-36-t-expected.png and b/LayoutTests/platform/mac/svg/W3C-SVG-1.1/animate-elem-36-t-expected.png differ
index 952f7e8..367286d 100644 (file)
Binary files a/LayoutTests/platform/mac/svg/W3C-SVG-1.1/animate-elem-39-t-expected.png and b/LayoutTests/platform/mac/svg/W3C-SVG-1.1/animate-elem-39-t-expected.png differ
index be888e9..6e90908 100644 (file)
Binary files a/LayoutTests/platform/mac/svg/carto.net/selectionlist-expected.png and b/LayoutTests/platform/mac/svg/carto.net/selectionlist-expected.png differ
diff --git a/LayoutTests/platform/mac/svg/custom/image-with-aspect-ratio-stretch-expected.checksum b/LayoutTests/platform/mac/svg/custom/image-with-aspect-ratio-stretch-expected.checksum
new file mode 100644 (file)
index 0000000..3a4f1f7
--- /dev/null
@@ -0,0 +1 @@
+16310588467cfc20d551635abc59b784
\ No newline at end of file
diff --git a/LayoutTests/platform/mac/svg/custom/image-with-aspect-ratio-stretch-expected.png b/LayoutTests/platform/mac/svg/custom/image-with-aspect-ratio-stretch-expected.png
new file mode 100644 (file)
index 0000000..3db2634
Binary files /dev/null and b/LayoutTests/platform/mac/svg/custom/image-with-aspect-ratio-stretch-expected.png differ
diff --git a/LayoutTests/platform/mac/svg/custom/image-with-aspect-ratio-stretch-expected.txt b/LayoutTests/platform/mac/svg/custom/image-with-aspect-ratio-stretch-expected.txt
new file mode 100644 (file)
index 0000000..f2c1a65
--- /dev/null
@@ -0,0 +1,11 @@
+layer at (0,0) size 800x600
+  RenderView at (0,0) size 800x600
+layer at (0,0) size 800x600
+  RenderSVGRoot {svg} at (0,-50) size 125x200
+    RenderSVGContainer {g} at (0,-50) size 125x200 [transform={m=((0.50,0.00)(0.00,1.00)) t=(0.00,0.00)}]
+      RenderSVGContainer {g} at (0,-50) size 50x200 [transform={m=((1.00,0.00)(0.00,1.00)) t=(-100.00,-150.00)}]
+        RenderPath {rect} at (0,0) size 50x100 [fill={[type=SOLID] [color=#FF0000]}] [data="M100.00,150.00L200.00,150.00L200.00,250.00L100.00,250.00"]
+        RenderImage {image} at (0,0) size 100x200
+      RenderSVGContainer {g} at (25,0) size 100x100 [transform={m=((1.00,0.00)(0.00,1.00)) t=(-50.00,-100.00)}]
+        RenderPath {rect} at (50,0) size 50x100 [fill={[type=SOLID] [color=#FF0000]}] [data="M150.00,100.00L250.00,100.00L250.00,200.00L150.00,200.00"]
+        RenderImage {image} at (0,0) size 200x100
index adf3e14..7c5e6c7 100644 (file)
Binary files a/LayoutTests/platform/mac/svg/custom/pointer-events-image-expected.png and b/LayoutTests/platform/mac/svg/custom/pointer-events-image-expected.png differ
index 05ee3df..0b1a436 100644 (file)
Binary files a/LayoutTests/platform/mac/svg/custom/text-image-opacity-expected.png and b/LayoutTests/platform/mac/svg/custom/text-image-opacity-expected.png differ
diff --git a/LayoutTests/svg/custom/image-with-aspect-ratio-stretch.svg b/LayoutTests/svg/custom/image-with-aspect-ratio-stretch.svg
new file mode 100644 (file)
index 0000000..bf16b73
--- /dev/null
@@ -0,0 +1,17 @@
+<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1">
+    <!-- This test ensures that we paint images to the correct location when
+         it has been transformed to retain aspect ratio.
+         
+         It should produce a single 100x100 green square.
+     -->
+    <g transform="scale(0.5, 1)">
+        <g transform="translate(-100, -150)">
+            <rect x="100" y="150" width="100" height="100" fill="red"/>
+            <image x="100" y="100" width="100" height="200" xlink:href="../../css2.1/support/swatch-green.png" />
+        </g>
+        <g transform="translate(-50, -100)">
+            <rect x="150" y="100" width="100" height="100" fill="red"/>
+            <image x="100" y="100" width="200" height="100" xlink:href="../../css2.1/support/swatch-green.png" />
+        </g>
+    </g>
+</svg>
index ba7fb9a..2611ffa 100644 (file)
@@ -1,3 +1,14 @@
+2008-01-07  Oliver Hunt  <oliver@apple.com>
+
+        Reviewed by Niko.
+
+        Fix painting of SVG <image> when the image must be scaled to retain aspect ratio
+
+        Test: svg/custom/image-with-aspect-ratio-stretch.svg
+
+        * rendering/RenderSVGImage.cpp:
+        (WebCore::RenderSVGImage::adjustRectsForAspectRatio):
+
 2008-01-07  Dan Bernstein  <mitz@apple.com>
 
         Build fix.
index 4986bbe..5f96897 100644 (file)
@@ -62,12 +62,12 @@ void RenderSVGImage::adjustRectsForAspectRatio(FloatRect& destRect, FloatRect& s
                 case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMINYMID:
                 case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMIDYMID:
                 case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMAXYMID:
-                    destRect.setY(origDestHeight / 2.0f - destRect.height() / 2.0f);
+                    destRect.setY(destRect.y() + origDestHeight / 2.0f - destRect.height() / 2.0f);
                     break;
                 case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMINYMAX:
                 case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMIDYMAX:
                 case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMAXYMAX:
-                    destRect.setY(origDestHeight - destRect.height());
+                    destRect.setY(destRect.y() + origDestHeight - destRect.height());
                     break;
             }
         }
@@ -77,12 +77,12 @@ void RenderSVGImage::adjustRectsForAspectRatio(FloatRect& destRect, FloatRect& s
                 case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMIDYMIN:
                 case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMIDYMID:
                 case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMIDYMAX:
-                    destRect.setX(origDestWidth / 2.0f - destRect.width() / 2.0f);
+                    destRect.setX(destRect.x() + origDestWidth / 2.0f - destRect.width() / 2.0f);
                     break;
                 case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMAXYMIN:
                 case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMAXYMID:
                 case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMAXYMAX:
-                    destRect.setX(origDestWidth - destRect.width());
+                    destRect.setX(destRect.x() + origDestWidth - destRect.width());
                     break;
             }
         }
@@ -96,12 +96,12 @@ void RenderSVGImage::adjustRectsForAspectRatio(FloatRect& destRect, FloatRect& s
                 case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMINYMID:
                 case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMIDYMID:
                 case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMAXYMID:
-                    srcRect.setY(image()->height() / 2.0f - srcRect.height() / 2.0f);
+                    srcRect.setY(destRect.y() + image()->height() / 2.0f - srcRect.height() / 2.0f);
                     break;
                 case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMINYMAX:
                 case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMIDYMAX:
                 case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMAXYMAX:
-                    srcRect.setY(image()->height() - srcRect.height());
+                    srcRect.setY(destRect.y() + image()->height() - srcRect.height());
                     break;
             }
         }
@@ -113,12 +113,12 @@ void RenderSVGImage::adjustRectsForAspectRatio(FloatRect& destRect, FloatRect& s
                 case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMIDYMIN:
                 case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMIDYMID:
                 case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMIDYMAX:
-                    srcRect.setX(image()->width() / 2.0f - srcRect.width() / 2.0f);
+                    srcRect.setX(destRect.x() + image()->width() / 2.0f - srcRect.width() / 2.0f);
                     break;
                 case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMAXYMIN:
                 case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMAXYMID:
                 case SVGPreserveAspectRatio::SVG_PRESERVEASPECTRATIO_XMAXYMAX:
-                    srcRect.setX(image()->width() - srcRect.width());
+                    srcRect.setX(destRect.x() + image()->width() - srcRect.width());
                     break;
             }
         }