[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-6.2' - sw/qa sw/source

Regina Henschel (via logerrit) logerrit at kemper.freedesktop.org
Tue Sep 17 06:21:50 UTC 2019


 sw/qa/extras/ww8export/data/tdf118375_240degClockwise.doc |binary
 sw/qa/extras/ww8export/ww8export3.cxx                     |   23 ++++++++++
 sw/source/filter/ww8/wrtw8esh.cxx                         |   30 ++++++++++++++
 sw/source/filter/ww8/ww8graf.cxx                          |   11 +++++
 4 files changed, 64 insertions(+)

New commits:
commit 90c29687bbbd467c5ec234adc19fc861ea8e270b
Author:     Regina Henschel <rb.henschel at t-online.de>
AuthorDate: Tue Apr 2 21:36:57 2019 +0200
Commit:     Andras Timar <andras.timar at collabora.com>
CommitDate: Tue Sep 17 08:21:08 2019 +0200

    tdf#118375, tdf#70838 correct position of rotated shape in doc
    
    Word relates the position to the unrotated shape in legacy doc
    format. Writer uses the rotated shape. The patch corrects the
    difference on import and export.
    
    Reviewed-on: https://gerrit.libreoffice.org/70152
    Tested-by: Jenkins
    Reviewed-by: Regina Henschel <rb.henschel at t-online.de>
    (cherry picked from commit 421e6fc3cd2e6fe37afbef341e2d0ad7b8edde37)
    
    Change-Id: I25537123656e62d6ffae5118ee8d621a4b5c5be0
    Reviewed-on: https://gerrit.libreoffice.org/79000
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice at gmail.com>
    Reviewed-by: Andras Timar <andras.timar at collabora.com>

diff --git a/sw/qa/extras/ww8export/data/tdf118375_240degClockwise.doc b/sw/qa/extras/ww8export/data/tdf118375_240degClockwise.doc
new file mode 100644
index 000000000000..99d15e20cea5
Binary files /dev/null and b/sw/qa/extras/ww8export/data/tdf118375_240degClockwise.doc differ
diff --git a/sw/qa/extras/ww8export/ww8export3.cxx b/sw/qa/extras/ww8export/ww8export3.cxx
index 42c2b1ac6072..7d6f4b756a39 100644
--- a/sw/qa/extras/ww8export/ww8export3.cxx
+++ b/sw/qa/extras/ww8export/ww8export3.cxx
@@ -254,6 +254,29 @@ DECLARE_WW8EXPORT_TEST(testBtlrFrame, "btlr-frame.odt")
     CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(9000), getProperty<sal_Int32>(xFrame, "RotateAngle"));
 }
 
+DECLARE_WW8EXPORT_TEST(testTdf118375export, "tdf118375_240degClockwise.doc")
+{
+    // The input document has one custom shape, which is rotated 240deg. Check
+    // that it has the same position as in Word.
+    uno::Reference<drawing::XDrawPagesSupplier> xDrawPagesSupplier(mxComponent,
+                                                                   uno::UNO_QUERY_THROW);
+    CPPUNIT_ASSERT_MESSAGE("Could not get XDrawPagesSupplier", xDrawPagesSupplier.is());
+    uno::Reference<drawing::XDrawPages> xDrawPages(xDrawPagesSupplier->getDrawPages());
+    uno::Reference<drawing::XDrawPage> xDrawPage(xDrawPages->getByIndex(0), uno::UNO_QUERY_THROW);
+    CPPUNIT_ASSERT_MESSAGE("Could not get xDrawPage", xDrawPage.is());
+    uno::Reference<drawing::XShape> xShape(xDrawPage->getByIndex(0), uno::UNO_QUERY);
+    CPPUNIT_ASSERT_MESSAGE("Could not get xShape", xShape.is());
+    uno::Reference<beans::XPropertySet> xShapeProps(xShape, uno::UNO_QUERY);
+    CPPUNIT_ASSERT_MESSAGE("Could not get the shape properties", xShapeProps.is());
+    sal_Int32 nPosX, nPosY;
+    xShapeProps->getPropertyValue("HoriOrientPosition") >>= nPosX;
+    xShapeProps->getPropertyValue("VertOrientPosition") >>= nPosY;
+    // Allow some tolerance because rounding errors through integer arithmethic
+    // in rotation.
+    CPPUNIT_ASSERT_DOUBLES_EQUAL(5200.0, static_cast<double>(nPosX), 1.0);
+    CPPUNIT_ASSERT_DOUBLES_EQUAL(1152.0, static_cast<double>(nPosY), 1.0);
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/filter/ww8/wrtw8esh.cxx b/sw/source/filter/ww8/wrtw8esh.cxx
index 31d5279fe54b..30270ad9255d 100644
--- a/sw/source/filter/ww8/wrtw8esh.cxx
+++ b/sw/source/filter/ww8/wrtw8esh.cxx
@@ -659,6 +659,7 @@ void PlcDrawObj::WritePlc( WW8Export& rWrt ) const
                 WinwordAnchoring::ConvertPosition( rHOr, rVOr, rFormat );
 
             Point aObjPos;
+            bool bHasHeightWidthSwapped(false);
             if (RES_FLYFRMFMT == rFormat.Which())
             {
                 SwRect aLayRect(rFormat.FindLayoutRect(false, &aObjPos));
@@ -694,6 +695,7 @@ void PlcDrawObj::WritePlc( WW8Export& rWrt ) const
                         const long nHeight = aRect.getHeight();
                         aRect.setWidth( nHeight );
                         aRect.setHeight( nWidth );
+                        bHasHeightWidthSwapped = true;
                     }
                 }
             }
