summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSzabolcs Toth <szabolcs450@gmail.com>2020-08-17 10:55:43 +0200
committerLászló Németh <nemeth@numbertext.org>2020-08-24 18:28:51 +0200
commit5e8875780d665b7ae0fee1a053b5ce78ec513f69 (patch)
tree5032900502913c136b804adf8eba1693b6681bb1
parent4557f04ee9aadc0b399a3bd2e08133d4929221b9 (diff)
tdf#135828 XLSX shape export: fix distortion of rotated shapes
Shapes that were rotated at angles {[45, 135) U [225, 315)} need new anchor positions that does an extra 90 degrees rotation. See commit 130e6a3f4493b987a7d0b177cc84d65219b47d13 (tdf#83593 XLSX DrawingML shape import: fix missing rotation) Co-authored-by: Balázs Regényi Change-Id: I42a5d203cf3b6f6e725d84dd5f39ac323f4f1ceb Reviewed-on: https://gerrit.libreoffice.org/c/core/+/100853 Tested-by: László Németh <nemeth@numbertext.org> Reviewed-by: László Németh <nemeth@numbertext.org>
-rw-r--r--sc/qa/unit/data/xlsx/tdf135828_Shape_Rect.xlsxbin0 -> 9534 bytes
-rw-r--r--sc/qa/unit/subsequent_export-test.cxx20
-rw-r--r--sc/source/filter/xcl97/xcl97rec.cxx19
3 files changed, 39 insertions, 0 deletions
diff --git a/sc/qa/unit/data/xlsx/tdf135828_Shape_Rect.xlsx b/sc/qa/unit/data/xlsx/tdf135828_Shape_Rect.xlsx
new file mode 100644
index 000000000000..c01c81ab6d74
--- /dev/null
+++ b/sc/qa/unit/data/xlsx/tdf135828_Shape_Rect.xlsx
Binary files differ
diff --git a/sc/qa/unit/subsequent_export-test.cxx b/sc/qa/unit/subsequent_export-test.cxx
index c249322cbcf4..d4cce709686f 100644
--- a/sc/qa/unit/subsequent_export-test.cxx
+++ b/sc/qa/unit/subsequent_export-test.cxx
@@ -257,6 +257,7 @@ public:
void testTdf134817_HeaderFooterTextWith2SectionXLSX();
void testTdf121718_UseFirstPageNumberXLSX();
void testHeaderFontStyleXLSX();
+ void testTdf135828_Shape_Rect();
CPPUNIT_TEST_SUITE(ScExportTest);
CPPUNIT_TEST(test);
@@ -412,6 +413,7 @@ public:
CPPUNIT_TEST(testTdf134817_HeaderFooterTextWith2SectionXLSX);
CPPUNIT_TEST(testTdf121718_UseFirstPageNumberXLSX);
CPPUNIT_TEST(testHeaderFontStyleXLSX);
+ CPPUNIT_TEST(testTdf135828_Shape_Rect);
CPPUNIT_TEST_SUITE_END();
@@ -5277,6 +5279,24 @@ void ScExportTest::testHeaderFontStyleXLSX()
xShell->DoClose();
}
+void ScExportTest::testTdf135828_Shape_Rect()
+{
+ // tdf#135828 Check that the width and the height of rectangle of the shape
+ // is correct.
+ ScDocShellRef xShell = loadDoc("tdf135828_Shape_Rect.", FORMAT_XLSX);
+ CPPUNIT_ASSERT(xShell.is());
+
+ ScDocShellRef xDocSh = saveAndReload(&(*xShell), FORMAT_XLSX);
+ CPPUNIT_ASSERT(xDocSh.is());
+
+ std::shared_ptr<utl::TempFile> pXPathFile = ScBootstrapFixture::exportTo(&(*xDocSh), FORMAT_XLSX);
+ xmlDocUniquePtr pDrawing = XPathHelper::parseExport(pXPathFile, m_xSFactory, "xl/drawings/drawing1.xml");
+ CPPUNIT_ASSERT(pDrawing);
+
+ assertXPath(pDrawing, "/xdr:wsDr/xdr:twoCellAnchor/xdr:sp/xdr:spPr/a:xfrm/a:ext", "cx", "294480"); // width
+ assertXPath(pDrawing, "/xdr:wsDr/xdr:twoCellAnchor/xdr:sp/xdr:spPr/a:xfrm/a:ext", "cy", "1990440"); // height
+}
+
CPPUNIT_TEST_SUITE_REGISTRATION(ScExportTest);
CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/sc/source/filter/xcl97/xcl97rec.cxx b/sc/source/filter/xcl97/xcl97rec.cxx
index fa2fc748bf2c..7af2ddc59fa2 100644
--- a/sc/source/filter/xcl97/xcl97rec.cxx
+++ b/sc/source/filter/xcl97/xcl97rec.cxx
@@ -1095,6 +1095,25 @@ void XclObjAny::WriteFromTo( XclExpXmlStream& rStrm, const Reference< XShape >&
awt::Point aTopLeft = rShape->getPosition();
awt::Size aSize = rShape->getSize();
+
+ uno::Reference< beans::XPropertySet > xShapeProperties(rShape, uno::UNO_QUERY_THROW);
+ uno::Any nRotProp = xShapeProperties->getPropertyValue("RotateAngle");
+ sal_Int32 nRot = nRotProp.get<sal_Int32>();
+
+ if ((nRot >= 45 * 100 && nRot < 135 * 100) || (nRot >= 225 * 100 && nRot < 315 * 100))
+ {
+ // MSO changes the anchor positions at these angles and that does an extra 90 degrees
+ // rotation on our shapes, so we output it in such position that MSO
+ // can draw this shape correctly.
+
+ sal_Int16 nHalfWidth = aSize.Width / 2;
+ sal_Int16 nHalfHeight = aSize.Height / 2;
+ aTopLeft.X = aTopLeft.X - nHalfHeight + nHalfWidth;
+ aTopLeft.Y = aTopLeft.Y - nHalfWidth + nHalfHeight;
+
+ std::swap(aSize.Width, aSize.Height);
+ }
+
tools::Rectangle aLocation( aTopLeft.X, aTopLeft.Y, aTopLeft.X + aSize.Width, aTopLeft.Y + aSize.Height );
ScRange aRange = rStrm.GetRoot().GetDoc().GetRange( nTab, aLocation );
tools::Rectangle aRangeRect = rStrm.GetRoot().GetDoc().GetMMRect( aRange.aStart.Col(), aRange.aStart.Row(),