include/editeng/unoprnms.hxx | 1 include/svx/unoshprp.hxx | 1 svx/qa/unit/xoutdev.cxx | 63 ++++++++++++++++++++++++++++++++++++------- svx/source/xoutdev/xattr.cxx | 43 ++++++++++++++++++++++++----- 4 files changed, 91 insertions(+), 17 deletions(-)
New commits: commit 0e083387551acc677efc903bffc866f5aadb3642 Author: Miklos Vajna <vmik...@collabora.com> AuthorDate: Wed Feb 23 20:54:01 2022 +0100 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Thu Feb 24 08:43:12 2022 +0100 sd theme: add UNO API for shape fill color In preparation of adding import/export for this. Change-Id: I195be9e9ccdbb25fa41878a2858c22ee11d189a0 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/130467 Tested-by: Jenkins Reviewed-by: Miklos Vajna <vmik...@collabora.com> diff --git a/include/editeng/unoprnms.hxx b/include/editeng/unoprnms.hxx index 7fc084e79102..d7045b5b56be 100644 --- a/include/editeng/unoprnms.hxx +++ b/include/editeng/unoprnms.hxx @@ -31,6 +31,7 @@ inline constexpr OUStringLiteral UNO_NAME_CHAR_WEIGHT = u"CharWeight"; inline constexpr OUStringLiteral UNO_NAME_FILLSTYLE = u"FillStyle"; inline constexpr OUStringLiteral UNO_NAME_FILLCOLOR = u"FillColor"; +inline constexpr OUStringLiteral UNO_NAME_FILLCOLOR_THEME = u"FillColorTheme"; inline constexpr OUStringLiteral UNO_NAME_FILLGRADIENT = u"FillGradient"; inline constexpr OUStringLiteral UNO_NAME_FILLGRADIENTNAME = u"FillGradientName"; inline constexpr OUStringLiteral UNO_NAME_FILLHATCH = u"FillHatch"; diff --git a/include/svx/unoshprp.hxx b/include/svx/unoshprp.hxx index b20e67ee5dc5..4dba8617f7a2 100644 --- a/include/svx/unoshprp.hxx +++ b/include/svx/unoshprp.hxx @@ -289,6 +289,7 @@ { UNO_NAME_FILLTRANSPARENCEGRADIENT, XATTR_FILLFLOATTRANSPARENCE, ::cppu::UnoType<css::awt::Gradient>::get(), 0, MID_FILLGRADIENT}, \ { UNO_NAME_FILLTRANSPARENCEGRADIENTNAME, XATTR_FILLFLOATTRANSPARENCE, ::cppu::UnoType<OUString>::get(), 0, MID_NAME }, \ { UNO_NAME_FILLCOLOR_2, XATTR_SECONDARYFILLCOLOR, ::cppu::UnoType<sal_Int32>::get(), 0, 0}, \ + { UNO_NAME_FILLCOLOR_THEME, XATTR_FILLCOLOR, ::cppu::UnoType<sal_Int16>::get(), 0, MID_COLOR_THEME_INDEX}, \ { UNO_NAME_GRAPHIC_GRAPHICCROP, SDRATTR_GRAFCROP , ::cppu::UnoType<css::text::GraphicCrop>::get(), 0, 0 }, #define EDGERADIUS_PROPERTIES \ diff --git a/svx/qa/unit/xoutdev.cxx b/svx/qa/unit/xoutdev.cxx index 35eac21cda72..ed5b75189c3a 100644 --- a/svx/qa/unit/xoutdev.cxx +++ b/svx/qa/unit/xoutdev.cxx @@ -7,10 +7,12 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include <cppunit/TestAssert.h> -#include <cppunit/TestFixture.h> -#include <cppunit/extensions/HelperMacros.h> -#include <unotest/bootstrapfixturebase.hxx> +#include <test/bootstrapfixture.hxx> +#include <unotest/macros_test.hxx> + +#include <com/sun/star/frame/Desktop.hpp> +#include <com/sun/star/drawing/XDrawPagesSupplier.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> #include <sal/types.h> #include <sfx2/app.hxx> @@ -22,16 +24,33 @@ #include <svx/xoutbmp.hxx> #include <vcl/filter/PDFiumLibrary.hxx> -class XOutdevTest : public CppUnit::TestFixture +using namespace com::sun::star; + +class XOutdevTest : public test::BootstrapFixture, public unotest::MacrosTest { + uno::Reference<lang::XComponent> mxComponent; + public: - virtual void setUp() override - { - CppUnit::TestFixture::setUp(); - SfxApplication::GetOrCreate(); - } + virtual void setUp() override; + void tearDown() override; + uno::Reference<lang::XComponent>& getComponent() { return mxComponent; } }; +void XOutdevTest::setUp() +{ + test::BootstrapFixture::setUp(); + + mxDesktop.set(frame::Desktop::create(mxComponentContext)); +} + +void XOutdevTest::tearDown() +{ + if (mxComponent.is()) + mxComponent->dispose(); + + test::BootstrapFixture::tearDown(); +} + CPPUNIT_TEST_FIXTURE(XOutdevTest, testPdfGraphicExport) { auto pPdfium = vcl::pdf::PDFiumLibrary::get(); @@ -96,4 +115,28 @@ CPPUNIT_TEST_FIXTURE(XOutdevTest, testTdf60684) CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt8>('G'), sFirstBytes[3]); } +CPPUNIT_TEST_FIXTURE(XOutdevTest, testFillColorThemeUnoApi) +{ + // Given an empty Impress document with a (title) shape: + getComponent() = loadFromDesktop("private:factory/simpress", + "com.sun.star.presentation.PresentationDocument"); + + // When setting the theme index of the shape's fill color: + uno::Reference<drawing::XDrawPagesSupplier> xPagesSupplier(getComponent(), uno::UNO_QUERY); + uno::Reference<drawing::XDrawPage> xPage(xPagesSupplier->getDrawPages()->getByIndex(0), + uno::UNO_QUERY); + uno::Reference<beans::XPropertySet> xShape(xPage->getByIndex(0), uno::UNO_QUERY); + sal_Int16 nExpected = 4; // Accent 1 + xShape->setPropertyValue("FillColorTheme", uno::makeAny(nExpected)); + + // Then make sure the value we read back is the expected one: + sal_Int16 nActual = -1; + xShape->getPropertyValue("FillColorTheme") >>= nActual; + // Without the accompanying fix in place, this test would have failed with: + // - Expected: 4 + // - Actual : -1 + // i.e. setting the value was broken. + CPPUNIT_ASSERT_EQUAL(nExpected, nActual); +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svx/source/xoutdev/xattr.cxx b/svx/source/xoutdev/xattr.cxx index 81d10a97061c..e28c85b4a70b 100644 --- a/svx/source/xoutdev/xattr.cxx +++ b/svx/source/xoutdev/xattr.cxx @@ -1900,20 +1900,49 @@ bool XFillColorItem::GetPresentation return true; } -bool XFillColorItem::QueryValue( css::uno::Any& rVal, sal_uInt8 /*nMemberId*/) const +bool XFillColorItem::QueryValue( css::uno::Any& rVal, sal_uInt8 nMemberId ) const { - rVal <<= GetColorValue().GetRGBColor(); + nMemberId &= ~CONVERT_TWIPS; + switch (nMemberId) + { + case MID_COLOR_THEME_INDEX: + { + rVal <<= GetThemeColor().GetThemeIndex(); + break; + } + default: + { + rVal <<= GetColorValue().GetRGBColor(); + break; + } + } return true; } -bool XFillColorItem::PutValue( const css::uno::Any& rVal, sal_uInt8 /*nMemberId*/) +bool XFillColorItem::PutValue( const css::uno::Any& rVal, sal_uInt8 nMemberId ) { - Color nValue; - if(!(rVal >>= nValue )) - return false; + nMemberId &= ~CONVERT_TWIPS; + switch(nMemberId) + { + case MID_COLOR_THEME_INDEX: + { + sal_Int16 nIndex = -1; + if (!(rVal >>= nIndex)) + return false; + GetThemeColor().SetThemeIndex(nIndex); + break; + } + default: + { + Color nValue; + if(!(rVal >>= nValue )) + return false; - SetColorValue( nValue ); + SetColorValue( nValue ); + break; + } + } return true; }