oox/source/drawingml/shape.cxx                                           |    
4 
 sw/qa/extras/ooxmlexport/ooxmlexport4.cxx                                |    
3 
 sw/qa/extras/ooxmlexport/ooxmlexport6.cxx                                |    
8 
 sw/qa/extras/ooxmlimport/ooxmlimport.cxx                                 |    
3 
 sw/qa/extras/ooxmlimport/ooxmlimport2.cxx                                |   
15 -
 writerfilter/qa/cppunittests/dmapper/GraphicImport.cxx                   |   
65 +++++
 writerfilter/qa/cppunittests/dmapper/data/tdf141540ChildRotation.docx    
|binary
 writerfilter/qa/cppunittests/dmapper/data/tdf141540GroupLinePosSize.docx 
|binary
 writerfilter/qa/cppunittests/dmapper/data/tdf141540GroupRotation.docx    
|binary
 writerfilter/source/dmapper/GraphicImport.cxx                            |  
121 +++++++++-
 10 files changed, 203 insertions(+), 16 deletions(-)

New commits:
commit 2a70cfb09c4d89154d229b6a95cf076e8bd76798
Author:     Regina Henschel <rb.hensc...@t-online.de>
AuthorDate: Sun Apr 11 13:03:27 2021 +0200
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Thu Apr 22 10:12:32 2021 +0200

    tdf#141540 fix docx import of group or line with rotation
    
    ... and fix case wrap 'Square' and 'in Line' with them.
    Non-uniform scaling of a rotated shape might produce skew. Such had
    happened, when setting group or line to the size contained in
    GraphicImport. Avoid it.
    Writer has special rules for shape position and marging in case of wrap
    'Square' and 'in Line', depending on rotation angle. The patch adds
    the needed margins.
    The patch changes some unit tests where we now get slightly different
    values.
    The patch fixes the wrong skew in sample document of tdf#73022.
    
    Change-Id: Ic743790c3fc8b8b10a4324d9e0184ad945cdceb6
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/114193
    Tested-by: Jenkins
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>

diff --git a/oox/source/drawingml/shape.cxx b/oox/source/drawingml/shape.cxx
index 729fb3c3712f..49f82a6fd137 100644
--- a/oox/source/drawingml/shape.cxx
+++ b/oox/source/drawingml/shape.cxx
@@ -982,6 +982,10 @@ Reference< XShape > const & Shape::createAndInsert(
         // TODO: use ph color when applying effect properties
         //sal_Int32 nEffectPhClr = -1;
 
+        // dmapper needs the original rotation angle for calculating square 
wrap. This angle is not
+        // available as property there, so store it in InteropGrabBag.
+        putPropertyToGrabBag("mso-rotation-angle", Any(mnRotation));
+
         if( pTheme )
         {
             if( const ShapeStyleRef* pLineRef = getShapeStyleRef( XML_lnRef ) )
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport4.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport4.cxx
index 03eff3c65513..603b1010b59a 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport4.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport4.cxx
@@ -77,6 +77,9 @@ DECLARE_OOXMLEXPORT_TEST(testRelorientation, 
"relorientation.docx")
     uno::Reference<drawing::XShapeDescriptor> 
xShapeDescriptor(xGroup->getByIndex(0), uno::UNO_QUERY);
     CPPUNIT_ASSERT_EQUAL(OUString("com.sun.star.drawing.GroupShape"), 
xShapeDescriptor->getShapeType());
 
+    // 'actual child size' = 'group ext' * 'child ext' / 'chExt from group', 
see section 'chExt' in
+    // [MS-OI29500]. Here for width from file 3108960 * 4896 / 4911 = 3099464 
EMU. That corresponds to
+    // width 8.61cm and 325px in UI in Word and rounds down to 8609 Hmm. 
FIXME: Expected value is wrong.
     // Right after import we get a rounding error: 8662 vs 8664.
     if (mbExported)
     {
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport6.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport6.cxx
index 7639e995b86a..0a71b2535587 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport6.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport6.cxx
@@ -125,12 +125,14 @@ DECLARE_OOXMLEXPORT_EXPORTONLY_TEST(testDmlTextshapeB, 
"dml-textshapeB.docx")
     uno::Reference<container::XIndexAccess> xGroup(getShape(1), 
uno::UNO_QUERY);
     uno::Reference<drawing::XShape> xShape(xGroup->getByIndex(3), 
uno::UNO_QUERY);
     // Connector was incorrectly shifted towards the top left corner, X was 
192, Y was -5743.
-    CPPUNIT_ASSERT_EQUAL(sal_Int32(3778), xShape->getPosition().X);
-    CPPUNIT_ASSERT_EQUAL(sal_Int32(-5066), xShape->getPosition().Y);
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(3776), xShape->getPosition().X);
+    // Value as of LO7.2. Whole group is still shifted 3mm to rigth and 5mm 
down.
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(-5063), xShape->getPosition().Y);
 
     xShape.set(xGroup->getByIndex(5), uno::UNO_QUERY);
     // This was incorrectly shifted towards the top of the page, Y was -5011.
-    CPPUNIT_ASSERT_EQUAL(sal_Int32(-4715), xShape->getPosition().Y);
+    // Value as of LO 7.2
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(-4712), xShape->getPosition().Y);
 }
 
 DECLARE_OOXMLEXPORT_TEST(testDMLSolidfillAlpha, "dml-solidfill-alpha.docx")
