include/oox/drawingml/clrscheme.hxx | 3 +++ include/oox/drawingml/theme.hxx | 1 + include/oox/ppt/pptimport.hxx | 1 + include/sfx2/ColorSets.hxx | 8 +++++++- oox/source/drawingml/clrscheme.cxx | 28 ++++++++++++++++++++++++++++ oox/source/ppt/pptimport.cxx | 31 +++++++++++++++++++++++++++---- sfx2/source/doc/sfxbasemodel.cxx | 23 ++++++++++++----------- 7 files changed, 79 insertions(+), 16 deletions(-)
New commits: commit 3b21d166f585dcdf8d576d166aeff3cfd4694aab Author: Sarper Akdemir <[email protected]> AuthorDate: Mon Sep 13 09:47:11 2021 +0300 Commit: Sarper Akdemir <[email protected]> CommitDate: Mon Sep 13 09:47:11 2021 +0300 import pptx color schemes as color sets initial import work for color sets. Themes (which we get the color schemes from) in MSO can be different for each master - will need to support that too. Change-Id: I30a75de2cbaf22ee48e37ceacabd83452177b697 diff --git a/include/oox/drawingml/clrscheme.hxx b/include/oox/drawingml/clrscheme.hxx index 21553aafe2fe..cd8755e77088 100644 --- a/include/oox/drawingml/clrscheme.hxx +++ b/include/oox/drawingml/clrscheme.hxx @@ -86,6 +86,9 @@ public: bool getColor( sal_Int32 nSchemeClrToken, ::Color& rColor ) const; void setColor( sal_Int32 nSchemeClrToken, ::Color nColor ); + std::vector<::Color> getColorVector(); + std::vector<sal_Int32> getColorVectorAsInts(); + bool getColorByIndex(size_t nIndex, ::Color& rColor) const; }; diff --git a/include/oox/drawingml/theme.hxx b/include/oox/drawingml/theme.hxx index 6d64649f3a69..40ef9784dab0 100644 --- a/include/oox/drawingml/theme.hxx +++ b/include/oox/drawingml/theme.hxx @@ -60,6 +60,7 @@ public: ~Theme(); void setStyleName( const OUString& rStyleName ) { maStyleName = rStyleName; } + const OUString& getStyleName() const { return maStyleName; } ClrScheme& getClrScheme() { return maClrScheme; } const ClrScheme& getClrScheme() const { return maClrScheme; } diff --git a/include/oox/ppt/pptimport.hxx b/include/oox/ppt/pptimport.hxx index 29ef3c5732a6..78f6d363b791 100644 --- a/include/oox/ppt/pptimport.hxx +++ b/include/oox/ppt/pptimport.hxx @@ -85,6 +85,7 @@ private: virtual GraphicHelper* implCreateGraphicHelper() const override; virtual ::oox::ole::VbaProject* implCreateVbaProject() const override; virtual OUString SAL_CALL getImplementationName() override; + void saveImportedThemesIntoDocumentColorSets(); private: OUString maTableStyleListPath; diff --git a/include/sfx2/ColorSets.hxx b/include/sfx2/ColorSets.hxx index ffd3ea4f6ed3..9ca322ab458d 100644 --- a/include/sfx2/ColorSets.hxx +++ b/include/sfx2/ColorSets.hxx @@ -60,6 +60,12 @@ public: const ColorSet& getColorSet(sal_uInt32 nIndex) const { return maColorSets[nIndex]; } const ColorSet& getColorSet(std::u16string_view rName) const; + + int addColorSet(const ColorSet& rColorSet) + { + maColorSets.push_back(rColorSet); + return maColorSets.size() - 1; + } }; class SFX2_DLLPUBLIC SfxColorSetListItem final : public SfxPoolItem @@ -81,7 +87,7 @@ public: virtual bool QueryValue(css::uno::Any& rVal, sal_uInt8 nMemberId = 0) const override; virtual bool PutValue(const css::uno::Any& rVal, sal_uInt8 nMemberId) override; - const ColorSets& GetSfxColorSetList() const { return *mpColorSets; } + ColorSets& GetSfxColorSetList() const { return *mpColorSets; } std::shared_ptr<ColorSets> GetSfxColorSetListPtr() const { return mpColorSets; } }; diff --git a/oox/source/drawingml/clrscheme.cxx b/oox/source/drawingml/clrscheme.cxx index 6b391d7877a8..cb3e9104855d 100644 --- a/oox/source/drawingml/clrscheme.cxx +++ b/oox/source/drawingml/clrscheme.cxx @@ -22,6 +22,7 @@ #include <osl/diagnose.h> #include <oox/drawingml/clrscheme.hxx> #include <oox/token/tokens.hxx> +#include <vector> namespace oox::drawingml { @@ -102,6 +103,33 @@ bool ClrScheme::getColorByIndex(size_t nIndex, ::Color& rColor) const return true; } +std::vector<::Color> ClrScheme::getColorVector() +{ + // most likely should reorder using tokens here... + // this is a experimental hack: + + std::vector<::Color> aColors; + + for( auto rIndexColorPair : maClrScheme ) + { + aColors.emplace_back(rIndexColorPair.second); + } + return aColors; +} + +std::vector<sal_Int32> ClrScheme::getColorVectorAsInts() +{ + // most likely should reorder using tokens here... + // this is a experimental hack: + + std::vector<sal_Int32> aColors; + + for (auto rIndexColorPair : maClrScheme) + { + aColors.emplace_back(static_cast<sal_Int32>(rIndexColorPair.second)); + } + return aColors; +} } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/oox/source/ppt/pptimport.cxx b/oox/source/ppt/pptimport.cxx index 1f569d099876..1dd0ea48557d 100644 --- a/oox/source/ppt/pptimport.cxx +++ b/oox/source/ppt/pptimport.cxx @@ -23,10 +23,12 @@ #include <com/sun/star/frame/XModel.hpp> #include <com/sun/star/lang/XMultiServiceFactory.hpp> #include <com/sun/star/uno/XComponentContext.hpp> +#include <com/sun/star/document/XColorSetsManager.hpp> #include <com/sun/star/document/XUndoManager.hpp> #include <com/sun/star/document/XUndoManagerSupplier.hpp> #include <comphelper/propertysequence.hxx> #include <comphelper/scopeguard.hxx> +#include <comphelper/sequence.hxx> #include <vcl/svapp.hxx> #include <vcl/weld.hxx> #include <svtools/sfxecode.hxx> @@ -58,6 +60,22 @@ namespace oox::ppt { XmlFilterBase* PowerPointImport::mpDebugFilterBase = nullptr; #endif +void PowerPointImport::saveImportedThemesIntoDocumentColorSets() +{ + auto rThemes = getThemes(); + css::uno::Reference<css::document::XColorSetsManager> xColorSetsManager(getModel(), css::uno::UNO_QUERY_THROW); + + for(auto& aItem : rThemes) + { + const OUString& rThemeName = aItem.second->getStyleName(); + drawingml::ClrScheme& rColorScheme = aItem.second->getClrScheme(); // gets the theme color scheme + + auto aColorVector = rColorScheme.getColorVectorAsInts(); + + xColorSetsManager->addNewColorSet(rThemeName, comphelper::containerToSequence(aColorVector)); + } +} + PowerPointImport::PowerPointImport( const Reference< XComponentContext >& rxContext ) : XmlFilterBase( rxContext ), mxChartConv( std::make_shared<::oox::drawingml::chart::ChartConverter>() ) @@ -101,11 +119,16 @@ bool PowerPointImport::importDocument() = xPresentationFragmentHandler->getFragmentPathFromFirstTypeFromOfficeDoc(u"presProps"); bool bRet = importFragment(xPresentationFragmentHandler); - if (bRet && !sPresPropsPath.isEmpty()) + if (bRet) { - FragmentHandlerRef xPresPropsFragmentHandler( - new PresPropsFragmentHandler(*this, sPresPropsPath)); - importFragment(xPresPropsFragmentHandler); + if(!sPresPropsPath.isEmpty()) + { + FragmentHandlerRef xPresPropsFragmentHandler( + new PresPropsFragmentHandler(*this, sPresPropsPath)); + importFragment(xPresPropsFragmentHandler); + } + + saveImportedThemesIntoDocumentColorSets(); } static bool bNoSmartartWarning = getenv("OOX_NO_SMARTART_WARNING"); diff --git a/sfx2/source/doc/sfxbasemodel.cxx b/sfx2/source/doc/sfxbasemodel.cxx index d3d6479e47e4..3178aa601718 100644 --- a/sfx2/source/doc/sfxbasemodel.cxx +++ b/sfx2/source/doc/sfxbasemodel.cxx @@ -2739,22 +2739,23 @@ void SfxBaseModel::loadCmisProperties( ) void SAL_CALL SfxBaseModel::addNewColorSet(const OUString& rColorSetName, const css::uno::Sequence<css::util::Color>& rColorSetColors) { - if(SfxObjectShell* pObjShell = SfxObjectShell::Current()) + if(SfxObjectShell* pObjShell = GetObjectShell()) { if(const SfxColorSetListItem* pColorSetItem = pObjShell->GetItem(SID_COLOR_SETS)) { - pColorSetItem->GetSfxColorSetListPtr();//->AddNewColorSet( NAME, COLORS ); - //SAL/_DEBUG("Got the ColorSet without a problem!"); - } - else - { - //SAL/_DEBUG("Couldn't get pColorSetItem (in addNewColorSet)"); + ColorSet aColorSet(rColorSetName); + int nIndex = 0; + for( const css::util::Color& rColor : rColorSetColors ) + { + aColorSet.add(nIndex++, rColor); + } + + ColorSets& rColorSets = pColorSetItem->GetSfxColorSetList(); + + // let's force it as the selected color set for the moment. + rColorSets.setThemeColorSet( rColorSets.addColorSet(aColorSet) ); } } - else - { - //SAL/_DEBUG("Couldn't get the object shell (in addNewColorSet)"); - } } SfxMedium* SfxBaseModel::handleLoadError( ErrCode nError, SfxMedium* pMedium )
