[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    branches/work/khtml-svg/svg
From:       Nikolas Zimmermann <wildfox () kde ! org>
Date:       2006-03-30 13:47:38
Message-ID: 1143726458.169934.30553.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 524406 by wildfox:

Fixing ems/exs length support & SVGHelper::PercentageOfViewport


 M  +21 -12    SVGHelper.cpp  
 M  +1 -1      SVGHelper.h  
 M  +19 -11    SVGLengthImpl.cpp  


--- branches/work/khtml-svg/svg/SVGHelper.cpp #524405:524406
@@ -20,24 +20,33 @@
     Boston, MA 02111-1307, USA.
 */
 
+#include <math.h>
+
 #include <QStringList>
 
+#include "khtmlview.h"
+#include "misc/hashes.h"
+#include "xml/dom_docimpl.h"
+#include "rendering/render_canvas.h"
+
 #include "SVGHelper.h"
+#include "SVGSVGElementImpl.h"
 #include "SVGStringListImpl.h"
+#include "SVGAnimatedRectImpl.h"
+#include "SVGAnimatedLengthImpl.h"
 
 using namespace KSVG;
 
-float SVGHelper::PercentageOfViewport(float value, const SVGElementImpl \
*viewportElement, LengthMode mode) +float SVGHelper::PercentageOfViewport(float \
value, SVGElementImpl *viewportElement, LengthMode mode)  {
-/* FIXME
     float width = 0, height = 0;
     if(!viewportElement)
         return 0.0;
- 
-    if(viewportElement && viewportElement->hasTagName(SVGNames::svgTag))
+
+    if(viewportElement && viewportElement->id() == SVGID_SVG)
     {
-        const SVGSVGElementImpl *svg = static_cast<const SVGSVGElementImpl \
                *>(viewportElement);
-        if(svg->hasAttribute(SVGNames::viewBoxAttr))
+        SVGSVGElementImpl *svg = static_cast<SVGSVGElementImpl *>(viewportElement);
+        if(!svg->getAttribute(SVGATTR_VIEWBOX).isNull())
         {
             width = svg->viewBox()->baseVal()->width();
             height = svg->viewBox()->baseVal()->height();
@@ -47,15 +56,15 @@
         {
             // TODO: Shouldn't w/h be multiplied with the percentage values?!
             // AFAIK, this assumes width & height == 100%, Rob??
-            SVGDocumentImpl *doc = static_cast<SVGDocumentImpl \
                *>(svg->ownerDocument());
-            if(doc && doc->rootElement() == svg)
+            DOM::DocumentImpl *doc = svg->getDocument();
+            if(doc->documentElement() == svg)
             {
                 // We have to ask the canvas for the full "canvas size"...
-                KCanvas *canvas = doc->canvas();
+                khtml::RenderCanvas *canvas = static_cast<khtml::RenderCanvas \
*>(doc->renderer());  if(canvas)
                 {
-                    width = canvas->canvasSize().width(); // TODO: recheck!
-                    height = canvas->canvasSize().height(); // TODO: recheck!
+                    width = canvas->view()->visibleWidth(); // TODO: recheck!
+                    height = canvas->view()->visibleHeight(); // TODO: recheck!
                 }
             }
         }
@@ -72,7 +81,7 @@
         return value * height;
     else if(mode == LM_OTHER)
         return value * sqrt(pow(double(width), 2) + pow(double(height), 2)) / \
                sqrt(2.0);
-*/
+
     return 0.0;
 }
 
--- branches/work/khtml-svg/svg/SVGHelper.h #524405:524406
@@ -43,7 +43,7 @@
     class SVGHelper
     {
     public:
-        static float PercentageOfViewport(float value, const SVGElementImpl \
*viewportElement, LengthMode mode); +        static float PercentageOfViewport(float \
                value, SVGElementImpl *viewportElement, LengthMode mode);
         static void ParseSeperatedList(SVGStringListImpl *list, const QString &data, \
const QChar &delimiter = ',');  };
 
--- branches/work/khtml-svg/svg/SVGLengthImpl.cpp #524405:524406
@@ -20,6 +20,10 @@
     Boston, MA 02111-1307, USA.
 */
 
+#include <math.h>
+
+#include "rendering/render_object.h"
+
 #include "svgpathparser.h"
 #include "SVGLengthImpl.h"
 #include "SVGStyledElementImpl.h"
@@ -95,7 +99,7 @@
         return result;
     }
 */
-    return SVGHelper::PercentageOfViewport(value, m_viewportElement, m_mode);
+    return SVGHelper::PercentageOfViewport(value, const_cast<SVGElementImpl \
*>(m_viewportElement), m_mode);  }
 
 void SVGLengthImpl::setValueInSpecifiedUnits(float valueInSpecifiedUnits, int &)
@@ -115,7 +119,7 @@
         return;
 
     QString valueAsQString = valueAsString.string();
-	QByteArray latinQString = valueAsQString.toLatin1();
+    QByteArray latinQString = valueAsQString.toLatin1();
 
     double convertedNumber = 0;
     const char *start = latinQString.constData();
@@ -213,22 +217,26 @@
             break;
         case SVG_LENGTHTYPE_EMS: // Be careful here, always recheck \
coords-units-BE-01.svg after touching (Niko)  case SVG_LENGTHTYPE_EXS:
-            if(m_context)
+            if(m_context && m_context->renderer())
             {
-                /* FIXME: EMS/EXS handling
-                KDOM::RenderStyle *style = m_context->renderStyle();
+                khtml::RenderStyle *style = m_context->renderer()->style();
+
                 float useSize = style->font().pixelSize();
-				if(useSize == -1)
-				    useSize = (style->font().pointSizeF() / 72.0) * dpi();
+                if(useSize <= 0)
+                    useSize = (style->font().pointSizeF() / 72.0) * dpi();
 
+                Q_ASSERT(useSize > 0);
+
                 if(m_unitType == SVG_LENGTHTYPE_EMS)
                     m_value = m_valueInSpecifiedUnits * useSize;
-					//kdDebug() << "EMS :" << m_valueInSpecifiedUnits << " * " << useSize << endl;
                 else
                 {
-                    QFontMetrics fm = style->fontMetrics();
-                    m_value = m_valueInSpecifiedUnits * \
                fm.boundingRect('x').height();
-                }*/
+                    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); +                }
             }
 
             break;


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic