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

Generated by: LCOV version 1.10