LCOV - code coverage report
Current view: top level - drawinglayer/source/primitive2d - baseprimitive2d.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 95 175 54.3 %
Date: 2015-06-13 12:38:46 Functions: 16 19 84.2 %
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      851643 :         BasePrimitive2D::BasePrimitive2D()
      36      851643 :         :   BasePrimitive2DImplBase(m_aMutex)
      37             :         {
      38      851643 :         }
      39             : 
      40      844219 :         BasePrimitive2D::~BasePrimitive2D()
      41             :         {
      42      844219 :         }
      43             : 
      44      113273 :         bool BasePrimitive2D::operator==( const BasePrimitive2D& rPrimitive ) const
      45             :         {
      46      113273 :             return (getPrimitive2DID() == rPrimitive.getPrimitive2DID());
      47             :         }
      48             : 
      49     1046040 :         basegfx::B2DRange BasePrimitive2D::getB2DRange(const geometry::ViewInformation2D& rViewInformation) const
      50             :         {
      51     1046040 :             return getB2DRangeFromPrimitive2DSequence(get2DDecomposition(rViewInformation), rViewInformation);
      52             :         }
      53             : 
      54           1 :         Primitive2DSequence BasePrimitive2D::get2DDecomposition(const geometry::ViewInformation2D& /*rViewInformation*/) const
      55             :         {
      56           1 :             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         295 :         com::sun::star::geometry::RealRectangle2D SAL_CALL BasePrimitive2D::getRange( const uno::Sequence< beans::PropertyValue >& rViewParameters ) throw ( uno::RuntimeException, std::exception )
      66             :         {
      67         295 :             const geometry::ViewInformation2D aViewInformation(rViewParameters);
      68         295 :             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      284318 :         BufferedDecompositionPrimitive2D::BufferedDecompositionPrimitive2D()
      85             :         :   BasePrimitive2D(),
      86      284318 :             maBuffered2DDecomposition()
      87             :         {
      88      284318 :         }
      89             : 
      90      658042 :         Primitive2DSequence BufferedDecompositionPrimitive2D::get2DDecomposition(const geometry::ViewInformation2D& rViewInformation) const
      91             :         {
      92      658042 :             ::osl::MutexGuard aGuard( m_aMutex );
      93             : 
      94      658042 :             if(!getBuffered2DDecomposition().hasElements())
      95             :             {
      96      133261 :                 const Primitive2DSequence aNewSequence(create2DDecomposition(rViewInformation));
      97      133261 :                 const_cast< BufferedDecompositionPrimitive2D* >(this)->setBuffered2DDecomposition(aNewSequence);
      98             :             }
      99             : 
     100      658042 :             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        3432 :         Primitive2DSequence Primitive2DVectorToPrimitive2DSequence(const Primitive2DVector& rSource, bool bInvert)
     114             :         {
     115        3432 :             const sal_uInt32 nSize(rSource.size());
     116        3432 :             Primitive2DSequence aRetval;
     117             : 
     118        3432 :             aRetval.realloc(nSize);
     119             : 
     120        7383 :             for(sal_uInt32 a(0); a < nSize; a++)
     121             :             {
     122        3951 :                 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        3432 :             const_cast< Primitive2DVector& >(rSource).clear();
     129             : 
     130        3432 :             return aRetval;
     131             :         }
     132             : 
     133             :         // get B2DRange from a given Primitive2DReference
     134     2306298 :         basegfx::B2DRange getB2DRangeFromPrimitive2DReference(const Primitive2DReference& rCandidate, const geometry::ViewInformation2D& aViewInformation)
     135             :         {
     136     2306298 :             basegfx::B2DRange aRetval;
     137             : 
     138     2306298 :             if(rCandidate.is())
     139             :             {
     140             :                 // try to get C++ implementation base
     141     2306298 :                 const BasePrimitive2D* pCandidate(dynamic_cast< BasePrimitive2D* >(rCandidate.get()));
     142             : 
     143     2306298 :                 if(pCandidate)
     144             :                 {
     145             :                     // use it if possible
     146     2306298 :                     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     2306298 :             return aRetval;
     157             :         }
     158             : 
     159             :         // get B2DRange from a given Primitive2DSequence
     160     1540051 :         basegfx::B2DRange getB2DRangeFromPrimitive2DSequence(const Primitive2DSequence& rCandidate, const geometry::ViewInformation2D& aViewInformation)
     161             :         {
     162     1540051 :             basegfx::B2DRange aRetval;
     163             : 
     164     1540051 :             if(rCandidate.hasElements())
     165             :             {
     166     1537008 :                 const sal_Int32 nCount(rCandidate.getLength());
     167             : 
     168     3843306 :                 for(sal_Int32 a(0L); a < nCount; a++)
     169             :                 {
     170     2306298 :                     aRetval.expand(getB2DRangeFromPrimitive2DReference(rCandidate[a], aViewInformation));
     171             :                 }
     172             :             }
     173             : 
     174     1540051 :             return aRetval;
     175             :         }
     176             : 
     177      113273 :         bool arePrimitive2DReferencesEqual(const Primitive2DReference& rxA, const Primitive2DReference& rxB)
     178             :         {
     179      113273 :             const bool bAIs(rxA.is());
     180             : 
     181      113273 :             if(bAIs != rxB.is())
     182             :             {
     183           0 :                 return false;
     184             :             }
     185             : 
     186      113273 :             if(!bAIs)
     187             :             {
     188           0 :                 return true;
     189             :             }
     190             : 
     191      113273 :             const BasePrimitive2D* pA(dynamic_cast< const BasePrimitive2D* >(rxA.get()));
     192      113273 :             const BasePrimitive2D* pB(dynamic_cast< const BasePrimitive2D* >(rxB.get()));
     193      113273 :             const bool bAEqualZero(pA == 0L);
     194             : 
     195      113273 :             if(bAEqualZero != (pB == 0L))
     196             :             {
     197           0 :                 return false;
     198             :             }
     199             : 
     200      113273 :             if(bAEqualZero)
     201             :             {
     202           0 :                 return false;
     203             :             }
     204             : 
     205      113273 :             return (pA->operator==(*pB));
     206             :         }
     207             : 
     208      206381 :         bool arePrimitive2DSequencesEqual(const Primitive2DSequence& rA, const Primitive2DSequence& rB)
     209             :         {
     210      206381 :             const bool bAHasElements(rA.hasElements());
     211             : 
     212      206381 :             if(bAHasElements != rB.hasElements())
     213             :             {
     214       93761 :                 return false;
     215             :             }
     216             : 
     217      112620 :             if(!bAHasElements)
     218             :             {
     219        7699 :                 return true;
     220             :             }
     221             : 
     222      104921 :             const sal_Int32 nCount(rA.getLength());
     223             : 
     224      104921 :             if(nCount != rB.getLength())
     225             :             {
     226         215 :                 return false;
     227             :             }
     228             : 
     229      204734 :             for(sal_Int32 a(0L); a < nCount; a++)
     230             :             {
     231      113273 :                 if(!arePrimitive2DReferencesEqual(rA[a], rB[a]))
     232             :                 {
     233       13245 :                     return false;
     234             :                 }
     235             :             }
     236             : 
     237       91461 :             return true;
     238             :         }
     239             : 
     240             :         // concatenate sequence
     241      603496 :         void appendPrimitive2DSequenceToPrimitive2DSequence(Primitive2DSequence& rDest, const Primitive2DSequence& rSource)
     242             :         {
     243      603496 :             if(rSource.hasElements())
     244             :             {
     245      115455 :                 if(rDest.hasElements())
     246             :                 {
     247       55074 :                     const sal_Int32 nSourceCount(rSource.getLength());
     248       55074 :                     const sal_Int32 nDestCount(rDest.getLength());
     249       55074 :                     const sal_Int32 nTargetCount(nSourceCount + nDestCount);
     250       55074 :                     sal_Int32 nInsertPos(nDestCount);
     251             : 
     252       55074 :                     rDest.realloc(nTargetCount);
     253             : 
     254      211373 :                     for(sal_Int32 a(0L); a < nSourceCount; a++)
     255             :                     {
     256      156299 :                         if(rSource[a].is())
     257             :                         {
     258      156299 :                             rDest[nInsertPos++] = rSource[a];
     259             :                         }
     260             :                     }
     261             : 
     262       55074 :                     if(nInsertPos != nTargetCount)
     263             :                     {
     264           0 :                         rDest.realloc(nInsertPos);
     265             :                     }
     266             :                 }
     267             :                 else
     268             :                 {
     269       60381 :                     rDest = rSource;
     270             :                 }
     271             :             }
     272      603496 :         }
     273             : 
     274             :         // concatenate single Primitive2D
     275       86501 :         void appendPrimitive2DReferenceToPrimitive2DSequence(Primitive2DSequence& rDest, const Primitive2DReference& rSource)
     276             :         {
     277       86501 :             if(rSource.is())
     278             :             {
     279       86426 :                 const sal_Int32 nDestCount(rDest.getLength());
     280       86426 :                 rDest.realloc(nDestCount + 1L);
     281       86426 :                 rDest[nDestCount] = rSource;
     282             :             }
     283       86501 :         }
     284             : 
     285          20 :         OUString idToString(sal_uInt32 nId)
     286             :         {
     287          20 :             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           4 :             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           4 :             case PRIMITIVE2D_ID_POLYPOLYGONSTROKEPRIMITIVE2D: return OUString("POLYPOLYGONSTROKE");
     314           0 :             case PRIMITIVE2D_ID_POLYPOLYGONSTROKEARROWPRIMITIVE2D: return OUString("POLYPOLYGONSTROKEARROW");
     315           4 :             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           4 :             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           4 :             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.11