diff options
author | Szymon Kłos <szymon.klos@collabora.com> | 2017-10-17 22:14:38 +0200 |
---|---|---|
committer | Szymon Kłos <szymon.klos@collabora.com> | 2017-10-19 21:02:07 +0200 |
commit | 98133504fde1e1b235c39e4bb3b72bb2ee0b7819 (patch) | |
tree | a40a89027bf64ac74fa9a3a76b0989e8bd679c7f /oox | |
parent | 278bdbca318defa3bb862e0422cff2492ef46705 (diff) |
PPTX export: remember color schemes in theme
Remember color scheme from loaded pptx file
or use default values.
Change-Id: Icb69c51603afc5f332c20c75e4ed5f659f4b5614
Reviewed-on: https://gerrit.libreoffice.org/43470
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Szymon Kłos <szymon.klos@collabora.com>
Diffstat (limited to 'oox')
-rw-r--r-- | oox/source/export/drawingml.cxx | 2 | ||||
-rw-r--r-- | oox/source/ppt/presentationfragmenthandler.cxx | 76 |
2 files changed, 77 insertions, 1 deletions
diff --git a/oox/source/export/drawingml.cxx b/oox/source/export/drawingml.cxx index 306e884fc0f3..953c16467596 100644 --- a/oox/source/export/drawingml.cxx +++ b/oox/source/export/drawingml.cxx @@ -2943,7 +2943,7 @@ void DrawingML::WriteStyleProperties( sal_Int32 nTokenId, const Sequence< Proper aProperties[i].Value >>= aTransformations; } mpFS->startElementNS( XML_a, nTokenId, XML_idx, I32S( nIdx ), FSEND ); - WriteColor( sSchemeClr, aTransformations ); + WriteColor(sSchemeClr, aTransformations); mpFS->endElementNS( XML_a, nTokenId ); } else diff --git a/oox/source/ppt/presentationfragmenthandler.cxx b/oox/source/ppt/presentationfragmenthandler.cxx index 07433617b612..f78e75c1bc00 100644 --- a/oox/source/ppt/presentationfragmenthandler.cxx +++ b/oox/source/ppt/presentationfragmenthandler.cxx @@ -64,6 +64,22 @@ using namespace ::com::sun::star::xml::sax; namespace oox { namespace ppt { +static std::map<PredefinedClrSchemeId, sal_Int32> PredefinedClrTokens = +{ + //{ dk1, XML_dk1 }, + //{ lt1, XML_lt1 }, + { dk2, XML_dk2 }, + { lt2, XML_lt2 }, + { accent1, XML_accent1 }, + { accent2, XML_accent2 }, + { accent3, XML_accent3 }, + { accent4, XML_accent4 }, + { accent5, XML_accent5 }, + { accent6, XML_accent6 }, + { hlink, XML_hlink }, + { folHlink, XML_folHlink } +}; + PresentationFragmentHandler::PresentationFragmentHandler( XmlFilterBase& rFilter, const OUString& rFragmentPath ) throw() : FragmentHandler2( rFilter, rFragmentPath ) , mpTextListStyle( new TextListStyle ) @@ -143,6 +159,65 @@ void ResolveTextFields( XmlFilterBase const & rFilter ) } } +void PresentationFragmentHandler::saveThemeToGrabBag(oox::drawingml::ThemePtr pThemePtr, const OUString& sTheme) +{ + if (!pThemePtr) + return; + + try + { + uno::Reference<beans::XPropertySet> xDocProps(getFilter().getModel(), uno::UNO_QUERY); + if (xDocProps.is()) + { + uno::Reference<beans::XPropertySetInfo> xPropsInfo = xDocProps->getPropertySetInfo(); + + const OUString aGrabBagPropName = "InteropGrabBag"; + if (xPropsInfo.is() && xPropsInfo->hasPropertyByName(aGrabBagPropName)) + { + // get existing grab bag + comphelper::SequenceAsHashMap aGrabBag(xDocProps->getPropertyValue(aGrabBagPropName)); + + uno::Sequence<beans::PropertyValue> aTheme(1); + comphelper::SequenceAsHashMap aThemesHashMap; + + // create current theme + uno::Sequence<beans::PropertyValue> aCurrentTheme(PredefinedClrSchemeId::Count); + + ClrScheme rClrScheme = pThemePtr->getClrScheme(); + for (int nId = PredefinedClrSchemeId::dk2; nId != PredefinedClrSchemeId::Count; nId++) + { + sal_uInt32 nToken = PredefinedClrTokens[static_cast<PredefinedClrSchemeId>(nId)]; + const OUString& sName = PredefinedClrNames[static_cast<PredefinedClrSchemeId>(nId)]; + sal_Int32 nColor = 0; + + rClrScheme.getColor(nToken, nColor); + const uno::Any& rColor = uno::makeAny(nColor); + + aCurrentTheme[nId].Name = sName; + aCurrentTheme[nId].Value = rColor; + } + + // add new theme to the sequence + aTheme[0].Name = sTheme; + const uno::Any& rCurrentTheme = makeAny(aCurrentTheme); + aTheme[0].Value = rCurrentTheme; + + aThemesHashMap << aTheme; + + // put the new items + aGrabBag.update(aThemesHashMap); + + // put it back to the document + xDocProps->setPropertyValue(aGrabBagPropName, uno::Any(aGrabBag.getAsConstPropertyValueList())); + } + } + } + catch (const uno::Exception&) + { + SAL_WARN("oox", "oox::ppt::PresentationFragmentHandler::saveThemeToGrabBag, Failed to save grab bag"); + } +} + void PresentationFragmentHandler::importSlide(sal_uInt32 nSlide, bool bFirstPage, bool bImportNotesPage) { PowerPointImport& rFilter = dynamic_cast< PowerPointImport& >( getFilter() ); @@ -232,6 +307,7 @@ void PresentationFragmentHandler::importSlide(sal_uInt32 nSlide, bool bFirstPage UNO_QUERY_THROW)); rThemes[ aThemeFragmentPath ] = pThemePtr; pThemePtr->setFragment(xDoc); + saveThemeToGrabBag(pThemePtr, aThemeFragmentPath); } else { |