LCOV - code coverage report
Current view: top level - chart2/source/view/main - AbstractShapeFactory.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 117 142 82.4 %
Date: 2014-04-11 Functions: 16 18 88.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             : 
      10             : #include "macros.hxx"
      11             : #include "PropertyMapper.hxx"
      12             : #include "CommonConverters.hxx"
      13             : 
      14             : #include "AbstractShapeFactory.hxx"
      15             : #include <com/sun/star/beans/XPropertySet.hpp>
      16             : #include <com/sun/star/drawing/CircleKind.hpp>
      17             : #include <com/sun/star/drawing/DoubleSequence.hpp>
      18             : #include <com/sun/star/drawing/FlagSequence.hpp>
      19             : #include <com/sun/star/drawing/FillStyle.hpp>
      20             : #include <com/sun/star/drawing/LineStyle.hpp>
      21             : #include <com/sun/star/drawing/NormalsKind.hpp>
      22             : #include <com/sun/star/drawing/PointSequence.hpp>
      23             : #include <com/sun/star/drawing/PolygonKind.hpp>
      24             : #include <com/sun/star/drawing/PolyPolygonBezierCoords.hpp>
      25             : #include <com/sun/star/drawing/ProjectionMode.hpp>
      26             : #include <com/sun/star/drawing/ShadeMode.hpp>
      27             : #include <com/sun/star/drawing/TextFitToSizeType.hpp>
      28             : #include <com/sun/star/drawing/TextureProjectionMode.hpp>
      29             : #include <com/sun/star/text/XText.hpp>
      30             : #include <com/sun/star/uno/Any.hxx>
      31             : 
      32             : #include <editeng/unoprnms.hxx>
      33             : #include <rtl/math.hxx>
      34             : #include <svx/svdocirc.hxx>
      35             : #include <svx/svdopath.hxx>
      36             : #include <vcl/svapp.hxx>
      37             : 
      38             : #include <basegfx/point/b2dpoint.hxx>
      39             : #include <basegfx/matrix/b2dhommatrix.hxx>
      40             : #include <basegfx/matrix/b3dhommatrix.hxx>
      41             : 
      42             : #include <osl/module.hxx>
      43             : 
      44             : #include "OpenglShapeFactory.hxx"
      45             : #include "ShapeFactory.hxx"
      46             : 
      47             : using namespace com::sun::star;
      48             : using ::com::sun::star::uno::Reference;
      49             : 
      50             : namespace chart {
      51             : 
      52             : namespace {
      53             : 
      54             : typedef opengl::OpenglShapeFactory* (*__getOpenglShapeFactory)(void);
      55             : 
      56             : #ifndef DISABLE_DYNLOADING
      57             : 
      58           0 : static void SAL_CALL thisModule() {}
      59             : 
      60           0 : osl::Module* getOpenGLModule()
      61             : {
      62           0 :     static osl::Module aModule;
      63           0 :     if (aModule.is())
      64             :         // Already loaded.
      65           0 :         return &aModule;
      66             : 
      67           0 :     OUString aLibName(SVLIBRARY("chartopengl"));
      68           0 :     bool bLoaded = aModule.loadRelative(&thisModule, aLibName);
      69           0 :     if (!bLoaded)
      70           0 :         bLoaded = aModule.load(aLibName);
      71             : 
      72           0 :     return bLoaded ? &aModule : NULL;
      73             : }
      74             : 
      75             : #endif
      76             : 
      77             : }
      78             : 
      79             : #ifdef DISABLE_DYNLOADING
      80             : extern "C" opengl::OpenglShapeFactory* getOpenglShapeFactory();
      81             : #endif
      82             : 
      83       23948 : AbstractShapeFactory* AbstractShapeFactory::getOrCreateShapeFactory(uno::Reference< lang::XMultiServiceFactory> xFactory)
      84             : {
      85             :     static AbstractShapeFactory* pShapeFactory = NULL;
      86             : 
      87       23948 :     if(pShapeFactory)
      88       23936 :         return pShapeFactory;
      89             : 
      90          12 :     if(getenv("CHART_DUMMY_FACTORY") && !Application::IsHeadlessModeEnabled())
      91             :     {
      92             : #ifndef DISABLE_DYNLOADING
      93           0 :         osl::Module* pModule = getOpenGLModule();
      94           0 :         if(pModule)
      95             :         {
      96           0 :             oslGenericFunction fn = pModule->getFunctionSymbol("getOpenglShapeFactory");
      97           0 :             if(fn)
      98             :             {
      99             : 
     100           0 :                 pShapeFactory = reinterpret_cast<__getOpenglShapeFactory>(fn)();
     101           0 :                 pShapeFactory->setShapeFactory(xFactory);
     102             :             }
     103             :         }
     104             : #elif defined(IOS) || defined(ANDROID) // Library_chartopengl is not portable enough yet
     105             :         pShapeFactory = NULL;
     106             : #else
     107             :         pShapeFactory = getOpenglShapeFactory();
     108             :         pShapeFactory->setShapeFactory(xFactory);
     109             : #endif
     110             :     }
     111             : 
     112             : 
     113          12 :     if(!pShapeFactory)
     114          12 :         pShapeFactory = new ShapeFactory(xFactory);
     115             : 
     116          12 :     return pShapeFactory;
     117             : }
     118             : 
     119         144 : sal_Int32 AbstractShapeFactory::getSymbolCount()
     120             : {
     121         144 :     return Symbol_COUNT;
     122             : }
     123             : 
     124        1339 : uno::Reference< drawing::XShapes > AbstractShapeFactory::getChartRootShape(
     125             :     const uno::Reference< drawing::XDrawPage>& xDrawPage )
     126             : {
     127        1339 :     uno::Reference< drawing::XShapes > xRet;
     128        2678 :     uno::Reference< drawing::XShapes > xShapes( xDrawPage, uno::UNO_QUERY );
     129        1339 :     if( xShapes.is() )
     130             :     {
     131        1339 :         sal_Int32 nCount = xShapes->getCount();
     132        1339 :         uno::Reference< drawing::XShape > xShape;
     133        2678 :         for( sal_Int32 nN = nCount; nN--; )
     134             :         {
     135         732 :             if( xShapes->getByIndex( nN ) >>= xShape )
     136             :             {
     137         732 :                 if( AbstractShapeFactory::getShapeName( xShape ).equals("com.sun.star.chart2.shapes") )
     138             :                 {
     139         732 :                     xRet = uno::Reference< drawing::XShapes >( xShape, uno::UNO_QUERY );
     140         732 :                     break;
     141             :                 }
     142             :             }
     143        1339 :         }
     144             :     }
     145        2678 :     return xRet;
     146             : }
     147             : 
     148        3412 : void AbstractShapeFactory::makeShapeInvisible( const uno::Reference< drawing::XShape >& xShape )
     149             : {
     150        3412 :     uno::Reference< beans::XPropertySet > xShapeProp( xShape, uno::UNO_QUERY );
     151             :     OSL_ENSURE(xShapeProp.is(), "created shape offers no XPropertySet");
     152        3412 :     if( xShapeProp.is())
     153             :     {
     154             :         try
     155             :         {
     156        3412 :             xShapeProp->setPropertyValue( "LineStyle", uno::makeAny( drawing::LineStyle_NONE ));
     157        3412 :             xShapeProp->setPropertyValue( "FillStyle", uno::makeAny( drawing::FillStyle_NONE ));
     158             :         }
     159           0 :         catch( const uno::Exception& e )
     160             :         {
     161             :             ASSERT_EXCEPTION( e );
     162             :         }
     163        3412 :     }
     164        3412 : }
     165             : 
     166             : // set a name/CID at a shape (is used for selection handling)
     167             : 
     168       23491 : void AbstractShapeFactory::setShapeName( const uno::Reference< drawing::XShape >& xShape
     169             :                                , const OUString& rName )
     170             : {
     171       23491 :     if(!xShape.is())
     172       23491 :         return;
     173       23491 :     uno::Reference< beans::XPropertySet > xProp( xShape, uno::UNO_QUERY );
     174             :     OSL_ENSURE(xProp.is(), "shape offers no XPropertySet");
     175       23491 :     if( xProp.is())
     176             :     {
     177             :         try
     178             :         {
     179       23491 :             xProp->setPropertyValue( UNO_NAME_MISC_OBJ_NAME
     180       23491 :                 , uno::makeAny( rName ) );
     181             :         }
     182           0 :         catch( const uno::Exception& e )
     183             :         {
     184             :             ASSERT_EXCEPTION( e );
     185             :         }
     186       23491 :     }
     187             : }
     188             : 
     189         732 : OUString AbstractShapeFactory::getShapeName( const uno::Reference< drawing::XShape >& xShape )
     190             : {
     191         732 :     OUString aRet;
     192             : 
     193        1464 :     uno::Reference< beans::XPropertySet > xProp( xShape, uno::UNO_QUERY );
     194             :     OSL_ENSURE(xProp.is(), "shape offers no XPropertySet");
     195         732 :     if( xProp.is())
     196             :     {
     197             :         try
     198             :         {
     199         732 :             xProp->getPropertyValue( UNO_NAME_MISC_OBJ_NAME ) >>= aRet;
     200             :         }
     201           0 :         catch( const uno::Exception& e )
     202             :         {
     203             :             ASSERT_EXCEPTION( e );
     204             :         }
     205             :     }
     206             : 
     207        1464 :     return aRet;
     208             : }
     209             : 
     210       17293 : uno::Any AbstractShapeFactory::makeTransformation( const awt::Point& rScreenPosition2D, double fRotationAnglePi )
     211             : {
     212       17293 :     ::basegfx::B2DHomMatrix aM;
     213             :     //As autogrow is active the rectangle is automatically expanded to that side
     214             :     //to which the text is not adjusted.
     215             :     // aM.scale( 1, 1 ); Oops? A scale with this parameters is neutral, line commented out
     216       17293 :     aM.rotate( fRotationAnglePi );
     217       17293 :     aM.translate( rScreenPosition2D.X, rScreenPosition2D.Y );
     218       17293 :     uno::Any aATransformation = uno::makeAny( B2DHomMatrixToHomogenMatrix3(aM) );
     219       17293 :     return aATransformation;
     220             : }
     221             : 
     222       10349 : OUString AbstractShapeFactory::getStackedString( const OUString& rString, bool bStacked )
     223             : {
     224       10349 :     sal_Int32 nLen = rString.getLength();
     225       10349 :     if(!bStacked || !nLen)
     226       10293 :         return rString;
     227             : 
     228          56 :     OUStringBuffer aStackStr;
     229             : 
     230             :     //add a newline after each letter
     231             :     //as we do not no letters here add a newline after each char
     232         238 :     for( sal_Int32 nPosSrc=0; nPosSrc < nLen; nPosSrc++ )
     233             :     {
     234         182 :         if( nPosSrc )
     235         126 :             aStackStr.append( '\r' );
     236         182 :         aStackStr.append(rString[nPosSrc]);
     237             :     }
     238          56 :     return aStackStr.makeStringAndClear();
     239             : }
     240             : 
     241         151 : bool AbstractShapeFactory::hasPolygonAnyLines( drawing::PolyPolygonShape3D& rPoly)
     242             : {
     243             :     // #i67757# check all contained polygons, if at least one polygon contains 2 or more points, return true
     244         151 :     for( sal_Int32 nIdx = 0, nCount = rPoly.SequenceX.getLength(); nIdx < nCount; ++nIdx )
     245         151 :         if( rPoly.SequenceX[ nIdx ].getLength() > 1 )
     246         151 :             return true;
     247           0 :     return false;
     248             : }
     249             : 
     250           8 : bool AbstractShapeFactory::isPolygonEmptyOrSinglePoint( drawing::PolyPolygonShape3D& rPoly)
     251             : {
     252             :     // true, if empty polypolygon or one polygon with one point
     253          16 :     return (rPoly.SequenceX.getLength() == 0) ||
     254          24 :         ((rPoly.SequenceX.getLength() == 1) && (rPoly.SequenceX[0].getLength() <= 1));
     255             : }
     256             : 
     257           8 : void AbstractShapeFactory::closePolygon( drawing::PolyPolygonShape3D& rPoly)
     258             : {
     259             :     OSL_ENSURE( rPoly.SequenceX.getLength() <= 1, "AbstractShapeFactory::closePolygon - single polygon expected" );
     260             :     //add a last point == first point
     261           8 :     if(isPolygonEmptyOrSinglePoint(rPoly))
     262           8 :         return;
     263           8 :     drawing::Position3D aFirst(rPoly.SequenceX[0][0],rPoly.SequenceY[0][0],rPoly.SequenceZ[0][0]);
     264           8 :     AddPointToPoly( rPoly, aFirst );
     265             : }
     266             : 
     267          74 : awt::Size AbstractShapeFactory::calculateNewSizeRespectingAspectRatio(
     268             :          const awt::Size& rTargetSize
     269             :          , const awt::Size& rSourceSizeWithCorrectAspectRatio )
     270             : {
     271          74 :     awt::Size aNewSize;
     272             : 
     273          74 :     double fFactorWidth = double(rTargetSize.Width)/double(rSourceSizeWithCorrectAspectRatio.Width);
     274          74 :     double fFactorHeight = double(rTargetSize.Height)/double(rSourceSizeWithCorrectAspectRatio.Height);
     275          74 :     double fFactor = std::min(fFactorWidth,fFactorHeight);
     276          74 :     aNewSize.Width=static_cast<sal_Int32>(fFactor*rSourceSizeWithCorrectAspectRatio.Width);
     277          74 :     aNewSize.Height=static_cast<sal_Int32>(fFactor*rSourceSizeWithCorrectAspectRatio.Height);
     278             : 
     279          74 :     return aNewSize;
     280             : }
     281             : 
     282          74 : awt::Point AbstractShapeFactory::calculateTopLeftPositionToCenterObject(
     283             :            const awt::Point& rTargetAreaPosition
     284             :          , const awt::Size& rTargetAreaSize
     285             :          , const awt::Size& rObjectSize )
     286             : {
     287          74 :     awt::Point aNewPosition(rTargetAreaPosition);
     288          74 :     aNewPosition.X += static_cast<sal_Int32>(double(rTargetAreaSize.Width-rObjectSize.Width)/2.0);
     289          74 :     aNewPosition.Y += static_cast<sal_Int32>(double(rTargetAreaSize.Height-rObjectSize.Height)/2.0);
     290          74 :     return aNewPosition;
     291             : }
     292             : 
     293        1219 : ::basegfx::B2IRectangle AbstractShapeFactory::getRectangleOfShape(
     294             :         const uno::Reference< drawing::XShape >& xShape )
     295             : {
     296        1219 :     ::basegfx::B2IRectangle aRet;
     297             : 
     298        1219 :     if( xShape.is() )
     299             :     {
     300        1219 :         awt::Point aPos = xShape->getPosition();
     301        1219 :         awt::Size aSize = xShape->getSize();
     302        1219 :         aRet = BaseGFXHelper::makeRectangle(aPos,aSize);
     303             :     }
     304        1219 :     return aRet;
     305             : 
     306             : }
     307             : 
     308       10863 : awt::Size AbstractShapeFactory::getSizeAfterRotation(
     309             :          const uno::Reference< drawing::XShape >& xShape, double fRotationAngleDegree )
     310             : {
     311       10863 :     awt::Size aRet(0,0);
     312       10863 :     if(xShape.is())
     313             :     {
     314       10863 :         const awt::Size aSize( xShape->getSize() );
     315             : 
     316       10863 :         if( ::rtl::math::approxEqual( fRotationAngleDegree, 0.0 ) )
     317       10713 :             aRet = aSize;
     318             :         else
     319             :         {
     320         300 :             while(fRotationAngleDegree>=360.0)
     321           0 :                 fRotationAngleDegree-=360.0;
     322         300 :             while(fRotationAngleDegree<0.0)
     323           0 :                 fRotationAngleDegree+=360.0;
     324         150 :             if(fRotationAngleDegree>270.0)
     325           0 :                 fRotationAngleDegree=360.0-fRotationAngleDegree;
     326         150 :             else if(fRotationAngleDegree>180.0)
     327           0 :                 fRotationAngleDegree=fRotationAngleDegree-180.0;
     328         150 :             else if(fRotationAngleDegree>90.0)
     329           0 :                 fRotationAngleDegree=180.0-fRotationAngleDegree;
     330             : 
     331         150 :             const double fAnglePi = fRotationAngleDegree*F_PI/180.0;
     332             : 
     333             :             aRet.Height = static_cast<sal_Int32>(
     334         150 :                 aSize.Width*rtl::math::sin( fAnglePi )
     335         150 :                 + aSize.Height*rtl::math::cos( fAnglePi ));
     336             :             aRet.Width = static_cast<sal_Int32>(
     337         150 :                 aSize.Width*rtl::math::cos( fAnglePi )
     338         150 :                 + aSize.Height*rtl::math::sin( fAnglePi ));
     339             :         }
     340             :     }
     341       10863 :     return aRet;
     342             : }
     343             : 
     344          30 : void AbstractShapeFactory::removeSubShapes( const uno::Reference< drawing::XShapes >& xShapes )
     345             : {
     346          30 :     if( xShapes.is() )
     347             :     {
     348          30 :         sal_Int32 nSubCount = xShapes->getCount();
     349          30 :         uno::Reference< drawing::XShape > xShape;
     350         135 :         for( sal_Int32 nS = nSubCount; nS--; )
     351             :         {
     352          75 :             if( xShapes->getByIndex( nS ) >>= xShape )
     353          75 :                 xShapes->remove( xShape );
     354          30 :         }
     355             :     }
     356          30 : }
     357             : 
     358             : }
     359             : 
     360             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10