2006-02-11 Alexander Kellett <lypanov@kde.org>
authoreseidel <eseidel@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 12 Feb 2006 00:51:37 +0000 (00:51 +0000)
committereseidel <eseidel@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 12 Feb 2006 00:51:37 +0000 (00:51 +0000)
        Reviewed by eseidel.

        - Fixing http://bugzilla.opendarwin.org/show_bug.cgi?id=6942
          Implement support for "em" and "ex" relative lengths.

        - Layout tests changes:
            Fixed: svg/W3C-SVG-1.1/coords-units-03-b.svg
            New:   svg/custom/coords-relative-units-transforms.svg

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

19 files changed:
LayoutTests/ChangeLog
LayoutTests/svg/W3C-SVG-1.1/coords-units-03-b-expected.checksum
LayoutTests/svg/W3C-SVG-1.1/coords-units-03-b-expected.png
LayoutTests/svg/W3C-SVG-1.1/coords-units-03-b-expected.txt
LayoutTests/svg/W3C-SVG-1.1/coords-viewattr-02-b-expected.checksum
LayoutTests/svg/W3C-SVG-1.1/coords-viewattr-02-b-expected.png
LayoutTests/svg/W3C-SVG-1.1/filters-composite-02-b-expected.checksum
LayoutTests/svg/W3C-SVG-1.1/filters-composite-02-b-expected.png
LayoutTests/svg/W3C-SVG-1.1/filters-displace-01-f-expected.checksum
LayoutTests/svg/W3C-SVG-1.1/filters-displace-01-f-expected.png
LayoutTests/svg/W3C-SVG-1.1/filters-image-01-b-expected.checksum
LayoutTests/svg/W3C-SVG-1.1/filters-image-01-b-expected.png
LayoutTests/svg/custom/coords-relative-units-transforms-expected.checksum [new file with mode: 0644]
LayoutTests/svg/custom/coords-relative-units-transforms-expected.png [new file with mode: 0644]
LayoutTests/svg/custom/coords-relative-units-transforms-expected.txt [new file with mode: 0644]
LayoutTests/svg/custom/coords-relative-units-transforms.svg [new file with mode: 0644]
WebCore/ChangeLog
WebCore/ksvg2/svg/SVGLengthImpl.cpp
WebCore/ksvg2/svg/SVGLengthImpl.h

index 1e4ef6274f2643cc01f322f526b05075a48fcae6..3664504958c9f3c617ad5d6856811ca694376ede 100644 (file)
@@ -1,3 +1,11 @@
+2006-02-11  Alexander Kellett  <lypanov@kde.org>
+
+        Adding test case for
+
+        http://bugzilla.opendarwin.org/show_bug.cgi?id=5360
+
+        * svg/custom/coords-relative-units-transforms.svg: Added.
+
 2006-02-11  Alexey Proskuryakov  <ap@nypop.com>
 
         Reviewed by Darin.
index d05dfd09195c929e10119cac711a73854d039533..67a4a1fb51ee5a94e540da02b9aca77ff37a5716 100644 (file)
@@ -1 +1 @@
-6ea2114091241d3a1e574986dbfce171
\ No newline at end of file
+ad0f014e899b46bd1f956fd5ad57b21b
\ No newline at end of file
index 23f2781d6a6289f99ee0f4945a560ba68a447156..c738ae8dbe3d1bd4e4fb567369ca092c0ecbb526 100644 (file)
Binary files a/LayoutTests/svg/W3C-SVG-1.1/coords-units-03-b-expected.png and b/LayoutTests/svg/W3C-SVG-1.1/coords-units-03-b-expected.png differ
index 7c7a29dd76604d91ebe08557298e847125d1c37d..f0ca9831f64a7dd0672d20ad9458fd45272ac660 100644 (file)
@@ -29,16 +29,16 @@ layer at (0,0) size 480x360
           RenderSVGText {text} at (0,0) size 465x15
             RenderText {TEXT} at (0,0) size 136x15
               text run at (0,0) width 136: "Relative to font size (em)"
