LCOV - code coverage report
Current view: top level - drawinglayer/source/primitive2d - baseprimitive2d.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 86 100 86.0 %
Date: 2014-04-11 Functions: 14 18 77.8 %
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/primitive2d/baseprimitive2d.hxx>
      21             : #include <drawinglayer/geometry/viewinformation2d.hxx>
      22             : #include <basegfx/tools/canvastools.hxx>
      23             : 
      24             : 
      25             : 
      26             : using namespace com::sun::star;
      27             : 
      28             : 
      29             : 
      30             : namespace drawinglayer
      31             : {
      32             :     namespace primitive2d
      33             :     {
      34      453562 :         BasePrimitive2D::BasePrimitive2D()
      35      453562 :         :   BasePrimitive2DImplBase(m_aMutex)
      36             :         {
      37      453562 :         }
      38             : 
      39      417511 :         BasePrimitive2D::~BasePrimitive2D()
      40             :         {
      41      417511 :         }
      42             : 
      43       67908 :         bool BasePrimitive2D::operator==( const BasePrimitive2D& rPrimitive ) const
      44             :         {
      45       67908 :             return (getPrimitive2DID() == rPrimitive.getPrimitive2DID());
      46             :         }
      47             : 
      48      569647 :         basegfx::B2DRange BasePrimitive2D::getB2DRange(const geometry::ViewInformation2D& rViewInformation) const
      49             :         {
      50      569647 :             return getB2DRangeFromPrimitive2DSequence(get2DDecomposition(rViewInformation), rViewInformation);
      51             :         }
      52             : 
      53           0 :         Primitive2DSequence BasePrimitive2D::get2DDecomposition(const geometry::ViewInformation2D& /*rViewInformation*/) const
      54             :         {
      55           0 :             return Primitive2DSequence();
      56             :         }
      57             : 
      58           0 :         Primitive2DSequence SAL_CALL BasePrimitive2D::getDecomposition( const uno::Sequence< beans::PropertyValue >& rViewParameters ) throw ( uno::RuntimeException, std::exception )
      59             :         {
      60           0 :             const geometry::ViewInformation2D aViewInformation(rViewParameters);
      61           0 :             return get2DDecomposition(aViewInformation);
      62             :         }
      63             : 
      64         292 :         com::sun::star::geometry::RealRectangle2D SAL_CALL BasePrimitive2D::getRange( const uno::Sequence< beans::PropertyValue >& rViewParameters ) throw ( uno::RuntimeException, std::exception )
      65             :         {
      66         292 :             const geometry::ViewInformation2D aViewInformation(rViewParameters);
      67         292 :             return basegfx::unotools::rectangle2DFromB2DRectangle(getB2DRange(aViewInformation));
      68             :         }
      69             :     } // end of namespace primitive2d
      70             : } // end of namespace drawinglayer
      71             : 
      72             : 
      73             : 
      74             : namespace drawinglayer
      75             : {
      76             :     namespace primitive2d
      77             :     {
      78           0 :         Primitive2DSequence BufferedDecompositionPrimitive2D::create2DDecomposition(const geometry::ViewInformation2D& /*rViewInformation*/) const
      79             :         {
      80           0 :             return Primitive2DSequence();
      81             :         }
      82             : 
      83      162355 :         BufferedDecompositionPrimitive2D::BufferedDecompositionPrimitive2D()
      84             :         :   BasePrimitive2D(),
      85      162355 :             maBuffered2DDecomposition()
      86             :         {
      87      162355 :         }
      88             : 
      89      357569 :         Primitive2DSequence BufferedDecompositionPrimitive2D::get2DDecomposition(const geometry::ViewInformation2D& rViewInformation) const
      90             :         {
      91      357569 :             ::osl::MutexGuard aGuard( m_aMutex );
      92             : 
      93      357569 :             if(!getBuffered2DDecomposition().hasElements())
      94             :             {
      95       72632 :                 const Primitive2DSequence aNewSequence(create2DDecomposition(rViewInformation));
      96       72632 :                 const_cast< BufferedDecompositionPrimitive2D* >(this)->setBuffered2DDecomposition(aNewSequence);
      97             :             }
      98             : 
      99      357569 :             return getBuffered2DDecomposition();
     100             :         }
     101             :     } // end of namespace primitive2d
     102             : } // end of namespace drawinglayer
     103             : 
     104             : 
     105             : // tooling
     106             : 
     107             : namespace drawinglayer
     108             : {
     109             :     namespace primitive2d
     110             :     {
     111             :         // convert helper stl vector of primitives to Primitive2DSequence
     112        3242 :         Primitive2DSequence Primitive2DVectorToPrimitive2DSequence(const Primitive2DVector& rSource, bool bInvert)
     113             :         {
     114        3242 :             const sal_uInt32 nSize(rSource.size());
     115        3242 :             Primitive2DSequence aRetval;
     116             : 
     117        3242 :             aRetval.realloc(nSize);
     118             : 
     119        6947 :             for(sal_uInt32 a(0); a < nSize; a++)
     120             :             {
     121        3705 :                 aRetval[bInvert ? nSize - 1 - a : a] = rSource[a];
     122             :             }
     123             : 
     124             :             // all entries taken over to Uno References as owners. To avoid
     125             :             // errors with users of this mechanism to delete pointers to BasePrimitive2D
     126             :             // itself, clear given vector
     127        3242 :             const_cast< Primitive2DVector& >(rSource).clear();
     128             : 
     129        3242 :             return aRetval;
     130             :         }
     131             : 
     132             :         // get B2DRange from a given Primitive2DReference
     133     1252103 :         basegfx::B2DRange getB2DRangeFromPrimitive2DReference(const Primitive2DReference& rCandidate, const geometry::ViewInformation2D& aViewInformation)
     134             :         {
     135     1252103 :             basegfx::B2DRange aRetval;
     136             : 
     137     1252103 :             if(rCandidate.is())
     138             :             {
     139             :                 // try to get C++ implementation base
     140     1252103 :                 const BasePrimitive2D* pCandidate(dynamic_cast< BasePrimitive2D* >(rCandidate.get()));
     141             : 
     142     1252103 :                 if(pCandidate)
     143             :                 {
     144             :                     // use it if possible
     145     1252103 :                     aRetval.expand(pCandidate->getB2DRange(aViewInformation));
     146             :                 }
     147             :                 else
     148             :                 {
     149             :                     // use UNO API call instead
     150           0 :                     const uno::Sequence< beans::PropertyValue >& rViewParameters(aViewInformation.getViewInformationSequence());
     151           0 :                     aRetval.expand(basegfx::unotools::b2DRectangleFromRealRectangle2D(rCandidate->getRange(rViewParameters)));
     152             :                 }
     153             :             }
     154             : 
     155     1252103 :             return aRetval;
     156             :         }
     157             : 
     158             :         // get B2DRange from a given Primitive2DSequence
     159      827590 :         basegfx::B2DRange getB2DRangeFromPrimitive2DSequence(const Primitive2DSequence& rCandidate, const geometry::ViewInformation2D& aViewInformation)
     160             :         {
     161      827590 :             basegfx::B2DRange aRetval;
     162             : 
     163      827590 :             if(rCandidate.hasElements())
     164             :             {
     165      825240 :                 const sal_Int32 nCount(rCandidate.getLength());
     166             : 
     167     2077343 :                 for(sal_Int32 a(0L); a < nCount; a++)
     168             :                 {
     169     1252103 :                     aRetval.expand(getB2DRangeFromPrimitive2DReference(rCandidate[a], aViewInformation));
     170             :                 }
     171             :             }
     172             : 
     173      827590 :             return aRetval;
     174             :         }
     175             : 
     176       67908 :         bool arePrimitive2DReferencesEqual(const Primitive2DReference& rxA, const Primitive2DReference& rxB)
     177             :         {
     178       67908 :             const bool bAIs(rxA.is());
     179             : 
     180       67908 :             if(bAIs != rxB.is())
     181             :             {
     182           0 :                 return false;
     183             :             }
     184             : 
     185       67908 :             if(!bAIs)
     186             :             {
     187           0 :                 return true;
     188             :             }
     189             : 
     190       67908 :             const BasePrimitive2D* pA(dynamic_cast< const BasePrimitive2D* >(rxA.get()));
     191       67908 :             const BasePrimitive2D* pB(dynamic_cast< const BasePrimitive2D* >(rxB.get()));
     192       67908 :             const bool bAEqualZero(pA == 0L);
     193             : 
     194       67908 :             if(bAEqualZero != (pB == 0L))
     195             :             {
     196           0 :                 return false;
     197             :             }
     198             : 
     199       67908 :             if(bAEqualZero)
     200             :             {
     201           0 :                 return false;
     202             :             }
     203             : 
     204       67908 :             return (pA->operator==(*pB));
     205             :         }
     206             : 
     207      112111 :         bool arePrimitive2DSequencesEqual(const Primitive2DSequence& rA, const Primitive2DSequence& rB)
     208             :         {
     209      112111 :             const bool bAHasElements(rA.hasElements());
     210             : 
     211      112111 :             if(bAHasElements != rB.hasElements())
     212             :             {
     213       50979 :                 return false;
     214             :             }
     215             : 
     216       61132 :             if(!bAHasElements)
     217             :             {
     218        4320 :                 return true;
     219             :             }
     220             : 
     221       56812 :             const sal_Int32 nCount(rA.getLength());
     222             : 
     223       56812 :             if(nCount != rB.getLength())
     224             :             {
     225         100 :                 return false;
     226             :             }
     227             : 
     228      117209 :             for(sal_Int32 a(0L); a < nCount; a++)
     229             :             {
     230       67908 :                 if(!arePrimitive2DReferencesEqual(rA[a], rB[a]))
     231             :                 {
     232        7411 :                     return false;
     233             :                 }
     234             :             }
     235             : 
     236       49301 :             return true;
     237             :         }
     238             : 
     239             :         // concatenate sequence
     240      199239 :         void appendPrimitive2DSequenceToPrimitive2DSequence(Primitive2DSequence& rDest, const Primitive2DSequence& rSource)
     241             :         {
     242      199239 :             if(rSource.hasElements())
     243             :             {
     244       71313 :                 if(rDest.hasElements())
     245             :                 {
     246       32918 :                     const sal_Int32 nSourceCount(rSource.getLength());
     247       32918 :                     const sal_Int32 nDestCount(rDest.getLength());
     248       32918 :                     const sal_Int32 nTargetCount(nSourceCount + nDestCount);
     249       32918 :                     sal_Int32 nInsertPos(nDestCount);
     250             : 
     251       32918 :                     rDest.realloc(nTargetCount);
     252             : 
     253      113601 :                     for(sal_Int32 a(0L); a < nSourceCount; a++)
     254             :                     {
     255       80683 :                         if(rSource[a].is())
     256             :                         {
     257       80683 :                             rDest[nInsertPos++] = rSource[a];
     258             :                         }
     259             :                     }
     260             : 
     261       32918 :                     if(nInsertPos != nTargetCount)
     262             :                     {
     263           0 :                         rDest.realloc(nInsertPos);
     264             :                     }
     265             :                 }
     266             :                 else
     267             :                 {
     268       38395 :                     rDest = rSource;
     269             :                 }
     270             :             }
     271      199239 :         }
     272             : 
     273             :         // concatenate single Primitive2D
     274       47501 :         void appendPrimitive2DReferenceToPrimitive2DSequence(Primitive2DSequence& rDest, const Primitive2DReference& rSource)
     275             :         {
     276       47501 :             if(rSource.is())
     277             :             {
     278       47501 :                 const sal_Int32 nDestCount(rDest.getLength());
     279       47501 :                 rDest.realloc(nDestCount + 1L);
     280       47501 :                 rDest[nDestCount] = rSource;
     281             :             }
     282       47501 :         }
     283             : 
     284             :     } // end of namespace primitive2d
     285             : } // end of namespace drawinglayer
     286             : 
     287             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10