LCOV - code coverage report
Current view: top level - svgio/source/svgreader - svgpatternnode.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 0 172 0.0 %
Date: 2014-04-11 Functions: 0 18 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/svgpatternnode.hxx>
      21             : #include <svgio/svgreader/svgdocument.hxx>
      22             : 
      23             : 
      24             : 
      25             : namespace svgio
      26             : {
      27             :     namespace svgreader
      28             :     {
      29           0 :         void SvgPatternNode::tryToFindLink()
      30             :         {
      31           0 :             if(!mpXLink && !maXLink.isEmpty())
      32             :             {
      33           0 :                 mpXLink = dynamic_cast< const SvgPatternNode* >(getDocument().findSvgNodeById(maXLink));
      34             :             }
      35           0 :         }
      36             : 
      37           0 :         SvgPatternNode::SvgPatternNode(
      38             :             SvgDocument& rDocument,
      39             :             SvgNode* pParent)
      40             :         :   SvgNode(SVGTokenPattern, rDocument, pParent),
      41             :             aPrimitives(),
      42             :             maSvgStyleAttributes(*this),
      43             :             mpViewBox(0),
      44             :             maSvgAspectRatio(),
      45             :             maX(),
      46             :             maY(),
      47             :             maWidth(),
      48             :             maHeight(),
      49             :             mpPatternUnits(0),
      50             :             mpPatternContentUnits(0),
      51             :             mpaPatternTransform(0),
      52             :             maXLink(),
      53           0 :             mpXLink(0)
      54             :         {
      55           0 :         }
      56             : 
      57           0 :         SvgPatternNode::~SvgPatternNode()
      58             :         {
      59           0 :             if(mpViewBox) delete mpViewBox;
      60           0 :             if(mpaPatternTransform) delete mpaPatternTransform;
      61           0 :             if(mpPatternUnits) delete mpPatternUnits;
      62           0 :             if(mpPatternContentUnits) delete mpPatternContentUnits;
      63           0 :         }
      64             : 
      65           0 :         const SvgStyleAttributes* SvgPatternNode::getSvgStyleAttributes() const
      66             :         {
      67           0 :             return checkForCssStyle(OUString("pattern"), maSvgStyleAttributes);
      68             :         }
      69             : 
      70           0 :         void SvgPatternNode::parseAttribute(const OUString& rTokenName, SVGToken aSVGToken, const OUString& aContent)
      71             :         {
      72             :             // call parent
      73           0 :             SvgNode::parseAttribute(rTokenName, aSVGToken, aContent);
      74             : 
      75             :             // read style attributes
      76           0 :             maSvgStyleAttributes.parseStyleAttribute(rTokenName, aSVGToken, aContent);
      77             : 
      78             :             // parse own
      79           0 :             switch(aSVGToken)
      80             :             {
      81             :                 case SVGTokenStyle:
      82             :                 {
      83           0 :                     maSvgStyleAttributes.readStyle(aContent);
      84           0 :                     break;
      85             :                 }
      86             :                 case SVGTokenViewBox:
      87             :                 {
      88           0 :                     const basegfx::B2DRange aRange(readViewBox(aContent, *this));
      89             : 
      90           0 :                     if(!aRange.isEmpty())
      91             :                     {
      92           0 :                         setViewBox(&aRange);
      93             :                     }
      94           0 :                     break;
      95             :                 }
      96             :                 case SVGTokenPreserveAspectRatio:
      97             :                 {
      98           0 :                     setSvgAspectRatio(readSvgAspectRatio(aContent));
      99           0 :                     break;
     100             :                 }
     101             :                 case SVGTokenX:
     102             :                 {
     103           0 :                     SvgNumber aNum;
     104             : 
     105           0 :                     if(readSingleNumber(aContent, aNum))
     106             :                     {
     107           0 :                         setX(aNum);
     108             :                     }
     109           0 :                     break;
     110             :                 }
     111             :                 case SVGTokenY:
     112             :                 {
     113           0 :                     SvgNumber aNum;
     114             : 
     115           0 :                     if(readSingleNumber(aContent, aNum))
     116             :                     {
     117           0 :                         setY(aNum);
     118             :                     }
     119           0 :                     break;
     120             :                 }
     121             :                 case SVGTokenWidth:
     122             :                 {
     123           0 :                     SvgNumber aNum;
     124             : 
     125           0 :                     if(readSingleNumber(aContent, aNum))
     126             :                     {
     127           0 :                         if(aNum.isPositive())
     128             :                         {
     129           0 :                             setWidth(aNum);
     130             :                         }
     131             :                     }
     132           0 :                     break;
     133             :                 }
     134             :                 case SVGTokenHeight:
     135             :                 {
     136           0 :                     SvgNumber aNum;
     137             : 
     138           0 :                     if(readSingleNumber(aContent, aNum))
     139             :                     {
     140           0 :                         if(aNum.isPositive())
     141             :                         {
     142           0 :                             setHeight(aNum);
     143             :                         }
     144             :                     }
     145           0 :                     break;
     146             :                 }
     147             :                 case SVGTokenPatternUnits:
     148             :                 {
     149           0 :                     if(!aContent.isEmpty())
     150             :                     {
     151           0 :                         if(aContent.match(commonStrings::aStrUserSpaceOnUse, 0))
     152             :                         {
     153           0 :                             setPatternUnits(userSpaceOnUse);
     154             :                         }
     155           0 :                         else if(aContent.match(commonStrings::aStrObjectBoundingBox, 0))
     156             :                         {
     157           0 :                             setPatternUnits(objectBoundingBox);
     158             :                         }
     159             :                     }
     160           0 :                     break;
     161             :                 }
     162             :                 case SVGTokenPatternContentUnits:
     163             :                 {
     164           0 :                     if(!aContent.isEmpty())
     165             :                     {
     166           0 :                         if(aContent.match(commonStrings::aStrUserSpaceOnUse, 0))
     167             :                         {
     168           0 :                             setPatternContentUnits(userSpaceOnUse);
     169             :                         }
     170           0 :                         else if(aContent.match(commonStrings::aStrObjectBoundingBox, 0))
     171             :                         {
     172           0 :                             setPatternContentUnits(objectBoundingBox);
     173             :                         }
     174             :                     }
     175           0 :                     break;
     176             :                 }
     177             :                 case SVGTokenPatternTransform:
     178             :                 {
     179           0 :                     const basegfx::B2DHomMatrix aMatrix(readTransform(aContent, *this));
     180             : 
     181           0 :                     if(!aMatrix.isIdentity())
     182             :                     {
     183           0 :                         setPatternTransform(&aMatrix);
     184             :                     }
     185           0 :                     break;
     186             :                 }
     187             :                 case SVGTokenXlinkHref:
     188             :                 {
     189           0 :                     const sal_Int32 nLen(aContent.getLength());
     190             : 
     191           0 :                     if(nLen && '#' == aContent[0])
     192             :                     {
     193           0 :                         maXLink = aContent.copy(1);
     194           0 :                         tryToFindLink();
     195             :                     }
     196           0 :                     break;
     197             :                 }
     198             :                 default:
     199             :                 {
     200           0 :                     break;
     201             :                 }
     202             :             }
     203           0 :         }
     204             : 
     205           0 :         void SvgPatternNode::getValuesRelative(double& rfX, double& rfY, double& rfW, double& rfH, const basegfx::B2DRange& rGeoRange, SvgNode& rUser) const
     206             :         {
     207           0 :             double fTargetWidth(rGeoRange.getWidth());
     208           0 :             double fTargetHeight(rGeoRange.getHeight());
     209             : 
     210           0 :             if(fTargetWidth > 0.0 && fTargetHeight > 0.0)
     211             :             {
     212           0 :                 const SvgUnits aPatternUnits(getPatternUnits() ? *getPatternUnits() : objectBoundingBox);
     213             : 
     214           0 :                 if(objectBoundingBox == aPatternUnits)
     215             :                 {
     216           0 :                     rfW = (getWidth().isSet()) ? getWidth().getNumber() : 0.0;
     217           0 :                     rfH = (getHeight().isSet()) ? getHeight().getNumber() : 0.0;
     218             : 
     219           0 :                     if(Unit_percent == getWidth().getUnit())
     220             :                     {
     221           0 :                         rfW *= 0.01;
     222             :                     }
     223             : 
     224           0 :                     if(Unit_percent == getHeight().getUnit())
     225             :                     {
     226           0 :                         rfH *= 0.01;
     227             :                     }
     228             :                 }
     229             :                 else
     230             :                 {
     231           0 :                     rfW = (getWidth().isSet()) ? getWidth().solve(rUser, xcoordinate) : 0.0;
     232           0 :                     rfH = (getHeight().isSet()) ? getHeight().solve(rUser, ycoordinate) : 0.0;
     233             : 
     234             :                     // make relative to rGeoRange
     235           0 :                     rfW /= fTargetWidth;
     236           0 :                     rfH /= fTargetHeight;
     237             :                 }
     238             : 
     239           0 :                 if(rfW > 0.0 && rfH > 0.0)
     240             :                 {
     241           0 :                     if(objectBoundingBox == aPatternUnits)
     242             :                     {
     243           0 :                         rfX = (getX().isSet()) ? getX().getNumber() : 0.0;
     244           0 :                         rfY = (getY().isSet()) ? getY().getNumber() : 0.0;
     245             : 
     246           0 :                         if(Unit_percent == getX().getUnit())
     247             :                         {
     248           0 :                             rfX *= 0.01;
     249             :                         }
     250             : 
     251           0 :                         if(Unit_percent == getY().getUnit())
     252             :                         {
     253           0 :                             rfY *= 0.01;
     254             :                         }
     255             :                     }
     256             :                     else
     257             :                     {
     258           0 :                         rfX = (getX().isSet()) ? getX().solve(rUser, xcoordinate) : 0.0;
     259           0 :                         rfY = (getY().isSet()) ? getY().solve(rUser, ycoordinate) : 0.0;
     260             : 
     261             :                         // make relative to rGeoRange
     262           0 :                         rfX = (rfX - rGeoRange.getMinX()) / fTargetWidth;
     263           0 :                         rfY = (rfY - rGeoRange.getMinY()) / fTargetHeight;
     264             :                     }
     265             :                 }
     266             :             }
     267           0 :         }
     268             : 
     269           0 :         const drawinglayer::primitive2d::Primitive2DSequence& SvgPatternNode::getPatternPrimitives() const
     270             :         {
     271           0 :             if(!aPrimitives.hasElements() && Display_none != getDisplay())
     272             :             {
     273           0 :                 decomposeSvgNode(const_cast< SvgPatternNode* >(this)->aPrimitives, true);
     274             :             }
     275             : 
     276           0 :             if(!aPrimitives.hasElements() && !maXLink.isEmpty())
     277             :             {
     278           0 :                 const_cast< SvgPatternNode* >(this)->tryToFindLink();
     279             : 
     280           0 :                 if(mpXLink)
     281             :                 {
     282           0 :                     return mpXLink->getPatternPrimitives();
     283             :                 }
     284             :             }
     285             : 
     286           0 :             return aPrimitives;
     287             :         }
     288             : 
     289           0 :         const basegfx::B2DRange SvgPatternNode::getCurrentViewPort() const
     290             :         {
     291           0 :             if(getViewBox())
     292             :             {
     293           0 :                 return *(getViewBox());
     294             :             }
     295             :             else
     296             :             {
     297           0 :                 return SvgNode::getCurrentViewPort();
     298             :             }
     299             :         }
     300             : 
     301           0 :         const basegfx::B2DRange* SvgPatternNode::getViewBox() const
     302             :         {
     303           0 :             if(mpViewBox)
     304             :             {
     305           0 :                 return mpViewBox;
     306             :             }
     307             : 
     308           0 :             const_cast< SvgPatternNode* >(this)->tryToFindLink();
     309             : 
     310           0 :             if(mpXLink)
     311             :             {
     312           0 :                 return mpXLink->getViewBox();
     313             :             }
     314             : 
     315           0 :             return 0;
     316             :         }
     317             : 
     318           0 :         const SvgAspectRatio& SvgPatternNode::getSvgAspectRatio() const
     319             :         {
     320           0 :             if(maSvgAspectRatio.isSet())
     321             :             {
     322           0 :                 return maSvgAspectRatio;
     323             :             }
     324             : 
     325           0 :             const_cast< SvgPatternNode* >(this)->tryToFindLink();
     326             : 
     327           0 :             if(mpXLink)
     328             :             {
     329           0 :                 return mpXLink->getSvgAspectRatio();
     330             :             }
     331             : 
     332           0 :             return maSvgAspectRatio;
     333             :         }
     334             : 
     335           0 :         const SvgNumber& SvgPatternNode::getX() const
     336             :         {
     337           0 :             if(maX.isSet())
     338             :             {
     339           0 :                 return maX;
     340             :             }
     341             : 
     342           0 :             const_cast< SvgPatternNode* >(this)->tryToFindLink();
     343             : 
     344           0 :             if(mpXLink)
     345             :             {
     346           0 :                 return mpXLink->getX();
     347             :             }
     348             : 
     349           0 :             return maX;
     350             :         }
     351             : 
     352           0 :         const SvgNumber& SvgPatternNode::getY() const
     353             :         {
     354           0 :             if(maY.isSet())
     355             :             {
     356           0 :                 return maY;
     357             :             }
     358             : 
     359           0 :             const_cast< SvgPatternNode* >(this)->tryToFindLink();
     360             : 
     361           0 :             if(mpXLink)
     362             :             {
     363           0 :                 return mpXLink->getY();
     364             :             }
     365             : 
     366           0 :             return maY;
     367             :         }
     368             : 
     369           0 :         const SvgNumber& SvgPatternNode::getWidth() const
     370             :         {
     371           0 :             if(maWidth.isSet())
     372             :             {
     373           0 :                 return maWidth;
     374             :             }
     375             : 
     376           0 :             const_cast< SvgPatternNode* >(this)->tryToFindLink();
     377             : 
     378           0 :             if(mpXLink)
     379             :             {
     380           0 :                 return mpXLink->getWidth();
     381             :             }
     382             : 
     383           0 :             return maWidth;
     384             :         }
     385             : 
     386           0 :         const SvgNumber& SvgPatternNode::getHeight() const
     387             :         {
     388           0 :             if(maHeight.isSet())
     389             :             {
     390           0 :                 return maHeight;
     391             :             }
     392             : 
     393           0 :             const_cast< SvgPatternNode* >(this)->tryToFindLink();
     394             : 
     395           0 :             if(mpXLink)
     396             :             {
     397           0 :                 return mpXLink->getHeight();
     398             :             }
     399             : 
     400           0 :             return maHeight;
     401             :         }
     402             : 
     403           0 :         const SvgUnits* SvgPatternNode::getPatternUnits() const
     404             :         {
     405           0 :             if(mpPatternUnits)
     406             :             {
     407           0 :                 return mpPatternUnits;
     408             :             }
     409             : 
     410           0 :             const_cast< SvgPatternNode* >(this)->tryToFindLink();
     411             : 
     412           0 :             if(mpXLink)
     413             :             {
     414           0 :                 return mpXLink->getPatternUnits();
     415             :             }
     416             : 
     417           0 :             return 0;
     418             :         }
     419             : 
     420           0 :         const SvgUnits* SvgPatternNode::getPatternContentUnits() const
     421             :         {
     422           0 :             if(mpPatternContentUnits)
     423             :             {
     424           0 :                 return mpPatternContentUnits;
     425             :             }
     426             : 
     427           0 :             const_cast< SvgPatternNode* >(this)->tryToFindLink();
     428             : 
     429           0 :             if(mpXLink)
     430             :             {
     431           0 :                 return mpXLink->getPatternContentUnits();
     432             :             }
     433             : 
     434           0 :             return 0;
     435             :         }
     436             : 
     437           0 :         const basegfx::B2DHomMatrix* SvgPatternNode::getPatternTransform() const
     438             :         {
     439           0 :             if(mpaPatternTransform)
     440             :             {
     441           0 :                 return mpaPatternTransform;
     442             :             }
     443             : 
     444           0 :             const_cast< SvgPatternNode* >(this)->tryToFindLink();
     445             : 
     446           0 :             if(mpXLink)
     447             :             {
     448           0 :                 return mpXLink->getPatternTransform();
     449             :             }
     450             : 
     451           0 :             return 0;
     452             :         }
     453             : 
     454             :     } // end of namespace svgreader
     455             : } // end of namespace svgio
     456             : 
     457             : 
     458             : // eof
     459             : 
     460             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10