diff options
-rw-r--r-- | include/oox/drawingml/clrscheme.hxx | 2 | ||||
-rw-r--r-- | oox/qa/unit/drawingml.cxx | 7 | ||||
-rw-r--r-- | oox/source/drawingml/clrscheme.cxx | 18 | ||||
-rw-r--r-- | oox/source/drawingml/theme.cxx | 4 | ||||
-rw-r--r-- | svx/source/styles/ColorSets.cxx | 33 |
5 files changed, 62 insertions, 2 deletions
diff --git a/include/oox/drawingml/clrscheme.hxx b/include/oox/drawingml/clrscheme.hxx index fbb107601940..01711fe8bfbd 100644 --- a/include/oox/drawingml/clrscheme.hxx +++ b/include/oox/drawingml/clrscheme.hxx @@ -92,6 +92,8 @@ public: void SetName(const OUString& rName) { maName = rName; } const OUString& GetName() const { return maName; } + + void ToAny(css::uno::Any& rVal) const; }; } diff --git a/oox/qa/unit/drawingml.cxx b/oox/qa/unit/drawingml.cxx index b220170f3edc..e45ee8d98dd1 100644 --- a/oox/qa/unit/drawingml.cxx +++ b/oox/qa/unit/drawingml.cxx @@ -419,6 +419,13 @@ CPPUNIT_TEST_FIXTURE(OoxDrawingmlTest, testPptxTheme) // i.e. the name of the color scheme was lost on import. CPPUNIT_ASSERT_EQUAL(OUString("Office"), aMap["ColorSchemeName"].get<OUString>()); + // Check the last color in the color set, value is from ppt/theme/theme1.xml. + // Without the accompanying fix in place, this test would have failed with: + // - Cannot extract an Any(void) to []long! + auto aColorScheme = aMap["ColorScheme"].get<uno::Sequence<util::Color>>(); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(12), aColorScheme.getLength()); + CPPUNIT_ASSERT_EQUAL(static_cast<util::Color>(0x954F72), aColorScheme[11]); + // Check the reference to that theme: uno::Reference<drawing::XShapes> xDrawPageShapes(xDrawPage, uno::UNO_QUERY); uno::Reference<text::XTextRange> xShape(xDrawPageShapes->getByIndex(0), uno::UNO_QUERY); diff --git a/oox/source/drawingml/clrscheme.cxx b/oox/source/drawingml/clrscheme.cxx index 6b391d7877a8..19c0afd44900 100644 --- a/oox/source/drawingml/clrscheme.cxx +++ b/oox/source/drawingml/clrscheme.cxx @@ -19,9 +19,15 @@ #include <algorithm> +#include <com/sun/star/uno/Sequence.hxx> +#include <com/sun/star/util/Color.hpp> + #include <osl/diagnose.h> #include <oox/drawingml/clrscheme.hxx> #include <oox/token/tokens.hxx> +#include <comphelper/sequence.hxx> + +using namespace com::sun::star; namespace oox::drawingml { @@ -102,6 +108,18 @@ bool ClrScheme::getColorByIndex(size_t nIndex, ::Color& rColor) const return true; } +void ClrScheme::ToAny(css::uno::Any& rVal) const +{ + std::vector<util::Color> aRet; + + for (const auto& rIndexAndColor : maClrScheme) + { + aRet.push_back(static_cast<sal_Int32>(rIndexAndColor.second)); + } + + rVal <<= comphelper::containerToSequence(aRet); +} + } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/oox/source/drawingml/theme.cxx b/oox/source/drawingml/theme.cxx index ba1761311154..56df9941169c 100644 --- a/oox/source/drawingml/theme.cxx +++ b/oox/source/drawingml/theme.cxx @@ -105,9 +105,13 @@ const TextFont* Theme::resolveFont( const OUString& rName ) const void Theme::addTheme(const css::uno::Reference<css::drawing::XDrawPage>& xDrawPage) const { + beans::PropertyValue aColorScheme; + aColorScheme.Name = "ColorScheme"; + maClrScheme.ToAny(aColorScheme.Value); beans::PropertyValues aValues = { comphelper::makePropertyValue("Name", maThemeName), comphelper::makePropertyValue("ColorSchemeName", maClrScheme.GetName()), + aColorScheme, }; uno::Reference<beans::XPropertySet> xPropertySet(xDrawPage, uno::UNO_QUERY); xPropertySet->setPropertyValue("Theme", uno::makeAny(aValues)); diff --git a/svx/source/styles/ColorSets.cxx b/svx/source/styles/ColorSets.cxx index fbcf4bd4a889..773e7c414ef3 100644 --- a/svx/source/styles/ColorSets.cxx +++ b/svx/source/styles/ColorSets.cxx @@ -15,9 +15,12 @@ #include <libxml/xmlwriter.h> #include <com/sun/star/beans/PropertyValues.hpp> +#include <com/sun/star/util/Color.hpp> #include <comphelper/propertyvalue.hxx> #include <comphelper/sequenceashashmap.hxx> +#include <comphelper/sequence.hxx> +#include <sal/log.hxx> using namespace com::sun::star; @@ -169,7 +172,14 @@ void Theme::ToAny(css::uno::Any& rVal) const if (mpColorSet) { + std::vector<util::Color> aColorScheme; + for (size_t i = 0; i < 12; ++i) + { + aColorScheme.push_back(static_cast<sal_Int32>(mpColorSet->getColor(i))); + } + aMap["ColorSchemeName"] <<= mpColorSet->getName(); + aMap["ColorScheme"] <<= comphelper::containerToSequence(aColorScheme); } rVal <<= aMap.getAsConstPropertyValueList(); @@ -179,6 +189,7 @@ std::unique_ptr<Theme> Theme::FromAny(const css::uno::Any& rVal) { comphelper::SequenceAsHashMap aMap(rVal); std::unique_ptr<Theme> pTheme; + ColorSet* pColorSet = nullptr; auto it = aMap.find("Name"); if (it != aMap.end()) @@ -193,8 +204,26 @@ std::unique_ptr<Theme> Theme::FromAny(const css::uno::Any& rVal) { OUString aName; it->second >>= aName; - auto pColorSet = std::make_unique<ColorSet>(aName); - pTheme->SetColorSet(std::move(pColorSet)); + auto pSet = std::make_unique<ColorSet>(aName); + pTheme->SetColorSet(std::move(pSet)); + pColorSet = pTheme->GetColorSet(); + } + + it = aMap.find("ColorScheme"); + if (it != aMap.end() && pColorSet) + { + uno::Sequence<util::Color> aColors; + it->second >>= aColors; + for (size_t i = 0; i < aColors.size(); ++i) + { + if (i >= 12) + { + SAL_WARN("svx", "Theme::FromAny: too many colors in the color set"); + break; + } + + pColorSet->add(i, Color(ColorTransparency, aColors[i])); + } } return pTheme; |