diff options
author | RĂ¼diger Timm <rt@openoffice.org> | 2008-04-18 13:35:06 +0000 |
---|---|---|
committer | RĂ¼diger Timm <rt@openoffice.org> | 2008-04-18 13:35:06 +0000 |
commit | 2df072ed934475aaf020bb0805f13fe504958342 (patch) | |
tree | ab64bf00edc5cb789ed89a5791b51433c5f737ef /oox/source/vml | |
parent | 197f66bfbeac72315b899ed7935a0d66a506cc73 (diff) |
INTEGRATION: CWS xmlfilter04 (1.2.12); FILE MERGED
2008/03/20 15:28:39 sj 1.2.12.7: fixed merge conflicts
2008/03/19 16:26:35 hbrinkm 1.2.12.6: RESYNC: (1.2-1.3); FILE MERGED
2008/02/29 17:01:15 sj 1.2.12.5: added some vml enhancements
2008/02/28 20:17:23 sj 1.2.12.4: improved vml import
2008/02/27 17:15:18 sj 1.2.12.3: added grouping of vml shapes
2008/02/26 08:35:05 hbrinkm 1.2.12.2: removed setting of size since property set threw exception
2008/02/21 12:42:06 hbrinkm 1.2.12.1: joined changes from xmlfilter03
Diffstat (limited to 'oox/source/vml')
-rw-r--r-- | oox/source/vml/vmlshape.cxx | 189 |
1 files changed, 164 insertions, 25 deletions
diff --git a/oox/source/vml/vmlshape.cxx b/oox/source/vml/vmlshape.cxx index d8ff1efac699..106eb394651f 100644 --- a/oox/source/vml/vmlshape.cxx +++ b/oox/source/vml/vmlshape.cxx @@ -7,7 +7,7 @@ * OpenOffice.org - a multi-platform office productivity suite * * $RCSfile: vmlshape.cxx,v $ - * $Revision: 1.4 $ + * $Revision: 1.5 $ * * This file is part of OpenOffice.org. * @@ -34,16 +34,17 @@ #include <com/sun/star/drawing/XEnhancedCustomShapeDefaulter.hpp> #include <com/sun/star/lang/XMultiServiceFactory.hpp> #include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/drawing/FillStyle.hpp> + using namespace com::sun::star; namespace oox { namespace vml { -Shape::Shape() -: mnShapeType( 0 ) +Shape::Shape( const rtl::OUString& rServiceName ) +: msServiceName( rServiceName ) , mnCoordWidth( 0 ) , mnCoordHeight( 0 ) , mnStroked( 0 ) -, mnFilled( 0 ) { } Shape::~Shape() @@ -56,39 +57,177 @@ void Shape::applyAttributes( const vml::Shape& rSource ) msId = rSource.msId; if ( rSource.msType.getLength() ) msType = rSource.msType; - if ( rSource.mnShapeType ) - mnShapeType = rSource.mnShapeType; + if ( rSource.msShapeType.getLength() ) + msShapeType = rSource.msShapeType; if ( rSource.mnCoordWidth ) mnCoordWidth = rSource.mnCoordWidth; if ( rSource.mnCoordHeight ) mnCoordHeight = rSource.mnCoordHeight; if ( rSource.mnStroked ) mnStroked = rSource.mnStroked; - if ( rSource.mnFilled ) - mnFilled = rSource.mnFilled; - if ( rSource.msPath.getLength() ) - msPath = rSource.msPath; + if ( rSource.moFilled ) + moFilled = rSource.moFilled; + if ( rSource.moFillColor ) + moFillColor = rSource.moFillColor; + if ( rSource.maPath.Name.getLength() ) + maPath = rSource.maPath; + if ( rSource.msPosition.getLength() ) + msPosition = rSource.msPosition; + maPosition = rSource.maPosition; + maSize = rSource.maSize; } -void Shape::addShape( const ::oox::core::XmlFilterBase& rFilterBase, - const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShapes >& rxShapes ) +::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape > Shape::createAndInsert( + const ::oox::core::XmlFilterBase& rFilterBase, const ::oox::vml::Shape& rShape, + const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShapes >& rxShapes, + const awt::Rectangle* pShapeRect ) { - ::rtl::OUString rServiceName( rtl::OUString::createFromAscii( "com.sun.star.drawing.CustomShape" ) ); - uno::Reference< lang::XMultiServiceFactory > xServiceFact( rFilterBase.getModel(), uno::UNO_QUERY_THROW ); - uno::Reference< drawing::XShape > xShape( xServiceFact->createInstance( rServiceName ), uno::UNO_QUERY_THROW ); - rxShapes->add( xShape ); + uno::Reference< drawing::XShape > xShape; + if ( rShape.msServiceName ) + { + try + { + uno::Reference< lang::XMultiServiceFactory > xServiceFact( rFilterBase.getModel(), uno::UNO_QUERY_THROW ); + xShape.set( xServiceFact->createInstance( rShape.msServiceName ), uno::UNO_QUERY_THROW ); + rxShapes->add( xShape ); + awt::Point aPosition; + awt::Size aSize; + if ( pShapeRect ) + { + aPosition.X = pShapeRect->X; + aPosition.Y = pShapeRect->Y; + aSize.Width = pShapeRect->Width; + aSize.Height = pShapeRect->Height; + } + else + { + aPosition = maPosition; + aSize = maSize; + } + xShape->setPosition( aPosition ); + xShape->setSize( aSize ); + uno::Reference< beans::XPropertySet > xPropSet( xShape, uno::UNO_QUERY ); + try + { + if ( maPath.Name.getLength() ) + xPropSet->setPropertyValue( maPath.Name, maPath.Value ); + + ::rtl::OUString sFillStyle( rtl::OUString::createFromAscii( "FillStyle" ) ); + if ( moFilled ) + xPropSet->setPropertyValue( sFillStyle, uno::Any( *moFilled ? drawing::FillStyle_SOLID : drawing::FillStyle_NONE ) ); + } + catch ( uno::Exception& ) + { + } + ::rtl::OUString rServiceName( rtl::OUString::createFromAscii( "com.sun.star.drawing.CustomShape" ) ); + if ( rShape.msShapeType.getLength() && ( msServiceName == rServiceName ) ) + { + uno::Reference< drawing::XEnhancedCustomShapeDefaulter > xDefaulter( xShape, uno::UNO_QUERY ); + if( xDefaulter.is() ) + xDefaulter->createCustomShapeDefaults( rShape.msShapeType ); + } + mxShape = xShape; + } + catch( uno::Exception& ) + { + } + } + return xShape; +} - static const ::rtl::OUString sShapePresetType(RTL_CONSTASCII_USTRINGPARAM("smiley")); +void Shape::addChilds( const ::oox::core::XmlFilterBase& rFilterBase, const ::oox::vml::Drawing& rDrawing, + const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShapes >& rxShapes, + const awt::Rectangle& rClientRect ) +{ + sal_Int32 nGlobalLeft = SAL_MAX_INT32; + sal_Int32 nGlobalRight = SAL_MIN_INT32; + sal_Int32 nGlobalTop = SAL_MAX_INT32; + sal_Int32 nGlobalBottom= SAL_MIN_INT32; + std::vector< ShapePtr >::iterator aIter( maChilds.begin() ); + while( aIter != maChilds.end() ) + { + sal_Int32 l = (*aIter)->maPosition.X; + sal_Int32 t = (*aIter)->maPosition.Y; + sal_Int32 r = l + (*aIter)->maSize.Width; + sal_Int32 b = t + (*aIter)->maSize.Height; + if ( nGlobalLeft > l ) + nGlobalLeft = l; + if ( nGlobalRight < r ) + nGlobalRight = r; + if ( nGlobalTop > t ) + nGlobalTop = t; + if ( nGlobalBottom < b ) + nGlobalBottom = b; + aIter++; + } + aIter = maChilds.begin(); + while( aIter != maChilds.end() ) + { + awt::Rectangle aShapeRect; + awt::Rectangle* pShapeRect = 0; + if ( ( nGlobalLeft != SAL_MAX_INT32 ) && ( nGlobalRight != SAL_MIN_INT32 ) && ( nGlobalTop != SAL_MAX_INT32 ) && ( nGlobalBottom != SAL_MIN_INT32 ) ) + { + sal_Int32 nGlobalWidth = nGlobalRight - nGlobalLeft; + sal_Int32 nGlobalHeight = nGlobalBottom - nGlobalTop; + if ( nGlobalWidth && nGlobalHeight ) + { + double fWidth = (*aIter)->maSize.Width; + double fHeight= (*aIter)->maSize.Height; + double fXScale = (double)rClientRect.Width / (double)nGlobalWidth; + double fYScale = (double)rClientRect.Height / (double)nGlobalHeight; + aShapeRect.X = static_cast< sal_Int32 >( ( ( (*aIter)->maPosition.X - nGlobalLeft ) * fXScale ) + rClientRect.X ); + aShapeRect.Y = static_cast< sal_Int32 >( ( ( (*aIter)->maPosition.Y - nGlobalTop ) * fYScale ) + rClientRect.Y ); + fWidth *= fXScale; + fHeight *= fYScale; + aShapeRect.Width = static_cast< sal_Int32 >( fWidth ); + aShapeRect.Height = static_cast< sal_Int32 >( fHeight ); + pShapeRect = &aShapeRect; + } + } + (*aIter++)->addShape( rFilterBase, rDrawing, rxShapes, pShapeRect ); + } +} + +void Shape::addShape( const ::oox::core::XmlFilterBase& rFilterBase, const ::oox::vml::Drawing& rDrawing, + const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShapes >& rxShapes, + const awt::Rectangle* pShapeRect ) +{ + oox::vml::Shape aShape( msServiceName ); + if ( msType.getLength() ) + { + std::vector< ShapePtr >& rShapeTypes = const_cast< ::oox::vml::Drawing& >( rDrawing ).getShapeTypes(); + std::vector< ShapePtr >::const_iterator aShapeTypeIter( rShapeTypes.begin() ); + while( aShapeTypeIter != rShapeTypes.end() ) + { + if ( (*aShapeTypeIter)->msType == aShape.msType ) + { + aShape.applyAttributes( *(*aShapeTypeIter).get() ); + break; + } + aShapeTypeIter++; + } + } + aShape.applyAttributes( *this ); - uno::Reference< drawing::XEnhancedCustomShapeDefaulter > xDefaulter( xShape, uno::UNO_QUERY ); - if( xDefaulter.is() ) - xDefaulter->createCustomShapeDefaults( sShapePresetType ); + // creating XShape + uno::Reference< drawing::XShape > xShape( createAndInsert( rFilterBase, aShape, rxShapes, pShapeRect ) ); - uno::Reference< beans::XPropertySet > xPropSet( xShape, uno::UNO_QUERY_THROW ); - static const rtl::OUString sWidth(RTL_CONSTASCII_USTRINGPARAM("Width")); - static const rtl::OUString sHeight(RTL_CONSTASCII_USTRINGPARAM("Height")); - xPropSet->setPropertyValue( sWidth, uno::Any( (sal_Int32)5000 ) ); - xPropSet->setPropertyValue( sHeight, uno::Any( (sal_Int32)5000 ) ); + // creating GroupShape if possible + uno::Reference< drawing::XShapes > xShapes( xShape, uno::UNO_QUERY ); + if ( xShapes.is() ) + { + awt::Rectangle aChildRect; + if ( pShapeRect ) + aChildRect = *pShapeRect; + else + { + aChildRect.X = maPosition.X; + aChildRect.Y = maPosition.Y; + aChildRect.Width = maSize.Width; + aChildRect.Height = maSize.Height; + } + addChilds( rFilterBase, rDrawing, xShapes, aChildRect ); + } } } } |