@@ -755,6 +757,34 @@ void PlcDrawObj::WritePlc( WW8Export& rWrt ) const
             //Nasty swap for bidi if necessary
             rWrt.MiserableRTLFrameFormatHack(nLeft, nRight, rFrameFormat);
 
+            // tdf#70838. Word relates the position to the unrotated rectangle,
+            // Writer to the rotated one. Because the rotation is around center,
+            // the difference counts half.
+            if(pObj && pObj->GetRotateAngle())
+            {
+                SwTwips nXOff;
+                SwTwips nYOff;
+                SwTwips nSnapWidth = pObj->GetSnapRect().getWidth();
+                SwTwips nSnapHeight = pObj->GetSnapRect().getHeight();
+                SwTwips nLogicWidth = pObj->GetLogicRect().getWidth();
+                SwTwips nLogicHeight = pObj->GetLogicRect().getHeight();
+                // +1 for to compensate integer arithmetic rounding errors
+                if(bHasHeightWidthSwapped)
+                {
+                    nXOff = (nSnapWidth - nLogicHeight + 1) / 2;
+                    nYOff = (nSnapHeight - nLogicWidth + 1) / 2;
+                }
+                else
+                {
+                    nXOff = (nSnapWidth - nLogicWidth + 1) / 2;
+                    nYOff = (nSnapHeight - nLogicHeight + 1) / 2;
+                }
+                nLeft += nXOff;
+                nRight += nXOff;
+                nTop += nYOff;
+                nBottom += nYOff;
+            }
+
             //xaLeft/yaTop/xaRight/yaBottom - rel. to anchor
             //(most of) the border is outside the graphic is word, so
             //change dimensions to fit
diff --git a/sw/source/filter/ww8/ww8graf.cxx b/sw/source/filter/ww8/ww8graf.cxx
index 866937a17c8f..29b7b3305c91 100644
--- a/sw/source/filter/ww8/ww8graf.cxx
+++ b/sw/source/filter/ww8/ww8graf.cxx
@@ -2531,6 +2531,17 @@ SwFrameFormat* SwWW8ImplReader::Read_GrafLayer( long nGrafAnchorCp )
         return nullptr;
     }
 
+    // tdf#118375 Word relates position to the unrotated rectangle,
+    // Writer uses the rotated one.
+    if (pObject->GetRotateAngle())
+    {
+        tools::Rectangle aObjSnapRect(pObject->GetSnapRect()); // recalculates the SnapRect
+        pF->nXaLeft = aObjSnapRect.Left();
+        pF->nYaTop = aObjSnapRect.Top();
+        pF->nXaRight = aObjSnapRect.Right();
+        pF->nYaBottom = aObjSnapRect.Bottom();
+    }
+
     bool bDone = false;
     SdrObject* pOurNewObject = nullptr;
     bool bReplaceable = false;


More information about the Libreoffice-commits mailing list