diff --git a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx 
b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
index fe15ef8d94de..84183572cefd 100644
--- a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
+++ b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
@@ -729,7 +729,8 @@ DECLARE_OOXMLIMPORT_TEST(testFdo43641, "fdo43641.docx")
     uno::Reference<container::XIndexAccess> xGroupShape(getShape(1), 
uno::UNO_QUERY);
     uno::Reference<drawing::XShape> xLine(xGroupShape->getByIndex(1), 
uno::UNO_QUERY);
     // This was 2200, not 2579 in mm100, i.e. the size of the line shape was 
incorrect.
-    CPPUNIT_ASSERT_EQUAL(oox::drawingml::convertEmuToHmm(928440), 
xLine->getSize().Width);
+    // File cx=928694EMU = 2579.7Hmm, round up 2580Hmm. Currently off by 1.
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(2581), xLine->getSize().Width);
 }
 
 DECLARE_OOXMLIMPORT_TEST(testGroupshapeSdt, "groupshape-sdt.docx")
diff --git a/sw/qa/extras/ooxmlimport/ooxmlimport2.cxx 
b/sw/qa/extras/ooxmlimport/ooxmlimport2.cxx
index ed3b0cd153dc..97781bacb94f 100644
--- a/sw/qa/extras/ooxmlimport/ooxmlimport2.cxx
+++ b/sw/qa/extras/ooxmlimport/ooxmlimport2.cxx
@@ -207,8 +207,9 @@ DECLARE_OOXMLIMPORT_TEST(testTdf118693, "tdf118693.docx")
 
     CPPUNIT_ASSERT_EQUAL(sal_Int32(10162), aPosGroup.X);
     CPPUNIT_ASSERT_EQUAL(sal_Int32(118), aPosGroup.Y);
-    CPPUNIT_ASSERT_EQUAL(sal_Int32(6369), aSizeGroup.Width);
-    CPPUNIT_ASSERT_EQUAL(sal_Int32(4983), aSizeGroup.Height);
+    // As of LO7.2 width by 1 too small, height by 2 too small. Reason unclear.
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(6368), aSizeGroup.Width);
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(4981), aSizeGroup.Height);
 
     // Without the fix in place, this test would have failed at many places
     // as the first shape in the group would have had an incorrect position,
@@ -218,10 +219,10 @@ DECLARE_OOXMLIMPORT_TEST(testTdf118693, "tdf118693.docx")
     awt::Point aPosShape1 = xShape1->getPosition();
     awt::Size aSizeShape1 = xShape1->getSize();
 
-    CPPUNIT_ASSERT_EQUAL(sal_Int32(12863), aPosShape1.X);
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(12861), aPosShape1.X);
     CPPUNIT_ASSERT_EQUAL(sal_Int32(146), aPosShape1.Y);
     CPPUNIT_ASSERT_EQUAL(sal_Int32(3669), aSizeShape1.Width);
-    CPPUNIT_ASSERT_EQUAL(sal_Int32(4914), aSizeShape1.Height);
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(4912), aSizeShape1.Height);
 
     uno::Reference<drawing::XShape> xShape2(xGroup->getByIndex(1), 
uno::UNO_QUERY_THROW);
     awt::Point aPosShape2 = xShape2->getPosition();
