LCOV - code coverage report
Current view: top level - svgio/source/svgreader - svgrectnode.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 66 79 83.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/svgrectnode.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         126 :         SvgRectNode::SvgRectNode(
      31             :             SvgDocument& rDocument,
      32             :             SvgNode* pParent)
      33             :         :   SvgNode(SVGTokenRect, rDocument, pParent),
      34             :             maSvgStyleAttributes(*this),
      35             :             maX(0),
      36             :             maY(0),
      37             :             maWidth(0),
      38             :             maHeight(0),
      39             :             maRx(0),
      40             :             maRy(0),
      41         126 :             mpaTransform(0)
      42             :         {
      43         126 :         }
      44             : 
      45         378 :         SvgRectNode::~SvgRectNode()
      46             :         {
      47         126 :             if(mpaTransform) delete mpaTransform;
      48         252 :         }
      49             : 
      50         126 :         const SvgStyleAttributes* SvgRectNode::getSvgStyleAttributes() const
      51             :         {
      52         126 :             return checkForCssStyle(OUString("rect"), maSvgStyleAttributes);
      53             :         }
      54             : 
      55         675 :         void SvgRectNode::parseAttribute(const OUString& rTokenName, SVGToken aSVGToken, const OUString& aContent)
      56             :         {
      57             :             // call parent
      58         675 :             SvgNode::parseAttribute(rTokenName, aSVGToken, aContent);
      59             : 
      60             :             // read style attributes
      61         675 :             maSvgStyleAttributes.parseStyleAttribute(rTokenName, aSVGToken, aContent);
      62             : 
      63             :             // parse own
      64         675 :             switch(aSVGToken)
      65             :             {
      66             :                 case SVGTokenStyle:
      67             :                 {
      68           7 :                     maSvgStyleAttributes.readStyle(aContent);
      69           7 :                     break;
      70             :                 }
      71             :                 case SVGTokenX:
      72             :                 {
      73         125 :                     SvgNumber aNum;
      74             : 
      75         125 :                     if(readSingleNumber(aContent, aNum))
      76             :                     {
      77         125 :                         setX(aNum);
      78             :                     }
      79         125 :                     break;
      80             :                 }
      81             :                 case SVGTokenY:
      82             :                 {
      83         126 :                     SvgNumber aNum;
      84             : 
      85         126 :                     if(readSingleNumber(aContent, aNum))
      86             :                     {
      87         126 :                         setY(aNum);
      88             :                     }
      89         126 :                     break;
      90             :                 }
      91             :                 case SVGTokenWidth:
      92             :                 {
      93         126 :                     SvgNumber aNum;
      94             : 
      95         126 :                     if(readSingleNumber(aContent, aNum))
      96             :                     {
      97         126 :                         if(aNum.isPositive())
      98             :                         {
      99         126 :                             setWidth(aNum);
     100             :                         }
     101             :                     }
     102         126 :                     break;
     103             :                 }
     104             :                 case SVGTokenHeight:
     105             :                 {
     106         126 :                     SvgNumber aNum;
     107             : 
     108         126 :                     if(readSingleNumber(aContent, aNum))
     109             :                     {
     110         126 :                         if(aNum.isPositive())
     111             :                         {
     112         126 :                             setHeight(aNum);
     113             :                         }
     114             :                     }
     115         126 :                     break;
     116             :                 }
     117             :                 case SVGTokenRx:
     118             :                 {
     119           0 :                     SvgNumber aNum;
     120             : 
     121           0 :                     if(readSingleNumber(aContent, aNum))
     122             :                     {
     123           0 :                         if(aNum.isPositive())
     124             :                         {
     125           0 :                             setRx(aNum);
     126             :                         }
     127             :                     }
     128           0 :                     break;
     129             :                 }
     130             :                 case SVGTokenRy:
     131             :                 {
     132           0 :                     SvgNumber aNum;
     133             : 
     134           0 :                     if(readSingleNumber(aContent, aNum))
     135             :                     {
     136           0 :                         if(aNum.isPositive())
     137             :                         {
     138           0 :                             setRy(aNum);
     139             :                         }
     140             :                     }
     141           0 :                     break;
     142             :                 }
     143             :                 case SVGTokenTransform:
     144             :                 {
     145          32 :                     const basegfx::B2DHomMatrix aMatrix(readTransform(aContent, *this));
     146             : 
     147          32 :                     if(!aMatrix.isIdentity())
     148             :                     {
     149          32 :                         setTransform(&aMatrix);
     150             :                     }
     151          32 :                     break;
     152             :                 }
     153             :                 default:
     154             :                 {
     155         133 :                     break;
     156             :                 }
     157             :             }
     158         675 :         }
     159             : 
     160         126 :         void SvgRectNode::decomposeSvgNode(drawinglayer::primitive2d::Primitive2DSequence& rTarget, bool /*bReferenced*/) const
     161             :         {
     162             :             // get size range and create path
     163         126 :             const SvgStyleAttributes* pStyle = getSvgStyleAttributes();
     164             : 
     165         126 :             if(pStyle && getWidth().isSet() && getHeight().isSet())
     166             :             {
     167         126 :                 const double fWidth(getWidth().solve(*this, xcoordinate));
     168         126 :                 const double fHeight(getHeight().solve(*this, ycoordinate));
     169             : 
     170         126 :                 if(fWidth > 0.0 && fHeight > 0.0)
     171             :                 {
     172         126 :                     const double fX(getX().isSet() ? getX().solve(*this, xcoordinate) : 0.0);
     173         126 :                     const double fY(getY().isSet() ? getY().solve(*this, ycoordinate) : 0.0);
     174         126 :                     const basegfx::B2DRange aRange(fX, fY, fX + fWidth, fY + fHeight);
     175         126 :                     basegfx::B2DPolygon aPath;
     176             : 
     177         126 :                     if(getRx().isSet() || getRy().isSet())
     178             :                     {
     179         126 :                         double frX(getRx().isSet() ? getRx().solve(*this, xcoordinate) : 0.0);
     180         126 :                         double frY(getRy().isSet() ? getRy().solve(*this, ycoordinate) : 0.0);
     181             : 
     182         126 :                         frX = std::max(0.0, frX);
     183         126 :                         frY = std::max(0.0, frY);
     184             : 
     185         126 :                         if(0.0 == frY && frX > 0.0)
     186             :                         {
     187           0 :                             frY = frX;
     188             :                         }
     189         126 :                         else if(0.0 == frX && frY > 0.0)
     190             :                         {
     191           0 :                             frX = frY;
     192             :                         }
     193             : 
     194         126 :                         frX /= fWidth;
     195         126 :                         frY /= fHeight;
     196             : 
     197         126 :                         frX = std::min(0.5, frX);
     198         126 :                         frY = std::min(0.5, frY);
     199             : 
     200         126 :                         aPath = basegfx::tools::createPolygonFromRect(aRange, frX * 2.0, frY * 2.0);
     201             :                     }
     202             :                     else
     203             :                     {
     204           0 :                         aPath = basegfx::tools::createPolygonFromRect(aRange);
     205             :                     }
     206             : 
     207         252 :                     drawinglayer::primitive2d::Primitive2DSequence aNewTarget;
     208             : 
     209         126 :                     pStyle->add_path(basegfx::B2DPolyPolygon(aPath), aNewTarget, 0);
     210             : 
     211         126 :                     if(aNewTarget.hasElements())
     212             :                     {
     213         106 :                         pStyle->add_postProcess(rTarget, aNewTarget, getTransform());
     214         126 :                     }
     215             :                 }
     216             :             }
     217         126 :         }
     218             :     } // end of namespace svgreader
     219             : } // end of namespace svgio
     220             : 
     221             : 
     222             : // eof
     223             : 
     224             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10