Apply none fill style for transparent fill color

This is followup for commit df8941ee5b
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 <quikee@gmail.com>
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/185808
Tested-by: Jenkins
Reviewed-by: Szymon Kłos <szymon.klos@collabora.com>
This commit is contained in:
Szymon Kłos
2025-05-27 06:25:02 +02:00
parent 1d52b5b089
commit 2b80f24529
2 changed files with 86 additions and 7 deletions
+65
View File
@@ -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>
@@ -70,6 +73,7 @@ public:
void testTdf99396();
void testTableObjectUndoTest();
void testFillColor();
void testFillGradient();
void testTdf44774();
void testTdf38225();
@@ -96,6 +100,7 @@ public:
CPPUNIT_TEST_SUITE(SdMiscTest);
CPPUNIT_TEST(testTdf99396);
CPPUNIT_TEST(testTableObjectUndoTest);
CPPUNIT_TEST(testFillColor);
CPPUNIT_TEST(testFillGradient);
CPPUNIT_TEST(testTdf44774);
CPPUNIT_TEST(testTdf38225);
@@ -264,6 +269,66 @@ void SdMiscTest::testTableObjectUndoTest()
CPPUNIT_ASSERT_EQUAL(u"Format cell"_ustr, 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();
+21 -7
View File
@@ -622,10 +622,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();
@@ -739,12 +758,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();
}