sd/qa/unit/tiledrendering/tiledrendering.cxx | 38 ++++++++++++++++++++++--- sd/source/ui/annotations/annotationmanager.cxx | 3 + svx/source/annotation/AnnotationObject.cxx | 6 +++ 3 files changed, 43 insertions(+), 4 deletions(-)
New commits: commit ab5774a2f1fc5fceb1600a83d8ae472cfcea8477 Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> AuthorDate: Wed Jul 10 14:22:53 2024 +0900 Commit: Caolán McNamara <caolan.mcnam...@collabora.com> CommitDate: Tue Jul 23 10:19:03 2024 +0200 tdf#161911 annot: fix for annotation with 0 size We need to set the size to something non-zero or it will stay zero even if we try to adapt the frame to the text content. Additionally when we adapt the frame to text, we need to update the annotation with the new size. Change-Id: I4125f95fe6d0e55ab3b00a6a457cd2c9e04ec7c5 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/170260 Reviewed-by: Tomaž Vajngerl <qui...@gmail.com> Tested-by: Jenkins (cherry picked from commit b547e9f19de339531709c14931998125b9a41649) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/170334 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com> diff --git a/sd/qa/unit/tiledrendering/tiledrendering.cxx b/sd/qa/unit/tiledrendering/tiledrendering.cxx index aa415db60cb1..39668614084b 100644 --- a/sd/qa/unit/tiledrendering/tiledrendering.cxx +++ b/sd/qa/unit/tiledrendering/tiledrendering.cxx @@ -1782,6 +1782,24 @@ CPPUNIT_TEST_FIXTURE(SdTiledRenderingTest, testCommentCallbacks) comphelper::LibreOfficeKit::setTiledAnnotations(true); } +namespace +{ + +OUString extractRectangleX(std::string const& rString) +{ + auto rOUString = OUString::createFromAscii(rString); + auto aRectangleStrings = comphelper::string::convertCommaSeparated(rOUString); + return aRectangleStrings[0]; +} + +OUString extractRectangleY(std::string const& rString) +{ + auto aOUString = OUString::createFromAscii(rString); + auto aRectangleStrings = comphelper::string::convertCommaSeparated(aOUString); + return aRectangleStrings[1]; +} + +} CPPUNIT_TEST_FIXTURE(SdTiledRenderingTest, testCommentChangeImpress) { @@ -1811,7 +1829,10 @@ CPPUNIT_TEST_FIXTURE(SdTiledRenderingTest, testCommentChangeImpress) CPPUNIT_ASSERT(!aView1.m_aCommentCallbackResult.get<std::string>("parthash").empty()); CPPUNIT_ASSERT_EQUAL(std::string("Comment"), aView1.m_aCommentCallbackResult.get<std::string>("text")); - CPPUNIT_ASSERT_EQUAL(std::string("0, 0, 282, 282"), aView1.m_aCommentCallbackResult.get<std::string>("rectangle")); + + auto aRectStringBefore = aView1.m_aCommentCallbackResult.get<std::string>("rectangle"); + CPPUNIT_ASSERT_EQUAL(u"0"_ustr, extractRectangleX(aRectStringBefore)); + CPPUNIT_ASSERT_EQUAL(u"0"_ustr, extractRectangleY(aRectStringBefore)); // Edit this annotation now aArgs = comphelper::InitPropertySequence( @@ -1824,7 +1845,10 @@ CPPUNIT_TEST_FIXTURE(SdTiledRenderingTest, testCommentChangeImpress) CPPUNIT_ASSERT_EQUAL(std::string("Modify"), aView1.m_aCommentCallbackResult.get<std::string>("action")); CPPUNIT_ASSERT_EQUAL(std::string("Comment"), aView1.m_aCommentCallbackResult.get<std::string>("text")); - CPPUNIT_ASSERT_EQUAL(std::string("10, 20, 282, 282"), aView1.m_aCommentCallbackResult.get<std::string>("rectangle")); + + auto aRectStringAfter = aView1.m_aCommentCallbackResult.get<std::string>("rectangle"); + CPPUNIT_ASSERT_EQUAL(u"10"_ustr, extractRectangleX(aRectStringAfter)); + CPPUNIT_ASSERT_EQUAL(u"20"_ustr, extractRectangleY(aRectStringAfter)); comphelper::LibreOfficeKit::setTiledAnnotations(true); } @@ -1857,7 +1881,10 @@ CPPUNIT_TEST_FIXTURE(SdTiledRenderingTest, testCommentChangeDraw) CPPUNIT_ASSERT(!aView1.m_aCommentCallbackResult.get<std::string>("parthash").empty()); CPPUNIT_ASSERT_EQUAL(std::string("Comment"), aView1.m_aCommentCallbackResult.get<std::string>("text")); - CPPUNIT_ASSERT_EQUAL(std::string("0, 0, 282, 282"), aView1.m_aCommentCallbackResult.get<std::string>("rectangle")); + + auto aRectStringBefore = aView1.m_aCommentCallbackResult.get<std::string>("rectangle"); + CPPUNIT_ASSERT_EQUAL(u"0"_ustr, extractRectangleX(aRectStringBefore)); + CPPUNIT_ASSERT_EQUAL(u"0"_ustr, extractRectangleY(aRectStringBefore)); // Edit this annotation now aArgs = comphelper::InitPropertySequence( @@ -1870,7 +1897,10 @@ CPPUNIT_TEST_FIXTURE(SdTiledRenderingTest, testCommentChangeDraw) CPPUNIT_ASSERT_EQUAL(std::string("Modify"), aView1.m_aCommentCallbackResult.get<std::string>("action")); CPPUNIT_ASSERT_EQUAL(std::string("Comment"), aView1.m_aCommentCallbackResult.get<std::string>("text")); - CPPUNIT_ASSERT_EQUAL(std::string("10, 20, 282, 282"), aView1.m_aCommentCallbackResult.get<std::string>("rectangle")); + + auto aRectStringAfter = aView1.m_aCommentCallbackResult.get<std::string>("rectangle"); + CPPUNIT_ASSERT_EQUAL(u"10"_ustr, extractRectangleX(aRectStringAfter)); + CPPUNIT_ASSERT_EQUAL(u"20"_ustr, extractRectangleY(aRectStringAfter)); comphelper::LibreOfficeKit::setTiledAnnotations(true); } diff --git a/sd/source/ui/annotations/annotationmanager.cxx b/sd/source/ui/annotations/annotationmanager.cxx index 6ed81042805b..5f7deeb17aaa 100644 --- a/sd/source/ui/annotations/annotationmanager.cxx +++ b/sd/source/ui/annotations/annotationmanager.cxx @@ -1032,6 +1032,9 @@ void AnnotationManagerImpl::SyncAnnotationObjects() auto aRealSize2D = xAnnotation->getSize(); Size aSize(::tools::Long(aRealSize2D.Width * 100.0), ::tools::Long(aRealSize2D.Height * 100.0)); + // If the size is not set, set it to a default value so it is non-zero + if (aSize.getWidth() == 0 || aSize.getHeight() == 0) + aSize = Size(500, 500); ::tools::Rectangle aRectangle(aPosition, aSize); diff --git a/svx/source/annotation/AnnotationObject.cxx b/svx/source/annotation/AnnotationObject.cxx index d69f9be6e9fa..193a3438c277 100644 --- a/svx/source/annotation/AnnotationObject.cxx +++ b/svx/source/annotation/AnnotationObject.cxx @@ -168,6 +168,12 @@ void AnnotationObject::ApplyAnnotationName() aItemSet.Put(makeSdrTextAutoGrowHeightItem(true)); SetMergedItemSet(aItemSet); + + // Update the annotation size after the auto-sizing the frame to content does its magic + auto& xAnnotationData = getAnnotationData(); + css::geometry::RealSize2D aRealSize2D{ GetLogicRect().GetWidth() / 100.0, + GetLogicRect().GetHeight() / 100.0 }; + xAnnotationData->mxAnnotation->SetSize(aRealSize2D); } AnnotationObject::~AnnotationObject() {}