LCOV - code coverage report
Current view: top level - svgio/source/svgreader - svglinenode.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 48 54 88.9 %
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/svglinenode.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           3 :         SvgLineNode::SvgLineNode(
      31             :             SvgDocument& rDocument,
      32             :             SvgNode* pParent)
      33             :         :   SvgNode(SVGTokenLine, rDocument, pParent),
      34             :             maSvgStyleAttributes(*this),
      35             :             maX1(0),
      36             :             maY1(0),
      37             :             maX2(0),
      38             :             maY2(0),
      39           3 :             mpaTransform(0)
      40             :         {
      41           3 :         }
      42             : 
      43           9 :         SvgLineNode::~SvgLineNode()
      44             :         {
      45           3 :             if(mpaTransform) delete mpaTransform;
      46           6 :         }
      47             : 
      48           3 :         const SvgStyleAttributes* SvgLineNode::getSvgStyleAttributes() const
      49             :         {
      50           3 :             return checkForCssStyle(OUString("line"), maSvgStyleAttributes);
      51             :         }
      52             : 
      53          24 :         void SvgLineNode::parseAttribute(const OUString& rTokenName, SVGToken aSVGToken, const OUString& aContent)
      54             :         {
      55             :             // call parent
      56          24 :             SvgNode::parseAttribute(rTokenName, aSVGToken, aContent);
      57             : 
      58             :             // read style attributes
      59          24 :             maSvgStyleAttributes.parseStyleAttribute(rTokenName, aSVGToken, aContent);
      60             : 
      61             :             // parse own
      62          24 :             switch(aSVGToken)
      63             :             {
      64             :                 case SVGTokenStyle:
      65             :                 {
      66           0 :                     maSvgStyleAttributes.readStyle(aContent);
      67           0 :                     break;
      68             :                 }
      69             :                 case SVGTokenX1:
      70             :                 {
      71           3 :                     SvgNumber aNum;
      72             : 
      73           3 :                     if(readSingleNumber(aContent, aNum))
      74             :                     {
      75           3 :                         setX1(aNum);
      76             :                     }
      77           3 :                     break;
      78             :                 }
      79             :                 case SVGTokenY1:
      80             :                 {
      81           3 :                     SvgNumber aNum;
      82             : 
      83           3 :                     if(readSingleNumber(aContent, aNum))
      84             :                     {
      85           3 :                         setY1(aNum);
      86             :                     }
      87           3 :                     break;
      88             :                 }
      89             :                 case SVGTokenX2:
      90             :                 {
      91           3 :                     SvgNumber aNum;
      92             : 
      93           3 :                     if(readSingleNumber(aContent, aNum))
      94             :                     {
      95           3 :                         setX2(aNum);
      96             :                     }
      97           3 :                     break;
      98             :                 }
      99             :                 case SVGTokenY2:
     100             :                 {
     101           3 :                     SvgNumber aNum;
     102             : 
     103           3 :                     if(readSingleNumber(aContent, aNum))
     104             :                     {
     105           3 :                         setY2(aNum);
     106             :                     }
     107           3 :                     break;
     108             :                 }
     109             :                 case SVGTokenTransform:
     110             :                 {
     111           0 :                     const basegfx::B2DHomMatrix aMatrix(readTransform(aContent, *this));
     112             : 
     113           0 :                     if(!aMatrix.isIdentity())
     114             :                     {
     115           0 :                         setTransform(&aMatrix);
     116             :                     }
     117           0 :                     break;
     118             :                 }
     119             :                 default:
     120             :                 {
     121          12 :                     break;
     122             :                 }
     123             :             }
     124          24 :         }
     125             : 
     126           3 :         void SvgLineNode::decomposeSvgNode(drawinglayer::primitive2d::Primitive2DSequence& rTarget, bool /*bReferenced*/) const
     127             :         {
     128           3 :             const SvgStyleAttributes* pStyle = getSvgStyleAttributes();
     129             : 
     130           3 :             if(pStyle)
     131             :             {
     132             :                 const basegfx::B2DPoint X(
     133           6 :                     getX1().isSet() ? getX1().solve(*this, xcoordinate) : 0.0,
     134           9 :                     getY1().isSet() ? getY1().solve(*this, ycoordinate) : 0.0);
     135             :                 const basegfx::B2DPoint Y(
     136           6 :                     getX2().isSet() ? getX2().solve(*this, xcoordinate) : 0.0,
     137          12 :                     getY2().isSet() ? getY2().solve(*this, ycoordinate) : 0.0);
     138             : 
     139           3 :                 if(!X.equal(Y))
     140             :                 {
     141           3 :                     basegfx::B2DPolygon aPath;
     142             : 
     143           3 :                     aPath.append(X);
     144           3 :                     aPath.append(Y);
     145             : 
     146           6 :                     drawinglayer::primitive2d::Primitive2DSequence aNewTarget;
     147             : 
     148           3 :                     pStyle->add_path(basegfx::B2DPolyPolygon(aPath), aNewTarget, 0);
     149             : 
     150           3 :                     if(aNewTarget.hasElements())
     151             :                     {
     152           3 :                         pStyle->add_postProcess(rTarget, aNewTarget, getTransform());
     153           3 :                     }
     154           3 :                 }
     155             :             }
     156           3 :         }
     157             :     } // end of namespace svgreader
     158             : } // end of namespace svgio
     159             : 
     160             : 
     161             : // eof
     162             : 
     163             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10