LCOV - code coverage report
Current view: top level - drawinglayer/source/primitive2d - baseprimitive2d.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 93 175 53.1 %
Date: 2014-11-03 Functions: 15 19 78.9 %
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/primitive2d/drawinglayer_primitivetypes2d.hxx>
      22             : #include <drawinglayer/geometry/viewinformation2d.hxx>
      23             : #include <basegfx/tools/canvastools.hxx>
      24             : 
      25             : 
      26             : 
      27             : using namespace com::sun::star;
      28             : 
      29             : 
      30             : 
      31             : namespace drawinglayer
      32             : {
      33             :     namespace primitive2d
      34             :     {
      35      632251 :         BasePrimitive2D::BasePrimitive2D()
      36      632251 :         :   BasePrimitive2DImplBase(m_aMutex)
      37             :         {
      38      632251 :         }
      39             : 
      40      619385 :         BasePrimitive2D::~BasePrimitive2D()
      41             :         {
      42      619385 :         }
      43             : 
      44      113666 :         bool BasePrimitive2D::operator==( const BasePrimitive2D& rPrimitive ) const
      45             :         {
      46      113666 :             return (getPrimitive2DID() == rPrimitive.getPrimitive2DID());
      47             :         }
      48             : 
      49      571754 :         basegfx::B2DRange BasePrimitive2D::getB2DRange(const geometry::ViewInformation2D& rViewInformation) const
      50             :         {
      51      571754 :             return getB2DRangeFromPrimitive2DSequence(get2DDecomposition(rViewInformation), rViewInformation);
      52             :         }
      53             : 
      54           0 :         Primitive2DSequence BasePrimitive2D::get2DDecomposition(const geometry::ViewInformation2D& /*rViewInformation*/) const
      55             :         {
      56           0 :             return Primitive2DSequence();
      57             :         }
      58             : 
      59           0 :         Primitive2DSequence SAL_CALL BasePrimitive2D::getDecomposition( const uno::Sequence< beans::PropertyValue >& rViewParameters ) throw ( uno::RuntimeException, std::exception )
      60             :         {
      61           0 :             const geometry::ViewInformation2D aViewInformation(rViewParameters);
      62           0 :             return get2DDecomposition(aViewInformation);
      63             :         }
      64             : 
      65         292 :         com::sun::star::geometry::RealRectangle2D SAL_CALL BasePrimitive2D::getRange( const uno::Sequence< beans::PropertyValue >& rViewParameters ) throw ( uno::RuntimeException, std::exception )
      66             :         {
      67         292 :             const geometry::ViewInformation2D aViewInformation(rViewParameters);
      68         292 :             return basegfx::unotools::rectangle2DFromB2DRectangle(getB2DRange(aViewInformation));
      69             :         }
      70             :     } // end of namespace primitive2d
      71             : } // end of namespace drawinglayer
      72             : 
      73             : 
      74             : 
      75             : namespace drawinglayer
      76             : {
      77             :     namespace primitive2d
      78             :     {
      79           0 :         Primitive2DSequence BufferedDecompositionPrimitive2D::create2DDecomposition(const geometry::ViewInformation2D& /*rViewInformation*/) const
      80             :         {
      81           0 :             return Primitive2DSequence();
      82             :         }
      83             : 
      84      242194 :         BufferedDecompositionPrimitive2D::BufferedDecompositionPrimitive2D()
      85             :         :   BasePrimitive2D(),
      86      242194 :             maBuffered2DDecomposition()
      87             :         {
      88      242194 :         }
      89             : 
      90      355085 :         Primitive2DSequence BufferedDecompositionPrimitive2D::get2DDecomposition(const geometry::ViewInformation2D& rViewInformation) const
      91             :         {
      92      355085 :             ::osl::MutexGuard aGuard( m_aMutex );
      93             : 
      94      355085 :             if(!getBuffered2DDecomposition().hasElements())
      95             :             {
      96      100428 :                 const Primitive2DSequence aNewSequence(create2DDecomposition(rViewInformation));
      97      100428 :                 const_cast< BufferedDecompositionPrimitive2D* >(this)->setBuffered2DDecomposition(aNewSequence);
      98             :             }
      99             : 
     100      355085 :             return getBuffered2DDecomposition();
     101             :         }
     102             :     } // end of namespace primitive2d
     103             : } // end of namespace drawinglayer
     104             : 
     105             : 
     106             : // tooling
     107             : 
     108             : namespace drawinglayer
     109             : {
     110             :     namespace primitive2d
     111             :     {
     112             :         // convert helper stl vector of primitives to Primitive2DSequence
     113        3731 :         Primitive2DSequence Primitive2DVectorToPrimitive2DSequence(const Primitive2DVector& rSource, bool bInvert)
     114             :         {
     115        3731 :             const sal_uInt32 nSize(rSource.size());
     116        3731 :             Primitive2DSequence aRetval;
     117             : 
     118        3731 :             aRetval.realloc(nSize);
     119             : 
     120        7560 :             for(sal_uInt32 a(0); a < nSize; a++)
     121             :             {
     122        3829 :                 aRetval[bInvert ? nSize - 1 - a : a] = rSource[a];
     123             :             }
     124             : 
     125             :             // all entries taken over to Uno References as owners. To avoid
     126             :             // errors with users of this mechanism to delete pointers to BasePrimitive2D
     127             :             // itself, clear given vector
     128        3731 :             const_cast< Primitive2DVector& >(rSource).clear();
     129             : 
     130        3731 :             return aRetval;
     131             :         }
     132             : 
     133             :         // get B2DRange from a given Primitive2DReference
     134     1285551 :         basegfx::B2DRange getB2DRangeFromPrimitive2DReference(const Primitive2DReference& rCandidate, const geometry::ViewInformation2D& aViewInformation)
     135             :         {
     136     1285551 :             basegfx::B2DRange aRetval;
     137             : 
     138     1285551 :             if(rCandidate.is())
     139             :             {
     140             :                 // try to get C++ implementation base
     141     1285551 :                 const BasePrimitive2D* pCandidate(dynamic_cast< BasePrimitive2D* >(rCandidate.get()));
     142             : 
     143     1285551 :                 if(pCandidate)
     144             :                 {
     145             :                     // use it if possible
     146     1285551 :                     aRetval.expand(pCandidate->getB2DRange(aViewInformation));
     147             :                 }
     148             :                 else
     149             :                 {
     150             :                     // use UNO API call instead
     151           0 :                     const uno::Sequence< beans::PropertyValue >& rViewParameters(aViewInformation.getViewInformationSequence());
     152           0 :                     aRetval.expand(basegfx::unotools::b2DRectangleFromRealRectangle2D(rCandidate->getRange(rViewParameters)));
     153             :                 }
     154             :             }
     155             : 
     156     1285551 :             return aRetval;
     157             :         }
     158             : 
     159             :         // get B2DRange from a given Primitive2DSequence
     160      843811 :         basegfx::B2DRange getB2DRangeFromPrimitive2DSequence(const Primitive2DSequence& rCandidate, const geometry::ViewInformation2D& aViewInformation)
     161             :         {
     162      843811 :             basegfx::B2DRange aRetval;
     163             : 
     164      843811 :             if(rCandidate.hasElements())
     165             :             {
     166      840425 :                 const sal_Int32 nCount(rCandidate.getLength());
     167             : 
     168     2125976 :                 for(sal_Int32 a(0L); a < nCount; a++)
     169             :                 {
     170     1285551 :                     aRetval.expand(getB2DRangeFromPrimitive2DReference(rCandidate[a], aViewInformation));
     171             :                 }
     172             :             }
     173             : 
     174      843811 :             return aRetval;
     175             :         }
     176             : 
     177      113666 :         bool arePrimitive2DReferencesEqual(const Primitive2DReference& rxA, const Primitive2DReference& rxB)
     178             :         {
     179      113666 :             const bool bAIs(rxA.is());
     180             : 
     181      113666 :             if(bAIs != rxB.is())
     182             :             {
     183           0 :                 return false;
     184             :             }
     185             : 
     186      113666 :             if(!bAIs)
     187             :             {
     188           0 :                 return true;
     189             :             }
     190             : 
     191      113666 :             const BasePrimitive2D* pA(dynamic_cast< const BasePrimitive2D* >(rxA.get()));
     192      113666 :             const BasePrimitive2D* pB(dynamic_cast< const BasePrimitive2D* >(rxB.get()));
     193      113666 :             const bool bAEqualZero(pA == 0L);
     194             : 
     195      113666 :             if(bAEqualZero != (pB == 0L))
     196             :             {
     197           0 :                 return false;
     198             :             }
     199             : 
     200      113666 :             if(bAEqualZero)
     201             :             {
     202           0 :                 return false;
     203             :             }
     204             : 
     205      113666 :             return (pA->operator==(*pB));
     206             :         }
     207             : 
     208      171813 :         bool arePrimitive2DSequencesEqual(const Primitive2DSequence& rA, const Primitive2DSequence& rB)
     209             :         {
     210      171813 :             const bool bAHasElements(rA.hasElements());
     211             : 
     212      171813 :             if(bAHasElements != rB.hasElements())
     213             :             {
     214       67774 :                 return false;
     215             :             }
     216             : 
     217      104039 :             if(!bAHasElements)
     218             :             {
     219       10046 :                 return true;
     220             :             }
     221             : 
     222       93993 :             const sal_Int32 nCount(rA.getLength());
     223             : 
     224       93993 :             if(nCount != rB.getLength())
     225             :             {
     226         392 :                 return false;
     227             :             }
     228             : 
     229      185056 :             for(sal_Int32 a(0L); a < nCount; a++)
     230             :             {
     231      113666 :                 if(!arePrimitive2DReferencesEqual(rA[a], rB[a]))
     232             :                 {
     233       22211 :                     return false;
     234             :                 }
     235             :             }
     236             : 
     237       71390 :             return true;
     238             :         }
     239             : 
     240             :         // concatenate sequence
     241      623740 :         void appendPrimitive2DSequenceToPrimitive2DSequence(Primitive2DSequence& rDest, const Primitive2DSequence& rSource)
     242             :         {
     243      623740 :             if(rSource.hasElements())
     244             :             {
     245       92021 :                 if(rDest.hasElements())
     246             :                 {
     247       40681 :                     const sal_Int32 nSourceCount(rSource.getLength());
     248       40681 :                     const sal_Int32 nDestCount(rDest.getLength());
     249       40681 :                     const sal_Int32 nTargetCount(nSourceCount + nDestCount);
     250       40681 :                     sal_Int32 nInsertPos(nDestCount);
     251             : 
     252       40681 :                     rDest.realloc(nTargetCount);
     253             : 
     254      120745 :                     for(sal_Int32 a(0L); a < nSourceCount; a++)
     255             :                     {
     256       80064 :                         if(rSource[a].is())
     257             :                         {
     258       80064 :                             rDest[nInsertPos++] = rSource[a];
     259             :                         }
     260             :                     }
     261             : 
     262       40681 :                     if(nInsertPos != nTargetCount)
     263             :                     {
     264           0 :                         rDest.realloc(nInsertPos);
     265             :                     }
     266             :                 }
     267             :                 else
     268             :                 {
     269       51340 :                     rDest = rSource;
     270             :                 }
     271             :             }
     272      623740 :         }
     273             : 
     274             :         // concatenate single Primitive2D
     275       67839 :         void appendPrimitive2DReferenceToPrimitive2DSequence(Primitive2DSequence& rDest, const Primitive2DReference& rSource)
     276             :         {
     277       67839 :             if(rSource.is())
     278             :             {
     279       67649 :                 const sal_Int32 nDestCount(rDest.getLength());
     280       67649 :                 rDest.realloc(nDestCount + 1L);
     281       67649 :                 rDest[nDestCount] = rSource;
     282             :             }
     283       67839 :         }
     284             : 
     285          40 :         OUString idToString(sal_uInt32 nId)
     286             :         {
     287          40 :             switch( nId )
     288             :             {
     289           0 :             case PRIMITIVE2D_ID_TRANSPARENCEPRIMITIVE2D: return OUString("TRANSPARENCE");
     290           0 :             case PRIMITIVE2D_ID_ANIMATEDSWITCHPRIMITIVE2D: return OUString("ANIMATEDSWITCH");
     291           0 :             case PRIMITIVE2D_ID_ANIMATEDBLINKPRIMITIVE2D: return OUString("ANIMATEDBLINK");
     292           0 :             case PRIMITIVE2D_ID_ANIMATEDINTERPOLATEPRIMITIVE2D: return OUString("ANIMATEDINTERPOLATE");
     293           0 :             case PRIMITIVE2D_ID_BACKGROUNDCOLORPRIMITIVE2D: return OUString("BACKGROUNDCOLOR");
     294           0 :             case PRIMITIVE2D_ID_BITMAPPRIMITIVE2D: return OUString("BITMAP");
     295           0 :             case PRIMITIVE2D_ID_CONTROLPRIMITIVE2D: return OUString("CONTROL");
     296           0 :             case PRIMITIVE2D_ID_EMBEDDED3DPRIMITIVE2D: return OUString("EMBEDDED3D");
     297           0 :             case PRIMITIVE2D_ID_FILLGRAPHICPRIMITIVE2D: return OUString("FILLGRAPHIC");
     298           0 :             case PRIMITIVE2D_ID_FILLGRADIENTPRIMITIVE2D: return OUString("FILLGRADIENT");
     299           0 :             case PRIMITIVE2D_ID_FILLHATCHPRIMITIVE2D: return OUString("FILLHATCH");
     300           0 :             case PRIMITIVE2D_ID_GRAPHICPRIMITIVE2D: return OUString("GRAPHIC");
     301           0 :             case PRIMITIVE2D_ID_GRIDPRIMITIVE2D: return OUString("GRID");
     302           0 :             case PRIMITIVE2D_ID_GROUPPRIMITIVE2D: return OUString("GROUP");
     303           0 :             case PRIMITIVE2D_ID_HELPLINEPRIMITIVE2D: return OUString("HELPLINE");
     304           0 :             case PRIMITIVE2D_ID_MARKERARRAYPRIMITIVE2D: return OUString("MARKERARRAY");
     305           0 :             case PRIMITIVE2D_ID_MASKPRIMITIVE2D: return OUString("MASK");
     306           0 :             case PRIMITIVE2D_ID_MEDIAPRIMITIVE2D: return OUString("MEDIA");
     307           0 :             case PRIMITIVE2D_ID_METAFILEPRIMITIVE2D: return OUString("METAFILE");
     308           0 :             case PRIMITIVE2D_ID_MODIFIEDCOLORPRIMITIVE2D: return OUString("MODIFIEDCOLOR");
     309           8 :             case PRIMITIVE2D_ID_POLYGONHAIRLINEPRIMITIVE2D: return OUString("POLYGONHAIRLINE");
     310           0 :             case PRIMITIVE2D_ID_POLYGONMARKERPRIMITIVE2D: return OUString("POLYGONMARKER");
     311           0 :             case PRIMITIVE2D_ID_POLYGONSTROKEPRIMITIVE2D: return OUString("POLYGONSTROKE");
     312           0 :             case PRIMITIVE2D_ID_POLYGONSTROKEARROWPRIMITIVE2D: return OUString("POLYGONSTROKEARROW");
     313           8 :             case PRIMITIVE2D_ID_POLYPOLYGONSTROKEPRIMITIVE2D: return OUString("POLYPOLYGONSTROKE");
     314           0 :             case PRIMITIVE2D_ID_POLYPOLYGONSTROKEARROWPRIMITIVE2D: return OUString("POLYPOLYGONSTROKEARROW");
     315           8 :             case PRIMITIVE2D_ID_POLYPOLYGONCOLORPRIMITIVE2D: return OUString("POLYPOLYGONCOLOR");
     316           0 :             case PRIMITIVE2D_ID_POLYPOLYGONGRADIENTPRIMITIVE2D: return OUString("POLYPOLYGONGRADIENT");
     317           0 :             case PRIMITIVE2D_ID_POLYPOLYGONHATCHPRIMITIVE2D: return OUString("POLYPOLYGONHATCH");
     318           0 :             case PRIMITIVE2D_ID_POLYPOLYGONGRAPHICPRIMITIVE2D: return OUString("POLYPOLYGONGRAPHIC");
     319           0 :             case PRIMITIVE2D_ID_SCENEPRIMITIVE2D: return OUString("SCENE");
     320           0 :             case PRIMITIVE2D_ID_SHADOWPRIMITIVE2D: return OUString("SHADOW");
     321           0 :             case PRIMITIVE2D_ID_TEXTSIMPLEPORTIONPRIMITIVE2D: return OUString("TEXTSIMPLEPORTION");
     322           0 :             case PRIMITIVE2D_ID_TEXTDECORATEDPORTIONPRIMITIVE2D: return OUString("TEXTDECORATEDPORTION");
     323           8 :             case PRIMITIVE2D_ID_TRANSFORMPRIMITIVE2D: return OUString("TRANSFORM");
     324           0 :             case PRIMITIVE2D_ID_UNIFIEDTRANSPARENCEPRIMITIVE2D: return OUString("UNIFIEDTRANSPARENCE");
     325           0 :             case PRIMITIVE2D_ID_POINTARRAYPRIMITIVE2D: return OUString("POINTARRAY");
     326           0 :             case PRIMITIVE2D_ID_TEXTHIERARCHYFIELDPRIMITIVE2D: return OUString("TEXTHIERARCHYFIELD");
     327           0 :             case PRIMITIVE2D_ID_TEXTHIERARCHYLINEPRIMITIVE2D: return OUString("TEXTHIERARCHYLINE");
     328           0 :             case PRIMITIVE2D_ID_TEXTHIERARCHYPARAGRAPHPRIMITIVE2D: return OUString("TEXTHIERARCHYPARAGRAPH");
     329           0 :             case PRIMITIVE2D_ID_TEXTHIERARCHYBLOCKPRIMITIVE2D: return OUString("TEXTHIERARCHYBLOCK");
     330           0 :             case PRIMITIVE2D_ID_TEXTHIERARCHYEDITPRIMITIVE2D: return OUString("TEXTHIERARCHYEDIT");
     331           0 :             case PRIMITIVE2D_ID_POLYGONWAVEPRIMITIVE2D: return OUString("POLYGONWAVE");
     332           0 :             case PRIMITIVE2D_ID_WRONGSPELLPRIMITIVE2D: return OUString("WRONGSPELL");
     333           0 :             case PRIMITIVE2D_ID_TEXTEFFECTPRIMITIVE2D: return OUString("TEXTEFFECT");
     334           0 :             case PRIMITIVE2D_ID_TEXTHIERARCHYBULLETPRIMITIVE2D: return OUString("TEXTHIERARCHYBULLET");
     335           0 :             case PRIMITIVE2D_ID_POLYPOLYGONHAIRLINEPRIMITIVE2D: return OUString("POLYPOLYGONHAIRLINE");
     336           0 :             case PRIMITIVE2D_ID_EXECUTEPRIMITIVE2D: return OUString("EXECUTE");
     337           0 :             case PRIMITIVE2D_ID_PAGEPREVIEWPRIMITIVE2D: return OUString("PAGEPREVIEW");
     338           0 :             case PRIMITIVE2D_ID_STRUCTURETAGPRIMITIVE2D: return OUString("STRUCTURETAG");
     339           0 :             case PRIMITIVE2D_ID_BORDERLINEPRIMITIVE2D: return OUString("BORDERLINE");
     340           0 :             case PRIMITIVE2D_ID_POLYPOLYGONMARKERPRIMITIVE2D: return OUString("POLYPOLYGONMARKER");
     341           0 :             case PRIMITIVE2D_ID_HITTESTPRIMITIVE2D: return OUString("HITTEST");
     342           0 :             case PRIMITIVE2D_ID_INVERTPRIMITIVE2D: return OUString("INVERT");
     343           0 :             case PRIMITIVE2D_ID_DISCRETEBITMAPPRIMITIVE2D: return OUString("DISCRETEBITMAP");
     344           0 :             case PRIMITIVE2D_ID_WALLPAPERBITMAPPRIMITIVE2D: return OUString("WALLPAPERBITMAP");
     345           0 :             case PRIMITIVE2D_ID_TEXTLINEPRIMITIVE2D: return OUString("TEXTLINE");
     346           0 :             case PRIMITIVE2D_ID_TEXTCHARACTERSTRIKEOUTPRIMITIVE2D: return OUString("TEXTCHARACTERSTRIKEOUT");
     347           0 :             case PRIMITIVE2D_ID_TEXTGEOMETRYSTRIKEOUTPRIMITIVE2D: return OUString("TEXTGEOMETRYSTRIKEOUT");
     348           0 :             case PRIMITIVE2D_ID_EPSPRIMITIVE2D: return OUString("EPS");
     349           0 :             case PRIMITIVE2D_ID_DISCRETESHADOWPRIMITIVE2D: return OUString("DISCRETESHADOW");
     350           8 :             case PRIMITIVE2D_ID_HIDDENGEOMETRYPRIMITIVE2D: return OUString("HIDDENGEOMETRY");
     351           0 :             case PRIMITIVE2D_ID_SVGLINEARGRADIENTPRIMITIVE2D: return OUString("SVGLINEARGRADIENT");
     352           0 :             case PRIMITIVE2D_ID_SVGRADIALGRADIENTPRIMITIVE2D: return OUString("SVGRADIALGRADIENT");
     353           0 :             case PRIMITIVE2D_ID_SVGLINEARATOMPRIMITIVE2D: return OUString("SVGLINEARATOM");
     354           0 :             case PRIMITIVE2D_ID_SVGRADIALATOMPRIMITIVE2D: return OUString("SVGRADIALATOM");
     355           0 :             case PRIMITIVE2D_ID_CROPPRIMITIVE2D: return OUString("CROP");
     356           0 :             case PRIMITIVE2D_ID_PATTERNFILLPRIMITIVE2D: return OUString("PATTERNFILL");
     357           0 :             case PRIMITIVE2D_ID_OBJECTINFOPRIMITIVE2D: return OUString("OBJECTINFO");
     358           0 :             case PRIMITIVE2D_ID_POLYPOLYGONSELECTIONPRIMITIVE2D: return OUString("POLYPOLYGONSELECTION");
     359           0 :             case PRIMITIVE2D_ID_CLIPPEDBORDERLINEPRIMITIVE2D: return OUString("CLIPPEDBORDERLINE");
     360           0 :             case PRIMITIVE2D_ID_OPENGLPRIMITIVE2D: return OUString("OPENGL");
     361           0 :             default: return OUString::number((nId >> 16) & 0xFF) + "|" + OUString::number(nId & 0xFF);
     362             :             }
     363             :         }
     364             :     } // end of namespace primitive2d
     365             : } // end of namespace drawinglayer
     366             : 
     367             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10