[Libreoffice-commits] core.git: filter/source

Jacobo Aragunde Pérez jaragunde at igalia.com
Thu Nov 14 03:27:20 PST 2013


 filter/source/msfilter/eschesdo.cxx |   25 ++++++++++++++++++++-----
 1 file changed, 20 insertions(+), 5 deletions(-)

New commits:
commit 6c5557c60f97778fd732c01f054553356ce7f258
Author: Jacobo Aragunde Pérez <jaragunde at igalia.com>
Date:   Fri Oct 25 09:22:22 2013 +0200

    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 at collabora.co.uk>
    Tested-by: Miklos Vajna <vmiklos at collabora.co.uk>

diff --git a/filter/source/msfilter/eschesdo.cxx b/filter/source/msfilter/eschesdo.cxx
index 2b632b3..43854c1 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;


More information about the Libreoffice-commits mailing list