summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRegényi Balázs <regenyi.balazsmiklos@nisz.hu>2020-08-19 15:32:54 +0200
committerGabor Kelemen <kelemen.gabor2@nisz.hu>2020-10-14 12:27:22 +0200
commit19bbd01b671877812928ba013d4828c213d2f68e (patch)
tree075118161ac10db510d4fed239a6ccc691d04399
parentf5977a2ac9a000b0fcef546a05f3ed6121906bbd (diff)
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 <nemeth@numbertext.org> Reviewed-by: László Németh <nemeth@numbertext.org> (cherry picked from commit 3e85b22769a4b02744a7006d7dc772973c0093f5) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/104292 Tested-by: Gabor Kelemen <kelemen.gabor2@nisz.hu> Reviewed-by: Gabor Kelemen <kelemen.gabor2@nisz.hu>
-rw-r--r--sc/qa/unit/data/xlsx/testShapeDisplacementOnRotationImport.xlsxbin0 -> 8067 bytes
-rw-r--r--sc/qa/unit/subsequent_filters-test.cxx19
-rw-r--r--sc/source/filter/oox/drawingfragment.cxx8
3 files changed, 24 insertions, 3 deletions
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
--- /dev/null
+++ b/sc/qa/unit/data/xlsx/testShapeDisplacementOnRotationImport.xlsx
Binary files differ
diff --git a/sc/qa/unit/subsequent_filters-test.cxx b/sc/qa/unit/subsequent_filters-test.cxx
index 99840eceaaae..149dbeb2b808 100644
--- a/sc/qa/unit/subsequent_filters-test.cxx
+++ b/sc/qa/unit/subsequent_filters-test.cxx
@@ -253,6 +253,7 @@ public:
void testXLSDefColWidth();
void testPreviewMissingObjLink();
void testShapeRotationImport();
+ void testShapeDisplacementOnRotationImport();
CPPUNIT_TEST_SUITE(ScFiltersTest);
CPPUNIT_TEST(testBooleanFormatXLSX);
@@ -396,6 +397,7 @@ public:
CPPUNIT_TEST(testXLSDefColWidth);
CPPUNIT_TEST(testPreviewMissingObjLink);
CPPUNIT_TEST(testShapeRotationImport);
+ CPPUNIT_TEST(testShapeDisplacementOnRotationImport);
CPPUNIT_TEST_SUITE_END();
@@ -4393,6 +4395,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 716c46d1f974..3ec32dcd0e42 100644
--- a/sc/source/filter/oox/drawingfragment.cxx
+++ b/sc/source/filter/oox/drawingfragment.cxx
@@ -294,9 +294,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 ) );
@@ -313,7 +315,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