diff options
author | Regina Henschel <rb.henschel@t-online.de> | 2021-01-15 17:40:10 +0100 |
---|---|---|
committer | Regina Henschel <rb.henschel@t-online.de> | 2021-01-16 15:27:04 +0100 |
commit | 6ce66560c59470a9eb76fbf80f439b452166d3e4 (patch) | |
tree | 5cc9d882fd18e4971ca58c7dc119b9f0024aba63 /sc/qa | |
parent | 19e5606df73994bbf6ddd8089843be645bd4d8be (diff) |
tdf#139583 fix case rot 180deg for cell anchored shapes
Method adjustAnchoredPosition() in ScDrawView::Notify() needs to
distinguish whether an object really has a changed geometry or only
becomes visible. The previous solution used the snap rectangle for this.
But in the case of a 180deg rotation only the logic rectangle changes,
not the snap rectangle. The patch extends the test to consider logic
rectangle as well. SetCellAnchoredFromPosition is adjusted to create
maShapeRect, which is compared to the logic rectangle.
Change-Id: Iba8a173938da05178f1058ef98e9ef526cca490e
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/109386
Tested-by: Jenkins
Reviewed-by: Regina Henschel <rb.henschel@t-online.de>
Diffstat (limited to 'sc/qa')
-rw-r--r-- | sc/qa/unit/scshapetest.cxx | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/sc/qa/unit/scshapetest.cxx b/sc/qa/unit/scshapetest.cxx index 64f3416c0264..bc5df4d4854c 100644 --- a/sc/qa/unit/scshapetest.cxx +++ b/sc/qa/unit/scshapetest.cxx @@ -19,6 +19,7 @@ #include <svx/svdoashp.hxx> #include <svx/svdomeas.hxx> #include <svx/svdpage.hxx> +#include <svx/svdorect.hxx> #include <unotools/tempfile.hxx> #include <vcl/keycodes.hxx> @@ -39,6 +40,7 @@ public: ScShapeTest(); void saveAndReload(css::uno::Reference<css::lang::XComponent>& xComponent, const OUString& rFilter); + void testTdf139583_Rotate180deg(); void testTdf137033_FlipHori_Resize(); void testTdf137033_RotShear_ResizeHide(); void testTdf137033_RotShear_Hide(); @@ -58,6 +60,7 @@ public: void testCustomShapeCellAnchoredRotatedShape(); CPPUNIT_TEST_SUITE(ScShapeTest); + CPPUNIT_TEST(testTdf139583_Rotate180deg); CPPUNIT_TEST(testTdf137033_FlipHori_Resize); CPPUNIT_TEST(testTdf137033_RotShear_ResizeHide); CPPUNIT_TEST(testTdf137033_RotShear_Hide); @@ -145,6 +148,62 @@ static void lcl_AssertPointEqualWithTolerance(std::string_view sInfo, const Poin CPPUNIT_ASSERT_MESSAGE(sMsg.getStr(), std::abs(rExpected.Y() - rActual.Y()) <= nTolerance); } +void ScShapeTest::testTdf139583_Rotate180deg() +{ + // Load an empty document. + OUString aFileURL; + createFileURL(u"ManualColWidthRowHeight.ods", aFileURL); + uno::Reference<css::lang::XComponent> xComponent = loadFromDesktop(aFileURL); + CPPUNIT_ASSERT(xComponent.is()); + + // Get ScDocShell + SfxObjectShell* pFoundShell = SfxObjectShell::GetShellFromComponent(xComponent); + CPPUNIT_ASSERT_MESSAGE("Failed to access document shell", pFoundShell); + ScDocShell* pDocSh = dynamic_cast<ScDocShell*>(pFoundShell); + CPPUNIT_ASSERT(pDocSh); + + // Get SdrPage + ScDocument& rDoc = pDocSh->GetDocument(); + ScDrawLayer* pDrawLayer = rDoc.GetDrawLayer(); + CPPUNIT_ASSERT_MESSAGE("No ScDrawLayer", pDrawLayer); + SdrPage* pPage = pDrawLayer->GetPage(0); + CPPUNIT_ASSERT_MESSAGE("No draw page", pPage); + + // Insert Shape + const tools::Rectangle aRect(Point(3000, 4000), Size(5000, 2000)); + SdrRectObj* pObj = new SdrRectObj(*pDrawLayer, aRect); + CPPUNIT_ASSERT_MESSAGE("Could not create rectangle", pObj); + pPage->InsertObject(pObj); + + // Anchor "to cell (resize with cell)" and then rotate it by 180deg around center + // The order is important here. + ScDrawLayer::SetCellAnchoredFromPosition(*pObj, rDoc, 0 /*SCTAB*/, true /*bResizeWithCell*/); + pObj->Rotate(aRect.Center(), Degree100(18000), 0.0, -1.0); + + // Save and reload. + saveAndReload(xComponent, "calc8"); + CPPUNIT_ASSERT(xComponent); + + // Get ScDocShell + pFoundShell = SfxObjectShell::GetShellFromComponent(xComponent); + CPPUNIT_ASSERT_MESSAGE("Reload: Failed to access document shell", pFoundShell); + pDocSh = dynamic_cast<ScDocShell*>(pFoundShell); + CPPUNIT_ASSERT(pDocSh); + + // Get document and object + ScDocument& rDoc2 = pDocSh->GetDocument(); + pDrawLayer = rDoc2.GetDrawLayer(); + CPPUNIT_ASSERT_MESSAGE("Reload: No ScDrawLayer", pDrawLayer); + pPage = pDrawLayer->GetPage(0); + CPPUNIT_ASSERT_MESSAGE("Reload: No draw page", pPage); + pObj = dynamic_cast<SdrRectObj*>(pPage->GetObj(0)); + CPPUNIT_ASSERT_MESSAGE("Reload: Shape no longer exists", pObj); + + // Without the fix in place, the shape would have nearly zero size. + lcl_AssertRectEqualWithTolerance("Show: Object geometry should not change", aRect, + pObj->GetSnapRect(), 1); +} + void ScShapeTest::testTdf137033_FlipHori_Resize() { // Load a document, which has a rotated custom shape, which is horizontal flipped. Error was, that |