sc/qa/unit/data/xlsx/testShapeDisplacementOnRotationImport.xlsx |binary
 sc/qa/unit/subsequent_filters-test.cxx                          |   19 
++++++++++
 sc/source/filter/oox/drawingfragment.cxx                        |    8 ++--
 3 files changed, 24 insertions(+), 3 deletions(-)

New commits:
commit 3e85b22769a4b02744a7006d7dc772973c0093f5
Author:     Regényi Balázs <regenyi.balazsmik...@nisz.hu>
AuthorDate: Wed Aug 19 15:32:54 2020 +0200
Commit:     László Németh <nem...@numbertext.org>
CommitDate: Mon Aug 24 11:02:47 2020 +0200

    tdf#135918 XLSX DrawingML shape import: fix needless displacement
    
    Shape was displaced on rotation if it is placed next to the sheets
    upper/left edges.
    
    Co-authored-by: Szabolcs Tóth
    
    Change-Id: I987e7b0d863b89cfb5d8154e2f0a017e21248ee1
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/101001
    Tested-by: Jenkins
    Tested-by: László Németh <nem...@numbertext.org>
    Reviewed-by: László Németh <nem...@numbertext.org>

diff --git a/sc/qa/unit/data/xlsx/testShapeDisplacementOnRotationImport.xlsx 
b/sc/qa/unit/data/xlsx/testShapeDisplacementOnRotationImport.xlsx
new file mode 100644
index 000000000000..a5fcd1ce2fbd
Binary files /dev/null and 
b/sc/qa/unit/data/xlsx/testShapeDisplacementOnRotationImport.xlsx differ
diff --git a/sc/qa/unit/subsequent_filters-test.cxx 
b/sc/qa/unit/subsequent_filters-test.cxx
index c602ec875beb..01f2db7f7d9d 100644
--- a/sc/qa/unit/subsequent_filters-test.cxx
+++ b/sc/qa/unit/subsequent_filters-test.cxx
@@ -272,6 +272,7 @@ public:
     void testXLSDefColWidth();
     void testPreviewMissingObjLink();
     void testShapeRotationImport();
+    void testShapeDisplacementOnRotationImport();
 
     CPPUNIT_TEST_SUITE(ScFiltersTest);
     CPPUNIT_TEST(testBooleanFormatXLSX);
@@ -434,6 +435,7 @@ public:
     CPPUNIT_TEST(testXLSDefColWidth);
     CPPUNIT_TEST(testPreviewMissingObjLink);
     CPPUNIT_TEST(testShapeRotationImport);
+    CPPUNIT_TEST(testShapeDisplacementOnRotationImport);
 
     CPPUNIT_TEST_SUITE_END();
 
@@ -4739,6 +4741,23 @@ void ScFiltersTest::testShapeRotationImport()
     }
 }
 
+void ScFiltersTest::testShapeDisplacementOnRotationImport()
+{
+    // tdf#135918 shape is displaced on rotation if it is placed next to the 
sheets upper/left edges
+    ScDocShellRef xDocSh = loadDoc("testShapeDisplacementOnRotationImport.", 
FORMAT_XLSX);
+    CPPUNIT_ASSERT_MESSAGE("Failed to load 
testShapeDisplacementOnRotationImport.xlsx", xDocSh.is());
+
+    uno::Reference<drawing::XDrawPagesSupplier> xDoc(xDocSh->GetModel(), 
uno::UNO_QUERY_THROW);
+    uno::Reference<drawing::XDrawPage> 
xPage(xDoc->getDrawPages()->getByIndex(0), uno::UNO_QUERY_THROW);
+    uno::Reference<drawing::XShape> xShape(xPage->getByIndex(0), 
uno::UNO_QUERY_THROW);
+
+    uno::Reference<beans::XPropertySet> xShapeProperties(xShape, 
uno::UNO_QUERY_THROW);
+    uno::Any aRectProp = xShapeProperties->getPropertyValue("FrameRect");
+    awt::Rectangle aRectangle = aRectProp.get<awt::Rectangle>();
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(0), aRectangle.X);
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aRectangle.Y);
+}
+
 ScFiltersTest::ScFiltersTest()
       : ScBootstrapFixture( "sc/qa/unit/data" )
 {
diff --git a/sc/source/filter/oox/drawingfragment.cxx 
b/sc/source/filter/oox/drawingfragment.cxx
index 83b3a7446f5e..1f1f38b25c28 100644
--- a/sc/source/filter/oox/drawingfragment.cxx
+++ b/sc/source/filter/oox/drawingfragment.cxx
@@ -295,9 +295,11 @@ void DrawingFragment::onEndElement()
                     }
 
                     // TODO: DrawingML implementation expects 32-bit 
coordinates for EMU rectangles (change that to EmuRectangle)
+                    // tdf#135918: Negative X,Y position has to be allowed to 
avoid shape displacement on rotation.
+                    // The negative values can exist because of previous lines 
where the anchor rectangle must be mirrored in some ranges.
                     Rectangle aShapeRectEmu32(
-                        getLimitedValue< sal_Int32, sal_Int64 >( 
aShapeRectEmu.X, 0, SAL_MAX_INT32 ),
-                        getLimitedValue< sal_Int32, sal_Int64 >( 
aShapeRectEmu.Y, 0, SAL_MAX_INT32 ),
+                        getLimitedValue< sal_Int32, sal_Int64 >( 
aShapeRectEmu.X, SAL_MIN_INT32, SAL_MAX_INT32 ),
+                        getLimitedValue< sal_Int32, sal_Int64 >( 
aShapeRectEmu.Y, SAL_MIN_INT32, SAL_MAX_INT32 ),
                         getLimitedValue< sal_Int32, sal_Int64 >( 
aShapeRectEmu.Width, 0, SAL_MAX_INT32 ),
                         getLimitedValue< sal_Int32, sal_Int64 >( 
aShapeRectEmu.Height, 0, SAL_MAX_INT32 ) );
 
@@ -314,7 +316,7 @@ void DrawingFragment::onEndElement()
                     /*  Collect all shape positions in the WorksheetHelper base
                         class. But first, scale EMUs to 1/100 mm. */
                     Rectangle aShapeRectHmm(
-                        convertEmuToHmm(aShapeRectEmu32.X ), 
convertEmuToHmm(aShapeRectEmu32.Y ),
+                        convertEmuToHmm(aShapeRectEmu32.X > 0 ? 
aShapeRectEmu32.X : 0), convertEmuToHmm(aShapeRectEmu32.Y > 0 ? 
aShapeRectEmu32.Y : 0),
                         convertEmuToHmm(aShapeRectEmu32.Width ), 
convertEmuToHmm(aShapeRectEmu32.Height ) );
                     extendShapeBoundingBox( aShapeRectHmm );
                     // set cell Anchoring
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to