diff options
author | Daniel Rentz [dr] <daniel.rentz@oracle.com> | 2011-01-04 18:51:14 +0100 |
---|---|---|
committer | Daniel Rentz [dr] <daniel.rentz@oracle.com> | 2011-01-04 18:51:14 +0100 |
commit | c15fb91736dfb70247d864267290d0053a05267c (patch) | |
tree | 0fe4b29ce3091812bda56cbccdf137594f067f3f /oox/source/drawingml | |
parent | 673e27f14bbf6ebd8e72c4715f7b34dcc6310519 (diff) |
dr78: oox - import of BIFF3-BIFF5 drawing objects - first bits
Diffstat (limited to 'oox/source/drawingml')
-rw-r--r-- | oox/source/drawingml/chart/chartdrawingfragment.cxx | 55 | ||||
-rw-r--r-- | oox/source/drawingml/shape.cxx | 5 |
2 files changed, 35 insertions, 25 deletions
diff --git a/oox/source/drawingml/chart/chartdrawingfragment.cxx b/oox/source/drawingml/chart/chartdrawingfragment.cxx index fcc350b583c3..f4d4ab8daf59 100644 --- a/oox/source/drawingml/chart/chartdrawingfragment.cxx +++ b/oox/source/drawingml/chart/chartdrawingfragment.cxx @@ -83,42 +83,41 @@ void ShapeAnchor::setPos( sal_Int32 nElement, sal_Int32 nParentContext, const OU } } -Rectangle ShapeAnchor::calcEmuLocation( const EmuRectangle& rEmuChartRect ) const +EmuRectangle ShapeAnchor::calcAnchorRectEmu( const EmuRectangle& rChartRect ) const { - Rectangle aLoc( -1, -1, -1, -1 ); + EmuRectangle aAnchorRect( -1, -1, -1, -1 ); - OSL_ENSURE( maFrom.isValid(), "ShapeAnchor::calcEmuLocation - invalid from position" ); - OSL_ENSURE( mbRelSize ? maTo.isValid() : maSize.isValid(), "ShapeAnchor::calcEmuLocation - invalid to/size" ); + OSL_ENSURE( maFrom.isValid(), "ShapeAnchor::calcAnchorRectEmu - invalid from position" ); + OSL_ENSURE( mbRelSize ? maTo.isValid() : maSize.isValid(), "ShapeAnchor::calcAnchorRectEmu - invalid to/size" ); if( maFrom.isValid() && (mbRelSize ? maTo.isValid() : maSize.isValid()) ) { // calculate shape position - aLoc.X = getLimitedValue< sal_Int32, double >( maFrom.mfX * rEmuChartRect.Width, 0, SAL_MAX_INT32 ); - aLoc.Y = getLimitedValue< sal_Int32, double >( maFrom.mfY * rEmuChartRect.Height, 0, SAL_MAX_INT32 ); + aAnchorRect.X = static_cast< sal_Int64 >( maFrom.mfX * rChartRect.Width + 0.5 ); + aAnchorRect.Y = static_cast< sal_Int64 >( maFrom.mfY * rChartRect.Height + 0.5 ); // calculate shape size if( mbRelSize ) { - aLoc.Width = getLimitedValue< sal_Int32, double >( maTo.mfX * rEmuChartRect.Width, 0, SAL_MAX_INT32 ) - aLoc.X; - if( aLoc.Width < 0 ) + aAnchorRect.Width = static_cast< sal_Int64 >( maTo.mfX * rChartRect.Width + 0.5 ) - aAnchorRect.X; + if( aAnchorRect.Width < 0 ) { - aLoc.X += aLoc.Width; - aLoc.Width *= -1; + aAnchorRect.X += aAnchorRect.Width; + aAnchorRect.Width *= -1; } - aLoc.Height = getLimitedValue< sal_Int32, double >( maTo.mfY * rEmuChartRect.Height, 0, SAL_MAX_INT32 ) - aLoc.Y; - if( aLoc.Height < 0 ) + aAnchorRect.Height = static_cast< sal_Int64 >( maTo.mfY * rChartRect.Height + 0.5 ) - aAnchorRect.Y; + if( aAnchorRect.Height < 0 ) { - aLoc.Y += aLoc.Height; - aLoc.Height *= -1; + aAnchorRect.Y += aAnchorRect.Height; + aAnchorRect.Height *= -1; } } else { - aLoc.Width = getLimitedValue< sal_Int32, sal_Int64 >( maSize.Width, 0, SAL_MAX_INT32 ); - aLoc.Height = getLimitedValue< sal_Int32, sal_Int64 >( maSize.Height, 0, SAL_MAX_INT32 ); + aAnchorRect.setSize( maSize ); } } - return aLoc; + return aAnchorRect; } // ============================================================================ @@ -129,10 +128,10 @@ ChartDrawingFragment::ChartDrawingFragment( XmlFilterBase& rFilter, mxDrawPage( rxDrawPage ), mbOleSupport( bOleSupport ) { - maEmuChartRect.X = static_cast< sal_Int64 >( rShapesOffset.X ) * 360; - maEmuChartRect.Y = static_cast< sal_Int64 >( rShapesOffset.Y ) * 360; - maEmuChartRect.Width = static_cast< sal_Int64 >( rChartSize.Width ) * 360; - maEmuChartRect.Height = static_cast< sal_Int64 >( rChartSize.Height ) * 360; + maChartRectEmu.X = convertHmmToEmu( rShapesOffset.X ); + maChartRectEmu.Y = convertHmmToEmu( rShapesOffset.Y ); + maChartRectEmu.Width = convertHmmToEmu( rChartSize.Width ); + maChartRectEmu.Height = convertHmmToEmu( rChartSize.Height ); } ChartDrawingFragment::~ChartDrawingFragment() @@ -217,9 +216,17 @@ void ChartDrawingFragment::onEndElement( const OUString& rChars ) case CDR_TOKEN( relSizeAnchor ): if( mxDrawPage.is() && mxShape.get() && mxAnchor.get() ) { - Rectangle aLoc = mxAnchor->calcEmuLocation( maEmuChartRect ); - if( (aLoc.X >= 0) && (aLoc.Y >= 0) && (aLoc.Width >= 0) && (aLoc.Height >= 0) ) - mxShape->addShape( getFilter(), getFilter().getCurrentTheme(), mxDrawPage, &aLoc ); + EmuRectangle aShapeRectEmu = mxAnchor->calcAnchorRectEmu( maChartRectEmu ); + if( (aShapeRectEmu.X >= 0) && (aShapeRectEmu.Y >= 0) && (aShapeRectEmu.Width >= 0) && (aShapeRectEmu.Height >= 0) ) + { + // TODO: DrawingML implementation expects 32-bit coordinates for EMU rectangles (change that to EmuRectangle) + Rectangle aShapeRectEmu32( + getLimitedValue< sal_Int32, sal_Int64 >( aShapeRectEmu.X, 0, SAL_MAX_INT32 ), + getLimitedValue< sal_Int32, sal_Int64 >( aShapeRectEmu.Y, 0, SAL_MAX_INT32 ), + getLimitedValue< sal_Int32, sal_Int64 >( aShapeRectEmu.Width, 0, SAL_MAX_INT32 ), + getLimitedValue< sal_Int32, sal_Int64 >( aShapeRectEmu.Height, 0, SAL_MAX_INT32 ) ); + mxShape->addShape( getFilter(), getFilter().getCurrentTheme(), mxDrawPage, &aShapeRectEmu32 ); + } } mxShape.reset(); mxAnchor.reset(); diff --git a/oox/source/drawingml/shape.cxx b/oox/source/drawingml/shape.cxx index f0ae2ec2a7a3..4d15886a641a 100644 --- a/oox/source/drawingml/shape.cxx +++ b/oox/source/drawingml/shape.cxx @@ -259,7 +259,10 @@ Reference< XShape > Shape::createAndInsert( OUString aServiceName = rServiceName; if( mxCreateCallback.get() ) - aServiceName = mxCreateCallback->onCreateXShape( aServiceName, awt::Rectangle( aPosition.X / 360, aPosition.Y / 360, aSize.Width / 360, aSize.Height / 360 ) ); + { + awt::Rectangle aShapeRectHmm( convertEmuToHmm( aPosition.X ), convertEmuToHmm( aPosition.Y ), convertEmuToHmm( aSize.Width ), convertEmuToHmm( aSize.Height ) ); + aServiceName = mxCreateCallback->onCreateXShape( aServiceName, aShapeRectHmm ); + } sal_Bool bIsCustomShape = aServiceName == OUString::createFromAscii( "com.sun.star.drawing.CustomShape" ); basegfx::B2DHomMatrix aTransformation; |