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 39b4e8d07859469df2e0879fa14d6fa38e0b1b29..1943615eca8db98cce2b65cabb9e6f2489f4703f 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 c9db23791ddc2e926d8adec80f7f71bc4449e045..947540b4ed4f8a1328f3e184363d450f003f7e3d 100644 (file)
@@ -1 +1 @@
-e1783af530b356977497837722a95a0e
\ No newline at end of file
+83ed5a8f6ae28310d94d197d1e82ecef
\ No newline at end of file
index 97c29b4e91f07816fc69bad147f8627c8921a26c..f8deb85de879f62cf026b069eda2e3bb912e8eaf 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 534fbddc2a410bedfd7f248e53db6f3e0324c9ce..37c5835c4baf77999206fac55a7576fe947bff12 100644 (file)
@@ -1 +1 @@
-52530c496fc5550095fe5eb428595df8
\ No newline at end of file
+19ca7a299ece087d3d9782f641652240
\ No newline at end of file
index f03ef6dafe8e2834031663fc8138e8a3a97c84df..098da88a7e55daadb0d5a2e239da2e87193cb480 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 c5ca047847cf522634a244d8c4c3c4829080df9d..8ddaaffc1db6793fb59e4fafde436965169ad81e 100644 (file)
@@ -1 +1 @@
-09388fee065b1ed2bea2762f7ed7dcb8
\ No newline at end of file
+8a63242a32fbd516b0d7d7124efa3548
\ No newline at end of file
index 952f7e81d2db10fa9ab10eb14d6e58bdd880829e..367286dc72a2e9117aa704d77e5391e5d84e38a5 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 f1e9a6b587b6eb746f9af649d2573dc777ac4a5a..5ae9d233a90b27ecb20a38ea417dc995b09979a8 100644 (file)
@@ -1 +1 @@
-4681dbe7afbb864b9930da6244f15e31
\ No newline at end of file
+234fe3566725585d6673af65d431e555
\ No newline at end of file
index be888e947f3cbc4079dbbd0c2ea760b0010d38dc..6e909089b7cd6a883b064c7fb4bb3a879a3575b8 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 8f7e8f9a391ce4b622c226bfd6a446d079283ad6..6b38127fc118ac56f294731fd71b70c8a53aa1c7 100644 (file)
@@ -1 +1 @@
-fa60af67b4cd9482bd210125d716a1e9
\ No newline at end of file
+354860e44e650ede47e6fb95dc92b509
\ No newline at end of file
index adf3e148d89e0c13278671846cca362a1abf60be..7c5e6c72d74d38495cb36e7b99d913efc8e07257 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 8285a2f1146c7bdd3f68238d7208cb4ee868a323..294258263102820957b595d1404a6fb187af05f8 100644 (file)
@@ -1 +1 @@
-e7ff9007e77ef0be3f36e366c45c47fc
\ No newline at end of file
+b85a20eaadd1e441ec9dc875b132edeb
\ No newline at end of file
index 05ee3df6e81d9e04c9f17cba720b06ccbc7230f2..0b1a43674adcc448706ee2b823783ecff5ad040d 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 ba7fb9a3f7479552376e71a87f33406d5059c711..2611ffa935e8ca1427e12f7205a898ee2075a5e6 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 4986bbe374b1e793c7e3de8475e9ac74a0f1e086..5f96897a8de9d0ab1d9c435cdb035e8b4e5d5026 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;
             }
         }