sd/qa/unit/misc-tests.cxx | 65 +++++++++++++++++++++++++++++++++++++++++ sd/source/ui/view/drviews2.cxx | 28 +++++++++++++---- 2 files changed, 86 insertions(+), 7 deletions(-)
New commits: commit 8254bbc20dd4ba3c002b2d3fede7bb067bce7a42 Author: Szymon Kłos <szymon.k...@collabora.com> AuthorDate: Mon May 5 13:33:52 2025 +0000 Commit: Szymon Kłos <szymon.k...@collabora.com> CommitDate: Thu May 8 09:25:36 2025 +0200 Apply none fill style for transparent fill color This is followup for commit df8941ee5bb375de504f106370f28d7f3c12ab70 tdf#163805: set fill style to solid on fill color selection When we have shape in Impress/Draw with solid fill color and we then use .uno:FillColor with "-1" (transparent) color, we should reset Ffill style to NONE. That makes shape transparent. Previous commit was doing something opposite: add SOLID style when color is used. Change-Id: I72bc8a81bc75941f337ed68125536f771c3e7d89 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/184961 Reviewed-by: Tomaž Vajngerl <qui...@gmail.com> Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> (cherry picked from commit 132e45484bb2162da1834409f35039be7b799759) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/185038 Reviewed-by: Szymon Kłos <szymon.k...@collabora.com> diff --git a/sd/qa/unit/misc-tests.cxx b/sd/qa/unit/misc-tests.cxx index 1bbf8364fd3e..c5654c9097e1 100644 --- a/sd/qa/unit/misc-tests.cxx +++ b/sd/qa/unit/misc-tests.cxx @@ -25,7 +25,10 @@ #include <com/sun/star/table/XTable.hpp> #include <com/sun/star/table/XMergeableCellRange.hpp> #include <com/sun/star/lang/XSingleServiceFactory.hpp> +#include <com/sun/star/view/XSelectionSupplier.hpp> +#include <comphelper/sequence.hxx> +#include <comphelper/propertysequence.hxx> #include <DrawDocShell.hxx> #include <drawdoc.hxx> #include <vcl/scheduler.hxx> @@ -65,6 +68,7 @@ public: void testTdf99396(); void testTableObjectUndoTest(); + void testFillColor(); void testFillGradient(); void testTdf44774(); void testTdf38225(); @@ -88,6 +92,7 @@ public: CPPUNIT_TEST_SUITE(SdMiscTest); CPPUNIT_TEST(testTdf99396); CPPUNIT_TEST(testTableObjectUndoTest); + CPPUNIT_TEST(testFillColor); CPPUNIT_TEST(testFillGradient); CPPUNIT_TEST(testTdf44774); CPPUNIT_TEST(testTdf38225); @@ -254,6 +259,66 @@ void SdMiscTest::testTableObjectUndoTest() CPPUNIT_ASSERT_EQUAL(OUString("Format cell"), pDoc->GetUndoManager()->GetUndoActionComment(2)); } +void SdMiscTest::testFillColor() +{ + // Test if setting the shape fill color from color to transparent automatically turns off the fill style to none + createSdImpressDoc(); + uno::Reference<drawing::XDrawPagesSupplier> xDrawPagesSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference<drawing::XDrawPages> xDrawPages = xDrawPagesSupplier->getDrawPages(); + // Insert a new page. + uno::Reference<drawing::XDrawPage> xDrawPage(xDrawPages->insertNewByIndex(0), + uno::UNO_SET_THROW); + uno::Reference<drawing::XShapes> xShapes(xDrawPage, uno::UNO_QUERY_THROW); + // Create a rectangle + uno::Reference<lang::XMultiServiceFactory> xFactory(mxComponent, uno::UNO_QUERY); + CPPUNIT_ASSERT(xFactory.is()); + uno::Reference<drawing::XShape> xShape1( + xFactory->createInstance(u"com.sun.star.drawing.RectangleShape"_ustr), + uno::UNO_QUERY_THROW); + uno::Reference<beans::XPropertySet> xPropSet(xShape1, uno::UNO_QUERY_THROW); + // Set FillStyle and FillColor + xPropSet->setPropertyValue(u"FillStyle"_ustr, uno::Any(drawing::FillStyle_SOLID)); + xPropSet->setPropertyValue(u"FillColor"_ustr, uno::Any(COL_RED)); + // Add the rectangle to the page. + xShapes->add(xShape1); + + // Retrieve the shape and check FillStyle and FillGradient + uno::Reference<container::XIndexAccess> xIndexAccess(xDrawPage, uno::UNO_QUERY_THROW); + uno::Reference<beans::XPropertySet> xPropSet2(xIndexAccess->getByIndex(0), + uno::UNO_QUERY_THROW); + drawing::FillStyle eFillStyle; + Color aColor; + CPPUNIT_ASSERT(xPropSet2->getPropertyValue(u"FillStyle"_ustr) >>= eFillStyle); + CPPUNIT_ASSERT_EQUAL(int(drawing::FillStyle_SOLID), static_cast<int>(eFillStyle)); + CPPUNIT_ASSERT(xPropSet2->getPropertyValue(u"FillColor"_ustr) >>= aColor); + + CPPUNIT_ASSERT_EQUAL(COL_RED, aColor); + + // Setup transparent color and check fill styles + uno::Reference<frame::XModel> xModel(mxComponent, uno::UNO_QUERY); + uno::Reference<view::XSelectionSupplier> xSelectionSupplier(xModel->getCurrentController(), + uno::UNO_QUERY); + + xSelectionSupplier->select(uno::Any(xShape1)); + CPPUNIT_ASSERT(xSelectionSupplier->getSelection().hasValue()); + + const char arguments[] = "{" + "\"FillColor.Color\":{" + "\"type\":\"long\"," + "\"value\":-1" + "}}"; + + dispatchCommand(mxComponent, u".uno:FillColor"_ustr, + comphelper::containerToSequence(comphelper::JsonToPropertyValues(arguments))); + + uno::Reference<container::XIndexAccess> xIndexAccess2(xDrawPage, uno::UNO_QUERY_THROW); + uno::Reference<beans::XPropertySet> xPropSet3(xIndexAccess2->getByIndex(0), + uno::UNO_QUERY_THROW); + drawing::FillStyle eFillStyle2; + CPPUNIT_ASSERT(xPropSet3->getPropertyValue(u"FillStyle"_ustr) >>= eFillStyle2); + CPPUNIT_ASSERT_EQUAL(int(drawing::FillStyle_NONE), static_cast<int>(eFillStyle2)); +} + void SdMiscTest::testFillGradient() { createSdImpressDoc(); diff --git a/sd/source/ui/view/drviews2.cxx b/sd/source/ui/view/drviews2.cxx index 787fc86825ef..2f5c146de8a6 100644 --- a/sd/source/ui/view/drviews2.cxx +++ b/sd/source/ui/view/drviews2.cxx @@ -614,10 +614,29 @@ public: } }; - void lcl_convertStringArguments(const std::unique_ptr<SfxItemSet>& pArgs) + void lcl_convertStringArguments(sal_uInt16 nSId, const std::unique_ptr<SfxItemSet>& pArgs) { const SfxPoolItem* pItem = nullptr; + if (nSId == SID_ATTR_FILL_COLOR) + { + pItem = pArgs->GetItem(SID_ATTR_FILL_COLOR); + Color aColor = pItem ? static_cast<const XFillColorItem*>(pItem)->GetColorValue() : COL_AUTO; + if (aColor.IsFullyTransparent()) + { + const XFillStyleItem aXFillStyleItem(drawing::FillStyle_NONE); + pArgs->Put(aXFillStyleItem); + } + else + { + SfxItemState eState = pArgs->GetItemState(SID_ATTR_FILL_STYLE, false, &pItem); + if (eState != SfxItemState::SET || static_cast<const XFillStyleItem*>(pItem)->GetValue() == drawing::FillStyle_NONE) + { + const XFillStyleItem aXFillStyleItem(drawing::FillStyle_SOLID); + pArgs->Put(aXFillStyleItem); + } + } + } if (SfxItemState::SET == pArgs->GetItemState(SID_ATTR_LINE_WIDTH_ARG, false, &pItem)) { double fValue = static_cast<const SvxDoubleItem*>(pItem)->GetValue(); @@ -729,12 +748,7 @@ void DrawViewShell::FuTemporary(SfxRequest& rReq) if( rReq.GetArgs() ) { std::unique_ptr<SfxItemSet> pNewArgs = rReq.GetArgs()->Clone(); - if (nSId == SID_ATTR_FILL_COLOR) - { - const XFillStyleItem aXFillStyleItem; - pNewArgs->Put(aXFillStyleItem); - } - lcl_convertStringArguments(pNewArgs); + lcl_convertStringArguments(nSId, pNewArgs); mpDrawView->SetAttributes(*pNewArgs); rReq.Done(); }