summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRegina Henschel <rb.henschel@t-online.de>2021-09-05 01:28:44 +0200
committerXisco Fauli <xiscofauli@libreoffice.org>2021-09-07 17:05:50 +0200
commit7ed532a2cbce52cd20b0801116d35ce713365f76 (patch)
tree5ecf68c3cc096da5a7c520bd471f18cf877c7412
parent463a1012c3e22ce40209b9fddd7cd5df4ae0870a (diff)
tdf#144242 no width-height swap for line and pathline
MS Office swaps width and height for rotation angle ranges 45..135 and 225..315. Line and Pathline objects incorporate the rotation into their points, so have no rotation. Line and open Pathline objects nevertheless report an rotation angle. That one is used to align the text direction to the line. But because of this reported angle, width and height were swapped. The patch excludes these objects explicitly. The case differentiation for the rotation range had forgotten to normalize the angle. Therefore, in a reopened spreadsheet, the line was accidentally exported correctly without width-height swap, because in this case the rotation angle is negative. Change-Id: I5f698d1cc734e17bcb02ff77db5224a228392e06 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/121661 Tested-by: Jenkins Reviewed-by: Regina Henschel <rb.henschel@t-online.de> (cherry picked from commit 84d6d704682a4d0e037a28895356b073e4f992a5) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/121752 Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
-rw-r--r--sc/qa/unit/scshapetest.cxx84
-rw-r--r--sc/source/filter/xcl97/xcl97rec.cxx8
2 files changed, 90 insertions, 2 deletions
diff --git a/sc/qa/unit/scshapetest.cxx b/sc/qa/unit/scshapetest.cxx
index c178c28578a6..5586cdb954f2 100644
--- a/sc/qa/unit/scshapetest.cxx
+++ b/sc/qa/unit/scshapetest.cxx
@@ -71,6 +71,8 @@ public:
void testTdf115655_HideDetail();
void testFitToCellSize();
void testCustomShapeCellAnchoredRotatedShape();
+ void testTdf144242_Line_noSwapWH();
+ void testTdf144242_OpenBezier_noSwapWH();
CPPUNIT_TEST_SUITE(ScShapeTest);
CPPUNIT_TEST(testTdf143619_validation_circle_pos);
@@ -98,6 +100,8 @@ public:
CPPUNIT_TEST(testTdf115655_HideDetail);
CPPUNIT_TEST(testFitToCellSize);
CPPUNIT_TEST(testCustomShapeCellAnchoredRotatedShape);
+ CPPUNIT_TEST(testTdf144242_Line_noSwapWH);
+ CPPUNIT_TEST(testTdf144242_OpenBezier_noSwapWH);
CPPUNIT_TEST_SUITE_END();
};
@@ -206,6 +210,86 @@ static SdrObject* lcl_getSdrObjectWithAssert(ScDocument& rDoc, sal_uInt16 nObjNu
return pObj;
}
+void ScShapeTest::testTdf144242_OpenBezier_noSwapWH()
+{
+ // Shapes, which have rotation incorporated in their points, got erroneously width-height
+ // swapped, because they report a rotation. (Rotation was introduced to align text with curve.)
+
+ // Create a spreadsheet document with default row height and col width
+ uno::Reference<lang::XComponent> xComponent
+ = loadFromDesktop("private:factory/scalc", "com.sun.star.sheet.SpreadsheetDocument");
+
+ // Get ScDocShell
+ ScDocShell* pDocSh = lcl_getScDocShellWithAssert(xComponent);
+
+ // Insert default open Bezier curve
+ ScTabViewShell* pTabViewShell = lcl_getScTabViewShellWithAssert(pDocSh);
+ SfxRequest aReq(pTabViewShell->GetViewFrame(), SID_DRAW_BEZIER_NOFILL);
+ aReq.SetModifier(KEY_MOD1); // Ctrl
+ pTabViewShell->ExecDraw(aReq);
+ pTabViewShell->SetDrawShell(false);
+
+ // Get document and newly created object
+ ScDocument& rDoc = pDocSh->GetDocument();
+ SdrObject* pObj = lcl_getSdrObjectWithAssert(rDoc, 0);
+
+ // Rotate object by 300deg
+ pObj->Rotate(pObj->GetSnapRect().Center(), 30000_deg100, sin(toRadians(30000_deg100)),
+ cos(toRadians(30000_deg100)));
+ tools::Rectangle aExpectRect(pObj->GetSnapRect());
+
+ // Save, reload and compare
+ saveAndReload(xComponent, "Calc Office Open XML");
+ pDocSh = lcl_getScDocShellWithAssert(xComponent);
+ ScDocument& rDoc2 = pDocSh->GetDocument();
+ pObj = lcl_getSdrObjectWithAssert(rDoc2, 0);
+ tools::Rectangle aSnapRect(pObj->GetSnapRect());
+ // Without fix in place width and height were swapped
+ lcl_AssertRectEqualWithTolerance("Reload: wrong pos and size", aExpectRect, aSnapRect, 30);
+
+ pDocSh->DoClose();
+}
+
+void ScShapeTest::testTdf144242_Line_noSwapWH()
+{
+ // Shapes, which have rotation incorporated in their points, got erroneously width-height
+ // swapped, because they report a rotation. (Rotation was introduced to align text with line.)
+
+ // Create a spreadsheet document with default row height and col width
+ uno::Reference<lang::XComponent> xComponent
+ = loadFromDesktop("private:factory/scalc", "com.sun.star.sheet.SpreadsheetDocument");
+
+ // Get ScDocShell
+ ScDocShell* pDocSh = lcl_getScDocShellWithAssert(xComponent);
+
+ // Insert default line
+ ScTabViewShell* pTabViewShell = lcl_getScTabViewShellWithAssert(pDocSh);
+ SfxRequest aReq(pTabViewShell->GetViewFrame(), SID_DRAW_LINE);
+ aReq.SetModifier(KEY_MOD1); // Ctrl
+ pTabViewShell->ExecDraw(aReq);
+ pTabViewShell->SetDrawShell(false);
+
+ // Get document and newly created object
+ ScDocument& rDoc = pDocSh->GetDocument();
+ SdrObject* pObj = lcl_getSdrObjectWithAssert(rDoc, 0);
+
+ // Rotate object by 300deg
+ pObj->Rotate(pObj->GetSnapRect().Center(), 30000_deg100, sin(toRadians(30000_deg100)),
+ cos(toRadians(30000_deg100)));
+ tools::Rectangle aExpectRect(pObj->GetSnapRect());
+
+ // Save, reload and compare
+ saveAndReload(xComponent, "Calc Office Open XML");
+ pDocSh = lcl_getScDocShellWithAssert(xComponent);
+ ScDocument& rDoc2 = pDocSh->GetDocument();
+ pObj = lcl_getSdrObjectWithAssert(rDoc2, 0);
+ tools::Rectangle aSnapRect(pObj->GetSnapRect());
+ // Without fix in place width and height were swapped
+ lcl_AssertRectEqualWithTolerance("Reload: wrong pos and size", aExpectRect, aSnapRect, 30);
+
+ pDocSh->DoClose();
+}
+
void ScShapeTest::testTdf143619_validation_circle_pos()
{
// Load a document, which has validation circle around cell E6.
diff --git a/sc/source/filter/xcl97/xcl97rec.cxx b/sc/source/filter/xcl97/xcl97rec.cxx
index b88604fb306d..19aaa0e934d7 100644
--- a/sc/source/filter/xcl97/xcl97rec.cxx
+++ b/sc/source/filter/xcl97/xcl97rec.cxx
@@ -1092,10 +1092,14 @@ void XclObjAny::WriteFromTo( XclExpXmlStream& rStrm, const Reference< XShape >&
awt::Size aSize = rShape->getSize();
// There are a few cases where we must adjust these values
+ // Do not adjust objects, which have rotation incorporated into their points
+ // but report a rotation angle nevertheless.
SdrObject* pObj = SdrObject::getSdrObjectFromXShape(rShape);
- if (pObj)
+ if (pObj && pObj->GetObjIdentifier() != OBJ_LINE && pObj->GetObjIdentifier() != OBJ_PLIN
+ && pObj->GetObjIdentifier() != OBJ_PATHLINE && pObj->GetObjIdentifier() != OBJ_FREELINE
+ && pObj->GetObjIdentifier() != OBJ_PATHPLIN)
{
- Degree100 nRotation = pObj->GetRotateAngle();
+ Degree100 nRotation = NormAngle36000(pObj->GetRotateAngle());
if (nRotation)
{
sal_Int16 nHalfWidth = aSize.Width / 2;