@@ -230,7 +231,7 @@ DECLARE_OOXMLIMPORT_TEST(testTdf118693, "tdf118693.docx")
     CPPUNIT_ASSERT_EQUAL(sal_Int32(10162), aPosShape2.X);
     CPPUNIT_ASSERT_EQUAL(sal_Int32(118), aPosShape2.Y);
     CPPUNIT_ASSERT_EQUAL(sal_Int32(4595), aSizeShape2.Width);
-    CPPUNIT_ASSERT_EQUAL(sal_Int32(4983), aSizeShape2.Height);
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(4981), aSizeShape2.Height);
 }
 
 DECLARE_OOXMLIMPORT_TEST(testGroupShapeFontName, "groupshape-fontname.docx")
@@ -286,7 +287,9 @@ DECLARE_OOXMLIMPORT_TEST(test120551, "tdf120551.docx")
     auto nHoriOrientPosition = getProperty<sal_Int32>(getShape(1), 
"HoriOrientPosition");
     // Without the accompanying fix in place, this test would have failed with
     // 'Expected: 430, Actual  : -2542'.
-    CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(430), nHoriOrientPosition);
+    // CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(430), nHoriOrientPosition);
+    // File 140335EMU = 389,8Hmm
+    CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(392), nHoriOrientPosition);
 }
 
 DECLARE_OOXMLIMPORT_TEST(testTdf111550, "tdf111550.docx")
diff --git a/writerfilter/qa/cppunittests/dmapper/GraphicImport.cxx 
b/writerfilter/qa/cppunittests/dmapper/GraphicImport.cxx
index c1e5cb6faad6..63bdb07e82a7 100644
--- a/writerfilter/qa/cppunittests/dmapper/GraphicImport.cxx
+++ b/writerfilter/qa/cppunittests/dmapper/GraphicImport.cxx
@@ -10,6 +10,8 @@
 #include <test/bootstrapfixture.hxx>
 #include <unotest/macros_test.hxx>
 
+#include <com/sun/star/awt/Point.hpp>
+#include <com/sun/star/awt/Size.hpp>
 #include <com/sun/star/beans/XPropertySet.hpp>
 #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
 #include <com/sun/star/frame/Desktop.hpp>
@@ -52,6 +54,69 @@ void Test::tearDown()
 
 constexpr OUStringLiteral DATA_DIRECTORY = 
u"/writerfilter/qa/cppunittests/dmapper/data/";
 
