Date: prev next · Thread: first prev next last
2012 Archives by date, by thread · List index


Hi,

if the corner radii-patch is fine, this patch moves the translation of rectangle attributes into a polygon into a helper method. Works fine here, but a short review would be nice.

@Thorsten: The method importSVG which calls the ShapeRenderingVisitor is used for magic file type detection?

Christina
From 12ab1277f1bc16cee0f8ec378ac3a4293bec1040 Mon Sep 17 00:00:00 2001
From: "Chr. Rossmanith" <Chr.Rossmanith@gmx.de>
Date: Sat, 28 Apr 2012 20:20:54 +0200
Subject: [PATCH] Move polygon creation from rect attrs into helper method

---
 filter/source/svg/svgreader.cxx |  144 ++++++++++++++-------------------------
 1 file changed, 52 insertions(+), 92 deletions(-)

diff --git a/filter/source/svg/svgreader.cxx b/filter/source/svg/svgreader.cxx
index 23794a7..357c732 100644
--- a/filter/source/svg/svgreader.cxx
+++ b/filter/source/svg/svgreader.cxx
@@ -75,6 +75,56 @@ namespace svgi
 namespace
 {
 
+void lcl_RectAttrs2Polygon( const uno::Reference<xml::dom::XNamedNodeMap>& xAttributes, const 
State& rCurrState, basegfx::B2DPolygon& rPoly )
+{
+    // collect attributes
+    const sal_Int32 nNumAttrs( xAttributes->getLength() );
+    rtl::OUString sAttributeValue;
+    bool bRxSeen=false, bRySeen=false;
+    double x=0.0,y=0.0,width=0.0,height=0.0,rx=0.0,ry=0.0;
+    for( sal_Int32 i=0; i<nNumAttrs; ++i )
+    {
+        sAttributeValue = xAttributes->item(i)->getNodeValue();
+        const sal_Int32 nAttribId(
+                                  getTokenId(xAttributes->item(i)->getNodeName()));
+        switch(nAttribId)
+        {
+        case XML_X:
+            x = convLength(sAttributeValue,rCurrState,'h');
+            break;
+        case XML_Y:
+            y = convLength(sAttributeValue,rCurrState,'v');
+            break;
+        case XML_WIDTH:
+            width = convLength(sAttributeValue,rCurrState,'h');
+            break;
+        case XML_HEIGHT:
+            height = convLength(sAttributeValue,rCurrState,'v');
+            break;
+        case XML_RX:
+            rx = convLength(sAttributeValue,rCurrState,'h');
+            bRxSeen=true;
+            break;
+        case XML_RY:
+            ry = convLength(sAttributeValue,rCurrState,'v');
+            bRySeen=true;
+            break;
+        default:
+            // skip
+            break;
+        }
+    }
+
+    if( bRxSeen && !bRySeen )
+        ry = rx;
+    else if( bRySeen && !bRxSeen )
+        rx = ry;
+
+    rPoly = basegfx::tools::createPolygonFromRect(
+                    basegfx::B2DRange(x,y,x+width,y+height),
+                    rx/(0.5*width), ry/(0.5*height) );
+}
+
 /** visits all children of the specified type with the given functor
  */
 template<typename Func> void visitChildren(const Func& rFunc,
@@ -1289,54 +1339,9 @@ struct ShapeWritingVisitor
             }
             case XML_RECT:
             {
-                // collect attributes
-                const sal_Int32 nNumAttrs( xAttributes->getLength() );
-                rtl::OUString sAttributeValue;
-                bool bRxSeen=false, bRySeen=false;
-                double x=0.0,y=0.0,width=0.0,height=0.0,rx=0.0,ry=0.0;
-                for( sal_Int32 i=0; i<nNumAttrs; ++i )
-                {
-                    sAttributeValue = xAttributes->item(i)->getNodeValue();
-                    const sal_Int32 nAttribId(
-                        getTokenId(xAttributes->item(i)->getNodeName()));
-                    switch(nAttribId)
-                    {
-                        case XML_X:
-                            x = convLength(sAttributeValue,maCurrState,'h');
-                            break;
-                        case XML_Y:
-                            y = convLength(sAttributeValue,maCurrState,'v');
-                            break;
-                        case XML_WIDTH:
-                            width = convLength(sAttributeValue,maCurrState,'h');
-                            break;
-                        case XML_HEIGHT:
-                            height = convLength(sAttributeValue,maCurrState,'v');
-                            break;
-                        case XML_RX:
-                            rx = convLength(sAttributeValue,maCurrState,'h');
-                            bRxSeen=true;
-                            break;
-                        case XML_RY:
-                            ry = convLength(sAttributeValue,maCurrState,'v');
-                            bRySeen=true;
-                            break;
-                        default:
-                            // skip
-                            break;
-                    }
-                }
-
-                if( bRxSeen && !bRySeen )
-                    ry = rx;
-                else if( bRySeen && !bRxSeen )
-                    rx = ry;
-
                 basegfx::B2DPolygon aPoly;
-                aPoly = basegfx::tools::createPolygonFromRect(
-                    basegfx::B2DRange(x,y,x+width,y+height),
-                    rx/(0.5*width), ry/(0.5*height) );
 
+                lcl_RectAttrs2Polygon( xAttributes, maCurrState, aPoly );
                 writePathShape(xAttrs,
                                xUnoAttrs,
                                xElem,
@@ -2133,54 +2138,9 @@ struct ShapeRenderingVisitor
             }
             case XML_RECT:
             {
-                // collect attributes
-                const sal_Int32 nNumAttrs( xAttributes->getLength() );
-                rtl::OUString sAttributeValue;
-                bool bRxSeen=false, bRySeen=false;
-                double x=0.0,y=0.0,width=0.0,height=0.0,rx=0.0,ry=0.0;
-                for( sal_Int32 i=0; i<nNumAttrs; ++i )
-                {
-                    sAttributeValue = xAttributes->item(i)->getNodeValue();
-                    const sal_Int32 nAttribId(
-                        getTokenId(xAttributes->item(i)->getNodeName()));
-                    switch(nAttribId)
-                    {
-                        case XML_X:
-                            x = convLength(sAttributeValue,maCurrState,'h');
-                            break;
-                        case XML_Y:
-                            y = convLength(sAttributeValue,maCurrState,'v');
-                            break;
-                        case XML_WIDTH:
-                            width = convLength(sAttributeValue,maCurrState,'h');
-                            break;
-                        case XML_HEIGHT:
-                            height = convLength(sAttributeValue,maCurrState,'v');
-                            break;
-                        case XML_RX:
-                            rx = convLength(sAttributeValue,maCurrState,'h');
-                            bRxSeen=true;
-                            break;
-                        case XML_RY:
-                            ry = convLength(sAttributeValue,maCurrState,'v');
-                            bRySeen=true;
-                            break;
-                        default:
-                            // skip
-                            break;
-                    }
-                }
-
-                if( bRxSeen && !bRySeen )
-                    ry = rx;
-                else if( bRySeen && !bRxSeen )
-                    rx = ry;
-
                 basegfx::B2DPolygon aPoly;
-                aPoly = basegfx::tools::createPolygonFromRect(
-                    basegfx::B2DRange(x,y,x+width,y+height),
-                    rx/(0.5*width), ry/(0.5*height) );
 
+                lcl_RectAttrs2Polygon( xAttributes, maCurrState, aPoly );
                 renderPathShape(basegfx::B2DPolyPolygon(aPoly));
                 break;
             }
-- 
1.7.9.5


Context


Privacy Policy | Impressum (Legal Info) | Copyright information: Unless otherwise specified, all text and images on this website are licensed under the Creative Commons Attribution-Share Alike 3.0 License. This does not include the source code of LibreOffice, which is licensed under the Mozilla Public License (MPLv2). "LibreOffice" and "The Document Foundation" are registered trademarks of their corresponding registered owners or are in actual use as trademarks in one or more countries. Their respective logos and icons are also subject to international copyright laws. Use thereof is explained in our trademark policy.