summaryrefslogtreecommitdiff
path: root/filter
diff options
context:
space:
mode:
authorJacobo Aragunde PĂ©rez <jaragunde@igalia.com>2013-10-25 09:22:22 +0200
committerMiklos Vajna <vmiklos@collabora.co.uk>2013-11-14 11:26:56 +0000
commit6c5557c60f97778fd732c01f054553356ce7f258 (patch)
treee3ce517093c8182b2281180b6ce36c45e9d6efa6 /filter
parentcc8c94b362e89d7d7e974119be77679f2f344d91 (diff)
fdo#70838: Fix position issue when exporting shapes to docx.
Fixed an error at ImplEESdrWriter::ImplFlipBoundingBox implementation. I've also tried to simplify and explain the calculations done there. Change-Id: I41c6c6e1a045803524479c92ef807913db38167a Reviewed-on: https://gerrit.libreoffice.org/6433 Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk> Tested-by: Miklos Vajna <vmiklos@collabora.co.uk>
Diffstat (limited to 'filter')
-rw-r--r--filter/source/msfilter/eschesdo.cxx25
1 files changed, 20 insertions, 5 deletions
diff --git a/filter/source/msfilter/eschesdo.cxx b/filter/source/msfilter/eschesdo.cxx
index 2b632b3b3e0f..43854c1d1d70 100644
--- a/filter/source/msfilter/eschesdo.cxx
+++ b/filter/source/msfilter/eschesdo.cxx
@@ -98,10 +98,11 @@ void ImplEESdrWriter::ImplFlipBoundingBox( ImplEESdrObject& rObj, EscherProperty
sal_Int32 nAngle = rObj.GetAngle();
Rectangle aRect( rObj.GetRect() );
+ // for position calculations, we normalize the angle between 0 and 90 degrees
if ( nAngle < 0 )
nAngle = ( 36000 + nAngle ) % 36000;
- else
- nAngle = ( 36000 - ( nAngle % 36000 ) );
+ while ( nAngle > 9000 )
+ nAngle = ( 18000 - ( nAngle % 18000 ) );
double fVal = (double)nAngle * F_PI18000;
double fCos = cos( fVal );
@@ -110,10 +111,24 @@ void ImplEESdrWriter::ImplFlipBoundingBox( ImplEESdrObject& rObj, EscherProperty
double nWidthHalf = (double) aRect.GetWidth() / 2;
double nHeightHalf = (double) aRect.GetHeight() / 2;
- double nXDiff = fCos * nWidthHalf + fSin * (-nHeightHalf);
- double nYDiff = - ( fSin * nWidthHalf - fCos * ( -nHeightHalf ) );
+ // fdo#70838:
+ // when you rotate an object, the top-left corner of its bounding box is moved
+ // nXDiff and nYDiff pixels. To get their values we use these equations:
+ //
+ // fSin * nHeightHalf + fCos * nWidthHalf == nXDiff + nWidthHalf
+ // fSin * nWidthHalf + fCos * nHeightHalf == nYDiff + nHeightHalf
+
+ double nXDiff = fSin * nHeightHalf + fCos * nWidthHalf - nWidthHalf;
+ double nYDiff = fSin * nWidthHalf + fCos * nHeightHalf - nHeightHalf;
+
+ aRect.Move( (sal_Int32) nXDiff, (sal_Int32) nYDiff );
- aRect.Move( (sal_Int32)( -( nWidthHalf - nXDiff ) ), (sal_Int32)( - ( nHeightHalf + nYDiff ) ) );
+ // calculate the proper angle value to be saved
+ nAngle = rObj.GetAngle();
+ if ( nAngle < 0 )
+ nAngle = ( 36000 + nAngle ) % 36000;
+ else
+ nAngle = ( 36000 - ( nAngle % 36000 ) );
nAngle *= 655;
nAngle += 0x8000;