+CPPUNIT_TEST_FIXTURE(Test, testTdf141540ChildRotation)
+{
+    OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + 
"tdf141540ChildRotation.docx";
+    getComponent() = loadFromDesktop(aURL);
+    uno::Reference<drawing::XDrawPageSupplier> 
xDrawPageSupplier(getComponent(), uno::UNO_QUERY);
+    uno::Reference<drawing::XDrawPage> xDrawPage = 
xDrawPageSupplier->getDrawPage();
+    uno::Reference<container::XIndexAccess> xGroup(xDrawPage->getByIndex(0), 
uno::UNO_QUERY_THROW);
+    uno::Reference<beans::XPropertySet> xRotatedShape(xGroup->getByIndex(1), 
uno::UNO_QUERY);
+    sal_Int32 nShearAngle = 9000; // initialize with invalid value
+    xRotatedShape->getPropertyValue("ShearAngle") >>= nShearAngle;
+    // Without fix in place, this test would have failed with:
+    // - Expected: 0
+    // - Actual  : 2494
+    // i.e. the rotated rectangle in the group was sheared, although the group 
itself is not rotated
+    CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(0), nShearAngle);
+}
+
+CPPUNIT_TEST_FIXTURE(Test, testTdf141540GroupRotation)
+{
+    OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + 
"tdf141540GroupRotation.docx";
+    getComponent() = loadFromDesktop(aURL);
+    uno::Reference<drawing::XDrawPageSupplier> 
xDrawPageSupplier(getComponent(), uno::UNO_QUERY);
+    uno::Reference<drawing::XDrawPage> xDrawPage = 
xDrawPageSupplier->getDrawPage();
+    uno::Reference<beans::XPropertySet> xShape(xDrawPage->getByIndex(0), 
uno::UNO_QUERY);
+    sal_Int32 nShearAngle = 9000; // init with invalid value
+    xShape->getPropertyValue("ShearAngle") >>= nShearAngle;
+    // Without fix in place, this test would have failed with:
+    // - Expected: 0
+    // - Actual  : -3190
+    // i.e. the group has got a shearing although MSO does not know shearing 
at all.
+    CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(0), nShearAngle);
+}
+
+CPPUNIT_TEST_FIXTURE(Test, testTdf141540GroupLinePosSize)
+{
+    OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + 
"tdf141540GroupLinePosSize.docx";
+    getComponent() = loadFromDesktop(aURL);
+    uno::Reference<drawing::XDrawPageSupplier> 
xDrawPageSupplier(getComponent(), uno::UNO_QUERY);
+    uno::Reference<drawing::XDrawPage> xDrawPage = 
xDrawPageSupplier->getDrawPage();
+
+    // Test line
+    uno::Reference<drawing::XShape> xLineShape(xDrawPage->getByIndex(0), 
uno::UNO_QUERY);
+    awt::Point aPosition = xLineShape->getPosition();
+    awt::Size aSize = xLineShape->getSize();
+    // Without fix in place, you had got Position = (19|6498), Size = 5001 x 2
+    // i.e. the line was nearly horizontal instead of vertical
+    CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(5022), aPosition.X);
+    CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(2963), aPosition.Y);
+    CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(0), aSize.Width);
+    CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(7073), aSize.Height);
+
+    // Test group
+    uno::Reference<drawing::XShape> xGroupShape(xDrawPage->getByIndex(1), 
uno::UNO_QUERY);
+    aPosition = xGroupShape->getPosition();
+    aSize = xGroupShape->getSize();
+    // Without fix in place, you had got Position = (11511|3480), Size = 4022 
x 4022
+    // i.e. the group was erroneously downscaled to unrotated size
+    CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(10679), aPosition.X);
+    CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(2648), aPosition.Y);
+    CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(5687), aSize.Width);
+    CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(5687), aSize.Height);
+}
+
 CPPUNIT_TEST_FIXTURE(Test, testGroupShapeRotation)
 {
     OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + 
"group-shape-rotation.docx";
diff --git 
a/writerfilter/qa/cppunittests/dmapper/data/tdf141540ChildRotation.docx 
b/writerfilter/qa/cppunittests/dmapper/data/tdf141540ChildRotation.docx
new file mode 100644
index 000000000000..902bb6192afe
Binary files /dev/null and 
b/writerfilter/qa/cppunittests/dmapper/data/tdf141540ChildRotation.docx differ
diff --git 
a/writerfilter/qa/cppunittests/dmapper/data/tdf141540GroupLinePosSize.docx 
b/writerfilter/qa/cppunittests/dmapper/data/tdf141540GroupLinePosSize.docx
new file mode 100644
index 000000000000..d0ceff118eab
Binary files /dev/null and 
b/writerfilter/qa/cppunittests/dmapper/data/tdf141540GroupLinePosSize.docx 
differ
diff --git 
a/writerfilter/qa/cppunittests/dmapper/data/tdf141540GroupRotation.docx 
b/writerfilter/qa/cppunittests/dmapper/data/tdf141540GroupRotation.docx
new file mode 100644
index 000000000000..13e65c1d122a
Binary files /dev/null and 
b/writerfilter/qa/cppunittests/dmapper/data/tdf141540GroupRotation.docx differ
diff --git a/writerfilter/source/dmapper/GraphicImport.cxx 
b/writerfilter/source/dmapper/GraphicImport.cxx
index 1aa0a03082a9..56d274719805 100644
--- a/writerfilter/source/dmapper/GraphicImport.cxx
+++ b/writerfilter/source/dmapper/GraphicImport.cxx
@@ -43,7 +43,9 @@
 #include <com/sun/star/uno/XComponentContext.hpp>
 #include <com/sun/star/table/ShadowFormat.hpp>
 
+#include <svx/svditer.hxx>
 #include <svx/svdobj.hxx>
+#include <svx/svdtrans.hxx>
 #include <svx/unoapi.hxx>
 #include <cppuhelper/implbase.hxx>
 #include <rtl/ustrbuf.hxx>
@@ -334,7 +336,7 @@ public:
         return nYSize;
     }
 
