LCOV - code coverage report
Current view: top level - svgio/source/svgreader - svgcirclenode.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 43 47 91.5 %
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/svgcirclenode.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         208 :         SvgCircleNode::SvgCircleNode(
      31             :             SvgDocument& rDocument,
      32             :             SvgNode* pParent)
      33             :         :   SvgNode(SVGTokenCircle, rDocument, pParent),
      34             :             maSvgStyleAttributes(*this),
      35             :             maCx(0),
      36             :             maCy(0),
      37             :             maR(0),
      38         208 :             mpaTransform(0)
      39             :         {
      40         208 :         }
      41             : 
      42         624 :         SvgCircleNode::~SvgCircleNode()
      43             :         {
      44         208 :             if(mpaTransform) delete mpaTransform;
      45         416 :         }
      46             : 
      47         278 :         const SvgStyleAttributes* SvgCircleNode::getSvgStyleAttributes() const
      48             :         {
      49         278 :             return checkForCssStyle(OUString("circle"), maSvgStyleAttributes);
      50             :         }
      51             : 
      52        1021 :         void SvgCircleNode::parseAttribute(const OUString& rTokenName, SVGToken aSVGToken, const OUString& aContent)
      53             :         {
      54             :             // call parent
      55        1021 :             SvgNode::parseAttribute(rTokenName, aSVGToken, aContent);
      56             : 
      57             :             // read style attributes
      58        1021 :             maSvgStyleAttributes.parseStyleAttribute(rTokenName, aSVGToken, aContent);
      59             : 
      60             :             // parse own
      61        1021 :             switch(aSVGToken)
      62             :             {
      63             :                 case SVGTokenStyle:
      64             :                 {
      65           6 :                     maSvgStyleAttributes.readStyle(aContent);
      66           6 :                     break;
      67             :                 }
      68             :                 case SVGTokenCx:
      69             :                 {
      70         208 :                     SvgNumber aNum;
      71             : 
      72         208 :                     if(readSingleNumber(aContent, aNum))
      73             :                     {
      74         208 :                         setCx(aNum);
      75             :                     }
      76         208 :                     break;
      77             :                 }
      78             :                 case SVGTokenCy:
      79             :                 {
      80         208 :                     SvgNumber aNum;
      81             : 
      82         208 :                     if(readSingleNumber(aContent, aNum))
      83             :                     {
      84         208 :                         setCy(aNum);
      85             :                     }
      86         208 :                     break;
      87             :                 }
      88             :                 case SVGTokenR:
      89             :                 {
      90         208 :                     SvgNumber aNum;
      91             : 
      92         208 :                     if(readSingleNumber(aContent, aNum))
      93             :                     {
      94         208 :                         if(aNum.isPositive())
      95             :                         {
      96         208 :                             setR(aNum);
      97             :                         }
      98             :                     }
      99         208 :                     break;
     100             :                 }
     101             :                 case SVGTokenTransform:
     102             :                 {
     103           0 :                     const basegfx::B2DHomMatrix aMatrix(readTransform(aContent, *this));
     104             : 
     105           0 :                     if(!aMatrix.isIdentity())
     106             :                     {
     107           0 :                         setTransform(&aMatrix);
     108             :                     }
     109           0 :                     break;
     110             :                 }
     111             :                 default:
     112             :                 {
     113         391 :                     break;
     114             :                 }
     115             :             }
     116        1021 :         }
     117             : 
     118         278 :         void SvgCircleNode::decomposeSvgNode(drawinglayer::primitive2d::Primitive2DSequence& rTarget, bool /*bReferenced*/) const
     119             :         {
     120         278 :             const SvgStyleAttributes* pStyle = getSvgStyleAttributes();
     121             : 
     122         278 :             if(pStyle && getR().isSet())
     123             :             {
     124         278 :                 const double fR(getR().solve(*this, length));
     125             : 
     126         278 :                 if(fR > 0.0)
     127             :                 {
     128             :                     const basegfx::B2DPolygon aPath(
     129             :                         basegfx::tools::createPolygonFromCircle(
     130             :                             basegfx::B2DPoint(
     131         556 :                                 getCx().isSet() ? getCx().solve(*this, xcoordinate) : 0.0,
     132         556 :                                 getCy().isSet() ? getCy().solve(*this, ycoordinate) : 0.0),
     133        1112 :                             fR));
     134             : 
     135         556 :                     drawinglayer::primitive2d::Primitive2DSequence aNewTarget;
     136             : 
     137         278 :                     pStyle->add_path(basegfx::B2DPolyPolygon(aPath), aNewTarget, 0);
     138             : 
     139         278 :                     if(aNewTarget.hasElements())
     140             :                     {
     141         278 :                         pStyle->add_postProcess(rTarget, aNewTarget, getTransform());
     142         278 :                     }
     143             :                 }
     144             :             }
     145         278 :         }
     146             :     } // end of namespace svgreader
     147             : } // end of namespace svgio
     148             : 
     149             : 
     150             : // eof
     151             : 
     152             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10