LCOV - code coverage report
Current view: top level - svgio/source/svgreader - svgusenode.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 34 63 54.0 %
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/svgusenode.hxx>
      21             : #include <drawinglayer/primitive2d/transformprimitive2d.hxx>
      22             : #include <svgio/svgreader/svgdocument.hxx>
      23             : 
      24             : 
      25             : 
      26             : namespace svgio
      27             : {
      28             :     namespace svgreader
      29             :     {
      30         130 :         SvgUseNode::SvgUseNode(
      31             :             SvgDocument& rDocument,
      32             :             SvgNode* pParent)
      33             :         :   SvgNode(SVGTokenG, rDocument, pParent),
      34             :             maSvgStyleAttributes(*this),
      35             :             mpaTransform(0),
      36             :             maX(),
      37             :             maY(),
      38             :             maWidth(),
      39             :             maHeight(),
      40         130 :             maXLink()
      41             :         {
      42         130 :         }
      43             : 
      44         390 :         SvgUseNode::~SvgUseNode()
      45             :         {
      46         130 :             if(mpaTransform) delete mpaTransform;
      47         260 :         }
      48             : 
      49        1659 :         const SvgStyleAttributes* SvgUseNode::getSvgStyleAttributes() const
      50             :         {
      51        1659 :             return checkForCssStyle(OUString("use"), maSvgStyleAttributes);
      52             :         }
      53             : 
      54         201 :         void SvgUseNode::parseAttribute(const OUString& rTokenName, SVGToken aSVGToken, const OUString& aContent)
      55             :         {
      56             :             // call parent
      57         201 :             SvgNode::parseAttribute(rTokenName, aSVGToken, aContent);
      58             : 
      59             :             // read style attributes
      60         201 :             maSvgStyleAttributes.parseStyleAttribute(rTokenName, aSVGToken, aContent);
      61             : 
      62             :             // parse own
      63         201 :             switch(aSVGToken)
      64             :             {
      65             :                 case SVGTokenStyle:
      66             :                 {
      67           0 :                     maSvgStyleAttributes.readStyle(aContent);
      68           0 :                     break;
      69             :                 }
      70             :                 case SVGTokenTransform:
      71             :                 {
      72           0 :                     const basegfx::B2DHomMatrix aMatrix(readTransform(aContent, *this));
      73             : 
      74           0 :                     if(!aMatrix.isIdentity())
      75             :                     {
      76           0 :                         setTransform(&aMatrix);
      77             :                     }
      78           0 :                     break;
      79             :                 }
      80             :                 case SVGTokenX:
      81             :                 {
      82           0 :                     SvgNumber aNum;
      83             : 
      84           0 :                     if(readSingleNumber(aContent, aNum))
      85             :                     {
      86           0 :                         setX(aNum);
      87             :                     }
      88           0 :                     break;
      89             :                 }
      90             :                 case SVGTokenY:
      91             :                 {
      92           0 :                     SvgNumber aNum;
      93             : 
      94           0 :                     if(readSingleNumber(aContent, aNum))
      95             :                     {
      96           0 :                         setY(aNum);
      97             :                     }
      98           0 :                     break;
      99             :                 }
     100             :                 case SVGTokenWidth:
     101             :                 {
     102           0 :                     SvgNumber aNum;
     103             : 
     104           0 :                     if(readSingleNumber(aContent, aNum))
     105             :                     {
     106           0 :                         if(aNum.isPositive())
     107             :                         {
     108           0 :                             setWidth(aNum);
     109             :                         }
     110             :                     }
     111           0 :                     break;
     112             :                 }
     113             :                 case SVGTokenHeight:
     114             :                 {
     115           0 :                     SvgNumber aNum;
     116             : 
     117           0 :                     if(readSingleNumber(aContent, aNum))
     118             :                     {
     119           0 :                         if(aNum.isPositive())
     120             :                         {
     121           0 :                             setHeight(aNum);
     122             :                         }
     123             :                     }
     124           0 :                     break;
     125             :                 }
     126             :                 case SVGTokenXlinkHref:
     127             :                 {
     128         130 :                     const sal_Int32 nLen(aContent.getLength());
     129             : 
     130         130 :                     if(nLen && '#' == aContent[0])
     131             :                     {
     132         130 :                         maXLink = aContent.copy(1);
     133             :                     }
     134         130 :                     break;
     135             :                 }
     136             :                 default:
     137             :                 {
     138          71 :                     break;
     139             :                 }
     140             :             }
     141         201 :         }
     142             : 
     143         193 :         void SvgUseNode::decomposeSvgNode(drawinglayer::primitive2d::Primitive2DSequence& rTarget, bool /*bReferenced*/) const
     144             :         {
     145             :             // try to access link to content
     146         193 :             const SvgNode* mpXLink = getDocument().findSvgNodeById(maXLink);
     147             : 
     148         193 :             if(mpXLink && Display_none != mpXLink->getDisplay())
     149             :             {
     150             :                 // decompose children
     151         193 :                 drawinglayer::primitive2d::Primitive2DSequence aNewTarget;
     152             : 
     153             :                 // todo: in case mpXLink is a SVGTokenSvg or SVGTokenSymbol the
     154             :                 // SVG docs want the getWidth() and getHeight() from this node
     155             :                 // to be valid for the subtree.
     156         193 :                 const_cast< SvgNode* >(mpXLink)->setAlternativeParent(this);
     157         193 :                 mpXLink->decomposeSvgNode(aNewTarget, true);
     158         193 :                 const_cast< SvgNode* >(mpXLink)->setAlternativeParent(0);
     159             : 
     160         193 :                 if(aNewTarget.hasElements())
     161             :                 {
     162         193 :                     basegfx::B2DHomMatrix aTransform;
     163             : 
     164         193 :                     if(getX().isSet() || getY().isSet())
     165             :                     {
     166             :                         aTransform.translate(
     167           0 :                             getX().solve(*this, xcoordinate),
     168           0 :                             getY().solve(*this, ycoordinate));
     169             :                     }
     170             : 
     171         193 :                     if(getTransform())
     172             :                     {
     173           0 :                         aTransform = *getTransform() * aTransform;
     174             :                     }
     175             : 
     176         193 :                     if(!aTransform.isIdentity())
     177             :                     {
     178             :                         const drawinglayer::primitive2d::Primitive2DReference xRef(
     179             :                             new drawinglayer::primitive2d::TransformPrimitive2D(
     180             :                                 aTransform,
     181           0 :                                 aNewTarget));
     182             : 
     183           0 :                         drawinglayer::primitive2d::appendPrimitive2DReferenceToPrimitive2DSequence(rTarget, xRef);
     184             :                     }
     185             :                     else
     186             :                     {
     187         193 :                         drawinglayer::primitive2d::appendPrimitive2DSequenceToPrimitive2DSequence(rTarget, aNewTarget);
     188         193 :                     }
     189         193 :                 }
     190             :             }
     191         193 :         }
     192             : 
     193             :     } // end of namespace svgreader
     194             : } // end of namespace svgio
     195             : 
     196             : 
     197             : // eof
     198             : 
     199             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10