-    bool isYSizeValis () const
+    bool isYSizeValid() const
     {
         return bYSizeValid;
     }
@@ -508,6 +510,31 @@ void GraphicImport::putPropertyToFrameGrabBag( const 
OUString& sPropertyName, co
     }
 }
 
+static bool lcl_bHasGroupSlantedChild (const SdrObject* pObj)
+{
+    // Returns true, if a child object differs more then 0.02deg from 
horizontal or vertical.
+    // Because lines sometimes are imported as customshapes, a horizontal or 
vertical line
+    // might not have exactly 0, 90, 180, or 270 degree as rotate angle.
+    if (!pObj)
+        return false;
+    if (!pObj->IsGroupObject())
+        return false;
+    SdrObjList* pSubList = pObj->GetSubList();
+    if (!pSubList)
+        return false;
+    SdrObjListIter aIterator(pSubList, SdrIterMode::DeepNoGroups);
+    while (aIterator.IsMore())
+    {
+            const SdrObject* pSubObj = aIterator.Next();
+            const Degree100 nRotateAngle = 
NormAngle36000(pSubObj->GetRotateAngle());
+            const sal_uInt16 nRot = nRotateAngle.get();
+            if ((3 < nRot && nRot < 8997) || (9003 < nRot && nRot < 17997)
+                || (18003 < nRot && nRot < 26997) || (27003 < nRot && nRot < 
35997))
+                return true;
+    }
+    return false;
+}
+
 void GraphicImport::lcl_attribute(Id nName, Value& rValue)
 {
     sal_Int32 nIntValue = rValue.getInt();
@@ -787,10 +814,34 @@ void GraphicImport::lcl_attribute(Id nName, Value& rValue)
 
                         awt::Size aSize(m_xShape->getSize());
 
-                        if (m_pImpl->isXSizeValid())
-                            aSize.Width = m_pImpl->getXSize();
-                        if (m_pImpl->isYSizeValis())
-                            aSize.Height = m_pImpl->getYSize();
+                        // One purpose of the next part is, to set the logic 
rectangle of the SdrObject
+                        // to nXSize and nYSize from import. That doesn't work 
for groups or lines,
+                        // because they do not have a logic rectangle and 
m_xShape->getSize and
+                        // m_xShape->setSize would work on the snap rectangle. 
In case a shape is
+                        // rotated, non-uniform scaling the snap rectangle 
will introduce shearing on
+                        // the shape. In case group or line is rotated, nXSize 
and nYSize contain the
+                        // unrotated size from oox. The rotation is already 
incorporated into group
+                        // children and line points. We must not scale them to 
unrotated size. Exclude
+                        // those shapes here.
+
+                        // Get MSO rotation angle. GetRotateAngle from 
SdrObject is not suitable
+                        // here, because it returns the rotate angle of the 
first child for groups
+                        // and slope angle for lines, even if line or group 
had not been rotated.
+                        // Import in oox has put the rotation from oox file 
into InteropGrabBag.
+                        comphelper::SequenceAsHashMap 
aInteropGrabBag(xShapeProps->getPropertyValue("InteropGrabBag"));
+                        sal_Int32 nOOXAngle(0);
+                        aInteropGrabBag.getValue("mso-rotation-angle") >>= 
nOOXAngle; // 1/60000 deg
+                        const bool bIsGroupOrLine = 
xServiceInfo->supportsService("com.sun.star.drawing.GroupShape")
+                            || 
xServiceInfo->supportsService("com.sun.star.drawing.LineShape");
+                        SdrObject* pShape = GetSdrObjectFromXShape(m_xShape);
+                        if ((bIsGroupOrLine && 
!lcl_bHasGroupSlantedChild(pShape) && nOOXAngle == 0)
+                            || !bIsGroupOrLine)
+                        {
+                            if (m_pImpl->isXSizeValid())
+                                aSize.Width = m_pImpl->getXSize();
+                            if (m_pImpl->isYSizeValid())
+                                aSize.Height = m_pImpl->getYSize();
+                        }
 
                         Degree100 nRotation;
                         if (bKeepRotation)
@@ -798,7 +849,7 @@ void GraphicImport::lcl_attribute(Id nName, Value& rValue)
                             // Use internal API, getPropertyValue(RotateAngle)
                             // would use GetObjectRotation(), which is not what
                             // we want.
-                            if (SdrObject* pShape = 
GetSdrObjectFromXShape(m_xShape))
+                            if (pShape)
                                 nRotation = pShape->GetRotateAngle();
                         }
                         m_xShape->setSize(aSize);