-          KCanvasContainer {g} at (0,60) size 0x0
-            KCanvasItem {rect} at (inf,inf) size 0x0 [fill={[type=SOLID] [color=#000000]}] [data=""]
+          KCanvasContainer {g} at (20,120) size 200x1
+            KCanvasItem {rect} at (20,120) size 200x1 [fill={[type=SOLID] [color=#000000]}] [data="M20.00,60.00L220.00,60.00L220.00,61.00L20.00,61.00"]
           RenderSVGText {text} at (0,0) size 465x15
             RenderText {TEXT} at (0,0) size 30x15
               text run at (0,0) width 30: "40 ex"
           RenderSVGText {text} at (0,0) size 465x15
             RenderText {TEXT} at (0,0) size 158x15
               text run at (0,0) width 158: "Relative to font x-height (ex)"
-          KCanvasContainer {g} at (0,60) size 0x0
-            KCanvasItem {rect} at (inf,inf) size 0x0 [fill={[type=SOLID] [color=#000000]}] [data=""]
+          KCanvasContainer {g} at (20,140) size 200x1
+            KCanvasItem {rect} at (20,140) size 200x1 [fill={[type=SOLID] [color=#000000]}] [data="M20.00,80.00L220.00,80.00L220.00,81.00L20.00,81.00"]
           RenderSVGText {text} at (0,0) size 465x15
             RenderText {TEXT} at (0,0) size 93x15
               text run at (0,0) width 93: "41.67% = 200 px"
index 4649eff01b2a9bfa67b601aac27ed7a507366ba8..a4a423bd0dc487fe408ee9971872b8fd822dc51f 100644 (file)
@@ -1 +1 @@
-54229441b75d2b2335567c7f780810e7
\ No newline at end of file
+32377a490808165b7bbc58a14fb0d7f8
\ No newline at end of file
index 69e836d6ef35af5c56d848856f9662f2c250ffc4..e590eb37a07a76766c6e2ae79b2f62a8ec354bda 100644 (file)
Binary files a/LayoutTests/svg/W3C-SVG-1.1/coords-viewattr-02-b-expected.png and b/LayoutTests/svg/W3C-SVG-1.1/coords-viewattr-02-b-expected.png differ
index c04bacaa4ee0d6f25fdec4d56153d64a926d8a8d..4346bd048c439a435e0faf8a0222233ffedb6cee 100644 (file)
@@ -1 +1 @@
-045d537ead570399e302b4bfa9fb7d1a
\ No newline at end of file
+849ef732548762d50ba82f256e7619f6
\ No newline at end of file
index d50c57e4a3cb372045e5ca21309473fe19974d9f..40b61052357d666518bd243fff81c52657f3df81 100644 (file)
Binary files a/LayoutTests/svg/W3C-SVG-1.1/filters-composite-02-b-expected.png and b/LayoutTests/svg/W3C-SVG-1.1/filters-composite-02-b-expected.png differ
index 54714a36d7364de6e5ceac262cf7553173a62f1e..0905796fa68890c961da0cb3329c40d5480a166e 100644 (file)
@@ -1 +1 @@
-10aae9bab31ed77a33002ea93e30908d
\ No newline at end of file
+8358f9bb800ec982bf0cad2861823a2a
\ No newline at end of file
index da0e72dd4e26f19db20d1a74b4b81de524dd652f..9f2b06afb1a4763c1a25b28e49a1782e84265e94 100644 (file)
Binary files a/LayoutTests/svg/W3C-SVG-1.1/filters-displace-01-f-expected.png and b/LayoutTests/svg/W3C-SVG-1.1/filters-displace-01-f-expected.png differ
index 2c154368597e27e68bb0139a7dcebecd639620d4..4994d217cd1f4afcdeca88302a5028ae760ec01c 100644 (file)
@@ -1 +1 @@
-2f71b43ef49aa710c0aa321fb6b91760
\ No newline at end of file
+104ab2aafe4997ef18a53fe441445232
\ No newline at end of file
index e6a888e362b7ea71cfe283d79ff88a0b2f5289d5..d61708a663050fc473f6632087ec1b0cde53018e 100644 (file)
Binary files a/LayoutTests/svg/W3C-SVG-1.1/filters-image-01-b-expected.png and b/LayoutTests/svg/W3C-SVG-1.1/filters-image-01-b-expected.png differ
diff --git a/LayoutTests/svg/custom/coords-relative-units-transforms-expected.checksum b/LayoutTests/svg/custom/coords-relative-units-transforms-expected.checksum
new file mode 100644 (file)
index 0000000..0eaac6d
--- /dev/null
@@ -0,0 +1 @@
+0d34a3ea924e1b9aa960400fea3daa91
\ No newline at end of file
diff --git a/LayoutTests/svg/custom/coords-relative-units-transforms-expected.png b/LayoutTests/svg/custom/coords-relative-units-transforms-expected.png
new file mode 100644 (file)
index 0000000..732970f
Binary files /dev/null and b/LayoutTests/svg/custom/coords-relative-units-transforms-expected.png differ
diff --git a/LayoutTests/svg/custom/coords-relative-units-transforms-expected.txt b/LayoutTests/svg/custom/coords-relative-units-transforms-expected.txt
new file mode 100644 (file)
index 0000000..41a6ea5
--- /dev/null
@@ -0,0 +1,30 @@
+layer at (0,0) size 800x600
+  RenderCanvas at (0,0) size 800x600
+    KCanvasContainer {svg} at (0,0) size 400x200
+      KCanvasItem {rect} at (0,0) size 400x200 [stroke={[type=SOLID] [color=#0000FF] [stroke width=10.00]}] [data="M5.00,5.00L3995.00,5.00L3995.00,1995.00L5.00,1995.00"]
+      KCanvasContainer {g} at (36.16,38.08) size 327.00x125.08
+        KCanvasContainer {g} at (36.16,38.08) size 79.68x121.76 [transform={m=((1.00,0.00)(0.00,1.00)) t=(400.00,0.00)}]
+          RenderSVGText {text} at (0,0) size 785x364
+            RenderText {TEXT} at (0,0) size 436x364
+              text run at (0,0) width 329: "Abs."
+              text run at (0,182) width 436: "units:"
+          KCanvasItem {rect} at (38.08,38.08) size 39.84x21.84 [stroke={[type=SOLID] [color=#FF0000] [stroke width=38.40]}] [fill={[type=SOLID] [color=#0000FF]}] [data="M0.00,400.00L360.00,400.00L360.00,580.00L0.00,580.00"]
+          KCanvasItem {rect} at (38.08,73.08) size 42.24x23.04 [stroke={[type=SOLID] [color=#FF0000] [stroke width=38.40]}] [fill={[type=SOLID] [color=#0000FF]}] [data="M0.00,750.00L384.00,750.00L384.00,942.00L0.00,942.00"]
+          KCanvasContainer {g} at (36.16,116.16) size 79.68x43.68 [transform={m=((2.00,0.00)(0.00,2.00)) t=(0.00,0.00)}]
+            KCanvasItem {rect} at (36.16,116.16) size 79.68x43.68 [stroke={[type=SOLID] [color=#FF0000] [stroke width=38.40]}] [fill={[type=SOLID] [color=#0000FF]}] [data="M0.00,600.00L360.00,600.00L360.00,780.00L0.00,780.00"]
+        KCanvasContainer {g} at (156.25,38.12) size 82.50x123.12 [transform={m=((1.00,0.00)(0.00,1.00)) t=(1600.00,0.00)}]
+          RenderSVGText {text} at (0,0) size 785x182
+            RenderText {TEXT} at (0,0) size 778x182
+              text run at (0,0) width 778: "Rel. units:"
+          KCanvasItem {rect} at (158.12,38.12) size 41.25x22.50 [stroke={[type=SOLID] [color=#FF0000] [stroke width=37.50]}] [fill={[type=SOLID] [color=#0000FF]}] [data="M0.00,400.00L375.00,400.00L375.00,587.50L0.00,587.50"]
+          KCanvasItem {rect} at (158.12,73.12) size 41.25x22.50 [stroke={[type=SOLID] [color=#FF0000] [stroke width=37.50]}] [fill={[type=SOLID] [color=#0000FF]}] [data="M0.00,750.00L375.00,750.00L375.00,937.50L0.00,937.50"]
+          KCanvasContainer {g} at (156.25,116.25) size 82.50x45 [transform={m=((2.00,0.00)(0.00,2.00)) t=(0.00,0.00)}]
+            KCanvasItem {rect} at (156.25,116.25) size 82.50x45 [stroke={[type=SOLID] [color=#FF0000] [stroke width=37.50]}] [fill={[type=SOLID] [color=#0000FF]}] [data="M0.00,600.00L375.00,600.00L375.00,787.50L0.00,787.50"]
+        KCanvasContainer {g} at (276.84,38.42) size 86.32x124.74 [transform={m=((1.00,0.00)(0.00,1.00)) t=(2800.00,0.00)}]
+          RenderSVGText {text} at (0,0) size 785x182
+            RenderText {TEXT} at (0,0) size 982x182
+              text run at (0,0) width 982: "Percentages:"
+          KCanvasItem {rect} at (278.42,38.42) size 43.16x23.16 [stroke={[type=SOLID] [color=#FF0000] [stroke width=31.62]}] [fill={[type=SOLID] [color=#0000FF]}] [data="M0.00,400.00L400.00,400.00L400.00,600.00L0.00,600.00"]
+          KCanvasItem {rect} at (278.42,73.42) size 43.16x23.16 [stroke={[type=SOLID] [color=#FF0000] [stroke width=31.62]}] [fill={[type=SOLID] [color=#0000FF]}] [data="M0.00,750.00L400.00,750.00L400.00,950.00L0.00,950.00"]
+          KCanvasContainer {g} at (276.84,116.84) size 86.32x46.32 [transform={m=((2.00,0.00)(0.00,2.00)) t=(0.00,0.00)}]
+            KCanvasItem {rect} at (276.84,116.84) size 86.32x46.32 [stroke={[type=SOLID] [color=#FF0000] [stroke width=31.62]}] [fill={[type=SOLID] [color=#0000FF]}] [data="M0.00,600.00L400.00,600.00L400.00,800.00L0.00,800.00"]
diff --git a/LayoutTests/svg/custom/coords-relative-units-transforms.svg b/LayoutTests/svg/custom/coords-relative-units-transforms.svg
new file mode 100644 (file)
index 0000000..4efb241
--- /dev/null
@@ -0,0 +1,45 @@
+<?xml version="1.0" standalone="no"?>
+<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" 
+  "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
+<svg width="400px" height="200px" viewBox="0 0 4000 2000"
+     xmlns="http://www.w3.org/2000/svg" version="1.1">
+  <title>Example Units</title>
+  <desc>Illustrates various units options</desc>
+
+  <!-- Frame the picture -->
+  <rect x="5" y="5" width="3990" height="1990" 
+        fill="none" stroke="blue" stroke-width="10"/>
+
+  <g fill="blue" stroke="red" font-family="Verdana" font-size="150">
+    <!-- Absolute unit specifiers -->
+    <g transform="translate(400,0)">
+      <text x="-50" y="300" fill="black" stroke="none">Abs. units:</text>
+      <rect x="0" y="400" width="4in" height="2in" stroke-width=".4in"/>
+      <rect x="0" y="750" width="384" height="192" stroke-width="38.4"/>
+      <g transform="scale(2)">
+        <rect x="0" y="600" width="4in" height="2in" stroke-width=".4in"/>
+      </g>
+    </g>
+
+    <!-- Relative unit specifiers -->
+    <g transform="translate(1600,0)">
+      <text x="-50" y="300" fill="black" stroke="none">Rel. units:</text>
+      <rect x="0" y="400" width="2.5em" height="1.25em" stroke-width=".25em"/>
+      <rect x="0" y="750" width="375" height="187.5" stroke-width="37.5"/>
+      <g transform="scale(2)">
+        <rect x="0" y="600" width="2.5em" height="1.25em" stroke-width=".25em"/>
+      </g>
+    </g>
+
+    <!-- Percentages -->
+    <g transform="translate(2800,0)">
+      <text x="-50" y="300" fill="black" stroke="none">Percentages:</text>
+      <rect x="0" y="400" width="10%" height="10%" stroke-width="1%"/>
+      <rect x="0" y="750" width="400" height="200" stroke-width="31.62"/>
+      <g transform="scale(2)">
+        <rect x="0" y="600" width="10%" height="10%" stroke-width="1%"/>
+      </g>
+    </g>
+  </g>
+</svg>
+
index 1577be0d5e1243820ffc3d1a33f7c672f46673f3..20902e7983552624f0e17f32dc23b063a881391f 100644 (file)
@@ -1,3 +1,21 @@
+2006-02-11  Alexander Kellett  <lypanov@kde.org>
+
+        Reviewed by eseidel.
+
+        - Fixing http://bugzilla.opendarwin.org/show_bug.cgi?id=6942
+          Implement support for "em" and "ex" relative lengths.
+
+        - Layout tests changes:
+            Fixed: svg/W3C-SVG-1.1/coords-units-03-b.svg
+            New:   svg/custom/coords-relative-units-transforms.svg
+
+        * ksvg2/svg/SVGLengthImpl.cpp:
+        (SVGLengthImpl::SVGLengthImpl):
+        (SVGLengthImpl::value):
+        (SVGLengthImpl::updateValue):
+        (SVGLengthImpl::updateValueInSpecifiedUnits):
+        * ksvg2/svg/SVGLengthImpl.h:
+
 2006-02-11  Darin Adler  <darin@apple.com>
 
         Rubber-stamped by Eric.
index 5266c06e7f4166d2383f4f679b9e61afca59fd8b..ebfac94bedd37e5d4a6c659b6fe183caac4eb5fa 100644 (file)
@@ -65,6 +65,8 @@ SVGLengthImpl::SVGLengthImpl(const SVGStyledElementImpl *context, LengthMode mod
 
     m_bboxRelative = false;
     m_unitType = SVG_LENGTHTYPE_UNKNOWN;
+    
+    m_requiresLayout = false;
 }
 
 SVGLengthImpl::~SVGLengthImpl()
@@ -84,6 +86,9 @@ void SVGLengthImpl::setValue(float value)
 
 float SVGLengthImpl::value() const
 {
+    if (m_requiresLayout)
+        const_cast<SVGLengthImpl*>(this)->updateValue(false);
+
     if(m_unitType != SVG_LENGTHTYPE_PERCENTAGE)
         return m_value;
 
@@ -186,7 +191,7 @@ double SVGLengthImpl::dpi() const
     return 90.0;
 }
 
-void SVGLengthImpl::updateValue()
+void SVGLengthImpl::updateValue(bool notify)
 {
     switch(m_unitType)
     {
@@ -208,59 +213,31 @@ void SVGLengthImpl::updateValue()
         case SVG_LENGTHTYPE_PC:
             m_value = (m_valueInSpecifiedUnits / 6.0) * dpi();
             break;
-        case SVG_LENGTHTYPE_EMS: // Be careful here, always recheck coords-units-BE-01.svg after touching (Niko)
+        case SVG_LENGTHTYPE_EMS:
         case SVG_LENGTHTYPE_EXS:
-            if(m_context)
-            {
-                /* FIXME: EMS/EXS handling
-                KCanvasRenderingStyle *style = context->style();
-                KCFontProperties *fontProperites = style->fontProperties();
-
-                bool sizeLocal = (style->getFontSize() != -1);
-                bool familyLocal = (style->getFontFamily() && style->getFontFamily()->getFirst());
-                
-                SVGStylableImpl *parentStyle = 0;
-                if((!sizeLocal || !familyLocal) && context) {
-                    parentStyle = dynamic_cast<SVGStylableImpl *>(context->ownerDoc()->getElementFromHandle(context->parentNode().handle()));
-                
-                // Look up font-size in a SAFE way, because at this place
-                // processStyle() has NOT yet been called, so we need
-                // a different solution (Niko)
-                QString useFont = "Arial";
-                double useSize = 12;
-                
-                if(sizeLocal)
-                    useSize = style->getFontSize();
-                else if(parentStyle && parentStyle->getFontSize() != -1)
-                    useSize = parentStyle->getFontSize();
-            
-                if(familyLocal)
-                    useFont = style->getFontFamily()->getFirst()->qstring();
-                else if(parentStyle && parentStyle->getFontFamily() && parentStyle->getFontFamily()->getFirst())
-                    useFont = parentStyle->getFontFamily()->getFirst()->qstring();
-
-                if(unitType == SVG_LENGTHTYPE_EMS)
-                    value = valueInSpecifiedUnits * useSize;
-                else
-                {
-                    // Easiest way, use qfont (Niko)
-                    QFont font(useFont);
-                    font.setPixelSize(static_cast<int>(useSize));
-
-                    QFontMetrics fm(font);
-                    value = valueInSpecifiedUnits * fm.boundingRect('x').height();
+            if (m_context && m_context->renderer()) {
+                khtml::RenderStyle *style = m_context->renderer()->style();
+                float useSize = style->font().pixelSize();
+                ASSERT(useSize > 0);
+                if (m_unitType == SVG_LENGTHTYPE_EMS)
+                    m_value = m_valueInSpecifiedUnits * useSize;
+                else {
+                    float xHeight = style->fontMetrics().xHeight();
+                    // Use of ceil allows a pixel match to the W3Cs expected output of coords-units-03-b.svg
+                    // if this causes problems in real world cases maybe it would be best to remove this
+                    m_value = m_valueInSpecifiedUnits * ceil(xHeight);
                 }
+                m_requiresLayout = false;
+            } else {
+                m_requiresLayout = true;
             }
-
-            break;*/
-        }
+            break;
     }
-
-    if(m_context)
+    if (notify && m_context)
         m_context->notifyAttributeChange();
 }
 
-bool SVGLengthImpl::updateValueInSpecifiedUnits()
+bool SVGLengthImpl::updateValueInSpecifiedUnits(bool notify)
 {
     if(m_unitType == SVG_LENGTHTYPE_UNKNOWN)
         return false;
@@ -296,7 +273,7 @@ bool SVGLengthImpl::updateValueInSpecifiedUnits()
             break;
     };
     
-    if(m_context)
+    if (notify && m_context)
         m_context->notifyAttributeChange();
 
     return true;
index 36826553edb7c0d64285300e13e8b63e5a451e7b..5e2763bb5b72b2e95029ea952ec74980c3867967 100644 (file)
@@ -64,8 +64,8 @@ namespace WebCore
         void setContext(const SVGStyledElementImpl *context);
 
     private:
-        bool updateValueInSpecifiedUnits();
-        void updateValue();
+        bool updateValueInSpecifiedUnits(bool notify = true);
+        void updateValue(bool notify = true);
 
         double dpi() const;
 
@@ -75,6 +75,7 @@ namespace WebCore
         LengthMode m_mode : 2;
         bool m_bboxRelative : 1;
         unsigned short m_unitType : 4;
+        bool m_requiresLayout : 1;
 
         const SVGStyledElementImpl *m_context;
         const SVGElementImpl *m_viewportElement;