LCOV - code coverage report
Current view: top level - drawinglayer/source/attribute - sdrfillgraphicattribute.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 92 100 92.0 %
Date: 2014-11-03 Functions: 32 32 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 <drawinglayer/attribute/sdrfillgraphicattribute.hxx>
      21             : #include <drawinglayer/attribute/fillgraphicattribute.hxx>
      22             : #include <rtl/instance.hxx>
      23             : #include <vcl/graph.hxx>
      24             : 
      25             : 
      26             : 
      27             : namespace drawinglayer
      28             : {
      29             :     namespace attribute
      30             :     {
      31        1487 :         class ImpSdrFillGraphicAttribute
      32             :         {
      33             :         public:
      34             :             // data definitions
      35             :             Graphic                                 maFillGraphic;
      36             :             basegfx::B2DVector                      maGraphicLogicSize;
      37             :             basegfx::B2DVector                      maSize;
      38             :             basegfx::B2DVector                      maOffset;
      39             :             basegfx::B2DVector                      maOffsetPosition;
      40             :             basegfx::B2DVector                      maRectPoint;
      41             : 
      42             :             // bitfield
      43             :             bool                                    mbTiling : 1;
      44             :             bool                                    mbStretch : 1;
      45             :             bool                                    mbLogSize : 1;
      46             : 
      47         458 :             ImpSdrFillGraphicAttribute(
      48             :                 const Graphic& rFillGraphic,
      49             :                 const basegfx::B2DVector& rGraphicLogicSize,
      50             :                 const basegfx::B2DVector& rSize,
      51             :                 const basegfx::B2DVector& rOffset,
      52             :                 const basegfx::B2DVector& rOffsetPosition,
      53             :                 const basegfx::B2DVector& rRectPoint,
      54             :                 bool bTiling,
      55             :                 bool bStretch,
      56             :                 bool bLogSize)
      57             :             :   maFillGraphic(rFillGraphic),
      58             :                 maGraphicLogicSize(rGraphicLogicSize),
      59             :                 maSize(rSize),
      60             :                 maOffset(rOffset),
      61             :                 maOffsetPosition(rOffsetPosition),
      62             :                 maRectPoint(rRectPoint),
      63             :                 mbTiling(bTiling),
      64             :                 mbStretch(bStretch),
      65         458 :                 mbLogSize(bLogSize)
      66             :             {
      67         458 :             }
      68             : 
      69         128 :             ImpSdrFillGraphicAttribute()
      70             :             :   maFillGraphic(Graphic()),
      71             :                 maGraphicLogicSize(basegfx::B2DVector()),
      72             :                 maSize(basegfx::B2DVector()),
      73             :                 maOffset(basegfx::B2DVector()),
      74             :                 maOffsetPosition(basegfx::B2DVector()),
      75             :                 maRectPoint(basegfx::B2DVector()),
      76             :                 mbTiling(false),
      77             :                 mbStretch(false),
      78         128 :                 mbLogSize(false)
      79             :             {
      80         128 :             }
      81             : 
      82             :             // data read access
      83        3633 :             const Graphic& getFillGraphic() const { return maFillGraphic; }
      84         480 :             const basegfx::B2DVector& getGraphicLogicSize() const { return maGraphicLogicSize; }
      85         504 :             const basegfx::B2DVector& getSize() const { return maSize; }
      86         908 :             const basegfx::B2DVector& getOffset() const { return maOffset; }
      87         488 :             const basegfx::B2DVector& getOffsetPosition() const { return maOffsetPosition; }
      88         488 :             const basegfx::B2DVector& getRectPoint() const { return maRectPoint; }
      89        1068 :             bool getTiling() const { return mbTiling; }
      90         538 :             bool getStretch() const { return mbStretch; }
      91         328 :             bool getLogSize() const { return mbLogSize; }
      92             : 
      93         164 :             bool operator==(const ImpSdrFillGraphicAttribute& rCandidate) const
      94             :             {
      95         164 :                 return (getFillGraphic() == rCandidate.getFillGraphic()
      96         164 :                     && getGraphicLogicSize() == rCandidate.getGraphicLogicSize()
      97         164 :                     && getSize() == rCandidate.getSize()
      98         164 :                     && getOffset() == rCandidate.getOffset()
      99         164 :                     && getOffsetPosition() == rCandidate.getOffsetPosition()
     100         164 :                     && getRectPoint() == rCandidate.getRectPoint()
     101         164 :                     && getTiling() == rCandidate.getTiling()
     102         164 :                     && getStretch() == rCandidate.getStretch()
     103         328 :                     && getLogSize() == rCandidate.getLogSize());
     104             :             }
     105             :         };
     106             : 
     107             :         namespace
     108             :         {
     109             :             struct theGlobalDefault :
     110             :                 public rtl::Static< SdrFillGraphicAttribute::ImplType, theGlobalDefault > {};
     111             :         }
     112             : 
     113         458 :         SdrFillGraphicAttribute::SdrFillGraphicAttribute(
     114             :             const Graphic& rFillGraphic,
     115             :             const basegfx::B2DVector& rGraphicLogicSize,
     116             :             const basegfx::B2DVector& rSize,
     117             :             const basegfx::B2DVector& rOffset,
     118             :             const basegfx::B2DVector& rOffsetPosition,
     119             :             const basegfx::B2DVector& rRectPoint,
     120             :             bool bTiling,
     121             :             bool bStretch,
     122             :             bool bLogSize)
     123             :         :   mpSdrFillGraphicAttribute(
     124             :                 ImpSdrFillGraphicAttribute(
     125             :                     rFillGraphic,
     126             :                     rGraphicLogicSize,
     127             :                     rSize,
     128             :                     rOffset,
     129             :                     rOffsetPosition,
     130             :                     rRectPoint,
     131             :                     bTiling,
     132             :                     bStretch,
     133         458 :                     bLogSize))
     134             :         {
     135         458 :         }
     136             : 
     137       37492 :         SdrFillGraphicAttribute::SdrFillGraphicAttribute()
     138       37492 :         :   mpSdrFillGraphicAttribute(theGlobalDefault::get())
     139             :         {
     140       37492 :         }
     141             : 
     142       74720 :         SdrFillGraphicAttribute::SdrFillGraphicAttribute(const SdrFillGraphicAttribute& rCandidate)
     143       74720 :         :   mpSdrFillGraphicAttribute(rCandidate.mpSdrFillGraphicAttribute)
     144             :         {
     145       74720 :         }
     146             : 
     147      112172 :         SdrFillGraphicAttribute::~SdrFillGraphicAttribute()
     148             :         {
     149      112172 :         }
     150             : 
     151       16386 :         bool SdrFillGraphicAttribute::isDefault() const
     152             :         {
     153       16386 :             return mpSdrFillGraphicAttribute.same_object(theGlobalDefault::get());
     154             :         }
     155             : 
     156         462 :         SdrFillGraphicAttribute& SdrFillGraphicAttribute::operator=(const SdrFillGraphicAttribute& rCandidate)
     157             :         {
     158         462 :             mpSdrFillGraphicAttribute = rCandidate.mpSdrFillGraphicAttribute;
     159         462 :             return *this;
     160             :         }
     161             : 
     162       13816 :         bool SdrFillGraphicAttribute::operator==(const SdrFillGraphicAttribute& rCandidate) const
     163             :         {
     164       13816 :             return rCandidate.mpSdrFillGraphicAttribute == mpSdrFillGraphicAttribute;
     165             :         }
     166             : 
     167        3305 :         const Graphic& SdrFillGraphicAttribute::getFillGraphic() const
     168             :         {
     169        3305 :             return mpSdrFillGraphicAttribute->getFillGraphic();
     170             :         }
     171             : 
     172         152 :         const basegfx::B2DVector& SdrFillGraphicAttribute::getGraphicLogicSize() const
     173             :         {
     174         152 :             return mpSdrFillGraphicAttribute->getGraphicLogicSize();
     175             :         }
     176             : 
     177         176 :         const basegfx::B2DVector& SdrFillGraphicAttribute::getSize() const
     178             :         {
     179         176 :             return mpSdrFillGraphicAttribute->getSize();
     180             :         }
     181             : 
     182         580 :         const basegfx::B2DVector& SdrFillGraphicAttribute::getOffset() const
     183             :         {
     184         580 :             return mpSdrFillGraphicAttribute->getOffset();
     185             :         }
     186             : 
     187         160 :         const basegfx::B2DVector& SdrFillGraphicAttribute::getOffsetPosition() const
     188             :         {
     189         160 :             return mpSdrFillGraphicAttribute->getOffsetPosition();
     190             :         }
     191             : 
     192         160 :         const basegfx::B2DVector& SdrFillGraphicAttribute::getRectPoint() const
     193             :         {
     194         160 :             return mpSdrFillGraphicAttribute->getRectPoint();
     195             :         }
     196             : 
     197         740 :         bool SdrFillGraphicAttribute::getTiling() const
     198             :         {
     199         740 :             return mpSdrFillGraphicAttribute->getTiling();
     200             :         }
     201             : 
     202         210 :         bool SdrFillGraphicAttribute::getStretch() const
     203             :         {
     204         210 :             return mpSdrFillGraphicAttribute->getStretch();
     205             :         }
     206             : 
     207         290 :         FillGraphicAttribute SdrFillGraphicAttribute::createFillGraphicAttribute(const basegfx::B2DRange& rRange) const
     208             :         {
     209             :             // get logical size of bitmap (before expanding eventually)
     210         290 :             Graphic aGraphic(getFillGraphic());
     211             : 
     212             :             // init values with defaults for stretched
     213         580 :             basegfx::B2DPoint aBitmapSize(1.0, 1.0);
     214         580 :             basegfx::B2DVector aBitmapTopLeft(0.0, 0.0);
     215             : 
     216             :             //UUUU are changes needed? When streched we are already done, all other values will have no influence
     217         290 :             if(getTiling() || !getStretch())
     218             :             {
     219             :                 // init values with range sizes
     220          80 :                 const double fRangeWidth(0.0 != rRange.getWidth() ? rRange.getWidth() : 1.0);
     221          80 :                 const double fRangeHeight(0.0 != rRange.getHeight() ? rRange.getHeight() : 1.0);
     222          80 :                 aBitmapSize = basegfx::B2DPoint(fRangeWidth, fRangeHeight);
     223             : 
     224             :                 // size changes
     225          80 :                 if(0.0 != getSize().getX())
     226             :                 {
     227           4 :                     if(getSize().getX() < 0.0)
     228             :                     {
     229           0 :                         aBitmapSize.setX(aBitmapSize.getX() * (getSize().getX() * -0.01));
     230             :                     }
     231             :                     else
     232             :                     {
     233           4 :                         aBitmapSize.setX(getSize().getX());
     234             :                     }
     235             :                 }
     236             :                 else
     237             :                 {
     238             :                     // #i124002# use GraphicLogicSize directly, do not try to use GetPrefSize
     239             :                     // of the graphic, that may not be adapted to the MapMode of the target
     240          76 :                     aBitmapSize.setX(getGraphicLogicSize().getX());
     241             :                 }
     242             : 
     243          80 :                 if(0.0 != getSize().getY())
     244             :                 {
     245           4 :                     if(getSize().getY() < 0.0)
     246             :                     {
     247           0 :                         aBitmapSize.setY(aBitmapSize.getY() * (getSize().getY() * -0.01));
     248             :                     }
     249             :                     else
     250             :                     {
     251           4 :                         aBitmapSize.setY(getSize().getY());
     252             :                     }
     253             :                 }
     254             :                 else
     255             :                 {
     256             :                     // #i124002# use GraphicLogicSize directly, do not try to use GetPrefSize
     257             :                     // of the graphic, that may not be adapted to the MapMode of the target
     258          76 :                     aBitmapSize.setY(getGraphicLogicSize().getY());
     259             :                 }
     260             : 
     261             :                 // position changes X
     262          80 :                 if(0.0 == getRectPoint().getX())
     263             :                 {
     264          80 :                     aBitmapTopLeft.setX((fRangeWidth - aBitmapSize.getX()) * 0.5);
     265             :                 }
     266           0 :                 else if(1.0 == getRectPoint().getX())
     267             :                 {
     268           0 :                     aBitmapTopLeft.setX(fRangeWidth - aBitmapSize.getX());
     269             :                 }
     270             : 
     271             :                 // offset positions are only meaningful when tiled
     272          80 :                 if(getTiling() && 0.0 != getOffsetPosition().getX())
     273             :                 {
     274           0 :                     aBitmapTopLeft.setX(aBitmapTopLeft.getX() + (aBitmapSize.getX() * (getOffsetPosition().getX() * 0.01)));
     275             :                 }
     276             : 
     277             :                 // position changes Y
     278          80 :                 if(0.0 == getRectPoint().getY())
     279             :                 {
     280          80 :                     aBitmapTopLeft.setY((fRangeHeight - aBitmapSize.getY()) * 0.5);
     281             :                 }
     282           0 :                 else if(1.0 == getRectPoint().getY())
     283             :                 {
     284           0 :                     aBitmapTopLeft.setY(fRangeHeight - aBitmapSize.getY());
     285             :                 }
     286             : 
     287             :                 // offset positions are only meaningful when tiled
     288          80 :                 if(getTiling() && 0.0 != getOffsetPosition().getY())
     289             :                 {
     290           0 :                     aBitmapTopLeft.setY(aBitmapTopLeft.getY() + (aBitmapSize.getY() * (getOffsetPosition().getY() * 0.01)));
     291             :                 }
     292             : 
     293             :                 // apply bitmap size scaling to unit rectangle
     294          80 :                 aBitmapTopLeft.setX(aBitmapTopLeft.getX() / fRangeWidth);
     295          80 :                 aBitmapTopLeft.setY(aBitmapTopLeft.getY() / fRangeHeight);
     296          80 :                 aBitmapSize.setX(aBitmapSize.getX() / fRangeWidth);
     297          80 :                 aBitmapSize.setY(aBitmapSize.getY() / fRangeHeight);
     298             :             }
     299             : 
     300             :             // get offset in percent
     301         290 :             const double fOffsetX(basegfx::clamp(getOffset().getX() * 0.01, 0.0, 1.0));
     302         290 :             const double fOffsetY(basegfx::clamp(getOffset().getY() * 0.01, 0.0, 1.0));
     303             : 
     304             :             // create FillGraphicAttribute
     305             :             return FillGraphicAttribute(
     306             :                 aGraphic,
     307         580 :                 basegfx::B2DRange(aBitmapTopLeft, aBitmapTopLeft + aBitmapSize),
     308         290 :                 getTiling(),
     309             :                 fOffsetX,
     310         870 :                 fOffsetY);
     311             :         }
     312             :     } // end of namespace attribute
     313        1143 : } // end of namespace drawinglayer
     314             : 
     315             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10