LCOV - code coverage report
Current view: top level - oox/source/drawingml/chart - chartdrawingfragment.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 93 0.0 %
Date: 2014-04-14 Functions: 0 12 0.0 %
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 "oox/drawingml/chart/chartdrawingfragment.hxx"
      21             : 
      22             : #include "oox/core/xmlfilterbase.hxx"
      23             : #include "oox/drawingml/connectorshapecontext.hxx"
      24             : #include "oox/drawingml/graphicshapecontext.hxx"
      25             : #include "oox/drawingml/shapecontext.hxx"
      26             : #include "oox/drawingml/shapegroupcontext.hxx"
      27             : 
      28             : namespace oox {
      29             : namespace drawingml {
      30             : namespace chart {
      31             : 
      32             : 
      33             : 
      34             : using namespace ::com::sun::star;
      35             : using namespace ::com::sun::star::drawing;
      36             : using namespace ::com::sun::star::uno;
      37             : using namespace ::oox::core;
      38             : 
      39             : 
      40             : 
      41           0 : ShapeAnchor::ShapeAnchor( bool bRelSize ) :
      42           0 :     mbRelSize( bRelSize )
      43             : {
      44           0 : }
      45             : 
      46           0 : void ShapeAnchor::importExt( const AttributeList& rAttribs )
      47             : {
      48             :     OSL_ENSURE( !mbRelSize, "ShapeAnchor::importExt - unexpected 'cdr:ext' element" );
      49           0 :     maSize.Width = rAttribs.getHyper( XML_cx, 0 );
      50           0 :     maSize.Height = rAttribs.getHyper( XML_cy, 0 );
      51           0 : }
      52             : 
      53           0 : void ShapeAnchor::setPos( sal_Int32 nElement, sal_Int32 nParentContext, const OUString& rValue )
      54             : {
      55           0 :     AnchorPosModel* pAnchorPos = 0;
      56           0 :     switch( nParentContext )
      57             :     {
      58             :         case CDR_TOKEN( from ):
      59           0 :             pAnchorPos = &maFrom;
      60           0 :         break;
      61             :         case CDR_TOKEN( to ):
      62             :             OSL_ENSURE( mbRelSize, "ShapeAnchor::setPos - unexpected 'cdr:to' element" );
      63           0 :             pAnchorPos = &maTo;
      64           0 :         break;
      65             :         default:
      66             :             OSL_FAIL( "ShapeAnchor::setPos - unexpected parent element" );
      67             :     }
      68           0 :     if( pAnchorPos ) switch( nElement )
      69             :     {
      70           0 :         case CDR_TOKEN( x ):    pAnchorPos->mfX = rValue.toDouble();    break;
      71           0 :         case CDR_TOKEN( y ):    pAnchorPos->mfY = rValue.toDouble();    break;
      72             :         default:    OSL_FAIL( "ShapeAnchor::setPos - unexpected element" );
      73             :     }
      74           0 : }
      75             : 
      76           0 : EmuRectangle ShapeAnchor::calcAnchorRectEmu( const EmuRectangle& rChartRect ) const
      77             : {
      78           0 :     EmuRectangle aAnchorRect( -1, -1, -1, -1 );
      79             : 
      80             :     OSL_ENSURE( maFrom.isValid(), "ShapeAnchor::calcAnchorRectEmu - invalid from position" );
      81             :     OSL_ENSURE( mbRelSize ? maTo.isValid() : maSize.isValid(), "ShapeAnchor::calcAnchorRectEmu - invalid to/size" );
      82           0 :     if( maFrom.isValid() && (mbRelSize ? maTo.isValid() : maSize.isValid()) )
      83             :     {
      84             :         // calculate shape position
      85           0 :         aAnchorRect.X = static_cast< sal_Int64 >( maFrom.mfX * rChartRect.Width + 0.5 );
      86           0 :         aAnchorRect.Y = static_cast< sal_Int64 >( maFrom.mfY * rChartRect.Height + 0.5 );
      87             : 
      88             :         // calculate shape size
      89           0 :         if( mbRelSize )
      90             :         {
      91           0 :             aAnchorRect.Width = static_cast< sal_Int64 >( maTo.mfX * rChartRect.Width + 0.5 ) - aAnchorRect.X;
      92           0 :             if( aAnchorRect.Width < 0 )
      93             :             {
      94           0 :                 aAnchorRect.X += aAnchorRect.Width;
      95           0 :                 aAnchorRect.Width *= -1;
      96             :             }
      97           0 :             aAnchorRect.Height = static_cast< sal_Int64 >( maTo.mfY * rChartRect.Height + 0.5 ) - aAnchorRect.Y;
      98           0 :             if( aAnchorRect.Height < 0 )
      99             :             {
     100           0 :                 aAnchorRect.Y += aAnchorRect.Height;
     101           0 :                 aAnchorRect.Height *= -1;
     102             :             }
     103             :         }
     104             :         else
     105             :         {
     106           0 :             aAnchorRect.setSize( maSize );
     107             :         }
     108             :     }
     109             : 
     110           0 :     return aAnchorRect;
     111             : }
     112             : 
     113             : 
     114           0 : ChartDrawingFragment::ChartDrawingFragment( XmlFilterBase& rFilter,
     115             :         const OUString& rFragmentPath, const Reference< XShapes >& rxDrawPage,
     116             :         const awt::Size& rChartSize, const awt::Point& rShapesOffset, bool bOleSupport ) :
     117             :     FragmentHandler2( rFilter, rFragmentPath ),
     118             :     mxDrawPage( rxDrawPage ),
     119           0 :     mbOleSupport( bOleSupport )
     120             : {
     121           0 :     maChartRectEmu.X = convertHmmToEmu( rShapesOffset.X );
     122           0 :     maChartRectEmu.Y = convertHmmToEmu( rShapesOffset.Y );
     123           0 :     maChartRectEmu.Width = convertHmmToEmu( rChartSize.Width );
     124           0 :     maChartRectEmu.Height = convertHmmToEmu( rChartSize.Height );
     125           0 : }
     126             : 
     127           0 : ChartDrawingFragment::~ChartDrawingFragment()
     128             : {
     129           0 : }
     130             : 
     131           0 : ContextHandlerRef ChartDrawingFragment::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
     132             : {
     133           0 :     switch( getCurrentElement() )
     134             :     {
     135             :         case XML_ROOT_CONTEXT:
     136           0 :             if( nElement == C_TOKEN( userShapes ) ) return this;
     137           0 :         break;
     138             : 
     139             :         case C_TOKEN( userShapes ):
     140           0 :             switch( nElement )
     141             :             {
     142             :                 case CDR_TOKEN( absSizeAnchor ):
     143           0 :                     mxAnchor.reset( new ShapeAnchor( false ) );
     144           0 :                     return this;
     145             :                 case CDR_TOKEN( relSizeAnchor ):
     146           0 :                     mxAnchor.reset( new ShapeAnchor( true ) );
     147           0 :                     return this;
     148             :             }
     149           0 :         break;
     150             : 
     151             :         case CDR_TOKEN( absSizeAnchor ):
     152             :         case CDR_TOKEN( relSizeAnchor ):
     153           0 :             switch( nElement )
     154             :             {
     155             :                 case CDR_TOKEN( sp ):
     156           0 :                     mxShape.reset( new Shape( "com.sun.star.drawing.CustomShape" ) );
     157           0 :                     return new ShapeContext( *this, ShapePtr(), mxShape );
     158             :                 case CDR_TOKEN( cxnSp ):
     159           0 :                     mxShape.reset( new Shape( "com.sun.star.drawing.ConnectorShape" ) );
     160           0 :                     return new ConnectorShapeContext( *this, ShapePtr(), mxShape );
     161             :                 case CDR_TOKEN( pic ):
     162           0 :                     mxShape.reset( new Shape( "com.sun.star.drawing.GraphicObjectShape" ) );
     163           0 :                     return new GraphicShapeContext( *this, ShapePtr(), mxShape );
     164             :                 case CDR_TOKEN( graphicFrame ):
     165           0 :                     if( !mbOleSupport )
     166           0 :                         return 0;
     167           0 :                     mxShape.reset( new Shape( "com.sun.star.drawing.GraphicObjectShape" ) );
     168           0 :                     return new GraphicalObjectFrameContext( *this, ShapePtr(), mxShape, true );
     169             :                 case CDR_TOKEN( grpSp ):
     170           0 :                     mxShape.reset( new Shape( "com.sun.star.drawing.GroupShape" ) );
     171           0 :                     return new ShapeGroupContext( *this, ShapePtr(), mxShape );
     172             : 
     173             :                 case CDR_TOKEN( from ):
     174             :                 case CDR_TOKEN( to ):
     175           0 :                     return this;
     176             : 
     177             :                 case CDR_TOKEN( ext ):
     178           0 :                     if( mxAnchor.get() ) mxAnchor->importExt( rAttribs );
     179           0 :                     return 0;
     180             :             }
     181           0 :         break;
     182             : 
     183             :         case CDR_TOKEN( from ):
     184             :         case CDR_TOKEN( to ):
     185           0 :             switch( nElement )
     186             :             {
     187             :                 case CDR_TOKEN( x ):
     188             :                 case CDR_TOKEN( y ):
     189           0 :                     return this;        // collect value in onEndElement()
     190             :             }
     191           0 :         break;
     192             :     }
     193           0 :     return 0;
     194             : }
     195             : 
     196           0 : void ChartDrawingFragment::onCharacters( const OUString& rChars )
     197             : {
     198           0 :     if( isCurrentElement( CDR_TOKEN( x ), CDR_TOKEN( y ) ) && mxAnchor.get() )
     199           0 :         mxAnchor->setPos( getCurrentElement(), getParentElement(), rChars );
     200           0 : }
     201             : 
     202           0 : void ChartDrawingFragment::onEndElement()
     203             : {
     204           0 :     if( isCurrentElement( CDR_TOKEN( absSizeAnchor ), CDR_TOKEN( relSizeAnchor ) ) )
     205             :     {
     206           0 :         if( mxDrawPage.is() && mxShape.get() && mxAnchor.get() )
     207             :         {
     208           0 :             EmuRectangle aShapeRectEmu = mxAnchor->calcAnchorRectEmu( maChartRectEmu );
     209           0 :             if( (aShapeRectEmu.X >= 0) && (aShapeRectEmu.Y >= 0) && (aShapeRectEmu.Width >= 0) && (aShapeRectEmu.Height >= 0) )
     210             :             {
     211             :                 // TODO: DrawingML implementation expects 32-bit coordinates for EMU rectangles (change that to EmuRectangle)
     212             :                 awt::Rectangle aShapeRectEmu32(
     213           0 :                     getLimitedValue< sal_Int32, sal_Int64 >( aShapeRectEmu.X, 0, SAL_MAX_INT32 ),
     214           0 :                     getLimitedValue< sal_Int32, sal_Int64 >( aShapeRectEmu.Y, 0, SAL_MAX_INT32 ),
     215           0 :                     getLimitedValue< sal_Int32, sal_Int64 >( aShapeRectEmu.Width, 0, SAL_MAX_INT32 ),
     216           0 :                     getLimitedValue< sal_Int32, sal_Int64 >( aShapeRectEmu.Height, 0, SAL_MAX_INT32 ) );
     217           0 :                 basegfx::B2DHomMatrix aMatrix;
     218           0 :                 mxShape->addShape( getFilter(), getFilter().getCurrentTheme(), mxDrawPage, aMatrix, mxShape->getFillProperties(), &aShapeRectEmu32 );
     219             :             }
     220             :         }
     221           0 :         mxShape.reset();
     222           0 :         mxAnchor.reset();
     223             :     }
     224           0 : }
     225             : 
     226             : 
     227             : 
     228             : } // namespace chart
     229             : } // namespace drawingml
     230           0 : } // namespace oox
     231             : 
     232             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10