LCOV - code coverage report
Current view: top level - svgio/source/svgreader - svgellipsenode.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 51 53 96.2 %
Date: 2014-04-11 Functions: 6 6 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <svgio/svgreader/svgellipsenode.hxx>
      21             : #include <basegfx/polygon/b2dpolygon.hxx>
      22             : #include <basegfx/polygon/b2dpolygontools.hxx>
      23             : 
      24             : 
      25             : 
      26             : namespace svgio
      27             : {
      28             :     namespace svgreader
      29             :     {
      30          66 :         SvgEllipseNode::SvgEllipseNode(
      31             :             SvgDocument& rDocument,
      32             :             SvgNode* pParent)
      33             :         :   SvgNode(SVGTokenEllipse, rDocument, pParent),
      34             :             maSvgStyleAttributes(*this),
      35             :             maCx(0),
      36             :             maCy(0),
      37             :             maRx(0),
      38             :             maRy(0),
      39          66 :             mpaTransform(0)
      40             :         {
      41          66 :         }
      42             : 
      43         198 :         SvgEllipseNode::~SvgEllipseNode()
      44             :         {
      45          66 :             if(mpaTransform) delete mpaTransform;
      46         132 :         }
      47             : 
      48          66 :         const SvgStyleAttributes* SvgEllipseNode::getSvgStyleAttributes() const
      49             :         {
      50          66 :             return checkForCssStyle(OUString("ellipse"), maSvgStyleAttributes);
      51             :         }
      52             : 
      53         511 :         void SvgEllipseNode::parseAttribute(const OUString& rTokenName, SVGToken aSVGToken, const OUString& aContent)
      54             :         {
      55             :             // call parent
      56         511 :             SvgNode::parseAttribute(rTokenName, aSVGToken, aContent);
      57             : 
      58             :             // read style attributes
      59         511 :             maSvgStyleAttributes.parseStyleAttribute(rTokenName, aSVGToken, aContent);
      60             : 
      61             :             // parse own
      62         511 :             switch(aSVGToken)
      63             :             {
      64             :                 case SVGTokenStyle:
      65             :                 {
      66           0 :                     maSvgStyleAttributes.readStyle(aContent);
      67           0 :                     break;
      68             :                 }
      69             :                 case SVGTokenCx:
      70             :                 {
      71          66 :                     SvgNumber aNum;
      72             : 
      73          66 :                     if(readSingleNumber(aContent, aNum))
      74             :                     {
      75          66 :                         setCx(aNum);
      76             :                     }
      77          66 :                     break;
      78             :                 }
      79             :                 case SVGTokenCy:
      80             :                 {
      81          66 :                     SvgNumber aNum;
      82             : 
      83          66 :                     if(readSingleNumber(aContent, aNum))
      84             :                     {
      85          66 :                         setCy(aNum);
      86             :                     }
      87          66 :                     break;
      88             :                 }
      89             :                 case SVGTokenRx:
      90             :                 {
      91          66 :                     SvgNumber aNum;
      92             : 
      93          66 :                     if(readSingleNumber(aContent, aNum))
      94             :                     {
      95          66 :                         if(aNum.isPositive())
      96             :                         {
      97          66 :                             setRx(aNum);
      98             :                         }
      99             :                     }
     100          66 :                     break;
     101             :                 }
     102             :                 case SVGTokenRy:
     103             :                 {
     104          66 :                     SvgNumber aNum;
     105             : 
     106          66 :                     if(readSingleNumber(aContent, aNum))
     107             :                     {
     108          66 :                         if(aNum.isPositive())
     109             :                         {
     110          66 :                             setRy(aNum);
     111             :                         }
     112             :                     }
     113          66 :                     break;
     114             :                 }
     115             :                 case SVGTokenTransform:
     116             :                 {
     117          51 :                     const basegfx::B2DHomMatrix aMatrix(readTransform(aContent, *this));
     118             : 
     119          51 :                     if(!aMatrix.isIdentity())
     120             :                     {
     121          51 :                         setTransform(&aMatrix);
     122             :                     }
     123          51 :                     break;
     124             :                 }
     125             :                 default:
     126             :                 {
     127         196 :                     break;
     128             :                 }
     129             :             }
     130         511 :         }
     131             : 
     132          66 :         void SvgEllipseNode::decomposeSvgNode(drawinglayer::primitive2d::Primitive2DSequence& rTarget, bool /*bReferenced*/) const
     133             :         {
     134          66 :             const SvgStyleAttributes* pStyle = getSvgStyleAttributes();
     135             : 
     136          66 :             if(pStyle && getRx().isSet() && getRy().isSet())
     137             :             {
     138          66 :                 const double fRx(getRx().solve(*this, xcoordinate));
     139          66 :                 const double fRy(getRy().solve(*this, ycoordinate));
     140             : 
     141          66 :                 if(fRx > 0.0 && fRy > 0.0)
     142             :                 {
     143             :                     const basegfx::B2DPolygon aPath(
     144             :                         basegfx::tools::createPolygonFromEllipse(
     145             :                             basegfx::B2DPoint(
     146         132 :                                 getCx().isSet() ? getCx().solve(*this, xcoordinate) : 0.0,
     147         132 :                                 getCy().isSet() ? getCy().solve(*this, ycoordinate) : 0.0),
     148         264 :                             fRx, fRy));
     149             : 
     150         132 :                     drawinglayer::primitive2d::Primitive2DSequence aNewTarget;
     151             : 
     152          66 :                     pStyle->add_path(basegfx::B2DPolyPolygon(aPath), aNewTarget, 0);
     153             : 
     154          66 :                     if(aNewTarget.hasElements())
     155             :                     {
     156          66 :                         pStyle->add_postProcess(rTarget, aNewTarget, getTransform());
     157          66 :                     }
     158             :                 }
     159             :             }
     160          66 :         }
     161             :     } // end of namespace svgreader
     162             : } // end of namespace svgio
     163             : 
     164             : 
     165             : // eof
     166             : 
     167             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10