From 41ae924469c9ec1ad76da8077014ca6598f4bd98 Mon Sep 17 00:00:00 2001 From: Radek Doulik Date: Mon, 7 Nov 2011 11:33:41 +0100 Subject: fixed remaining issues with ooxml custom shapes scaling --- svx/inc/svx/EnhancedCustomShape2d.hxx | 4 +- svx/source/customshapes/EnhancedCustomShape2d.cxx | 114 +++++++++------------- 2 files changed, 45 insertions(+), 73 deletions(-) (limited to 'svx') diff --git a/svx/inc/svx/EnhancedCustomShape2d.hxx b/svx/inc/svx/EnhancedCustomShape2d.hxx index d2228e90c743..ebd7f0bd7162 100644 --- a/svx/inc/svx/EnhancedCustomShape2d.hxx +++ b/svx/inc/svx/EnhancedCustomShape2d.hxx @@ -92,8 +92,6 @@ class EnhancedCustomShape2d : public SfxItemSet double fXScale; double fYScale; - double fXScaleOOXML; - double fYScaleOOXML; double fXRatio; double fYRatio; @@ -136,7 +134,7 @@ class EnhancedCustomShape2d : public SfxItemSet void AdaptObjColor(SdrPathObj& rObj, const SfxItemSet& rCustomShapeSet, sal_uInt32& nColorIndex, sal_uInt32 nColorCount); sal_Bool GetParameter( double& rParameterReturnValue, const com::sun::star::drawing::EnhancedCustomShapeParameter&, - const sal_Bool bReplaceGeoWidth, const sal_Bool bReplaceGeoHeight, sal_Bool& bNormal ) const; + const sal_Bool bReplaceGeoWidth, const sal_Bool bReplaceGeoHeight ) const; Point GetPoint( const com::sun::star::drawing::EnhancedCustomShapeParameterPair&, const sal_Bool bScale = sal_True, const sal_Bool bReplaceGeoSize = sal_False ) const; diff --git a/svx/source/customshapes/EnhancedCustomShape2d.cxx b/svx/source/customshapes/EnhancedCustomShape2d.cxx index e91ad20552d3..76e523e154f3 100644 --- a/svx/source/customshapes/EnhancedCustomShape2d.cxx +++ b/svx/source/customshapes/EnhancedCustomShape2d.cxx @@ -798,48 +798,37 @@ EnhancedCustomShape2d::EnhancedCustomShape2d( SdrObject* pAObj ) : default: break; } + fXScale = nCoordWidth == 0 ? 0.0 : (double)aLogicRect.GetWidth() / (double)nCoordWidth; fYScale = nCoordHeight == 0 ? 0.0 : (double)aLogicRect.GetHeight() / (double)nCoordHeight; if ( bOOXMLShape ) { - fXScaleOOXML = 1; //fXScale; - fYScaleOOXML = 1; //fYScale; - fXScale = 1.0/(double)nCoordWidth; - fYScale = 1.0/(double)nCoordHeight; - - // if ( nXRef != (sal_uInt32)nXRef != 0x80000000 && nXRef != 0 ) - // { - // fXScale *= (double)aLogicRect.GetWidth() / (double) nXRef; - // } - // if ( nYRef != (sal_uInt32)nYRef != 0x80000000 && nYRef != 0 ) - // { - // fYScale *= (double)aLogicRect.GetHeight() / (double) nYRef; - // } - } else { - fXScaleOOXML = 1; - fYScaleOOXML = 1; - - if ( (sal_uInt32)nXRef != 0x80000000 && aLogicRect.GetHeight() ) - { - fXRatio = (double)aLogicRect.GetWidth() / (double)aLogicRect.GetHeight(); - if ( fXRatio > 1 ) - fXScale /= fXRatio; - else - fXRatio = 1.0; - } + OSL_TRACE("ooxml shape, path width: %d height: %d", nCoordWidth, nCoordHeight); + if ( nCoordWidth == 0 ) + fXScale = 1.0; + if ( nCoordHeight == 0 ) + fYScale = 1.0; + } + if ( (sal_uInt32)nXRef != 0x80000000 && aLogicRect.GetHeight() ) + { + fXRatio = (double)aLogicRect.GetWidth() / (double)aLogicRect.GetHeight(); + if ( fXRatio > 1 ) + fXScale /= fXRatio; else fXRatio = 1.0; - if ( (sal_uInt32)nYRef != 0x80000000 && aLogicRect.GetWidth() ) - { - fYRatio = (double)aLogicRect.GetHeight() / (double)aLogicRect.GetWidth(); - if ( fYRatio > 1 ) - fYScale /= fYRatio; - else - fYRatio = 1.0; - } + } + else + fXRatio = 1.0; + if ( (sal_uInt32)nYRef != 0x80000000 && aLogicRect.GetWidth() ) + { + fYRatio = (double)aLogicRect.GetHeight() / (double)aLogicRect.GetWidth(); + if ( fYRatio > 1 ) + fYScale /= fYRatio; else fYRatio = 1.0; } + else + fYRatio = 1.0; sal_Int32 i, nLength = seqEquations.getLength(); @@ -982,7 +971,6 @@ Point EnhancedCustomShape2d::GetPoint( const com::sun::star::drawing::EnhancedCu { Point aRetValue; sal_Bool bExchange = ( nFlags & DFF_CUSTOMSHAPE_EXCH ) != 0; // x <-> y - sal_Bool bNormal; sal_uInt32 nPass = 0; do { @@ -995,13 +983,11 @@ Point EnhancedCustomShape2d::GetPoint( const com::sun::star::drawing::EnhancedCu const EnhancedCustomShapeParameter& rParameter = nIndex ? rPair.Second : rPair.First; if ( nPass ) // height { - GetParameter( fVal, rParameter, sal_False, bReplaceGeoSize, bNormal ); + GetParameter( fVal, rParameter, sal_False, bReplaceGeoSize ); fVal -= nCoordTop; if ( bScale ) { fVal *= fYScale; - if (bNormal) - fVal *= fYScaleOOXML; if ( nFlags & DFF_CUSTOMSHAPE_FLIP_V ) fVal = aLogicRect.GetHeight() - fVal; @@ -1010,13 +996,11 @@ Point EnhancedCustomShape2d::GetPoint( const com::sun::star::drawing::EnhancedCu } else // width { - GetParameter( fVal, rParameter, bReplaceGeoSize, sal_False, bNormal ); + GetParameter( fVal, rParameter, bReplaceGeoSize, sal_False ); fVal -= nCoordLeft; if ( bScale ) { fVal *= fXScale; - if ( bNormal ) - fVal *= fXScaleOOXML; if ( nFlags & DFF_CUSTOMSHAPE_FLIP_H ) fVal = aLogicRect.GetWidth() - fVal; @@ -1029,11 +1013,10 @@ Point EnhancedCustomShape2d::GetPoint( const com::sun::star::drawing::EnhancedCu } sal_Bool EnhancedCustomShape2d::GetParameter( double& rRetValue, const EnhancedCustomShapeParameter& rParameter, - const sal_Bool bReplaceGeoWidth, const sal_Bool bReplaceGeoHeight, sal_Bool& bNormal ) const + const sal_Bool bReplaceGeoWidth, const sal_Bool bReplaceGeoHeight ) const { rRetValue = 0.0; sal_Bool bRetValue = sal_False; - bNormal = sal_False; switch ( rParameter.Type ) { case EnhancedCustomShapeParameterType::ADJUSTMENT : @@ -1080,7 +1063,6 @@ sal_Bool EnhancedCustomShape2d::GetParameter( double& rRetValue, const EnhancedC rRetValue *= fYRatio; } } - bNormal = sal_True; } break; case EnhancedCustomShapeParameterType::LEFT : @@ -1204,9 +1186,8 @@ sal_Bool EnhancedCustomShape2d::GetHandlePosition( const sal_uInt32 nIndex, Poin double fAngle; double fRadius; - sal_Bool bNormal; - GetParameter( fRadius, aHandle.aPosition.First, sal_False, sal_False, bNormal ); - GetParameter( fAngle, aHandle.aPosition.Second, sal_False, sal_False, bNormal ); + GetParameter( fRadius, aHandle.aPosition.First, sal_False, sal_False ); + GetParameter( fAngle, aHandle.aPosition.Second, sal_False, sal_False ); double a = ( 360.0 - fAngle ) * F_PI180; double dx = fRadius * fXScale; @@ -1309,12 +1290,11 @@ sal_Bool EnhancedCustomShape2d::SetHandleControllerPosition( const sal_uInt32 nI if ( aHandle.aPosition.Second.Type == EnhancedCustomShapeParameterType::ADJUSTMENT ) aHandle.aPosition.Second.Value>>= nSecondAdjustmentValue; - sal_Bool bNormal; if ( aHandle.nFlags & HANDLE_FLAGS_POLAR ) { double fXRef, fYRef, fAngle; - GetParameter( fXRef, aHandle.aPolar.First, sal_False, sal_False, bNormal ); - GetParameter( fYRef, aHandle.aPolar.Second, sal_False, sal_False, bNormal ); + GetParameter( fXRef, aHandle.aPolar.First, sal_False, sal_False ); + GetParameter( fYRef, aHandle.aPolar.Second, sal_False, sal_False ); const double fDX = fPos1 - fXRef; fAngle = -( atan2( -fPos2 + fYRef, ( ( fDX == 0.0L ) ? 0.000000001 : fDX ) ) / F_PI180 ); double fX = ( fPos1 - fXRef ); @@ -1323,14 +1303,14 @@ sal_Bool EnhancedCustomShape2d::SetHandleControllerPosition( const sal_uInt32 nI if ( aHandle.nFlags & HANDLE_FLAGS_RADIUS_RANGE_MINIMUM ) { double fMin; - GetParameter( fMin, aHandle.aRadiusRangeMinimum, sal_False, sal_False, bNormal ); + GetParameter( fMin, aHandle.aRadiusRangeMinimum, sal_False, sal_False ); if ( fRadius < fMin ) fRadius = fMin; } if ( aHandle.nFlags & HANDLE_FLAGS_RADIUS_RANGE_MAXIMUM ) { double fMax; - GetParameter( fMax, aHandle.aRadiusRangeMaximum, sal_False, sal_False, bNormal ); + GetParameter( fMax, aHandle.aRadiusRangeMaximum, sal_False, sal_False ); if ( fRadius > fMax ) fRadius = fMax; } @@ -1358,14 +1338,14 @@ sal_Bool EnhancedCustomShape2d::SetHandleControllerPosition( const sal_uInt32 nI if ( aHandle.nFlags & HANDLE_FLAGS_RANGE_X_MINIMUM ) // check if horizontal handle needs to be within a range { double fXMin; - GetParameter( fXMin, aHandle.aXRangeMinimum, sal_False, sal_False, bNormal ); + GetParameter( fXMin, aHandle.aXRangeMinimum, sal_False, sal_False ); if ( fPos1 < fXMin ) fPos1 = fXMin; } if ( aHandle.nFlags & HANDLE_FLAGS_RANGE_X_MAXIMUM ) // check if horizontal handle needs to be within a range { double fXMax; - GetParameter( fXMax, aHandle.aXRangeMaximum, sal_False, sal_False, bNormal ); + GetParameter( fXMax, aHandle.aXRangeMaximum, sal_False, sal_False ); if ( fPos1 > fXMax ) fPos1 = fXMax; } @@ -1376,14 +1356,14 @@ sal_Bool EnhancedCustomShape2d::SetHandleControllerPosition( const sal_uInt32 nI if ( aHandle.nFlags & HANDLE_FLAGS_RANGE_Y_MINIMUM ) // check if vertical handle needs to be within a range { double fYMin; - GetParameter( fYMin, aHandle.aYRangeMinimum, sal_False, sal_False, bNormal ); + GetParameter( fYMin, aHandle.aYRangeMinimum, sal_False, sal_False ); if ( fPos2 < fYMin ) fPos2 = fYMin; } if ( aHandle.nFlags & HANDLE_FLAGS_RANGE_Y_MAXIMUM ) // check if vertical handle needs to be within a range { double fYMax; - GetParameter( fYMax, aHandle.aYRangeMaximum, sal_False, sal_False, bNormal ); + GetParameter( fYMax, aHandle.aYRangeMaximum, sal_False, sal_False ); if ( fPos2 > fYMax ) fPos2 = fYMax; } @@ -1573,14 +1553,13 @@ void EnhancedCustomShape2d::CreateSubPath( sal_uInt16& rSrcPt, sal_uInt16& rSegm } case ANGLEELLIPSETO : { - sal_Bool bNormal; for ( sal_uInt16 i = 0; ( i < nPntCount ) && ( ( rSrcPt + 2 ) < nCoordSize ); i++ ) { // create a circle Point _aCenter( GetPoint( seqCoordinates[ rSrcPt ], sal_True, sal_True ) ); double fWidth, fHeight; - GetParameter( fWidth, seqCoordinates[ rSrcPt + 1 ].First, sal_True, sal_False, bNormal ); - GetParameter( fHeight, seqCoordinates[ rSrcPt + 1 ].Second, sal_False, sal_True, bNormal ); + GetParameter( fWidth, seqCoordinates[ rSrcPt + 1 ].First, sal_True, sal_False ); + GetParameter( fHeight, seqCoordinates[ rSrcPt + 1 ].Second, sal_False, sal_True ); fWidth *= fXScale; fHeight*= fYScale; Point aP( (sal_Int32)( _aCenter.X() - fWidth ), (sal_Int32)( _aCenter.Y() - fHeight ) ); @@ -1589,8 +1568,8 @@ void EnhancedCustomShape2d::CreateSubPath( sal_uInt16& rSrcPt, sal_uInt16& rSegm if ( aRect.GetWidth() && aRect.GetHeight() ) { double fStartAngle, fEndAngle; - GetParameter( fStartAngle, seqCoordinates[ rSrcPt + 2 ].First, sal_False, sal_False, bNormal ); - GetParameter( fEndAngle , seqCoordinates[ rSrcPt + 2 ].Second, sal_False, sal_False, bNormal ); + GetParameter( fStartAngle, seqCoordinates[ rSrcPt + 2 ].First, sal_False, sal_False ); + GetParameter( fEndAngle , seqCoordinates[ rSrcPt + 2 ].Second, sal_False, sal_False ); if ( ((sal_Int32)fStartAngle % 360) != ((sal_Int32)fEndAngle % 360) ) { @@ -1716,19 +1695,14 @@ void EnhancedCustomShape2d::CreateSubPath( sal_uInt16& rSrcPt, sal_uInt16& rSegm case ARCANGLETO : { double fWR, fHR, fStartAngle, fSwingAngle; - sal_Bool bNormal; for ( sal_uInt16 i = 0; ( i < nPntCount ) && ( rSrcPt + 1 < nCoordSize ); i++ ) { - GetParameter ( fWR, seqCoordinates[ (sal_uInt16)( rSrcPt ) ].First, sal_True, sal_False, bNormal ); - if ( bNormal ) - fWR *= fXScaleOOXML; - GetParameter ( fHR, seqCoordinates[ (sal_uInt16)( rSrcPt ) ].Second, sal_False, sal_True, bNormal ); - if ( bNormal ) - fHR *= fYScaleOOXML; - - GetParameter ( fStartAngle, seqCoordinates[ (sal_uInt16)( rSrcPt + 1) ].First, sal_False, sal_False, bNormal ); - GetParameter ( fSwingAngle, seqCoordinates[ (sal_uInt16)( rSrcPt + 1 ) ].Second, sal_False, sal_False, bNormal ); + GetParameter ( fWR, seqCoordinates[ (sal_uInt16)( rSrcPt ) ].First, sal_True, sal_False ); + GetParameter ( fHR, seqCoordinates[ (sal_uInt16)( rSrcPt ) ].Second, sal_False, sal_True ); + + GetParameter ( fStartAngle, seqCoordinates[ (sal_uInt16)( rSrcPt + 1) ].First, sal_False, sal_False ); + GetParameter ( fSwingAngle, seqCoordinates[ (sal_uInt16)( rSrcPt + 1 ) ].Second, sal_False, sal_False ); fWR *= fXScale; fHR *= fYScale; -- cgit