LCOV - code coverage report
Current view: top level - svgio/source/svgreader - svgpolynode.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 33 37 89.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/svgpolynode.hxx>
      21             : #include <basegfx/polygon/b2dpolygon.hxx>
      22             : #include <basegfx/polygon/b2dpolypolygontools.hxx>
      23             : #include <basegfx/polygon/b2dpolygontools.hxx>
      24             : 
      25             : 
      26             : 
      27             : namespace svgio
      28             : {
      29             :     namespace svgreader
      30             :     {
      31         710 :         SvgPolyNode::SvgPolyNode(
      32             :             SvgDocument& rDocument,
      33             :             SvgNode* pParent,
      34             :             bool bIsPolyline)
      35             :         :   SvgNode(SVGTokenPolygon, rDocument, pParent),
      36             :             maSvgStyleAttributes(*this),
      37             :             mpPolygon(0),
      38             :             mpaTransform(0),
      39         710 :             mbIsPolyline(bIsPolyline)
      40             :         {
      41         710 :         }
      42             : 
      43        2130 :         SvgPolyNode::~SvgPolyNode()
      44             :         {
      45         710 :             if(mpaTransform) delete mpaTransform;
      46         710 :             if(mpPolygon) delete mpPolygon;
      47        1420 :         }
      48             : 
      49         698 :         const SvgStyleAttributes* SvgPolyNode::getSvgStyleAttributes() const
      50             :         {
      51         698 :             return checkForCssStyle(mbIsPolyline? OUString("polyline") : OUString("polygon"), maSvgStyleAttributes);
      52             :         }
      53             : 
      54        1650 :         void SvgPolyNode::parseAttribute(const OUString& rTokenName, SVGToken aSVGToken, const OUString& aContent)
      55             :         {
      56             :             // call parent
      57        1650 :             SvgNode::parseAttribute(rTokenName, aSVGToken, aContent);
      58             : 
      59             :             // read style attributes
      60        1650 :             maSvgStyleAttributes.parseStyleAttribute(rTokenName, aSVGToken, aContent);
      61             : 
      62             :             // parse own
      63        1650 :             switch(aSVGToken)
      64             :             {
      65             :                 case SVGTokenStyle:
      66             :                 {
      67          27 :                     maSvgStyleAttributes.readStyle(aContent);
      68          27 :                     break;
      69             :                 }
      70             :                 case SVGTokenPoints:
      71             :                 {
      72         710 :                     basegfx::B2DPolygon aPath;
      73             : 
      74         710 :                     if(basegfx::tools::importFromSvgPoints(aPath, aContent))
      75             :                     {
      76         710 :                         if(aPath.count())
      77             :                         {
      78         710 :                             if(!isPolyline())
      79             :                             {
      80         673 :                                 aPath.setClosed(true);
      81             :                             }
      82             : 
      83         710 :                             setPolygon(&aPath);
      84             :                         }
      85             :                     }
      86         710 :                     break;
      87             :                 }
      88             :                 case SVGTokenTransform:
      89             :                 {
      90           0 :                     const basegfx::B2DHomMatrix aMatrix(readTransform(aContent, *this));
      91             : 
      92           0 :                     if(!aMatrix.isIdentity())
      93             :                     {
      94           0 :                         setTransform(&aMatrix);
      95             :                     }
      96           0 :                     break;
      97             :                 }
      98             :                 default:
      99             :                 {
     100         913 :                     break;
     101             :                 }
     102             :             }
     103        1650 :         }
     104             : 
     105         698 :         void SvgPolyNode::decomposeSvgNode(drawinglayer::primitive2d::Primitive2DSequence& rTarget, bool /*bReferenced*/) const
     106             :         {
     107         698 :             const SvgStyleAttributes* pStyle = getSvgStyleAttributes();
     108             : 
     109         698 :             if(pStyle && getPolygon())
     110             :             {
     111         698 :                 drawinglayer::primitive2d::Primitive2DSequence aNewTarget;
     112             : 
     113         698 :                 pStyle->add_path(basegfx::B2DPolyPolygon(*getPolygon()), aNewTarget, 0);
     114             : 
     115         698 :                 if(aNewTarget.hasElements())
     116             :                 {
     117         697 :                     pStyle->add_postProcess(rTarget, aNewTarget, getTransform());
     118         698 :                 }
     119             :             }
     120         698 :         }
     121             :     } // end of namespace svgreader
     122             : } // end of namespace svgio
     123             : 
     124             : 
     125             : // eof
     126             : 
     127             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10