LCOV - code coverage report
Current view: top level - libreoffice/drawinglayer/source/primitive2d - baseprimitive2d.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 75 100 75.0 %
Date: 2012-12-27 Functions: 12 18 66.7 %
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        5833 :         BasePrimitive2D::BasePrimitive2D()
      35        5833 :         :   BasePrimitive2DImplBase(m_aMutex)
      36             :         {
      37        5833 :         }
      38             : 
      39        5381 :         BasePrimitive2D::~BasePrimitive2D()
      40             :         {
      41        5381 :         }
      42             : 
      43         350 :         bool BasePrimitive2D::operator==( const BasePrimitive2D& rPrimitive ) const
      44             :         {
      45         350 :             return (getPrimitive2DID() == rPrimitive.getPrimitive2DID());
      46             :         }
      47             : 
      48        1278 :         basegfx::B2DRange BasePrimitive2D::getB2DRange(const geometry::ViewInformation2D& rViewInformation) const
      49             :         {
      50        1278 :             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 )
      59             :         {
      60           0 :             const geometry::ViewInformation2D aViewInformation(rViewParameters);
      61           0 :             return get2DDecomposition(aViewInformation);
      62             :         }
      63             : 
      64           0 :         com::sun::star::geometry::RealRectangle2D SAL_CALL BasePrimitive2D::getRange( const uno::Sequence< beans::PropertyValue >& rViewParameters ) throw ( uno::RuntimeException )
      65             :         {
      66           0 :             const geometry::ViewInformation2D aViewInformation(rViewParameters);
      67           0 :             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        1922 :         BufferedDecompositionPrimitive2D::BufferedDecompositionPrimitive2D()
      84             :         :   BasePrimitive2D(),
      85        1922 :             maBuffered2DDecomposition()
      86             :         {
      87        1922 :         }
      88             : 
      89        1545 :         Primitive2DSequence BufferedDecompositionPrimitive2D::get2DDecomposition(const geometry::ViewInformation2D& rViewInformation) const
      90             :         {
      91        1545 :             ::osl::MutexGuard aGuard( m_aMutex );
      92             : 
      93        1545 :             if(!getBuffered2DDecomposition().hasElements())
      94             :             {
      95        1272 :                 const Primitive2DSequence aNewSequence(create2DDecomposition(rViewInformation));
      96        1272 :                 const_cast< BufferedDecompositionPrimitive2D* >(this)->setBuffered2DDecomposition(aNewSequence);
      97             :             }
      98             : 
      99        1545 :             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           0 :         Primitive2DSequence Primitive2DVectorToPrimitive2DSequence(const Primitive2DVector& rSource, bool bInvert)
     113             :         {
     114           0 :             const sal_uInt32 nSize(rSource.size());
     115           0 :             Primitive2DSequence aRetval;
     116             : 
     117           0 :             aRetval.realloc(nSize);
     118             : 
     119           0 :             for(sal_uInt32 a(0); a < nSize; a++)
     120             :             {
     121           0 :                 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           0 :             const_cast< Primitive2DVector& >(rSource).clear();
     128             : 
     129           0 :             return aRetval;
     130             :         }
     131             : 
     132             :         // get B2DRange from a given Primitive2DReference
     133        3111 :         basegfx::B2DRange getB2DRangeFromPrimitive2DReference(const Primitive2DReference& rCandidate, const geometry::ViewInformation2D& aViewInformation)
     134             :         {
     135        3111 :             basegfx::B2DRange aRetval;
     136             : 
     137        3111 :             if(rCandidate.is())
     138             :             {
     139             :                 // try to get C++ implementation base
     140        3111 :                 const BasePrimitive2D* pCandidate(dynamic_cast< BasePrimitive2D* >(rCandidate.get()));
     141             : 
     142        3111 :                 if(pCandidate)
     143             :                 {
     144             :                     // use it if possible
     145        3111 :                     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        3111 :             return aRetval;
     156             :         }
     157             : 
     158             :         // get B2DRange from a given Primitive2DSequence
     159        2463 :         basegfx::B2DRange getB2DRangeFromPrimitive2DSequence(const Primitive2DSequence& rCandidate, const geometry::ViewInformation2D& aViewInformation)
     160             :         {
     161        2463 :             basegfx::B2DRange aRetval;
     162             : 
     163        2463 :             if(rCandidate.hasElements())
     164             :             {
     165        2462 :                 const sal_Int32 nCount(rCandidate.getLength());
     166             : 
     167        5573 :                 for(sal_Int32 a(0L); a < nCount; a++)
     168             :                 {
     169        3111 :                     aRetval.expand(getB2DRangeFromPrimitive2DReference(rCandidate[a], aViewInformation));
     170             :                 }
     171             :             }
     172             : 
     173        2463 :             return aRetval;
     174             :         }
     175             : 
     176         350 :         bool arePrimitive2DReferencesEqual(const Primitive2DReference& rxA, const Primitive2DReference& rxB)
     177             :         {
     178         350 :             const sal_Bool bAIs(rxA.is());
     179             : 
     180         350 :             if(bAIs != rxB.is())
     181             :             {
     182           0 :                 return false;
     183             :             }
     184             : 
     185         350 :             if(!bAIs)
     186             :             {
     187           0 :                 return true;
     188             :             }
     189             : 
     190         350 :             const BasePrimitive2D* pA(dynamic_cast< const BasePrimitive2D* >(rxA.get()));
     191         350 :             const BasePrimitive2D* pB(dynamic_cast< const BasePrimitive2D* >(rxB.get()));
     192         350 :             const bool bAEqualZero(pA == 0L);
     193             : 
     194         350 :             if(bAEqualZero != (pB == 0L))
     195             :             {
     196           0 :                 return false;
     197             :             }
     198             : 
     199         350 :             if(bAEqualZero)
     200             :             {
     201           0 :                 return false;
     202             :             }
     203             : 
     204         350 :             return (pA->operator==(*pB));
     205             :         }
     206             : 
     207        1173 :         bool arePrimitive2DSequencesEqual(const Primitive2DSequence& rA, const Primitive2DSequence& rB)
     208             :         {
     209        1173 :             const sal_Bool bAHasElements(rA.hasElements());
     210             : 
     211        1173 :             if(bAHasElements != rB.hasElements())
     212             :             {
     213         494 :                 return false;
     214             :             }
     215             : 
     216         679 :             if(!bAHasElements)
     217             :             {
     218         340 :                 return true;
     219             :             }
     220             : 
     221         339 :             const sal_Int32 nCount(rA.getLength());
     222             : 
     223         339 :             if(nCount != rB.getLength())
     224             :             {
     225           8 :                 return false;
     226             :             }
     227             : 
     228         617 :             for(sal_Int32 a(0L); a < nCount; a++)
     229             :             {
     230         350 :                 if(!arePrimitive2DReferencesEqual(rA[a], rB[a]))
     231             :                 {
     232          64 :                     return false;
     233             :                 }
     234             :             }
     235             : 
     236         267 :             return true;
     237             :         }
     238             : 
     239             :         // concatenate sequence
     240        9903 :         void appendPrimitive2DSequenceToPrimitive2DSequence(Primitive2DSequence& rDest, const Primitive2DSequence& rSource)
     241             :         {
     242        9903 :             if(rSource.hasElements())
     243             :             {
     244         482 :                 if(rDest.hasElements())
     245             :                 {
     246         167 :                     const sal_Int32 nSourceCount(rSource.getLength());
     247         167 :                     const sal_Int32 nDestCount(rDest.getLength());
     248         167 :                     const sal_Int32 nTargetCount(nSourceCount + nDestCount);
     249         167 :                     sal_Int32 nInsertPos(nDestCount);
     250             : 
     251         167 :                     rDest.realloc(nTargetCount);
     252             : 
     253         335 :                     for(sal_Int32 a(0L); a < nSourceCount; a++)
     254             :                     {
     255         168 :                         if(rSource[a].is())
     256             :                         {
     257         168 :                             rDest[nInsertPos++] = rSource[a];
     258             :                         }
     259             :                     }
     260             : 
     261         167 :                     if(nInsertPos != nTargetCount)
     262             :                     {
     263           0 :                         rDest.realloc(nInsertPos);
     264             :                     }
     265             :                 }
     266             :                 else
     267             :                 {
     268         315 :                     rDest = rSource;
     269             :                 }
     270             :             }
     271        9903 :         }
     272             : 
     273             :         // concatenate single Primitive2D
     274         449 :         void appendPrimitive2DReferenceToPrimitive2DSequence(Primitive2DSequence& rDest, const Primitive2DReference& rSource)
     275             :         {
     276         449 :             if(rSource.is())
     277             :             {
     278         449 :                 const sal_Int32 nDestCount(rDest.getLength());
     279         449 :                 rDest.realloc(nDestCount + 1L);
     280         449 :                 rDest[nDestCount] = rSource;
     281             :             }
     282         449 :         }
     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