LCOV - code coverage report
Current view: top level - filter/source/msfilter - msdffimp.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 1972 3854 51.2 %
Date: 2014-11-03 Functions: 90 105 85.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 <com/sun/star/embed/Aspects.hpp>
      21             : 
      22             : #include <math.h>
      23             : #include <limits.h>
      24             : #include <vector>
      25             : #include <osl/endian.h>
      26             : #include <tools/solar.h>
      27             : #include <rtl/math.hxx>
      28             : 
      29             : #include <comphelper/classids.hxx>
      30             : #include <toolkit/helper/vclunohelper.hxx>
      31             : #include <unotools/streamwrap.hxx>
      32             : #include <comphelper/processfactory.hxx>
      33             : #include <comphelper/string.hxx>
      34             : #include <comphelper/seqstream.hxx>
      35             : #include <comphelper/storagehelper.hxx>
      36             : #include <sot/exchange.hxx>
      37             : #include <sot/storinfo.hxx>
      38             : #include <vcl/cvtgrf.hxx>
      39             : #include <vcl/wmf.hxx>
      40             : #include <vcl/settings.hxx>
      41             : #include "viscache.hxx"
      42             : 
      43             : // SvxItem-Mapping. Is needed to successfully include the SvxItem-Header
      44             : #include <editeng/eeitem.hxx>
      45             : #include <editeng/editdata.hxx>
      46             : #include <svl/urihelper.hxx>
      47             : #include <tools/stream.hxx>
      48             : #include <tools/debug.hxx>
      49             : #include <tools/zcodec.hxx>
      50             : #include <unotools/ucbstreamhelper.hxx>
      51             : #include <unotools/localfilehelper.hxx>
      52             : #include <filter/msfilter/escherex.hxx>
      53             : #include <basegfx/range/b2drange.hxx>
      54             : #include <com/sun/star/container/XIdentifierContainer.hpp>
      55             : #include <com/sun/star/drawing/XGluePointsSupplier.hpp>
      56             : #include <com/sun/star/drawing/Position3D.hpp>
      57             : #include <com/sun/star/drawing/Direction3D.hpp>
      58             : #include <com/sun/star/drawing/GluePoint2.hpp>
      59             : #include <com/sun/star/drawing/XShapes.hpp>
      60             : #include <editeng/charscaleitem.hxx>
      61             : #include <editeng/kernitem.hxx>
      62             : #include <vcl/graphicfilter.hxx>
      63             : #include <tools/urlobj.hxx>
      64             : #include <vcl/virdev.hxx>
      65             : #include <vcl/bmpacc.hxx>
      66             : #include <sot/storage.hxx>
      67             : #include <sfx2/docfac.hxx>
      68             : #include <sfx2/docfilt.hxx>
      69             : #include <sfx2/docfile.hxx>
      70             : #include <sfx2/fcontnr.hxx>
      71             : #include <sfx2/module.hxx>
      72             : #include <svx/sdgcpitm.hxx>
      73             : #include <svx/sdgmoitm.hxx>
      74             : #include <editeng/tstpitem.hxx>
      75             : #include <svx/fmmodel.hxx>
      76             : #include <svx/svdmodel.hxx>
      77             : #include <svx/svdobj.hxx>
      78             : #include <svx/svdpage.hxx>
      79             : #include <svx/svdogrp.hxx>
      80             : #include <svx/svdograf.hxx>
      81             : #include <svx/svdotext.hxx>
      82             : #include <svx/svdorect.hxx>
      83             : #include <svx/svdocapt.hxx>
      84             : #include <svx/svdoedge.hxx>
      85             : #include <svx/svdocirc.hxx>
      86             : #include <svx/svdoutl.hxx>
      87             : #include <svx/svdoole2.hxx>
      88             : #include <svx/svdopath.hxx>
      89             : #include <editeng/frmdir.hxx>
      90             : #include <editeng/frmdiritem.hxx>
      91             : #include <svx/svdtrans.hxx>
      92             : #include <svx/sxenditm.hxx>
      93             : #include <svx/sdgluitm.hxx>
      94             : #include <editeng/fhgtitem.hxx>
      95             : #include <editeng/wghtitem.hxx>
      96             : #include <editeng/postitem.hxx>
      97             : #include <editeng/udlnitem.hxx>
      98             : #include <editeng/crossedoutitem.hxx>
      99             : #include <editeng/shdditem.hxx>
     100             : #include <editeng/fontitem.hxx>
     101             : #include <editeng/colritem.hxx>
     102             : #include <svx/sxekitm.hxx>
     103             : #include <editeng/bulletitem.hxx>
     104             : #include <svx/polysc3d.hxx>
     105             : #include <svx/extrud3d.hxx>
     106             : #include "svx/svditer.hxx"
     107             : #include <svx/xpoly.hxx>
     108             : #include "svx/xattr.hxx"
     109             : #include <filter/msfilter/msdffimp.hxx>
     110             : #include <editeng/outliner.hxx>
     111             : #include <editeng/outlobj.hxx>
     112             : #include <editeng/editobj.hxx>
     113             : #include <editeng/editeng.hxx>
     114             : #include "svx/gallery.hxx"
     115             : #include <com/sun/star/drawing/ShadeMode.hpp>
     116             : #include <svl/itempool.hxx>
     117             : #include <vcl/dibtools.hxx>
     118             : #include <vcl/svapp.hxx>
     119             : #include <svx/svx3ditems.hxx>
     120             : #include <svx/svdoashp.hxx>
     121             : #include <svx/sdasaitm.hxx>
     122             : #include "svx/EnhancedCustomShapeTypeNames.hxx"
     123             : #include "svx/EnhancedCustomShapeGeometry.hxx"
     124             : #include <com/sun/star/drawing/EnhancedCustomShapeParameterPair.hpp>
     125             : #include <com/sun/star/drawing/EnhancedCustomShapeParameterType.hpp>
     126             : #include <com/sun/star/drawing/EnhancedCustomShapeSegment.hpp>
     127             : #include <com/sun/star/drawing/EnhancedCustomShapeGluePointType.hpp>
     128             : #include <com/sun/star/drawing/EnhancedCustomShapeSegmentCommand.hpp>
     129             : #include <com/sun/star/drawing/EnhancedCustomShapeTextFrame.hpp>
     130             : #include <com/sun/star/drawing/EnhancedCustomShapeAdjustmentValue.hpp>
     131             : #include <com/sun/star/drawing/EnhancedCustomShapeTextPathMode.hpp>
     132             : #include <com/sun/star/beans/PropertyValues.hpp>
     133             : #include <com/sun/star/drawing/ProjectionMode.hpp>
     134             : #include "svx/EnhancedCustomShape2d.hxx"
     135             : #include <svx/xbitmap.hxx>
     136             : #include <rtl/strbuf.hxx>
     137             : #include <rtl/ustring.hxx>
     138             : #include <svtools/embedhlp.hxx>
     139             : #include <boost/scoped_array.hpp>
     140             : #include <boost/scoped_ptr.hpp>
     141             : 
     142             : using namespace ::com::sun::star    ;
     143             : using namespace ::com::sun::star::drawing;
     144             : using namespace uno                 ;
     145             : using namespace beans               ;
     146             : using namespace drawing             ;
     147             : using namespace container           ;
     148             : 
     149             : // static counter for OLE-Objects
     150             : static sal_uInt32 nMSOleObjCntr = 0;
     151             : #define MSO_OLE_Obj "MSO_OLE_Obj"
     152             : 
     153             : /************************************************************************/
     154           0 : void Impl_OlePres::Write( SvStream & rStm )
     155             : {
     156           0 :     WriteClipboardFormat( rStm, FORMAT_GDIMETAFILE );
     157           0 :     rStm.WriteInt32( (nJobLen +4) );       // a TargetDevice that's always empty
     158           0 :     if( nJobLen )
     159           0 :         rStm.Write( pJob, nJobLen );
     160           0 :     rStm.WriteUInt32( nAspect );
     161           0 :     rStm.WriteInt32( -1 );      //L-Index always -1
     162           0 :     rStm.WriteInt32( nAdvFlags );
     163           0 :     rStm.WriteInt32( 0 );       //Compression
     164           0 :     rStm.WriteInt32( aSize.Width() );
     165           0 :     rStm.WriteInt32( aSize.Height() );
     166           0 :     sal_uLong nPos = rStm.Tell();
     167           0 :     rStm.WriteInt32( 0 );
     168             : 
     169           0 :     if( GetFormat() == FORMAT_GDIMETAFILE && pMtf )
     170             :     {
     171             :         // Always to 1/100 mm, until Mtf-Solution found
     172             :         // Assumption (no scaling, no origin translation)
     173             :         DBG_ASSERT( pMtf->GetPrefMapMode().GetScaleX() == Fraction( 1, 1 ),
     174             :                     "X-Skalierung im Mtf" );
     175             :         DBG_ASSERT( pMtf->GetPrefMapMode().GetScaleY() == Fraction( 1, 1 ),
     176             :                     "Y-Skalierung im Mtf" );
     177             :         DBG_ASSERT( pMtf->GetPrefMapMode().GetOrigin() == Point(),
     178             :                     "Origin-Verschiebung im Mtf" );
     179           0 :         MapUnit nMU = pMtf->GetPrefMapMode().GetMapUnit();
     180           0 :         if( MAP_100TH_MM != nMU )
     181             :         {
     182           0 :             Size aPrefS( pMtf->GetPrefSize() );
     183           0 :             Size aS( aPrefS );
     184           0 :             aS = OutputDevice::LogicToLogic( aS, nMU, MAP_100TH_MM );
     185             : 
     186           0 :             pMtf->Scale( Fraction( aS.Width(), aPrefS.Width() ),
     187           0 :                          Fraction( aS.Height(), aPrefS.Height() ) );
     188           0 :             pMtf->SetPrefMapMode( MAP_100TH_MM );
     189           0 :             pMtf->SetPrefSize( aS );
     190             :         }
     191           0 :         WriteWindowMetafileBits( rStm, *pMtf );
     192             :     }
     193             :     else
     194             :     {
     195             :         OSL_FAIL( "unknown format" );
     196             :     }
     197           0 :     sal_uLong nEndPos = rStm.Tell();
     198           0 :     rStm.Seek( nPos );
     199           0 :     rStm.WriteUInt32( (nEndPos - nPos - 4) );
     200           0 :     rStm.Seek( nEndPos );
     201           0 : }
     202             : 
     203        1364 : DffPropertyReader::DffPropertyReader( const SvxMSDffManager& rMan )
     204             :     : rManager(rMan)
     205             :     , pDefaultPropSet(NULL)
     206             :     , mnFix16Angle(0)
     207        1364 :     , mbRotateGranientFillWithAngle(false)
     208             : {
     209        1364 :     InitializePropSet( DFF_msofbtOPT );
     210        1364 : }
     211             : 
     212         388 : void DffPropertyReader::SetDefaultPropSet( SvStream& rStCtrl, sal_uInt32 nOffsDgg ) const
     213             : {
     214         388 :     delete pDefaultPropSet;
     215         388 :     sal_uInt32 nMerk = rStCtrl.Tell();
     216         388 :     rStCtrl.Seek( nOffsDgg );
     217         388 :     DffRecordHeader aRecHd;
     218         388 :     ReadDffRecordHeader( rStCtrl, aRecHd );
     219         388 :     if ( aRecHd.nRecType == DFF_msofbtDggContainer )
     220             :     {
     221         152 :         if ( rManager.SeekToRec( rStCtrl, DFF_msofbtOPT, aRecHd.GetRecEndFilePos() ) )
     222             :         {
     223         100 :             ( (DffPropertyReader*) this )->pDefaultPropSet = new DffPropSet;
     224         100 :             ReadDffPropSet( rStCtrl, *pDefaultPropSet );
     225             :         }
     226             :     }
     227         388 :     rStCtrl.Seek( nMerk );
     228         388 : }
     229             : 
     230             : #ifdef DBG_CUSTOMSHAPE
     231             : void DffPropertyReader::ReadPropSet( SvStream& rIn, void* pClientData, sal_uInt32 nShapeId ) const
     232             : #else
     233        4634 : void DffPropertyReader::ReadPropSet( SvStream& rIn, void* pClientData ) const
     234             : #endif
     235             : {
     236        4634 :     sal_uLong nFilePos = rIn.Tell();
     237        4634 :     ReadDffPropSet( rIn, (DffPropertyReader&)*this );
     238             : 
     239        4634 :     if ( IsProperty( DFF_Prop_hspMaster ) )
     240             :     {
     241         200 :         if ( rManager.SeekToShape( rIn, pClientData, GetPropertyValue( DFF_Prop_hspMaster ) ) )
     242             :         {
     243         200 :             DffRecordHeader aRecHd;
     244         200 :             ReadDffRecordHeader( rIn, aRecHd );
     245         200 :             if ( rManager.SeekToRec( rIn, DFF_msofbtOPT, aRecHd.GetRecEndFilePos() ) )
     246             :             {
     247         200 :                 rIn |= (DffPropertyReader&)*this;
     248             :             }
     249             :         }
     250             :     }
     251             : 
     252        4634 :     ( (DffPropertyReader*) this )->mnFix16Angle = Fix16ToAngle( GetPropertyValue( DFF_Prop_Rotation, 0 ) );
     253             : 
     254             : #ifdef DBG_CUSTOMSHAPE
     255             : 
     256             :     OUString aURLStr;
     257             : 
     258             :     if( ::utl::LocalFileHelper::ConvertPhysicalNameToURL( OUString("d:\\ashape.dbg"), aURLStr ) )
     259             :     {
     260             :         boost::scoped_ptr<SvStream> pOut(::utl::UcbStreamHelper::CreateStream( aURLStr, STREAM_WRITE ));
     261             : 
     262             :         if( pOut )
     263             :         {
     264             :             pOut->Seek( STREAM_SEEK_TO_END );
     265             : 
     266             :             if ( IsProperty( DFF_Prop_adjustValue ) || IsProperty( DFF_Prop_pVertices ) )
     267             :             {
     268             :                 pOut->WriteLine( "" );
     269             :                 OString aString("ShapeId: " + OString::number(nShapeId));
     270             :                 pOut->WriteLine(aString);
     271             :             }
     272             :             for ( sal_uInt32 i = DFF_Prop_adjustValue; i <= DFF_Prop_adjust10Value; i++ )
     273             :             {
     274             :                 if ( IsProperty( i ) )
     275             :                 {
     276             :                     OString aString("Prop_adjustValue" + OString::number( ( i - DFF_Prop_adjustValue ) + 1 ) +
     277             :                                     ":" + OString::number(GetPropertyValue(i)) );
     278             :                     pOut->WriteLine(aString);
     279             :                 }
     280             :             }
     281             :             sal_Int32 i;
     282             :             for ( i = 320; i < 383; i++ )
     283             :             {
     284             :                 if ( ( i >= DFF_Prop_adjustValue ) && ( i <= DFF_Prop_adjust10Value ) )
     285             :                     continue;
     286             :                 if ( IsProperty( i ) )
     287             :                 {
     288             :                     if ( SeekToContent( i, rIn ) )
     289             :                     {
     290             :                         sal_Int32 nLen = (sal_Int32)GetPropertyValue( i );
     291             :                         if ( nLen )
     292             :                         {
     293             :                             pOut->WriteLine( "" );
     294             :                             OStringBuffer aDesc("Property:" + OString::number(i) +
     295             :                                                 "  Size:" + OString::number(nLen));
     296             :                             pOut->WriteLine(aDesc.makeStringAndClear());
     297             :                             sal_Int16   nNumElem, nNumElemMem, nNumSize;
     298             :                             rIn >> nNumElem >> nNumElemMem >> nNumSize;
     299             :                             aDesc.append("Entries: " + OString::number(nNumElem) +
     300             :                                          "  Size:" + OString::number(nNumSize));
     301             :                             pOut->WriteLine(aDesc.makeStringAndClear());
     302             :                             if ( nNumSize < 0 )
     303             :                                 nNumSize = ( ( -nNumSize ) >> 2 );
     304             :                             if ( !nNumSize )
     305             :                                 nNumSize = 16;
     306             :                             nLen -= 6;
     307             :                             while ( nLen > 0 )
     308             :                             {
     309             :                                 for ( sal_uInt32 j = 0; nLen && ( j < ( nNumSize >> 1 ) ); j++ )
     310             :                                 {
     311             :                                     for ( sal_uInt32 k = 0; k < 2; k++ )
     312             :                                     {
     313             :                                         if ( nLen )
     314             :                                         {
     315             :                                             sal_uInt8 nVal;
     316             :                                             rIn >> nVal;
     317             :                                             if ( ( nVal >> 4 ) > 9 )
     318             :                                                 *pOut << (sal_uInt8)( ( nVal >> 4 ) + 'A' - 10 );
     319             :                                             else
     320             :                                                 *pOut << (sal_uInt8)( ( nVal >> 4 ) + '0' );
     321             : 
     322             :                                             if ( ( nVal & 0xf ) > 9 )
     323             :                                                 *pOut << (sal_uInt8)( ( nVal & 0xf ) + 'A' - 10 );
     324             :                                             else
     325             :                                                 *pOut << (sal_uInt8)( ( nVal & 0xf ) + '0' );
     326             : 
     327             :                                             nLen--;
     328             :                                         }
     329             :                                     }
     330             :                                     *pOut << (char)( ' ' );
     331             :                                 }
     332             :                                 pOut->WriteLine( OString() );
     333             :                             }
     334             :                         }
     335             :                     }
     336             :                     else
     337             :                     {
     338             :                         OString aString("Property" + OString::number(i) +
     339             :                                         ":" + OString::number(GetPropertyValue(i)));
     340             :                         pOut->WriteLine(aString);
     341             :                     }
     342             :                 }
     343             :             }
     344             :         }
     345             :     }
     346             : 
     347             : #endif
     348             : 
     349        4634 :     rIn.Seek( nFilePos );
     350        4634 : }
     351             : 
     352             : 
     353        4676 : sal_Int32 DffPropertyReader::Fix16ToAngle( sal_Int32 nContent ) const
     354             : {
     355        4676 :     sal_Int32 nAngle = 0;
     356        4676 :     if ( nContent )
     357             :     {
     358          20 :         nAngle = ( (sal_Int16)( nContent >> 16) * 100L ) + ( ( ( nContent & 0x0000ffff) * 100L ) >> 16 );
     359          20 :         nAngle = NormAngle360( -nAngle );
     360             :     }
     361        4676 :     return nAngle;
     362             : }
     363             : 
     364        2728 : DffPropertyReader::~DffPropertyReader()
     365             : {
     366        1364 :     delete pDefaultPropSet;
     367        1364 : }
     368             : 
     369             : 
     370             : 
     371           4 : SvStream& operator>>( SvStream& rIn, SvxMSDffConnectorRule& rRule )
     372             : {
     373           4 :     rIn.ReadUInt32( rRule.nRuleId )
     374           8 :        .ReadUInt32( rRule.nShapeA )
     375           8 :        .ReadUInt32( rRule.nShapeB )
     376           8 :        .ReadUInt32( rRule.nShapeC )
     377           8 :        .ReadUInt32( rRule.ncptiA )
     378           8 :        .ReadUInt32( rRule.ncptiB );
     379             : 
     380           4 :     return rIn;
     381             : }
     382             : 
     383         256 : SvxMSDffSolverContainer::SvxMSDffSolverContainer()
     384             : {
     385         256 : }
     386             : 
     387         512 : SvxMSDffSolverContainer::~SvxMSDffSolverContainer()
     388             : {
     389         260 :     for( size_t i = 0, n = aCList.size(); i < n; ++i ) {
     390           4 :         delete aCList[ i ];
     391             :     }
     392         256 :     aCList.clear();
     393         256 : }
     394             : 
     395          18 : SvStream& ReadSvxMSDffSolverContainer( SvStream& rIn, SvxMSDffSolverContainer& rContainer )
     396             : {
     397          18 :     DffRecordHeader aHd;
     398          18 :     ReadDffRecordHeader( rIn, aHd );
     399          18 :     if ( aHd.nRecType == DFF_msofbtSolverContainer )
     400             :     {
     401          18 :         DffRecordHeader aCRule;
     402          54 :         while ( ( rIn.GetError() == 0 ) && ( rIn.Tell() < aHd.GetRecEndFilePos() ) )
     403             :         {
     404          18 :             ReadDffRecordHeader( rIn, aCRule );
     405          18 :             if ( aCRule.nRecType == DFF_msofbtConnectorRule )
     406             :             {
     407           4 :                 SvxMSDffConnectorRule* pRule = new SvxMSDffConnectorRule;
     408           4 :                 rIn >> *pRule;
     409           4 :                 rContainer.aCList.push_back( pRule );
     410             :             }
     411          18 :             aCRule.SeekToEndOfRecord( rIn );
     412             :         }
     413             :     }
     414          18 :     return rIn;
     415             : }
     416             : 
     417         256 : void SvxMSDffManager::SolveSolver( const SvxMSDffSolverContainer& rSolver )
     418             : {
     419             :     size_t i, nCnt;
     420         260 :     for ( i = 0, nCnt = rSolver.aCList.size(); i < nCnt; i++ )
     421             :     {
     422           4 :         SvxMSDffConnectorRule* pPtr = rSolver.aCList[ i ];
     423           4 :         if ( pPtr->pCObj )
     424             :         {
     425          12 :             for ( int nN = 0; nN < 2; nN++ )
     426             :             {
     427             :                 SdrObject*  pO;
     428             :                 sal_uInt32  nC, nSpFlags;
     429           8 :                 if ( !nN )
     430             :                 {
     431           4 :                     pO = pPtr->pAObj;
     432           4 :                     nC = pPtr->ncptiA;
     433           4 :                     nSpFlags = pPtr->nSpFlagsA;
     434             :                 }
     435             :                 else
     436             :                 {
     437           4 :                     pO = pPtr->pBObj;
     438           4 :                     nC = pPtr->ncptiB;
     439           4 :                     nSpFlags = pPtr->nSpFlagsB;
     440             :                 }
     441           8 :                 if ( pO )
     442             :                 {
     443           8 :                     Any aAny;
     444           8 :                     SdrGluePoint aGluePoint;
     445          16 :                     Reference< XShape > aXShape( pO->getUnoShape(), UNO_QUERY );
     446          16 :                     Reference< XShape > aXConnector( pPtr->pCObj->getUnoShape(), UNO_QUERY );
     447           8 :                     SdrGluePointList* pList = pO->ForceGluePointList();
     448             : 
     449           8 :                     bool bValidGluePoint = false;
     450           8 :                     sal_Int32 nId = nC;
     451           8 :                     sal_uInt32 nInventor = pO->GetObjInventor();
     452             : 
     453           8 :                     if( nInventor == SdrInventor )
     454             :                     {
     455           8 :                         sal_uInt32 nObjId = pO->GetObjIdentifier();
     456           8 :                         switch( nObjId )
     457             :                         {
     458             :                             case OBJ_GRUP :
     459             :                             case OBJ_GRAF :
     460             :                             case OBJ_RECT :
     461             :                             case OBJ_TEXT :
     462             :                             case OBJ_PAGE :
     463             :                             case OBJ_TEXTEXT :
     464             :                             case OBJ_wegFITTEXT :
     465             :                             case OBJ_wegFITALLTEXT :
     466             :                             case OBJ_TITLETEXT :
     467             :                             case OBJ_OUTLINETEXT :
     468             :                             {
     469           0 :                                 if ( nC & 1 )
     470             :                                 {
     471           0 :                                     if ( nSpFlags & SP_FFLIPH )
     472           0 :                                         nC ^= 2;    // 1 <-> 3
     473             :                                 }
     474             :                                 else
     475             :                                 {
     476           0 :                                     if ( nSpFlags & SP_FFLIPV )
     477           0 :                                         nC ^= 1;    // 0 <-> 2
     478             :                                 }
     479           0 :                                 switch( nC )
     480             :                                 {
     481             :                                     case 0 :
     482           0 :                                         nId = 0;    // SDRVERTALIGN_TOP;
     483           0 :                                     break;
     484             :                                     case 1 :
     485           0 :                                         nId = 3;    // SDRHORZALIGN_RIGHT;
     486           0 :                                     break;
     487             :                                     case 2 :
     488           0 :                                         nId = 2;    // SDRVERTALIGN_BOTTOM;
     489           0 :                                     break;
     490             :                                     case 3 :
     491           0 :                                         nId = 1; // SDRHORZALIGN_LEFT;
     492           0 :                                     break;
     493             :                                 }
     494           0 :                                 if ( nId <= 3 )
     495           0 :                                     bValidGluePoint = true;
     496             :                             }
     497           0 :                             break;
     498             :                             case OBJ_POLY :
     499             :                             case OBJ_PLIN :
     500             :                             case OBJ_LINE :
     501             :                             case OBJ_PATHLINE :
     502             :                             case OBJ_PATHFILL :
     503             :                             case OBJ_FREELINE :
     504             :                             case OBJ_FREEFILL :
     505             :                             case OBJ_SPLNLINE :
     506             :                             case OBJ_SPLNFILL :
     507             :                             case OBJ_PATHPOLY :
     508             :                             case OBJ_PATHPLIN :
     509             :                             {
     510           0 :                                 if (pList)
     511             :                                 {
     512           0 :                                     if (pList->GetCount() > nC )
     513             :                                     {
     514           0 :                                         bValidGluePoint = true;
     515           0 :                                         nId = (sal_Int32)((*pList)[ (sal_uInt16)nC].GetId() + 3 );
     516             :                                     }
     517             :                                     else
     518             :                                     {
     519           0 :                                         bool bNotFound = true;
     520             : 
     521           0 :                                         tools::PolyPolygon aPolyPoly( EscherPropertyContainer::GetPolyPolygon( aXShape ) );
     522           0 :                                         sal_uInt16 k, j, nPolySize = aPolyPoly.Count();
     523           0 :                                         if ( nPolySize )
     524             :                                         {
     525           0 :                                             Rectangle aBoundRect( aPolyPoly.GetBoundRect() );
     526           0 :                                             if ( aBoundRect.GetWidth() && aBoundRect.GetHeight() )
     527             :                                             {
     528           0 :                                                 sal_uInt32  nPointCount = 0;
     529           0 :                                                 for ( k = 0; bNotFound && ( k < nPolySize ); k++ )
     530             :                                                 {
     531           0 :                                                     const Polygon& rPolygon = aPolyPoly.GetObject( k );
     532           0 :                                                     for ( j = 0; bNotFound && ( j < rPolygon.GetSize() ); j++ )
     533             :                                                     {
     534           0 :                                                         PolyFlags eFlags = rPolygon.GetFlags( j );
     535           0 :                                                         if ( eFlags == POLY_NORMAL )
     536             :                                                         {
     537           0 :                                                             if ( nC == nPointCount )
     538             :                                                             {
     539           0 :                                                                 const Point& rPoint = rPolygon.GetPoint( j );
     540           0 :                                                                 double fXRel = rPoint.X() - aBoundRect.Left();
     541           0 :                                                                 double fYRel = rPoint.Y() - aBoundRect.Top();
     542           0 :                                                                 sal_Int32 nWidth = aBoundRect.GetWidth();
     543           0 :                                                                 if ( !nWidth )
     544           0 :                                                                     nWidth = 1;
     545           0 :                                                                 sal_Int32 nHeight= aBoundRect.GetHeight();
     546           0 :                                                                 if ( !nHeight )
     547           0 :                                                                     nHeight = 1;
     548           0 :                                                                 fXRel /= (double)nWidth;
     549           0 :                                                                 fXRel *= 10000;
     550           0 :                                                                 fYRel /= (double)nHeight;
     551           0 :                                                                 fYRel *= 10000;
     552           0 :                                                                 aGluePoint.SetPos( Point( (sal_Int32)fXRel, (sal_Int32)fYRel ) );
     553           0 :                                                                 aGluePoint.SetPercent( true );
     554           0 :                                                                 aGluePoint.SetAlign( SDRVERTALIGN_TOP | SDRHORZALIGN_LEFT );
     555           0 :                                                                 aGluePoint.SetEscDir( SDRESC_SMART );
     556           0 :                                                                 nId = (sal_Int32)((*pList)[ pList->Insert( aGluePoint ) ].GetId() + 3 );
     557           0 :                                                                 bNotFound = false;
     558             :                                                             }
     559           0 :                                                             nPointCount++;
     560             :                                                         }
     561             :                                                     }
     562             :                                                 }
     563             :                                             }
     564             :                                         }
     565           0 :                                         if ( !bNotFound )
     566             :                                         {
     567           0 :                                             bValidGluePoint = true;
     568           0 :                                         }
     569             :                                     }
     570             :                                 }
     571             :                             }
     572           0 :                             break;
     573             : 
     574             :                             case OBJ_CUSTOMSHAPE :
     575             :                             {
     576           8 :                                 const SfxPoolItem& aCustomShape =  static_cast<SdrObjCustomShape*>(pO)->GetMergedItem( SDRATTR_CUSTOMSHAPE_GEOMETRY );
     577           8 :                                 SdrCustomShapeGeometryItem aGeometryItem( static_cast<const SdrCustomShapeGeometryItem&>(aCustomShape) );
     578          16 :                                 const OUString sPath( "Path" );
     579          16 :                                 const OUString sGluePointType( "GluePointType" );
     580           8 :                                 sal_Int16 nGluePointType = EnhancedCustomShapeGluePointType::SEGMENTS;
     581           8 :                                 com::sun::star::uno::Any* pAny = aGeometryItem.GetPropertyValueByName( sPath, sGluePointType );
     582           8 :                                 if ( pAny )
     583           0 :                                     *pAny >>= nGluePointType;
     584             :                                 else
     585             :                                 {
     586           8 :                                     const OUString sType( "Type" );
     587          16 :                                     OUString sShapeType;
     588           8 :                                     pAny = aGeometryItem.GetPropertyValueByName( sType );
     589           8 :                                     if ( pAny )
     590           8 :                                         *pAny >>= sShapeType;
     591           8 :                                     MSO_SPT eSpType = EnhancedCustomShapeTypeNames::Get( sShapeType );
     592          16 :                                     nGluePointType = GetCustomShapeConnectionTypeDefault( eSpType );
     593             :                                 }
     594           8 :                                 if ( nGluePointType == EnhancedCustomShapeGluePointType::CUSTOM )
     595             :                                 {
     596           8 :                                     if ( pList && ( pList->GetCount() > nC ) )
     597             :                                     {
     598           8 :                                         bValidGluePoint = true;
     599           8 :                                         nId = (sal_Int32)((*pList)[ (sal_uInt16)nC].GetId() + 3 );
     600             :                                     }
     601             :                                 }
     602           0 :                                 else if ( nGluePointType == EnhancedCustomShapeGluePointType::RECT )
     603             :                                 {
     604           0 :                                     if ( nC & 1 )
     605             :                                     {
     606           0 :                                         if ( nSpFlags & SP_FFLIPH )
     607           0 :                                             nC ^= 2;    // 1 <-> 3
     608             :                                     }
     609             :                                     else
     610             :                                     {
     611           0 :                                         if ( nSpFlags & SP_FFLIPV )
     612           0 :                                             nC ^= 1;    // 0 <-> 2
     613             :                                     }
     614           0 :                                     switch( nC )
     615             :                                     {
     616             :                                         case 0 :
     617           0 :                                             nId = 0;    // SDRVERTALIGN_TOP;
     618           0 :                                         break;
     619             :                                         case 1 :
     620           0 :                                             nId = 3;    // SDRHORZALIGN_RIGHT;
     621           0 :                                         break;
     622             :                                         case 2 :
     623           0 :                                             nId = 2;    // SDRVERTALIGN_BOTTOM;
     624           0 :                                         break;
     625             :                                         case 3 :
     626           0 :                                             nId = 1; // SDRHORZALIGN_LEFT;
     627           0 :                                         break;
     628             :                                     }
     629           0 :                                     if ( nId <= 3 )
     630           0 :                                         bValidGluePoint = true;
     631             :                                 }
     632           0 :                                 else if ( nGluePointType == EnhancedCustomShapeGluePointType::SEGMENTS )
     633             :                                 {
     634           0 :                                     const OUString sSegments( "Segments" );
     635           0 :                                     const OUString sCoordinates( "Coordinates" );
     636             : 
     637           0 :                                     sal_uInt32 k, nPt = nC;
     638           0 :                                     com::sun::star::uno::Sequence< com::sun::star::drawing::EnhancedCustomShapeSegment > aSegments;
     639           0 :                                     pAny = aGeometryItem.GetPropertyValueByName( sPath, sSegments );
     640           0 :                                     if ( pAny )
     641             :                                     {
     642           0 :                                         if ( *pAny >>= aSegments )
     643             :                                         {
     644           0 :                                             for ( nPt = 0, k = 1; nC && ( k < (sal_uInt32)aSegments.getLength() ); k++ )
     645             :                                             {
     646           0 :                                                 sal_Int16 j, nCnt2 = aSegments[ k ].Count;
     647           0 :                                                 if ( aSegments[ k ].Command != EnhancedCustomShapeSegmentCommand::UNKNOWN )
     648             :                                                 {
     649           0 :                                                     for ( j = 0; nC && ( j < nCnt2 ); j++ )
     650             :                                                     {
     651           0 :                                                         switch( aSegments[ k ].Command )
     652             :                                                         {
     653             :                                                             case EnhancedCustomShapeSegmentCommand::ENDSUBPATH :
     654             :                                                             case EnhancedCustomShapeSegmentCommand::CLOSESUBPATH :
     655             :                                                             case EnhancedCustomShapeSegmentCommand::LINETO :
     656             :                                                             case EnhancedCustomShapeSegmentCommand::MOVETO :
     657             :                                                             {
     658           0 :                                                                 nC--;
     659           0 :                                                                 nPt++;
     660             :                                                             }
     661           0 :                                                             break;
     662             :                                                             case EnhancedCustomShapeSegmentCommand::ELLIPTICALQUADRANTX :
     663             :                                                             case EnhancedCustomShapeSegmentCommand::ELLIPTICALQUADRANTY :
     664           0 :                                                             break;
     665             : 
     666             :                                                             case EnhancedCustomShapeSegmentCommand::CURVETO :
     667             :                                                             {
     668           0 :                                                                 nC--;
     669           0 :                                                                 nPt += 3;
     670             :                                                             }
     671           0 :                                                             break;
     672             : 
     673             :                                                             case EnhancedCustomShapeSegmentCommand::ANGLEELLIPSETO :
     674             :                                                             case EnhancedCustomShapeSegmentCommand::ANGLEELLIPSE :
     675             :                                                             {
     676           0 :                                                                 nC--;
     677           0 :                                                                 nPt += 3;
     678             :                                                             }
     679           0 :                                                             break;
     680             :                                                             case EnhancedCustomShapeSegmentCommand::ARCTO :
     681             :                                                             case EnhancedCustomShapeSegmentCommand::ARC :
     682             :                                                             case EnhancedCustomShapeSegmentCommand::CLOCKWISEARCTO :
     683             :                                                             case EnhancedCustomShapeSegmentCommand::CLOCKWISEARC :
     684             :                                                             {
     685           0 :                                                                 nC--;
     686           0 :                                                                 nPt += 4;
     687             :                                                             }
     688           0 :                                                             break;
     689             :                                                         }
     690             :                                                     }
     691             :                                                 }
     692             :                                             }
     693             :                                         }
     694             :                                     }
     695           0 :                                     pAny = aGeometryItem.GetPropertyValueByName( sPath, sCoordinates );
     696           0 :                                     if ( pAny )
     697             :                                     {
     698           0 :                                         com::sun::star::uno::Sequence< com::sun::star::drawing::EnhancedCustomShapeParameterPair > aCoordinates;
     699           0 :                                         *pAny >>= aCoordinates;
     700           0 :                                         if ( nPt < (sal_uInt32)aCoordinates.getLength() )
     701             :                                         {
     702           0 :                                             nId = 4;
     703           0 :                                             com::sun::star::drawing::EnhancedCustomShapeParameterPair& rPara = aCoordinates[ nPt ];
     704           0 :                                             sal_Int32 nX = 0, nY = 0;
     705           0 :                                             if ( ( rPara.First.Value >>= nX ) && ( rPara.Second.Value >>= nY ) )
     706             :                                             {
     707           0 :                                                 const OUString sGluePoints( "GluePoints" );
     708           0 :                                                 com::sun::star::uno::Sequence< com::sun::star::drawing::EnhancedCustomShapeParameterPair > aGluePoints;
     709           0 :                                                 pAny = aGeometryItem.GetPropertyValueByName( sPath, sGluePoints );
     710           0 :                                                 if ( pAny )
     711           0 :                                                     *pAny >>= aGluePoints;
     712           0 :                                                 sal_Int32 nGluePoints = aGluePoints.getLength();
     713           0 :                                                 aGluePoints.realloc( nGluePoints + 1 );
     714           0 :                                                 EnhancedCustomShape2d::SetEnhancedCustomShapeParameter( aGluePoints[ nGluePoints ].First, nX );
     715           0 :                                                 EnhancedCustomShape2d::SetEnhancedCustomShapeParameter( aGluePoints[ nGluePoints ].Second, nY );
     716           0 :                                                 PropertyValue aProp;
     717           0 :                                                 aProp.Name = sGluePoints;
     718           0 :                                                 aProp.Value <<= aGluePoints;
     719           0 :                                                 aGeometryItem.SetPropertyValue( sPath, aProp );
     720           0 :                                                 bValidGluePoint = true;
     721           0 :                                                 static_cast<SdrObjCustomShape*>(pO)->SetMergedItem( aGeometryItem );
     722           0 :                                                 SdrGluePointList* pLst = pO->ForceGluePointList();
     723           0 :                                                 if ( pLst->GetCount() > nGluePoints )
     724           0 :                                                     nId = (sal_Int32)((*pLst)[ (sal_uInt16)nGluePoints ].GetId() + 3 );
     725             :                                             }
     726           0 :                                         }
     727           0 :                                     }
     728           8 :                                 }
     729             :                             }
     730           8 :                             break;
     731             :                         }
     732           8 :                         if ( bValidGluePoint )
     733             :                         {
     734           8 :                             Reference< XPropertySet > xPropSet( aXConnector, UNO_QUERY );
     735           8 :                             if ( xPropSet.is() )
     736             :                             {
     737           8 :                                 if ( nN )
     738             :                                 {
     739           4 :                                     OUString aPropName( "EndShape" );
     740           4 :                                     aAny <<= aXShape;
     741           4 :                                     SetPropValue( aAny, xPropSet, aPropName, true );
     742           4 :                                     aPropName = "EndGluePointIndex";
     743           4 :                                     aAny <<= nId;
     744           4 :                                     SetPropValue( aAny, xPropSet, aPropName, true );
     745             :                                 }
     746             :                                 else
     747             :                                 {
     748           4 :                                     OUString aPropName( "StartShape" );
     749           4 :                                     aAny <<= aXShape;
     750           4 :                                     SetPropValue( aAny, xPropSet, aPropName, true );
     751           4 :                                     aPropName = "StartGluePointIndex";
     752           4 :                                     aAny <<= nId;
     753           4 :                                     SetPropValue( aAny, xPropSet, aPropName, true );
     754             :                                 }
     755             : 
     756             :                                 // Not sure what this is good for, repaint or broadcast of object change.
     757             :                                 //( Thus i am adding repaint here
     758           8 :                                 pO->SetChanged();
     759           8 :                                 pO->BroadcastObjectChange();
     760           8 :                             }
     761             :                         }
     762           8 :                     }
     763             :                 }
     764             :             }
     765             :         }
     766             :     }
     767         256 : }
     768             : 
     769             : 
     770             : 
     771         128 : static basegfx::B2DPolyPolygon GetLineArrow( const sal_Int32 nLineWidth, const MSO_LineEnd eLineEnd,
     772             :     const MSO_LineEndWidth eLineWidth, const MSO_LineEndLength eLineLength,
     773             :     sal_Int32& rnArrowWidth, bool& rbArrowCenter,
     774             :     OUString& rsArrowName, bool bScaleArrow )
     775             : {
     776         128 :     basegfx::B2DPolyPolygon aRetPolyPoly;
     777             :     // 70 100mm = 2pt = 40 twip. In MS, line width less than 2pt has the same size arrow as 2pt
     778             :     //If the unit is twip. Make all use this unit especailly the critical value 70/40.
     779         128 :     sal_Int32   nLineWidthCritical = bScaleArrow ? 40 : 70;
     780         128 :     double      fLineWidth = nLineWidth < nLineWidthCritical ? nLineWidthCritical : nLineWidth;;
     781             : 
     782             :     double      fLengthMul, fWidthMul;
     783             :     sal_Int32   nLineNumber;
     784         128 :     switch( eLineLength )
     785             :     {
     786             :         default :
     787          56 :         case mso_lineMediumLenArrow     : fLengthMul = 3.0; nLineNumber = 2; break;
     788           0 :         case mso_lineShortArrow         : fLengthMul = 2.0; nLineNumber = 1; break;
     789          72 :         case mso_lineLongArrow          : fLengthMul = 5.0; nLineNumber = 3; break;
     790             :     }
     791         128 :     switch( eLineWidth )
     792             :     {
     793             :         default :
     794         128 :         case mso_lineMediumWidthArrow   : fWidthMul = 3.0; nLineNumber += 3; break;
     795           0 :         case mso_lineNarrowArrow        : fWidthMul = 2.0; break;
     796           0 :         case mso_lineWideArrow          : fWidthMul = 5.0; nLineNumber += 6; break;
     797             :     }
     798             : 
     799         128 :     rbArrowCenter = false;
     800         128 :     OUStringBuffer aArrowName;
     801         128 :     switch ( eLineEnd )
     802             :     {
     803             :         case mso_lineArrowEnd :
     804             :         {
     805          48 :             basegfx::B2DPolygon aTriangle;
     806          48 :             aTriangle.append(basegfx::B2DPoint( fWidthMul * fLineWidth * 0.50, 0.0 ));
     807          48 :             aTriangle.append(basegfx::B2DPoint( fWidthMul * fLineWidth, fLengthMul * fLineWidth ));
     808          48 :             aTriangle.append(basegfx::B2DPoint( 0.0, fLengthMul * fLineWidth ));
     809          48 :             aTriangle.setClosed(true);
     810          48 :             aRetPolyPoly = basegfx::B2DPolyPolygon(aTriangle);
     811          48 :             aArrowName.append("msArrowEnd ");
     812             :         }
     813          48 :         break;
     814             : 
     815             :         case mso_lineArrowOpenEnd :
     816             :         {
     817           2 :             switch( eLineLength )
     818             :             {
     819             :                 default :
     820           2 :                 case mso_lineMediumLenArrow     : fLengthMul = 4.5; break;
     821           0 :                 case mso_lineShortArrow         : fLengthMul = 3.5; break;
     822           0 :                 case mso_lineLongArrow          : fLengthMul = 6.0; break;
     823             :             }
     824           2 :             switch( eLineWidth )
     825             :             {
     826             :                 default :
     827           2 :                 case mso_lineMediumWidthArrow   : fWidthMul = 4.5; break;
     828           0 :                 case mso_lineNarrowArrow        : fWidthMul = 3.5; break;
     829           0 :                 case mso_lineWideArrow          : fWidthMul = 6.0; break;
     830             :             }
     831           2 :             basegfx::B2DPolygon aTriangle;
     832           2 :             aTriangle.append(basegfx::B2DPoint( fWidthMul * fLineWidth * 0.50 , 0.0 ));
     833           2 :             aTriangle.append(basegfx::B2DPoint( fWidthMul * fLineWidth, fLengthMul * fLineWidth * 0.91 ));
     834           2 :             aTriangle.append(basegfx::B2DPoint( fWidthMul * fLineWidth * 0.85, fLengthMul * fLineWidth ));
     835           2 :             aTriangle.append(basegfx::B2DPoint( fWidthMul * fLineWidth * 0.50, fLengthMul * fLineWidth * 0.36 ));
     836           2 :             aTriangle.append(basegfx::B2DPoint( fWidthMul * fLineWidth * 0.15, fLengthMul * fLineWidth ));
     837           2 :             aTriangle.append(basegfx::B2DPoint( 0.0, fLengthMul * fLineWidth * 0.91 ));
     838           2 :             aTriangle.setClosed(true);
     839           2 :             aRetPolyPoly = basegfx::B2DPolyPolygon(aTriangle);
     840           2 :             aArrowName.append("msArrowOpenEnd ");
     841             :         }
     842           2 :         break;
     843             :         case mso_lineArrowStealthEnd :
     844             :         {
     845          78 :             basegfx::B2DPolygon aTriangle;
     846          78 :             aTriangle.append(basegfx::B2DPoint( fWidthMul * fLineWidth * 0.50 , 0.0 ));
     847          78 :             aTriangle.append(basegfx::B2DPoint( fWidthMul * fLineWidth , fLengthMul * fLineWidth ));
     848          78 :             aTriangle.append(basegfx::B2DPoint( fWidthMul * fLineWidth * 0.50 , fLengthMul * fLineWidth * 0.60 ));
     849          78 :             aTriangle.append(basegfx::B2DPoint( 0.0, fLengthMul * fLineWidth ));
     850          78 :             aTriangle.setClosed(true);
     851          78 :             aRetPolyPoly = basegfx::B2DPolyPolygon(aTriangle);
     852          78 :             aArrowName.append("msArrowStealthEnd ");
     853             :         }
     854          78 :         break;
     855             :         case mso_lineArrowDiamondEnd :
     856             :         {
     857           0 :             basegfx::B2DPolygon aTriangle;
     858           0 :             aTriangle.append(basegfx::B2DPoint( fWidthMul * fLineWidth * 0.50 , 0.0 ));
     859           0 :             aTriangle.append(basegfx::B2DPoint( fWidthMul * fLineWidth , fLengthMul * fLineWidth * 0.50 ));
     860           0 :             aTriangle.append(basegfx::B2DPoint( fWidthMul * fLineWidth * 0.50 , fLengthMul * fLineWidth ));
     861           0 :             aTriangle.append(basegfx::B2DPoint( 0.0, fLengthMul * fLineWidth * 0.50 ));
     862           0 :             aTriangle.setClosed(true);
     863           0 :             aRetPolyPoly = basegfx::B2DPolyPolygon(aTriangle);
     864           0 :             rbArrowCenter = true;
     865           0 :             aArrowName.append("msArrowDiamondEnd ");
     866             :         }
     867           0 :         break;
     868             :         case mso_lineArrowOvalEnd :
     869             :         {
     870           0 :             aRetPolyPoly = basegfx::B2DPolyPolygon( XPolygon( Point( (sal_Int32)( fWidthMul * fLineWidth * 0.50 ), 0 ),
     871           0 :                                 (sal_Int32)( fWidthMul * fLineWidth * 0.50 ),
     872           0 :                                     (sal_Int32)( fLengthMul * fLineWidth * 0.50 ), 0, 3600 ).getB2DPolygon() );
     873           0 :             rbArrowCenter = true;
     874           0 :             aArrowName.append("msArrowOvalEnd ");
     875             :         }
     876           0 :         break;
     877           0 :         default: break;
     878             :     }
     879         128 :     aArrowName.append(nLineNumber);
     880         128 :     rsArrowName = aArrowName.makeStringAndClear();
     881         128 :     rnArrowWidth = (sal_Int32)( fLineWidth * fWidthMul );
     882             : 
     883         128 :     return aRetPolyPoly;
     884             : }
     885             : 
     886        4014 : void DffPropertyReader::ApplyLineAttributes( SfxItemSet& rSet, const MSO_SPT eShapeType ) const // #i28269#
     887             : {
     888        4014 :     sal_uInt32 nLineFlags(GetPropertyValue( DFF_Prop_fNoLineDrawDash ));
     889             : 
     890        4014 :     if(!IsHardAttribute( DFF_Prop_fLine ) && !IsCustomShapeStrokedByDefault( eShapeType ))
     891             :     {
     892          22 :         nLineFlags &= ~0x08;
     893             :     }
     894             : 
     895        4014 :     if ( nLineFlags & 8 )
     896             :     {
     897             :         // Line Attributes
     898        1746 :         sal_Int32 nLineWidth = (sal_Int32)GetPropertyValue( DFF_Prop_lineWidth, 9525 );
     899             : 
     900             :         // support LineCap
     901        1746 :         const MSO_LineCap eLineCap((MSO_LineCap)GetPropertyValue(DFF_Prop_lineEndCapStyle, mso_lineEndCapSquare));
     902             : 
     903        1746 :         switch(eLineCap)
     904             :         {
     905             :             default: /* case mso_lineEndCapFlat */
     906             :             {
     907             :                 // no need to set, it is the default. If this changes, this needs to be activated
     908             :                 // rSet.Put(XLineCapItem(com::sun::star::drawing::LineCap_BUTT));
     909           6 :                 break;
     910             :             }
     911             :             case mso_lineEndCapRound:
     912             :             {
     913           0 :                 rSet.Put(XLineCapItem(com::sun::star::drawing::LineCap_ROUND));
     914           0 :                 break;
     915             :             }
     916             :             case mso_lineEndCapSquare:
     917             :             {
     918        1740 :                 rSet.Put(XLineCapItem(com::sun::star::drawing::LineCap_SQUARE));
     919        1740 :                 break;
     920             :             }
     921             :         }
     922             : 
     923        1746 :         MSO_LineDashing eLineDashing = (MSO_LineDashing)GetPropertyValue( DFF_Prop_lineDashing, mso_lineSolid );
     924        1746 :         if ( eLineDashing == mso_lineSolid )
     925        1646 :             rSet.Put(XLineStyleItem( XLINE_SOLID ) );
     926             :         else
     927             :         {
     928         100 :             XDashStyle  eDash = XDASH_RECT;
     929         100 :             sal_uInt16  nDots = 1;
     930         100 :             sal_uInt32  nDotLen = nLineWidth / 360;
     931         100 :             sal_uInt16  nDashes = 0;
     932         100 :             sal_uInt32  nDashLen = ( 8 * nLineWidth ) / 360;
     933         100 :             sal_uInt32  nDistance = ( 3 * nLineWidth ) / 360;
     934             : 
     935         100 :             switch ( eLineDashing )
     936             :             {
     937             :                 default:
     938             :                 case mso_lineDotSys :
     939             :                 {
     940          60 :                     nDots = 1;
     941          60 :                     nDashes = 0;
     942          60 :                     nDistance = nDotLen;
     943             :                 }
     944          60 :                 break;
     945             : 
     946             :                 case mso_lineDashGEL :
     947             :                 {
     948          40 :                     nDots = 0;
     949          40 :                     nDashes = 1;
     950          40 :                     nDashLen = ( 4 * nLineWidth ) / 360;
     951             :                 }
     952          40 :                 break;
     953             : 
     954             :                 case mso_lineDashDotGEL :
     955             :                 {
     956           0 :                     nDots = 1;
     957           0 :                     nDashes = 1;
     958           0 :                     nDashLen = ( 4 * nLineWidth ) / 360;
     959             :                 }
     960           0 :                 break;
     961             : 
     962             :                 case mso_lineLongDashGEL :
     963             :                 {
     964           0 :                     nDots = 0;
     965           0 :                     nDashes = 1;
     966             :                 }
     967           0 :                 break;
     968             : 
     969             :                 case mso_lineLongDashDotGEL :
     970             :                 {
     971           0 :                     nDots = 1;
     972           0 :                     nDashes = 1;
     973             :                 }
     974           0 :                 break;
     975             : 
     976             :                 case mso_lineLongDashDotDotGEL:
     977             :                 {
     978           0 :                     nDots = 2;
     979           0 :                     nDashes = 1;
     980             :                 }
     981           0 :                 break;
     982             :             }
     983             : 
     984         100 :             rSet.Put( XLineDashItem( OUString(), XDash( eDash, nDots, nDotLen, nDashes, nDashLen, nDistance ) ) );
     985         100 :             rSet.Put( XLineStyleItem( XLINE_DASH ) );
     986             :         }
     987        1746 :         rSet.Put( XLineColorItem( OUString(), rManager.MSO_CLR_ToColor( GetPropertyValue( DFF_Prop_lineColor ), DFF_Prop_lineColor ) ) );
     988        1746 :         if ( IsProperty( DFF_Prop_lineOpacity ) )
     989             :         {
     990          18 :             double nTrans = GetPropertyValue(DFF_Prop_lineOpacity, 0x10000);
     991          18 :             nTrans = (nTrans * 100) / 65536;
     992             :             rSet.Put(XLineTransparenceItem(
     993          18 :                 sal_uInt16(100 - ::rtl::math::round(nTrans))));
     994             :         }
     995             : 
     996        1746 :         rManager.ScaleEmu( nLineWidth );
     997        1746 :         rSet.Put( XLineWidthItem( nLineWidth ) );
     998             : 
     999             :         // SJ: LineJoint (setting each time a line is set, because our internal joint type has another default)
    1000        1746 :         MSO_LineJoin eLineJointDefault = mso_lineJoinMiter;
    1001        1746 :         if ( eShapeType == mso_sptMin )
    1002           4 :             eLineJointDefault = mso_lineJoinRound;
    1003        1746 :         MSO_LineJoin eLineJoint = (MSO_LineJoin)GetPropertyValue( DFF_Prop_lineJoinStyle, eLineJointDefault );
    1004        1746 :         com::sun::star::drawing::LineJoint eXLineJoint( com::sun::star::drawing::LineJoint_MITER );
    1005        1746 :         if ( eLineJoint == mso_lineJoinBevel )
    1006           0 :             eXLineJoint = com::sun::star::drawing::LineJoint_BEVEL;
    1007        1746 :         else if ( eLineJoint == mso_lineJoinRound )
    1008          12 :             eXLineJoint = com::sun::star::drawing::LineJoint_ROUND;
    1009        1746 :         rSet.Put( XLineJointItem( eXLineJoint ) );
    1010             : 
    1011        1746 :         if ( nLineFlags & 0x10 )
    1012             :         {
    1013        1742 :             bool bScaleArrows = rManager.pSdrModel->GetScaleUnit() == MAP_TWIP;
    1014             : 
    1015             :             // LineStart
    1016             : 
    1017        1742 :             if ( IsProperty( DFF_Prop_lineStartArrowhead ) )
    1018             :             {
    1019          60 :                 MSO_LineEnd         eLineEnd = (MSO_LineEnd)GetPropertyValue( DFF_Prop_lineStartArrowhead );
    1020          60 :                 MSO_LineEndWidth    eWidth = (MSO_LineEndWidth)GetPropertyValue( DFF_Prop_lineStartArrowWidth, mso_lineMediumWidthArrow );
    1021          60 :                 MSO_LineEndLength   eLength = (MSO_LineEndLength)GetPropertyValue( DFF_Prop_lineStartArrowLength, mso_lineMediumLenArrow );
    1022             : 
    1023             :                 sal_Int32   nArrowWidth;
    1024             :                 bool        bArrowCenter;
    1025          60 :                 OUString    aArrowName;
    1026         120 :                 basegfx::B2DPolyPolygon aPolyPoly(GetLineArrow( nLineWidth, eLineEnd, eWidth, eLength, nArrowWidth, bArrowCenter, aArrowName, bScaleArrows ));
    1027             : 
    1028          60 :                 rSet.Put( XLineStartWidthItem( nArrowWidth ) );
    1029          60 :                 rSet.Put( XLineStartItem( aArrowName, aPolyPoly) );
    1030         120 :                 rSet.Put( XLineStartCenterItem( bArrowCenter ) );
    1031             :             }
    1032             : 
    1033             :             // LineEnd
    1034             : 
    1035        1742 :             if ( IsProperty( DFF_Prop_lineEndArrowhead ) )
    1036             :             {
    1037          68 :                 MSO_LineEnd         eLineEnd = (MSO_LineEnd)GetPropertyValue( DFF_Prop_lineEndArrowhead );
    1038          68 :                 MSO_LineEndWidth    eWidth = (MSO_LineEndWidth)GetPropertyValue( DFF_Prop_lineEndArrowWidth, mso_lineMediumWidthArrow );
    1039          68 :                 MSO_LineEndLength   eLength = (MSO_LineEndLength)GetPropertyValue( DFF_Prop_lineEndArrowLength, mso_lineMediumLenArrow );
    1040             : 
    1041             :                 sal_Int32   nArrowWidth;
    1042             :                 bool        bArrowCenter;
    1043          68 :                 OUString    aArrowName;
    1044         136 :                 basegfx::B2DPolyPolygon aPolyPoly(GetLineArrow( nLineWidth, eLineEnd, eWidth, eLength, nArrowWidth, bArrowCenter, aArrowName, bScaleArrows ));
    1045             : 
    1046          68 :                 rSet.Put( XLineEndWidthItem( nArrowWidth ) );
    1047          68 :                 rSet.Put( XLineEndItem( aArrowName, aPolyPoly ) );
    1048         136 :                 rSet.Put( XLineEndCenterItem( bArrowCenter ) );
    1049             :             }
    1050             :         }
    1051             :     }
    1052             :     else
    1053        2268 :         rSet.Put( XLineStyleItem( XLINE_NONE ) );
    1054        4014 : }
    1055             : 
    1056             : struct ShadeColor
    1057             : {
    1058             :     Color       aColor;
    1059             :     double      fDist;
    1060             : 
    1061        8032 :     ShadeColor( const Color& rC, double fR ) : aColor( rC ), fDist( fR ) {};
    1062             : };
    1063             : 
    1064        4014 : void GetShadeColors( const SvxMSDffManager& rManager, const DffPropertyReader& rProperties, SvStream& rIn, std::vector< ShadeColor >& rShadeColors )
    1065             : {
    1066        4014 :     sal_uInt32 nPos = rIn.Tell();
    1067        4014 :     if ( rProperties.IsProperty( DFF_Prop_fillShadeColors ) )
    1068             :     {
    1069         194 :         sal_uInt16 i = 0, nNumElem = 0, nNumElemReserved = 0, nSize = 0;
    1070         194 :         bool bOk = false;
    1071         194 :         if (rProperties.SeekToContent(DFF_Prop_fillShadeColors, rIn))
    1072             :         {
    1073           4 :             rIn.ReadUInt16( nNumElem ).ReadUInt16( nNumElemReserved ).ReadUInt16( nSize );
    1074             :             //sanity check that the stream is long enough to fulfill nNumElem * 2 sal_Int32s
    1075           4 :             bOk = rIn.remainingSize() / (2*sizeof(sal_Int32)) >= nNumElem;
    1076             :         }
    1077         194 :         if (bOk)
    1078             :         {
    1079          16 :             for ( ; i < nNumElem; i++ )
    1080             :             {
    1081          12 :                 sal_Int32 nColor(0);
    1082          12 :                 sal_Int32 nDist(0);
    1083             : 
    1084          12 :                 rIn.ReadInt32( nColor ).ReadInt32( nDist );
    1085          12 :                 rShadeColors.push_back( ShadeColor( rManager.MSO_CLR_ToColor( nColor, DFF_Prop_fillColor ), 1.0 - ( nDist / 65536.0 ) ) );
    1086             :             }
    1087             :         }
    1088             :     }
    1089        4014 :     if ( rShadeColors.empty() )
    1090             :     {
    1091        4010 :         rShadeColors.push_back( ShadeColor( rManager.MSO_CLR_ToColor( rProperties.GetPropertyValue( DFF_Prop_fillBackColor, COL_WHITE ), DFF_Prop_fillBackColor ), 0 ) );
    1092        4010 :         rShadeColors.push_back( ShadeColor( rManager.MSO_CLR_ToColor( rProperties.GetPropertyValue( DFF_Prop_fillColor, COL_WHITE ), DFF_Prop_fillColor ), 1 ) );
    1093             :     }
    1094        4014 :     rIn.Seek( nPos );
    1095        4014 : }
    1096             : 
    1097           0 : void ApplyRectangularGradientAsBitmap( const SvxMSDffManager& rManager, SvStream& rIn, SfxItemSet& rSet, const std::vector< ShadeColor >& rShadeColors, const DffObjData& rObjData, sal_Int32 nFix16Angle )
    1098             : {
    1099           0 :     Size aBitmapSizePixel( static_cast< sal_Int32 >( ( rObjData.aBoundRect.GetWidth() / 2540.0 ) * 90.0 ),      // we will create a bitmap with 90 dpi
    1100           0 :                            static_cast< sal_Int32 >( ( rObjData.aBoundRect.GetHeight() / 2540.0 ) * 90.0 ) );
    1101           0 :     if ( aBitmapSizePixel.Width() && aBitmapSizePixel.Height() && ( aBitmapSizePixel.Width() <= 1024 ) && ( aBitmapSizePixel.Height() <= 1024 ) )
    1102             :     {
    1103           0 :         double fFocusX = rManager.GetPropertyValue( DFF_Prop_fillToRight, 0 ) / 65536.0;
    1104           0 :         double fFocusY = rManager.GetPropertyValue( DFF_Prop_fillToBottom, 0 ) / 65536.0;
    1105             : 
    1106           0 :         Bitmap aBitmap( aBitmapSizePixel, 24 );
    1107           0 :         BitmapWriteAccess* pAcc = aBitmap.AcquireWriteAccess();
    1108           0 :         if ( pAcc )
    1109             :         {
    1110             :             sal_Int32 nX, nY;
    1111           0 :             for ( nY = 0; nY < aBitmapSizePixel.Height(); nY++ )
    1112             :             {
    1113           0 :                 for ( nX = 0; nX < aBitmapSizePixel.Width(); nX++ )
    1114             :                 {
    1115           0 :                     double fX = static_cast< double >( nX ) / aBitmapSizePixel.Width();
    1116           0 :                     double fY = static_cast< double >( nY ) / aBitmapSizePixel.Height();
    1117             : 
    1118             :                     double fD, fDist;
    1119           0 :                     if ( fX < fFocusX )
    1120             :                     {
    1121           0 :                         if ( fY < fFocusY )
    1122             :                         {
    1123           0 :                             if ( fX > fY )
    1124           0 :                                 fDist = fY, fD = fFocusY;
    1125             :                             else
    1126           0 :                                 fDist = fX, fD = fFocusX;
    1127             :                         }
    1128             :                         else
    1129             :                         {
    1130           0 :                             if ( fX > ( 1 - fY ) )
    1131           0 :                                 fDist = ( 1 - fY ), fD = 1 - fFocusY;
    1132             :                             else
    1133           0 :                                 fDist = fX, fD = fFocusX;
    1134             :                         }
    1135             :                     }
    1136             :                     else
    1137             :                     {
    1138           0 :                         if ( fY < fFocusY )
    1139             :                         {
    1140           0 :                             if ( ( 1 - fX ) > fY )
    1141           0 :                                 fDist = fY, fD = fFocusY;
    1142             :                             else
    1143           0 :                                 fDist = ( 1 - fX ), fD = 1 - fFocusX;
    1144             :                         }
    1145             :                         else
    1146             :                         {
    1147           0 :                             if ( ( 1 - fX ) > ( 1 - fY ) )
    1148           0 :                                 fDist = ( 1 - fY ), fD = 1 - fFocusY;
    1149             :                             else
    1150           0 :                                 fDist = ( 1 - fX ), fD = 1 - fFocusX;
    1151             :                         }
    1152             :                     }
    1153           0 :                     if ( fD != 0.0 )
    1154           0 :                         fDist /= fD;
    1155             : 
    1156           0 :                     std::vector< ShadeColor >::const_iterator aIter( rShadeColors.begin() );
    1157           0 :                     double fA = 0.0;
    1158           0 :                     Color aColorA = aIter->aColor;
    1159           0 :                     double fB = 1.0;
    1160           0 :                     Color aColorB( aColorA );
    1161           0 :                     while ( aIter != rShadeColors.end() )
    1162             :                     {
    1163           0 :                         if ( aIter->fDist <= fDist )
    1164             :                         {
    1165           0 :                             if ( aIter->fDist >= fA )
    1166             :                             {
    1167           0 :                                 fA = aIter->fDist;
    1168           0 :                                 aColorA = aIter->aColor;
    1169             :                             }
    1170             :                         }
    1171           0 :                         if ( aIter->fDist > fDist )
    1172             :                         {
    1173           0 :                             if ( aIter->fDist <= fB )
    1174             :                             {
    1175           0 :                                 fB = aIter->fDist;
    1176           0 :                                 aColorB = aIter->aColor;
    1177             :                             }
    1178             :                         }
    1179           0 :                         ++aIter;
    1180             :                     }
    1181           0 :                     double fRed = aColorA.GetRed(), fGreen = aColorA.GetGreen(), fBlue = aColorA.GetBlue();
    1182           0 :                     double fD1 = fB - fA;
    1183           0 :                     if ( fD1 != 0.0 )
    1184             :                     {
    1185           0 :                         fRed   += ( ( ( fDist - fA ) * ( aColorB.GetRed() - aColorA.GetRed() ) ) / fD1 );       // + aQuantErrCurrScan[ nX ].fRed;
    1186           0 :                         fGreen += ( ( ( fDist - fA ) * ( aColorB.GetGreen() - aColorA.GetGreen() ) ) / fD1 );   // + aQuantErrCurrScan[ nX ].fGreen;
    1187           0 :                         fBlue  += ( ( ( fDist - fA ) * ( aColorB.GetBlue() - aColorA.GetBlue() ) ) / fD1 );     // + aQuantErrCurrScan[ nX ].fBlue;
    1188             :                     }
    1189           0 :                     sal_Int16 nRed   = static_cast< sal_Int16 >( fRed   + 0.5 );
    1190           0 :                     sal_Int16 nGreen = static_cast< sal_Int16 >( fGreen + 0.5 );
    1191           0 :                     sal_Int16 nBlue  = static_cast< sal_Int16 >( fBlue  + 0.5 );
    1192           0 :                     if ( nRed < 0 )
    1193           0 :                         nRed = 0;
    1194           0 :                     if ( nRed > 255 )
    1195           0 :                         nRed = 255;
    1196           0 :                     if ( nGreen < 0 )
    1197           0 :                         nGreen = 0;
    1198           0 :                     if ( nGreen > 255 )
    1199           0 :                         nGreen = 255;
    1200           0 :                     if ( nBlue < 0 )
    1201           0 :                         nBlue = 0;
    1202           0 :                     if ( nBlue > 255 )
    1203           0 :                         nBlue = 255;
    1204             : 
    1205           0 :                     pAcc->SetPixel( nY, nX, BitmapColor( static_cast< sal_Int8 >( nRed ), static_cast< sal_Int8 >( nGreen ), static_cast< sal_Int8 >( nBlue ) ) );
    1206             :                 }
    1207             :             }
    1208           0 :             aBitmap.ReleaseAccess( pAcc );
    1209             : 
    1210           0 :             if ( nFix16Angle )
    1211             :             {
    1212           0 :                 bool bRotateWithShape = true;   // sal_True seems to be default
    1213           0 :                 sal_uInt32 nPos = rIn.Tell();
    1214           0 :                 if ( const_cast< SvxMSDffManager& >( rManager ).maShapeRecords.SeekToContent( rIn, DFF_msofbtUDefProp, SEEK_FROM_CURRENT_AND_RESTART ) )
    1215             :                 {
    1216           0 :                     const_cast< SvxMSDffManager& >( rManager ).maShapeRecords.Current()->SeekToBegOfRecord( rIn );
    1217           0 :                     DffPropertyReader aSecPropSet( rManager );
    1218           0 :                     aSecPropSet.ReadPropSet( rIn, NULL );
    1219           0 :                     sal_Int32 nSecFillProperties = aSecPropSet.GetPropertyValue( DFF_Prop_fNoFillHitTest, 0x200020 );
    1220           0 :                     bRotateWithShape = ( nSecFillProperties & 0x0020 );
    1221             :                 }
    1222           0 :                 rIn.Seek( nPos );
    1223           0 :                 if ( bRotateWithShape )
    1224             :                 {
    1225           0 :                     aBitmap.Rotate( nFix16Angle / 10, rShadeColors[ 0 ].aColor );
    1226             : 
    1227           0 :                     sal_uLong nMirrorFlags = BMP_MIRROR_NONE;
    1228           0 :                     if ( rObjData.nSpFlags & SP_FFLIPV )
    1229           0 :                         nMirrorFlags |= BMP_MIRROR_VERT;
    1230           0 :                     if ( rObjData.nSpFlags & SP_FFLIPH )
    1231           0 :                         nMirrorFlags |= BMP_MIRROR_HORZ;
    1232           0 :                     if ( nMirrorFlags != BMP_MIRROR_NONE )
    1233           0 :                         aBitmap.Mirror( nMirrorFlags );
    1234             :                 }
    1235             :             }
    1236             : 
    1237           0 :             rSet.Put(XFillBmpTileItem(false));
    1238           0 :             rSet.Put(XFillBitmapItem(OUString(), Graphic(aBitmap)));
    1239           0 :         }
    1240             :     }
    1241           0 : }
    1242             : 
    1243        4014 : void DffPropertyReader::ApplyFillAttributes( SvStream& rIn, SfxItemSet& rSet, const DffObjData& rObjData ) const
    1244             : {
    1245        4014 :     sal_uInt32 nFillFlags(GetPropertyValue( DFF_Prop_fNoFillHitTest ));
    1246             : 
    1247        4014 :     std::vector< ShadeColor > aShadeColors;
    1248        4014 :     GetShadeColors( rManager, *this, rIn, aShadeColors );
    1249             : 
    1250        4014 :     if(!IsHardAttribute( DFF_Prop_fFilled ) && !IsCustomShapeFilledByDefault( rObjData.eShapeType ))
    1251             :     {
    1252         174 :         nFillFlags &= ~0x10;
    1253             :     }
    1254             : 
    1255        4014 :     if ( nFillFlags & 0x10 )
    1256             :     {
    1257         942 :         MSO_FillType eMSO_FillType = (MSO_FillType)GetPropertyValue( DFF_Prop_fillType, mso_fillSolid );
    1258         942 :         drawing::FillStyle eXFill = drawing::FillStyle_NONE;
    1259         942 :         switch( eMSO_FillType )
    1260             :         {
    1261             :             case mso_fillSolid :            // Fill with a solid color
    1262         936 :                 eXFill = drawing::FillStyle_SOLID;
    1263         936 :             break;
    1264             :             case mso_fillPattern :          // Fill with a pattern (bitmap)
    1265             :             case mso_fillTexture :          // A texture (pattern with its own color map)
    1266             :             case mso_fillPicture :          // Center a picture in the shape
    1267           0 :                 eXFill = drawing::FillStyle_BITMAP;
    1268           0 :             break;
    1269             :             case mso_fillShadeCenter :      // Shade from bounding rectangle to end point
    1270             :             {
    1271             :                 //If it is imported as a bitmap, it will not work well with transparecy especially 100
    1272             :                 //But the gradient look well comparing with imported as gradient. And rotate with shape
    1273             :                 //also works better. So here just keep it.
    1274           0 :                 if ( rObjData.aBoundRect.IsEmpty() )// size of object needed to be able
    1275           0 :                     eXFill = drawing::FillStyle_GRADIENT;        // to create a bitmap substitution
    1276             :                 else
    1277           0 :                     eXFill = drawing::FillStyle_BITMAP;
    1278             :             }
    1279           0 :             break;
    1280             :             case mso_fillShade :            // Shade from start to end points
    1281             :             case mso_fillShadeShape :       // Shade from shape outline to end point
    1282             :             case mso_fillShadeScale :       // Similar to mso_fillShade, but the fillAngle
    1283             :             case mso_fillShadeTitle :       // special type - shade to title ---  for PP
    1284           6 :                 eXFill = drawing::FillStyle_GRADIENT;
    1285           6 :             break;
    1286             : //          case mso_fillBackground :       // Use the background fill color/pattern
    1287           0 :             default: break;
    1288             :         }
    1289         942 :         rSet.Put( XFillStyleItem( eXFill ) );
    1290             : 
    1291         942 :         double dTrans  = 1.0;
    1292         942 :         double dBackTrans = 1.0;
    1293         942 :         if (IsProperty(DFF_Prop_fillOpacity))
    1294             :         {
    1295         272 :             dTrans = GetPropertyValue(DFF_Prop_fillOpacity) / 65536.0;
    1296         272 :             if ( eXFill != drawing::FillStyle_GRADIENT )
    1297             :             {
    1298         272 :                 dTrans = dTrans * 100;
    1299             :                 rSet.Put(XFillTransparenceItem(
    1300         272 :                     sal_uInt16(100 - ::rtl::math::round(dTrans))));
    1301             :             }
    1302             :         }
    1303             : 
    1304         942 :         if ( IsProperty(DFF_Prop_fillBackOpacity) )
    1305         190 :             dBackTrans = GetPropertyValue(DFF_Prop_fillBackOpacity) / 65536.0;
    1306             : 
    1307         942 :         if ( ( eMSO_FillType == mso_fillShadeCenter ) && ( eXFill == drawing::FillStyle_BITMAP ) )
    1308             :         {
    1309           0 :             ApplyRectangularGradientAsBitmap( rManager, rIn, rSet, aShadeColors, rObjData, mnFix16Angle );
    1310             :         }
    1311         942 :         else if ( eXFill == drawing::FillStyle_GRADIENT )
    1312             :         {
    1313           6 :             ImportGradientColor ( rSet, eMSO_FillType, dTrans , dBackTrans );
    1314             :         }
    1315         936 :         else if ( eXFill == drawing::FillStyle_BITMAP )
    1316             :         {
    1317           0 :             if( IsProperty( DFF_Prop_fillBlip ) )
    1318             :             {
    1319           0 :                 Graphic aGraf;
    1320             :                 // first try to get BLIP from cache
    1321           0 :                 bool bOK = const_cast<SvxMSDffManager&>(rManager).GetBLIP( GetPropertyValue( DFF_Prop_fillBlip ), aGraf, NULL );
    1322             :                 // then try directly from stream (i.e. Excel chart hatches/bitmaps)
    1323           0 :                 if ( !bOK )
    1324           0 :                     bOK = SeekToContent( DFF_Prop_fillBlip, rIn ) && rManager.GetBLIPDirect( rIn, aGraf, NULL );
    1325           0 :                 if ( bOK )
    1326             :                 {
    1327           0 :                     if ( eMSO_FillType == mso_fillPattern )
    1328             :                     {
    1329           0 :                         Bitmap aBmp( aGraf.GetBitmap() );
    1330           0 :                         if( aBmp.GetSizePixel().Width() == 8 && aBmp.GetSizePixel().Height() == 8 && aBmp.GetColorCount() == 2)
    1331             :                         {
    1332           0 :                             Color aCol1( COL_WHITE ), aCol2( COL_WHITE );
    1333             : 
    1334           0 :                             if ( IsProperty( DFF_Prop_fillColor ) )
    1335           0 :                                 aCol1 = rManager.MSO_CLR_ToColor( GetPropertyValue( DFF_Prop_fillColor ), DFF_Prop_fillColor );
    1336             : 
    1337           0 :                             if ( IsProperty( DFF_Prop_fillBackColor ) )
    1338           0 :                                 aCol2 = rManager.MSO_CLR_ToColor( GetPropertyValue( DFF_Prop_fillBackColor ), DFF_Prop_fillBackColor );
    1339             : 
    1340           0 :                             XOBitmap aXOBitmap( aBmp );
    1341           0 :                             aXOBitmap.Bitmap2Array();
    1342           0 :                             aXOBitmap.SetBitmapType( XBITMAP_8X8 );
    1343           0 :                             aXOBitmap.SetPixelSize( aBmp.GetSizePixel() );
    1344             : 
    1345           0 :                             if( aXOBitmap.GetBackgroundColor() == COL_BLACK )
    1346             :                             {
    1347           0 :                                 aXOBitmap.SetPixelColor( aCol1 );
    1348           0 :                                 aXOBitmap.SetBackgroundColor( aCol2 );
    1349             :                             }
    1350             :                             else
    1351             :                             {
    1352           0 :                                 aXOBitmap.SetPixelColor( aCol2 );
    1353           0 :                                 aXOBitmap.SetBackgroundColor( aCol1 );
    1354             :                             }
    1355             : 
    1356           0 :                             aXOBitmap.Array2Bitmap();
    1357           0 :                             aGraf = Graphic( aXOBitmap.GetBitmap()  );
    1358             :                         }
    1359             : 
    1360           0 :                         rSet.Put(XFillBitmapItem(OUString(), aGraf));
    1361             :                     }
    1362           0 :                     else if ( eMSO_FillType == mso_fillTexture )
    1363             :                     {
    1364           0 :                         rSet.Put(XFillBmpTileItem(true));
    1365           0 :                         rSet.Put(XFillBitmapItem(OUString(), aGraf));
    1366           0 :                         rSet.Put(XFillBmpSizeXItem(GetPropertyValue(DFF_Prop_fillWidth, 0) / 360));
    1367           0 :                         rSet.Put(XFillBmpSizeYItem(GetPropertyValue(DFF_Prop_fillHeight, 0) / 360));
    1368           0 :                         rSet.Put(XFillBmpSizeLogItem(true));
    1369             :                     }
    1370             :                     else
    1371             :                     {
    1372           0 :                         rSet.Put(XFillBitmapItem(OUString(), aGraf));
    1373           0 :                         rSet.Put(XFillBmpTileItem(false));
    1374             :                     }
    1375           0 :                 }
    1376             :             }
    1377             :         }
    1378             :     }
    1379             :     else
    1380        3072 :         rSet.Put( XFillStyleItem( drawing::FillStyle_NONE ) );
    1381        4014 : }
    1382             : 
    1383        3768 : void DffPropertyReader::ApplyCustomShapeTextAttributes( SfxItemSet& rSet ) const
    1384             : {
    1385        3768 :     bool  bVerticalText = false;
    1386        3768 :     sal_Int32 nTextLeft = GetPropertyValue( DFF_Prop_dxTextLeft, 25 * 3600 ) / 360;     // 0.25 cm (emu)
    1387        3768 :     sal_Int32 nTextRight = GetPropertyValue( DFF_Prop_dxTextRight, 25 * 3600 ) / 360;   // 0.25 cm (emu)
    1388        3768 :     sal_Int32 nTextTop = GetPropertyValue( DFF_Prop_dyTextTop, 13 * 3600 ) / 360;       // 0.13 cm (emu)
    1389        3768 :     sal_Int32 nTextBottom = GetPropertyValue( DFF_Prop_dyTextBottom, 13 * 3600 ) /360;  // 0.13 cm (emu)
    1390             : 
    1391             :     SdrTextVertAdjust eTVA;
    1392             :     SdrTextHorzAdjust eTHA;
    1393             : 
    1394        3768 :     if ( IsProperty( DFF_Prop_txflTextFlow ) )
    1395             :     {
    1396          44 :         MSO_TextFlow eTextFlow = (MSO_TextFlow)( GetPropertyValue( DFF_Prop_txflTextFlow ) & 0xFFFF );
    1397          44 :         switch( eTextFlow )
    1398             :         {
    1399             :             case mso_txflTtoBA :    /* #68110# */   // Top to Bottom @-font, oben -> unten
    1400             :             case mso_txflTtoBN :                    // Top to Bottom non-@, oben -> unten
    1401             :             case mso_txflVertN :                    // Vertical, non-@, oben -> unten
    1402           0 :                 bVerticalText = true;           // nTextRotationAngle += 27000;
    1403           0 :             break;
    1404          44 :             default: break;
    1405             :         }
    1406             :     }
    1407        3768 :     sal_Int32 nFontDirection = GetPropertyValue( DFF_Prop_cdirFont, mso_cdir0 );
    1408        3768 :     if ( ( nFontDirection == 1 ) || ( nFontDirection == 3 ) )
    1409           0 :         bVerticalText = !bVerticalText;
    1410             : 
    1411        3768 :     if ( bVerticalText )
    1412             :     {
    1413           0 :         eTVA = SDRTEXTVERTADJUST_BLOCK;
    1414           0 :         eTHA = SDRTEXTHORZADJUST_CENTER;
    1415             : 
    1416             :         // read text anchor
    1417           0 :         MSO_Anchor eTextAnchor = (MSO_Anchor)GetPropertyValue( DFF_Prop_anchorText, mso_anchorTop );
    1418             : 
    1419           0 :         switch( eTextAnchor )
    1420             :         {
    1421             :             case mso_anchorTop:
    1422             :             case mso_anchorTopCentered:
    1423             :             case mso_anchorTopBaseline:
    1424             :             case mso_anchorTopCenteredBaseline:
    1425           0 :                 eTHA = SDRTEXTHORZADJUST_RIGHT;
    1426           0 :             break;
    1427             : 
    1428             :             case mso_anchorMiddle :
    1429             :             case mso_anchorMiddleCentered:
    1430           0 :                 eTHA = SDRTEXTHORZADJUST_CENTER;
    1431           0 :             break;
    1432             : 
    1433             :             case mso_anchorBottom:
    1434             :             case mso_anchorBottomCentered:
    1435             :             case mso_anchorBottomBaseline:
    1436             :             case mso_anchorBottomCenteredBaseline:
    1437           0 :                 eTHA = SDRTEXTHORZADJUST_LEFT;
    1438           0 :             break;
    1439             :         }
    1440             :         // if there is a 100% use of following attributes, the textbox can been aligned also in vertical direction
    1441           0 :         switch ( eTextAnchor )
    1442             :         {
    1443             :             case mso_anchorTopCentered :
    1444             :             case mso_anchorMiddleCentered :
    1445             :             case mso_anchorBottomCentered :
    1446             :             case mso_anchorTopCenteredBaseline:
    1447             :             case mso_anchorBottomCenteredBaseline:
    1448           0 :                 eTVA = SDRTEXTVERTADJUST_CENTER;
    1449           0 :             break;
    1450             : 
    1451             :             default :
    1452           0 :                 eTVA = SDRTEXTVERTADJUST_TOP;
    1453           0 :             break;
    1454             :         }
    1455             :     }
    1456             :     else
    1457             :     {
    1458        3768 :         eTVA = SDRTEXTVERTADJUST_CENTER;
    1459        3768 :         eTHA = SDRTEXTHORZADJUST_BLOCK;
    1460             : 
    1461             :         // read text anchor
    1462        3768 :         MSO_Anchor eTextAnchor = (MSO_Anchor)GetPropertyValue( DFF_Prop_anchorText, mso_anchorTop );
    1463             : 
    1464        3768 :         switch( eTextAnchor )
    1465             :         {
    1466             :             case mso_anchorTop:
    1467             :             case mso_anchorTopCentered:
    1468             :             case mso_anchorTopBaseline:
    1469             :             case mso_anchorTopCenteredBaseline:
    1470        3336 :                 eTVA = SDRTEXTVERTADJUST_TOP;
    1471        3336 :             break;
    1472             : 
    1473             :             case mso_anchorMiddle :
    1474             :             case mso_anchorMiddleCentered:
    1475         362 :                 eTVA = SDRTEXTVERTADJUST_CENTER;
    1476         362 :             break;
    1477             : 
    1478             :             case mso_anchorBottom:
    1479             :             case mso_anchorBottomCentered:
    1480             :             case mso_anchorBottomBaseline:
    1481             :             case mso_anchorBottomCenteredBaseline:
    1482          70 :                 eTVA = SDRTEXTVERTADJUST_BOTTOM;
    1483          70 :             break;
    1484             :         }
    1485             :         // if there is a 100% usage of following attributes, the textbox can be aligned also in horizontal direction
    1486        3768 :         switch ( eTextAnchor )
    1487             :         {
    1488             :             case mso_anchorTopCentered :
    1489             :             case mso_anchorMiddleCentered :
    1490             :             case mso_anchorBottomCentered :
    1491             :             case mso_anchorTopCenteredBaseline:
    1492             :             case mso_anchorBottomCenteredBaseline:
    1493           0 :                 eTHA = SDRTEXTHORZADJUST_CENTER;    // the text has to be displayed using the full width;
    1494           0 :             break;
    1495             : 
    1496             :             default :
    1497        3768 :                 eTHA = SDRTEXTHORZADJUST_LEFT;
    1498        3768 :             break;
    1499             :         }
    1500             :     }
    1501        3768 :     rSet.Put( SvxFrameDirectionItem( bVerticalText ? FRMDIR_VERT_TOP_RIGHT : FRMDIR_HORI_LEFT_TOP, EE_PARA_WRITINGDIR ) );
    1502             : 
    1503        3768 :     rSet.Put( SdrTextVertAdjustItem( eTVA ) );
    1504        3768 :     rSet.Put( SdrTextHorzAdjustItem( eTHA ) );
    1505             : 
    1506        3768 :     rSet.Put( makeSdrTextLeftDistItem( nTextLeft ) );
    1507        3768 :     rSet.Put( makeSdrTextRightDistItem( nTextRight ) );
    1508        3768 :     rSet.Put( makeSdrTextUpperDistItem( nTextTop ) );
    1509        3768 :     rSet.Put( makeSdrTextLowerDistItem( nTextBottom ) );
    1510             : 
    1511        3768 :     rSet.Put( makeSdrTextWordWrapItem( (MSO_WrapMode)GetPropertyValue( DFF_Prop_WrapText, mso_wrapSquare ) != mso_wrapNone ? sal_True : sal_False ) );
    1512        3768 :     rSet.Put( makeSdrTextAutoGrowHeightItem( ( GetPropertyValue( DFF_Prop_FitTextToShape ) & 2 ) != 0 ) );
    1513        3768 : }
    1514             : 
    1515        3768 : void DffPropertyReader::ApplyCustomShapeGeometryAttributes( SvStream& rIn, SfxItemSet& rSet, const DffObjData& rObjData ) const
    1516             : {
    1517             : 
    1518        3768 :     sal_uInt32 nAdjustmentsWhichNeedsToBeConverted = 0;
    1519             : 
    1520             : 
    1521             :     // creating SdrCustomShapeGeometryItem
    1522             : 
    1523             :     typedef uno::Sequence< beans::PropertyValue > PropSeq;
    1524             :     typedef std::vector< beans::PropertyValue > PropVec;
    1525             :     typedef PropVec::iterator PropVecIter;
    1526        3768 :     PropVecIter aIter;
    1527        3768 :     PropVecIter aEnd;
    1528             : 
    1529             : 
    1530             :     // aPropVec will be filled with all PropertyValues
    1531        3768 :     PropVec aPropVec;
    1532        7536 :     PropertyValue aProp;
    1533             : 
    1534             : 
    1535             :     // "Type" property, including the predefined CustomShape type name
    1536             : 
    1537        7536 :     const OUString sType( "Type" );
    1538        3768 :     aProp.Name  = sType;
    1539        3768 :     aProp.Value <<= EnhancedCustomShapeTypeNames::Get( rObjData.eShapeType );
    1540        3768 :     aPropVec.push_back( aProp );
    1541             : 
    1542             : 
    1543             :     // "ViewBox"
    1544             : 
    1545             : 
    1546        3768 :     sal_Int32 nCoordWidth = 21600;  // needed to replace handle type center with absolute value
    1547        3768 :     sal_Int32 nCoordHeight= 21600;
    1548        3768 :     if ( IsProperty( DFF_Prop_geoLeft ) || IsProperty( DFF_Prop_geoTop ) || IsProperty( DFF_Prop_geoRight ) || IsProperty( DFF_Prop_geoBottom ) )
    1549             :     {
    1550           4 :         com::sun::star::awt::Rectangle aViewBox;
    1551           4 :         const OUString sViewBox( "ViewBox" );
    1552           4 :         aViewBox.X = GetPropertyValue( DFF_Prop_geoLeft, 0 );
    1553           4 :         aViewBox.Y = GetPropertyValue( DFF_Prop_geoTop, 0 );
    1554           4 :         aViewBox.Width = nCoordWidth = ((sal_Int32)GetPropertyValue( DFF_Prop_geoRight, 21600 ) ) - aViewBox.X;
    1555           4 :         aViewBox.Height = nCoordHeight = ((sal_Int32)GetPropertyValue( DFF_Prop_geoBottom, 21600 ) ) - aViewBox.Y;
    1556           4 :         aProp.Name = sViewBox;
    1557           4 :         aProp.Value <<= aViewBox;
    1558           4 :         aPropVec.push_back( aProp );
    1559             :     }
    1560             : 
    1561             :     // TextRotateAngle
    1562             : 
    1563        3768 :     if ( IsProperty( DFF_Prop_txflTextFlow ) || IsProperty( DFF_Prop_cdirFont ) )
    1564             :     {
    1565          44 :         sal_Int32 nTextRotateAngle = 0;
    1566          44 :         MSO_TextFlow eTextFlow = (MSO_TextFlow)( GetPropertyValue( DFF_Prop_txflTextFlow ) & 0xFFFF );
    1567             : 
    1568          44 :         if ( eTextFlow == mso_txflBtoT )    // Bottom to Top non-@
    1569           0 :             nTextRotateAngle += 90;
    1570          44 :         switch( GetPropertyValue( DFF_Prop_cdirFont, mso_cdir0 ) )  // SJ: mso_cdir90 and mso_cdir270 will be simulated by
    1571             :         {                                                           // activating vertical writing for the text objects
    1572             :             case mso_cdir90 :
    1573             :             {
    1574           0 :                 if ( eTextFlow == mso_txflTtoBA )
    1575           0 :                     nTextRotateAngle -= 180;
    1576             :             }
    1577           0 :             break;
    1578           0 :             case mso_cdir180: nTextRotateAngle -= 180; break;
    1579             :             case mso_cdir270:
    1580             :             {
    1581           0 :                 if ( eTextFlow != mso_txflTtoBA )
    1582           0 :                     nTextRotateAngle -= 180;
    1583             :             }
    1584           0 :             break;
    1585          44 :             default: break;
    1586             :         }
    1587          44 :         if ( nTextRotateAngle )
    1588             :         {
    1589           0 :             double fTextRotateAngle = nTextRotateAngle;
    1590           0 :             const OUString sTextRotateAngle( "TextRotateAngle" );
    1591           0 :             aProp.Name = sTextRotateAngle;
    1592           0 :             aProp.Value <<= fTextRotateAngle;
    1593           0 :             aPropVec.push_back( aProp );
    1594             :         }
    1595             :     }
    1596             : 
    1597             :     // "Extrusion" PropertySequence element
    1598             : 
    1599        3768 :     bool bExtrusionOn = ( GetPropertyValue( DFF_Prop_fc3DLightFace ) & 8 ) != 0;
    1600        3768 :     if ( bExtrusionOn )
    1601             :     {
    1602           0 :         PropVec aExtrusionPropVec;
    1603             : 
    1604             :         // "Extrusion"
    1605           0 :         const OUString sExtrusionOn( "Extrusion" );
    1606           0 :         aProp.Name = sExtrusionOn;
    1607           0 :         aProp.Value <<= bExtrusionOn;
    1608           0 :         aExtrusionPropVec.push_back( aProp );
    1609             : 
    1610             :         // "Brightness"
    1611           0 :         if ( IsProperty( DFF_Prop_c3DAmbientIntensity ) )
    1612             :         {
    1613           0 :             const OUString sExtrusionBrightness( "Brightness" );
    1614           0 :             double fBrightness = (sal_Int32)GetPropertyValue( DFF_Prop_c3DAmbientIntensity );
    1615           0 :             fBrightness /= 655.36;
    1616           0 :             aProp.Name = sExtrusionBrightness;
    1617           0 :             aProp.Value <<= fBrightness;
    1618           0 :             aExtrusionPropVec.push_back( aProp );
    1619             :         }
    1620             :         // "Depth" in 1/100mm
    1621           0 :         if ( IsProperty( DFF_Prop_c3DExtrudeBackward ) || IsProperty( DFF_Prop_c3DExtrudeForward ) )
    1622             :         {
    1623           0 :             const OUString sDepth( "Depth" );
    1624           0 :             double fBackDepth = (double)((sal_Int32)GetPropertyValue( DFF_Prop_c3DExtrudeBackward, 1270 * 360 )) / 360.0;
    1625           0 :             double fForeDepth = (double)((sal_Int32)GetPropertyValue( DFF_Prop_c3DExtrudeForward, 0 )) / 360.0;
    1626           0 :             double fDepth = fBackDepth + fForeDepth;
    1627           0 :             double fFraction = fDepth != 0.0 ? fForeDepth / fDepth : 0;
    1628           0 :             EnhancedCustomShapeParameterPair aDepthParaPair;
    1629           0 :             aDepthParaPair.First.Value <<= fDepth;
    1630           0 :             aDepthParaPair.First.Type = EnhancedCustomShapeParameterType::NORMAL;
    1631           0 :             aDepthParaPair.Second.Value <<= fFraction;
    1632           0 :             aDepthParaPair.Second.Type = EnhancedCustomShapeParameterType::NORMAL;
    1633           0 :             aProp.Name = sDepth;
    1634           0 :             aProp.Value <<= aDepthParaPair;
    1635           0 :             aExtrusionPropVec.push_back( aProp );
    1636             :         }
    1637             :         // "Diffusion"
    1638           0 :         if ( IsProperty( DFF_Prop_c3DDiffuseAmt ) )
    1639             :         {
    1640           0 :             const OUString sExtrusionDiffusion( "Diffusion" );
    1641           0 :             double fDiffusion = (sal_Int32)GetPropertyValue( DFF_Prop_c3DDiffuseAmt );
    1642           0 :             fDiffusion /= 655.36;
    1643           0 :             aProp.Name = sExtrusionDiffusion;
    1644           0 :             aProp.Value <<= fDiffusion;
    1645           0 :             aExtrusionPropVec.push_back( aProp );
    1646             :         }
    1647             :         // "NumberOfLineSegments"
    1648           0 :         if ( IsProperty( DFF_Prop_c3DTolerance ) )
    1649             :         {
    1650           0 :             const OUString sExtrusionNumberOfLineSegments( "NumberOfLineSegments" );
    1651           0 :             aProp.Name = sExtrusionNumberOfLineSegments;
    1652           0 :             aProp.Value <<= (sal_Int32)GetPropertyValue( DFF_Prop_c3DTolerance );
    1653           0 :             aExtrusionPropVec.push_back( aProp );
    1654             :         }
    1655             :         // "LightFace"
    1656           0 :         const OUString sExtrusionLightFace( "LightFace" );
    1657           0 :         bool bExtrusionLightFace = ( GetPropertyValue( DFF_Prop_fc3DLightFace ) & 1 ) != 0;
    1658           0 :         aProp.Name = sExtrusionLightFace;
    1659           0 :         aProp.Value <<= bExtrusionLightFace;
    1660           0 :         aExtrusionPropVec.push_back( aProp );
    1661             :         // "FirstLightHarsh"
    1662           0 :         const OUString sExtrusionFirstLightHarsh( "FirstLightHarsh" );
    1663           0 :         bool bExtrusionFirstLightHarsh = ( GetPropertyValue( DFF_Prop_fc3DFillHarsh ) & 2 ) != 0;
    1664           0 :         aProp.Name = sExtrusionFirstLightHarsh;
    1665           0 :         aProp.Value <<= bExtrusionFirstLightHarsh;
    1666           0 :         aExtrusionPropVec.push_back( aProp );
    1667             :         // "SecondLightHarsh"
    1668           0 :         const OUString sExtrusionSecondLightHarsh( "SecondLightHarsh" );
    1669           0 :         bool bExtrusionSecondLightHarsh = ( GetPropertyValue( DFF_Prop_fc3DFillHarsh ) & 1 ) != 0;
    1670           0 :         aProp.Name = sExtrusionSecondLightHarsh;
    1671           0 :         aProp.Value <<= bExtrusionSecondLightHarsh;
    1672           0 :         aExtrusionPropVec.push_back( aProp );
    1673             :         // "FirstLightLevel"
    1674           0 :         if ( IsProperty( DFF_Prop_c3DKeyIntensity ) )
    1675             :         {
    1676           0 :             const OUString sExtrusionFirstLightLevel( "FirstLightLevel" );
    1677           0 :             double fFirstLightLevel = (sal_Int32)GetPropertyValue( DFF_Prop_c3DKeyIntensity );
    1678           0 :             fFirstLightLevel /= 655.36;
    1679           0 :             aProp.Name = sExtrusionFirstLightLevel;
    1680           0 :             aProp.Value <<= fFirstLightLevel;
    1681           0 :             aExtrusionPropVec.push_back( aProp );
    1682             :         }
    1683             :         // "SecondLightLevel"
    1684           0 :         if ( IsProperty( DFF_Prop_c3DFillIntensity ) )
    1685             :         {
    1686           0 :             const OUString sExtrusionSecondLightLevel( "SecondLightLevel" );
    1687           0 :             double fSecondLightLevel = (sal_Int32)GetPropertyValue( DFF_Prop_c3DFillIntensity );
    1688           0 :             fSecondLightLevel /= 655.36;
    1689           0 :             aProp.Name = sExtrusionSecondLightLevel;
    1690           0 :             aProp.Value <<= fSecondLightLevel;
    1691           0 :             aExtrusionPropVec.push_back( aProp );
    1692             :         }
    1693             :         // "FirtstLightDirection"
    1694           0 :         if ( IsProperty( DFF_Prop_c3DKeyX ) || IsProperty( DFF_Prop_c3DKeyY ) || IsProperty( DFF_Prop_c3DKeyZ ) )
    1695             :         {
    1696           0 :             double fLightX = (double)((sal_Int32)GetPropertyValue( DFF_Prop_c3DKeyX, 50000 ));
    1697           0 :             double fLightY = (double)((sal_Int32)GetPropertyValue( DFF_Prop_c3DKeyY, 0 ));
    1698           0 :             double fLightZ = (double)((sal_Int32)GetPropertyValue( DFF_Prop_c3DKeyZ, 10000 ));
    1699           0 :             ::com::sun::star::drawing::Direction3D aExtrusionFirstLightDirection( fLightX, fLightY, fLightZ );
    1700           0 :             const OUString sExtrusionFirstLightDirection( "FirstLightDirection" );
    1701           0 :             aProp.Name = sExtrusionFirstLightDirection;
    1702           0 :             aProp.Value <<= aExtrusionFirstLightDirection;
    1703           0 :             aExtrusionPropVec.push_back( aProp );
    1704             :         }
    1705             :         // "SecondLightDirection"
    1706           0 :         if ( IsProperty( DFF_Prop_c3DFillX ) || IsProperty( DFF_Prop_c3DFillY ) || IsProperty( DFF_Prop_c3DFillZ ) )
    1707             :         {
    1708           0 :             double fLight2X = (double)((sal_Int32)GetPropertyValue( DFF_Prop_c3DFillX, (sal_uInt32)-50000 ));
    1709           0 :             double fLight2Y = (double)((sal_Int32)GetPropertyValue( DFF_Prop_c3DFillY, 0 ));
    1710           0 :             double fLight2Z = (double)((sal_Int32)GetPropertyValue( DFF_Prop_c3DFillZ, 10000 ));
    1711           0 :             ::com::sun::star::drawing::Direction3D aExtrusionSecondLightDirection( fLight2X, fLight2Y, fLight2Z );
    1712           0 :             const OUString sExtrusionSecondLightDirection( "SecondLightDirection" );
    1713           0 :             aProp.Name = sExtrusionSecondLightDirection;
    1714           0 :             aProp.Value <<= aExtrusionSecondLightDirection;
    1715           0 :             aExtrusionPropVec.push_back( aProp );
    1716             :         }
    1717             : 
    1718             :         // "Metal"
    1719           0 :         const OUString sExtrusionMetal( "Metal" );
    1720           0 :         bool bExtrusionMetal = ( GetPropertyValue( DFF_Prop_fc3DLightFace ) & 4 ) != 0;
    1721           0 :         aProp.Name = sExtrusionMetal;
    1722           0 :         aProp.Value <<= bExtrusionMetal;
    1723           0 :         aExtrusionPropVec.push_back( aProp );
    1724             :         // "ShadeMode"
    1725           0 :         if ( IsProperty( DFF_Prop_c3DRenderMode ) )
    1726             :         {
    1727           0 :             const OUString sExtrusionShadeMode( "ShadeMode" );
    1728           0 :             sal_uInt32 nExtrusionRenderMode = GetPropertyValue( DFF_Prop_c3DRenderMode );
    1729           0 :             com::sun::star::drawing::ShadeMode eExtrusionShadeMode( com::sun::star::drawing::ShadeMode_FLAT );
    1730           0 :             if ( nExtrusionRenderMode == mso_Wireframe )
    1731           0 :                 eExtrusionShadeMode = com::sun::star::drawing::ShadeMode_DRAFT;
    1732             : 
    1733           0 :             aProp.Name = sExtrusionShadeMode;
    1734           0 :             aProp.Value <<= eExtrusionShadeMode;
    1735           0 :             aExtrusionPropVec.push_back( aProp );
    1736             :         }
    1737             :         // "RotateAngle" in Grad
    1738           0 :         if ( IsProperty( DFF_Prop_c3DXRotationAngle ) || IsProperty( DFF_Prop_c3DYRotationAngle ) )
    1739             :         {
    1740           0 :             const OUString sExtrusionAngle( "RotateAngle" );
    1741           0 :             double fAngleX = (double)((sal_Int32)GetPropertyValue( DFF_Prop_c3DXRotationAngle, 0 )) / 65536.0;
    1742           0 :             double fAngleY = (double)((sal_Int32)GetPropertyValue( DFF_Prop_c3DYRotationAngle, 0 )) / 65536.0;
    1743           0 :             EnhancedCustomShapeParameterPair aRotateAnglePair;
    1744           0 :             aRotateAnglePair.First.Value <<= fAngleX;
    1745           0 :             aRotateAnglePair.First.Type = EnhancedCustomShapeParameterType::NORMAL;
    1746           0 :             aRotateAnglePair.Second.Value <<= fAngleY;
    1747           0 :             aRotateAnglePair.Second.Type = EnhancedCustomShapeParameterType::NORMAL;
    1748           0 :             aProp.Name = sExtrusionAngle;
    1749           0 :             aProp.Value <<= aRotateAnglePair;
    1750           0 :             aExtrusionPropVec.push_back( aProp );
    1751             :         }
    1752             : 
    1753             :         // "AutoRotationCenter"
    1754           0 :         if ( ( GetPropertyValue( DFF_Prop_fc3DFillHarsh ) & 8 ) == 0 )
    1755             :         {
    1756             :             // "RotationCenter"
    1757           0 :             if ( IsProperty( DFF_Prop_c3DRotationCenterX ) || IsProperty( DFF_Prop_c3DRotationCenterY ) || IsProperty( DFF_Prop_c3DRotationCenterZ ) )
    1758             :             {
    1759             :                 ::com::sun::star::drawing::Direction3D aRotationCenter(
    1760           0 :                     (double)((sal_Int32)GetPropertyValue( DFF_Prop_c3DRotationCenterX, 0 )) / 360.0,
    1761           0 :                     (double)((sal_Int32)GetPropertyValue( DFF_Prop_c3DRotationCenterY, 0 )) / 360.0,
    1762           0 :                     (double)((sal_Int32)GetPropertyValue( DFF_Prop_c3DRotationCenterZ, 0 )) / 360.0 );
    1763             : 
    1764           0 :                 const OUString sExtrusionRotationCenter( "RotationCenter" );
    1765           0 :                 aProp.Name = sExtrusionRotationCenter;
    1766           0 :                 aProp.Value <<= aRotationCenter;
    1767           0 :                 aExtrusionPropVec.push_back( aProp );
    1768             :             }
    1769             :         }
    1770             :         // "Shininess"
    1771           0 :         if ( IsProperty( DFF_Prop_c3DShininess ) )
    1772             :         {
    1773           0 :             const OUString sExtrusionShininess( "Shininess" );
    1774           0 :             double fShininess = (sal_Int32)GetPropertyValue( DFF_Prop_c3DShininess );
    1775           0 :             fShininess /= 655.36;
    1776           0 :             aProp.Name = sExtrusionShininess;
    1777           0 :             aProp.Value <<= fShininess;
    1778           0 :             aExtrusionPropVec.push_back( aProp );
    1779             :         }
    1780             :         // "Skew"
    1781           0 :         if ( IsProperty( DFF_Prop_c3DSkewAmount ) || IsProperty( DFF_Prop_c3DSkewAngle ) )
    1782             :         {
    1783           0 :             const OUString sExtrusionSkew( "Skew" );
    1784           0 :             double fSkewAmount = (sal_Int32)GetPropertyValue( DFF_Prop_c3DSkewAmount, 50 );
    1785           0 :             double fSkewAngle = (double)((sal_Int32)GetPropertyValue( DFF_Prop_c3DSkewAngle, sal::static_int_cast< sal_uInt32 >(-135 * 65536) )) / 65536.0;
    1786             : 
    1787           0 :             EnhancedCustomShapeParameterPair aSkewPair;
    1788           0 :             aSkewPair.First.Value <<= fSkewAmount;
    1789           0 :             aSkewPair.First.Type = EnhancedCustomShapeParameterType::NORMAL;
    1790           0 :             aSkewPair.Second.Value <<= fSkewAngle;
    1791           0 :             aSkewPair.Second.Type = EnhancedCustomShapeParameterType::NORMAL;
    1792           0 :             aProp.Name = sExtrusionSkew;
    1793           0 :             aProp.Value <<= aSkewPair;
    1794           0 :             aExtrusionPropVec.push_back( aProp );
    1795             :         }
    1796             :         // "Specularity"
    1797           0 :         if ( IsProperty( DFF_Prop_c3DSpecularAmt ) )
    1798             :         {
    1799           0 :             const OUString sExtrusionSpecularity( "Specularity" );
    1800           0 :             double fSpecularity = (sal_Int32)GetPropertyValue( DFF_Prop_c3DSpecularAmt );
    1801           0 :             fSpecularity /= 1333;
    1802           0 :             aProp.Name = sExtrusionSpecularity;
    1803           0 :             aProp.Value <<= fSpecularity;
    1804           0 :             aExtrusionPropVec.push_back( aProp );
    1805             :         }
    1806             :         // "ProjectionMode"
    1807           0 :         const OUString sExtrusionProjectionMode( "ProjectionMode" );
    1808           0 :         ProjectionMode eProjectionMode = GetPropertyValue( DFF_Prop_fc3DFillHarsh ) & 4 ? ProjectionMode_PARALLEL : ProjectionMode_PERSPECTIVE;
    1809           0 :         aProp.Name = sExtrusionProjectionMode;
    1810           0 :         aProp.Value <<= eProjectionMode;
    1811           0 :         aExtrusionPropVec.push_back( aProp );
    1812             : 
    1813             :         // "ViewPoint" in 1/100mm
    1814           0 :         if ( IsProperty( DFF_Prop_c3DXViewpoint ) || IsProperty( DFF_Prop_c3DYViewpoint ) || IsProperty( DFF_Prop_c3DZViewpoint ) )
    1815             :         {
    1816           0 :             double fViewX = (double)((sal_Int32)GetPropertyValue( DFF_Prop_c3DXViewpoint, 1250000 )) / 360.0;
    1817           0 :             double fViewY = (double)((sal_Int32)GetPropertyValue( DFF_Prop_c3DYViewpoint, (sal_uInt32)-1250000 ))/ 360.0;
    1818           0 :             double fViewZ = (double)((sal_Int32)GetPropertyValue( DFF_Prop_c3DZViewpoint, 9000000 )) / 360.0;
    1819           0 :             ::com::sun::star::drawing::Position3D aExtrusionViewPoint( fViewX, fViewY, fViewZ );
    1820           0 :             const OUString sExtrusionViewPoint( "ViewPoint" );
    1821           0 :             aProp.Name = sExtrusionViewPoint;
    1822           0 :             aProp.Value <<= aExtrusionViewPoint;
    1823           0 :             aExtrusionPropVec.push_back( aProp );
    1824             :         }
    1825             :         // "Origin"
    1826           0 :         if ( IsProperty( DFF_Prop_c3DOriginX ) || IsProperty( DFF_Prop_c3DOriginY ) )
    1827             :         {
    1828           0 :             const OUString sExtrusionOrigin( "Origin" );
    1829           0 :             double fOriginX = (double)((sal_Int32)GetPropertyValue( DFF_Prop_c3DOriginX, 32768 ));
    1830           0 :             double fOriginY = (double)((sal_Int32)GetPropertyValue( DFF_Prop_c3DOriginY, (sal_uInt32)-32768 ));
    1831           0 :             fOriginX /= 65536;
    1832           0 :             fOriginY /= 65536;
    1833           0 :             EnhancedCustomShapeParameterPair aOriginPair;
    1834           0 :             aOriginPair.First.Value <<= fOriginX;
    1835           0 :             aOriginPair.First.Type = EnhancedCustomShapeParameterType::NORMAL;
    1836           0 :             aOriginPair.Second.Value <<= fOriginY;
    1837           0 :             aOriginPair.Second.Type = EnhancedCustomShapeParameterType::NORMAL;
    1838           0 :             aProp.Name = sExtrusionOrigin;
    1839           0 :             aProp.Value <<= aOriginPair;
    1840           0 :             aExtrusionPropVec.push_back( aProp );
    1841             :         }
    1842             :         // "ExtrusionColor"
    1843           0 :         const OUString sExtrusionColor( "Color" );
    1844           0 :         bool bExtrusionColor = IsProperty( DFF_Prop_c3DExtrusionColor );    // ( GetPropertyValue( DFF_Prop_fc3DLightFace ) & 2 ) != 0;
    1845           0 :         aProp.Name = sExtrusionColor;
    1846           0 :         aProp.Value <<= bExtrusionColor;
    1847           0 :         aExtrusionPropVec.push_back( aProp );
    1848           0 :         if ( IsProperty( DFF_Prop_c3DExtrusionColor ) )
    1849             :             rSet.Put( XSecondaryFillColorItem( OUString(), rManager.MSO_CLR_ToColor(
    1850           0 :                 GetPropertyValue( DFF_Prop_c3DExtrusionColor ), DFF_Prop_c3DExtrusionColor ) ) );
    1851             :         // pushing the whole Extrusion element
    1852           0 :         const OUString sExtrusion( "Extrusion" );
    1853           0 :         PropSeq aExtrusionPropSeq( aExtrusionPropVec.size() );
    1854           0 :         aIter = aExtrusionPropVec.begin();
    1855           0 :         aEnd = aExtrusionPropVec.end();
    1856           0 :         beans::PropertyValue* pExtrusionValues = aExtrusionPropSeq.getArray();
    1857           0 :         while ( aIter != aEnd )
    1858           0 :             *pExtrusionValues++ = *aIter++;
    1859           0 :         aProp.Name = sExtrusion;
    1860           0 :         aProp.Value <<= aExtrusionPropSeq;
    1861           0 :         aPropVec.push_back( aProp );
    1862             :     }
    1863             : 
    1864             : 
    1865             :     // "Equations" PropertySequence element
    1866             : 
    1867        3768 :     if ( IsProperty( DFF_Prop_pFormulas ) )
    1868             :     {
    1869           0 :         sal_uInt16 nNumElem = 0;
    1870             : 
    1871           0 :         if ( SeekToContent( DFF_Prop_pFormulas, rIn ) )
    1872             :         {
    1873           0 :             sal_uInt16 nNumElemMem = 0;
    1874           0 :             sal_uInt16 nElemSize = 8;
    1875           0 :             rIn.ReadUInt16( nNumElem ).ReadUInt16( nNumElemMem ).ReadUInt16( nElemSize );
    1876             :         }
    1877           0 :         if ( nNumElem <= 128 )
    1878             :         {
    1879           0 :             uno::Sequence< OUString > aEquations( nNumElem );
    1880           0 :             for ( sal_uInt16 i = 0; i < nNumElem; i++ )
    1881             :             {
    1882           0 :                 sal_Int16 nP1(0), nP2(0), nP3(0);
    1883           0 :                 sal_uInt16 nFlags(0);
    1884           0 :                 rIn.ReadUInt16( nFlags ).ReadInt16( nP1 ).ReadInt16( nP2 ).ReadInt16( nP3 );
    1885           0 :                 aEquations[ i ] = EnhancedCustomShape2d::GetEquation( nFlags, nP1, nP2, nP3 );
    1886             :             }
    1887             :             // pushing the whole Equations element
    1888           0 :             const OUString sEquations( "Equations" );
    1889           0 :             aProp.Name = sEquations;
    1890           0 :             aProp.Value <<= aEquations;
    1891           0 :             aPropVec.push_back( aProp );
    1892             :         }
    1893             :     }
    1894             : 
    1895             : 
    1896             :     // "Handles" PropertySequence element
    1897             : 
    1898        3768 :     if ( IsProperty( DFF_Prop_Handles ) )
    1899             :     {
    1900           0 :         sal_uInt16 nNumElem = 0;
    1901           0 :         sal_uInt16 nElemSize = 36;
    1902             : 
    1903           0 :         if ( SeekToContent( DFF_Prop_Handles, rIn ) )
    1904             :         {
    1905           0 :             sal_uInt16 nNumElemMem = 0;
    1906           0 :             rIn.ReadUInt16( nNumElem ).ReadUInt16( nNumElemMem ).ReadUInt16( nElemSize );
    1907             :         }
    1908           0 :         bool bImport = false;
    1909           0 :         if (nElemSize == 36)
    1910             :         {
    1911             :             //sanity check that the stream is long enough to fulfill nNumElem * nElemSize;
    1912           0 :             bImport = rIn.remainingSize() / nElemSize >= nNumElem;
    1913             :         }
    1914           0 :         if (bImport)
    1915             :         {
    1916           0 :             uno::Sequence< beans::PropertyValues > aHandles( nNumElem );
    1917           0 :             for ( sal_uInt16 i = 0; i < nNumElem; i++ )
    1918             :             {
    1919           0 :                 PropVec aHandlePropVec;
    1920             :                 sal_uInt32  nFlags;
    1921             :                 sal_Int32   nPositionX, nPositionY, nCenterX, nCenterY, nRangeXMin, nRangeXMax, nRangeYMin, nRangeYMax;
    1922           0 :                 rIn.ReadUInt32( nFlags )
    1923           0 :                    .ReadInt32( nPositionX )
    1924           0 :                    .ReadInt32( nPositionY )
    1925           0 :                    .ReadInt32( nCenterX )
    1926           0 :                    .ReadInt32( nCenterY )
    1927           0 :                    .ReadInt32( nRangeXMin )
    1928           0 :                    .ReadInt32( nRangeXMax )
    1929           0 :                    .ReadInt32( nRangeYMin )
    1930           0 :                    .ReadInt32( nRangeYMax );
    1931             : 
    1932           0 :                 if ( nPositionX == 2 )  // replacing center position with absolute value
    1933           0 :                     nPositionX = nCoordWidth / 2;
    1934           0 :                 if ( nPositionY == 2 )
    1935           0 :                     nPositionY = nCoordHeight / 2;
    1936           0 :                 EnhancedCustomShapeParameterPair aPosition;
    1937           0 :                 EnhancedCustomShape2d::SetEnhancedCustomShapeHandleParameter( aPosition.First,  nPositionX, true, true  );
    1938           0 :                 EnhancedCustomShape2d::SetEnhancedCustomShapeHandleParameter( aPosition.Second, nPositionY, true, false );
    1939           0 :                 const OUString sHandlePosition( "Position" );
    1940           0 :                 aProp.Name = sHandlePosition;
    1941           0 :                 aProp.Value <<= aPosition;
    1942           0 :                 aHandlePropVec.push_back( aProp );
    1943             : 
    1944           0 :                 if ( nFlags & MSDFF_HANDLE_FLAGS_MIRRORED_X )
    1945             :                 {
    1946           0 :                     bool bMirroredX = true;
    1947           0 :                     const OUString sHandleMirroredX( "MirroredX" );
    1948           0 :                     aProp.Name = sHandleMirroredX;
    1949           0 :                     aProp.Value <<= bMirroredX;
    1950           0 :                     aHandlePropVec.push_back( aProp );
    1951             :                 }
    1952           0 :                 if ( nFlags & MSDFF_HANDLE_FLAGS_MIRRORED_Y )
    1953             :                 {
    1954           0 :                     bool bMirroredY = true;
    1955           0 :                     const OUString sHandleMirroredY( "MirroredY" );
    1956           0 :                     aProp.Name = sHandleMirroredY;
    1957           0 :                     aProp.Value <<= bMirroredY;
    1958           0 :                     aHandlePropVec.push_back( aProp );
    1959             :                 }
    1960           0 :                 if ( nFlags & MSDFF_HANDLE_FLAGS_SWITCHED )
    1961             :                 {
    1962           0 :                     bool bSwitched = true;
    1963           0 :                     const OUString sHandleSwitched( "Switched" );
    1964           0 :                     aProp.Name = sHandleSwitched;
    1965           0 :                     aProp.Value <<= bSwitched;
    1966           0 :                     aHandlePropVec.push_back( aProp );
    1967             :                 }
    1968           0 :                 if ( nFlags & MSDFF_HANDLE_FLAGS_POLAR )
    1969             :                 {
    1970           0 :                     if ( nCenterX == 2 )
    1971           0 :                         nCenterX = nCoordWidth / 2;
    1972           0 :                     if ( nCenterY == 2 )
    1973           0 :                         nCenterY = nCoordHeight / 2;
    1974           0 :                     if ( ( nPositionY >= 0x256 ) || ( nPositionY <= 0x107 ) )   // position y
    1975           0 :                         nAdjustmentsWhichNeedsToBeConverted |= ( 1 << i );
    1976           0 :                     EnhancedCustomShapeParameterPair aPolar;
    1977           0 :                     EnhancedCustomShape2d::SetEnhancedCustomShapeHandleParameter( aPolar.First,  nCenterX, ( nFlags & 0x800  ) != 0, true  );
    1978           0 :                     EnhancedCustomShape2d::SetEnhancedCustomShapeHandleParameter( aPolar.Second, nCenterY, ( nFlags & 0x1000 ) != 0, false );
    1979           0 :                     const OUString sHandlePolar( "Polar" );
    1980           0 :                     aProp.Name = sHandlePolar;
    1981           0 :                     aProp.Value <<= aPolar;
    1982           0 :                     aHandlePropVec.push_back( aProp );
    1983             :                 }
    1984           0 :                 if ( nFlags & MSDFF_HANDLE_FLAGS_MAP )
    1985             :                 {
    1986           0 :                     if ( nCenterX == 2 )
    1987           0 :                         nCenterX = nCoordWidth / 2;
    1988           0 :                     if ( nCenterY == 2 )
    1989           0 :                         nCenterY = nCoordHeight / 2;
    1990           0 :                     EnhancedCustomShapeParameterPair aMap;
    1991           0 :                     EnhancedCustomShape2d::SetEnhancedCustomShapeHandleParameter( aMap.First,  nCenterX, ( nFlags & 0x800  ) != 0, true  );
    1992           0 :                     EnhancedCustomShape2d::SetEnhancedCustomShapeHandleParameter( aMap.Second, nCenterY, ( nFlags & 0x1000 ) != 0, false );
    1993           0 :                     const OUString sHandleMap( "Map" );
    1994           0 :                     aProp.Name = sHandleMap;
    1995           0 :                     aProp.Value <<= aMap;
    1996           0 :                     aHandlePropVec.push_back( aProp );
    1997             :                 }
    1998           0 :                 if ( nFlags & MSDFF_HANDLE_FLAGS_RANGE )
    1999             :                 {
    2000           0 :                     if ( (sal_uInt32)nRangeXMin != 0x80000000 )
    2001             :                     {
    2002           0 :                         if ( nRangeXMin == 2 )
    2003           0 :                             nRangeXMin = nCoordWidth / 2;
    2004           0 :                         EnhancedCustomShapeParameter aRangeXMinimum;
    2005             :                         EnhancedCustomShape2d::SetEnhancedCustomShapeHandleParameter( aRangeXMinimum,  nRangeXMin,
    2006           0 :                             ( nFlags & MSDFF_HANDLE_FLAGS_RANGE_X_MIN_IS_SPECIAL ) != 0, true  );
    2007           0 :                         const OUString sHandleRangeXMinimum( "RangeXMinimum" );
    2008           0 :                         aProp.Name = sHandleRangeXMinimum;
    2009           0 :                         aProp.Value <<= aRangeXMinimum;
    2010           0 :                         aHandlePropVec.push_back( aProp );
    2011             :                     }
    2012           0 :                     if ( (sal_uInt32)nRangeXMax != 0x7fffffff )
    2013             :                     {
    2014           0 :                         if ( nRangeXMax == 2 )
    2015           0 :                             nRangeXMax = nCoordWidth / 2;
    2016           0 :                         EnhancedCustomShapeParameter aRangeXMaximum;
    2017             :                         EnhancedCustomShape2d::SetEnhancedCustomShapeHandleParameter( aRangeXMaximum, nRangeXMax,
    2018           0 :                             ( nFlags & MSDFF_HANDLE_FLAGS_RANGE_X_MAX_IS_SPECIAL ) != 0, false );
    2019           0 :                         const OUString sHandleRangeXMaximum( "RangeXMaximum" );
    2020           0 :                         aProp.Name = sHandleRangeXMaximum;
    2021           0 :                         aProp.Value <<= aRangeXMaximum;
    2022           0 :                         aHandlePropVec.push_back( aProp );
    2023             :                     }
    2024           0 :                     if ( (sal_uInt32)nRangeYMin != 0x80000000 )
    2025             :                     {
    2026           0 :                         if ( nRangeYMin == 2 )
    2027           0 :                             nRangeYMin = nCoordHeight / 2;
    2028           0 :                         EnhancedCustomShapeParameter aRangeYMinimum;
    2029             :                         EnhancedCustomShape2d::SetEnhancedCustomShapeHandleParameter( aRangeYMinimum, nRangeYMin,
    2030           0 :                             ( nFlags & MSDFF_HANDLE_FLAGS_RANGE_Y_MIN_IS_SPECIAL ) != 0, true );
    2031           0 :                         const OUString sHandleRangeYMinimum( "RangeYMinimum" );
    2032           0 :                         aProp.Name = sHandleRangeYMinimum;
    2033           0 :                         aProp.Value <<= aRangeYMinimum;
    2034           0 :                         aHandlePropVec.push_back( aProp );
    2035             :                     }
    2036           0 :                     if ( (sal_uInt32)nRangeYMax != 0x7fffffff )
    2037             :                     {
    2038           0 :                         if ( nRangeYMax == 2 )
    2039           0 :                             nRangeYMax = nCoordHeight / 2;
    2040           0 :                         EnhancedCustomShapeParameter aRangeYMaximum;
    2041             :                         EnhancedCustomShape2d::SetEnhancedCustomShapeHandleParameter( aRangeYMaximum, nRangeYMax,
    2042           0 :                             ( nFlags & MSDFF_HANDLE_FLAGS_RANGE_Y_MAX_IS_SPECIAL ) != 0, false );
    2043           0 :                         const OUString sHandleRangeYMaximum( "RangeYMaximum" );
    2044           0 :                         aProp.Name = sHandleRangeYMaximum;
    2045           0 :                         aProp.Value <<= aRangeYMaximum;
    2046           0 :                         aHandlePropVec.push_back( aProp );
    2047             :                     }
    2048             :                 }
    2049           0 :                 if ( nFlags & MSDFF_HANDLE_FLAGS_RADIUS_RANGE )
    2050             :                 {
    2051           0 :                     if ( (sal_uInt32)nRangeXMin != 0x7fffffff )
    2052             :                     {
    2053           0 :                         if ( nRangeXMin == 2 )
    2054           0 :                             nRangeXMin = nCoordWidth / 2;
    2055           0 :                         EnhancedCustomShapeParameter aRadiusRangeMinimum;
    2056             :                         EnhancedCustomShape2d::SetEnhancedCustomShapeHandleParameter( aRadiusRangeMinimum, nRangeXMin,
    2057           0 :                             ( nFlags & MSDFF_HANDLE_FLAGS_RANGE_X_MIN_IS_SPECIAL ) != 0, true  );
    2058           0 :                         const OUString sHandleRadiusRangeMinimum( "RadiusRangeMinimum" );
    2059           0 :                         aProp.Name = sHandleRadiusRangeMinimum;
    2060           0 :                         aProp.Value <<= aRadiusRangeMinimum;
    2061           0 :                         aHandlePropVec.push_back( aProp );
    2062             :                     }
    2063           0 :                     if ( (sal_uInt32)nRangeXMax != 0x80000000 )
    2064             :                     {
    2065           0 :                         if ( nRangeXMax == 2 )
    2066           0 :                             nRangeXMax = nCoordWidth / 2;
    2067           0 :                         EnhancedCustomShapeParameter aRadiusRangeMaximum;
    2068             :                         EnhancedCustomShape2d::SetEnhancedCustomShapeHandleParameter( aRadiusRangeMaximum, nRangeXMax,
    2069           0 :                             ( nFlags & MSDFF_HANDLE_FLAGS_RANGE_X_MAX_IS_SPECIAL ) != 0, false );
    2070           0 :                         const OUString sHandleRadiusRangeMaximum( "RadiusRangeMaximum" );
    2071           0 :                         aProp.Name = sHandleRadiusRangeMaximum;
    2072           0 :                         aProp.Value <<= aRadiusRangeMaximum;
    2073           0 :                         aHandlePropVec.push_back( aProp );
    2074             :                     }
    2075             :                 }
    2076           0 :                 if ( !aHandlePropVec.empty() )
    2077             :                 {
    2078           0 :                     PropSeq aHandlePropSeq( aHandlePropVec.size() );
    2079           0 :                     aIter = aHandlePropVec.begin();
    2080           0 :                     aEnd = aHandlePropVec.end();
    2081           0 :                     beans::PropertyValue* pHandleValues = aHandlePropSeq.getArray();
    2082           0 :                     while ( aIter != aEnd )
    2083           0 :                         *pHandleValues++ = *aIter++;
    2084           0 :                     aHandles[ i ] = aHandlePropSeq;
    2085             :                 }
    2086           0 :             }
    2087             :             // pushing the whole Handles element
    2088           0 :             const OUString sHandles( "Handles" );
    2089           0 :             aProp.Name = sHandles;
    2090           0 :             aProp.Value <<= aHandles;
    2091           0 :             aPropVec.push_back( aProp );
    2092             :         }
    2093             :     }
    2094             :     else
    2095             :     {
    2096        3768 :         const mso_CustomShape* pDefCustomShape = GetCustomShapeContent( rObjData.eShapeType );
    2097        3768 :         if ( pDefCustomShape && pDefCustomShape->nHandles && pDefCustomShape->pHandles )
    2098             :         {
    2099          84 :             sal_Int32 i, nCnt = pDefCustomShape->nHandles;
    2100          84 :             const SvxMSDffHandle* pData = pDefCustomShape->pHandles;
    2101         190 :             for ( i = 0; i < nCnt; i++, pData++ )
    2102             :             {
    2103         106 :                 if ( pData->nFlags & MSDFF_HANDLE_FLAGS_POLAR )
    2104             :                 {
    2105           0 :                     if ( ( pData->nPositionY >= 0x256 ) || ( pData->nPositionY <= 0x107 ) )
    2106           0 :                         nAdjustmentsWhichNeedsToBeConverted |= ( 1 << i );
    2107             :                 }
    2108             :             }
    2109             :         }
    2110             :     }
    2111             : 
    2112             :     // "Path" PropertySequence element
    2113             : 
    2114             :     {
    2115        3768 :         PropVec aPathPropVec;
    2116             : 
    2117             :         // "Path/ExtrusionAllowed"
    2118        3768 :         if ( IsHardAttribute( DFF_Prop_f3DOK ) )
    2119             :         {
    2120           6 :             const OUString sExtrusionAllowed( "ExtrusionAllowed" );
    2121           6 :             bool bExtrusionAllowed = ( GetPropertyValue( DFF_Prop_fFillOK ) & 16 ) != 0;
    2122           6 :             aProp.Name = sExtrusionAllowed;
    2123           6 :             aProp.Value <<= bExtrusionAllowed;
    2124           6 :             aPathPropVec.push_back( aProp );
    2125             :         }
    2126             :         // "Path/ConcentricGradientFillAllowed"
    2127        3768 :         if ( IsHardAttribute( DFF_Prop_fFillShadeShapeOK ) )
    2128             :         {
    2129           0 :             const OUString sConcentricGradientFillAllowed( "ConcentricGradientFillAllowed" );
    2130           0 :             bool bConcentricGradientFillAllowed = ( GetPropertyValue( DFF_Prop_fFillOK ) & 2 ) != 0;
    2131           0 :             aProp.Name = sConcentricGradientFillAllowed;
    2132           0 :             aProp.Value <<= bConcentricGradientFillAllowed;
    2133           0 :             aPathPropVec.push_back( aProp );
    2134             :         }
    2135             :         // "Path/TextPathAllowed"
    2136        3768 :         if ( IsHardAttribute( DFF_Prop_fGtextOK ) || ( GetPropertyValue( DFF_Prop_gtextFStrikethrough, 0 ) & 0x4000 ) )
    2137             :         {
    2138           2 :             const OUString sTextPathAllowed( "TextPathAllowed" );
    2139           2 :             bool bTextPathAllowed = ( GetPropertyValue( DFF_Prop_fFillOK ) & 4 ) != 0;
    2140           2 :             aProp.Name = sTextPathAllowed;
    2141           2 :             aProp.Value <<= bTextPathAllowed;
    2142           2 :             aPathPropVec.push_back( aProp );
    2143             :         }
    2144             :         // Path/Coordinates
    2145        3768 :         if ( IsProperty( DFF_Prop_pVertices ) )
    2146             :         {
    2147           4 :             com::sun::star::uno::Sequence< com::sun::star::drawing::EnhancedCustomShapeParameterPair > aCoordinates;
    2148           4 :             sal_uInt16 nNumElemVert = 0;
    2149           4 :             sal_uInt16 nElemSizeVert = 8;
    2150             : 
    2151           4 :             if ( SeekToContent( DFF_Prop_pVertices, rIn ) )
    2152             :             {
    2153           4 :                 sal_uInt16 nNumElemMemVert = 0;
    2154           4 :                 rIn.ReadUInt16( nNumElemVert ).ReadUInt16( nNumElemMemVert ).ReadUInt16( nElemSizeVert );
    2155             :             }
    2156           4 :             if ( nNumElemVert )
    2157             :             {
    2158             :                 sal_Int32 nX, nY;
    2159             :                 sal_Int16 nTmpA, nTmpB;
    2160           4 :                 aCoordinates.realloc( nNumElemVert );
    2161          56 :                 for ( sal_uInt16 i = 0; i < nNumElemVert; i++ )
    2162             :                 {
    2163          52 :                     if ( nElemSizeVert == 8 )
    2164             :                     {
    2165           0 :                         rIn.ReadInt32( nX )
    2166           0 :                            .ReadInt32( nY );
    2167             :                     }
    2168             :                     else
    2169             :                     {
    2170          52 :                         rIn.ReadInt16( nTmpA )
    2171          52 :                            .ReadInt16( nTmpB );
    2172             : 
    2173          52 :                         nX = nTmpA;
    2174          52 :                         nY = nTmpB;
    2175             :                     }
    2176          52 :                     EnhancedCustomShape2d::SetEnhancedCustomShapeParameter( aCoordinates[ i ].First, nX );
    2177          52 :                     EnhancedCustomShape2d::SetEnhancedCustomShapeParameter( aCoordinates[ i ].Second, nY );
    2178             :                 }
    2179             :             }
    2180           8 :             const OUString sCoordinates( "Coordinates" );
    2181           4 :             aProp.Name = sCoordinates;
    2182           4 :             aProp.Value <<= aCoordinates;
    2183           8 :             aPathPropVec.push_back( aProp );
    2184             :         }
    2185             :         // Path/Segments
    2186        3768 :         if ( IsProperty( DFF_Prop_pSegmentInfo ) )
    2187             :         {
    2188           4 :             com::sun::star::uno::Sequence< com::sun::star::drawing::EnhancedCustomShapeSegment > aSegments;
    2189             : 
    2190             :             sal_uInt16 i, nTmp;
    2191           4 :             sal_uInt16 nNumElemSeg = 0;
    2192             : 
    2193           4 :             if ( SeekToContent( DFF_Prop_pSegmentInfo, rIn ) )
    2194             :             {
    2195           4 :                 sal_uInt16 nNumElemMemSeg = 0;
    2196           4 :                 sal_uInt16 nElemSizeSeg = 2;
    2197           4 :                 rIn.ReadUInt16( nNumElemSeg ).ReadUInt16( nNumElemMemSeg ).ReadUInt16( nElemSizeSeg );
    2198             :             }
    2199           4 :             if ( nNumElemSeg )
    2200             :             {
    2201             :                 sal_Int16 nCommand;
    2202             :                 sal_Int16 nCnt;
    2203           4 :                 aSegments.realloc( nNumElemSeg );
    2204          44 :                 for ( i = 0; i < nNumElemSeg; i++ )
    2205             :                 {
    2206          40 :                     rIn.ReadUInt16( nTmp );
    2207          40 :                     nCommand = EnhancedCustomShapeSegmentCommand::UNKNOWN;
    2208          40 :                     nCnt = (sal_Int16)( nTmp & 0x1fff );//Last 13 bits for segment points number
    2209          40 :                     switch( nTmp >> 13 )//First 3 bits for command type
    2210             :                     {
    2211           0 :                         case 0x0: nCommand = EnhancedCustomShapeSegmentCommand::LINETO; if ( !nCnt ) nCnt = 1; break;
    2212          14 :                         case 0x1: nCommand = EnhancedCustomShapeSegmentCommand::CURVETO; if ( !nCnt ) nCnt = 1; break;
    2213           4 :                         case 0x2: nCommand = EnhancedCustomShapeSegmentCommand::MOVETO; if ( !nCnt ) nCnt = 1; break;
    2214           0 :                         case 0x3: nCommand = EnhancedCustomShapeSegmentCommand::CLOSESUBPATH; nCnt = 0; break;
    2215           4 :                         case 0x4: nCommand = EnhancedCustomShapeSegmentCommand::ENDSUBPATH; nCnt = 0; break;
    2216             :                         case 0x5:
    2217             :                         case 0x6:
    2218             :                         {
    2219          18 :                             switch ( ( nTmp >> 8 ) & 0x1f )//5 bits next to command type is for path escape type
    2220             :                             {
    2221             :                                 case 0x0:
    2222             :                                 {
    2223             :                                     //It is msopathEscapeExtension which is transformed into LINETO.
    2224             :                                     //If issue happens, I think this part can be comment so that it will be taken as unknow command.
    2225             :                                     //When export, origin data will be export without any change.
    2226           0 :                                     nCommand = EnhancedCustomShapeSegmentCommand::LINETO;
    2227           0 :                                     if ( !nCnt )
    2228           0 :                                         nCnt = 1;
    2229             :                                 }
    2230           0 :                                 break;
    2231             :                                 case 0x1:
    2232             :                                 {
    2233           0 :                                     nCommand = EnhancedCustomShapeSegmentCommand::ANGLEELLIPSETO;
    2234           0 :                                     nCnt = ( nTmp & 0xff ) / 3;
    2235             :                                 }
    2236           0 :                                 break;
    2237             :                                 case 0x2:
    2238             :                                 {
    2239           0 :                                     nCommand = EnhancedCustomShapeSegmentCommand::ANGLEELLIPSE;
    2240           0 :                                     nCnt = ( nTmp & 0xff ) / 3;
    2241             :                                 }
    2242           0 :                                 break;
    2243             :                                 case 0x3:
    2244             :                                 {
    2245           0 :                                     nCommand = EnhancedCustomShapeSegmentCommand::ARCTO;
    2246           0 :                                     nCnt = ( nTmp & 0xff ) >> 2;
    2247             :                                 };
    2248           0 :                                 break;
    2249             :                                 case 0x4:
    2250             :                                 {
    2251           0 :                                     nCommand = EnhancedCustomShapeSegmentCommand::ARC;
    2252           0 :                                     nCnt = ( nTmp & 0xff ) >> 2;
    2253             :                                 }
    2254           0 :                                 break;
    2255             :                                 case 0x5:
    2256             :                                 {
    2257           0 :                                     nCommand = EnhancedCustomShapeSegmentCommand::CLOCKWISEARCTO;
    2258           0 :                                     nCnt = ( nTmp & 0xff ) >> 2;
    2259             :                                 }
    2260           0 :                                 break;
    2261             :                                 case 0x6:
    2262             :                                 {
    2263           0 :                                     nCommand = EnhancedCustomShapeSegmentCommand::CLOCKWISEARC;
    2264           0 :                                     nCnt = ( nTmp & 0xff ) >> 2;
    2265             :                                 }
    2266           0 :                                 break;
    2267             :                                 case 0x7:
    2268             :                                 {
    2269           0 :                                     nCommand = EnhancedCustomShapeSegmentCommand::ELLIPTICALQUADRANTX;
    2270           0 :                                     nCnt = nTmp & 0xff;
    2271             :                                 }
    2272           0 :                                 break;
    2273             :                                 case 0x8:
    2274             :                                 {
    2275           0 :                                     nCommand = EnhancedCustomShapeSegmentCommand::ELLIPTICALQUADRANTY;
    2276           0 :                                     nCnt = nTmp & 0xff;
    2277             :                                 }
    2278           0 :                                 break;
    2279           0 :                                 case 0xa: nCommand = EnhancedCustomShapeSegmentCommand::NOFILL; nCnt = 0; break;
    2280           0 :                                 case 0xb: nCommand = EnhancedCustomShapeSegmentCommand::NOSTROKE; nCnt = 0; break;
    2281             :                             }
    2282             :                         }
    2283          18 :                         break;
    2284             :                     }
    2285             :                     // if the command is unknown, we will store all the data in nCnt, so it will be possible to export without loss
    2286          40 :                     if ( nCommand == EnhancedCustomShapeSegmentCommand::UNKNOWN )
    2287          18 :                         nCnt = (sal_Int16)nTmp;
    2288          40 :                     aSegments[ i ].Command = nCommand;
    2289          40 :                     aSegments[ i ].Count = nCnt;
    2290             :                 }
    2291             :             }
    2292           4 :             const OUString sSegments( "Segments" );
    2293           4 :             aProp.Name = sSegments;
    2294           4 :             aProp.Value <<= aSegments;
    2295           4 :             aPathPropVec.push_back( aProp );
    2296             :         }
    2297             :         // Path/StretchX
    2298        3768 :         if ( IsProperty( DFF_Prop_stretchPointX ) )
    2299             :         {
    2300           0 :             const OUString sStretchX( "StretchX" );
    2301           0 :             sal_Int32 nStretchX = GetPropertyValue( DFF_Prop_stretchPointX, 0 );
    2302           0 :             aProp.Name = sStretchX;
    2303           0 :             aProp.Value <<= nStretchX;
    2304           0 :             aPathPropVec.push_back( aProp );
    2305             :         }
    2306             :         // Path/StretchX
    2307        3768 :         if ( IsProperty( DFF_Prop_stretchPointY ) )
    2308             :         {
    2309           0 :             const OUString sStretchY( "StretchY" );
    2310           0 :             sal_Int32 nStretchY = GetPropertyValue( DFF_Prop_stretchPointY, 0 );
    2311           0 :             aProp.Name = sStretchY;
    2312           0 :             aProp.Value <<= nStretchY;
    2313           0 :             aPathPropVec.push_back( aProp );
    2314             :         }
    2315             :         // Path/TextFrames
    2316        3768 :         if ( IsProperty( DFF_Prop_textRectangles ) )
    2317             :         {
    2318           0 :             sal_uInt16 nNumElem = 0;
    2319           0 :             sal_uInt16 nElemSize = 16;
    2320             : 
    2321           0 :             if ( SeekToContent( DFF_Prop_textRectangles, rIn ) )
    2322             :             {
    2323           0 :                 sal_uInt16 nNumElemMem = 0;
    2324           0 :                 rIn.ReadUInt16( nNumElem ).ReadUInt16( nNumElemMem ).ReadUInt16( nElemSize );
    2325             :             }
    2326           0 :             bool bImport = false;
    2327           0 :             if (nElemSize == 16)
    2328             :             {
    2329             :                 //sanity check that the stream is long enough to fulfill nNumElem * nElemSize;
    2330           0 :                 bImport = rIn.remainingSize() / nElemSize >= nNumElem;
    2331             :             }
    2332           0 :             if (bImport)
    2333             :             {
    2334           0 :                 com::sun::star::uno::Sequence< com::sun::star::drawing::EnhancedCustomShapeTextFrame > aTextFrames( nNumElem );
    2335           0 :                 for (sal_uInt16 i = 0; i < nNumElem; ++i)
    2336             :                 {
    2337           0 :                     sal_Int32 nLeft(0), nTop(0), nRight(0), nBottom(0);
    2338             : 
    2339           0 :                     rIn.ReadInt32( nLeft )
    2340           0 :                        .ReadInt32( nTop )
    2341           0 :                        .ReadInt32( nRight )
    2342           0 :                        .ReadInt32( nBottom );
    2343             : 
    2344           0 :                     EnhancedCustomShape2d::SetEnhancedCustomShapeParameter( aTextFrames[ i ].TopLeft.First,  nLeft );
    2345           0 :                     EnhancedCustomShape2d::SetEnhancedCustomShapeParameter( aTextFrames[ i ].TopLeft.Second, nTop  );
    2346           0 :                     EnhancedCustomShape2d::SetEnhancedCustomShapeParameter( aTextFrames[ i ].BottomRight.First,  nRight );
    2347           0 :                     EnhancedCustomShape2d::SetEnhancedCustomShapeParameter( aTextFrames[ i ].BottomRight.Second, nBottom);
    2348             :                 }
    2349           0 :                 const OUString sTextFrames( "TextFrames" );
    2350           0 :                 aProp.Name = sTextFrames;
    2351           0 :                 aProp.Value <<= aTextFrames;
    2352           0 :                 aPathPropVec.push_back( aProp );
    2353             :             }
    2354             :         }
    2355             :         //Path/GluePoints
    2356        3768 :         if ( IsProperty( DFF_Prop_connectorPoints ) )
    2357             :         {
    2358           0 :             com::sun::star::uno::Sequence< com::sun::star::drawing::EnhancedCustomShapeParameterPair > aGluePoints;
    2359           0 :             sal_uInt16 nNumElemVert = 0;
    2360           0 :             sal_uInt16 nNumElemMemVert = 0;
    2361           0 :             sal_uInt16 nElemSizeVert = 8;
    2362             : 
    2363           0 :             if ( SeekToContent( DFF_Prop_connectorPoints, rIn ) )
    2364           0 :                 rIn.ReadUInt16( nNumElemVert ).ReadUInt16( nNumElemMemVert ).ReadUInt16( nElemSizeVert );
    2365             : 
    2366           0 :             bool bImport = false;
    2367           0 :             if (nNumElemVert)
    2368             :             {
    2369             :                 //sanity check that the stream is long enough to fulfill nNumElemVert * nElemSizeVert;
    2370           0 :                 bImport = rIn.remainingSize() / nElemSizeVert >= nNumElemVert;
    2371             :             }
    2372             : 
    2373           0 :             if (bImport)
    2374             :             {
    2375           0 :                 aGluePoints.realloc( nNumElemVert );
    2376           0 :                 for (sal_uInt16 i = 0; i < nNumElemVert; ++i)
    2377             :                 {
    2378           0 :                     sal_Int32 nX(0), nY(0);
    2379           0 :                     if ( nElemSizeVert == 8 )
    2380             :                     {
    2381           0 :                         rIn.ReadInt32( nX )
    2382           0 :                            .ReadInt32( nY );
    2383             :                     }
    2384             :                     else
    2385             :                     {
    2386           0 :                         sal_Int16 nTmpA(0), nTmpB(0);
    2387             : 
    2388           0 :                         rIn.ReadInt16( nTmpA )
    2389           0 :                            .ReadInt16( nTmpB );
    2390             : 
    2391           0 :                         nX = nTmpA;
    2392           0 :                         nY = nTmpB;
    2393             :                     }
    2394           0 :                     EnhancedCustomShape2d::SetEnhancedCustomShapeParameter( aGluePoints[ i ].First,  nX );
    2395           0 :                     EnhancedCustomShape2d::SetEnhancedCustomShapeParameter( aGluePoints[ i ].Second, nY );
    2396             :                 }
    2397             :             }
    2398           0 :             const OUString sGluePoints( "GluePoints" );
    2399           0 :             aProp.Name = sGluePoints;
    2400           0 :             aProp.Value <<= aGluePoints;
    2401           0 :             aPathPropVec.push_back( aProp );
    2402             :         }
    2403        3768 :         if ( IsProperty( DFF_Prop_connectorType ) )
    2404             :         {
    2405          12 :             sal_Int16 nGluePointType = (sal_uInt16)GetPropertyValue( DFF_Prop_connectorType );
    2406          12 :             const OUString sGluePointType( "GluePointType" );
    2407          12 :             aProp.Name = sGluePointType;
    2408          12 :             aProp.Value <<= nGluePointType;
    2409          12 :             aPathPropVec.push_back( aProp );
    2410             :         }
    2411             :         // pushing the whole Path element
    2412        3768 :         if ( !aPathPropVec.empty() )
    2413             :         {
    2414          20 :             const OUString sPath( "Path" );
    2415          40 :             PropSeq aPathPropSeq( aPathPropVec.size() );
    2416          20 :             aIter = aPathPropVec.begin();
    2417          20 :             aEnd = aPathPropVec.end();
    2418          20 :             beans::PropertyValue* pPathValues = aPathPropSeq.getArray();
    2419          68 :             while ( aIter != aEnd )
    2420          28 :                 *pPathValues++ = *aIter++;
    2421          20 :             aProp.Name = sPath;
    2422          20 :             aProp.Value <<= aPathPropSeq;
    2423          40 :             aPropVec.push_back( aProp );
    2424        3768 :         }
    2425             :     }
    2426             : 
    2427             :     // "TextPath" PropertySequence element
    2428             : 
    2429        3768 :     bool bTextPathOn = ( GetPropertyValue( DFF_Prop_gtextFStrikethrough ) & 0x4000 ) != 0;
    2430        3768 :     if ( bTextPathOn )
    2431             :     {
    2432           2 :         PropVec aTextPathPropVec;
    2433             : 
    2434             :         // TextPath
    2435           4 :         const OUString sTextPathOn( "TextPath" );
    2436           2 :         aProp.Name = sTextPathOn;
    2437           2 :         aProp.Value <<= bTextPathOn;
    2438           2 :         aTextPathPropVec.push_back( aProp );
    2439             : 
    2440             :         // TextPathMode
    2441           4 :         const OUString sTextPathMode( "TextPathMode" );
    2442           2 :         bool bTextPathFitPath = ( GetPropertyValue( DFF_Prop_gtextFStrikethrough ) & 0x100 ) != 0;
    2443             : 
    2444             :         bool bTextPathFitShape;
    2445           2 :         if ( IsHardAttribute( DFF_Prop_gtextFStretch ) )
    2446           2 :             bTextPathFitShape = ( GetPropertyValue( DFF_Prop_gtextFStrikethrough ) & 0x400 ) != 0;
    2447             :         else
    2448             :         {
    2449           0 :             bTextPathFitShape = true;
    2450           0 :             switch( rObjData.eShapeType )
    2451             :             {
    2452             :                 case mso_sptTextArchUpCurve :
    2453             :                 case mso_sptTextArchDownCurve :
    2454             :                 case mso_sptTextCircleCurve :
    2455             :                 case mso_sptTextButtonCurve :
    2456           0 :                     bTextPathFitShape = false;
    2457           0 :                 default : break;
    2458             :             }
    2459             :         }
    2460           2 :         EnhancedCustomShapeTextPathMode eTextPathMode( EnhancedCustomShapeTextPathMode_NORMAL );
    2461           2 :         if ( bTextPathFitShape )
    2462           2 :             eTextPathMode = EnhancedCustomShapeTextPathMode_SHAPE;
    2463           0 :         else if ( bTextPathFitPath )
    2464           0 :             eTextPathMode = EnhancedCustomShapeTextPathMode_PATH;
    2465           2 :         aProp.Name = sTextPathMode;
    2466           2 :         aProp.Value <<= eTextPathMode;
    2467           2 :         aTextPathPropVec.push_back( aProp );
    2468             : 
    2469             :         // ScaleX
    2470           2 :         const OUString sTextPathScaleX( "ScaleX" );
    2471           2 :         bool bTextPathScaleX = ( GetPropertyValue( DFF_Prop_gtextFStrikethrough ) & 0x40 ) != 0;
    2472           2 :         aProp.Name = sTextPathScaleX;
    2473           2 :         aProp.Value <<= bTextPathScaleX;
    2474           2 :         aTextPathPropVec.push_back( aProp );
    2475             :         // SameLetterHeights
    2476           4 :         const OUString sSameLetterHeight( "SameLetterHeights" );
    2477           2 :         bool bSameLetterHeight = ( GetPropertyValue( DFF_Prop_gtextFStrikethrough ) & 0x80 ) != 0;
    2478           2 :         aProp.Name = sSameLetterHeight;
    2479           2 :         aProp.Value <<= bSameLetterHeight;
    2480           2 :         aTextPathPropVec.push_back( aProp );
    2481             : 
    2482             :         // pushing the whole TextPath element
    2483           4 :         const OUString sTextPath( "TextPath" );
    2484           4 :         PropSeq aTextPathPropSeq( aTextPathPropVec.size() );
    2485           2 :         aIter = aTextPathPropVec.begin();
    2486           2 :         aEnd = aTextPathPropVec.end();
    2487           2 :         beans::PropertyValue* pTextPathValues = aTextPathPropSeq.getArray();
    2488          12 :         while ( aIter != aEnd )
    2489           8 :             *pTextPathValues++ = *aIter++;
    2490           2 :         aProp.Name = sTextPath;
    2491           2 :         aProp.Value <<= aTextPathPropSeq;
    2492           6 :         aPropVec.push_back( aProp );
    2493             :     }
    2494             : 
    2495             :     // "AdjustmentValues" // The AdjustmentValues are imported at last, because depending to the type of the
    2496             :     //////////////////////// handle (POLAR) we will convert the adjustment value from a fixed float to double
    2497             : 
    2498             :     // checking the last used adjustment handle, so we can determine how many handles are to allocate
    2499        3768 :     sal_Int32 i = DFF_Prop_adjust10Value;
    2500       45092 :     while ( ( i >= DFF_Prop_adjustValue ) && !IsProperty( i ) )
    2501       37556 :         i--;
    2502        3768 :     sal_Int32 nAdjustmentValues = ( i - DFF_Prop_adjustValue ) + 1;
    2503        3768 :     if ( nAdjustmentValues )
    2504             :     {
    2505          46 :         uno::Sequence< com::sun::star::drawing::EnhancedCustomShapeAdjustmentValue > aAdjustmentSeq( nAdjustmentValues );
    2506         216 :         while( --nAdjustmentValues >= 0 )
    2507             :         {
    2508         124 :             sal_Int32 nValue = 0;
    2509         124 :             beans::PropertyState ePropertyState = beans::PropertyState_DEFAULT_VALUE;
    2510         124 :             if ( IsProperty( i ) )
    2511             :             {
    2512         122 :                 nValue = GetPropertyValue( i );
    2513         122 :                 ePropertyState = beans::PropertyState_DIRECT_VALUE;
    2514             :             }
    2515         124 :             if ( nAdjustmentsWhichNeedsToBeConverted & ( 1 << ( i - DFF_Prop_adjustValue ) ) )
    2516             :             {
    2517           0 :                 double fValue = nValue;
    2518           0 :                 fValue /= 65536;
    2519           0 :                 aAdjustmentSeq[ nAdjustmentValues ].Value <<= fValue;
    2520             :             }
    2521             :             else
    2522         124 :                 aAdjustmentSeq[ nAdjustmentValues ].Value <<= nValue;
    2523         124 :             aAdjustmentSeq[ nAdjustmentValues ].State = ePropertyState;
    2524         124 :             i--;
    2525             :         }
    2526          92 :         const OUString sAdjustmentValues( "AdjustmentValues" );
    2527          46 :         aProp.Name = sAdjustmentValues;
    2528          46 :         aProp.Value <<= aAdjustmentSeq;
    2529          92 :         aPropVec.push_back( aProp );
    2530             :     }
    2531             : 
    2532             :     // creating the whole property set
    2533        3768 :     PropSeq aSeq( aPropVec.size() );
    2534        3768 :     beans::PropertyValue* pValues = aSeq.getArray();
    2535        3768 :     aIter = aPropVec.begin();
    2536        3768 :     aEnd = aPropVec.end();
    2537       11376 :     while ( aIter != aEnd )
    2538        3840 :         *pValues++ = *aIter++;
    2539        7536 :     rSet.Put( SdrCustomShapeGeometryItem( aSeq ) );
    2540        3768 : }
    2541             : 
    2542         210 : void DffPropertyReader::ApplyAttributes( SvStream& rIn, SfxItemSet& rSet ) const
    2543             : {
    2544         210 :     Rectangle aEmptyRect;
    2545         210 :     DffRecordHeader aHdTemp;
    2546         210 :     DffObjData aDffObjTemp( aHdTemp, aEmptyRect, 0 );
    2547         210 :     ApplyAttributes( rIn, rSet, aDffObjTemp );
    2548         210 : }
    2549             : 
    2550        4014 : void DffPropertyReader::ApplyAttributes( SvStream& rIn, SfxItemSet& rSet, DffObjData& rObjData ) const
    2551             : {
    2552        4014 :     bool bHasShadow = false;
    2553        4014 :     bool bNonZeroShadowOffset = false;
    2554             : 
    2555        4014 :     if ( IsProperty( DFF_Prop_gtextSize ) )
    2556           0 :         rSet.Put( SvxFontHeightItem( rManager.ScalePt( GetPropertyValue( DFF_Prop_gtextSize ) ), 100, EE_CHAR_FONTHEIGHT ) );
    2557        4014 :     sal_uInt32 nFontAttributes = GetPropertyValue( DFF_Prop_gtextFStrikethrough );
    2558        4014 :     if ( nFontAttributes & 0x20 )
    2559           0 :         rSet.Put( SvxWeightItem( nFontAttributes & 0x20 ? WEIGHT_BOLD : WEIGHT_NORMAL, EE_CHAR_WEIGHT ) );
    2560        4014 :     if ( nFontAttributes & 0x10 )
    2561           0 :         rSet.Put( SvxPostureItem( nFontAttributes & 0x10 ? ITALIC_NORMAL : ITALIC_NONE, EE_CHAR_ITALIC ) );
    2562        4014 :     if ( nFontAttributes & 0x08 )
    2563           0 :         rSet.Put( SvxUnderlineItem( nFontAttributes & 0x08 ? UNDERLINE_SINGLE : UNDERLINE_NONE, EE_CHAR_UNDERLINE ) );
    2564        4014 :     if ( nFontAttributes & 0x40 )
    2565           0 :         rSet.Put( SvxShadowedItem( (nFontAttributes & 0x40) != 0, EE_CHAR_SHADOW ) );
    2566             : //    if ( nFontAttributes & 0x02 )
    2567             : //        rSet.Put( SvxCaseMapItem( nFontAttributes & 0x02 ? SVX_CASEMAP_KAPITAELCHEN : SVX_CASEMAP_NOT_MAPPED ) );
    2568        4014 :     if ( nFontAttributes & 0x01 )
    2569           0 :         rSet.Put( SvxCrossedOutItem( nFontAttributes & 0x01 ? STRIKEOUT_SINGLE : STRIKEOUT_NONE, EE_CHAR_STRIKEOUT ) );
    2570        4014 :     if ( IsProperty( DFF_Prop_fillColor ) )
    2571        4014 :         rSet.Put( XFillColorItem( OUString(), rManager.MSO_CLR_ToColor( GetPropertyValue( DFF_Prop_fillColor ), DFF_Prop_fillColor ) ) );
    2572        4014 :     if ( IsProperty( DFF_Prop_shadowColor ) )
    2573        2958 :         rSet.Put( makeSdrShadowColorItem( rManager.MSO_CLR_ToColor( GetPropertyValue( DFF_Prop_shadowColor ), DFF_Prop_shadowColor ) ) );
    2574             :     else
    2575             :     {
    2576             :         //The default value for this property is 0x00808080
    2577        1056 :         rSet.Put( makeSdrShadowColorItem( rManager.MSO_CLR_ToColor( 0x00808080, DFF_Prop_shadowColor ) ) );
    2578             :     }
    2579        4014 :     if ( IsProperty( DFF_Prop_shadowOpacity ) )
    2580          12 :         rSet.Put( makeSdrShadowTransparenceItem( (sal_uInt16)( ( 0x10000 - GetPropertyValue( DFF_Prop_shadowOpacity ) ) / 655 ) ) );
    2581        4014 :     if ( IsProperty( DFF_Prop_shadowOffsetX ) )
    2582             :     {
    2583         192 :         sal_Int32 nVal = static_cast< sal_Int32 >( GetPropertyValue( DFF_Prop_shadowOffsetX ) );
    2584         192 :         rManager.ScaleEmu( nVal );
    2585         192 :         rSet.Put( makeSdrShadowXDistItem( nVal ) );
    2586         192 :         bNonZeroShadowOffset = ( nVal > 0 );
    2587             :     }
    2588        4014 :     if ( IsProperty( DFF_Prop_shadowOffsetY ) )
    2589             :     {
    2590          64 :         sal_Int32 nVal = static_cast< sal_Int32 >( GetPropertyValue( DFF_Prop_shadowOffsetY ) );
    2591          64 :         rManager.ScaleEmu( nVal );
    2592          64 :         rSet.Put( makeSdrShadowYDistItem( nVal ) );
    2593          64 :         bNonZeroShadowOffset = ( nVal > 0 );
    2594             :     }
    2595        4014 :     if ( IsProperty( DFF_Prop_fshadowObscured ) )
    2596             :     {
    2597        4014 :         bHasShadow = ( GetPropertyValue( DFF_Prop_fshadowObscured ) & 2 ) != 0;
    2598        4014 :         if ( bHasShadow )
    2599             :         {
    2600          74 :             if ( !IsProperty( DFF_Prop_shadowOffsetX ) )
    2601           8 :                 rSet.Put( makeSdrShadowXDistItem( 35 ) );
    2602          74 :             if ( !IsProperty( DFF_Prop_shadowOffsetY ) )
    2603          10 :                 rSet.Put( makeSdrShadowYDistItem( 35 ) );
    2604             :         }
    2605             :     }
    2606        4014 :     if ( IsProperty( DFF_Prop_shadowType ) )
    2607             :     {
    2608           6 :         MSO_ShadowType eShadowType = static_cast< MSO_ShadowType >( GetPropertyValue( DFF_Prop_shadowType ) );
    2609           6 :         if( eShadowType != mso_shadowOffset && !bNonZeroShadowOffset )
    2610             :         {
    2611             :             //0.12" == 173 twip == 302 100mm
    2612           0 :             sal_uInt32 nDist = rManager.pSdrModel->GetScaleUnit() == MAP_TWIP ? 173: 302;
    2613           0 :             rSet.Put( makeSdrShadowXDistItem( nDist ) );
    2614           0 :             rSet.Put( makeSdrShadowYDistItem( nDist ) );
    2615             :         }
    2616             :     }
    2617        4014 :     if ( bHasShadow )
    2618             :     {
    2619             :         static bool bCheckShadow(false);
    2620             : 
    2621             :         // #i124477# Found no reason not to set shadow, esp. since it is applied to evtl. existing text
    2622             :         // and will lead to an error of in PPT someone used text and added the object shadow to the
    2623             :         // object carryintg that text. I found no cases where this leads to problems (the old bugtracker
    2624             :         // task #160376# from sj is unfortunately no longer available). Keeping the code for now
    2625             :         // to allow easy fallback when this shows problems in the future
    2626          74 :         if(bCheckShadow)
    2627             :         {
    2628             :             // #160376# sj: activating shadow only if fill and or linestyle is used
    2629             :             // this is required because of the latest drawing layer core changes.
    2630             :             // #i104085# is related to this.
    2631           0 :             sal_uInt32 nLineFlags(GetPropertyValue( DFF_Prop_fNoLineDrawDash ));
    2632           0 :             if(!IsHardAttribute( DFF_Prop_fLine ) && !IsCustomShapeStrokedByDefault( rObjData.eShapeType ))
    2633           0 :                 nLineFlags &= ~0x08;
    2634           0 :             sal_uInt32 nFillFlags(GetPropertyValue( DFF_Prop_fNoFillHitTest ));
    2635           0 :             if(!IsHardAttribute( DFF_Prop_fFilled ) && !IsCustomShapeFilledByDefault( rObjData.eShapeType ))
    2636           0 :                 nFillFlags &= ~0x10;
    2637           0 :             if ( nFillFlags & 0x10 )
    2638             :             {
    2639           0 :                 MSO_FillType eMSO_FillType = (MSO_FillType)GetPropertyValue( DFF_Prop_fillType, mso_fillSolid );
    2640           0 :                 switch( eMSO_FillType )
    2641             :                 {
    2642             :                     case mso_fillSolid :
    2643             :                     case mso_fillPattern :
    2644             :                     case mso_fillTexture :
    2645             :                     case mso_fillPicture :
    2646             :                     case mso_fillShade :
    2647             :                     case mso_fillShadeCenter :
    2648             :                     case mso_fillShadeShape :
    2649             :                     case mso_fillShadeScale :
    2650             :                     case mso_fillShadeTitle :
    2651           0 :                     break;
    2652             :                     default:
    2653           0 :                         nFillFlags &=~0x10;         // no fillstyle used
    2654           0 :                     break;
    2655             :                 }
    2656             :             }
    2657           0 :             if ( ( ( nLineFlags & 0x08 ) == 0 ) && ( ( nFillFlags & 0x10 ) == 0 ) && ( rObjData.eShapeType != mso_sptPictureFrame ))    // if there is no fillstyle and linestyle
    2658           0 :                 bHasShadow = false;                                             // we are turning shadow off.
    2659             :         }
    2660             : 
    2661          74 :         if ( bHasShadow )
    2662          74 :             rSet.Put( makeSdrShadowItem( bHasShadow ) );
    2663             :     }
    2664        4014 :     ApplyLineAttributes( rSet, rObjData.eShapeType ); // #i28269#
    2665        4014 :     ApplyFillAttributes( rIn, rSet, rObjData );
    2666        4014 :     if ( rObjData.eShapeType != mso_sptNil || IsProperty( DFF_Prop_pVertices ) )
    2667             :     {
    2668        3768 :         ApplyCustomShapeGeometryAttributes( rIn, rSet, rObjData );
    2669        3768 :         ApplyCustomShapeTextAttributes( rSet );
    2670        3768 :         if ( rManager.GetSvxMSDffSettings() & SVXMSDFF_SETTINGS_IMPORT_EXCEL )
    2671             :         {
    2672         108 :             if ( mnFix16Angle || ( rObjData.nSpFlags & SP_FFLIPV ) )
    2673           0 :                 CheckAndCorrectExcelTextRotation( rIn, rSet, rObjData );
    2674             :         }
    2675             :     }
    2676        4014 : }
    2677             : 
    2678           0 : void DffPropertyReader::CheckAndCorrectExcelTextRotation( SvStream& rIn, SfxItemSet& rSet, DffObjData& rObjData ) const
    2679             : {
    2680           0 :     bool bRotateTextWithShape = rObjData.bRotateTextWithShape;
    2681           0 :     if ( rObjData.bOpt2 )        // sj: #158494# is the second property set available ? if then we have to check the xml data of
    2682             :     {                            // the shape, because the textrotation of Excel 2003 and greater versions is stored there
    2683             :                                 // (upright property of the textbox)
    2684           0 :         if ( rManager.pSecPropSet->SeekToContent( DFF_Prop_metroBlob, rIn ) )
    2685             :         {
    2686           0 :             sal_uInt32 nLen = rManager.pSecPropSet->GetPropertyValue( DFF_Prop_metroBlob );
    2687           0 :             if ( nLen )
    2688             :             {
    2689           0 :                 ::com::sun::star::uno::Sequence< sal_Int8 > aXMLDataSeq( nLen );
    2690           0 :                 rIn.Read( aXMLDataSeq.getArray(), nLen );
    2691             :                 ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > xInputStream
    2692           0 :                     ( new ::comphelper::SequenceInputStream( aXMLDataSeq ) );
    2693             :                 try
    2694             :                 {
    2695           0 :                     ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > xContext( ::comphelper::getProcessComponentContext() );
    2696             :                     ::com::sun::star::uno::Reference< com::sun::star::embed::XStorage > xStorage
    2697             :                         ( ::comphelper::OStorageHelper::GetStorageOfFormatFromInputStream(
    2698           0 :                             OFOPXML_STORAGE_FORMAT_STRING, xInputStream, xContext, true ) );
    2699           0 :                     if ( xStorage.is() )
    2700             :                     {
    2701           0 :                         const OUString sDRS( "drs" );
    2702             :                         ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >
    2703           0 :                             xStorageDRS( xStorage->openStorageElement( sDRS, ::com::sun::star::embed::ElementModes::SEEKABLEREAD ) );
    2704           0 :                         if ( xStorageDRS.is() )
    2705             :                         {
    2706           0 :                             const OUString sShapeXML( "shapexml.xml" );
    2707           0 :                             ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream > xShapeXMLStream( xStorageDRS->openStreamElement( sShapeXML, ::com::sun::star::embed::ElementModes::SEEKABLEREAD ) );
    2708           0 :                             if ( xShapeXMLStream.is() )
    2709             :                             {
    2710           0 :                                 ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > xShapeXMLInputStream( xShapeXMLStream->getInputStream() );
    2711           0 :                                 if ( xShapeXMLInputStream.is() )
    2712             :                                 {
    2713           0 :                                     ::com::sun::star::uno::Sequence< sal_Int8 > aSeq;
    2714           0 :                                     sal_Int32 nBytesRead = xShapeXMLInputStream->readBytes( aSeq, 0x7fffffff );
    2715           0 :                                     if ( nBytesRead )
    2716             :                                     {    // for only one property I spare to use a XML parser at this point, this
    2717             :                                         // should be enhanced if needed
    2718             : 
    2719           0 :                                         bRotateTextWithShape = true;    // using the correct xml default
    2720           0 :                                         const char* pArry = reinterpret_cast< char* >( aSeq.getArray() );
    2721           0 :                                         const char* pUpright = "upright=";
    2722           0 :                                         const char* pEnd = pArry + nBytesRead;
    2723           0 :                                         const char* pPtr = pArry;
    2724           0 :                                         while( ( pPtr + 12 ) < pEnd )
    2725             :                                         {
    2726           0 :                                             if ( !memcmp( pUpright, pPtr, 8 ) )
    2727             :                                             {
    2728           0 :                                                 bRotateTextWithShape = ( pPtr[ 9 ] != '1' ) && ( pPtr[ 9 ] != 't' );
    2729           0 :                                                 break;
    2730             :                                             }
    2731             :                                             else
    2732           0 :                                                 pPtr++;
    2733             :                                         }
    2734           0 :                                     }
    2735           0 :                                 }
    2736           0 :                             }
    2737           0 :                         }
    2738           0 :                     }
    2739             :                 }
    2740           0 :                 catch( com::sun::star::uno::Exception& )
    2741             :                 {
    2742           0 :                 }
    2743             :             }
    2744             :         }
    2745             :     }
    2746           0 :     if ( !bRotateTextWithShape )
    2747             :     {
    2748             :         const com::sun::star::uno::Any* pAny;
    2749           0 :         SdrCustomShapeGeometryItem aGeometryItem(static_cast<const SdrCustomShapeGeometryItem&>(rSet.Get( SDRATTR_CUSTOMSHAPE_GEOMETRY )));
    2750           0 :         const OUString sTextRotateAngle( "TextRotateAngle" );
    2751           0 :         pAny = aGeometryItem.GetPropertyValueByName( sTextRotateAngle );
    2752           0 :         double fExtraTextRotateAngle = 0.0;
    2753           0 :         if ( pAny )
    2754           0 :             *pAny >>= fExtraTextRotateAngle;
    2755             : 
    2756           0 :         if ( rManager.mnFix16Angle )
    2757           0 :             fExtraTextRotateAngle += mnFix16Angle / 100.0;
    2758           0 :         if ( rObjData.nSpFlags & SP_FFLIPV )
    2759           0 :             fExtraTextRotateAngle -= 180.0;
    2760             : 
    2761           0 :         com::sun::star::beans::PropertyValue aTextRotateAngle;
    2762           0 :         aTextRotateAngle.Name = sTextRotateAngle;
    2763           0 :         aTextRotateAngle.Value <<= fExtraTextRotateAngle;
    2764           0 :         aGeometryItem.SetPropertyValue( aTextRotateAngle );
    2765           0 :         rSet.Put( aGeometryItem );
    2766             :     }
    2767           0 : }
    2768             : 
    2769             : 
    2770           6 : void DffPropertyReader::ImportGradientColor( SfxItemSet& aSet,MSO_FillType eMSO_FillType, double dTrans , double dBackTrans) const
    2771             : {
    2772             :     //MS Focus prop will impact the start and end color position. And AOO does not
    2773             :     //support this prop. So need some swap for the two color to keep fidelity with AOO and MS shape.
    2774             :     //So below var is defined.
    2775           6 :     sal_Int32 nChgColors = 0;
    2776           6 :     sal_Int32 nAngle = GetPropertyValue( DFF_Prop_fillAngle, 0 );
    2777           6 :     sal_Int32 nRotateAngle = 0;
    2778           6 :     if(nAngle >= 0)
    2779           6 :         nChgColors ^= 1;
    2780             : 
    2781             :     //Translate a MS clockwise(+) or count clockwise angle(-) into a AOO count clock wise angle
    2782           6 :     nAngle=3600 - ( ( Fix16ToAngle(nAngle) + 5 ) / 10 );
    2783             :     //Make sure this angle belongs to 0~3600
    2784           6 :     while ( nAngle >= 3600 ) nAngle -= 3600;
    2785           6 :     while ( nAngle < 0 ) nAngle += 3600;
    2786             : 
    2787             :     //Rotate angle
    2788           6 :     if ( mbRotateGranientFillWithAngle )
    2789             :     {
    2790           4 :         nRotateAngle = GetPropertyValue( DFF_Prop_Rotation, 0 );
    2791           4 :         if(nRotateAngle)//fixed point number
    2792           0 :             nRotateAngle = ( (sal_Int16)( nRotateAngle >> 16) * 100L ) + ( ( ( nRotateAngle & 0x0000ffff) * 100L ) >> 16 );
    2793           4 :         nRotateAngle = ( nRotateAngle + 5 ) / 10 ;//round up
    2794             :         //nAngle is a clockwise angle. If nRotateAngle is a clockwise angle, then gradient need be rotated a little less
    2795             :         //Or it need be rotated a little more
    2796           4 :         nAngle -=  nRotateAngle;
    2797             :     }
    2798           6 :     while ( nAngle >= 3600 ) nAngle -= 3600;
    2799           6 :     while ( nAngle < 0 ) nAngle += 3600;
    2800             : 
    2801           6 :     XGradientStyle eGrad = XGRAD_LINEAR;
    2802             : 
    2803           6 :     sal_Int32 nFocus = GetPropertyValue( DFF_Prop_fillFocus, 0 );
    2804           6 :     if ( !nFocus )
    2805           0 :         nChgColors ^= 1;
    2806           6 :     else if ( nFocus < 0 )//If it is a negative focus, the color will be swapped
    2807             :     {
    2808           0 :         nFocus = -nFocus;
    2809           0 :         nChgColors ^= 1;
    2810             :     }
    2811             : 
    2812           6 :     if( nFocus > 40 && nFocus < 60 )
    2813             :     {
    2814           0 :         eGrad = XGRAD_AXIAL;//A axial gradient other than linear
    2815           0 :         nChgColors ^= 1;
    2816             :     }
    2817             :     //if the type is linear or axial, just save focus to nFocusX and nFocusY for export
    2818             :     //Core function does no need them. They serves for rect gradient(CenterXY).
    2819           6 :     sal_uInt16 nFocusX = (sal_uInt16)nFocus;
    2820           6 :     sal_uInt16 nFocusY = (sal_uInt16)nFocus;
    2821             : 
    2822           6 :     switch( eMSO_FillType )
    2823             :     {
    2824             :     case mso_fillShadeShape :
    2825             :         {
    2826           0 :             eGrad = XGRAD_RECT;
    2827           0 :             nFocusY = nFocusX = 50;
    2828           0 :             nChgColors ^= 1;
    2829             :         }
    2830           0 :         break;
    2831             :     case mso_fillShadeCenter :
    2832             :         {
    2833           0 :             eGrad = XGRAD_RECT;
    2834             :             //A MS fillTo prop specifies the relative position of the left boundary
    2835             :             //of the center rectangle in a concentric shaded fill. Use 100 or 0 to keep fidelity
    2836           0 :             nFocusX=(GetPropertyValue( DFF_Prop_fillToRight, 0 )==0x10000) ? 100 : 0;
    2837           0 :             nFocusY=(GetPropertyValue( DFF_Prop_fillToBottom,0 )==0x10000) ? 100 : 0;
    2838           0 :             nChgColors ^= 1;
    2839             :         }
    2840           0 :         break;
    2841           6 :         default: break;
    2842             :     }
    2843             : 
    2844           6 :     Color aCol1( rManager.MSO_CLR_ToColor( GetPropertyValue( DFF_Prop_fillColor, COL_WHITE ), DFF_Prop_fillColor ) );
    2845           6 :     Color aCol2( rManager.MSO_CLR_ToColor( GetPropertyValue( DFF_Prop_fillBackColor, COL_WHITE ), DFF_Prop_fillBackColor ) );
    2846           6 :     if ( nChgColors )
    2847             :     {
    2848             :         //Swap start and end color
    2849           6 :         Color aZwi( aCol1 );
    2850           6 :         aCol1 = aCol2;
    2851           6 :         aCol2 = aZwi;
    2852             :         //Swap two colors' transparency
    2853           6 :         double dTemp = dTrans;
    2854           6 :         dTrans = dBackTrans;
    2855           6 :         dBackTrans = dTemp;
    2856             :     }
    2857             : 
    2858             :     //Construct gradient item
    2859           6 :     XGradient aGrad( aCol2, aCol1, eGrad, nAngle, nFocusX, nFocusY );
    2860             :     //Intensity has been merged into color. So here just set is as 100
    2861           6 :     aGrad.SetStartIntens( 100 );
    2862           6 :     aGrad.SetEndIntens( 100 );
    2863           6 :     aSet.Put( XFillGradientItem( OUString(), aGrad ) );
    2864             :     //Construct tranparency item. This item can coodinate with both solid and gradient.
    2865           6 :     if ( dTrans < 1.0 || dBackTrans < 1.0 )
    2866             :     {
    2867           0 :         sal_uInt8 nStartCol = (sal_uInt8)( (1 - dTrans )* 255 );
    2868           0 :         sal_uInt8 nEndCol = (sal_uInt8)( ( 1- dBackTrans ) * 255 );
    2869           0 :         aCol1 = Color(nStartCol, nStartCol, nStartCol);
    2870           0 :         aCol2 = Color(nEndCol, nEndCol, nEndCol);
    2871             : 
    2872           0 :         XGradient aGrad2( aCol2 ,  aCol1 , eGrad, nAngle, nFocusX, nFocusY );
    2873           0 :         aSet.Put( XFillFloatTransparenceItem( OUString(), aGrad2 ) );
    2874             :     }
    2875           6 : }
    2876             : 
    2877             : 
    2878             : //- Record Manager ----------------------------------------------------------
    2879             : 
    2880             : 
    2881         442 : DffRecordList::DffRecordList( DffRecordList* pList ) :
    2882             :     nCount                  ( 0 ),
    2883             :     nCurrent                ( 0 ),
    2884             :     pPrev                   ( pList ),
    2885         442 :     pNext                   ( NULL )
    2886             : {
    2887         442 :     if ( pList )
    2888           0 :         pList->pNext = this;
    2889         442 : }
    2890             : 
    2891         442 : DffRecordList::~DffRecordList()
    2892             : {
    2893         442 :     delete pNext;
    2894         442 : }
    2895             : 
    2896         434 : DffRecordManager::DffRecordManager() :
    2897             :     DffRecordList   ( NULL ),
    2898         434 :     pCList          ( (DffRecordList*)this )
    2899             : {
    2900         434 : }
    2901             : 
    2902           8 : DffRecordManager::DffRecordManager( SvStream& rIn ) :
    2903             :     DffRecordList   ( NULL ),
    2904           8 :     pCList          ( (DffRecordList*)this )
    2905             : {
    2906           8 :     Consume( rIn );
    2907           8 : }
    2908             : 
    2909        3756 : void DffRecordManager::Consume( SvStream& rIn, bool bAppend, sal_uInt32 nStOfs )
    2910             : {
    2911        3756 :     if ( !bAppend )
    2912        3756 :         Clear();
    2913        3756 :     sal_uInt32 nOldPos = rIn.Tell();
    2914        3756 :     if ( !nStOfs )
    2915             :     {
    2916        3750 :         DffRecordHeader aHd;
    2917        3750 :         ReadDffRecordHeader( rIn, aHd );
    2918        3750 :         if ( aHd.nRecVer == DFF_PSFLAG_CONTAINER )
    2919        3750 :             nStOfs = aHd.GetRecEndFilePos();
    2920             :     }
    2921        3756 :     if ( nStOfs )
    2922             :     {
    2923        3756 :         pCList = (DffRecordList*)this;
    2924        7512 :         while ( pCList->pNext )
    2925           0 :             pCList = pCList->pNext;
    2926       22282 :         while ( ( rIn.GetError() == 0 ) && ( ( rIn.Tell() + 8 ) <=  nStOfs ) )
    2927             :         {
    2928       14770 :             if ( pCList->nCount == DFF_RECORD_MANAGER_BUF_SIZE )
    2929           0 :                 pCList = new DffRecordList( pCList );
    2930       14770 :             ReadDffRecordHeader( rIn, pCList->mHd[ pCList->nCount ] );
    2931       14770 :             bool bSeekSucceeded = pCList->mHd[ pCList->nCount++ ].SeekToEndOfRecord(rIn);
    2932       14770 :             if (!bSeekSucceeded)
    2933           0 :                 break;
    2934             :         }
    2935        3756 :         rIn.Seek( nOldPos );
    2936             :     }
    2937        3756 : }
    2938             : 
    2939        3756 : void DffRecordManager::Clear()
    2940             : {
    2941        3756 :     pCList = (DffRecordList*)this;
    2942        3756 :     delete pNext, pNext = NULL;
    2943        3756 :     nCurrent = 0;
    2944        3756 :     nCount = 0;
    2945        3756 : }
    2946             : 
    2947       14574 : DffRecordHeader* DffRecordManager::Current()
    2948             : {
    2949       14574 :     DffRecordHeader* pRet = NULL;
    2950       14574 :     if ( pCList->nCurrent < pCList->nCount )
    2951       14574 :         pRet = &pCList->mHd[ pCList->nCurrent ];
    2952       14574 :     return pRet;
    2953             : }
    2954             : 
    2955       24724 : DffRecordHeader* DffRecordManager::First()
    2956             : {
    2957       24724 :     DffRecordHeader* pRet = NULL;
    2958       24724 :     pCList = (DffRecordList*)this;
    2959       24724 :     if ( pCList->nCount )
    2960             :     {
    2961       24718 :         pCList->nCurrent = 0;
    2962       24718 :         pRet = &pCList->mHd[ 0 ];
    2963             :     }
    2964       24724 :     return pRet;
    2965             : }
    2966             : 
    2967       86188 : DffRecordHeader* DffRecordManager::Next()
    2968             : {
    2969       86188 :     DffRecordHeader* pRet = NULL;
    2970       86188 :     sal_uInt32 nC = pCList->nCurrent + 1;
    2971       86188 :     if ( nC < pCList->nCount )
    2972             :     {
    2973       66202 :         pCList->nCurrent++;
    2974       66202 :         pRet = &pCList->mHd[ nC ];
    2975             :     }
    2976       19986 :     else if ( pCList->pNext )
    2977             :     {
    2978           0 :         pCList = pCList->pNext;
    2979           0 :         pCList->nCurrent = 0;
    2980           0 :         pRet = &pCList->mHd[ 0 ];
    2981             :     }
    2982       86188 :     return pRet;
    2983             : }
    2984             : 
    2985           0 : DffRecordHeader* DffRecordManager::Prev()
    2986             : {
    2987           0 :     DffRecordHeader* pRet = NULL;
    2988           0 :     sal_uInt32 nCur = pCList->nCurrent;
    2989           0 :     if ( !nCur && pCList->pPrev )
    2990             :     {
    2991           0 :         pCList = pCList->pPrev;
    2992           0 :         nCur = pCList->nCount;
    2993             :     }
    2994           0 :     if ( nCur-- )
    2995             :     {
    2996           0 :         pCList->nCurrent = nCur;
    2997           0 :         pRet = &pCList->mHd[ nCur ];
    2998             :     }
    2999           0 :     return pRet;
    3000             : }
    3001             : 
    3002           0 : DffRecordHeader* DffRecordManager::Last()
    3003             : {
    3004           0 :     DffRecordHeader* pRet = NULL;
    3005           0 :     while ( pCList->pNext )
    3006           0 :         pCList = pCList->pNext;
    3007           0 :     sal_uInt32 nCnt = pCList->nCount;
    3008           0 :     if ( nCnt-- )
    3009             :     {
    3010           0 :         pCList->nCurrent = nCnt;
    3011           0 :         pRet = &pCList->mHd[ nCnt ];
    3012             :     }
    3013           0 :     return pRet;
    3014             : }
    3015             : 
    3016       34334 : bool DffRecordManager::SeekToContent( SvStream& rIn, sal_uInt16 nRecId, DffSeekToContentMode eMode )
    3017             : {
    3018       34334 :     DffRecordHeader* pHd = GetRecordHeader( nRecId, eMode );
    3019       34334 :     if ( pHd )
    3020             :     {
    3021       16000 :         pHd->SeekToContent( rIn );
    3022       16000 :         return true;
    3023             :     }
    3024             :     else
    3025       18334 :         return false;
    3026             : }
    3027             : 
    3028       34810 : DffRecordHeader* DffRecordManager::GetRecordHeader( sal_uInt16 nRecId, DffSeekToContentMode eMode )
    3029             : {
    3030       34810 :     sal_uInt32 nOldCurrent = pCList->nCurrent;
    3031       34810 :     DffRecordList* pOldList = pCList;
    3032             :     DffRecordHeader* pHd;
    3033             : 
    3034       34810 :     if ( eMode == SEEK_FROM_BEGINNING )
    3035        7616 :         pHd = First();
    3036             :     else
    3037       27194 :         pHd = Next();
    3038             : 
    3039       94780 :     while ( pHd )
    3040             :     {
    3041       39984 :         if ( pHd->nRecType == nRecId )
    3042       14824 :             break;
    3043       25160 :         pHd = Next();
    3044             :     }
    3045       34810 :     if ( !pHd && eMode == SEEK_FROM_CURRENT_AND_RESTART )
    3046             :     {
    3047       17108 :         DffRecordHeader* pBreak = &pOldList->mHd[ nOldCurrent ];
    3048       17108 :         pHd = First();
    3049       17108 :         if ( pHd )
    3050             :         {
    3051       68038 :             while ( pHd != pBreak )
    3052             :             {
    3053       34480 :                 if ( pHd->nRecType == nRecId )
    3054         646 :                     break;
    3055       33834 :                 pHd = Next();
    3056             :             }
    3057       17102 :             if ( pHd->nRecType != nRecId )
    3058       15518 :                 pHd = NULL;
    3059             :         }
    3060             :     }
    3061       34810 :     if ( !pHd )
    3062             :     {
    3063       18402 :         pCList = pOldList;
    3064       18402 :         pOldList->nCurrent = nOldCurrent;
    3065             :     }
    3066       34810 :     return pHd;
    3067             : }
    3068             : 
    3069             : 
    3070             : //  private methods
    3071             : 
    3072             : 
    3073        6434 : bool CompareSvxMSDffShapeInfoById::operator() (
    3074             :     ::boost::shared_ptr<SvxMSDffShapeInfo> const& lhs,
    3075             :     ::boost::shared_ptr<SvxMSDffShapeInfo> const& rhs) const
    3076             : {
    3077        6434 :     return lhs->nShapeId < rhs->nShapeId;
    3078             : }
    3079             : 
    3080        4066 : bool CompareSvxMSDffShapeInfoByTxBxComp::operator() (
    3081             :     ::boost::shared_ptr<SvxMSDffShapeInfo> const& lhs,
    3082             :     ::boost::shared_ptr<SvxMSDffShapeInfo> const& rhs) const
    3083             : {
    3084        4066 :     return lhs->nTxBxComp < rhs->nTxBxComp;
    3085             : }
    3086             : 
    3087       20344 : void SvxMSDffManager::Scale( sal_Int32& rVal ) const
    3088             : {
    3089       20344 :     if ( bNeedMap )
    3090       17400 :         rVal = BigMulDiv( rVal, nMapMul, nMapDiv );
    3091       20344 : }
    3092             : 
    3093           0 : void SvxMSDffManager::Scale( Point& rPos ) const
    3094             : {
    3095           0 :     rPos.X() += nMapXOfs;
    3096           0 :     rPos.Y() += nMapYOfs;
    3097           0 :     if ( bNeedMap )
    3098             :     {
    3099           0 :         rPos.X() = BigMulDiv( rPos.X(), nMapMul, nMapDiv );
    3100           0 :         rPos.Y() = BigMulDiv( rPos.Y(), nMapMul, nMapDiv );
    3101             :     }
    3102           0 : }
    3103             : 
    3104         242 : void SvxMSDffManager::Scale( Size& rSiz ) const
    3105             : {
    3106         242 :     if ( bNeedMap )
    3107             :     {
    3108         242 :         rSiz.Width() = BigMulDiv( rSiz.Width(), nMapMul, nMapDiv );
    3109         242 :         rSiz.Height() = BigMulDiv( rSiz.Height(), nMapMul, nMapDiv );
    3110             :     }
    3111         242 : }
    3112             : 
    3113        7884 : void SvxMSDffManager::ScaleEmu( sal_Int32& rVal ) const
    3114             : {
    3115        7884 :     rVal = BigMulDiv( rVal, nEmuMul, nEmuDiv );
    3116        7884 : }
    3117             : 
    3118           0 : sal_uInt32 SvxMSDffManager::ScalePt( sal_uInt32 nVal ) const
    3119             : {
    3120           0 :     MapUnit eMap = pSdrModel->GetScaleUnit();
    3121           0 :     Fraction aFact( GetMapFactor( MAP_POINT, eMap ).X() );
    3122           0 :     long aMul = aFact.GetNumerator();
    3123           0 :     long aDiv = aFact.GetDenominator() * 65536;
    3124           0 :     aFact = Fraction( aMul, aDiv ); // try again to shorten it
    3125           0 :     return BigMulDiv( nVal, aFact.GetNumerator(), aFact.GetDenominator() );
    3126             : }
    3127             : 
    3128        2148 : sal_Int32 SvxMSDffManager::ScalePoint( sal_Int32 nVal ) const
    3129             : {
    3130        2148 :     return BigMulDiv( nVal, nPntMul, nPntDiv );
    3131             : };
    3132             : 
    3133         836 : void SvxMSDffManager::SetModel(SdrModel* pModel, long nApplicationScale)
    3134             : {
    3135         836 :     pSdrModel = pModel;
    3136         836 :     if( pModel && (0 < nApplicationScale) )
    3137             :     {
    3138             :         // PPT works in units of 576DPI
    3139             :         // WW on the other side uses twips, i.e. 1440DPI.
    3140         710 :         MapUnit eMap = pSdrModel->GetScaleUnit();
    3141         710 :         Fraction aFact( GetMapFactor(MAP_INCH, eMap).X() );
    3142         710 :         long nMul=aFact.GetNumerator();
    3143         710 :         long nDiv=aFact.GetDenominator()*nApplicationScale;
    3144         710 :         aFact=Fraction(nMul,nDiv); // try again to shorten it
    3145             :         // For 100TH_MM -> 2540/576=635/144
    3146             :         // For Twip     -> 1440/576=5/2
    3147         710 :         nMapMul  = aFact.GetNumerator();
    3148         710 :         nMapDiv  = aFact.GetDenominator();
    3149         710 :         bNeedMap = nMapMul!=nMapDiv;
    3150             : 
    3151             :         // MS-DFF-Properties are mostly given in EMU (English Metric Units)
    3152             :         // 1mm=36000emu, 1twip=635emu
    3153         710 :         aFact=GetMapFactor(MAP_100TH_MM,eMap).X();
    3154         710 :         nMul=aFact.GetNumerator();
    3155         710 :         nDiv=aFact.GetDenominator()*360;
    3156         710 :         aFact=Fraction(nMul,nDiv); // try again to shorten it
    3157             :         // For 100TH_MM ->                            1/360
    3158             :         // For Twip     -> 14,40/(25,4*360)=144/91440=1/635
    3159         710 :         nEmuMul=aFact.GetNumerator();
    3160         710 :         nEmuDiv=aFact.GetDenominator();
    3161             : 
    3162             :         // And something for typographic Points
    3163         710 :         aFact=GetMapFactor(MAP_POINT,eMap).X();
    3164         710 :         nPntMul=aFact.GetNumerator();
    3165         710 :         nPntDiv=aFact.GetDenominator();
    3166             :     }
    3167             :     else
    3168             :     {
    3169         126 :         pModel = 0;
    3170         126 :         nMapMul = nMapDiv = nMapXOfs = nMapYOfs = nEmuMul = nEmuDiv = nPntMul = nPntDiv = 0;
    3171         126 :         bNeedMap = false;
    3172             :     }
    3173         836 : }
    3174             : 
    3175         370 : bool SvxMSDffManager::SeekToShape( SvStream& rSt, void* /* pClientData */, sal_uInt32 nId ) const
    3176             : {
    3177         370 :     bool bRet = false;
    3178         370 :     if ( !maFidcls.empty() )
    3179             :     {
    3180         370 :         sal_uInt32 nMerk = rSt.Tell();
    3181         370 :         sal_uInt32 nShapeId, nSec = ( nId >> 10 ) - 1;
    3182         370 :         if ( nSec < mnIdClusters )
    3183             :         {
    3184         370 :             OffsetMap::const_iterator it = maDgOffsetTable.find( maFidcls[ nSec ].dgid );
    3185         370 :             if ( it != maDgOffsetTable.end() )
    3186             :             {
    3187         370 :                 sal_IntPtr nOfs = it->second;
    3188         370 :                 rSt.Seek( nOfs );
    3189         370 :                 DffRecordHeader aEscherF002Hd;
    3190         370 :                 ReadDffRecordHeader( rSt, aEscherF002Hd );
    3191         370 :                 sal_uLong nEscherF002End = aEscherF002Hd.GetRecEndFilePos();
    3192         370 :                 DffRecordHeader aEscherObjListHd;
    3193        3328 :                 while (rSt.good() && rSt.Tell() < nEscherF002End)
    3194             :                 {
    3195        2958 :                     ReadDffRecordHeader( rSt, aEscherObjListHd );
    3196        2958 :                     if ( aEscherObjListHd.nRecVer != 0xf )
    3197         370 :                         aEscherObjListHd.SeekToEndOfRecord( rSt );
    3198        2588 :                     else if ( aEscherObjListHd.nRecType == DFF_msofbtSpContainer )
    3199             :                     {
    3200        2012 :                         DffRecordHeader aShapeHd;
    3201        2012 :                         if ( SeekToRec( rSt, DFF_msofbtSp, aEscherObjListHd.GetRecEndFilePos(), &aShapeHd ) )
    3202             :                         {
    3203        2012 :                             rSt.ReadUInt32( nShapeId );
    3204        2012 :                             if ( nId == nShapeId )
    3205             :                             {
    3206         370 :                                 aEscherObjListHd.SeekToBegOfRecord( rSt );
    3207         370 :                                 bRet = true;
    3208         370 :                                 break;
    3209             :                             }
    3210             :                         }
    3211        1642 :                         aEscherObjListHd.SeekToEndOfRecord( rSt );
    3212             :                     }
    3213             :                 }
    3214             :             }
    3215             :         }
    3216         370 :         if ( !bRet )
    3217           0 :             rSt.Seek( nMerk );
    3218             :     }
    3219         370 :     return bRet;
    3220             : }
    3221             : 
    3222       12608 : bool SvxMSDffManager::SeekToRec( SvStream& rSt, sal_uInt16 nRecId, sal_uLong nMaxFilePos, DffRecordHeader* pRecHd, sal_uLong nSkipCount ) const
    3223             : {
    3224       12608 :     bool bRet = false;
    3225       12608 :     sal_uLong nFPosMerk = rSt.Tell(); // store FilePos to restore it later if necessary
    3226       12608 :     DffRecordHeader aHd;
    3227       32106 :     do
    3228             :     {
    3229       32108 :         ReadDffRecordHeader( rSt, aHd );
    3230       32108 :         if (!rSt.good())
    3231           0 :             break;
    3232       32108 :         if (aHd.nRecLen > nMaxLegalDffRecordLength)
    3233           0 :             break;
    3234       32108 :         if ( aHd.nRecType == nRecId )
    3235             :         {
    3236        9998 :             if ( nSkipCount )
    3237           0 :                 nSkipCount--;
    3238             :             else
    3239             :             {
    3240        9998 :                 bRet = true;
    3241        9998 :                 if ( pRecHd != NULL )
    3242        8668 :                     *pRecHd = aHd;
    3243             :                 else
    3244        1330 :                     aHd.SeekToBegOfRecord( rSt );
    3245             :             }
    3246             :         }
    3247       32108 :         if ( !bRet )
    3248             :         {
    3249       22110 :             bool bSeekSuccess = aHd.SeekToEndOfRecord( rSt );
    3250       22110 :             if (!bSeekSuccess)
    3251           2 :                 break;
    3252             :         }
    3253             :     }
    3254       32106 :     while ( rSt.good() && rSt.Tell() < nMaxFilePos && !bRet );
    3255       12608 :     if ( !bRet )
    3256        2610 :         rSt.Seek( nFPosMerk );  // restore original FilePos
    3257       12608 :     return bRet;
    3258             : }
    3259             : 
    3260        1294 : bool SvxMSDffManager::SeekToRec2( sal_uInt16 nRecId1, sal_uInt16 nRecId2, sal_uLong nMaxFilePos, DffRecordHeader* pRecHd, sal_uLong nSkipCount ) const
    3261             : {
    3262        1294 :     bool bRet = false;
    3263        1294 :     sal_uLong nFPosMerk = rStCtrl.Tell();   // remember FilePos for conditionally later restauration
    3264        1294 :     DffRecordHeader aHd;
    3265        1514 :     do
    3266             :     {
    3267        1514 :         ReadDffRecordHeader( rStCtrl, aHd );
    3268        1514 :         if ( aHd.nRecType == nRecId1 || aHd.nRecType == nRecId2 )
    3269             :         {
    3270        1136 :             if ( nSkipCount )
    3271           0 :                 nSkipCount--;
    3272             :             else
    3273             :             {
    3274        1136 :                 bRet = true;
    3275        1136 :                 if ( pRecHd )
    3276           0 :                     *pRecHd = aHd;
    3277             :                 else
    3278        1136 :                     aHd.SeekToBegOfRecord( rStCtrl );
    3279             :             }
    3280             :         }
    3281        1514 :         if ( !bRet )
    3282         378 :             aHd.SeekToEndOfRecord( rStCtrl );
    3283             :     }
    3284        1514 :     while ( rStCtrl.good() && rStCtrl.Tell() < nMaxFilePos && !bRet );
    3285        1294 :     if ( !bRet )
    3286         158 :         rStCtrl.Seek( nFPosMerk ); // restore FilePos
    3287        1294 :     return bRet;
    3288             : }
    3289             : 
    3290             : 
    3291          44 : bool SvxMSDffManager::GetColorFromPalette( sal_uInt16 /* nNum */, Color& rColor ) const
    3292             : {
    3293             :     // This method has to be overwritten in the class
    3294             :     // derived for the excel export
    3295          44 :     rColor.SetColor( COL_WHITE );
    3296          44 :     return true;
    3297             : }
    3298             : 
    3299             : // sj: the documentation is not complete, especially in ppt the normal rgb for text
    3300             : // color is written as 0xfeRRGGBB, this can't be explained by the documentation, nearly
    3301             : // every bit in the upper code is set -> so there seems to be a special handling for
    3302             : // ppt text colors, i decided not to fix this in MSO_CLR_ToColor because of possible
    3303             : // side effects, instead MSO_TEXT_CLR_ToColor is called for PPT text colors, to map
    3304             : // the color code to something that behaves like the other standard color codes used by
    3305             : // fill and line color
    3306       17120 : Color SvxMSDffManager::MSO_TEXT_CLR_ToColor( sal_uInt32 nColorCode ) const
    3307             : {
    3308             :     // for text colors: Header is 0xfeRRGGBB
    3309       17120 :     if ( ( nColorCode & 0xfe000000 ) == 0xfe000000 )
    3310        3608 :         nColorCode &= 0x00ffffff;
    3311             :     else
    3312             :     {
    3313             :         // for colorscheme colors the color index are the lower three bits of the upper byte
    3314       13512 :         if ( ( nColorCode & 0xf8000000 ) == 0 ) // this must be a colorscheme index
    3315             :         {
    3316       13266 :             nColorCode >>= 24;
    3317       13266 :             nColorCode |= 0x8000000;
    3318             :         }
    3319             :     }
    3320       17120 :     return MSO_CLR_ToColor( nColorCode );
    3321             : }
    3322             : 
    3323       35060 : Color SvxMSDffManager::MSO_CLR_ToColor( sal_uInt32 nColorCode, sal_uInt16 nContentProperty ) const
    3324             : {
    3325       35060 :     Color aColor( mnDefaultColor );
    3326             : 
    3327             :     // for text colors: Header is 0xfeRRGGBB
    3328       35060 :     if ( ( nColorCode & 0xfe000000 ) == 0xfe000000 )    // sj: it needs to be checked if 0xfe is used in
    3329           0 :         nColorCode &= 0x00ffffff;                       // other cases than ppt text -> if not this code can be removed
    3330             : 
    3331       35060 :     sal_uInt8 nUpper = (sal_uInt8)( nColorCode >> 24 );
    3332             : 
    3333             :     // sj: below change from 0x1b to 0x19 was done because of i84812 (0x02 -> rgb color),
    3334             :     // now I have some problems to fix i104685 (there the color value is 0x02000000 whichs requires
    3335             :     // a 0x2 scheme color to be displayed properly), the color docu seems to be incomplete
    3336       35060 :     if( nUpper & 0x19 )      // if( nUpper & 0x1f )
    3337             :     {
    3338       20188 :         if( ( nUpper & 0x08 ) || ( ( nUpper & 0x10 ) == 0 ) )
    3339             :         {
    3340             :             // SCHEMECOLOR
    3341       40376 :             if ( !GetColorFromPalette( ( nUpper & 8 ) ? (sal_uInt16)nColorCode : nUpper, aColor ) )
    3342             :             {
    3343           0 :                 switch( nContentProperty )
    3344             :                 {
    3345             :                     case DFF_Prop_pictureTransparent :
    3346             :                     case DFF_Prop_shadowColor :
    3347             :                     case DFF_Prop_fillBackColor :
    3348             :                     case DFF_Prop_fillColor :
    3349           0 :                         aColor = Color( COL_WHITE );
    3350           0 :                     break;
    3351             :                     case DFF_Prop_lineColor :
    3352             :                     {
    3353           0 :                         aColor = Color( COL_BLACK );
    3354             :                     }
    3355           0 :                     break;
    3356             :                 }
    3357             :             }
    3358             :         }
    3359             :         else    // SYSCOLOR
    3360             :         {
    3361           0 :             const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
    3362             : 
    3363           0 :             sal_uInt16 nParameter = sal_uInt16(( nColorCode >> 16 ) & 0x00ff);  // the HiByte of nParameter is not zero, an exclusive AND is helping :o
    3364           0 :             sal_uInt16 nFunctionBits = (sal_uInt16)( ( nColorCode & 0x00000f00 ) >> 8 );
    3365           0 :             sal_uInt16 nAdditionalFlags = (sal_uInt16)( ( nColorCode & 0x0000f000) >> 8 );
    3366           0 :             sal_uInt16 nColorIndex = sal_uInt16(nColorCode & 0x00ff);
    3367           0 :             sal_uInt32 nPropColor = 0;
    3368             : 
    3369           0 :             sal_uInt16  nCProp = 0;
    3370             : 
    3371           0 :             switch ( nColorIndex )
    3372             :             {
    3373           0 :                 case mso_syscolorButtonFace :           aColor = rStyleSettings.GetFaceColor(); break;
    3374           0 :                 case mso_syscolorWindowText :           aColor = rStyleSettings.GetWindowTextColor(); break;
    3375           0 :                 case mso_syscolorMenu :                 aColor = rStyleSettings.GetMenuColor(); break;
    3376             :                 case mso_syscolor3DLight :
    3377             :                 case mso_syscolorButtonHighlight :
    3378           0 :                 case mso_syscolorHighlight :            aColor = rStyleSettings.GetHighlightColor(); break;
    3379           0 :                 case mso_syscolorHighlightText :        aColor = rStyleSettings.GetHighlightTextColor(); break;
    3380           0 :                 case mso_syscolorCaptionText :          aColor = rStyleSettings.GetMenuTextColor(); break;
    3381           0 :                 case mso_syscolorActiveCaption :        aColor = rStyleSettings.GetHighlightColor(); break;
    3382           0 :                 case mso_syscolorButtonShadow :         aColor = rStyleSettings.GetShadowColor(); break;
    3383           0 :                 case mso_syscolorButtonText :           aColor = rStyleSettings.GetButtonTextColor(); break;
    3384           0 :                 case mso_syscolorGrayText :             aColor = rStyleSettings.GetDeactiveColor(); break;
    3385           0 :                 case mso_syscolorInactiveCaption :      aColor = rStyleSettings.GetDeactiveColor(); break;
    3386           0 :                 case mso_syscolorInactiveCaptionText :  aColor = rStyleSettings.GetDeactiveColor(); break;
    3387           0 :                 case mso_syscolorInfoBackground :       aColor = rStyleSettings.GetFaceColor(); break;
    3388           0 :                 case mso_syscolorInfoText :             aColor = rStyleSettings.GetInfoTextColor(); break;
    3389           0 :                 case mso_syscolorMenuText :             aColor = rStyleSettings.GetMenuTextColor(); break;
    3390           0 :                 case mso_syscolorScrollbar :            aColor = rStyleSettings.GetFaceColor(); break;
    3391           0 :                 case mso_syscolorWindow :               aColor = rStyleSettings.GetWindowColor(); break;
    3392           0 :                 case mso_syscolorWindowFrame :          aColor = rStyleSettings.GetWindowColor(); break;
    3393             : 
    3394             :                 case mso_colorFillColor :
    3395             :                 {
    3396           0 :                     nPropColor = GetPropertyValue( DFF_Prop_fillColor, 0xffffff );
    3397           0 :                     nCProp = DFF_Prop_fillColor;
    3398             :                 }
    3399           0 :                 break;
    3400             :                 case mso_colorLineOrFillColor :     // ( use the line color only if there is a line )
    3401             :                 {
    3402           0 :                     if ( GetPropertyValue( DFF_Prop_fNoLineDrawDash ) & 8 )
    3403             :                     {
    3404           0 :                         nPropColor = GetPropertyValue( DFF_Prop_lineColor, 0 );
    3405           0 :                         nCProp = DFF_Prop_lineColor;
    3406             :                     }
    3407             :                     else
    3408             :                     {
    3409           0 :                         nPropColor = GetPropertyValue( DFF_Prop_fillColor, 0xffffff );
    3410           0 :                         nCProp = DFF_Prop_fillColor;
    3411             :                     }
    3412             :                 }
    3413           0 :                 break;
    3414             :                 case mso_colorLineColor :
    3415             :                 {
    3416           0 :                     nPropColor = GetPropertyValue( DFF_Prop_lineColor, 0 );
    3417           0 :                     nCProp = DFF_Prop_lineColor;
    3418             :                 }
    3419           0 :                 break;
    3420             :                 case mso_colorShadowColor :
    3421             :                 {
    3422           0 :                     nPropColor = GetPropertyValue( DFF_Prop_shadowColor, 0x808080 );
    3423           0 :                     nCProp = DFF_Prop_shadowColor;
    3424             :                 }
    3425           0 :                 break;
    3426             :                 case mso_colorThis :                // ( use this color ... )
    3427             :                 {
    3428           0 :                     nPropColor = GetPropertyValue( DFF_Prop_fillColor, 0xffffff );  //?????????????
    3429           0 :                     nCProp = DFF_Prop_fillColor;
    3430             :                 }
    3431           0 :                 break;
    3432             :                 case mso_colorFillBackColor :
    3433             :                 {
    3434           0 :                     nPropColor = GetPropertyValue( DFF_Prop_fillBackColor, 0xffffff );
    3435           0 :                     nCProp = DFF_Prop_fillBackColor;
    3436             :                 }
    3437           0 :                 break;
    3438             :                 case mso_colorLineBackColor :
    3439             :                 {
    3440           0 :                     nPropColor = GetPropertyValue( DFF_Prop_lineBackColor, 0xffffff );
    3441           0 :                     nCProp = DFF_Prop_lineBackColor;
    3442             :                 }
    3443           0 :                 break;
    3444             :                 case mso_colorFillThenLine :        // ( use the fillcolor unless no fill and line )
    3445             :                 {
    3446           0 :                     nPropColor = GetPropertyValue( DFF_Prop_fillColor, 0xffffff );  //?????????????
    3447           0 :                     nCProp = DFF_Prop_fillColor;
    3448             :                 }
    3449           0 :                 break;
    3450             :                 case mso_colorIndexMask :           // ( extract the color index ) ?
    3451             :                 {
    3452           0 :                     nPropColor = GetPropertyValue( DFF_Prop_fillColor, 0xffffff );  //?????????????
    3453           0 :                     nCProp = DFF_Prop_fillColor;
    3454             :                 }
    3455           0 :                 break;
    3456             :             }
    3457           0 :             if ( nCProp && ( nPropColor & 0x10000000 ) == 0 )       // beware of looping recursive
    3458           0 :                 aColor = MSO_CLR_ToColor( nPropColor, nCProp );
    3459             : 
    3460           0 :             if( nAdditionalFlags & 0x80 )           // make color gray
    3461             :             {
    3462           0 :                 sal_uInt8 nZwi = aColor.GetLuminance();
    3463           0 :                 aColor = Color( nZwi, nZwi, nZwi );
    3464             :             }
    3465           0 :             switch( nFunctionBits )
    3466             :             {
    3467             :                 case 0x01 :     // darken color by parameter
    3468             :                 {
    3469           0 :                     aColor.SetRed( sal::static_int_cast< sal_uInt8 >( ( nParameter * aColor.GetRed() ) >> 8 ) );
    3470           0 :                     aColor.SetGreen( sal::static_int_cast< sal_uInt8 >( ( nParameter * aColor.GetGreen() ) >> 8 ) );
    3471           0 :                     aColor.SetBlue( sal::static_int_cast< sal_uInt8 >( ( nParameter * aColor.GetBlue() ) >> 8 ) );
    3472             :                 }
    3473           0 :                 break;
    3474             :                 case 0x02 :     // lighten color by parameter
    3475             :                 {
    3476           0 :                     sal_uInt16 nInvParameter = ( 0x00ff - nParameter ) * 0xff;
    3477           0 :                     aColor.SetRed( sal::static_int_cast< sal_uInt8 >( ( nInvParameter + ( nParameter * aColor.GetRed() ) ) >> 8 ) );
    3478           0 :                     aColor.SetGreen( sal::static_int_cast< sal_uInt8 >( ( nInvParameter + ( nParameter * aColor.GetGreen() ) ) >> 8 ) );
    3479           0 :                     aColor.SetBlue( sal::static_int_cast< sal_uInt8 >( ( nInvParameter + ( nParameter * aColor.GetBlue() ) ) >> 8 ) );
    3480             :                 }
    3481           0 :                 break;
    3482             :                 case 0x03 :     // add grey level RGB(p,p,p)
    3483             :                 {
    3484           0 :                     sal_Int16 nR = (sal_Int16)aColor.GetRed() + (sal_Int16)nParameter;
    3485           0 :                     sal_Int16 nG = (sal_Int16)aColor.GetGreen() + (sal_Int16)nParameter;
    3486           0 :                     sal_Int16 nB = (sal_Int16)aColor.GetBlue() + (sal_Int16)nParameter;
    3487           0 :                     if ( nR > 0x00ff )
    3488           0 :                         nR = 0x00ff;
    3489           0 :                     if ( nG > 0x00ff )
    3490           0 :                         nG = 0x00ff;
    3491           0 :                     if ( nB > 0x00ff )
    3492           0 :                         nB = 0x00ff;
    3493           0 :                     aColor = Color( (sal_uInt8)nR, (sal_uInt8)nG, (sal_uInt8)nB );
    3494             :                 }
    3495           0 :                 break;
    3496             :                 case 0x04 :     // subtract grey level RGB(p,p,p)
    3497             :                 {
    3498           0 :                     sal_Int16 nR = (sal_Int16)aColor.GetRed() - (sal_Int16)nParameter;
    3499           0 :                     sal_Int16 nG = (sal_Int16)aColor.GetGreen() - (sal_Int16)nParameter;
    3500           0 :                     sal_Int16 nB = (sal_Int16)aColor.GetBlue() - (sal_Int16)nParameter;
    3501           0 :                     if ( nR < 0 )
    3502           0 :                         nR = 0;
    3503           0 :                     if ( nG < 0 )
    3504           0 :                         nG = 0;
    3505           0 :                     if ( nB < 0 )
    3506           0 :                         nB = 0;
    3507           0 :                     aColor = Color( (sal_uInt8)nR, (sal_uInt8)nG, (sal_uInt8)nB );
    3508             :                 }
    3509           0 :                 break;
    3510             :                 case 0x05 :     // subtract from gray level RGB(p,p,p)
    3511             :                 {
    3512           0 :                     sal_Int16 nR = (sal_Int16)nParameter - (sal_Int16)aColor.GetRed();
    3513           0 :                     sal_Int16 nG = (sal_Int16)nParameter - (sal_Int16)aColor.GetGreen();
    3514           0 :                     sal_Int16 nB = (sal_Int16)nParameter - (sal_Int16)aColor.GetBlue();
    3515           0 :                     if ( nR < 0 )
    3516           0 :                         nR = 0;
    3517           0 :                     if ( nG < 0 )
    3518           0 :                         nG = 0;
    3519           0 :                     if ( nB < 0 )
    3520           0 :                         nB = 0;
    3521           0 :                     aColor = Color( (sal_uInt8)nR, (sal_uInt8)nG, (sal_uInt8)nB );
    3522             :                 }
    3523           0 :                 break;
    3524             :                 case 0x06 :     // per component: black if < p, white if >= p
    3525             :                 {
    3526           0 :                     aColor.SetRed( aColor.GetRed() < nParameter ? 0x00 : 0xff );
    3527           0 :                     aColor.SetGreen( aColor.GetGreen() < nParameter ? 0x00 : 0xff );
    3528           0 :                     aColor.SetBlue( aColor.GetBlue() < nParameter ? 0x00 : 0xff );
    3529             :                 }
    3530           0 :                 break;
    3531             :             }
    3532           0 :             if ( nAdditionalFlags & 0x40 )                  // top-bit invert
    3533           0 :                 aColor = Color( aColor.GetRed() ^ 0x80, aColor.GetGreen() ^ 0x80, aColor.GetBlue() ^ 0x80 );
    3534             : 
    3535           0 :             if ( nAdditionalFlags & 0x20 )                  // invert color
    3536           0 :                 aColor = Color(0xff - aColor.GetRed(), 0xff - aColor.GetGreen(), 0xff - aColor.GetBlue());
    3537             :         }
    3538             :     }
    3539       14872 :     else if ( ( nUpper & 4 ) && ( ( nColorCode & 0xfffff8 ) == 0 ) )
    3540             :     {   // case of nUpper == 4 powerpoint takes this as argument for a colorschemecolor
    3541           0 :         GetColorFromPalette( nUpper, aColor );
    3542             :     }
    3543             :     else    // attributed hard, maybe with hint to SYSTEMRGB
    3544       14872 :         aColor = Color( (sal_uInt8)nColorCode, (sal_uInt8)( nColorCode >> 8 ), (sal_uInt8)( nColorCode >> 16 ) );
    3545       35060 :     return aColor;
    3546             : }
    3547             : 
    3548           0 : void SvxMSDffManager::ReadObjText( SvStream& rStream, SdrObject* pObj )
    3549             : {
    3550           0 :     DffRecordHeader aRecHd;
    3551           0 :     ReadDffRecordHeader( rStream, aRecHd );
    3552           0 :     if( aRecHd.nRecType == DFF_msofbtClientTextbox || aRecHd.nRecType == 0x1022 )
    3553             :     {
    3554           0 :         while( rStream.GetError() == 0 && rStream.Tell() < aRecHd.GetRecEndFilePos() )
    3555             :         {
    3556           0 :             DffRecordHeader aHd;
    3557           0 :             ReadDffRecordHeader( rStream, aHd );
    3558           0 :             switch( aHd.nRecType )
    3559             :             {
    3560             :                 case DFF_PST_TextBytesAtom:
    3561             :                 case DFF_PST_TextCharsAtom:
    3562             :                     {
    3563           0 :                         bool bUniCode = ( aHd.nRecType == DFF_PST_TextCharsAtom );
    3564           0 :                         sal_uInt32 nBytes = aHd.nRecLen;
    3565           0 :                         OUString aStr = MSDFFReadZString( rStream, nBytes, bUniCode );
    3566           0 :                         ReadObjText( aStr, pObj );
    3567             :                     }
    3568           0 :                     break;
    3569             :                 default:
    3570           0 :                     break;
    3571             :             }
    3572           0 :             aHd.SeekToEndOfRecord( rStream );
    3573             :         }
    3574             :     }
    3575           0 : }
    3576             : 
    3577             : // sj: I just want to set a string for a text object that may contain multiple
    3578             : // paragraphs. If I now take a look at the following code I get the impression that
    3579             : // our outliner is too complicate to be used properly,
    3580           2 : void SvxMSDffManager::ReadObjText( const OUString& rText, SdrObject* pObj )
    3581             : {
    3582           2 :     SdrTextObj* pText = PTR_CAST( SdrTextObj, pObj );
    3583           2 :     if ( pText )
    3584             :     {
    3585           2 :         SdrOutliner& rOutliner = pText->ImpGetDrawOutliner();
    3586           2 :         rOutliner.Init( OUTLINERMODE_TEXTOBJECT );
    3587             : 
    3588           2 :         bool bOldUpdateMode = rOutliner.GetUpdateMode();
    3589           2 :         rOutliner.SetUpdateMode( false );
    3590           2 :         rOutliner.SetVertical( pText->IsVerticalWriting() );
    3591             : 
    3592           2 :         sal_Int32 nParaIndex = 0;
    3593             :         sal_Int32 nParaSize;
    3594           2 :         const sal_Unicode* pCurrent, *pBuf = rText.getStr();
    3595           2 :         const sal_Unicode* pEnd = rText.getStr() + rText.getLength();
    3596             : 
    3597           6 :         while( pBuf < pEnd )
    3598             :         {
    3599           2 :             pCurrent = pBuf;
    3600             : 
    3601          32 :             for ( nParaSize = 0; pBuf < pEnd; )
    3602             :             {
    3603          28 :                 sal_Unicode nChar = *pBuf++;
    3604          28 :                 if ( nChar == 0xa )
    3605             :                 {
    3606           0 :                     if ( ( pBuf < pEnd ) && ( *pBuf == 0xd ) )
    3607           0 :                         pBuf++;
    3608           0 :                     break;
    3609             :                 }
    3610          28 :                 else if ( nChar == 0xd )
    3611             :                 {
    3612           0 :                     if ( ( pBuf < pEnd ) && ( *pBuf == 0xa ) )
    3613           0 :                         pBuf++;
    3614           0 :                     break;
    3615             :                 }
    3616             :                 else
    3617          28 :                     ++nParaSize;
    3618             :             }
    3619           2 :             ESelection aSelection( nParaIndex, 0, nParaIndex, 0 );
    3620           2 :             OUString aParagraph( pCurrent, nParaSize );
    3621           2 :             if ( !nParaIndex && aParagraph.isEmpty() )              // SJ: we are crashing if the first paragraph is empty ?
    3622           0 :                 aParagraph += " ";                   // otherwise these two lines can be removed.
    3623           2 :             rOutliner.Insert( aParagraph, nParaIndex, 0 );
    3624           2 :             rOutliner.SetParaAttribs( nParaIndex, rOutliner.GetEmptyItemSet() );
    3625             : 
    3626           4 :             SfxItemSet aParagraphAttribs( rOutliner.GetEmptyItemSet() );
    3627           2 :             if ( !aSelection.nStartPos )
    3628           2 :                 aParagraphAttribs.Put( SfxBoolItem( EE_PARA_BULLETSTATE, false ) );
    3629           2 :             aSelection.nStartPos = 0;
    3630           2 :             rOutliner.QuickSetAttribs( aParagraphAttribs, aSelection );
    3631           2 :             nParaIndex++;
    3632           2 :         }
    3633           2 :         OutlinerParaObject* pNewText = rOutliner.CreateParaObject();
    3634           2 :         rOutliner.Clear();
    3635           2 :         rOutliner.SetUpdateMode( bOldUpdateMode );
    3636           2 :         pText->SetOutlinerParaObject( pNewText );
    3637             :     }
    3638           2 : }
    3639             : 
    3640             : //static
    3641        2102 : OUString SvxMSDffManager::MSDFFReadZString(SvStream& rIn,
    3642             :     sal_uInt32 nLen, bool bUniCode)
    3643             : {
    3644        2102 :     if (!nLen)
    3645           0 :         return OUString();
    3646             : 
    3647        2102 :     OUString sBuf;
    3648             : 
    3649        2102 :     if( bUniCode )
    3650        2102 :         sBuf = read_uInt16s_ToOUString(rIn, nLen/2);
    3651             :     else
    3652           0 :         sBuf = read_uInt8s_ToOUString(rIn, nLen, RTL_TEXTENCODING_MS_1252);
    3653             : 
    3654        2102 :     return comphelper::string::stripEnd(sBuf, 0);
    3655             : }
    3656             : 
    3657           0 : static Size lcl_GetPrefSize(const Graphic& rGraf, MapMode aWanted)
    3658             : {
    3659           0 :     MapMode aPrefMapMode(rGraf.GetPrefMapMode());
    3660           0 :     if (aPrefMapMode == aWanted)
    3661           0 :         return rGraf.GetPrefSize();
    3662           0 :     Size aRetSize;
    3663           0 :     if (aPrefMapMode == MAP_PIXEL)
    3664             :     {
    3665             :         aRetSize = Application::GetDefaultDevice()->PixelToLogic(
    3666           0 :             rGraf.GetPrefSize(), aWanted);
    3667             :     }
    3668             :     else
    3669             :     {
    3670             :         aRetSize = OutputDevice::LogicToLogic(
    3671           0 :             rGraf.GetPrefSize(), rGraf.GetPrefMapMode(), aWanted);
    3672             :     }
    3673           0 :     return aRetSize;
    3674             : }
    3675             : 
    3676             : // sj: if the parameter pSet is null, then the resulting crop bitmap will be stored in rGraf,
    3677             : // otherwise rGraf is untouched and pSet is used to store the corresponding SdrGrafCropItem
    3678          84 : static void lcl_ApplyCropping( const DffPropSet& rPropSet, SfxItemSet* pSet, Graphic& rGraf )
    3679             : {
    3680          84 :     sal_Int32 nCropTop      = (sal_Int32)rPropSet.GetPropertyValue( DFF_Prop_cropFromTop, 0 );
    3681          84 :     sal_Int32 nCropBottom   = (sal_Int32)rPropSet.GetPropertyValue( DFF_Prop_cropFromBottom, 0 );
    3682          84 :     sal_Int32 nCropLeft     = (sal_Int32)rPropSet.GetPropertyValue( DFF_Prop_cropFromLeft, 0 );
    3683          84 :     sal_Int32 nCropRight    = (sal_Int32)rPropSet.GetPropertyValue( DFF_Prop_cropFromRight, 0 );
    3684             : 
    3685          84 :     if( nCropTop || nCropBottom || nCropLeft || nCropRight )
    3686             :     {
    3687             :         double      fFactor;
    3688           0 :         Size        aCropSize;
    3689           0 :         BitmapEx    aCropBitmap;
    3690           0 :         sal_uInt32  nTop( 0 ),  nBottom( 0 ), nLeft( 0 ), nRight( 0 );
    3691             : 
    3692           0 :         if ( pSet ) // use crop attributes ?
    3693           0 :             aCropSize = lcl_GetPrefSize( rGraf, MAP_100TH_MM );
    3694             :         else
    3695             :         {
    3696           0 :             aCropBitmap = rGraf.GetBitmapEx();
    3697           0 :             aCropSize = aCropBitmap.GetSizePixel();
    3698             :         }
    3699           0 :         if ( nCropTop )
    3700             :         {
    3701           0 :             fFactor = (double)nCropTop / 65536.0;
    3702           0 :             nTop = (sal_uInt32)( ( (double)( aCropSize.Height() + 1 ) * fFactor ) + 0.5 );
    3703             :         }
    3704           0 :         if ( nCropBottom )
    3705             :         {
    3706           0 :             fFactor = (double)nCropBottom / 65536.0;
    3707           0 :             nBottom = (sal_uInt32)( ( (double)( aCropSize.Height() + 1 ) * fFactor ) + 0.5 );
    3708             :         }
    3709           0 :         if ( nCropLeft )
    3710             :         {
    3711           0 :             fFactor = (double)nCropLeft / 65536.0;
    3712           0 :             nLeft = (sal_uInt32)( ( (double)( aCropSize.Width() + 1 ) * fFactor ) + 0.5 );
    3713             :         }
    3714           0 :         if ( nCropRight )
    3715             :         {
    3716           0 :             fFactor = (double)nCropRight / 65536.0;
    3717           0 :             nRight = (sal_uInt32)( ( (double)( aCropSize.Width() + 1 ) * fFactor ) + 0.5 );
    3718             :         }
    3719           0 :         if ( pSet ) // use crop attributes ?
    3720           0 :             pSet->Put( SdrGrafCropItem( nLeft, nTop, nRight, nBottom ) );
    3721             :         else
    3722             :         {
    3723           0 :             Rectangle aCropRect( nLeft, nTop, aCropSize.Width() - nRight, aCropSize.Height() - nBottom );
    3724           0 :             aCropBitmap.Crop( aCropRect );
    3725           0 :             rGraf = aCropBitmap;
    3726           0 :         }
    3727             :     }
    3728          84 : }
    3729             : 
    3730         180 : SdrObject* SvxMSDffManager::ImportGraphic( SvStream& rSt, SfxItemSet& rSet, const DffObjData& rObjData )
    3731             : {
    3732         180 :     SdrObject*  pRet = NULL;
    3733         180 :     OUString    aFileName;
    3734         360 :     OUString    aLinkFileName, aLinkFilterName;
    3735         180 :     Rectangle   aVisArea;
    3736             : 
    3737         180 :     MSO_BlipFlags eFlags = (MSO_BlipFlags)GetPropertyValue( DFF_Prop_pibFlags, mso_blipflagDefault );
    3738         180 :     sal_uInt32 nBlipId = GetPropertyValue( DFF_Prop_pib, 0 );
    3739         180 :     bool bGrfRead = false,
    3740             : 
    3741             :     // Graphic linked
    3742         180 :     bLinkGrf = 0 != ( eFlags & mso_blipflagLinkToFile );
    3743             :     {
    3744         180 :         Graphic aGraf;  // be sure this graphic is deleted before swapping out
    3745         180 :         if( SeekToContent( DFF_Prop_pibName, rSt ) )
    3746          36 :             aFileName = MSDFFReadZString( rSt, GetPropertyValue( DFF_Prop_pibName ), true );
    3747             : 
    3748             :         //   AND, OR the following:
    3749         180 :         if( !( eFlags & mso_blipflagDoNotSave ) ) // Graphic embedded
    3750             :         {
    3751         180 :             bGrfRead = GetBLIP( nBlipId, aGraf, &aVisArea );
    3752         180 :             if ( !bGrfRead )
    3753             :             {
    3754             :                 /*
    3755             :                 Still no luck, lets look at the end of this record for a FBSE pool,
    3756             :                 this fallback is a specific case for how word does it sometimes
    3757             :                 */
    3758          48 :                 rObjData.rSpHd.SeekToEndOfRecord( rSt );
    3759          48 :                 DffRecordHeader aHd;
    3760          48 :                 ReadDffRecordHeader( rSt, aHd );
    3761          48 :                 if( DFF_msofbtBSE == aHd.nRecType )
    3762             :                 {
    3763          40 :                     const sal_uLong nSkipBLIPLen = 20;
    3764          40 :                     const sal_uLong nSkipShapePos = 4;
    3765          40 :                     const sal_uLong nSkipBLIP = 4;
    3766             :                     const sal_uLong nSkip =
    3767          40 :                         nSkipBLIPLen + 4 + nSkipShapePos + 4 + nSkipBLIP;
    3768             : 
    3769          40 :                     if (nSkip <= aHd.nRecLen)
    3770             :                     {
    3771          40 :                         rSt.SeekRel(nSkip);
    3772          40 :                         if (0 == rSt.GetError())
    3773          40 :                             bGrfRead = GetBLIPDirect( rSt, aGraf, &aVisArea );
    3774             :                     }
    3775             :                 }
    3776             :             }
    3777             :         }
    3778         180 :         if ( bGrfRead )
    3779             :         {
    3780             :             // the writer is doing its own cropping, so this part affects only impress and calc,
    3781             :             // unless we're inside a group, in which case writer doesn't crop either
    3782         170 :             if (( GetSvxMSDffSettings() & SVXMSDFF_SETTINGS_CROP_BITMAPS ) || rObjData.nCalledByGroup != 0 )
    3783          84 :                 lcl_ApplyCropping( *this, ( rObjData.nSpFlags & SP_FOLESHAPE ) == 0 ? &rSet : NULL, aGraf );
    3784             : 
    3785         170 :             if ( IsProperty( DFF_Prop_pictureTransparent ) )
    3786             :             {
    3787           8 :                 sal_uInt32 nTransColor = GetPropertyValue( DFF_Prop_pictureTransparent, 0 );
    3788             : 
    3789           8 :                 if ( aGraf.GetType() == GRAPHIC_BITMAP )
    3790             :                 {
    3791           8 :                     BitmapEx    aBitmapEx( aGraf.GetBitmapEx() );
    3792          16 :                     Bitmap      aBitmap( aBitmapEx.GetBitmap() );
    3793          16 :                     Bitmap      aMask( aBitmap.CreateMask( MSO_CLR_ToColor( nTransColor, DFF_Prop_pictureTransparent ), 9 ) );
    3794           8 :                     if ( aBitmapEx.IsTransparent() )
    3795           0 :                         aMask.CombineSimple( aBitmapEx.GetMask(), BMP_COMBINE_OR );
    3796          16 :                     aGraf = BitmapEx( aBitmap, aMask );
    3797             :                 }
    3798             :             }
    3799             : 
    3800         170 :             sal_Int32 nContrast = GetPropertyValue( DFF_Prop_pictureContrast, 0x10000 );
    3801             :             /*
    3802             :             0x10000 is msoffice 50%
    3803             :             < 0x10000 is in units of 1/50th of 0x10000 per 1%
    3804             :             > 0x10000 is in units where
    3805             :             a msoffice x% is stored as 50/(100-x) * 0x10000
    3806             : 
    3807             :             plus, a (ui) microsoft % ranges from 0 to 100, OOO
    3808             :             from -100 to 100, so also normalize into that range
    3809             :             */
    3810         170 :             if ( nContrast > 0x10000 )
    3811             :             {
    3812           0 :                 double fX = nContrast;
    3813           0 :                 fX /= 0x10000;
    3814           0 :                 fX /= 51;   // 50 + 1 to round
    3815           0 :                 fX = 1/fX;
    3816           0 :                 nContrast = static_cast<sal_Int32>(fX);
    3817           0 :                 nContrast -= 100;
    3818           0 :                 nContrast = -nContrast;
    3819           0 :                 nContrast = (nContrast-50)*2;
    3820             :             }
    3821         170 :             else if ( nContrast == 0x10000 )
    3822         168 :                 nContrast = 0;
    3823             :             else
    3824             :             {
    3825           2 :                 nContrast *= 101;   //100 + 1 to round
    3826           2 :                 nContrast /= 0x10000;
    3827           2 :                 nContrast -= 100;
    3828             :             }
    3829         170 :             sal_Int16   nBrightness     = (sal_Int16)( (sal_Int32)GetPropertyValue( DFF_Prop_pictureBrightness, 0 ) / 327 );
    3830         170 :             sal_Int32   nGamma          = GetPropertyValue( DFF_Prop_pictureGamma, 0x10000 );
    3831         170 :             GraphicDrawMode eDrawMode   = GRAPHICDRAWMODE_STANDARD;
    3832         170 :             switch ( GetPropertyValue( DFF_Prop_pictureActive ) & 6 )
    3833             :             {
    3834           2 :                 case 4 : eDrawMode = GRAPHICDRAWMODE_GREYS; break;
    3835           0 :                 case 6 : eDrawMode = GRAPHICDRAWMODE_MONO; break;
    3836             :                 case 0 :
    3837             :                 {
    3838             :                     //office considers the converted values of (in OOo) 70 to be the
    3839             :                     //"watermark" values, which can vary slightly due to rounding from the
    3840             :                     //above values
    3841         168 :                     if (( nContrast == -70 ) && ( nBrightness == 70 ))
    3842             :                     {
    3843           0 :                         nContrast = 0;
    3844           0 :                         nBrightness = 0;
    3845           0 :                         eDrawMode = GRAPHICDRAWMODE_WATERMARK;
    3846             :                     };
    3847             :                 }
    3848         168 :                 break;
    3849             :             }
    3850             : 
    3851         170 :             if ( nContrast || nBrightness || ( nGamma != 0x10000 ) || ( eDrawMode != GRAPHICDRAWMODE_STANDARD ) )
    3852             :             {
    3853             :                 // MSO uses a different algorithm for contrast+brightness, LO applies contrast before brightness,
    3854             :                 // while MSO apparently applies half of brightness before contrast and half after. So if only
    3855             :                 // contrast or brightness need to be altered, the result is the same, but if both are involved,
    3856             :                 // there's no way to map that, so just force a conversion of the image.
    3857           2 :                 bool needsConversion = nContrast != 0 && nBrightness != 0;
    3858           2 :                 if ( ( rObjData.nSpFlags & SP_FOLESHAPE ) == 0 && !needsConversion )
    3859             :                 {
    3860           0 :                     if ( nBrightness )
    3861           0 :                         rSet.Put( SdrGrafLuminanceItem( nBrightness ) );
    3862           0 :                     if ( nContrast )
    3863           0 :                         rSet.Put( SdrGrafContrastItem( (sal_Int16)nContrast ) );
    3864           0 :                     if ( nGamma != 0x10000 )
    3865           0 :                         rSet.Put( SdrGrafGamma100Item( nGamma / 655 ) );
    3866           0 :                     if ( eDrawMode != GRAPHICDRAWMODE_STANDARD )
    3867           0 :                         rSet.Put( SdrGrafModeItem( eDrawMode ) );
    3868             :                 }
    3869             :                 else
    3870             :                 {
    3871           2 :                     if ( eDrawMode == GRAPHICDRAWMODE_WATERMARK )
    3872             :                     {
    3873           0 :                         nContrast = 60;
    3874           0 :                         nBrightness = 70;
    3875           0 :                         eDrawMode = GRAPHICDRAWMODE_STANDARD;
    3876             :                     }
    3877           2 :                     switch ( aGraf.GetType() )
    3878             :                     {
    3879             :                         case GRAPHIC_BITMAP :
    3880             :                         {
    3881           2 :                             BitmapEx    aBitmapEx( aGraf.GetBitmapEx() );
    3882           2 :                             if ( nBrightness || nContrast || ( nGamma != 0x10000 ) )
    3883           2 :                                 aBitmapEx.Adjust( nBrightness, (sal_Int16)nContrast, 0, 0, 0, (double)nGamma / 0x10000, false, true );
    3884           2 :                             if ( eDrawMode == GRAPHICDRAWMODE_GREYS )
    3885           2 :                                 aBitmapEx.Convert( BMP_CONVERSION_8BIT_GREYS );
    3886           0 :                             else if ( eDrawMode == GRAPHICDRAWMODE_MONO )
    3887           0 :                                 aBitmapEx.Convert( BMP_CONVERSION_1BIT_THRESHOLD );
    3888           2 :                             aGraf = aBitmapEx;
    3889             : 
    3890             :                         }
    3891           2 :                         break;
    3892             : 
    3893             :                         case GRAPHIC_GDIMETAFILE :
    3894             :                         {
    3895           0 :                             GDIMetaFile aGdiMetaFile( aGraf.GetGDIMetaFile() );
    3896           0 :                             if ( nBrightness || nContrast || ( nGamma != 0x10000 ) )
    3897           0 :                                 aGdiMetaFile.Adjust( nBrightness, (sal_Int16)nContrast, 0, 0, 0, (double)nGamma / 0x10000, false, true );
    3898           0 :                             if ( eDrawMode == GRAPHICDRAWMODE_GREYS )
    3899           0 :                                 aGdiMetaFile.Convert( MTF_CONVERSION_8BIT_GREYS );
    3900           0 :                             else if ( eDrawMode == GRAPHICDRAWMODE_MONO )
    3901           0 :                                 aGdiMetaFile.Convert( MTF_CONVERSION_1BIT_THRESHOLD );
    3902           0 :                             aGraf = aGdiMetaFile;
    3903             :                         }
    3904           0 :                         break;
    3905           0 :                         default: break;
    3906             :                     }
    3907             :                 }
    3908             :             }
    3909             :         }
    3910             : 
    3911             :         // should it be an OLE object?
    3912         180 :         if( bGrfRead && !bLinkGrf && IsProperty( DFF_Prop_pictureId ) )
    3913             :         {
    3914             :             // TODO/LATER: in future probably the correct aspect should be provided here
    3915          90 :             sal_Int64 nAspect = embed::Aspects::MSOLE_CONTENT;
    3916             :             // #i32596# - pass <nCalledByGroup> to method
    3917          90 :             pRet = ImportOLE( GetPropertyValue( DFF_Prop_pictureId ), aGraf, rObjData.aBoundRect, aVisArea, rObjData.nCalledByGroup, nAspect );
    3918             :         }
    3919         180 :         if( !pRet )
    3920             :         {
    3921         148 :             pRet = new SdrGrafObj;
    3922         148 :             if( bGrfRead )
    3923         138 :                 static_cast<SdrGrafObj*>(pRet)->SetGraphic( aGraf );
    3924             : 
    3925         148 :             if( bLinkGrf && !bGrfRead )     // sj: #i55484# if the graphic was embedded ( bGrfRead == true ) then
    3926             :             {                               // we do not need to set a link. TODO: not to lose the information where the graphic is linked from
    3927           0 :                 INetURLObject aAbsURL;
    3928           0 :                 if ( !INetURLObject( maBaseURL ).GetNewAbsURL( aFileName, &aAbsURL ) )
    3929             :                 {
    3930           0 :                     OUString aValidURL;
    3931           0 :                     if( ::utl::LocalFileHelper::ConvertPhysicalNameToURL( aFileName, aValidURL ) )
    3932           0 :                         aAbsURL = INetURLObject( aValidURL );
    3933             :                 }
    3934           0 :                 if( aAbsURL.GetProtocol() != INET_PROT_NOT_VALID )
    3935             :                 {
    3936           0 :                     GraphicFilter &rGrfFilter = GraphicFilter::GetGraphicFilter();
    3937           0 :                     aLinkFilterName = rGrfFilter.GetImportFormatName(
    3938           0 :                         rGrfFilter.GetImportFormatNumberForShortName( aAbsURL.getExtension() ) );
    3939           0 :                     aLinkFileName = aAbsURL.GetMainURL( INetURLObject::DECODE_TO_IURI );
    3940             :                 }
    3941             :                 else
    3942           0 :                     aLinkFileName = aFileName;
    3943             :             }
    3944             :         }
    3945             : 
    3946             :         // set the size from BLIP if there is one
    3947         180 :         if ( pRet && bGrfRead && !aVisArea.IsEmpty() )
    3948         108 :             pRet->SetBLIPSizeRectangle( aVisArea );
    3949             : 
    3950         180 :         if (pRet->GetName().isEmpty())                   // SJ 22.02.00 : PPT OLE IMPORT:
    3951             :         {                                                // name is already set in ImportOLE !!
    3952             :             // JP 01.12.99: SetName before SetModel - because in the other order the Bug 70098 is active
    3953         180 :             if ( ( eFlags & mso_blipflagType ) != mso_blipflagComment )
    3954             :             {
    3955          24 :                 INetURLObject aURL;
    3956          24 :                 aURL.SetSmartURL( aFileName );
    3957          24 :                 pRet->SetName( aURL.getBase() );
    3958             :             }
    3959             :             else
    3960         156 :                 pRet->SetName( aFileName );
    3961         180 :         }
    3962             :     }
    3963         180 :     pRet->SetModel( pSdrModel ); // required for GraphicLink
    3964         180 :     pRet->SetLogicRect( rObjData.aBoundRect );
    3965             : 
    3966         180 :     if ( pRet->ISA( SdrGrafObj ) )
    3967             :     {
    3968         148 :         if( aLinkFileName.getLength() )
    3969           0 :             static_cast<SdrGrafObj*>(pRet)->SetGraphicLink( aLinkFileName, ""/*TODO?*/, aLinkFilterName );
    3970             : 
    3971         148 :         if ( bLinkGrf && !bGrfRead )
    3972             :         {
    3973           0 :             static_cast<SdrGrafObj*>(pRet)->ForceSwapIn();
    3974           0 :             Graphic aGraf(static_cast<SdrGrafObj*>(pRet)->GetGraphic());
    3975           0 :             lcl_ApplyCropping( *this, &rSet, aGraf );
    3976             :         }
    3977         148 :         static_cast<SdrGrafObj*>(pRet)->ForceSwapOut();
    3978             :     }
    3979             : 
    3980         360 :     return pRet;
    3981             : }
    3982             : 
    3983             : // PptSlidePersistEntry& rPersistEntry, SdPage* pPage
    3984        1658 : SdrObject* SvxMSDffManager::ImportObj( SvStream& rSt, void* pClientData,
    3985             :     Rectangle& rClientRect, const Rectangle& rGlobalChildRect, int nCalledByGroup, sal_Int32* pShapeId )
    3986             : {
    3987        1658 :     SdrObject* pRet = NULL;
    3988        1658 :     DffRecordHeader aObjHd;
    3989        1658 :     ReadDffRecordHeader( rSt, aObjHd );
    3990        1658 :     if ( aObjHd.nRecType == DFF_msofbtSpgrContainer )
    3991             :     {
    3992         100 :         pRet = ImportGroup( aObjHd, rSt, pClientData, rClientRect, rGlobalChildRect, nCalledByGroup, pShapeId );
    3993             :     }
    3994        1558 :     else if ( aObjHd.nRecType == DFF_msofbtSpContainer )
    3995             :     {
    3996        1558 :         pRet = ImportShape( aObjHd, rSt, pClientData, rClientRect, rGlobalChildRect, nCalledByGroup, pShapeId );
    3997             :     }
    3998        1658 :     aObjHd.SeekToBegOfRecord( rSt );    // restore FilePos
    3999        1658 :     return pRet;
    4000             : }
    4001             : 
    4002         102 : SdrObject* SvxMSDffManager::ImportGroup( const DffRecordHeader& rHd, SvStream& rSt, void* pClientData,
    4003             :                                             Rectangle& rClientRect, const Rectangle& rGlobalChildRect,
    4004             :                                                 int nCalledByGroup, sal_Int32* pShapeId )
    4005             : {
    4006         102 :     SdrObject* pRet = NULL;
    4007             : 
    4008         102 :     if( pShapeId )
    4009          70 :         *pShapeId = 0;
    4010             : 
    4011         102 :     if (!rHd.SeekToContent(rSt))
    4012           0 :         return pRet;
    4013             : 
    4014         102 :     DffRecordHeader aRecHd;     // the first atom has to be the SpContainer for the GroupObject
    4015         102 :     ReadDffRecordHeader( rSt, aRecHd );
    4016         102 :     if ( aRecHd.nRecType == DFF_msofbtSpContainer )
    4017             :     {
    4018         102 :         mnFix16Angle = 0;
    4019         102 :         if (!aRecHd.SeekToBegOfRecord(rSt))
    4020           0 :             return pRet;
    4021         102 :         pRet = ImportObj( rSt, pClientData, rClientRect, rGlobalChildRect, nCalledByGroup + 1, pShapeId );
    4022         102 :         if ( pRet )
    4023             :         {
    4024         102 :             sal_Int32 nGroupRotateAngle = 0;
    4025         102 :             sal_Int32 nSpFlags = nGroupShapeFlags;
    4026         102 :             nGroupRotateAngle = mnFix16Angle;
    4027             : 
    4028         102 :             Rectangle aClientRect( rClientRect );
    4029             : 
    4030         102 :             Rectangle aGlobalChildRect;
    4031         102 :             if ( !nCalledByGroup || rGlobalChildRect.IsEmpty() )
    4032         100 :                 aGlobalChildRect = GetGlobalChildAnchor( rHd, rSt, aClientRect );
    4033             :             else
    4034           2 :                 aGlobalChildRect = rGlobalChildRect;
    4035             : 
    4036         102 :             if ( ( nGroupRotateAngle > 4500 && nGroupRotateAngle <= 13500 )
    4037         102 :                 || ( nGroupRotateAngle > 22500 && nGroupRotateAngle <= 31500 ) )
    4038             :             {
    4039           0 :                 sal_Int32 nHalfWidth = ( aClientRect.GetWidth() + 1 ) >> 1;
    4040           0 :                 sal_Int32 nHalfHeight = ( aClientRect.GetHeight() + 1 ) >> 1;
    4041           0 :                 Point aTopLeft( aClientRect.Left() + nHalfWidth - nHalfHeight,
    4042           0 :                                 aClientRect.Top() + nHalfHeight - nHalfWidth );
    4043           0 :                 const long nRotatedWidth = aClientRect.GetHeight();
    4044           0 :                 const long nRotatedHeight = aClientRect.GetWidth();
    4045           0 :                 Size aNewSize(nRotatedWidth, nRotatedHeight);
    4046           0 :                 Rectangle aNewRect( aTopLeft, aNewSize );
    4047           0 :                 aClientRect = aNewRect;
    4048             :             }
    4049             : 
    4050             :             // now importing the inner objects of the group
    4051         102 :             if (!aRecHd.SeekToEndOfRecord(rSt))
    4052           0 :                 return pRet;
    4053             : 
    4054        2370 :             while ( ( rSt.GetError() == 0 ) && ( rSt.Tell() < rHd.GetRecEndFilePos() ) )
    4055             :             {
    4056        2166 :                 DffRecordHeader aRecHd2;
    4057        2166 :                 ReadDffRecordHeader( rSt, aRecHd2 );
    4058        2166 :                 if ( aRecHd2.nRecType == DFF_msofbtSpgrContainer )
    4059             :                 {
    4060           2 :                     Rectangle aGroupClientAnchor, aGroupChildAnchor;
    4061           2 :                     GetGroupAnchors( aRecHd2, rSt, aGroupClientAnchor, aGroupChildAnchor, aClientRect, aGlobalChildRect );
    4062           2 :                     if (!aRecHd2.SeekToBegOfRecord(rSt))
    4063           0 :                         return pRet;
    4064             :                     sal_Int32 nShapeId;
    4065           2 :                     SdrObject* pTmp = ImportGroup( aRecHd2, rSt, pClientData, aGroupClientAnchor, aGroupChildAnchor, nCalledByGroup + 1, &nShapeId );
    4066           2 :                     if ( pTmp && pRet && static_cast<SdrObjGroup*>(pRet)->GetSubList() )
    4067             :                     {
    4068           2 :                         static_cast<SdrObjGroup*>(pRet)->GetSubList()->NbcInsertObject( pTmp );
    4069           2 :                         if( nShapeId )
    4070           2 :                             insertShapeId( nShapeId, pTmp );
    4071             :                     }
    4072             :                 }
    4073        2164 :                 else if ( aRecHd2.nRecType == DFF_msofbtSpContainer )
    4074             :                 {
    4075        2164 :                     if (!aRecHd2.SeekToBegOfRecord(rSt))
    4076           0 :                         return pRet;
    4077             :                     sal_Int32 nShapeId;
    4078        2164 :                     SdrObject* pTmp = ImportShape( aRecHd2, rSt, pClientData, aClientRect, aGlobalChildRect, nCalledByGroup + 1, &nShapeId );
    4079        2164 :                     if ( pTmp && pRet && static_cast<SdrObjGroup*>(pRet)->GetSubList())
    4080             :                     {
    4081        2164 :                         static_cast<SdrObjGroup*>(pRet)->GetSubList()->NbcInsertObject( pTmp );
    4082        2164 :                         if( nShapeId )
    4083        2164 :                             insertShapeId( nShapeId, pTmp );
    4084             :                     }
    4085             :                 }
    4086        2166 :                 if (!aRecHd2.SeekToEndOfRecord(rSt))
    4087           0 :                     return pRet;
    4088             :             }
    4089             : 
    4090         102 :             if ( nGroupRotateAngle )
    4091             :             {
    4092           0 :                 double a = nGroupRotateAngle * nPi180;
    4093           0 :                 pRet->NbcRotate( aClientRect.Center(), nGroupRotateAngle, sin( a ), cos( a ) );
    4094             :             }
    4095         102 :             if ( nSpFlags & SP_FFLIPV )     // Vertical flip?
    4096             :             {   // BoundRect in aBoundRect
    4097           0 :                 Point aLeft( aClientRect.Left(), ( aClientRect.Top() + aClientRect.Bottom() ) >> 1 );
    4098           0 :                 Point aRight( aLeft.X() + 1000, aLeft.Y() );
    4099           0 :                 pRet->NbcMirror( aLeft, aRight );
    4100             :             }
    4101         102 :             if ( nSpFlags & SP_FFLIPH )     // Horizontal flip?
    4102             :             {   // BoundRect in aBoundRect
    4103           0 :                 Point aTop( ( aClientRect.Left() + aClientRect.Right() ) >> 1, aClientRect.Top() );
    4104           0 :                 Point aBottom( aTop.X(), aTop.Y() + 1000 );
    4105           0 :                 pRet->NbcMirror( aTop, aBottom );
    4106             :             }
    4107             :         }
    4108             :     }
    4109         102 :     return pRet;
    4110             : }
    4111             : 
    4112        3722 : SdrObject* SvxMSDffManager::ImportShape( const DffRecordHeader& rHd, SvStream& rSt, void* pClientData,
    4113             :                                             Rectangle& rClientRect, const Rectangle& rGlobalChildRect,
    4114             :                                             int nCalledByGroup, sal_Int32* pShapeId )
    4115             : {
    4116        3722 :     SdrObject* pRet = NULL;
    4117             : 
    4118        3722 :     if( pShapeId )
    4119        2662 :         *pShapeId = 0;
    4120             : 
    4121        3722 :     if (!rHd.SeekToBegOfRecord(rSt))
    4122           0 :         return pRet;
    4123             : 
    4124        3722 :     DffObjData aObjData( rHd, rClientRect, nCalledByGroup );
    4125        3722 :     aObjData.bRotateTextWithShape = ( GetSvxMSDffSettings() & SVXMSDFF_SETTINGS_IMPORT_EXCEL ) == 0;
    4126        3722 :     maShapeRecords.Consume( rSt, false );
    4127        3722 :     if( maShapeRecords.SeekToContent( rSt,
    4128             :         DFF_msofbtUDefProp,
    4129        3722 :         SEEK_FROM_BEGINNING ) )
    4130             :     {
    4131         906 :         sal_uInt32  nBytesLeft = maShapeRecords.Current()->nRecLen;
    4132             :         sal_uInt32  nUDData;
    4133             :         sal_uInt16  nPID;
    4134       27318 :         while( 5 < nBytesLeft )
    4135             :         {
    4136       25712 :             rSt.ReadUInt16( nPID );
    4137       25712 :             if ( rSt.GetError() != 0 )
    4138           0 :                 break;
    4139       25712 :             rSt.ReadUInt32( nUDData );
    4140       25712 :             if ( rSt.GetError() != 0 )
    4141           0 :                 break;
    4142       25712 :             if ( nPID == 447 )
    4143             :             {
    4144         206 :                 mbRotateGranientFillWithAngle = nUDData & 0x20;
    4145         206 :                 break;
    4146             :             }
    4147       25506 :             nBytesLeft  -= 6;
    4148             :         }
    4149             :     }
    4150        3722 :     aObjData.bShapeType = maShapeRecords.SeekToContent( rSt, DFF_msofbtSp, SEEK_FROM_BEGINNING );
    4151        3722 :     if ( aObjData.bShapeType )
    4152             :     {
    4153        3722 :         rSt.ReadUInt32( aObjData.nShapeId )
    4154        3722 :            .ReadUInt32( aObjData.nSpFlags );
    4155        3722 :         aObjData.eShapeType = (MSO_SPT)maShapeRecords.Current()->nRecInstance;
    4156             :     }
    4157             :     else
    4158             :     {
    4159           0 :         aObjData.nShapeId = 0;
    4160           0 :         aObjData.nSpFlags = 0;
    4161           0 :         aObjData.eShapeType = mso_sptNil;
    4162             :     }
    4163             : 
    4164        3722 :     if( pShapeId )
    4165        2662 :         *pShapeId = aObjData.nShapeId;
    4166             : 
    4167        3722 :     aObjData.bOpt = maShapeRecords.SeekToContent( rSt, DFF_msofbtOPT, SEEK_FROM_CURRENT_AND_RESTART );
    4168        3722 :     if ( aObjData.bOpt )
    4169             :     {
    4170        3470 :         if (!maShapeRecords.Current()->SeekToBegOfRecord(rSt))
    4171           0 :             return pRet;
    4172             : #ifdef DBG_AUTOSHAPE
    4173             :         ReadPropSet( rSt, pClientData, (sal_uInt32)aObjData.eShapeType );
    4174             : #else
    4175        3470 :         ReadPropSet( rSt, pClientData );
    4176             : #endif
    4177             :     }
    4178             :     else
    4179             :     {
    4180         252 :         InitializePropSet( DFF_msofbtOPT ); // get the default PropSet
    4181         252 :         ( (DffPropertyReader*) this )->mnFix16Angle = 0;
    4182             :     }
    4183             : 
    4184        3722 :     aObjData.bOpt2 = maShapeRecords.SeekToContent( rSt, DFF_msofbtUDefProp, SEEK_FROM_CURRENT_AND_RESTART );
    4185        3722 :     if ( aObjData.bOpt2 )
    4186             :     {
    4187         906 :         maShapeRecords.Current()->SeekToBegOfRecord( rSt );
    4188         906 :         delete pSecPropSet;
    4189         906 :         pSecPropSet = new DffPropertyReader( *this );
    4190         906 :         pSecPropSet->ReadPropSet( rSt, NULL );
    4191             :     }
    4192             : 
    4193        3722 :     aObjData.bChildAnchor = maShapeRecords.SeekToContent( rSt, DFF_msofbtChildAnchor, SEEK_FROM_CURRENT_AND_RESTART );
    4194        3722 :     if ( aObjData.bChildAnchor )
    4195             :     {
    4196             :         sal_Int32 l, o, r, u;
    4197        2166 :         rSt.ReadInt32( l ).ReadInt32( o ).ReadInt32( r ).ReadInt32( u );
    4198        2166 :         Scale( l );
    4199        2166 :         Scale( o );
    4200        2166 :         Scale( r );
    4201        2166 :         Scale( u );
    4202        2166 :         aObjData.aChildAnchor = Rectangle( l, o, r, u );
    4203        2166 :         if ( !rGlobalChildRect.IsEmpty() && !rClientRect.IsEmpty() && rGlobalChildRect.GetWidth() && rGlobalChildRect.GetHeight() )
    4204             :         {
    4205        2166 :             double fWidth = r - l;
    4206        2166 :             double fHeight= u - o;
    4207        2166 :             double fXScale = (double)rClientRect.GetWidth() / (double)rGlobalChildRect.GetWidth();
    4208        2166 :             double fYScale = (double)rClientRect.GetHeight() / (double)rGlobalChildRect.GetHeight();
    4209        2166 :             double fl = ( ( l - rGlobalChildRect.Left() ) * fXScale ) + rClientRect.Left();
    4210        2166 :             double fo = ( ( o - rGlobalChildRect.Top()  ) * fYScale ) + rClientRect.Top();
    4211        2166 :             fWidth *= fXScale;
    4212        2166 :             fHeight *= fYScale;
    4213        2166 :             aObjData.aChildAnchor = Rectangle( Point( (sal_Int32)fl, (sal_Int32)fo ), Size( (sal_Int32)( fWidth + 1 ), (sal_Int32)( fHeight + 1 ) ) );
    4214             :         }
    4215             :     }
    4216             : 
    4217        3722 :     aObjData.bClientAnchor = maShapeRecords.SeekToContent( rSt, DFF_msofbtClientAnchor, SEEK_FROM_CURRENT_AND_RESTART );
    4218        3722 :     if ( aObjData.bClientAnchor )
    4219        1142 :         ProcessClientAnchor2( rSt, *maShapeRecords.Current(), pClientData, aObjData );
    4220             : 
    4221        3722 :     if ( aObjData.bChildAnchor )
    4222        3108 :         aObjData.aBoundRect = aObjData.aChildAnchor;
    4223             : 
    4224        3722 :     if ( aObjData.nSpFlags & SP_FBACKGROUND )
    4225         132 :         aObjData.aBoundRect = Rectangle( Point(), Size( 1, 1 ) );
    4226             : 
    4227        3722 :     Rectangle aTextRect;
    4228        3722 :     if ( !aObjData.aBoundRect.IsEmpty() )
    4229             :     {   // apply rotation to the BoundingBox BEFORE an object has been generated
    4230        3476 :         if( mnFix16Angle )
    4231             :         {
    4232          16 :             long nAngle = mnFix16Angle;
    4233          16 :             if ( ( nAngle > 4500 && nAngle <= 13500 ) || ( nAngle > 22500 && nAngle <= 31500 ) )
    4234             :             {
    4235          10 :                 sal_Int32 nHalfWidth = ( aObjData.aBoundRect.GetWidth() + 1 ) >> 1;
    4236          10 :                 sal_Int32 nHalfHeight = ( aObjData.aBoundRect.GetHeight() + 1 ) >> 1;
    4237          10 :                 Point aTopLeft( aObjData.aBoundRect.Left() + nHalfWidth - nHalfHeight,
    4238          20 :                                 aObjData.aBoundRect.Top() + nHalfHeight - nHalfWidth );
    4239          10 :                 Size aNewSize( aObjData.aBoundRect.GetHeight(), aObjData.aBoundRect.GetWidth() );
    4240          10 :                 Rectangle aNewRect( aTopLeft, aNewSize );
    4241          10 :                 aObjData.aBoundRect = aNewRect;
    4242             :             }
    4243             :         }
    4244        3476 :         aTextRect = aObjData.aBoundRect;
    4245        6772 :         bool bGraphic = IsProperty( DFF_Prop_pib ) ||
    4246        6772 :                             IsProperty( DFF_Prop_pibName ) ||
    4247        6772 :                             IsProperty( DFF_Prop_pibFlags );
    4248             : 
    4249        3476 :         if ( aObjData.nSpFlags & SP_FGROUP )
    4250             :         {
    4251         102 :             pRet = new SdrObjGroup;
    4252             :             /*  After CWS aw033 has been integrated, an empty group object
    4253             :                 cannot store its resulting bounding rectangle anymore. We have
    4254             :                 to return this rectangle via rClientRect now, but only, if
    4255             :                 caller has not passed an own bounding ractangle. */
    4256         102 :             if ( rClientRect.IsEmpty() )
    4257          70 :                  rClientRect = aObjData.aBoundRect;
    4258         102 :             nGroupShapeFlags = aObjData.nSpFlags;       // #73013#
    4259             :         }
    4260        3374 :         else if ( ( aObjData.eShapeType != mso_sptNil ) || IsProperty( DFF_Prop_pVertices ) || bGraphic )
    4261             :         {
    4262        3374 :             SfxItemSet  aSet( pSdrModel->GetItemPool() );
    4263             : 
    4264        3374 :             bool    bIsConnector = ( ( aObjData.eShapeType >= mso_sptStraightConnector1 ) && ( aObjData.eShapeType <= mso_sptCurvedConnector5 ) );
    4265        3374 :             sal_Int32   nObjectRotation = mnFix16Angle;
    4266        3374 :             sal_uInt32  nSpFlags = aObjData.nSpFlags;
    4267             : 
    4268        3374 :             if ( bGraphic )
    4269             :             {
    4270         180 :                 pRet = ImportGraphic( rSt, aSet, aObjData );        // SJ: #68396# is no longer true (fixed in ppt2000)
    4271         180 :                 ApplyAttributes( rSt, aSet, aObjData );
    4272         180 :                 pRet->SetMergedItemSet(aSet);
    4273             :             }
    4274        3194 :             else if ( aObjData.eShapeType == mso_sptLine && !( GetPropertyValue( DFF_Prop_fc3DLightFace ) & 8 ) )
    4275             :             {
    4276        1232 :                 basegfx::B2DPolygon aPoly;
    4277        1232 :                 aPoly.append(basegfx::B2DPoint(aObjData.aBoundRect.Left(), aObjData.aBoundRect.Top()));
    4278        1232 :                 aPoly.append(basegfx::B2DPoint(aObjData.aBoundRect.Right(), aObjData.aBoundRect.Bottom()));
    4279        1232 :                 pRet = new SdrPathObj(OBJ_LINE, basegfx::B2DPolyPolygon(aPoly));
    4280        1232 :                 pRet->SetModel( pSdrModel );
    4281        1232 :                 ApplyAttributes( rSt, aSet, aObjData );
    4282        1232 :                 pRet->SetMergedItemSet(aSet);
    4283             :             }
    4284             :             else
    4285             :             {
    4286        1962 :                 if ( GetCustomShapeContent( aObjData.eShapeType ) || IsProperty( DFF_Prop_pVertices ) )
    4287             :                 {
    4288             : 
    4289        1806 :                     ApplyAttributes( rSt, aSet, aObjData );
    4290             : 
    4291        1806 :                     pRet = new SdrObjCustomShape();
    4292        1806 :                     pRet->SetModel( pSdrModel );
    4293             : 
    4294        1806 :                     bool bIsFontwork = ( GetPropertyValue( DFF_Prop_gtextFStrikethrough, 0 ) & 0x4000 ) != 0;
    4295             : 
    4296             :                     // in case of a FontWork, the text is set by the escher import
    4297        1806 :                     if ( bIsFontwork )
    4298             :                     {
    4299           2 :                         OUString            aObjectText;
    4300           4 :                         OUString            aFontName;
    4301             :                         MSO_GeoTextAlign    eGeoTextAlign;
    4302             : 
    4303           2 :                         if ( SeekToContent( DFF_Prop_gtextFont, rSt ) )
    4304             :                         {
    4305           4 :                             SvxFontItem aLatin(EE_CHAR_FONTINFO), aAsian(EE_CHAR_FONTINFO_CJK), aComplex(EE_CHAR_FONTINFO_CTL);
    4306           2 :                             GetDefaultFonts( aLatin, aAsian, aComplex );
    4307             : 
    4308           2 :                             aFontName = MSDFFReadZString( rSt, GetPropertyValue( DFF_Prop_gtextFont ), true );
    4309           2 :                             aSet.Put( SvxFontItem( aLatin.GetFamily(), aFontName, aLatin.GetStyleName(),
    4310           2 :                                         PITCH_DONTKNOW, RTL_TEXTENCODING_DONTKNOW, EE_CHAR_FONTINFO ));
    4311           2 :                             aSet.Put( SvxFontItem( aLatin.GetFamily(), aFontName, aLatin.GetStyleName(),
    4312           2 :                                         PITCH_DONTKNOW, RTL_TEXTENCODING_DONTKNOW, EE_CHAR_FONTINFO_CJK ) );
    4313           2 :                             aSet.Put( SvxFontItem( aLatin.GetFamily(), aFontName, aLatin.GetStyleName(),
    4314           4 :                                         PITCH_DONTKNOW, RTL_TEXTENCODING_DONTKNOW, EE_CHAR_FONTINFO_CTL ) );
    4315             :                         }
    4316             : 
    4317             :                         // SJ: applying fontattributes for Fontwork :
    4318           2 :                         if ( IsHardAttribute( DFF_Prop_gtextFItalic ) )
    4319           2 :                             aSet.Put( SvxPostureItem( ( GetPropertyValue( DFF_Prop_gtextFStrikethrough, 0 ) & 0x0010 ) != 0 ? ITALIC_NORMAL : ITALIC_NONE, EE_CHAR_ITALIC ) );
    4320             : 
    4321           2 :                         if ( IsHardAttribute( DFF_Prop_gtextFBold ) )
    4322           2 :                             aSet.Put( SvxWeightItem( ( GetPropertyValue( DFF_Prop_gtextFStrikethrough, 0 ) & 0x0020 ) != 0 ? WEIGHT_BOLD : WEIGHT_NORMAL, EE_CHAR_WEIGHT ) );
    4323             : 
    4324             :                         // SJ TODO: Vertical Writing is not correct, instead
    4325             :                         // this should be replaced through "CharacterRotation"
    4326             :                         // by 90 degrees, therefore a new Item has to be
    4327             :                         // supported by svx core, api and xml file format
    4328           2 :                         static_cast<SdrObjCustomShape*>(pRet)->SetVerticalWriting( ( GetPropertyValue( DFF_Prop_gtextFStrikethrough, 0 ) & 0x2000 ) != 0 );
    4329             : 
    4330           2 :                         if ( SeekToContent( DFF_Prop_gtextUNICODE, rSt ) )
    4331             :                         {
    4332           2 :                             aObjectText = MSDFFReadZString( rSt, GetPropertyValue( DFF_Prop_gtextUNICODE ), true );
    4333           2 :                             ReadObjText( aObjectText, pRet );
    4334             :                         }
    4335             : 
    4336           2 :                         eGeoTextAlign = ( (MSO_GeoTextAlign)GetPropertyValue( DFF_Prop_gtextAlign, mso_alignTextCenter ) );
    4337             :                         {
    4338             :                             SdrTextHorzAdjust eHorzAdjust;
    4339           2 :                             switch( eGeoTextAlign )
    4340             :                             {
    4341             :                                 case mso_alignTextLetterJust :
    4342             :                                 case mso_alignTextWordJust :
    4343           0 :                                 case mso_alignTextStretch : eHorzAdjust = SDRTEXTHORZADJUST_BLOCK; break;
    4344             :                                 default:
    4345             :                                 case mso_alignTextInvalid :
    4346           2 :                                 case mso_alignTextCenter : eHorzAdjust = SDRTEXTHORZADJUST_CENTER; break;
    4347           0 :                                 case mso_alignTextLeft : eHorzAdjust = SDRTEXTHORZADJUST_LEFT; break;
    4348           0 :                                 case mso_alignTextRight : eHorzAdjust = SDRTEXTHORZADJUST_RIGHT; break;
    4349             :                             }
    4350           2 :                             aSet.Put( SdrTextHorzAdjustItem( eHorzAdjust ) );
    4351             : 
    4352           2 :                             SdrFitToSizeType eFTS = SDRTEXTFIT_NONE;
    4353           2 :                             if ( eGeoTextAlign == mso_alignTextStretch )
    4354           0 :                                 eFTS = SDRTEXTFIT_ALLLINES;
    4355           2 :                             aSet.Put( SdrTextFitToSizeTypeItem( eFTS ) );
    4356             :                         }
    4357           2 :                         if ( IsProperty( DFF_Prop_gtextSpacing ) )
    4358             :                         {
    4359           0 :                             sal_Int32 nTextWidth = GetPropertyValue( DFF_Prop_gtextSpacing, 1 << 16 ) / 655;
    4360           0 :                             if ( nTextWidth != 100 )
    4361           0 :                                 aSet.Put( SvxCharScaleWidthItem( (sal_uInt16)nTextWidth, EE_CHAR_FONTWIDTH ) );
    4362             :                         }
    4363           2 :                         if ( GetPropertyValue( DFF_Prop_gtextFStrikethrough, 0 ) & 0x1000 ) // SJ: Font Kerning On ?
    4364           2 :                             aSet.Put( SvxKerningItem( 1, EE_CHAR_KERNING ) );
    4365             : 
    4366             :                         // #i119496# the resize autoshape to fit text attr of word art in MS PPT is always false
    4367           2 :                         aSet.Put(makeSdrTextAutoGrowHeightItem(false));
    4368           4 :                         aSet.Put(makeSdrTextAutoGrowWidthItem(false));
    4369             :                     }
    4370        1806 :                     pRet->SetMergedItemSet( aSet );
    4371             : 
    4372             :                     // sj: taking care of rtl, ltr. In case of fontwork mso. seems not to be able to set
    4373             :                     // proper text directions, instead the text default is depending to the string.
    4374             :                     // so we have to calculate the a text direction from string:
    4375        1806 :                     if ( bIsFontwork )
    4376             :                     {
    4377           2 :                         OutlinerParaObject* pParaObj = static_cast<SdrObjCustomShape*>(pRet)->GetOutlinerParaObject();
    4378           2 :                         if ( pParaObj )
    4379             :                         {
    4380           2 :                             SdrOutliner& rOutliner = static_cast<SdrObjCustomShape*>(pRet)->ImpGetDrawOutliner();
    4381           2 :                             bool bOldUpdateMode = rOutliner.GetUpdateMode();
    4382           2 :                             SdrModel* pModel = pRet->GetModel();
    4383           2 :                             if ( pModel )
    4384           2 :                                 rOutliner.SetStyleSheetPool( static_cast<SfxStyleSheetPool*>(pModel->GetStyleSheetPool()) );
    4385           2 :                             rOutliner.SetUpdateMode( false );
    4386           2 :                             rOutliner.SetText( *pParaObj );
    4387           2 :                             VirtualDevice aVirDev( 1 );
    4388           2 :                             aVirDev.SetMapMode( MAP_100TH_MM );
    4389           2 :                             sal_Int32 i, nParagraphs = rOutliner.GetParagraphCount();
    4390           2 :                             if ( nParagraphs )
    4391             :                             {
    4392           2 :                                 bool bCreateNewParaObject = false;
    4393           4 :                                 for ( i = 0; i < nParagraphs; i++ )
    4394             :                                 {
    4395           2 :                                     OUString aString(rOutliner.GetText(rOutliner.GetParagraph(i)));
    4396           2 :                                     bool bIsRTL = aVirDev.GetTextIsRTL(aString, 0, aString.getLength());
    4397           2 :                                     if ( bIsRTL )
    4398             :                                     {
    4399           0 :                                         SfxItemSet aSet2( rOutliner.GetParaAttribs( i ) );
    4400           0 :                                         aSet2.Put( SvxFrameDirectionItem( FRMDIR_HORI_RIGHT_TOP, EE_PARA_WRITINGDIR ) );
    4401           0 :                                         rOutliner.SetParaAttribs( i, aSet2 );
    4402           0 :                                         bCreateNewParaObject = true;
    4403             :                                     }
    4404           2 :                                 }
    4405           2 :                                 if  ( bCreateNewParaObject )
    4406             :                                 {
    4407           0 :                                     OutlinerParaObject* pNewText = rOutliner.CreateParaObject();
    4408           0 :                                     rOutliner.Init( OUTLINERMODE_TEXTOBJECT );
    4409           0 :                                     static_cast<SdrObjCustomShape*>(pRet)->NbcSetOutlinerParaObject( pNewText );
    4410             :                                 }
    4411             :                             }
    4412           2 :                             rOutliner.Clear();
    4413           2 :                             rOutliner.SetUpdateMode( bOldUpdateMode );
    4414             :                         }
    4415             :                     }
    4416             : 
    4417             :                     // mso_sptArc special treating:
    4418             :                     // sj: since we actually can't render the arc because of its weird SnapRect settings,
    4419             :                     // we will create a new CustomShape, that can be saved/loaded without problems.
    4420             :                     // We will change the shape type, so this code applys only if importing arcs from msoffice.
    4421        1806 :                     if ( aObjData.eShapeType == mso_sptArc )
    4422             :                     {
    4423           0 :                         const OUString sAdjustmentValues( "AdjustmentValues" );
    4424           0 :                         const OUString sCoordinates( "Coordinates" );
    4425           0 :                         const OUString sHandles( "Handles" );
    4426           0 :                         const OUString sEquations( "Equations" );
    4427           0 :                         const OUString sViewBox( "ViewBox" );
    4428           0 :                         const OUString sPath( "Path" );
    4429           0 :                         const OUString sTextFrames( "TextFrames" );
    4430           0 :                         SdrCustomShapeGeometryItem aGeometryItem( static_cast<const SdrCustomShapeGeometryItem&>(static_cast<SdrObjCustomShape*>(pRet)->GetMergedItem( SDRATTR_CUSTOMSHAPE_GEOMETRY ) ) );
    4431           0 :                         com::sun::star::uno::Sequence< com::sun::star::drawing::EnhancedCustomShapeParameterPair> seqCoordinates;
    4432           0 :                         com::sun::star::uno::Sequence< com::sun::star::drawing::EnhancedCustomShapeAdjustmentValue > seqAdjustmentValues;
    4433             : 
    4434             :                         // before clearing the GeometryItem we have to store the current Coordinates
    4435           0 :                         const uno::Any* pAny = ((SdrCustomShapeGeometryItem&)aGeometryItem).GetPropertyValueByName( sPath, sCoordinates );
    4436           0 :                         Rectangle aPolyBoundRect;
    4437           0 :                         Point aStartPt( 0,0 );
    4438           0 :                         if ( pAny && ( *pAny >>= seqCoordinates ) && ( seqCoordinates.getLength() >= 4 ) )
    4439             :                         {
    4440           0 :                             sal_Int32 nPtNum, nNumElemVert = seqCoordinates.getLength();
    4441           0 :                             XPolygon aXP( (sal_uInt16)nNumElemVert );
    4442           0 :                             for ( nPtNum = 0; nPtNum < nNumElemVert; nPtNum++ )
    4443             :                             {
    4444           0 :                                 Point aP;
    4445           0 :                                 sal_Int32 nX = 0, nY = 0;
    4446           0 :                                 seqCoordinates[ nPtNum ].First.Value >>= nX;
    4447           0 :                                 seqCoordinates[ nPtNum ].Second.Value >>= nY;
    4448           0 :                                 aP.X() = nX;
    4449           0 :                                 aP.Y() = nY;
    4450           0 :                                 aXP[ (sal_uInt16)nPtNum ] = aP;
    4451             :                             }
    4452           0 :                             aPolyBoundRect = Rectangle( aXP.GetBoundRect() );
    4453           0 :                             if ( nNumElemVert >= 3 )
    4454             :                             { // arc first command is always wr -- clockwise arc
    4455             :                                 // the parameters are : (left,top),(right,bottom),start(x,y),end(x,y)
    4456           0 :                                 aStartPt = aXP[2];
    4457           0 :                             }
    4458             :                         }
    4459             :                         else
    4460           0 :                             aPolyBoundRect = Rectangle( -21600, 0, 21600, 43200 );  // defaulting
    4461             : 
    4462             :                         // clearing items, so MergeDefaultAttributes will set the corresponding defaults from EnhancedCustomShapeGeometry
    4463           0 :                         aGeometryItem.ClearPropertyValue( sHandles );
    4464           0 :                         aGeometryItem.ClearPropertyValue( sEquations );
    4465           0 :                         aGeometryItem.ClearPropertyValue( sViewBox );
    4466           0 :                         aGeometryItem.ClearPropertyValue( sPath );
    4467             : 
    4468           0 :                         sal_Int32 nEndAngle = 9000;
    4469           0 :                         sal_Int32 nStartAngle = 0;
    4470           0 :                         pAny = ((SdrCustomShapeGeometryItem&)aGeometryItem).GetPropertyValueByName( sAdjustmentValues );
    4471           0 :                         if ( pAny && ( *pAny >>= seqAdjustmentValues ) && seqAdjustmentValues.getLength() > 1 )
    4472             :                         {
    4473             :                             double fNumber;
    4474           0 :                             if ( seqAdjustmentValues[ 0 ].State == com::sun::star::beans::PropertyState_DIRECT_VALUE )
    4475             :                             {
    4476           0 :                                 seqAdjustmentValues[ 0 ].Value >>= fNumber;
    4477           0 :                                 nEndAngle = NormAngle360( - (sal_Int32)fNumber * 100 );
    4478             :                             }
    4479             :                             else
    4480             :                             {
    4481           0 :                                 fNumber = 270.0;
    4482             :                                 //normal situation:if endAngle != 90,there will be a direct_value,but for damaged curve,the endAngle need to recalculate.
    4483           0 :                                 Point cent = aPolyBoundRect.Center();
    4484           0 :                                 if ( aStartPt.Y() == cent.Y() )
    4485           0 :                                     fNumber = ( aStartPt.X() >= cent.X() ) ? 0:180.0;
    4486           0 :                                 else if ( aStartPt.X() == cent.X() )
    4487           0 :                                     fNumber = ( aStartPt.Y() >= cent.Y() ) ? 90.0: 270.0;
    4488             :                                 else
    4489             :                                 {
    4490           0 :                                     fNumber = atan2( double( aStartPt.X() - cent.X() ),double( aStartPt.Y() - cent.Y() ) )+ F_PI; // 0..2PI
    4491           0 :                                     fNumber /= F_PI180; // 0..360.0
    4492             :                                 }
    4493           0 :                                 nEndAngle = NormAngle360( - (sal_Int32)fNumber * 100 );
    4494           0 :                                 seqAdjustmentValues[ 0 ].Value <<= fNumber;
    4495           0 :                                 seqAdjustmentValues[ 0 ].State = com::sun::star::beans::PropertyState_DIRECT_VALUE;     // so this value will properly be stored
    4496             :                             }
    4497             : 
    4498           0 :                             if ( seqAdjustmentValues[ 1 ].State == com::sun::star::beans::PropertyState_DIRECT_VALUE )
    4499             :                             {
    4500           0 :                                 seqAdjustmentValues[ 1 ].Value >>= fNumber;
    4501           0 :                                 nStartAngle = NormAngle360( - (sal_Int32)fNumber * 100 );
    4502             :                             }
    4503             :                             else
    4504             :                             {
    4505           0 :                                 fNumber = 0.0;
    4506           0 :                                 seqAdjustmentValues[ 1 ].Value <<= fNumber;
    4507           0 :                                 seqAdjustmentValues[ 1 ].State = com::sun::star::beans::PropertyState_DIRECT_VALUE;
    4508             :                             }
    4509             : 
    4510           0 :                             PropertyValue aPropVal;
    4511           0 :                             aPropVal.Name = sAdjustmentValues;
    4512           0 :                             aPropVal.Value <<= seqAdjustmentValues;
    4513           0 :                             aGeometryItem.SetPropertyValue( aPropVal );     // storing the angle attribute
    4514             :                         }
    4515           0 :                         if ( nStartAngle != nEndAngle )
    4516             :                         {
    4517           0 :                             XPolygon aXPoly( aPolyBoundRect.Center(), aPolyBoundRect.GetWidth() / 2, aPolyBoundRect.GetHeight() / 2,
    4518           0 :                                 (sal_uInt16)nStartAngle / 10, (sal_uInt16)nEndAngle / 10, true );
    4519           0 :                             Rectangle aPolyPieRect( aXPoly.GetBoundRect() );
    4520             : 
    4521           0 :                             double  fYScale = 0.0, fXScale = 0.0;
    4522             :                             double  fYOfs, fXOfs;
    4523             : 
    4524           0 :                             Point aP( aObjData.aBoundRect.Center() );
    4525           0 :                             Size aS( aObjData.aBoundRect.GetSize() );
    4526           0 :                             aP.X() -= aS.Width() / 2;
    4527           0 :                             aP.Y() -= aS.Height() / 2;
    4528           0 :                             Rectangle aLogicRect( aP, aS );
    4529             : 
    4530           0 :                             fYOfs = fXOfs = 0.0;
    4531             : 
    4532           0 :                             if ( aPolyBoundRect.GetWidth() && aPolyPieRect.GetWidth() )
    4533             :                             {
    4534           0 :                                 fXScale = (double)aLogicRect.GetWidth() / (double)aPolyPieRect.GetWidth();
    4535           0 :                                 if ( nSpFlags & SP_FFLIPH )
    4536           0 :                                     fXOfs = ( (double)aPolyPieRect.Right() - (double)aPolyBoundRect.Right() ) * fXScale;
    4537             :                                 else
    4538           0 :                                     fXOfs = ( (double)aPolyBoundRect.Left() - (double)aPolyPieRect.Left() ) * fXScale;
    4539             :                             }
    4540           0 :                             if ( aPolyBoundRect.GetHeight() && aPolyPieRect.GetHeight() )
    4541             :                             {
    4542           0 :                                 fYScale = (double)aLogicRect.GetHeight() / (double)aPolyPieRect.GetHeight();
    4543           0 :                                 if ( nSpFlags & SP_FFLIPV )
    4544           0 :                                     fYOfs = ( (double)aPolyPieRect.Bottom() - (double)aPolyBoundRect.Bottom() ) * fYScale;
    4545             :                                 else
    4546           0 :                                     fYOfs = ((double)aPolyBoundRect.Top() - (double)aPolyPieRect.Top() ) * fYScale;
    4547             :                             }
    4548             : 
    4549           0 :                             if ( aPolyPieRect.GetWidth() )
    4550           0 :                                 fXScale = (double)aPolyBoundRect.GetWidth() / (double)aPolyPieRect.GetWidth();
    4551           0 :                             if ( aPolyPieRect.GetHeight() )
    4552           0 :                                 fYScale = (double)aPolyBoundRect.GetHeight() / (double)aPolyPieRect.GetHeight();
    4553             : 
    4554           0 :                             Rectangle aOldBoundRect( aObjData.aBoundRect );
    4555           0 :                             aObjData.aBoundRect = Rectangle( Point( aLogicRect.Left() + (sal_Int32)fXOfs, aLogicRect.Top() + (sal_Int32)fYOfs ),
    4556           0 :                                  Size( (sal_Int32)( aLogicRect.GetWidth() * fXScale ), (sal_Int32)( aLogicRect.GetHeight() * fYScale ) ) );
    4557             : 
    4558             :                             // creating the text frame -> scaling into (0,0),(21600,21600) destination coordinate system
    4559           0 :                             double fTextFrameScaleX = (double)21600 / (double)aPolyBoundRect.GetWidth();
    4560           0 :                             double fTextFrameScaleY = (double)21600 / (double)aPolyBoundRect.GetHeight();
    4561           0 :                             sal_Int32 nLeft  = (sal_Int32)(( aPolyPieRect.Left()  - aPolyBoundRect.Left() ) * fTextFrameScaleX );
    4562           0 :                             sal_Int32 nTop   = (sal_Int32)(( aPolyPieRect.Top()   - aPolyBoundRect.Top() )  * fTextFrameScaleY );
    4563           0 :                             sal_Int32 nRight = (sal_Int32)(( aPolyPieRect.Right() - aPolyBoundRect.Left() ) * fTextFrameScaleX );
    4564           0 :                             sal_Int32 nBottom= (sal_Int32)(( aPolyPieRect.Bottom()- aPolyBoundRect.Top() )  * fTextFrameScaleY );
    4565           0 :                             com::sun::star::uno::Sequence< com::sun::star::drawing::EnhancedCustomShapeTextFrame > aTextFrame( 1 );
    4566           0 :                             EnhancedCustomShape2d::SetEnhancedCustomShapeParameter( aTextFrame[ 0 ].TopLeft.First,     nLeft );
    4567           0 :                             EnhancedCustomShape2d::SetEnhancedCustomShapeParameter( aTextFrame[ 0 ].TopLeft.Second,    nTop );
    4568           0 :                             EnhancedCustomShape2d::SetEnhancedCustomShapeParameter( aTextFrame[ 0 ].BottomRight.First, nRight );
    4569           0 :                             EnhancedCustomShape2d::SetEnhancedCustomShapeParameter( aTextFrame[ 0 ].BottomRight.Second,nBottom );
    4570           0 :                             PropertyValue aProp;
    4571           0 :                             aProp.Name = sTextFrames;
    4572           0 :                             aProp.Value <<= aTextFrame;
    4573           0 :                             aGeometryItem.SetPropertyValue( sPath, aProp );
    4574             : 
    4575             :                             // sj: taking care of the different rotation points, since the new arc is having a bigger snaprect
    4576           0 :                             if ( mnFix16Angle )
    4577             :                             {
    4578           0 :                                 sal_Int32 nAngle = mnFix16Angle;
    4579           0 :                                 if ( nSpFlags & SP_FFLIPH )
    4580           0 :                                     nAngle = 36000 - nAngle;
    4581           0 :                                 if ( nSpFlags & SP_FFLIPV )
    4582           0 :                                     nAngle = -nAngle;
    4583           0 :                                 double a = nAngle * F_PI18000;
    4584           0 :                                 double ss = sin( a );
    4585           0 :                                 double cc = cos( a );
    4586           0 :                                 Point aP1( aOldBoundRect.TopLeft() );
    4587           0 :                                 Point aC1( aObjData.aBoundRect.Center() );
    4588           0 :                                 Point aP2( aOldBoundRect.TopLeft() );
    4589           0 :                                 Point aC2( aOldBoundRect.Center() );
    4590           0 :                                 RotatePoint( aP1, aC1, ss, cc );
    4591           0 :                                 RotatePoint( aP2, aC2, ss, cc );
    4592           0 :                                 aObjData.aBoundRect.Move( aP2.X() - aP1.X(), aP2.Y() - aP1.Y() );
    4593           0 :                             }
    4594             :                         }
    4595           0 :                         static_cast<SdrObjCustomShape*>(pRet)->SetMergedItem( aGeometryItem );
    4596           0 :                         static_cast<SdrObjCustomShape*>(pRet)->MergeDefaultAttributes();
    4597             : 
    4598             :                         // now setting a new name, so the above correction is only done once when importing from ms
    4599           0 :                         SdrCustomShapeGeometryItem aGeoName( static_cast<const SdrCustomShapeGeometryItem&>(static_cast<SdrObjCustomShape*>(pRet)->GetMergedItem( SDRATTR_CUSTOMSHAPE_GEOMETRY ) ) );
    4600           0 :                         const OUString sType( "Type" );
    4601           0 :                         const OUString sName( "mso-spt100" );
    4602           0 :                         PropertyValue aPropVal;
    4603           0 :                         aPropVal.Name = sType;
    4604           0 :                         aPropVal.Value <<= sName;
    4605           0 :                         aGeoName.SetPropertyValue( aPropVal );
    4606           0 :                         static_cast<SdrObjCustomShape*>(pRet)->SetMergedItem( aGeoName );
    4607             :                     }
    4608             :                     else
    4609        1806 :                         static_cast<SdrObjCustomShape*>(pRet)->MergeDefaultAttributes();
    4610             : 
    4611        1806 :                     pRet->SetSnapRect( aObjData.aBoundRect );
    4612        1806 :                     EnhancedCustomShape2d aCustomShape2d( pRet );
    4613        1806 :                     aTextRect = aCustomShape2d.GetTextRect();
    4614             : 
    4615        1806 :                     if( bIsConnector )
    4616             :                     {
    4617          64 :                         if( nObjectRotation )
    4618             :                         {
    4619          10 :                             double a = nObjectRotation * nPi180;
    4620          10 :                             pRet->NbcRotate( aObjData.aBoundRect.Center(), nObjectRotation, sin( a ), cos( a ) );
    4621             :                         }
    4622             :                         // mirrored horizontally?
    4623          64 :                         if ( nSpFlags & SP_FFLIPH )
    4624             :                         {
    4625           4 :                             Rectangle aBndRect( pRet->GetSnapRect() );
    4626           4 :                             Point aTop( ( aBndRect.Left() + aBndRect.Right() ) >> 1, aBndRect.Top() );
    4627           4 :                             Point aBottom( aTop.X(), aTop.Y() + 1000 );
    4628           4 :                             pRet->NbcMirror( aTop, aBottom );
    4629             :                         }
    4630             :                         // mirrored vertically?
    4631          64 :                         if ( nSpFlags & SP_FFLIPV )
    4632             :                         {
    4633           4 :                             Rectangle aBndRect( pRet->GetSnapRect() );
    4634           4 :                             Point aLeft( aBndRect.Left(), ( aBndRect.Top() + aBndRect.Bottom() ) >> 1 );
    4635           4 :                             Point aRight( aLeft.X() + 1000, aLeft.Y() );
    4636           4 :                             pRet->NbcMirror( aLeft, aRight );
    4637             :                         }
    4638          64 :                         basegfx::B2DPolyPolygon aPoly( static_cast<SdrObjCustomShape*>(pRet)->GetLineGeometry( true ) );
    4639          64 :                         SdrObject::Free( pRet );
    4640             : 
    4641          64 :                         pRet = new SdrEdgeObj();
    4642          64 :                         ApplyAttributes( rSt, aSet, aObjData );
    4643          64 :                         pRet->SetLogicRect( aObjData.aBoundRect );
    4644          64 :                         pRet->SetMergedItemSet(aSet);
    4645             : 
    4646             :                         // connectors
    4647          64 :                         MSO_ConnectorStyle eConnectorStyle = (MSO_ConnectorStyle)GetPropertyValue( DFF_Prop_cxstyle, mso_cxstyleStraight );
    4648             : 
    4649          64 :                         static_cast<SdrEdgeObj*>(pRet)->ConnectToNode(true, NULL);
    4650          64 :                         static_cast<SdrEdgeObj*>(pRet)->ConnectToNode(false, NULL);
    4651             : 
    4652          64 :                         Point aPoint1( aObjData.aBoundRect.TopLeft() );
    4653          64 :                         Point aPoint2( aObjData.aBoundRect.BottomRight() );
    4654             : 
    4655             :                         // pay attention to the rotations
    4656          64 :                         if ( nObjectRotation )
    4657             :                         {
    4658          10 :                             double a = nObjectRotation * nPi180;
    4659          10 :                             Point aCenter( aObjData.aBoundRect.Center() );
    4660          10 :                             double ss = sin(a);
    4661          10 :                             double cc = cos(a);
    4662             : 
    4663          10 :                             RotatePoint(aPoint1, aCenter, ss, cc);
    4664          10 :                             RotatePoint(aPoint2, aCenter, ss, cc);
    4665             : 
    4666             :                             // #i120437# reset rotation, it is part of the path and shall not be applied again
    4667          10 :                             nObjectRotation = 0;
    4668             :                         }
    4669             : 
    4670             :                         // rotate/mirror line within the area as we need it
    4671          64 :                         if ( nSpFlags & SP_FFLIPH )
    4672             :                         {
    4673           4 :                             sal_Int32 n = aPoint1.X();
    4674           4 :                             aPoint1.X() = aPoint2.X();
    4675           4 :                             aPoint2.X() = n;
    4676             : 
    4677             :                             // #i120437# reset hor filp
    4678           4 :                             nSpFlags &= ~SP_FFLIPH;
    4679             :                         }
    4680          64 :                         if ( nSpFlags & SP_FFLIPV )
    4681             :                         {
    4682           4 :                             sal_Int32 n = aPoint1.Y();
    4683           4 :                             aPoint1.Y() = aPoint2.Y();
    4684           4 :                             aPoint2.Y() = n;
    4685             : 
    4686             :                             // #i120437# reset ver filp
    4687           4 :                             nSpFlags &= ~SP_FFLIPV;
    4688             :                         }
    4689             : 
    4690          64 :                         pRet->NbcSetPoint(aPoint1, 0L); // start point
    4691          64 :                         pRet->NbcSetPoint(aPoint2, 1L); // endpoint
    4692             : 
    4693             :                         sal_Int32 n1HorzDist, n1VertDist, n2HorzDist, n2VertDist;
    4694          64 :                         n1HorzDist = n1VertDist = n2HorzDist = n2VertDist = 0;
    4695          64 :                         switch( eConnectorStyle )
    4696             :                         {
    4697             :                             case mso_cxstyleBent:
    4698             :                             {
    4699           8 :                                 aSet.Put( SdrEdgeKindItem( SDREDGE_ORTHOLINES ) );
    4700           8 :                                 n1HorzDist = n1VertDist = n2HorzDist = n2VertDist = 630;
    4701             :                             }
    4702           8 :                             break;
    4703             :                             case mso_cxstyleCurved:
    4704           4 :                                 aSet.Put( SdrEdgeKindItem( SDREDGE_BEZIER ) );
    4705           4 :                             break;
    4706             :                             default: // mso_cxstyleStraight || mso_cxstyleNone
    4707          52 :                                 aSet.Put( SdrEdgeKindItem( SDREDGE_ONELINE ) );
    4708          52 :                             break;
    4709             :                         }
    4710          64 :                         aSet.Put( SdrEdgeNode1HorzDistItem( n1HorzDist ) );
    4711          64 :                         aSet.Put( SdrEdgeNode1VertDistItem( n1VertDist ) );
    4712          64 :                         aSet.Put( SdrEdgeNode2HorzDistItem( n2HorzDist ) );
    4713          64 :                         aSet.Put( SdrEdgeNode2VertDistItem( n2VertDist ) );
    4714             : 
    4715          64 :                         static_cast<SdrEdgeObj*>(pRet)->SetEdgeTrackPath( aPoly );
    4716          64 :                         pRet->SetMergedItemSet( aSet );
    4717             :                     }
    4718        1806 :                     if ( aObjData.eShapeType == mso_sptLine )
    4719             :                     {
    4720           0 :                         pRet->SetMergedItemSet(aSet);
    4721           0 :                         static_cast<SdrObjCustomShape*>(pRet)->MergeDefaultAttributes();
    4722        1806 :                     }
    4723             :                 }
    4724             :             }
    4725             : 
    4726        3374 :             if ( pRet )
    4727             :             {
    4728        3218 :                 if( nObjectRotation )
    4729             :                 {
    4730           6 :                     double a = nObjectRotation * nPi180;
    4731           6 :                     pRet->NbcRotate( aObjData.aBoundRect.Center(), nObjectRotation, sin( a ), cos( a ) );
    4732             :                 }
    4733             :                 // mirrored horizontally?
    4734        3218 :                 if ( nSpFlags & SP_FFLIPH )
    4735             :                 {
    4736          16 :                     Rectangle aBndRect( pRet->GetSnapRect() );
    4737          16 :                     Point aTop( ( aBndRect.Left() + aBndRect.Right() ) >> 1, aBndRect.Top() );
    4738          16 :                     Point aBottom( aTop.X(), aTop.Y() + 1000 );
    4739          16 :                     pRet->NbcMirror( aTop, aBottom );
    4740             :                 }
    4741             :                 // mirrored vertically?
    4742        3218 :                 if ( nSpFlags & SP_FFLIPV )
    4743             :                 {
    4744          20 :                     Rectangle aBndRect( pRet->GetSnapRect() );
    4745          20 :                     Point aLeft( aBndRect.Left(), ( aBndRect.Top() + aBndRect.Bottom() ) >> 1 );
    4746          20 :                     Point aRight( aLeft.X() + 1000, aLeft.Y() );
    4747          20 :                     pRet->NbcMirror( aLeft, aRight );
    4748             :                 }
    4749        3374 :             }
    4750             :         }
    4751             :     }
    4752             : 
    4753             :     // #i51348# #118052# name of the shape
    4754        3722 :     if( pRet )
    4755             :     {
    4756        3320 :         OUString aObjName = GetPropertyString( DFF_Prop_wzName, rSt );
    4757        3320 :         if( !aObjName.isEmpty() )
    4758         142 :             pRet->SetName( aObjName );
    4759             :     }
    4760             : 
    4761             :     pRet =
    4762        3722 :         ProcessObj( rSt, aObjData, pClientData, aTextRect, pRet);
    4763             : 
    4764        3722 :     if ( pRet )
    4765             :     {
    4766        3398 :         sal_Int32 nGroupProperties( GetPropertyValue( DFF_Prop_fPrint ) );
    4767        3398 :         pRet->SetVisible( ( nGroupProperties & 2 ) == 0 );
    4768        3398 :         pRet->SetPrintable( ( nGroupProperties & 1 ) != 0 );
    4769             :     }
    4770             : 
    4771             :     //Import alt text as description
    4772        3722 :     if ( pRet && SeekToContent( DFF_Prop_wzDescription, rSt ) )
    4773             :     {
    4774           6 :         OUString aAltText = MSDFFReadZString(rSt, GetPropertyValue(DFF_Prop_wzDescription), true);
    4775           6 :         pRet->SetDescription( aAltText );
    4776             :     }
    4777             : 
    4778        3722 :     return pRet;
    4779             : }
    4780             : 
    4781         100 : Rectangle SvxMSDffManager::GetGlobalChildAnchor( const DffRecordHeader& rHd, SvStream& rSt, Rectangle& aClientRect )
    4782             : {
    4783         100 :     Rectangle aChildAnchor;
    4784         100 :     if (!rHd.SeekToContent(rSt))
    4785           0 :         return aChildAnchor;
    4786             : 
    4787         100 :     bool bIsClientRectRead = false;
    4788        2440 :     while ( ( rSt.GetError() == 0 ) && ( rSt.Tell() < rHd.GetRecEndFilePos() ) )
    4789             :     {
    4790        2240 :         DffRecordHeader aShapeHd;
    4791        2240 :         ReadDffRecordHeader( rSt, aShapeHd );
    4792        2242 :         if ( ( aShapeHd.nRecType == DFF_msofbtSpContainer ) ||
    4793           2 :                 ( aShapeHd.nRecType == DFF_msofbtSpgrContainer ) )
    4794             :         {
    4795        2240 :             DffRecordHeader aShapeHd2( aShapeHd );
    4796        2240 :             if ( aShapeHd.nRecType == DFF_msofbtSpgrContainer )
    4797           2 :                 ReadDffRecordHeader( rSt, aShapeHd2 );
    4798        9558 :             while( ( rSt.GetError() == 0 ) && ( rSt.Tell() < aShapeHd2.GetRecEndFilePos() ) )
    4799             :             {
    4800        7318 :                 DffRecordHeader aShapeAtom;
    4801        7318 :                 ReadDffRecordHeader( rSt, aShapeAtom );
    4802             : 
    4803        7318 :                 if ( aShapeAtom.nRecType == DFF_msofbtClientAnchor )
    4804             :                 {
    4805         100 :                     if ( GetSvxMSDffSettings() & SVXMSDFF_SETTINGS_IMPORT_PPT )
    4806             :                     {
    4807             :                         sal_Int32 l, t, r, b;
    4808          70 :                         if ( aShapeAtom.nRecLen == 16 )
    4809             :                         {
    4810           0 :                             rSt.ReadInt32( l ).ReadInt32( t ).ReadInt32( r ).ReadInt32( b );
    4811             :                         }
    4812             :                         else
    4813             :                         {
    4814             :                             sal_Int16 ls, ts, rs, bs;
    4815          70 :                             rSt.ReadInt16( ts ).ReadInt16( ls ).ReadInt16( rs ).ReadInt16( bs ); // the order of coordinates is a bit strange...
    4816          70 :                             l = ls, t = ts, r = rs, b = bs;
    4817             :                         }
    4818          70 :                         Scale( l );
    4819          70 :                         Scale( t );
    4820          70 :                         Scale( r );
    4821          70 :                         Scale( b );
    4822          70 :                         if ( bIsClientRectRead )
    4823             :                         {
    4824           0 :                             Rectangle aChild( l, t, r, b );
    4825           0 :                             aChildAnchor.Union( aChild );
    4826             :                         }
    4827             :                         else
    4828             :                         {
    4829          70 :                             aClientRect = Rectangle( l, t, r, b );
    4830          70 :                             bIsClientRectRead = true;
    4831             :                         }
    4832             :                     }
    4833        2340 :                     break;
    4834             :                 }
    4835        7218 :                 else if ( aShapeAtom.nRecType == DFF_msofbtChildAnchor )
    4836             :                 {
    4837             :                     sal_Int32 l, o, r, u;
    4838        2140 :                     rSt.ReadInt32( l ).ReadInt32( o ).ReadInt32( r ).ReadInt32( u );
    4839        2140 :                     Scale( l );
    4840        2140 :                     Scale( o );
    4841        2140 :                     Scale( r );
    4842        2140 :                     Scale( u );
    4843        2140 :                     Rectangle aChild( l, o, r, u );
    4844        2140 :                     aChildAnchor.Union( aChild );
    4845        2140 :                     break;
    4846             :                 }
    4847        5078 :                 if (!aShapeAtom.SeekToEndOfRecord(rSt))
    4848           0 :                     break;
    4849             :             }
    4850             :         }
    4851        2240 :         if (!aShapeHd.SeekToEndOfRecord(rSt))
    4852           0 :             break;
    4853             :     }
    4854         100 :     return aChildAnchor;
    4855             : }
    4856             : 
    4857           2 : void SvxMSDffManager::GetGroupAnchors( const DffRecordHeader& rHd, SvStream& rSt,
    4858             :                             Rectangle& rGroupClientAnchor, Rectangle& rGroupChildAnchor,
    4859             :                                 const Rectangle& rClientRect, const Rectangle& rGlobalChildRect )
    4860             : {
    4861           2 :     if (!rHd.SeekToContent(rSt))
    4862           2 :         return;
    4863             : 
    4864           2 :     bool bFirst = true;
    4865           2 :     DffRecordHeader aShapeHd;
    4866           2 :     while ( ( rSt.GetError() == 0 ) && ( rSt.Tell() < rHd.GetRecEndFilePos() ) )
    4867             :     {
    4868          28 :         ReadDffRecordHeader( rSt, aShapeHd );
    4869          28 :         if ( ( aShapeHd.nRecType == DFF_msofbtSpContainer ) ||
    4870           0 :                 ( aShapeHd.nRecType == DFF_msofbtSpgrContainer ) )
    4871             :         {
    4872          28 :             DffRecordHeader aShapeHd2( aShapeHd );
    4873          28 :             if ( aShapeHd.nRecType == DFF_msofbtSpgrContainer )
    4874           0 :                 ReadDffRecordHeader( rSt, aShapeHd2 );
    4875         140 :             while( ( rSt.GetError() == 0 ) && ( rSt.Tell() < aShapeHd2.GetRecEndFilePos() ) )
    4876             :             {
    4877         112 :                 DffRecordHeader aShapeAtom;
    4878         112 :                 ReadDffRecordHeader( rSt, aShapeAtom );
    4879         112 :                 if ( aShapeAtom.nRecType == DFF_msofbtChildAnchor )
    4880             :                 {
    4881             :                     sal_Int32 l, o, r, u;
    4882          28 :                     rSt.ReadInt32( l ).ReadInt32( o ).ReadInt32( r ).ReadInt32( u );
    4883          28 :                     Scale( l );
    4884          28 :                     Scale( o );
    4885          28 :                     Scale( r );
    4886          28 :                     Scale( u );
    4887          28 :                     Rectangle aChild( l, o, r, u );
    4888             : 
    4889          28 :                     if ( bFirst )
    4890             :                     {
    4891           2 :                         if ( !rGlobalChildRect.IsEmpty() && !rClientRect.IsEmpty() && rGlobalChildRect.GetWidth() && rGlobalChildRect.GetHeight() )
    4892             :                         {
    4893           2 :                             double fWidth = r - l;
    4894           2 :                             double fHeight= u - o;
    4895           2 :                             double fXScale = (double)rClientRect.GetWidth() / (double)rGlobalChildRect.GetWidth();
    4896           2 :                             double fYScale = (double)rClientRect.GetHeight() / (double)rGlobalChildRect.GetHeight();
    4897           2 :                             double fl = ( ( l - rGlobalChildRect.Left() ) * fXScale ) + rClientRect.Left();
    4898           2 :                             double fo = ( ( o - rGlobalChildRect.Top()  ) * fYScale ) + rClientRect.Top();
    4899           2 :                             fWidth *= fXScale;
    4900           2 :                             fHeight *= fYScale;
    4901           2 :                             rGroupClientAnchor = Rectangle( Point( (sal_Int32)fl, (sal_Int32)fo ), Size( (sal_Int32)( fWidth + 1 ), (sal_Int32)( fHeight + 1 ) ) );
    4902             :                         }
    4903           2 :                         bFirst = false;
    4904             :                     }
    4905             :                     else
    4906          26 :                         rGroupChildAnchor.Union( aChild );
    4907          28 :                     break;
    4908             :                 }
    4909          84 :                 if (!aShapeAtom.SeekToEndOfRecord(rSt))
    4910           0 :                     break;
    4911             :             }
    4912             :         }
    4913          28 :         if (!aShapeHd.SeekToEndOfRecord(rSt))
    4914           0 :             break;
    4915             :     }
    4916             : }
    4917             : 
    4918           0 : SdrObject* SvxMSDffManager::ProcessObj(SvStream& rSt,
    4919             :                                        DffObjData& rObjData,
    4920             :                                        void* pData,
    4921             :                                        Rectangle& rTextRect,
    4922             :                                        SdrObject* pObj
    4923             :                                        )
    4924             : {
    4925           0 :     if( !rTextRect.IsEmpty() )
    4926             :     {
    4927           0 :         SvxMSDffImportData& rImportData = *(SvxMSDffImportData*)pData;
    4928           0 :         SvxMSDffImportRec* pImpRec = new SvxMSDffImportRec;
    4929           0 :         bool bDeleteImpRec = true;
    4930           0 :         SvxMSDffImportRec* pTextImpRec = pImpRec;
    4931           0 :         bool bDeleteTextImpRec = false;
    4932             : 
    4933             :         // fill Import Record with data
    4934           0 :         pImpRec->nShapeId   = rObjData.nShapeId;
    4935           0 :         pImpRec->eShapeType = rObjData.eShapeType;
    4936             : 
    4937             :         MSO_WrapMode eWrapMode( (MSO_WrapMode)GetPropertyValue(
    4938             :                                                             DFF_Prop_WrapText,
    4939           0 :                                                             mso_wrapSquare ) );
    4940             :         rObjData.bClientAnchor = maShapeRecords.SeekToContent( rSt,
    4941             :                                             DFF_msofbtClientAnchor,
    4942           0 :                                             SEEK_FROM_CURRENT_AND_RESTART );
    4943           0 :         if( rObjData.bClientAnchor )
    4944             :             ProcessClientAnchor( rSt,
    4945           0 :                     maShapeRecords.Current()->nRecLen,
    4946           0 :                     pImpRec->pClientAnchorBuffer, pImpRec->nClientAnchorLen );
    4947             : 
    4948             :         rObjData.bClientData = maShapeRecords.SeekToContent( rSt,
    4949             :                                             DFF_msofbtClientData,
    4950           0 :                                             SEEK_FROM_CURRENT_AND_RESTART );
    4951           0 :         if( rObjData.bClientData )
    4952             :             ProcessClientData( rSt,
    4953           0 :                     maShapeRecords.Current()->nRecLen,
    4954           0 :                     pImpRec->pClientDataBuffer, pImpRec->nClientDataLen );
    4955             : 
    4956             : 
    4957             :         // process user (== Winword) defined parameters in 0xF122 record
    4958           0 :         if(    maShapeRecords.SeekToContent( rSt,
    4959             :                                              DFF_msofbtUDefProp,
    4960           0 :                                              SEEK_FROM_CURRENT_AND_RESTART )
    4961           0 :             && maShapeRecords.Current()->nRecLen )
    4962             :         {
    4963           0 :             sal_uInt32  nBytesLeft = maShapeRecords.Current()->nRecLen;
    4964             :             sal_uInt32  nUDData;
    4965             :             sal_uInt16  nPID;
    4966           0 :             while( 5 < nBytesLeft )
    4967             :             {
    4968           0 :                 rSt.ReadUInt16( nPID );
    4969           0 :                 if ( rSt.GetError() != 0 )
    4970           0 :                     break;
    4971           0 :                 rSt.ReadUInt32( nUDData );
    4972           0 :                 switch( nPID )
    4973             :                 {
    4974           0 :                     case 0x038F: pImpRec->nXAlign = nUDData; break;
    4975             :                     case 0x0390:
    4976           0 :                         if (pImpRec->pXRelTo)
    4977           0 :                             delete pImpRec->pXRelTo;
    4978           0 :                         pImpRec->pXRelTo = new sal_uInt32;
    4979           0 :                         *(pImpRec->pXRelTo) = nUDData;
    4980           0 :                         break;
    4981           0 :                     case 0x0391: pImpRec->nYAlign = nUDData; break;
    4982             :                     case 0x0392:
    4983           0 :                         if (pImpRec->pYRelTo)
    4984           0 :                             delete pImpRec->pYRelTo;
    4985           0 :                         pImpRec->pYRelTo = new sal_uInt32;
    4986           0 :                         *(pImpRec->pYRelTo) = nUDData;
    4987           0 :                         break;
    4988           0 :                     case 0x03BF: pImpRec->nLayoutInTableCell = nUDData; break;
    4989             :                     case 0x0393:
    4990             :                     // This seems to correspond to o:hrpct from .docx (even including
    4991             :                     // the difference that it's in 0.1% even though the .docx spec
    4992             :                     // says it's in 1%).
    4993           0 :                         pImpRec->relativeHorizontalWidth = nUDData;
    4994           0 :                         break;
    4995             :                     case 0x0394:
    4996             :                     // And this is really just a guess, but a mere presence of this
    4997             :                     // flag makes a horizontal rule be as wide as the page (unless
    4998             :                     // overridden by something), so it probably matches o:hr from .docx.
    4999           0 :                         pImpRec->isHorizontalRule = true;
    5000           0 :                         break;
    5001             :                 }
    5002           0 :                 if ( rSt.GetError() != 0 )
    5003           0 :                     break;
    5004           0 :                 nBytesLeft  -= 6;
    5005             :             }
    5006             :         }
    5007             : 
    5008             :         //  text frame, also Title or Outline
    5009           0 :         SdrObject*  pOrgObj  = pObj;
    5010           0 :         SdrRectObj* pTextObj = 0;
    5011           0 :         sal_uInt32 nTextId = GetPropertyValue( DFF_Prop_lTxid, 0 );
    5012           0 :         if( nTextId )
    5013             :         {
    5014           0 :             SfxItemSet aSet( pSdrModel->GetItemPool() );
    5015             : 
    5016             :             //Originally anything that as a mso_sptTextBox was created as a
    5017             :             //textbox, this was changed for #88277# to be created as a simple
    5018             :             //rect to keep impress happy. For the rest of us we'd like to turn
    5019             :             //it back into a textbox again.
    5020           0 :             bool bTextFrame = (pImpRec->eShapeType == mso_sptTextBox);
    5021           0 :             if (!bTextFrame)
    5022             :             {
    5023             :                 //Either
    5024             :                 //a) it's a simple text object or
    5025             :                 //b) it's a rectangle with text and square wrapping.
    5026             :                 bTextFrame =
    5027             :                 (
    5028           0 :                     (pImpRec->eShapeType == mso_sptTextSimple) ||
    5029             :                     (
    5030           0 :                         (pImpRec->eShapeType == mso_sptRectangle)
    5031           0 :                         && (eWrapMode == mso_wrapSquare)
    5032           0 :                         && ShapeHasText(pImpRec->nShapeId, rObjData.rSpHd.GetRecBegFilePos() )
    5033             :                     )
    5034           0 :                 );
    5035             :             }
    5036             : 
    5037           0 :             if (bTextFrame)
    5038             :             {
    5039           0 :                 SdrObject::Free( pObj );
    5040           0 :                 pObj = pOrgObj = 0;
    5041             :             }
    5042             : 
    5043             :             // Distance of Textbox to it's surrounding Customshape
    5044           0 :             sal_Int32 nTextLeft = GetPropertyValue( DFF_Prop_dxTextLeft, 91440L);
    5045           0 :             sal_Int32 nTextRight = GetPropertyValue( DFF_Prop_dxTextRight, 91440L );
    5046           0 :             sal_Int32 nTextTop = GetPropertyValue( DFF_Prop_dyTextTop, 45720L  );
    5047           0 :             sal_Int32 nTextBottom = GetPropertyValue( DFF_Prop_dyTextBottom, 45720L );
    5048             : 
    5049           0 :             ScaleEmu( nTextLeft );
    5050           0 :             ScaleEmu( nTextRight );
    5051           0 :             ScaleEmu( nTextTop );
    5052           0 :             ScaleEmu( nTextBottom );
    5053             : 
    5054           0 :             sal_Int32 nTextRotationAngle=0;
    5055           0 :             bool bVerticalText = false;
    5056           0 :             if ( IsProperty( DFF_Prop_txflTextFlow ) )
    5057             :             {
    5058             :                 MSO_TextFlow eTextFlow = (MSO_TextFlow)(GetPropertyValue(
    5059           0 :                     DFF_Prop_txflTextFlow) & 0xFFFF);
    5060           0 :                 switch( eTextFlow )
    5061             :                 {
    5062             :                     case mso_txflBtoT:
    5063           0 :                         nTextRotationAngle = 9000;
    5064           0 :                     break;
    5065             :                     case mso_txflVertN:
    5066             :                     case mso_txflTtoBN:
    5067           0 :                         nTextRotationAngle = 27000;
    5068           0 :                         break;
    5069             :                     case mso_txflTtoBA:
    5070           0 :                         bVerticalText = true;
    5071           0 :                     break;
    5072             :                     case mso_txflHorzA:
    5073           0 :                         bVerticalText = true;
    5074           0 :                         nTextRotationAngle = 9000;
    5075             :                     case mso_txflHorzN:
    5076             :                     default :
    5077           0 :                         break;
    5078             :                 }
    5079             :             }
    5080             : 
    5081           0 :             if (nTextRotationAngle)
    5082             :             {
    5083           0 :                 while (nTextRotationAngle > 360000)
    5084           0 :                     nTextRotationAngle-=9000;
    5085           0 :                 switch (nTextRotationAngle)
    5086             :                 {
    5087             :                     case 9000:
    5088             :                         {
    5089           0 :                             long nWidth = rTextRect.GetWidth();
    5090           0 :                             rTextRect.Right() = rTextRect.Left() + rTextRect.GetHeight();
    5091           0 :                             rTextRect.Bottom() = rTextRect.Top() + nWidth;
    5092             : 
    5093           0 :                             sal_Int32 nOldTextLeft = nTextLeft;
    5094           0 :                             sal_Int32 nOldTextRight = nTextRight;
    5095           0 :                             sal_Int32 nOldTextTop = nTextTop;
    5096           0 :                             sal_Int32 nOldTextBottom = nTextBottom;
    5097             : 
    5098           0 :                             nTextLeft = nOldTextBottom;
    5099           0 :                             nTextRight = nOldTextTop;
    5100           0 :                             nTextTop = nOldTextLeft;
    5101           0 :                             nTextBottom = nOldTextRight;
    5102             :                         }
    5103           0 :                         break;
    5104             :                     case 27000:
    5105             :                         {
    5106           0 :                             long nWidth = rTextRect.GetWidth();
    5107           0 :                             rTextRect.Right() = rTextRect.Left() + rTextRect.GetHeight();
    5108           0 :                             rTextRect.Bottom() = rTextRect.Top() + nWidth;
    5109             : 
    5110           0 :                             sal_Int32 nOldTextLeft = nTextLeft;
    5111           0 :                             sal_Int32 nOldTextRight = nTextRight;
    5112           0 :                             sal_Int32 nOldTextTop = nTextTop;
    5113           0 :                             sal_Int32 nOldTextBottom = nTextBottom;
    5114             : 
    5115           0 :                             nTextLeft = nOldTextTop;
    5116           0 :                             nTextRight = nOldTextBottom;
    5117           0 :                             nTextTop = nOldTextRight;
    5118           0 :                             nTextBottom = nOldTextLeft;
    5119             :                         }
    5120           0 :                         break;
    5121             :                 }
    5122             :             }
    5123             : 
    5124           0 :             pTextObj = new SdrRectObj(OBJ_TEXT, rTextRect);
    5125           0 :             pTextImpRec = new SvxMSDffImportRec(*pImpRec);
    5126           0 :             bDeleteTextImpRec = true;
    5127             : 
    5128             :             // the vertical paragraph indents are part of the BoundRect,
    5129             :             // here we 'remove' them by calculating
    5130           0 :             Rectangle aNewRect(rTextRect);
    5131           0 :             aNewRect.Bottom() -= nTextTop + nTextBottom;
    5132           0 :             aNewRect.Right() -= nTextLeft + nTextRight;
    5133             : 
    5134             :             // Only if it's a simple textbox may Writer replace
    5135             :             // the object with a frame, otherwise
    5136           0 :             if( bTextFrame )
    5137             :             {
    5138             :                 ::boost::shared_ptr<SvxMSDffShapeInfo> const pTmpRec(
    5139           0 :                     new SvxMSDffShapeInfo(0, pImpRec->nShapeId));
    5140             : 
    5141             :                 SvxMSDffShapeInfos_ById::const_iterator const it =
    5142           0 :                     m_pShapeInfosById->find(pTmpRec);
    5143           0 :                 if (it != m_pShapeInfosById->end())
    5144             :                 {
    5145           0 :                     SvxMSDffShapeInfo& rInfo = **it;
    5146           0 :                     pTextImpRec->bReplaceByFly   = rInfo.bReplaceByFly;
    5147           0 :                 }
    5148             :             }
    5149             : 
    5150           0 :             if( !pObj )
    5151           0 :                 ApplyAttributes( rSt, aSet, rObjData );
    5152             : 
    5153           0 :             bool bFitText = false;
    5154           0 :             if (GetPropertyValue(DFF_Prop_FitTextToShape) & 2)
    5155             :             {
    5156           0 :                 aSet.Put( makeSdrTextAutoGrowHeightItem( true ) );
    5157             :                 aSet.Put( makeSdrTextMinFrameHeightItem(
    5158           0 :                     aNewRect.Bottom() - aNewRect.Top() ) );
    5159             :                 aSet.Put( makeSdrTextMinFrameWidthItem(
    5160           0 :                     aNewRect.Right() - aNewRect.Left() ) );
    5161           0 :                 bFitText = true;
    5162             :             }
    5163             :             else
    5164             :             {
    5165           0 :                 aSet.Put( makeSdrTextAutoGrowHeightItem( false ) );
    5166           0 :                 aSet.Put( makeSdrTextAutoGrowWidthItem( false ) );
    5167             :             }
    5168             : 
    5169           0 :             switch ( (MSO_WrapMode)
    5170           0 :                 GetPropertyValue( DFF_Prop_WrapText, mso_wrapSquare ) )
    5171             :             {
    5172             :                 case mso_wrapNone :
    5173           0 :                     aSet.Put( makeSdrTextAutoGrowWidthItem( true ) );
    5174           0 :                     if (bFitText)
    5175             :                     {
    5176             :                         //can't do autowidth in flys #i107184#
    5177           0 :                         pTextImpRec->bReplaceByFly = false;
    5178             :                     }
    5179           0 :                 break;
    5180             :                 case mso_wrapByPoints :
    5181           0 :                     aSet.Put( makeSdrTextContourFrameItem( true ) );
    5182           0 :                 break;
    5183           0 :                 default: break;
    5184             :             }
    5185             : 
    5186             :             // set margins at the border of the textbox
    5187           0 :             aSet.Put( makeSdrTextLeftDistItem( nTextLeft ) );
    5188           0 :             aSet.Put( makeSdrTextRightDistItem( nTextRight ) );
    5189           0 :             aSet.Put( makeSdrTextUpperDistItem( nTextTop ) );
    5190           0 :             aSet.Put( makeSdrTextLowerDistItem( nTextBottom ) );
    5191           0 :             pTextImpRec->nDxTextLeft    = nTextLeft;
    5192           0 :             pTextImpRec->nDyTextTop     = nTextTop;
    5193           0 :             pTextImpRec->nDxTextRight   = nTextRight;
    5194           0 :             pTextImpRec->nDyTextBottom  = nTextBottom;
    5195             : 
    5196             :             // read text anchor
    5197           0 :             if ( IsProperty( DFF_Prop_anchorText ) )
    5198             :             {
    5199             :                 MSO_Anchor eTextAnchor =
    5200           0 :                     (MSO_Anchor)GetPropertyValue( DFF_Prop_anchorText );
    5201             : 
    5202           0 :                 SdrTextVertAdjust eTVA = SDRTEXTVERTADJUST_CENTER;
    5203           0 :                 bool bTVASet(false);
    5204           0 :                 SdrTextHorzAdjust eTHA = SDRTEXTHORZADJUST_CENTER;
    5205           0 :                 bool bTHASet(false);
    5206             : 
    5207           0 :                 switch( eTextAnchor )
    5208             :                 {
    5209             :                     case mso_anchorTop:
    5210             :                     {
    5211           0 :                         eTVA = SDRTEXTVERTADJUST_TOP;
    5212           0 :                         bTVASet = true;
    5213             :                     }
    5214           0 :                     break;
    5215             :                     case mso_anchorTopCentered:
    5216             :                     {
    5217           0 :                         eTVA = SDRTEXTVERTADJUST_TOP;
    5218           0 :                         bTVASet = true;
    5219           0 :                         bTHASet = true;
    5220             :                     }
    5221           0 :                     break;
    5222             : 
    5223             :                     case mso_anchorMiddle:
    5224           0 :                         bTVASet = true;
    5225           0 :                     break;
    5226             :                     case mso_anchorMiddleCentered:
    5227             :                     {
    5228           0 :                         bTVASet = true;
    5229           0 :                         bTHASet = true;
    5230             :                     }
    5231           0 :                     break;
    5232             :                     case mso_anchorBottom:
    5233             :                     {
    5234           0 :                         eTVA = SDRTEXTVERTADJUST_BOTTOM;
    5235           0 :                         bTVASet = true;
    5236             :                     }
    5237           0 :                     break;
    5238             :                     case mso_anchorBottomCentered:
    5239             :                     {
    5240           0 :                         eTVA = SDRTEXTVERTADJUST_BOTTOM;
    5241           0 :                         bTVASet = true;
    5242           0 :                         bTHASet = true;
    5243             :                     }
    5244           0 :                     break;
    5245           0 :                     default : break;
    5246             :                 }
    5247             :                 // insert
    5248           0 :                 if ( bTVASet )
    5249           0 :                     aSet.Put( SdrTextVertAdjustItem( eTVA ) );
    5250           0 :                 if ( bTHASet )
    5251           0 :                     aSet.Put( SdrTextHorzAdjustItem( eTHA ) );
    5252             :             }
    5253             : 
    5254           0 :             pTextObj->SetMergedItemSet(aSet);
    5255           0 :             pTextObj->SetModel(pSdrModel);
    5256             : 
    5257           0 :             if (bVerticalText)
    5258           0 :                 pTextObj->SetVerticalWriting(true);
    5259             : 
    5260           0 :             if (nTextRotationAngle)
    5261             :             {
    5262           0 :                 long nMinWH = rTextRect.GetWidth() < rTextRect.GetHeight() ?
    5263           0 :                     rTextRect.GetWidth() : rTextRect.GetHeight();
    5264           0 :                 nMinWH /= 2;
    5265           0 :                 Point aPivot(rTextRect.TopLeft());
    5266           0 :                 aPivot.X() += nMinWH;
    5267           0 :                 aPivot.Y() += nMinWH;
    5268           0 :                 double a = nTextRotationAngle * nPi180;
    5269           0 :                 pTextObj->NbcRotate(aPivot, nTextRotationAngle, sin(a), cos(a));
    5270             :             }
    5271             : 
    5272             :             // rotate text with shape?
    5273           0 :             if ( mnFix16Angle )
    5274             :             {
    5275           0 :                 double a = mnFix16Angle * nPi180;
    5276           0 :                 pTextObj->NbcRotate( rObjData.aBoundRect.Center(), mnFix16Angle,
    5277           0 :                     sin( a ), cos( a ) );
    5278             :             }
    5279             : 
    5280           0 :             if( !pObj )
    5281             :             {
    5282           0 :                 pObj = pTextObj;
    5283             :             }
    5284             :             else
    5285             :             {
    5286           0 :                 if( pTextObj != pObj )
    5287             :                 {
    5288           0 :                     SdrObject* pGroup = new SdrObjGroup;
    5289           0 :                     pGroup->GetSubList()->NbcInsertObject( pObj );
    5290           0 :                     pGroup->GetSubList()->NbcInsertObject( pTextObj );
    5291           0 :                     if (pOrgObj == pObj)
    5292           0 :                         pOrgObj = pGroup;
    5293             :                     else
    5294           0 :                         pOrgObj = pObj;
    5295           0 :                     pObj = pGroup;
    5296             :                 }
    5297           0 :             }
    5298             :         }
    5299           0 :         else if( !pObj )
    5300             :         {
    5301             :             // simple rectangular objects are ignored by ImportObj()  :-(
    5302             :             // this is OK for Draw but not for Calc and Writer
    5303             :             // cause here these objects have a default border
    5304           0 :             pObj = new SdrRectObj(rTextRect);
    5305           0 :             pOrgObj = pObj;
    5306           0 :             pObj->SetModel( pSdrModel );
    5307           0 :             SfxItemSet aSet( pSdrModel->GetItemPool() );
    5308           0 :             ApplyAttributes( rSt, aSet, rObjData );
    5309             : 
    5310           0 :             const SfxPoolItem* pPoolItem=NULL;
    5311             :             SfxItemState eState = aSet.GetItemState( XATTR_FILLCOLOR,
    5312           0 :                                                      false, &pPoolItem );
    5313           0 :             if( SfxItemState::DEFAULT == eState )
    5314             :                 aSet.Put( XFillColorItem( OUString(),
    5315           0 :                           Color( mnDefaultColor ) ) );
    5316           0 :             pObj->SetMergedItemSet(aSet);
    5317             :         }
    5318             : 
    5319             :         //Means that fBehindDocument is set
    5320           0 :         if (GetPropertyValue(DFF_Prop_fPrint) & 0x20)
    5321           0 :             pImpRec->bDrawHell = true;
    5322             :         else
    5323           0 :             pImpRec->bDrawHell = false;
    5324           0 :         if (GetPropertyValue(DFF_Prop_fPrint) & 0x02)
    5325           0 :             pImpRec->bHidden = true;
    5326           0 :         pTextImpRec->bDrawHell  = pImpRec->bDrawHell;
    5327           0 :         pTextImpRec->bHidden = pImpRec->bHidden;
    5328           0 :         pImpRec->nNextShapeId   = GetPropertyValue( DFF_Prop_hspNext, 0 );
    5329           0 :         pTextImpRec->nNextShapeId=pImpRec->nNextShapeId;
    5330             : 
    5331           0 :         if ( nTextId )
    5332             :         {
    5333           0 :             pTextImpRec->aTextId.nTxBxS = (sal_uInt16)( nTextId >> 16 );
    5334           0 :             pTextImpRec->aTextId.nSequence = (sal_uInt16)nTextId;
    5335             :         }
    5336             : 
    5337             :         pTextImpRec->nDxWrapDistLeft = GetPropertyValue(
    5338           0 :                                     DFF_Prop_dxWrapDistLeft, 114935L ) / 635L;
    5339             :         pTextImpRec->nDyWrapDistTop = GetPropertyValue(
    5340           0 :                                     DFF_Prop_dyWrapDistTop, 0 ) / 635L;
    5341             :         pTextImpRec->nDxWrapDistRight = GetPropertyValue(
    5342           0 :                                     DFF_Prop_dxWrapDistRight, 114935L ) / 635L;
    5343             :         pTextImpRec->nDyWrapDistBottom = GetPropertyValue(
    5344           0 :                                     DFF_Prop_dyWrapDistBottom, 0 ) / 635L;
    5345             :         // 16.16 fraction times total image width or height, as appropriate.
    5346             : 
    5347           0 :         if (SeekToContent(DFF_Prop_pWrapPolygonVertices, rSt))
    5348             :         {
    5349           0 :             delete pTextImpRec->pWrapPolygon;
    5350           0 :             pTextImpRec->pWrapPolygon = NULL;
    5351           0 :             sal_uInt16 nNumElemVert(0), nNumElemMemVert(0), nElemSizeVert(0);
    5352           0 :             rSt.ReadUInt16( nNumElemVert ).ReadUInt16( nNumElemMemVert ).ReadUInt16( nElemSizeVert );
    5353           0 :             bool bOk = false;
    5354           0 :             if (nNumElemVert && ((nElemSizeVert == 8) || (nElemSizeVert == 4)))
    5355             :             {
    5356           0 :                 bOk = rSt.remainingSize() / nElemSizeVert >= nNumElemVert;
    5357             :             }
    5358           0 :             if (bOk)
    5359             :             {
    5360           0 :                 pTextImpRec->pWrapPolygon = new Polygon(nNumElemVert);
    5361           0 :                 for (sal_uInt16 i = 0; i < nNumElemVert; ++i)
    5362             :                 {
    5363           0 :                     sal_Int32 nX(0), nY(0);
    5364           0 :                     if (nElemSizeVert == 8)
    5365           0 :                         rSt.ReadInt32( nX ).ReadInt32( nY );
    5366             :                     else
    5367             :                     {
    5368           0 :                         sal_Int16 nSmallX(0), nSmallY(0);
    5369           0 :                         rSt.ReadInt16( nSmallX ).ReadInt16( nSmallY );
    5370           0 :                         nX = nSmallX;
    5371           0 :                         nY = nSmallY;
    5372             :                     }
    5373           0 :                     (*(pTextImpRec->pWrapPolygon))[i].X() = nX;
    5374           0 :                     (*(pTextImpRec->pWrapPolygon))[i].Y() = nY;
    5375             :                 }
    5376             :             }
    5377             :         }
    5378             : 
    5379             :         pImpRec->nCropFromTop = GetPropertyValue(
    5380           0 :                                     DFF_Prop_cropFromTop, 0 );
    5381             :         pImpRec->nCropFromBottom = GetPropertyValue(
    5382           0 :                                     DFF_Prop_cropFromBottom, 0 );
    5383             :         pImpRec->nCropFromLeft = GetPropertyValue(
    5384           0 :                                     DFF_Prop_cropFromLeft, 0 );
    5385             :         pImpRec->nCropFromRight = GetPropertyValue(
    5386           0 :                                     DFF_Prop_cropFromRight, 0 );
    5387             : 
    5388           0 :         pImpRec->bVFlip = (rObjData.nSpFlags & SP_FFLIPV) ? true : false;
    5389           0 :         pImpRec->bHFlip = (rObjData.nSpFlags & SP_FFLIPH) ? true : false;
    5390             : 
    5391           0 :         sal_uInt32 nLineFlags = GetPropertyValue( DFF_Prop_fNoLineDrawDash );
    5392           0 :         pImpRec->eLineStyle = (nLineFlags & 8)
    5393             :                             ? (MSO_LineStyle)GetPropertyValue(
    5394             :                                                 DFF_Prop_lineStyle,
    5395           0 :                                                 mso_lineSimple )
    5396           0 :                             : MSO_LineStyle_NONE;
    5397           0 :         pTextImpRec->eLineStyle = pImpRec->eLineStyle;
    5398             : 
    5399             :         pImpRec->eLineDashing = (MSO_LineDashing)GetPropertyValue(
    5400           0 :                 DFF_Prop_lineDashing, mso_lineSolid );
    5401           0 :         pTextImpRec->eLineDashing = pImpRec->eLineDashing;
    5402             : 
    5403           0 :         if( pImpRec->nShapeId )
    5404             :         {
    5405             :             // Import-Record-Liste ergaenzen
    5406           0 :             if( pOrgObj )
    5407             :             {
    5408           0 :                 pImpRec->pObj = pOrgObj;
    5409           0 :                 rImportData.aRecords.insert( pImpRec );
    5410           0 :                 bDeleteImpRec = false;
    5411           0 :                 if (pImpRec == pTextImpRec)
    5412           0 :                     bDeleteTextImpRec = false;
    5413             :             }
    5414             : 
    5415           0 :             if( pTextObj && (pOrgObj != pTextObj) )
    5416             :             {
    5417             :                 // Modify ShapeId (must be unique)
    5418           0 :                 pImpRec->nShapeId |= 0x8000000;
    5419           0 :                 pTextImpRec->pObj = pTextObj;
    5420           0 :                 rImportData.aRecords.insert( pTextImpRec );
    5421           0 :                 bDeleteTextImpRec = false;
    5422           0 :                 if (pTextImpRec == pImpRec)
    5423           0 :                     bDeleteImpRec = false;
    5424             :             }
    5425             : 
    5426             :             // entry in the z-order-list in order to complement the pointer to this object
    5427             :             /*Only store objects which are not deep inside the tree*/
    5428           0 :             if( ( rObjData.nCalledByGroup == 0 )
    5429           0 :                 ||
    5430           0 :                 ( (rObjData.nSpFlags & SP_FGROUP)
    5431           0 :                  && (rObjData.nCalledByGroup < 2) )
    5432             :               )
    5433             :                 StoreShapeOrder( pImpRec->nShapeId,
    5434           0 :                                 ( ( (sal_uLong)pImpRec->aTextId.nTxBxS ) << 16 )
    5435           0 :                                     + pImpRec->aTextId.nSequence, pObj );
    5436             :         }
    5437             : 
    5438           0 :         if (bDeleteImpRec)
    5439           0 :             delete pImpRec;
    5440             : 
    5441           0 :         if (bDeleteTextImpRec)
    5442           0 :             delete pTextImpRec;
    5443             :     }
    5444             : 
    5445           0 :     return pObj;
    5446             : };
    5447             : 
    5448         306 : void SvxMSDffManager::StoreShapeOrder(sal_uLong         nId,
    5449             :                                       sal_uLong         nTxBx,
    5450             :                                       SdrObject*    pObject,
    5451             :                                       SwFlyFrmFmt*  pFly,
    5452             :                                       short         nHdFtSection) const
    5453             : {
    5454         306 :     sal_uInt16 nShpCnt = pShapeOrders->size();
    5455        7662 :     for (sal_uInt16 nShapeNum=0; nShapeNum < nShpCnt; nShapeNum++)
    5456             :     {
    5457        7356 :         SvxMSDffShapeOrder& rOrder = (*pShapeOrders)[ nShapeNum ];
    5458             : 
    5459        7356 :         if( rOrder.nShapeId == nId )
    5460             :         {
    5461         282 :             rOrder.nTxBxComp = nTxBx;
    5462         282 :             rOrder.pObj      = pObject;
    5463         282 :             rOrder.pFly      = pFly;
    5464         282 :             rOrder.nHdFtSection = nHdFtSection;
    5465             :         }
    5466             :     }
    5467         306 : }
    5468             : 
    5469             : 
    5470          32 : void SvxMSDffManager::ExchangeInShapeOrder( SdrObject*   pOldObject,
    5471             :                                             sal_uLong        nTxBx,
    5472             :                                             SwFlyFrmFmt* pFly,
    5473             :                                             SdrObject*   pObject) const
    5474             : {
    5475          32 :     sal_uInt16 nShpCnt = pShapeOrders->size();
    5476         362 :     for (sal_uInt16 nShapeNum=0; nShapeNum < nShpCnt; nShapeNum++)
    5477             :     {
    5478         330 :         SvxMSDffShapeOrder& rOrder = (*pShapeOrders)[ nShapeNum ];
    5479             : 
    5480         330 :         if( rOrder.pObj == pOldObject )
    5481             :         {
    5482          20 :             rOrder.pFly      = pFly;
    5483          20 :             rOrder.pObj      = pObject;
    5484          20 :             rOrder.nTxBxComp = nTxBx;
    5485             :         }
    5486             :     }
    5487          32 : }
    5488             : 
    5489             : 
    5490          64 : void SvxMSDffManager::RemoveFromShapeOrder( SdrObject* pObject ) const
    5491             : {
    5492          64 :     sal_uInt16 nShpCnt = pShapeOrders->size();
    5493        2166 :     for (sal_uInt16 nShapeNum=0; nShapeNum < nShpCnt; nShapeNum++)
    5494             :     {
    5495        2102 :         SvxMSDffShapeOrder& rOrder = (*pShapeOrders)[ nShapeNum ];
    5496             : 
    5497        2102 :         if( rOrder.pObj == pObject )
    5498             :         {
    5499          56 :             rOrder.pObj      = 0;
    5500          56 :             rOrder.pFly      = 0;
    5501          56 :             rOrder.nTxBxComp = 0;
    5502             :         }
    5503             :     }
    5504          64 : }
    5505             : 
    5506             : 
    5507             : 
    5508             : 
    5509             : 
    5510             : //  exported class: Public Methods
    5511             : 
    5512             : 
    5513         370 : SvxMSDffManager::SvxMSDffManager(SvStream& rStCtrl_,
    5514             :                                  const OUString& rBaseURL,
    5515             :                                  sal_uInt32 nOffsDgg_,
    5516             :                                  SvStream* pStData_,
    5517             :                                  SdrModel* pSdrModel_,// see SetModel() below
    5518             :                                  long      nApplicationScale,
    5519             :                                  ColorData mnDefaultColor_,
    5520             :                                  sal_uLong     nDefaultFontHeight_,
    5521             :                                  SvStream* pStData2_ )
    5522             :     :DffPropertyReader( *this ),
    5523             :      pFormModel( NULL ),
    5524         370 :      pBLIPInfos( new SvxMSDffBLIPInfos  ),
    5525         370 :      m_pShapeInfosByTxBxComp( new SvxMSDffShapeInfos_ByTxBxComp ),
    5526         370 :      pShapeOrders( new SvxMSDffShapeOrders ),
    5527             :      nDefaultFontHeight( nDefaultFontHeight_),
    5528             :      nOffsDgg( nOffsDgg_ ),
    5529             :      nBLIPCount(  USHRT_MAX ),              // initialize with error, since we fist check if the
    5530             :      nShapeCount( USHRT_MAX ),              // control stream has correct data
    5531             :      nGroupShapeFlags(0),                   // ensure initialization here, as some corrupted
    5532             :                                             // files may yield to this being unitialized
    5533             :      maBaseURL( rBaseURL ),
    5534             :      rStCtrl(  rStCtrl_  ),
    5535             :      pStData(  pStData_  ),
    5536             :      pStData2( pStData2_ ),
    5537             :      nSvxMSDffSettings( 0 ),
    5538             :      nSvxMSDffOLEConvFlags( 0 ),
    5539             :      pSecPropSet( NULL ),
    5540             :      mnDefaultColor( mnDefaultColor_),
    5541        1480 :      mbTracing( false )
    5542             : {
    5543         370 :     SetModel( pSdrModel_, nApplicationScale );
    5544             : 
    5545             :     // remember FilePos of the stream(s)
    5546         370 :     sal_uLong nOldPosCtrl = rStCtrl.Tell();
    5547         370 :     sal_uLong nOldPosData = pStData ? pStData->Tell() : nOldPosCtrl;
    5548             : 
    5549             :     // if no data stream is given we assume that the BLIPs
    5550             :     // are in the control stream
    5551         370 :     if( !pStData )
    5552         264 :         pStData = &rStCtrl;
    5553             : 
    5554         370 :     SetDefaultPropSet( rStCtrl, nOffsDgg );
    5555             : 
    5556             :     // read control stream, if successful set nBLIPCount
    5557         370 :     GetCtrlData( nOffsDgg );
    5558             : 
    5559             :     // check Text-Box-Story-Chain-Infos
    5560         370 :     CheckTxBxStoryChain();
    5561             : 
    5562             :     // restore old FilePos of the stream(s)
    5563         370 :     rStCtrl.Seek( nOldPosCtrl );
    5564         370 :     if( &rStCtrl != pStData )
    5565         106 :         pStData->Seek( nOldPosData );
    5566         370 : }
    5567             : 
    5568          20 : SvxMSDffManager::SvxMSDffManager( SvStream& rStCtrl_, const OUString& rBaseURL )
    5569             :     :DffPropertyReader( *this ),
    5570             :      pFormModel( NULL ),
    5571          20 :      pBLIPInfos(   new SvxMSDffBLIPInfos  ),
    5572          20 :      m_pShapeInfosByTxBxComp( new SvxMSDffShapeInfos_ByTxBxComp ),
    5573          20 :      pShapeOrders( new SvxMSDffShapeOrders ),
    5574             :      nDefaultFontHeight( 24 ),
    5575             :      nOffsDgg( 0 ),
    5576             :      nBLIPCount(  USHRT_MAX ),              // initialize with error, since we first have to check
    5577             :      nShapeCount( USHRT_MAX ),              // whether the control stream contains the correct data
    5578             :      nGroupShapeFlags(0),
    5579             :      maBaseURL( rBaseURL ),
    5580             :      mnCurMaxShapeId(0),
    5581             :      mnDrawingsSaved(0),
    5582             :      mnIdClusters(0),
    5583             :      rStCtrl(  rStCtrl_  ),
    5584             :      pStData( 0 ),
    5585             :      pStData2( 0 ),
    5586             :      nSvxMSDffSettings( 0 ),
    5587             :      nSvxMSDffOLEConvFlags( 0 ),
    5588             :      pSecPropSet( NULL ),
    5589             :      mnDefaultColor( COL_DEFAULT ),
    5590          80 :      mbTracing( false )
    5591             : {
    5592          20 :     SetModel( NULL, 0 );
    5593          20 : }
    5594             : 
    5595         780 : SvxMSDffManager::~SvxMSDffManager()
    5596             : {
    5597         390 :     delete pSecPropSet;
    5598         390 :     delete pBLIPInfos;
    5599         390 :     delete pShapeOrders;
    5600         390 :     delete pFormModel;
    5601         390 : }
    5602             : 
    5603          18 : void SvxMSDffManager::InitSvxMSDffManager( sal_uInt32 nOffsDgg_, SvStream* pStData_, sal_uInt32 nOleConvFlags )
    5604             : {
    5605          18 :     nOffsDgg = nOffsDgg_;
    5606          18 :     pStData = pStData_;
    5607          18 :     nSvxMSDffOLEConvFlags = nOleConvFlags;
    5608             : 
    5609             :     // remember FilePos of the stream(s)
    5610          18 :     sal_uLong nOldPosCtrl = rStCtrl.Tell();
    5611             : 
    5612          18 :     SetDefaultPropSet( rStCtrl, nOffsDgg );
    5613             : 
    5614             :     // insert fidcl cluster table
    5615          18 :     GetFidclData( nOffsDgg );
    5616             : 
    5617             :     // read control stream, if successful, set nBLIPCount
    5618          18 :     GetCtrlData( nOffsDgg );
    5619             : 
    5620             :     // check Text-Box-Story-Chain-Infos
    5621          18 :     CheckTxBxStoryChain();
    5622             : 
    5623             :     // restore old FilePos of the stream(s)
    5624          18 :     rStCtrl.Seek( nOldPosCtrl );
    5625          18 : }
    5626             : 
    5627         152 : void SvxMSDffManager::SetDgContainer( SvStream& rSt )
    5628             : {
    5629         152 :     sal_uInt32 nFilePos = rSt.Tell();
    5630         152 :     DffRecordHeader aDgContHd;
    5631         152 :     ReadDffRecordHeader( rSt, aDgContHd );
    5632             :     // insert this container only if there is also a DgAtom
    5633         152 :     if ( SeekToRec( rSt, DFF_msofbtDg, aDgContHd.GetRecEndFilePos() ) )
    5634             :     {
    5635         152 :         DffRecordHeader aRecHd;
    5636         152 :         ReadDffRecordHeader( rSt, aRecHd );
    5637         152 :         sal_uInt32 nDrawingId = aRecHd.nRecInstance;
    5638         152 :         maDgOffsetTable[ nDrawingId ] = nFilePos;
    5639         152 :         rSt.Seek( nFilePos );
    5640             :     }
    5641         152 : }
    5642             : 
    5643          18 : void SvxMSDffManager::GetFidclData( sal_uInt32 nOffsDggL )
    5644             : {
    5645          18 :     if (!nOffsDggL)
    5646          18 :         return;
    5647             : 
    5648          18 :     sal_uInt32 nDummy, nMerk = rStCtrl.Tell();
    5649             : 
    5650          18 :     if (nOffsDggL == rStCtrl.Seek(nOffsDggL))
    5651             :     {
    5652          18 :         DffRecordHeader aRecHd;
    5653          18 :         ReadDffRecordHeader( rStCtrl, aRecHd );
    5654             : 
    5655          18 :         DffRecordHeader aDggAtomHd;
    5656          18 :         if ( SeekToRec( rStCtrl, DFF_msofbtDgg, aRecHd.GetRecEndFilePos(), &aDggAtomHd ) )
    5657             :         {
    5658          18 :             aDggAtomHd.SeekToContent( rStCtrl );
    5659          18 :             rStCtrl.ReadUInt32( mnCurMaxShapeId )
    5660          36 :                    .ReadUInt32( mnIdClusters )
    5661          18 :                    .ReadUInt32( nDummy )
    5662          36 :                    .ReadUInt32( mnDrawingsSaved );
    5663             : 
    5664          18 :             if ( mnIdClusters-- > 2 )
    5665             :             {
    5666          18 :                 const sal_Size nFIDCLsize = sizeof(sal_uInt32) * 2;
    5667          18 :                 if ( aDggAtomHd.nRecLen == ( mnIdClusters * nFIDCLsize + 16 ) )
    5668             :                 {
    5669          18 :                     sal_Size nMaxEntriesPossible = rStCtrl.remainingSize() / nFIDCLsize;
    5670             :                     SAL_WARN_IF(nMaxEntriesPossible < mnIdClusters,
    5671             :                         "filter.ms", "FIDCL list longer than remaining bytes, ppt or parser is wrong");
    5672          18 :                     mnIdClusters = std::min(nMaxEntriesPossible, static_cast<sal_Size>(mnIdClusters));
    5673             : 
    5674          18 :                     maFidcls.resize(mnIdClusters);
    5675        1362 :                     for (sal_uInt32 i = 0; i < mnIdClusters; ++i)
    5676             :                     {
    5677        1344 :                         rStCtrl.ReadUInt32( maFidcls[ i ].dgid )
    5678        2688 :                                .ReadUInt32( maFidcls[ i ].cspidCur );
    5679             :                     }
    5680             :                 }
    5681             :             }
    5682             :         }
    5683             :     }
    5684          18 :     rStCtrl.Seek( nMerk );
    5685             : }
    5686             : 
    5687         388 : void SvxMSDffManager::CheckTxBxStoryChain()
    5688             : {
    5689         388 :     m_pShapeInfosById.reset(new SvxMSDffShapeInfos_ById);
    5690             :     // mangle old Info array, sorted by nTxBxComp
    5691         388 :     sal_uLong nChain    = ULONG_MAX;
    5692         388 :     bool bSetReplaceFALSE = false;
    5693        3216 :     for (SvxMSDffShapeInfos_ByTxBxComp::iterator iter =
    5694         388 :                 m_pShapeInfosByTxBxComp->begin(),
    5695         388 :             mark = m_pShapeInfosByTxBxComp->begin();
    5696        2144 :          iter != m_pShapeInfosByTxBxComp->end(); ++iter)
    5697             :     {
    5698         684 :         boost::shared_ptr<SvxMSDffShapeInfo> const pObj = *iter;
    5699         684 :         if( pObj->nTxBxComp )
    5700             :         {
    5701             :             // group change?
    5702             :             // #156763#
    5703             :             // the text id also contains an internal drawing container id
    5704             :             // to distinguish between text id of drawing objects in different
    5705             :             // drawing containers.
    5706         148 :             if( nChain != pObj->nTxBxComp )
    5707             :             {
    5708             :                 // reset mark and helper flag
    5709         148 :                 mark = iter;
    5710         148 :                 nChain = pObj->nTxBxComp;
    5711         148 :                 bSetReplaceFALSE = !pObj->bReplaceByFly;
    5712             :             }
    5713           0 :             else if( !pObj->bReplaceByFly )
    5714             :             {
    5715             :                 // object that must NOT be replaced by frame?
    5716           0 :                 bSetReplaceFALSE = true;
    5717             :                 // maybe reset flags in start of group
    5718           0 :                 for (SvxMSDffShapeInfos_ByTxBxComp::iterator itemp = mark;
    5719             :                         itemp != iter; ++itemp)
    5720             :                 {
    5721           0 :                     (*itemp)->bReplaceByFly = false;
    5722             :                 }
    5723             :             }
    5724             : 
    5725         148 :             if( bSetReplaceFALSE )
    5726             :             {
    5727           8 :                 pObj->bReplaceByFly = false;
    5728             :             }
    5729             :         }
    5730             :         // copy all Shape Info objects to m_pShapeInfosById, sorted by nShapeId
    5731         684 :         pObj->nTxBxComp = pObj->nTxBxComp & 0xFFFF0000;
    5732         684 :         m_pShapeInfosById->insert( pObj );
    5733         684 :     }
    5734             :     // free original array but don't free its elements
    5735         388 :     m_pShapeInfosByTxBxComp.reset();
    5736         388 : }
    5737             : 
    5738             : 
    5739             : /*****************************************************************************
    5740             : 
    5741             :     Reading the Shape-Infos in the Ctor:
    5742             :     ---------------------------------
    5743             :     remembering the Shape-Ids and the associated Blip-Numbers und TextBox-Infos
    5744             :                     =========                    ============     =============
    5745             :     and remembering the File-Offsets for each Blip
    5746             :                        ============
    5747             : ******************************************************************************/
    5748         388 : void SvxMSDffManager::GetCtrlData( sal_uInt32 nOffsDgg_ )
    5749             : {
    5750             :     // absolutely remember Start Offset, in case we have to position again
    5751         388 :     sal_uInt32 nOffsDggL = nOffsDgg_;
    5752             : 
    5753             :     // position control stream
    5754         388 :     if (nOffsDggL != rStCtrl.Seek(nOffsDggL))
    5755         190 :         return;
    5756             : 
    5757             :     sal_uInt8   nVer;
    5758             :     sal_uInt16 nInst;
    5759             :     sal_uInt16 nFbt;
    5760             :     sal_uInt32  nLength;
    5761         388 :     if( !ReadCommonRecordHeader( rStCtrl, nVer, nInst, nFbt, nLength ) ) return;
    5762             : 
    5763             :     bool bOk;
    5764         198 :     sal_uLong nPos = nOffsDggL + DFF_COMMON_RECORD_HEADER_SIZE;
    5765             : 
    5766             :     // case A: first Drawing Group Container, then n times Drawing Container
    5767         198 :     if( DFF_msofbtDggContainer == nFbt )
    5768             :     {
    5769         152 :         GetDrawingGroupContainerData( rStCtrl, nLength );
    5770             : 
    5771         152 :         rStCtrl.Seek( STREAM_SEEK_TO_END );
    5772         152 :         sal_uInt32 nMaxStrPos = rStCtrl.Tell();
    5773             : 
    5774         152 :         nPos += nLength;
    5775         152 :         unsigned long nDrawingContainerId = 1;
    5776         222 :         do
    5777             :         {
    5778         222 :             if (nPos != rStCtrl.Seek(nPos))
    5779           0 :                 break;
    5780             : 
    5781         222 :             bOk = ReadCommonRecordHeader( rStCtrl, nVer, nInst, nFbt, nLength ) && ( DFF_msofbtDgContainer == nFbt );
    5782             : 
    5783         222 :             if( !bOk )
    5784             :             {
    5785         222 :                 nPos++;                // ????????? TODO: trying to get an one-hit wonder, this code code should be rewritten...
    5786         222 :                 if (nPos != rStCtrl.Seek(nPos))
    5787           0 :                     break;
    5788         222 :                 bOk = ReadCommonRecordHeader( rStCtrl, nVer, nInst, nFbt, nLength )
    5789         222 :                         && ( DFF_msofbtDgContainer == nFbt );
    5790             :             }
    5791         222 :             if( bOk )
    5792             :             {
    5793          72 :                 GetDrawingContainerData( rStCtrl, nLength, nDrawingContainerId );
    5794             :             }
    5795         222 :             nPos += DFF_COMMON_RECORD_HEADER_SIZE + nLength;
    5796         222 :             ++nDrawingContainerId;
    5797             :         }
    5798         222 :         while( ( rStCtrl.GetError() == 0 ) && ( nPos < nMaxStrPos ) && bOk );
    5799             :     }
    5800             : }
    5801             : 
    5802             : 
    5803             : // from here on: Drawing Group Container  i.e. Ddocument-wide valid data
    5804             : //                      =======================           ========
    5805             : 
    5806         152 : void SvxMSDffManager::GetDrawingGroupContainerData( SvStream& rSt, sal_uLong nLenDgg )
    5807             : {
    5808             :     sal_uInt8   nVer;
    5809             :     sal_uInt16 nInst;
    5810             :     sal_uInt16 nFbt;
    5811             :     sal_uInt32 nLength;
    5812             : 
    5813         152 :     sal_uLong nLenBStoreCont = 0, nLenFBSE = 0, nRead = 0;
    5814             : 
    5815             :     // search for a  BStore Container
    5816         246 :     do
    5817             :     {
    5818         400 :         if(!ReadCommonRecordHeader( rSt, nVer, nInst, nFbt, nLength)) return;
    5819         340 :         nRead += DFF_COMMON_RECORD_HEADER_SIZE + nLength;
    5820         340 :         if( DFF_msofbtBstoreContainer == nFbt )
    5821             :         {
    5822          94 :             nLenBStoreCont = nLength;       break;
    5823             :         }
    5824         246 :         rSt.SeekRel( nLength );
    5825             :     }
    5826             :     while( nRead < nLenDgg );
    5827             : 
    5828         152 :     if( !nLenBStoreCont ) return;
    5829             : 
    5830             :     // Read all atoms of the containers from the BStore container and store all
    5831             :     // relevant data of all contained FBSEs in out pointer array.
    5832             :     // We also count all found FBSEs in member nBLIPCount.
    5833             : 
    5834          92 :     const sal_uLong nSkipBLIPLen = 20;  // skip to get to the nBLIPLen
    5835          92 :     const sal_uLong nSkipBLIPPos =  4;  // thereafter skip up to nBLIPPos
    5836             : 
    5837          92 :     sal_uInt32 nBLIPLen = 0, nBLIPPos = 0;
    5838             : 
    5839          92 :     nRead = 0;
    5840         188 :     do
    5841             :     {
    5842         188 :         if(!ReadCommonRecordHeader( rSt, nVer, nInst, nFbt, nLength)) return;
    5843         188 :         nRead += DFF_COMMON_RECORD_HEADER_SIZE + nLength;
    5844         188 :         if( DFF_msofbtBSE == nFbt )
    5845             :         {
    5846         188 :             nLenFBSE = nLength;
    5847             :             // is FBSE big enough for our data
    5848         188 :             bool bOk = ( nSkipBLIPLen + 4 + nSkipBLIPPos + 4 <= nLenFBSE );
    5849             : 
    5850         188 :             if( bOk )
    5851             :             {
    5852         188 :                 rSt.SeekRel( nSkipBLIPLen );
    5853         188 :                 rSt.ReadUInt32( nBLIPLen );
    5854         188 :                 rSt.SeekRel( nSkipBLIPPos );
    5855         188 :                 rSt.ReadUInt32( nBLIPPos );
    5856         188 :                 bOk = rSt.GetError() == 0;
    5857             : 
    5858         188 :                 nLength -= nSkipBLIPLen+ 4 + nSkipBLIPPos + 4;
    5859             :             }
    5860             : 
    5861         188 :             if( bOk )
    5862             :             {
    5863             :                 // specialty:
    5864             :                 // If nBLIPLen is less than nLenFBSE AND nBLIPPos is NULL,
    5865             :                 // then we assume, that the image is in FBSE!
    5866         188 :                 if( (!nBLIPPos) && (nBLIPLen < nLenFBSE) )
    5867         122 :                     nBLIPPos = rSt.Tell() + 4;
    5868             : 
    5869             :                 // That worked great!
    5870             :                 // We store, that we do have one FBSE more in the pointer array.
    5871         188 :                 nBLIPPos = Calc_nBLIPPos(nBLIPPos, rSt.Tell());
    5872             : 
    5873         188 :                 if( USHRT_MAX == nBLIPCount )
    5874          92 :                     nBLIPCount = 1;
    5875             :                 else
    5876          96 :                     nBLIPCount++;
    5877             : 
    5878             :                 // now save the info for later access
    5879         188 :                 pBLIPInfos->push_back( new SvxMSDffBLIPInfo( nInst, nBLIPPos, nBLIPLen ) );
    5880             :             }
    5881             :         }
    5882         188 :         rSt.SeekRel( nLength );
    5883             :     }
    5884             :     while( nRead < nLenBStoreCont );
    5885             : }
    5886             : 
    5887             : 
    5888             : // from now on: Drawing Container  which means Pages (Sheet, Slide) - wide valid data
    5889             : //                      =================               ======
    5890             : 
    5891          72 : void SvxMSDffManager::GetDrawingContainerData( SvStream& rSt, sal_uLong nLenDg,
    5892             :                                                const unsigned long nDrawingContainerId )
    5893             : {
    5894             :     sal_uInt8 nVer;sal_uInt16 nInst;sal_uInt16 nFbt;sal_uInt32 nLength;
    5895             : 
    5896          72 :     sal_uLong nReadDg = 0;
    5897             : 
    5898             :     // We are now in a drawing container (one per each page) and
    5899             :     // we now have to iterate through all contained shape group containers
    5900         212 :     do
    5901             :     {
    5902         212 :         if(!ReadCommonRecordHeader( rSt, nVer, nInst, nFbt, nLength)) return;
    5903         212 :         nReadDg += DFF_COMMON_RECORD_HEADER_SIZE;
    5904             :         // Patriarch found (the upmost shape group container) ?
    5905         212 :         if( DFF_msofbtSpgrContainer == nFbt )
    5906             :         {
    5907          72 :             if(!this->GetShapeGroupContainerData( rSt, nLength, true, nDrawingContainerId )) return;
    5908             :         }
    5909             :         // empty Shape Container ? (outside of shape group container)
    5910         140 :         else if( DFF_msofbtSpContainer == nFbt )
    5911             :         {
    5912          60 :             if(!this->GetShapeContainerData( rSt, nLength, ULONG_MAX, nDrawingContainerId )) return;
    5913             :         }
    5914             :         else
    5915          80 :             rSt.SeekRel( nLength );
    5916         212 :         nReadDg += nLength;
    5917             :     }
    5918             :     while( nReadDg < nLenDg );
    5919             : }
    5920             : 
    5921         102 : bool SvxMSDffManager::GetShapeGroupContainerData( SvStream& rSt,
    5922             :                                                   sal_uLong nLenShapeGroupCont,
    5923             :                                                   bool bPatriarch,
    5924             :                                                   const unsigned long nDrawingContainerId )
    5925             : {
    5926             :     sal_uInt8 nVer;sal_uInt16 nInst;sal_uInt16 nFbt;sal_uInt32 nLength;
    5927         102 :     long nStartShapeGroupCont = rSt.Tell();
    5928             :     // We are now in a shape group container (conditionally mulitple per page)
    5929             :     // an we now have to iterate through all contained shape containers
    5930         102 :     bool  bFirst = !bPatriarch;
    5931         102 :     sal_uLong nReadSpGrCont = 0;
    5932         654 :     do
    5933             :     {
    5934         654 :         if( !ReadCommonRecordHeader( rSt, nVer, nInst, nFbt, nLength ) )
    5935           0 :             return false;
    5936         654 :         nReadSpGrCont += DFF_COMMON_RECORD_HEADER_SIZE;
    5937             :         // Shape Container?
    5938         654 :         if( DFF_msofbtSpContainer == nFbt )
    5939             :         {
    5940         624 :             sal_uLong nGroupOffs = bFirst ? nStartShapeGroupCont - DFF_COMMON_RECORD_HEADER_SIZE : ULONG_MAX;
    5941         624 :             if ( !this->GetShapeContainerData( rSt, nLength, nGroupOffs, nDrawingContainerId ) )
    5942           0 :                 return false;
    5943         624 :             bFirst = false;
    5944             :         }
    5945             :         // nested shape group container ?
    5946          30 :         else if( DFF_msofbtSpgrContainer == nFbt )
    5947             :         {
    5948          30 :             if ( !this->GetShapeGroupContainerData( rSt, nLength, false, nDrawingContainerId ) )
    5949           0 :                 return false;
    5950             :         }
    5951             :         else
    5952           0 :             rSt.SeekRel( nLength );
    5953         654 :         nReadSpGrCont += nLength;
    5954             :     }
    5955             :     while( nReadSpGrCont < nLenShapeGroupCont );
    5956             :     // possition the steam correctly
    5957         102 :     rSt.Seek( nStartShapeGroupCont + nLenShapeGroupCont );
    5958         102 :     return true;
    5959             : }
    5960             : 
    5961         684 : bool SvxMSDffManager::GetShapeContainerData( SvStream& rSt,
    5962             :                                              sal_uLong nLenShapeCont,
    5963             :                                              sal_uLong nPosGroup,
    5964             :                                              const unsigned long nDrawingContainerId )
    5965             : {
    5966             :     sal_uInt8 nVer;sal_uInt16 nInst;sal_uInt16 nFbt;sal_uInt32 nLength;
    5967         684 :     long  nStartShapeCont = rSt.Tell();
    5968             : 
    5969             :     // We are in a shape container (possibly more than one per shape group) and we now
    5970             :     // have to fetch the shape id and file position (to be able to access them again later)
    5971             :     // and the first BStore reference (if present).
    5972         684 :     sal_uLong nLenShapePropTbl = 0;
    5973         684 :     sal_uLong nReadSpCont = 0;
    5974             : 
    5975             :     // Store file offset of the shape containers or respectivly the group(!).
    5976             :     sal_uLong nStartOffs = (ULONG_MAX > nPosGroup) ?
    5977         684 :                             nPosGroup : nStartShapeCont - DFF_COMMON_RECORD_HEADER_SIZE;
    5978         684 :     SvxMSDffShapeInfo aInfo( nStartOffs );
    5979             : 
    5980             :     // Can the shape be replaced with a frame?
    5981             :     // (provided that it is a TextBox and the text is not rotated)
    5982         684 :     bool bCanBeReplaced = (ULONG_MAX > nPosGroup) ? sal_False : sal_True;
    5983             : 
    5984             :     // we don't know yet whether it's a TextBox
    5985         684 :     MSO_SPT         eShapeType      = mso_sptNil;
    5986             : 
    5987             :     // analyze Shape
    5988             : 
    5989        2980 :     do
    5990             :     {
    5991        2980 :         if(!ReadCommonRecordHeader( rSt, nVer, nInst, nFbt, nLength)) return false;
    5992        2980 :         nReadSpCont += DFF_COMMON_RECORD_HEADER_SIZE;
    5993             :         // FSP ?
    5994        2980 :         if( ( DFF_msofbtSp == nFbt ) && ( 4 <= nLength ) )
    5995             :         {
    5996             :             // we've found the FSP gefunden: note Shape Type and Id!
    5997         684 :             eShapeType = (MSO_SPT)nInst;
    5998         684 :             rSt.ReadUInt32( aInfo.nShapeId );
    5999         684 :             rSt.SeekRel( nLength - 4 );
    6000         684 :             nReadSpCont += nLength;
    6001             :         }
    6002        2296 :         else if( DFF_msofbtOPT == nFbt ) // Shape Property Table ?
    6003             :         {
    6004             :             // We've found the Property Table:
    6005             :             // search for the Blip Property!
    6006         604 :             sal_uLong  nPropRead = 0;
    6007             :             sal_uInt16 nPropId;
    6008             :             sal_uInt32  nPropVal;
    6009         604 :             nLenShapePropTbl = nLength;
    6010         604 :             long nStartShapePropTbl = rSt.Tell();
    6011        3796 :             do
    6012             :             {
    6013        3796 :                 rSt.ReadUInt16( nPropId )
    6014        3796 :                    .ReadUInt32( nPropVal );
    6015        3796 :                 nPropRead += 6;
    6016             : 
    6017        3796 :                 switch( nPropId )
    6018             :                 {
    6019             :                     case DFF_Prop_txflTextFlow :
    6020             :                         //Writer can now handle vertical textflows in its
    6021             :                         //native frames, to only need to do this for the
    6022             :                         //other two formats
    6023             : 
    6024             :                         //Writer will handle all textflow except BtoT
    6025           6 :                         if (GetSvxMSDffSettings() &
    6026             :                             (SVXMSDFF_SETTINGS_IMPORT_PPT |
    6027             :                              SVXMSDFF_SETTINGS_IMPORT_EXCEL))
    6028             :                         {
    6029           0 :                             if( 0 != nPropVal )
    6030           0 :                                 bCanBeReplaced = false;
    6031             :                         }
    6032           6 :                         else if (
    6033           6 :                             (nPropVal != mso_txflHorzN) &&
    6034           0 :                             (nPropVal != mso_txflTtoBA)
    6035             :                                 )
    6036             :                         {
    6037           0 :                             bCanBeReplaced = false;
    6038             :                         }
    6039           6 :                     break;
    6040             :                     case DFF_Prop_cdirFont :
    6041             :                         //Writer can now handle right to left and left
    6042             :                         //to right in its native frames, so only do
    6043             :                         //this for the other two formats.
    6044           0 :                         if (GetSvxMSDffSettings() &
    6045             :                             (SVXMSDFF_SETTINGS_IMPORT_PPT |
    6046             :                              SVXMSDFF_SETTINGS_IMPORT_EXCEL))
    6047             :                         {
    6048           0 :                             if( 0 != nPropVal )
    6049           0 :                                 bCanBeReplaced = false;
    6050             :                         }
    6051           0 :                     break;
    6052             :                     case DFF_Prop_Rotation :
    6053           6 :                         if( 0 != nPropVal )
    6054           6 :                             bCanBeReplaced = false;
    6055           6 :                     break;
    6056             : 
    6057             :                     case DFF_Prop_gtextFStrikethrough :
    6058           0 :                         if( ( 0x20002000 & nPropVal )  == 0x20002000 )
    6059           0 :                             bCanBeReplaced = false;
    6060           0 :                     break;
    6061             : 
    6062             :                     case DFF_Prop_fc3DLightFace :
    6063         144 :                         if( ( 0x00080008 & nPropVal ) == 0x00080008 )
    6064           0 :                             bCanBeReplaced = false;
    6065         144 :                     break;
    6066             : 
    6067             :                     case DFF_Prop_WrapText :
    6068             :                         //TODO: eWrapMode = (MSO_WrapMode)nPropVal;
    6069           2 :                     break;
    6070             : 
    6071             :                     default:
    6072             :                     {
    6073             :                         // is the Bit set and valid?
    6074        3638 :                         if( 0x4000 == ( nPropId & 0xC000 ) )
    6075             :                         {
    6076             :                             // Blip Property found: remember BStore Idx!
    6077          52 :                             nPropRead = nLenShapePropTbl;
    6078             :                         }
    6079        3586 :                         else if( 0x8000 & nPropId )
    6080             :                         {
    6081             :                             // complex Prop found:
    6082             :                             // Length is always 6. The length of the appended extra data
    6083             :                             // after the actual prop table is of different size.
    6084          50 :                             nPropVal = 6;
    6085             :                         }
    6086             :                     }
    6087        3638 :                     break;
    6088             :                 }
    6089             :             }
    6090             :             while( nPropRead < nLenShapePropTbl );
    6091         604 :             rSt.Seek( nStartShapePropTbl + nLenShapePropTbl );
    6092         604 :             nReadSpCont += nLenShapePropTbl;
    6093             :         }
    6094        1692 :         else if( ( DFF_msofbtClientTextbox == nFbt ) && ( 4 == nLength ) )  // Text-Box-Story-Entry found
    6095             :         {
    6096         148 :             rSt.ReadUInt32( aInfo.nTxBxComp );
    6097             :             // Add internal drawing container id to text id.
    6098             :             // Note: The text id uses the first two bytes, while the internal
    6099             :             // drawing container id used the second two bytes.
    6100             :             aInfo.nTxBxComp = ( aInfo.nTxBxComp & 0xFFFF0000 ) +
    6101         148 :                               nDrawingContainerId;
    6102         148 :             DBG_ASSERT( (aInfo.nTxBxComp & 0x0000FFFF) == nDrawingContainerId,
    6103             :                         "<SvxMSDffManager::GetShapeContainerData(..)> - internal drawing container Id could not be correctly merged into DFF_msofbtClientTextbox value." );
    6104             :         }
    6105             :         else
    6106             :         {
    6107        1544 :             rSt.SeekRel( nLength );
    6108        1544 :             nReadSpCont += nLength;
    6109             :         }
    6110             :     }
    6111             :     while( nReadSpCont < nLenShapeCont );
    6112             : 
    6113             : 
    6114             :     // Now possibly store the information for subsequent accesses to the shape
    6115             : 
    6116         684 :     if( aInfo.nShapeId )
    6117             :     {
    6118             :         // Possibly allow replacement of textboxes with frames
    6119         684 :         if(     bCanBeReplaced
    6120         648 :              && aInfo.nTxBxComp
    6121         148 :              && (
    6122             :                     ( eShapeType == mso_sptTextSimple )
    6123         148 :                  || ( eShapeType == mso_sptTextBox    )
    6124         112 :                  || (    (    ( eShapeType == mso_sptRectangle      )
    6125          16 :                            || ( eShapeType == mso_sptRoundRectangle )
    6126             :                          )
    6127             :                 ) ) )
    6128             :         {
    6129         140 :             aInfo.bReplaceByFly = true;
    6130             :         }
    6131             :         m_pShapeInfosByTxBxComp->insert(::boost::shared_ptr<SvxMSDffShapeInfo>(
    6132         684 :                     new SvxMSDffShapeInfo(aInfo)));
    6133         684 :         pShapeOrders->push_back( new SvxMSDffShapeOrder( aInfo.nShapeId ) );
    6134             :     }
    6135             : 
    6136             :     // and position the Stream correctly again
    6137         684 :     rSt.Seek( nStartShapeCont + nLenShapeCont );
    6138         684 :     return true;
    6139             : }
    6140             : 
    6141             : 
    6142             : 
    6143             : /*****************************************************************************
    6144             : 
    6145             :     Access to a shape at runtime (via the Shape-Id)
    6146             :     ----------------------------
    6147             : ******************************************************************************/
    6148         252 : bool SvxMSDffManager::GetShape(sal_uLong nId, SdrObject*&         rpShape,
    6149             :                                           SvxMSDffImportData& rData)
    6150             : {
    6151             :     ::boost::shared_ptr<SvxMSDffShapeInfo> const pTmpRec(
    6152         252 :         new SvxMSDffShapeInfo(0, nId));
    6153             : 
    6154             :     SvxMSDffShapeInfos_ById::const_iterator const it =
    6155         252 :         m_pShapeInfosById->find(pTmpRec);
    6156         252 :     if (it != m_pShapeInfosById->end())
    6157             :     {
    6158             :         // Possibly delete old error flag.
    6159         208 :         if( rStCtrl.GetError() )
    6160           0 :             rStCtrl.ResetError();
    6161             :         // store FilePos of the stream(s)
    6162         208 :         sal_uLong nOldPosCtrl = rStCtrl.Tell();
    6163         208 :         sal_uLong nOldPosData = pStData ? pStData->Tell() : nOldPosCtrl;
    6164             :         // jump to the shape in the control stream
    6165         208 :         sal_uLong const nFilePos((*it)->nFilePos);
    6166         208 :         bool bSeeked = (nFilePos == rStCtrl.Seek(nFilePos));
    6167             : 
    6168             :         // if it failed, reset error statusF
    6169         208 :         if (!bSeeked || rStCtrl.GetError())
    6170           0 :             rStCtrl.ResetError();
    6171             :         else
    6172         208 :             rpShape = ImportObj( rStCtrl, &rData, rData.aParentRect, rData.aParentRect );
    6173             : 
    6174             :         // restore old alte FilePos of the stream(s)
    6175         208 :         rStCtrl.Seek( nOldPosCtrl );
    6176         208 :         if( &rStCtrl != pStData && pStData )
    6177         208 :             pStData->Seek( nOldPosData );
    6178         208 :         return ( 0 != rpShape );
    6179             :     }
    6180          44 :     return false;
    6181             : }
    6182             : 
    6183             : 
    6184             : 
    6185             : /*      access to a BLIP at runtime (if the Blip-Number is already known)
    6186             :         ---------------------------
    6187             : ******************************************************************************/
    6188         180 : bool SvxMSDffManager::GetBLIP( sal_uLong nIdx_, Graphic& rData, Rectangle* pVisArea )
    6189             : {
    6190         180 :     if (!pStData)
    6191           0 :         return false;
    6192             : 
    6193         180 :     bool bOk = false;       // initialize result variable
    6194             : 
    6195             :     // check if a graphic for this blipId is already imported
    6196         180 :     if ( nIdx_)
    6197             :     {
    6198         180 :         std::map<sal_uInt32,OString>::iterator iter = aEscherBlipCache.find(nIdx_);
    6199             : 
    6200         180 :         if (iter != aEscherBlipCache.end())
    6201             :         {
    6202             :             /* if this entry is available, then it should be possible
    6203             :             to get the Graphic via GraphicObject */
    6204           8 :             GraphicObject aGraphicObject( iter->second );
    6205           8 :             rData = aGraphicObject.GetGraphic();
    6206           8 :             if ( rData.GetType() != GRAPHIC_NONE )
    6207           8 :                 bOk = true;
    6208             :             else
    6209           0 :                 aEscherBlipCache.erase(iter);
    6210             :         }
    6211             :     }
    6212             : 
    6213         180 :     if ( !bOk )
    6214             :     {
    6215         172 :         sal_uInt16 nIdx = sal_uInt16( nIdx_ );
    6216         172 :         if( !nIdx || (pBLIPInfos->size() < nIdx) )
    6217          34 :             return false;
    6218             : 
    6219             :         // possibly delete old error flag(s)
    6220         138 :         if( rStCtrl.GetError() )
    6221           0 :             rStCtrl.ResetError();
    6222         276 :         if(    ( &rStCtrl != pStData )
    6223         138 :             && pStData->GetError() )
    6224           0 :             pStData->ResetError();
    6225             : 
    6226             :         // remember FilePos of the stream(s)
    6227         138 :         sal_uLong nOldPosCtrl = rStCtrl.Tell();
    6228         138 :         sal_uLong nOldPosData = pStData ? pStData->Tell() : nOldPosCtrl;
    6229             : 
    6230             :         // fetch matching info struct out of the pointer array
    6231         138 :         SvxMSDffBLIPInfo& rInfo = (*pBLIPInfos)[ nIdx-1 ];
    6232             :         // jump to the BLIP atom in the data stream
    6233         138 :         pStData->Seek( rInfo.nFilePos );
    6234             :         // possibly reset error status
    6235         138 :         if( pStData->GetError() )
    6236           0 :             pStData->ResetError();
    6237             :         else
    6238         138 :             bOk = GetBLIPDirect( *pStData, rData, pVisArea );
    6239         138 :         if( pStData2 && !bOk )
    6240             :         {
    6241             :             // Error, but the is a second chance: There is a second
    6242             :             //         data stream in which the graphic could be stored!
    6243          22 :             if( pStData2->GetError() )
    6244           0 :                 pStData2->ResetError();
    6245          22 :             sal_uLong nOldPosData2 = pStData2->Tell();
    6246             :             // jump to the BLIP atom in the second data stream
    6247          22 :             pStData2->Seek( rInfo.nFilePos );
    6248             :             // reset error status if necessary
    6249          22 :             if( pStData2->GetError() )
    6250           0 :                 pStData2->ResetError();
    6251             :             else
    6252          22 :                 bOk = GetBLIPDirect( *pStData2, rData, pVisArea );
    6253             :             // restore olf FilePos of the second data stream
    6254          22 :             pStData2->Seek( nOldPosData2 );
    6255             :         }
    6256             :         // restore old FilePos of the stream(s)
    6257         138 :         rStCtrl.Seek( nOldPosCtrl );
    6258         138 :         if( &rStCtrl != pStData )
    6259          66 :           pStData->Seek( nOldPosData );
    6260             : 
    6261         138 :         if ( bOk )
    6262             :         {
    6263             :             // create new BlipCacheEntry for this graphic
    6264         124 :             GraphicObject aGraphicObject( rData );
    6265         124 :             aEscherBlipCache.insert(std::make_pair(nIdx_,aGraphicObject.GetUniqueID()));
    6266             :         }
    6267             :     }
    6268             : 
    6269         146 :     return bOk;
    6270             : }
    6271             : 
    6272             : /*      access to a BLIP at runtime (with correctly positioned stream)
    6273             :     ---------------------------------
    6274             : ******************************************************************************/
    6275         200 : bool SvxMSDffManager::GetBLIPDirect( SvStream& rBLIPStream, Graphic& rData, Rectangle* pVisArea ) const
    6276             : {
    6277         200 :     sal_uLong nOldPos = rBLIPStream.Tell();
    6278             : 
    6279         200 :     int nRes = GRFILTER_OPENERROR;  // initialize error variable
    6280             : 
    6281             :     // check whether it's really a BLIP
    6282             :     sal_uInt32 nLength;
    6283         200 :     sal_uInt16 nInst, nFbt( 0 );
    6284             :     sal_uInt8   nVer;
    6285         200 :     if( ReadCommonRecordHeader( rBLIPStream, nVer, nInst, nFbt, nLength) && ( 0xF018 <= nFbt ) && ( 0xF117 >= nFbt ) )
    6286             :     {
    6287         172 :         Size        aMtfSize100;
    6288         172 :         bool        bMtfBLIP = false;
    6289         172 :         bool        bZCodecCompression = false;
    6290             :         // now position it exactly at the beinning of the embedded graphic
    6291         172 :         sal_uLong nSkip = ( nInst & 0x0001 ) ? 32 : 16;
    6292             : 
    6293         172 :         switch( nInst & 0xFFFE )
    6294             :         {
    6295             :             case 0x216 :            // Metafile header then compressed WMF
    6296             :             case 0x3D4 :            // Metafile header then compressed EMF
    6297             :             case 0x542 :            // Metafile hd. then compressed PICT
    6298             :             {
    6299         116 :                 rBLIPStream.SeekRel( nSkip + 20 );
    6300             : 
    6301             :                 // read in size of metafile in EMUS
    6302             :                 sal_Int32 width, height;
    6303         116 :                 rBLIPStream.ReadInt32( width ).ReadInt32( height );
    6304         116 :                 aMtfSize100.Width() = width;
    6305         116 :                 aMtfSize100.Height() = height;
    6306             : 
    6307             :                 // scale to 1/100mm
    6308         116 :                 aMtfSize100.Width() /= 360, aMtfSize100.Height() /= 360;
    6309             : 
    6310         116 :                 if ( pVisArea )     // seem that we currently are skipping the visarea position
    6311         116 :                     *pVisArea = Rectangle( Point(), aMtfSize100 );
    6312             : 
    6313             :                 // skip rest of header
    6314         116 :                 nSkip = 6;
    6315         116 :                 bMtfBLIP = bZCodecCompression = true;
    6316             :             }
    6317         116 :             break;
    6318             :             case 0x46A :            // One byte tag then JPEG (= JFIF) data
    6319             :             case 0x6E0 :            // One byte tag then PNG data
    6320             :             case 0x6E2 :            // One byte tag then JPEG in CMYK color space
    6321             :             case 0x7A8 :
    6322          56 :                 nSkip += 1;         // One byte tag then DIB data
    6323          56 :             break;
    6324             :         }
    6325         172 :         rBLIPStream.SeekRel( nSkip );
    6326             : 
    6327         172 :         SvStream* pGrStream = &rBLIPStream;
    6328         172 :         boost::scoped_ptr<SvMemoryStream> pOut;
    6329         172 :         if( bZCodecCompression )
    6330             :         {
    6331         116 :             pOut.reset(new SvMemoryStream( 0x8000, 0x4000 ));
    6332         116 :             ZCodec aZCodec( 0x8000, 0x8000 );
    6333         116 :             aZCodec.BeginCompression();
    6334         116 :             aZCodec.Decompress( rBLIPStream, *pOut );
    6335         116 :             aZCodec.EndCompression();
    6336         116 :             pOut->Seek( STREAM_SEEK_TO_BEGIN );
    6337         116 :             pOut->SetResizeOffset( 0 ); // sj: #i102257# setting ResizeOffset of 0 prevents from seeking
    6338             :                                         // behind the stream end (allocating too much memory)
    6339         116 :             pGrStream = pOut.get();
    6340             :         }
    6341             : 
    6342             : #if OSL_DEBUG_LEVEL > 2
    6343             :         // extract graphics from ole storage into "dbggfxNNN.*"
    6344             :         static sal_Int32 nGrfCount;
    6345             : 
    6346             :         OUString aFileName = "dbggfx" + OUString::number( nGrfCount++ );
    6347             :         switch( nInst &~ 1 )
    6348             :         {
    6349             :             case 0x216 : aFileName += ".wmf"; break;
    6350             :             case 0x3d4 : aFileName += ".emf"; break;
    6351             :             case 0x542 : aFileName += ".pct"; break;
    6352             :             case 0x46a : aFileName += ".jpg"; break;
    6353             :             case 0x6e0 : aFileName += ".png"; break;
    6354             :             case 0x6e2 : aFileName += ".jpg"; break;
    6355             :             case 0x7a8 : aFileName += ".bmp"; break;
    6356             :         }
    6357             : 
    6358             :         OUString aURLStr;
    6359             :         if( ::utl::LocalFileHelper::ConvertPhysicalNameToURL( Application::GetAppFileName(), aURLStr ) )
    6360             :         {
    6361             :             INetURLObject aURL( aURLStr );
    6362             : 
    6363             :             aURL.removeSegment();
    6364             :             aURL.removeFinalSlash();
    6365             :             aURL.Append( aFileName );
    6366             : 
    6367             :             aURLStr = aURL.GetMainURL( INetURLObject::NO_DECODE );
    6368             : 
    6369             :             SAL_INFO("filter.ms", "dumping " << aURLStr);
    6370             : 
    6371             :             boost::scoped_ptr<SvStream> pDbgOut(::utl::UcbStreamHelper::CreateStream(aURLStr, STREAM_TRUNC | STREAM_WRITE));
    6372             : 
    6373             :             if( pDbgOut )
    6374             :             {
    6375             :                 if ( bZCodecCompression )
    6376             :                 {
    6377             :                     pOut->Seek( STREAM_SEEK_TO_END );
    6378             :                     pDbgOut->Write( pOut->GetData(), pOut->Tell() );
    6379             :                     pOut->Seek( STREAM_SEEK_TO_BEGIN );
    6380             :                 }
    6381             :                 else
    6382             :                 {
    6383             :                     sal_Int32 nDbgLen = nLength - nSkip;
    6384             :                     if ( nDbgLen )
    6385             :                     {
    6386             :                         boost::scoped_array<sal_Char> pDat(new sal_Char[ nDbgLen ]);
    6387             :                         pGrStream->Read( pDat.get(), nDbgLen );
    6388             :                         pDbgOut->Write( pDat.get(), nDbgLen );
    6389             :                         pGrStream->SeekRel( -nDbgLen );
    6390             :                     }
    6391             :                 }
    6392             :             }
    6393             :         }
    6394             : #endif
    6395             : 
    6396         172 :         if( ( nInst & 0xFFFE ) == 0x7A8 )
    6397             :         {   // getting the DIBs immediately
    6398           0 :             Bitmap aNew;
    6399           0 :             if( ReadDIB(aNew, *pGrStream, false) )
    6400             :             {
    6401           0 :                 rData = Graphic( aNew );
    6402           0 :                 nRes = GRFILTER_OK;
    6403           0 :             }
    6404             :         }
    6405             :         else
    6406             :         {   // and unleash our filter
    6407         172 :             GraphicFilter& rGF = GraphicFilter::GetGraphicFilter();
    6408         172 :             OUString aEmptyStr;
    6409         172 :             nRes = rGF.ImportGraphic( rData, aEmptyStr, *pGrStream, GRFILTER_FORMAT_DONTKNOW );
    6410             : 
    6411             :             // SJ: I40472, sometimes the aspect ratio (aMtfSize100) does not match and we get scaling problems,
    6412             :             // then it is better to use the prefsize that is stored within the metafile. Bug #72846# for what the
    6413             :             // scaling has been implemented does not happen anymore.
    6414             :             //
    6415             :             // For pict graphics we will furthermore scale the metafile, because font scaling leads to error if the
    6416             :             // dxarray is empty (this has been solved in wmf/emf but not for pict)
    6417         172 :             if( bMtfBLIP && ( GRFILTER_OK == nRes ) && ( rData.GetType() == GRAPHIC_GDIMETAFILE ) && ( ( nInst & 0xFFFE ) == 0x542 ) )
    6418             :             {
    6419           0 :                 if ( ( aMtfSize100.Width() >= 1000 ) && ( aMtfSize100.Height() >= 1000 ) )
    6420             :                 {   // #75956#, scaling does not work properly, if the graphic is less than 1cm
    6421           0 :                     GDIMetaFile aMtf( rData.GetGDIMetaFile() );
    6422           0 :                     const Size  aOldSize( aMtf.GetPrefSize() );
    6423             : 
    6424           0 :                     if( aOldSize.Width() && ( aOldSize.Width() != aMtfSize100.Width() ) &&
    6425           0 :                         aOldSize.Height() && ( aOldSize.Height() != aMtfSize100.Height() ) )
    6426             :                     {
    6427           0 :                         aMtf.Scale( (double) aMtfSize100.Width() / aOldSize.Width(),
    6428           0 :                                     (double) aMtfSize100.Height() / aOldSize.Height() );
    6429           0 :                         aMtf.SetPrefSize( aMtfSize100 );
    6430           0 :                         aMtf.SetPrefMapMode( MAP_100TH_MM );
    6431           0 :                         rData = aMtf;
    6432           0 :                     }
    6433             :                 }
    6434         172 :             }
    6435             :         }
    6436             :         // reset error status if necessary
    6437         172 :         if ( ERRCODE_IO_PENDING == pGrStream->GetError() )
    6438           0 :           pGrStream->ResetError();
    6439             :     }
    6440         200 :     rBLIPStream.Seek( nOldPos );    // restore old FilePos of the strem
    6441             : 
    6442         200 :     return ( GRFILTER_OK == nRes ); // return result
    6443             : }
    6444             : 
    6445             : /* also static */
    6446        5406 : bool SvxMSDffManager::ReadCommonRecordHeader(SvStream& rSt,
    6447             :     sal_uInt8& rVer, sal_uInt16& rInst, sal_uInt16& rFbt, sal_uInt32& rLength)
    6448             : {
    6449        5406 :     sal_uInt16 nTmp(0);
    6450        5406 :     rSt.ReadUInt16( nTmp ).ReadUInt16( rFbt ).ReadUInt32( rLength );
    6451        5406 :     rVer = sal::static_int_cast< sal_uInt8 >(nTmp & 15);
    6452        5406 :     rInst = nTmp >> 4;
    6453        5406 :     if (!rSt.good())
    6454         338 :         return false;
    6455        5068 :     if (rLength > nMaxLegalDffRecordLength)
    6456           0 :         return false;
    6457        5068 :     return true;
    6458             : }
    6459             : 
    6460         200 : bool SvxMSDffManager::ProcessClientAnchor(SvStream& rStData, sal_uInt32 nDatLen,
    6461             :                                           char*& rpBuff, sal_uInt32& rBuffLen ) const
    6462             : {
    6463         200 :     if( nDatLen )
    6464             :     {
    6465         200 :         rBuffLen = std::min(rStData.remainingSize(), static_cast<sal_uInt64>(nDatLen));
    6466         200 :         rpBuff = new char[rBuffLen];
    6467         200 :         rBuffLen = rStData.Read(rpBuff, rBuffLen);
    6468             :     }
    6469         200 :     return true;
    6470             : }
    6471             : 
    6472         540 : bool SvxMSDffManager::ProcessClientData(SvStream& rStData, sal_uInt32 nDatLen,
    6473             :                                         char*& rpBuff, sal_uInt32& rBuffLen ) const
    6474             : {
    6475         540 :     if( nDatLen )
    6476             :     {
    6477         540 :         rBuffLen = std::min(rStData.remainingSize(), static_cast<sal_uInt64>(nDatLen));
    6478         540 :         rpBuff = new char[rBuffLen];
    6479         540 :         rBuffLen = rStData.Read(rpBuff, rBuffLen);
    6480             :     }
    6481         540 :     return true;
    6482             : }
    6483             : 
    6484             : 
    6485         200 : void SvxMSDffManager::ProcessClientAnchor2( SvStream& /* rSt */, DffRecordHeader& /* rHd */ , void* /* pData */, DffObjData& /* rObj */ )
    6486             : {
    6487         200 :     return;  // will be overloaded by SJ in Draw
    6488             : }
    6489             : 
    6490         188 : sal_uLong SvxMSDffManager::Calc_nBLIPPos( sal_uLong nOrgVal, sal_uLong /* nStreamPos */ ) const
    6491             : {
    6492         188 :     return nOrgVal;
    6493             : }
    6494             : 
    6495          58 : bool SvxMSDffManager::GetOLEStorageName( long /* nOLEId */, OUString&, SvStorageRef&, uno::Reference < embed::XStorage >& ) const
    6496             : {
    6497          58 :     return false;
    6498             : }
    6499             : 
    6500           0 : bool SvxMSDffManager::ShapeHasText( sal_uLong /* nShapeId */, sal_uLong /* nFilePos */ ) const
    6501             : {
    6502           0 :     return true;
    6503             : }
    6504             : 
    6505             : // #i32596# - add new parameter <_nCalledByGroup>
    6506          58 : SdrObject* SvxMSDffManager::ImportOLE( long nOLEId,
    6507             :                                        const Graphic& rGrf,
    6508             :                                        const Rectangle& rBoundRect,
    6509             :                                        const Rectangle& rVisArea,
    6510             :                                        const int /* _nCalledByGroup */,
    6511             :                                        sal_Int64 nAspect ) const
    6512             : {
    6513          58 :     SdrObject* pRet = 0;
    6514          58 :     OUString sStorageName;
    6515         116 :     SvStorageRef xSrcStg;
    6516          58 :     ErrCode nError = ERRCODE_NONE;
    6517         116 :     uno::Reference < embed::XStorage > xDstStg;
    6518          58 :     if( GetOLEStorageName( nOLEId, sStorageName, xSrcStg, xDstStg ))
    6519             :         pRet = CreateSdrOLEFromStorage( sStorageName, xSrcStg, xDstStg,
    6520             :                                         rGrf, rBoundRect, rVisArea, pStData, nError,
    6521           0 :                                         nSvxMSDffOLEConvFlags, nAspect );
    6522         116 :     return pRet;
    6523             : }
    6524             : 
    6525           0 : bool SvxMSDffManager::MakeContentStream( SotStorage * pStor, const GDIMetaFile & rMtf )
    6526             : {
    6527           0 :     SotStorageStreamRef xStm = pStor->OpenSotStream(OUString(SVEXT_PERSIST_STREAM));
    6528           0 :     xStm->SetVersion( pStor->GetVersion() );
    6529           0 :     xStm->SetBufferSize( 8192 );
    6530             : 
    6531           0 :     sal_uInt16 nAspect = ASPECT_CONTENT;
    6532           0 :     sal_uLong nAdviseModes = 2;
    6533             : 
    6534           0 :     Impl_OlePres aEle( FORMAT_GDIMETAFILE );
    6535             :     // Convert the size in 1/100 mm
    6536             :     // If a not applicable MapUnit (device dependent) is used,
    6537             :     // SV tries to guess a best match for the right value
    6538           0 :     Size aSize = rMtf.GetPrefSize();
    6539           0 :     MapMode aMMSrc = rMtf.GetPrefMapMode();
    6540           0 :     MapMode aMMDst( MAP_100TH_MM );
    6541           0 :     aSize = OutputDevice::LogicToLogic( aSize, aMMSrc, aMMDst );
    6542           0 :     aEle.SetSize( aSize );
    6543           0 :      aEle.SetAspect( nAspect );
    6544           0 :     aEle.SetAdviseFlags( nAdviseModes );
    6545           0 :     aEle.SetMtf( rMtf );
    6546           0 :     aEle.Write( *xStm );
    6547             : 
    6548           0 :     xStm->SetBufferSize( 0 );
    6549           0 :     return xStm->GetError() == SVSTREAM_OK;
    6550             : }
    6551             : 
    6552             : struct ClsIDs {
    6553             :     sal_uInt32      nId;
    6554             :     const sal_Char* pSvrName;
    6555             :     const sal_Char* pDspName;
    6556             : };
    6557             : static const ClsIDs aClsIDs[] = {
    6558             : 
    6559             :     { 0x000212F0, "MSWordArt",          "Microsoft Word Art"            },
    6560             :     { 0x000212F0, "MSWordArt.2",        "Microsoft Word Art 2.0"        },
    6561             : 
    6562             :     // MS Apps
    6563             :     { 0x00030000, "ExcelWorksheet",     "Microsoft Excel Worksheet"     },
    6564             :     { 0x00030001, "ExcelChart",         "Microsoft Excel Chart"         },
    6565             :     { 0x00030002, "ExcelMacrosheet",    "Microsoft Excel Macro"         },
    6566             :     { 0x00030003, "WordDocument",       "Microsoft Word Document"       },
    6567             :     { 0x00030004, "MSPowerPoint",       "Microsoft PowerPoint"          },
    6568             :     { 0x00030005, "MSPowerPointSho",    "Microsoft PowerPoint Slide Show"},
    6569             :     { 0x00030006, "MSGraph",            "Microsoft Graph"               },
    6570             :     { 0x00030007, "MSDraw",             "Microsoft Draw"                },
    6571             :     { 0x00030008, "Note-It",            "Microsoft Note-It"             },
    6572             :     { 0x00030009, "WordArt",            "Microsoft Word Art"            },
    6573             :     { 0x0003000a, "PBrush",             "Microsoft PaintBrush Picture"  },
    6574             :     { 0x0003000b, "Equation",           "Microsoft Equation Editor"     },
    6575             :     { 0x0003000c, "Package",            "Package"                       },
    6576             :     { 0x0003000d, "SoundRec",           "Sound"                         },
    6577             :     { 0x0003000e, "MPlayer",            "Media Player"                  },
    6578             :     // MS Demos
    6579             :     { 0x0003000f, "ServerDemo",         "OLE 1.0 Server Demo"           },
    6580             :     { 0x00030010, "Srtest",             "OLE 1.0 Test Demo"             },
    6581             :     { 0x00030011, "SrtInv",             "OLE 1.0 Inv Demo"              },
    6582             :     { 0x00030012, "OleDemo",            "OLE 1.0 Demo"                  },
    6583             : 
    6584             :     // Coromandel / Dorai Swamy / 718-793-7963
    6585             :     { 0x00030013, "CoromandelIntegra",  "Coromandel Integra"            },
    6586             :     { 0x00030014, "CoromandelObjServer","Coromandel Object Server"      },
    6587             : 
    6588             :     // 3-d Visions Corp / Peter Hirsch / 310-325-1339
    6589             :     { 0x00030015, "StanfordGraphics",   "Stanford Graphics"             },
    6590             : 
    6591             :     // Deltapoint / Nigel Hearne / 408-648-4000
    6592             :     { 0x00030016, "DGraphCHART",        "DeltaPoint Graph Chart"        },
    6593             :     { 0x00030017, "DGraphDATA",         "DeltaPoint Graph Data"         },
    6594             : 
    6595             :     // Corel / Richard V. Woodend / 613-728-8200 x1153
    6596             :     { 0x00030018, "PhotoPaint",         "Corel PhotoPaint"              },
    6597             :     { 0x00030019, "CShow",              "Corel Show"                    },
    6598             :     { 0x0003001a, "CorelChart",         "Corel Chart"                   },
    6599             :     { 0x0003001b, "CDraw",              "Corel Draw"                    },
    6600             : 
    6601             :     // Inset Systems / Mark Skiba / 203-740-2400
    6602             :     { 0x0003001c, "HJWIN1.0",           "Inset Systems"                 },
    6603             : 
    6604             :     // Mark V Systems / Mark McGraw / 818-995-7671
    6605             :     { 0x0003001d, "ObjMakerOLE",        "MarkV Systems Object Maker"    },
    6606             : 
    6607             :     // IdentiTech / Mike Gilger / 407-951-9503
    6608             :     { 0x0003001e, "FYI",                "IdentiTech FYI"                },
    6609             :     { 0x0003001f, "FYIView",            "IdentiTech FYI Viewer"         },
    6610             : 
    6611             :     // Inventa Corporation / Balaji Varadarajan / 408-987-0220
    6612             :     { 0x00030020, "Stickynote",         "Inventa Sticky Note"           },
    6613             : 
    6614             :     // ShapeWare Corp. / Lori Pearce / 206-467-6723
    6615             :     { 0x00030021, "ShapewareVISIO10",   "Shapeware Visio 1.0"           },
    6616             :     { 0x00030022, "ImportServer",       "Spaheware Import Server"       },
    6617             : 
    6618             :     // test app SrTest
    6619             :     { 0x00030023, "SrvrTest",           "OLE 1.0 Server Test"           },
    6620             : 
    6621             :     // test app ClTest.  Doesn't really work as a server but is in reg db
    6622             :     { 0x00030025, "Cltest",             "OLE 1.0 Client Test"           },
    6623             : 
    6624             :     // Microsoft ClipArt Gallery   Sherry Larsen-Holmes
    6625             :     { 0x00030026, "MS_ClipArt_Gallery", "Microsoft ClipArt Gallery"     },
    6626             :     // Microsoft Project  Cory Reina
    6627             :     { 0x00030027, "MSProject",          "Microsoft Project"             },
    6628             : 
    6629             :     // Microsoft Works Chart
    6630             :     { 0x00030028, "MSWorksChart",       "Microsoft Works Chart"         },
    6631             : 
    6632             :     // Microsoft Works Spreadsheet
    6633             :     { 0x00030029, "MSWorksSpreadsheet", "Microsoft Works Spreadsheet"   },
    6634             : 
    6635             :     // AFX apps - Dean McCrory
    6636             :     { 0x0003002A, "MinSvr",             "AFX Mini Server"               },
    6637             :     { 0x0003002B, "HierarchyList",      "AFX Hierarchy List"            },
    6638             :     { 0x0003002C, "BibRef",             "AFX BibRef"                    },
    6639             :     { 0x0003002D, "MinSvrMI",           "AFX Mini Server MI"            },
    6640             :     { 0x0003002E, "TestServ",           "AFX Test Server"               },
    6641             : 
    6642             :     // Ami Pro
    6643             :     { 0x0003002F, "AmiProDocument",     "Ami Pro Document"              },
    6644             : 
    6645             :     // WordPerfect Presentations For Windows
    6646             :     { 0x00030030, "WPGraphics",         "WordPerfect Presentation"      },
    6647             :     { 0x00030031, "WPCharts",           "WordPerfect Chart"             },
    6648             : 
    6649             :     // MicroGrafx Charisma
    6650             :     { 0x00030032, "Charisma",           "MicroGrafx Charisma"           },
    6651             :     { 0x00030033, "Charisma_30",        "MicroGrafx Charisma 3.0"       },
    6652             :     { 0x00030034, "CharPres_30",        "MicroGrafx Charisma 3.0 Pres"  },
    6653             :     // MicroGrafx Draw
    6654             :     { 0x00030035, "Draw",               "MicroGrafx Draw"               },
    6655             :     // MicroGrafx Designer
    6656             :     { 0x00030036, "Designer_40",        "MicroGrafx Designer 4.0"       },
    6657             : 
    6658             :     // STAR DIVISION
    6659             :     { 0x00043AD2, "FontWork",           "Star FontWork"                 },
    6660             : 
    6661             :     { 0, "", "" } };
    6662             : 
    6663             : 
    6664           0 : bool SvxMSDffManager::ConvertToOle2( SvStream& rStm, sal_uInt32 nReadLen,
    6665             :                     const GDIMetaFile * pMtf, const SotStorageRef& rDest )
    6666             : {
    6667           0 :     bool bMtfRead = false;
    6668             :     SotStorageStreamRef xOle10Stm = rDest->OpenSotStream( OUString("\1Ole10Native"),
    6669           0 :                                                     STREAM_WRITE| STREAM_SHARE_DENYALL );
    6670           0 :     if( xOle10Stm->GetError() )
    6671           0 :         return false;
    6672             : 
    6673             :     sal_uInt32 nType;
    6674             :     sal_uInt32 nRecType;
    6675             :     sal_uInt32 nStrLen;
    6676           0 :     OUString   aSvrName;
    6677             :     sal_uInt32 nDummy0;
    6678             :     sal_uInt32 nDummy1;
    6679             :     sal_uInt32 nDataLen;
    6680           0 :     sal_uInt32 nBytesRead = 0;
    6681           0 :     do
    6682             :     {
    6683           0 :         rStm.ReadUInt32( nType );
    6684           0 :         rStm.ReadUInt32( nRecType );
    6685           0 :         rStm.ReadUInt32( nStrLen );
    6686           0 :         if( nStrLen )
    6687             :         {
    6688           0 :             if( 0x10000L > nStrLen )
    6689             :             {
    6690           0 :                 boost::scoped_array<sal_Char> pBuf(new sal_Char[ nStrLen ]);
    6691           0 :                 rStm.Read( pBuf.get(), nStrLen );
    6692           0 :                 aSvrName = OUString( pBuf.get(), (sal_uInt16) nStrLen-1, osl_getThreadTextEncoding() );
    6693             :             }
    6694             :             else
    6695           0 :                 break;
    6696             :         }
    6697           0 :         rStm.ReadUInt32( nDummy0 );
    6698           0 :         rStm.ReadUInt32( nDummy1 );
    6699           0 :         rStm.ReadUInt32( nDataLen );
    6700             : 
    6701           0 :         nBytesRead += 6 * sizeof( sal_uInt32 ) + nStrLen + nDataLen;
    6702             : 
    6703           0 :         if( !rStm.IsEof() && nReadLen > nBytesRead && nDataLen )
    6704             :         {
    6705           0 :             if( xOle10Stm.Is() )
    6706             :             {
    6707           0 :                 boost::scoped_array<sal_uInt8> pData(new sal_uInt8[ nDataLen ]);
    6708           0 :                 if( !pData )
    6709           0 :                     return false;
    6710             : 
    6711           0 :                 rStm.Read( pData.get(), nDataLen );
    6712             : 
    6713             :                 // write to ole10 stream
    6714           0 :                 xOle10Stm->WriteUInt32( nDataLen );
    6715           0 :                 xOle10Stm->Write( pData.get(), nDataLen );
    6716           0 :                 xOle10Stm = SotStorageStreamRef();
    6717             : 
    6718             :                 // set the compobj stream
    6719             :                 const ClsIDs* pIds;
    6720           0 :                 for( pIds = aClsIDs; pIds->nId; pIds++ )
    6721             :                 {
    6722           0 :                     if( aSvrName == OUString::createFromAscii(pIds->pSvrName) )
    6723           0 :                         break;
    6724             :                 }
    6725             : 
    6726           0 :                 if( pIds->nId )
    6727             :                 {
    6728             :                     // found!
    6729           0 :                     sal_uLong nCbFmt = SotExchange::RegisterFormatName( aSvrName );
    6730           0 :                     rDest->SetClass( SvGlobalName( pIds->nId, 0, 0, 0xc0,0,0,0,0,0,0,0x46 ), nCbFmt,
    6731           0 :                                     OUString::createFromAscii( pIds->pDspName ) );
    6732             :                 }
    6733             :                 else
    6734             :                 {
    6735           0 :                     sal_uLong nCbFmt = SotExchange::RegisterFormatName( aSvrName );
    6736           0 :                     rDest->SetClass( SvGlobalName(), nCbFmt, aSvrName );
    6737           0 :                 }
    6738             :             }
    6739           0 :             else if( nRecType == 5 && !pMtf )
    6740             :             {
    6741           0 :                 sal_uLong nPos = rStm.Tell();
    6742             :                 sal_uInt16 sz[4];
    6743           0 :                 rStm.Read( sz, 8 );
    6744           0 :                 Graphic aGraphic;
    6745           0 :                 if( ERRCODE_NONE == GraphicConverter::Import( rStm, aGraphic ) && aGraphic.GetType() )
    6746             :                 {
    6747           0 :                     const GDIMetaFile& rMtf = aGraphic.GetGDIMetaFile();
    6748           0 :                     MakeContentStream( rDest, rMtf );
    6749           0 :                     bMtfRead = true;
    6750             :                 }
    6751             :                 // set behind the data
    6752           0 :                 rStm.Seek( nPos + nDataLen );
    6753             :             }
    6754             :             else
    6755           0 :                 rStm.SeekRel( nDataLen );
    6756             :         }
    6757           0 :     } while( !rStm.IsEof() && nReadLen >= nBytesRead );
    6758             : 
    6759           0 :     if( !bMtfRead && pMtf )
    6760             :     {
    6761           0 :         MakeContentStream( rDest, *pMtf );
    6762           0 :         return true;
    6763             :     }
    6764             : 
    6765           0 :     return false;
    6766             : }
    6767             : 
    6768          40 : const char* GetInternalServerName_Impl( const SvGlobalName& aGlobName )
    6769             : {
    6770         160 :     if ( aGlobName == SvGlobalName( SO3_SW_OLE_EMBED_CLASSID_60 )
    6771         160 :       || aGlobName == SvGlobalName( SO3_SW_OLE_EMBED_CLASSID_8 ) )
    6772           0 :         return "swriter";
    6773         160 :     else if ( aGlobName == SvGlobalName( SO3_SC_OLE_EMBED_CLASSID_60 )
    6774         160 :       || aGlobName == SvGlobalName( SO3_SC_OLE_EMBED_CLASSID_8 ) )
    6775           0 :         return "scalc";
    6776         160 :     else if ( aGlobName == SvGlobalName( SO3_SIMPRESS_OLE_EMBED_CLASSID_60 )
    6777         160 :       || aGlobName == SvGlobalName( SO3_SIMPRESS_OLE_EMBED_CLASSID_8 ) )
    6778           0 :         return "simpress";
    6779         160 :     else if ( aGlobName == SvGlobalName( SO3_SDRAW_OLE_EMBED_CLASSID_60 )
    6780         160 :       || aGlobName == SvGlobalName( SO3_SDRAW_OLE_EMBED_CLASSID_8 ) )
    6781           0 :         return "sdraw";
    6782         160 :     else if ( aGlobName == SvGlobalName( SO3_SM_OLE_EMBED_CLASSID_60 )
    6783         160 :       || aGlobName == SvGlobalName( SO3_SM_OLE_EMBED_CLASSID_8 ) )
    6784           0 :         return "smath";
    6785         160 :     else if ( aGlobName == SvGlobalName( SO3_SCH_OLE_EMBED_CLASSID_60 )
    6786         160 :       || aGlobName == SvGlobalName( SO3_SCH_OLE_EMBED_CLASSID_8 ) )
    6787          10 :         return "schart";
    6788          30 :     return 0;
    6789             : }
    6790             : 
    6791          10 : OUString GetFilterNameFromClassID_Impl( const SvGlobalName& aGlobName )
    6792             : {
    6793          10 :     if ( aGlobName == SvGlobalName( SO3_SW_OLE_EMBED_CLASSID_60 ) )
    6794           0 :         return OUString( "StarOffice XML (Writer)" );
    6795             : 
    6796          10 :     if ( aGlobName == SvGlobalName( SO3_SW_OLE_EMBED_CLASSID_8 ) )
    6797           0 :         return OUString( "writer8" );
    6798             : 
    6799          10 :     if ( aGlobName == SvGlobalName( SO3_SC_OLE_EMBED_CLASSID_60 ) )
    6800           0 :         return OUString( "StarOffice XML (Calc)" );
    6801             : 
    6802          10 :     if ( aGlobName == SvGlobalName( SO3_SC_OLE_EMBED_CLASSID_8 ) )
    6803           0 :         return OUString( "calc8" );
    6804             : 
    6805          10 :     if ( aGlobName == SvGlobalName( SO3_SIMPRESS_OLE_EMBED_CLASSID_60 ) )
    6806           0 :         return OUString( "StarOffice XML (Impress)" );
    6807             : 
    6808          10 :     if ( aGlobName == SvGlobalName( SO3_SIMPRESS_OLE_EMBED_CLASSID_8 ) )
    6809           0 :         return OUString( "impress8" );
    6810             : 
    6811          10 :     if ( aGlobName == SvGlobalName( SO3_SDRAW_OLE_EMBED_CLASSID_60 ) )
    6812           0 :         return OUString( "StarOffice XML (Draw)" );
    6813             : 
    6814          10 :     if ( aGlobName == SvGlobalName( SO3_SDRAW_OLE_EMBED_CLASSID_8 ) )
    6815           0 :         return OUString( "draw8" );
    6816             : 
    6817          10 :     if ( aGlobName == SvGlobalName( SO3_SM_OLE_EMBED_CLASSID_60 ) )
    6818           0 :         return OUString( "StarOffice XML (Math)" );
    6819             : 
    6820          10 :     if ( aGlobName == SvGlobalName( SO3_SM_OLE_EMBED_CLASSID_8 ) )
    6821           0 :         return OUString( "math8" );
    6822             : 
    6823          10 :     if ( aGlobName == SvGlobalName( SO3_SCH_OLE_EMBED_CLASSID_60 ) )
    6824           0 :         return OUString( "StarOffice XML (Chart)" );
    6825             : 
    6826          10 :     if ( aGlobName == SvGlobalName( SO3_SCH_OLE_EMBED_CLASSID_8 ) )
    6827          10 :         return OUString( "chart8" );
    6828             : 
    6829           0 :     return OUString();
    6830             : }
    6831             : 
    6832          40 : com::sun::star::uno::Reference < com::sun::star::embed::XEmbeddedObject >  SvxMSDffManager::CheckForConvertToSOObj( sal_uInt32 nConvertFlags,
    6833             :                         SotStorage& rSrcStg, const uno::Reference < embed::XStorage >& rDestStorage,
    6834             :                         const Graphic& rGrf,
    6835             :                         const Rectangle& rVisArea )
    6836             : {
    6837          40 :     uno::Reference < embed::XEmbeddedObject > xObj;
    6838          80 :     SvGlobalName aStgNm = rSrcStg.GetClassName();
    6839          40 :     const char* pName = GetInternalServerName_Impl( aStgNm );
    6840          80 :     OUString sStarName;
    6841          40 :     if ( pName )
    6842          10 :         sStarName = OUString::createFromAscii( pName );
    6843          30 :     else if ( nConvertFlags )
    6844             :     {
    6845             :         static struct _ObjImpType
    6846             :         {
    6847             :             sal_uInt32 nFlag;
    6848             :             const char* pFactoryNm;
    6849             :             // GlobalNameId
    6850             :             sal_uInt32 n1;
    6851             :             sal_uInt16 n2, n3;
    6852             :             sal_uInt8 b8, b9, b10, b11, b12, b13, b14, b15;
    6853             :         } aArr[] = {
    6854             :             { OLE_MATHTYPE_2_STARMATH, "smath",
    6855             :                 0x0002ce02L, 0x0000, 0x0000,
    6856             :                 0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x46 },
    6857             :             { OLE_MATHTYPE_2_STARMATH, "smath",
    6858             :                 0x00021700L, 0x0000, 0x0000,
    6859             :                 0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x46 },
    6860             :             { OLE_WINWORD_2_STARWRITER, "swriter",
    6861             :                 0x00020906L, 0x0000, 0x0000,
    6862             :                 0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x46 },
    6863             :             { OLE_EXCEL_2_STARCALC, "scalc",                // Excel table
    6864             :                 0x00020810L, 0x0000, 0x0000,
    6865             :                 0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x46 },
    6866             :             { OLE_EXCEL_2_STARCALC, "scalc",                // Excel chart
    6867             :                 0x00020820L, 0x0000, 0x0000,
    6868             :                 0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x46 },
    6869             :             // 114465: additional Excel OLE chart classId to above.
    6870             :             { OLE_EXCEL_2_STARCALC, "scalc",
    6871             :                 0x00020821L, 0x0000, 0x0000,
    6872             :                 0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x46 },
    6873             :             { OLE_POWERPOINT_2_STARIMPRESS, "simpress",     // PowerPoint presentation
    6874             :                 0x64818d10L, 0x4f9b, 0x11cf,
    6875             :                 0x86,0xea,0x00,0xaa,0x00,0xb9,0x29,0xe8 },
    6876             :             { OLE_POWERPOINT_2_STARIMPRESS, "simpress",     // PowerPoint slide
    6877             :                 0x64818d11L, 0x4f9b, 0x11cf,
    6878             :                 0x86,0xea,0x00,0xaa,0x00,0xb9,0x29,0xe8 },
    6879             :             { 0, 0,
    6880             :               0, 0, 0,
    6881             :               0, 0, 0, 0, 0, 0, 0, 0 }
    6882             :         };
    6883             : 
    6884          98 :         for( const _ObjImpType* pArr = aArr; pArr->nFlag; ++pArr )
    6885             :         {
    6886          92 :             if( nConvertFlags & pArr->nFlag )
    6887             :             {
    6888             :                 SvGlobalName aTypeName( pArr->n1, pArr->n2, pArr->n3,
    6889             :                                 pArr->b8, pArr->b9, pArr->b10, pArr->b11,
    6890          92 :                                 pArr->b12, pArr->b13, pArr->b14, pArr->b15 );
    6891             : 
    6892          92 :                 if ( aStgNm == aTypeName )
    6893             :                 {
    6894          24 :                     sStarName = OUString::createFromAscii( pArr->pFactoryNm );
    6895          24 :                     break;
    6896          68 :                 }
    6897             :             }
    6898             :         }
    6899             :     }
    6900             : 
    6901          40 :     if ( sStarName.getLength() )
    6902             :     {
    6903             :         //TODO/MBA: check if (and when) storage and stream will be destroyed!
    6904          34 :         const SfxFilter* pFilter = 0;
    6905          34 :         ::boost::scoped_ptr<SvMemoryStream> xMemStream (new SvMemoryStream);
    6906          34 :         if ( pName )
    6907             :         {
    6908             :             // TODO/LATER: perhaps we need to retrieve VisArea and Metafile from the storage also
    6909          10 :             SotStorageStreamRef xStr = rSrcStg.OpenSotStream( OUString( "package_stream" ), STREAM_STD_READ );
    6910          10 :             xStr->ReadStream( *xMemStream );
    6911             :         }
    6912             :         else
    6913             :         {
    6914          24 :             SfxFilterMatcher aMatch( sStarName );
    6915          48 :             SotStorageRef xStorage = new SotStorage( false, *xMemStream );
    6916          24 :             rSrcStg.CopyTo( xStorage );
    6917          24 :             xStorage->Commit();
    6918          24 :             xStorage.Clear();
    6919          48 :             OUString aType = SfxFilter::GetTypeFromStorage( rSrcStg );
    6920          24 :             if ( aType.getLength() )
    6921          48 :                 pFilter = aMatch.GetFilter4EA( aType );
    6922             :         }
    6923             : 
    6924             : #if OSL_DEBUG_LEVEL > 2
    6925             :         // extract embedded ole streams into "/tmp/embedded_stream_NNN"
    6926             :         static sal_Int32 nOleCount(0);
    6927             :         OUString aTmpName("/tmp/embedded_stream_");
    6928             :         aTmpName += OUString::number(nOleCount++);
    6929             :         aTmpName += ".bin";
    6930             :         SvFileStream aTmpStream(aTmpName,STREAM_READ|STREAM_WRITE|STREAM_TRUNC);
    6931             :         xMemStream->Seek(0);
    6932             :         *xMemStream >> aTmpStream;
    6933             :         aTmpStream.Close();
    6934             : #endif
    6935          34 :         if ( pName || pFilter )
    6936             :         {
    6937             :             //Reuse current ole name
    6938          34 :             OUString aDstStgName(MSO_OLE_Obj);
    6939          34 :             aDstStgName += OUString::number(nMSOleObjCntr);
    6940             : 
    6941          60 :             OUString aFilterName;
    6942          34 :             if ( pFilter )
    6943          24 :                 aFilterName = pFilter->GetName();
    6944             :             else
    6945          10 :                 aFilterName = GetFilterNameFromClassID_Impl( aStgNm );
    6946             : 
    6947          60 :             uno::Sequence < beans::PropertyValue > aMedium( aFilterName.isEmpty() ? 2 : 3);
    6948          34 :             aMedium[0].Name = "InputStream";
    6949          60 :             uno::Reference < io::XInputStream > xStream = new ::utl::OSeekableInputStreamWrapper( *xMemStream );
    6950          34 :             aMedium[0].Value <<= xStream;
    6951          34 :             aMedium[1].Name = "URL";
    6952          34 :             aMedium[1].Value <<= OUString( "private:stream" );
    6953             : 
    6954          34 :             if ( !aFilterName.isEmpty() )
    6955             :             {
    6956          34 :                 aMedium[2].Name = "FilterName";
    6957          34 :                 aMedium[2].Value <<= aFilterName;
    6958             :             }
    6959             : 
    6960          60 :             OUString aName( aDstStgName );
    6961          60 :             comphelper::EmbeddedObjectContainer aCnt( rDestStorage );
    6962          34 :             xObj = aCnt.InsertEmbeddedObject( aMedium, aName );
    6963             : 
    6964          34 :             if ( !xObj.is() )
    6965             :             {
    6966           8 :                 if( !aFilterName.isEmpty() )
    6967             :                 {
    6968             :                     // throw the filter parameter away as workaround
    6969           8 :                     aMedium.realloc( 2 );
    6970           8 :                     xObj = aCnt.InsertEmbeddedObject( aMedium, aName );
    6971             :                 }
    6972             : 
    6973           8 :                 if ( !xObj.is() )
    6974           8 :                      return xObj;
    6975             :             }
    6976             : 
    6977             :             // TODO/LATER: ViewAspect must be passed from outside!
    6978          26 :             sal_Int64 nViewAspect = embed::Aspects::MSOLE_CONTENT;
    6979             : 
    6980             :             // JP 26.10.2001: Bug 93374 / 91928 the writer
    6981             :             // objects need the correct visarea needs the
    6982             :             // correct visarea, but this is not true for
    6983             :             // PowerPoint (see bugdoc 94908b)
    6984             :             // SJ: 19.11.2001 bug 94908, also chart objects
    6985             :             // needs the correct visarea
    6986             : 
    6987             :             // If pName is set this is an own embedded object, it should have the correct size internally
    6988             :             // TODO/LATER: it might make sence in future to set the size stored in internal object
    6989          26 :             if( !pName && ( sStarName == "swriter" || sStarName == "scalc" ) )
    6990             :             {
    6991           2 :                 MapMode aMapMode( VCLUnoHelper::UnoEmbed2VCLMapUnit( xObj->getMapUnit( nViewAspect ) ) );
    6992           2 :                 Size aSz;
    6993           2 :                 if ( rVisArea.IsEmpty() )
    6994           0 :                     aSz = lcl_GetPrefSize(rGrf, aMapMode );
    6995             :                 else
    6996             :                 {
    6997           2 :                     aSz = rVisArea.GetSize();
    6998           2 :                     aSz = OutputDevice::LogicToLogic( aSz, MapMode( MAP_100TH_MM ), aMapMode );
    6999             :                 }
    7000             : 
    7001             :                 // don't modify the object
    7002             :                 //TODO/LATER: remove those hacks, that needs to be done differently!
    7003             :                 //xIPObj->EnableSetModified( sal_False );
    7004           2 :                 awt::Size aSize;
    7005           2 :                 aSize.Width = aSz.Width();
    7006           2 :                 aSize.Height = aSz.Height();
    7007           2 :                 xObj->setVisualAreaSize( nViewAspect, aSize );
    7008             :                 //xIPObj->EnableSetModified( sal_True );
    7009             :             }
    7010          24 :             else if ( sStarName == "smath" )
    7011             :             {   // SJ: force the object to recalc its visarea
    7012             :                 //TODO/LATER: wait for PrinterChangeNotification
    7013             :                 //xIPObj->OnDocumentPrinterChanged( NULL );
    7014          26 :             }
    7015          26 :         }
    7016             :     }
    7017             : 
    7018          32 :     return xObj;
    7019             : }
    7020             : 
    7021             : // TODO/MBA: code review and testing!
    7022          32 : SdrOle2Obj* SvxMSDffManager::CreateSdrOLEFromStorage(
    7023             :                 const OUString& rStorageName,
    7024             :                 SotStorageRef& rSrcStorage,
    7025             :                 const uno::Reference < embed::XStorage >& xDestStorage,
    7026             :                 const Graphic& rGrf,
    7027             :                 const Rectangle& rBoundRect,
    7028             :                 const Rectangle& rVisArea,
    7029             :                 SvStream* pDataStrm,
    7030             :                 ErrCode& rError,
    7031             :                 sal_uInt32 nConvertFlags,
    7032             :                 sal_Int64 nRecommendedAspect )
    7033             : {
    7034          32 :     sal_Int64 nAspect = nRecommendedAspect;
    7035          32 :     SdrOle2Obj* pRet = 0;
    7036          32 :     if( rSrcStorage.Is() && xDestStorage.is() && rStorageName.getLength() )
    7037             :     {
    7038          32 :         comphelper::EmbeddedObjectContainer aCnt( xDestStorage );
    7039             :         // does the 01Ole-Stream exist at all?
    7040             :         // (that's not the case for e.g. Fontwork )
    7041             :         // If that's not the case -> include it as graphic
    7042          32 :         bool bValidStorage = false;
    7043          64 :         OUString aDstStgName(MSO_OLE_Obj);
    7044             : 
    7045          32 :         aDstStgName += OUString::number( ++nMSOleObjCntr );
    7046             : 
    7047             :         {
    7048             :             SvStorageRef xObjStg = rSrcStorage->OpenSotStorage( rStorageName,
    7049          32 :                                 STREAM_READWRITE| STREAM_SHARE_DENYALL );
    7050          32 :             if( xObjStg.Is()  )
    7051             :             {
    7052             :                 {
    7053             :                     sal_uInt8 aTestA[10];   // exist the \1CompObj-Stream ?
    7054          32 :                     SvStorageStreamRef xSrcTst = xObjStg->OpenSotStream( OUString( "\1CompObj" ) );
    7055          64 :                     bValidStorage = xSrcTst.Is() && sizeof( aTestA ) ==
    7056          64 :                                     xSrcTst->Read( aTestA, sizeof( aTestA ) );
    7057          32 :                     if( !bValidStorage )
    7058             :                     {
    7059             :                         // or the \1Ole-Stream ?
    7060           0 :                         xSrcTst = xObjStg->OpenSotStream( OUString( "\1Ole" ) );
    7061           0 :                         bValidStorage = xSrcTst.Is() && sizeof(aTestA) ==
    7062           0 :                                         xSrcTst->Read(aTestA, sizeof(aTestA));
    7063          32 :                     }
    7064             :                 }
    7065             : 
    7066          32 :                 if( bValidStorage )
    7067             :                 {
    7068          32 :                     if ( nAspect != embed::Aspects::MSOLE_ICON )
    7069             :                     {
    7070             :                         // check whether the object is iconified one
    7071             :                         // usually this information is already known, the only exception
    7072             :                         // is a kind of embedded objects in Word documents
    7073             :                         // TODO/LATER: should the caller be notified if the aspect changes in future?
    7074             : 
    7075             :                         SvStorageStreamRef xObjInfoSrc = xObjStg->OpenSotStream(
    7076          30 :                             OUString( "\3ObjInfo" ), STREAM_STD_READ | STREAM_NOCREATE );
    7077          30 :                         if ( xObjInfoSrc.Is() && !xObjInfoSrc->GetError() )
    7078             :                         {
    7079          28 :                             sal_uInt8 nByte = 0;
    7080          28 :                             xObjInfoSrc->ReadUChar( nByte );
    7081          28 :                             if ( ( nByte >> 4 ) & embed::Aspects::MSOLE_ICON )
    7082           0 :                                 nAspect = embed::Aspects::MSOLE_ICON;
    7083          30 :                         }
    7084             :                     }
    7085             : 
    7086             :                     uno::Reference < embed::XEmbeddedObject > xObj( CheckForConvertToSOObj(
    7087          32 :                                 nConvertFlags, *xObjStg, xDestStorage, rGrf, rVisArea ));
    7088          32 :                     if ( xObj.is() )
    7089             :                     {
    7090          24 :                         svt::EmbeddedObjectRef aObj( xObj, nAspect );
    7091             : 
    7092             :                         // TODO/LATER: need MediaType
    7093          24 :                         aObj.SetGraphic( rGrf, OUString() );
    7094             : 
    7095             :                         // TODO/MBA: check setting of PersistName
    7096          24 :                         pRet = new SdrOle2Obj( aObj, OUString(), rBoundRect, false);
    7097             :                         // we have the Object, don't create another
    7098          24 :                         bValidStorage = false;
    7099          32 :                     }
    7100             :                 }
    7101          32 :             }
    7102             :         }
    7103             : 
    7104          32 :         if( bValidStorage )
    7105             :         {
    7106             :             // object is not an own object
    7107           8 :             SotStorageRef xObjStor = SotStorage::OpenOLEStorage( xDestStorage, aDstStgName, STREAM_READWRITE );
    7108             : 
    7109           8 :             if ( xObjStor.Is() )
    7110             :             {
    7111           8 :                 SotStorageRef xSrcStor = rSrcStorage->OpenSotStorage( rStorageName, STREAM_READ );
    7112           8 :                 xSrcStor->CopyTo( xObjStor );
    7113             : 
    7114           8 :                 if( !xObjStor->GetError() )
    7115           6 :                     xObjStor->Commit();
    7116             : 
    7117           8 :                 if( xObjStor->GetError() )
    7118             :                 {
    7119           2 :                     rError = xObjStor->GetError();
    7120           2 :                     bValidStorage = false;
    7121             :                 }
    7122           6 :                 else if( !xObjStor.Is() )
    7123           0 :                     bValidStorage = false;
    7124           8 :             }
    7125             :         }
    7126          24 :         else if( pDataStrm )
    7127             :         {
    7128             :             sal_uInt32 nLen, nDummy;
    7129          22 :             pDataStrm->ReadUInt32( nLen ).ReadUInt32( nDummy );
    7130          44 :             if( SVSTREAM_OK != pDataStrm->GetError() ||
    7131             :                 // Id in BugDoc - exist there other Ids?
    7132             :                 // The ConvertToOle2 - does not check for consistent
    7133          22 :                 0x30008 != nDummy )
    7134          22 :                 bValidStorage = false;
    7135             :             else
    7136             :             {
    7137             :                 // or is it an OLE-1 Stream in the DataStream?
    7138           0 :                 SvStorageRef xObjStor = SotStorage::OpenOLEStorage( xDestStorage, aDstStgName );
    7139             :                 //TODO/MBA: remove metafile conversion from ConvertToOle2
    7140             :                 //when is this code used?!
    7141           0 :                 GDIMetaFile aMtf;
    7142           0 :                 bValidStorage = ConvertToOle2( *pDataStrm, nLen, &aMtf, xObjStor );
    7143           0 :                 xObjStor->Commit();
    7144             :             }
    7145             :         }
    7146             : 
    7147          32 :         if( bValidStorage )
    7148             :         {
    7149           6 :             uno::Reference < embed::XEmbeddedObject > xObj = aCnt.GetEmbeddedObject( aDstStgName );
    7150           6 :             if( xObj.is() )
    7151             :             {
    7152             :                 // the visual area must be retrieved from the metafile (object doesn't know it so far)
    7153             : 
    7154           6 :                 if ( nAspect != embed::Aspects::MSOLE_ICON )
    7155             :                 {
    7156             :                     // working with visual area can switch the object to running state
    7157           4 :                     awt::Size aAwtSz;
    7158             :                     try
    7159             :                     {
    7160             :                         // the provided visual area should be used, if there is any
    7161           4 :                         if ( rVisArea.IsEmpty() )
    7162             :                         {
    7163           0 :                             MapUnit aMapUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xObj->getMapUnit( nAspect ) );
    7164           0 :                             Size aSz(lcl_GetPrefSize(rGrf, MapMode(aMapUnit)));
    7165           0 :                             aAwtSz.Width = aSz.Width();
    7166           0 :                             aAwtSz.Height = aSz.Height();
    7167             :                         }
    7168             :                         else
    7169             :                         {
    7170           4 :                             aAwtSz.Width = rVisArea.GetWidth();
    7171           4 :                             aAwtSz.Height = rVisArea.GetHeight();
    7172             :                         }
    7173             :                         //xInplaceObj->EnableSetModified( sal_False );
    7174           4 :                         xObj->setVisualAreaSize( nAspect, aAwtSz );
    7175             :                         //xInplaceObj->EnableSetModified( sal_True );
    7176             :                     }
    7177           0 :                     catch( const uno::Exception& )
    7178             :                     {
    7179             :                         OSL_FAIL( "Could not set visual area of the object!\n" );
    7180             :                     }
    7181             :                 }
    7182             : 
    7183           6 :                 svt::EmbeddedObjectRef aObj( xObj, nAspect );
    7184             : 
    7185             :                 // TODO/LATER: need MediaType
    7186           6 :                 aObj.SetGraphic( rGrf, OUString() );
    7187             : 
    7188           6 :                 pRet = new SdrOle2Obj( aObj, aDstStgName, rBoundRect, false);
    7189           6 :             }
    7190          32 :         }
    7191             :     }
    7192             : 
    7193          32 :     return pRet;
    7194             : }
    7195             : 
    7196          16 : bool SvxMSDffManager::SetPropValue( const uno::Any& rAny, const uno::Reference< ::com::sun::star::beans::XPropertySet > & rXPropSet,
    7197             :             const OUString& rPropName, bool bTestPropertyAvailability )
    7198             : {
    7199          16 :     bool bRetValue = true;
    7200          16 :     if ( bTestPropertyAvailability )
    7201             :     {
    7202          16 :         bRetValue = false;
    7203             :         try
    7204             :         {
    7205             :             uno::Reference< beans::XPropertySetInfo >
    7206          16 :                 aXPropSetInfo( rXPropSet->getPropertySetInfo() );
    7207          16 :             if ( aXPropSetInfo.is() )
    7208          16 :                 bRetValue = aXPropSetInfo->hasPropertyByName( rPropName );
    7209             :         }
    7210           0 :         catch( const uno::Exception& )
    7211             :         {
    7212           0 :             bRetValue = false;
    7213             :         }
    7214             :     }
    7215          16 :     if ( bRetValue )
    7216             :     {
    7217             :         try
    7218             :         {
    7219          16 :             rXPropSet->setPropertyValue( rPropName, rAny );
    7220          16 :             bRetValue = true;
    7221             :         }
    7222           0 :         catch( const uno::Exception& )
    7223             :         {
    7224           0 :             bRetValue = false;
    7225             :         }
    7226             :     }
    7227          16 :     return bRetValue;
    7228             : }
    7229             : 
    7230         810 : SvxMSDffImportRec::SvxMSDffImportRec()
    7231             :     : pObj( 0 ),
    7232             :       pWrapPolygon(0),
    7233             :       pClientAnchorBuffer( 0 ),
    7234             :       nClientAnchorLen(  0 ),
    7235             :       pClientDataBuffer( 0 ),
    7236             :       nClientDataLen(    0 ),
    7237             :       nXAlign( 0 ), // position n cm from left
    7238             :       pXRelTo( NULL ), //   relative to column
    7239             :       nYAlign( 0 ), // position n cm below
    7240             :       pYRelTo( NULL ), //   relative to paragraph
    7241             :       nLayoutInTableCell( 0 ), // element is laid out in table cell
    7242             :       nFlags( 0 ),
    7243             :       nTextRotationAngle( 0 ),
    7244             :       nDxTextLeft( 144 ),
    7245             :       nDyTextTop( 72 ),
    7246             :       nDxTextRight( 144 ),
    7247             :       nDyTextBottom( 72 ),
    7248             :       nDxWrapDistLeft( 0 ),
    7249             :       nDyWrapDistTop( 0 ),
    7250             :       nDxWrapDistRight( 0 ),
    7251             :       nDyWrapDistBottom(0 ),
    7252             :       nCropFromTop( 0 ),
    7253             :       nCropFromBottom( 0 ),
    7254             :       nCropFromLeft( 0 ),
    7255             :       nCropFromRight( 0 ),
    7256             :       aTextId( 0, 0 ),
    7257             :       nNextShapeId( 0 ),
    7258             :       nShapeId( 0 ),
    7259             :       eShapeType( mso_sptNil ),
    7260             :       relativeHorizontalWidth( -1 ),
    7261         810 :       isHorizontalRule( false )
    7262             : {
    7263         810 :       eLineStyle      = mso_lineSimple; // GPF-Bug #66227#
    7264         810 :       eLineDashing    = mso_lineSolid;
    7265         810 :       bDrawHell       = false;
    7266         810 :       bHidden         = false;
    7267             : 
    7268         810 :       bReplaceByFly   = false;
    7269         810 :       bVFlip          = false;
    7270         810 :       bHFlip          = false;
    7271         810 :       bAutoWidth      = false;
    7272         810 : }
    7273             : 
    7274           0 : SvxMSDffImportRec::SvxMSDffImportRec(const SvxMSDffImportRec& rCopy)
    7275             :     : pObj( rCopy.pObj ),
    7276             :       nXAlign( rCopy.nXAlign ),
    7277             :       pXRelTo( NULL ),
    7278             :       nYAlign( rCopy.nYAlign ),
    7279             :       pYRelTo( NULL ),
    7280             :       nLayoutInTableCell( rCopy.nLayoutInTableCell ),
    7281             :       nFlags( rCopy.nFlags ),
    7282             :       nTextRotationAngle( rCopy.nTextRotationAngle ),
    7283             :       nDxTextLeft( rCopy.nDxTextLeft    ),
    7284             :       nDyTextTop( rCopy.nDyTextTop ),
    7285             :       nDxTextRight( rCopy.nDxTextRight ),
    7286             :       nDyTextBottom( rCopy.nDyTextBottom ),
    7287             :       nDxWrapDistLeft( rCopy.nDxWrapDistLeft ),
    7288             :       nDyWrapDistTop( rCopy.nDyWrapDistTop ),
    7289             :       nDxWrapDistRight( rCopy.nDxWrapDistRight ),
    7290             :       nDyWrapDistBottom(rCopy.nDyWrapDistBottom ),
    7291             :       nCropFromTop( rCopy.nCropFromTop ),
    7292             :       nCropFromBottom( rCopy.nCropFromBottom ),
    7293             :       nCropFromLeft( rCopy.nCropFromLeft ),
    7294             :       nCropFromRight( rCopy.nCropFromRight ),
    7295             :       aTextId( rCopy.aTextId ),
    7296             :       nNextShapeId( rCopy.nNextShapeId ),
    7297             :       nShapeId( rCopy.nShapeId ),
    7298             :       eShapeType( rCopy.eShapeType ),
    7299             :       relativeHorizontalWidth( rCopy.relativeHorizontalWidth ),
    7300           0 :       isHorizontalRule( rCopy.isHorizontalRule )
    7301             : {
    7302           0 :     if (rCopy.pXRelTo)
    7303             :     {
    7304           0 :        pXRelTo = new sal_uInt32;
    7305           0 :        *pXRelTo = *(rCopy.pXRelTo);
    7306             :     }
    7307           0 :     if (rCopy.pYRelTo)
    7308             :     {
    7309           0 :        pYRelTo = new sal_uInt32;
    7310           0 :        *pYRelTo = *(rCopy.pYRelTo);
    7311             :     }
    7312           0 :     eLineStyle       = rCopy.eLineStyle; // GPF-Bug #66227#
    7313           0 :     eLineDashing     = rCopy.eLineDashing;
    7314           0 :     bDrawHell        = rCopy.bDrawHell;
    7315           0 :     bHidden          = rCopy.bHidden;
    7316           0 :     bReplaceByFly    = rCopy.bReplaceByFly;
    7317           0 :     bAutoWidth       = rCopy.bAutoWidth;
    7318           0 :     bVFlip = rCopy.bVFlip;
    7319           0 :     bHFlip = rCopy.bHFlip;
    7320           0 :     nClientAnchorLen = rCopy.nClientAnchorLen;
    7321           0 :     if( rCopy.nClientAnchorLen )
    7322             :     {
    7323           0 :         pClientAnchorBuffer = new char[ nClientAnchorLen ];
    7324             :         memcpy( pClientAnchorBuffer,
    7325             :                 rCopy.pClientAnchorBuffer,
    7326           0 :                 nClientAnchorLen );
    7327             :     }
    7328             :     else
    7329           0 :         pClientAnchorBuffer = 0;
    7330             : 
    7331           0 :     nClientDataLen = rCopy.nClientDataLen;
    7332           0 :     if( rCopy.nClientDataLen )
    7333             :     {
    7334           0 :         pClientDataBuffer = new char[ nClientDataLen ];
    7335             :         memcpy( pClientDataBuffer,
    7336             :                 rCopy.pClientDataBuffer,
    7337           0 :                 nClientDataLen );
    7338             :     }
    7339             :     else
    7340           0 :         pClientDataBuffer = 0;
    7341             : 
    7342           0 :     if (rCopy.pWrapPolygon)
    7343           0 :         pWrapPolygon = new Polygon(*rCopy.pWrapPolygon);
    7344             :     else
    7345           0 :         pWrapPolygon = 0;
    7346           0 : }
    7347             : 
    7348         810 : SvxMSDffImportRec::~SvxMSDffImportRec()
    7349             : {
    7350         810 :     delete[] pClientAnchorBuffer;
    7351         810 :     delete[] pClientDataBuffer;
    7352         810 :     delete pWrapPolygon;
    7353         810 :     delete pXRelTo;
    7354         810 :     delete pYRelTo;
    7355         810 : }
    7356             : 
    7357        2642 : void SvxMSDffManager::insertShapeId( sal_Int32 nShapeId, SdrObject* pShape )
    7358             : {
    7359        2642 :     maShapeIdContainer[nShapeId] = pShape;
    7360        2642 : }
    7361             : 
    7362        1762 : void SvxMSDffManager::removeShapeId( SdrObject* pShape )
    7363             : {
    7364        1762 :     SvxMSDffShapeIdContainer::iterator aIter( maShapeIdContainer.begin() );
    7365        1762 :     const SvxMSDffShapeIdContainer::iterator aEnd( maShapeIdContainer.end() );
    7366      132196 :     while( aIter != aEnd )
    7367             :     {
    7368      130434 :         if( (*aIter).second == pShape )
    7369             :         {
    7370        1762 :             maShapeIdContainer.erase( aIter );
    7371        1762 :             break;
    7372             :         }
    7373      128672 :         ++aIter;
    7374             :     }
    7375        1762 : }
    7376             : 
    7377         308 : SdrObject* SvxMSDffManager::getShapeForId( sal_Int32 nShapeId )
    7378             : {
    7379         308 :     SvxMSDffShapeIdContainer::iterator aIter( maShapeIdContainer.find(nShapeId) );
    7380         308 :     return aIter != maShapeIdContainer.end() ? (*aIter).second : 0;
    7381         570 : }
    7382             : 
    7383             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10