@@ -865,6 +916,64 @@ void GraphicImport::lcl_attribute(Id nName, Value& rValue)
                         {
                             putPropertyToFrameGrabBag("AnchorId", 
uno::makeAny(m_pImpl->sAnchorId));
                         }
+
+                        // Calculate mso unrotated rectangle and its center, 
needed below
+                        awt::Size aImportSize(m_xShape->getSize()); // here 
only fallback
+                        if (m_pImpl->isXSizeValid())
+                            aImportSize.Width = m_pImpl->getXSize(); // Hmm
+                        if (m_pImpl->isYSizeValid())
+                            aImportSize.Height = m_pImpl->getYSize(); // Hmm
+                        const awt::Point 
aImportPosition(GetGraphicObjectPosition()); // Hmm
+                        const awt::Point aCentrum(aImportPosition.X + 
aImportSize.Width / 2,
+                                                  aImportPosition.Y + 
aImportSize.Height / 2);
+
+                        // In case of group and lines, rotations are 
incorported in the child shapes or
+                        // points respectively in LO. MSO has rotation as 
separate property. The
+                        // position refers to the unrotated rectangle of MSO. 
We need to adapt it to
+                        // the left-top of the rotated shape.
+                        if (bIsGroupOrLine)
+                        {
+                            // Get actual LO snap rectangle size of group or 
line.
+                            awt::Size aLOSize(m_xShape->getSize()); //Hmm
+
+                            // Set LO position. MSO rotation is done on shape 
center.
+                            m_pImpl->nLeftPosition = aCentrum.X - 
aLOSize.Width / 2;
+                            m_pImpl->nTopPosition = aCentrum.Y - 
aLOSize.Height / 2;
+                            m_xShape->setPosition(GetGraphicObjectPosition());
+                        }
+
+                        // Margin correction
+                        // In case of wrap "Square" or "in Line", MSO uses 
special rules to
+                        // determine the rectangle into which the shape is 
placed, depending on
+                        // rotation angle.
+                        // If angle is smaller to horizontal than 45deg, the 
unrotated mso shape
+                        // rectangle is used, whereby the height is expanded 
to the bounding
+                        // rectangle height of the shape.
+                        // If angle is larger to horizontal than 45deg, the 
90deg rotated rectangle
+                        // is used, whereby the width is expanded to the 
bounding width of the
+                        // shape.
+                        if (bIsGroupOrLine && (m_pImpl->eGraphicImportType == 
IMPORT_AS_DETECTED_INLINE
+                            || (m_pImpl->nWrap == text::WrapTextMode_PARALLEL 
&& !(m_pImpl->mpWrapPolygon))))
+                        {
+
+                            nOOXAngle = (nOOXAngle / 60000) % 180; // convert 
to degree in [0°,180°[
+
+                            if (nOOXAngle >= 45 && nOOXAngle < 135)
+                            {
+                                const sal_Int32 nImportRot90Top(aCentrum.Y - 
aImportSize.Width / 2);
+                                sal_Int32 
nVertMarginOffset(m_pImpl->nTopPosition - nImportRot90Top);
+                                nVertMarginOffset = 
std::max<sal_Int32>(nVertMarginOffset, 0);
+                                m_pImpl->nTopMargin += nVertMarginOffset;
+                                m_pImpl->nBottomMargin += nVertMarginOffset;
+                            }
+                            else
+                            {
+                                sal_Int32 
nHoriMarginOffset(m_pImpl->nLeftPosition - aImportPosition.X);
+                                nHoriMarginOffset = 
std::max<sal_Int32>(nHoriMarginOffset, 0);
+                                m_pImpl->nLeftMargin += nHoriMarginOffset;
+                                m_pImpl->nRightMargin += nHoriMarginOffset;
+                            }
+                        }
                     }
 
                     if (bUseShape && m_pImpl->eGraphicImportType == 
IMPORT_AS_DETECTED_ANCHOR)
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to