sd/qa/unit/export-tests-ooxml2.cxx | 7 ++ sd/source/filter/eppt/epptooxml.hxx | 13 ++++- sd/source/filter/eppt/pptx-epptooxml.cxx | 75 ++++++++++++++++++++++++++++--- 3 files changed, 88 insertions(+), 7 deletions(-)
New commits: commit 7fdbc18afc6f1d34907b872d405b10b602ebdf16 Author: Miklos Vajna <vmik...@collabora.com> AuthorDate: Wed Dec 1 11:48:17 2021 +0100 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Mon Jun 27 08:58:52 2022 +0200 PPTX export: write the theme for the master pages from the doc model The instant benefit is that now the name of the theme and the color scheme are preserved, but this will also take changes done on the UI into account (which is not true for the grab-bag). (cherry picked from commit 5b253b2197e957fb5e42e3d0e233c10ac83afc10) Change-Id: I162eb7275d5a69d66db71fc5cd6e2e3ec94725bb Reviewed-on: https://gerrit.libreoffice.org/c/core/+/136373 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Reviewed-by: Miklos Vajna <vmik...@collabora.com> diff --git a/sd/qa/unit/export-tests-ooxml2.cxx b/sd/qa/unit/export-tests-ooxml2.cxx index 0b244bc76233..1e0bbf410b17 100644 --- a/sd/qa/unit/export-tests-ooxml2.cxx +++ b/sd/qa/unit/export-tests-ooxml2.cxx @@ -1608,6 +1608,13 @@ void SdOOXMLExportTest2::testAccentColor() assertXPath(pXmlDocTheme1, "/a:theme/a:themeElements/a:clrScheme/a:accent6/a:srgbClr", "val", "70ad47"); xmlDocUniquePtr pXmlDocTheme2 = parseExport(tempFile, "ppt/theme/theme2.xml"); assertXPath(pXmlDocTheme2, "/a:theme/a:themeElements/a:clrScheme/a:accent6/a:srgbClr", "val", "deb340"); + + // Without the accompanying fix in place, this test would have failed with: + // - Expected: Motyw pakietu Office + // - Actual : Office Theme + // i.e. the theme and color scheme name was lost on export. + assertXPath(pXmlDocTheme1, "/a:theme", "name", "Motyw pakietu Office"); + assertXPath(pXmlDocTheme1, "/a:theme/a:themeElements/a:clrScheme", "name", "Pakiet Office"); } void SdOOXMLExportTest2::testThemeColors() diff --git a/sd/source/filter/eppt/epptooxml.hxx b/sd/source/filter/eppt/epptooxml.hxx index 0c7e098f5771..5ee3248ec81e 100644 --- a/sd/source/filter/eppt/epptooxml.hxx +++ b/sd/source/filter/eppt/epptooxml.hxx @@ -26,6 +26,11 @@ using ::sax_fastparser::FSHelperPtr; +namespace svx +{ +class Theme; +} + namespace oox::core { struct LayoutInfo @@ -85,9 +90,15 @@ private: virtual void ImplWriteNotes( sal_uInt32 nPageNum ) override; virtual void ImplWriteSlideMaster( sal_uInt32 nPageNum, css::uno::Reference< css::beans::XPropertySet > const & aXBackgroundPropSet ) override; void ImplWritePPTXLayout( sal_Int32 nOffset, sal_uInt32 nMasterNum ); + + /// Export the color set part of a theme. + static bool WriteColorSets(const FSHelperPtr& pFS, svx::Theme* pTheme); + + /// Same as WriteColorSets(), but works from a grab-bag. bool WriteColorSchemes(const FSHelperPtr& pFS, const OUString& rThemePath); + static void WriteDefaultColorSchemes(const FSHelperPtr& pFS); - void WriteTheme( sal_Int32 nThemeNum ); + void WriteTheme( sal_Int32 nThemeNum, svx::Theme* pTheme ); virtual bool ImplCreateDocument() override; virtual bool ImplCreateMainNotes() override; diff --git a/sd/source/filter/eppt/pptx-epptooxml.cxx b/sd/source/filter/eppt/pptx-epptooxml.cxx index 0bc49e4a63ac..f6e78d357ead 100644 --- a/sd/source/filter/eppt/pptx-epptooxml.cxx +++ b/sd/source/filter/eppt/pptx-epptooxml.cxx @@ -1490,8 +1490,15 @@ void PowerPointExport::ImplWriteSlideMaster(sal_uInt32 nPageNum, Reference< XPro OUString::number(nPageNum + 1) + ".xml", "application/vnd.openxmlformats-officedocument.presentationml.slideMaster+xml"); + SdrPage* pMasterPage = SdPage::getImplementation(mXDrawPage); + svx::Theme* pTheme = nullptr; + if (pMasterPage) + { + pTheme = pMasterPage->getSdrPageProperties().GetTheme(); + } + // write theme per master - WriteTheme(nPageNum); + WriteTheme(nPageNum, pTheme); // add implicit relation to the presentation theme addRelation(pFS->getOutputStream(), @@ -2138,6 +2145,48 @@ void PowerPointExport::WriteDefaultColorSchemes(const FSHelperPtr& pFS) } } +bool PowerPointExport::WriteColorSets(const FSHelperPtr& pFS, svx::Theme* pTheme) +{ + static std::map<PredefinedClrSchemeId, sal_Int32> aPredefinedClrTokens = + { + // dk1 and lt1 is intentionally missing. + { 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 } + }; + + if (!pTheme) + { + return false; + } + + svx::ColorSet* pColorSet = pTheme->GetColorSet(); + if (!pColorSet) + { + return false; + } + + for (int nId = PredefinedClrSchemeId::dk2; nId < PredefinedClrSchemeId::Count; nId++) + { + // dk1 and lt1 are not written here. + int nIndex = nId + 2; + + sal_Int32 nToken = aPredefinedClrTokens[static_cast<PredefinedClrSchemeId>(nId)]; + pFS->startElementNS(XML_a, nToken); + pFS->singleElementNS(XML_a, XML_srgbClr, XML_val, I32SHEX(static_cast<sal_Int32>(pColorSet->getColor(nIndex)))); + pFS->endElementNS(XML_a, nToken); + } + + return true; +} + bool PowerPointExport::WriteColorSchemes(const FSHelperPtr& pFS, const OUString& rThemePath) { try @@ -2195,23 +2244,37 @@ bool PowerPointExport::WriteColorSchemes(const FSHelperPtr& pFS, const OUString& return false; } -void PowerPointExport::WriteTheme(sal_Int32 nThemeNum) +void PowerPointExport::WriteTheme(sal_Int32 nThemeNum, svx::Theme* pTheme) { OUString sThemePath = "ppt/theme/theme" + OUString::number(nThemeNum + 1) + ".xml"; FSHelperPtr pFS = openFragmentStreamWithSerializer(sThemePath, "application/vnd.openxmlformats-officedocument.theme+xml"); + OUString aThemeName("Office Theme"); + if (pTheme) + { + aThemeName = pTheme->GetName(); + } pFS->startElementNS(XML_a, XML_theme, FSNS(XML_xmlns, XML_a), this->getNamespaceURL(OOX_NS(dml)), - XML_name, "Office Theme"); + XML_name, aThemeName); pFS->startElementNS(XML_a, XML_themeElements); - pFS->startElementNS(XML_a, XML_clrScheme, XML_name, "Office"); + OUString aColorSchemeName("Office"); + if (pTheme) + { + svx::ColorSet* pColorSet = pTheme->GetColorSet(); + if (pColorSet) + { + aColorSchemeName = pColorSet->getName(); + } + } + pFS->startElementNS(XML_a, XML_clrScheme, XML_name, aColorSchemeName); pFS->write(SYS_COLOR_SCHEMES); - if (!WriteColorSchemes(pFS, sThemePath)) + if (!WriteColorSets(pFS, pTheme) && !WriteColorSchemes(pFS, sThemePath)) { // if style is not defined, try to use first one if (!WriteColorSchemes(pFS, "ppt/theme/theme1.xml")) @@ -2268,7 +2331,7 @@ void PowerPointExport::WriteNotesMaster() openFragmentStreamWithSerializer("ppt/notesMasters/notesMaster1.xml", "application/vnd.openxmlformats-officedocument.presentationml.notesMaster+xml"); // write theme per master - WriteTheme(mnMasterPages); + WriteTheme(mnMasterPages, nullptr); // add implicit relation to the presentation theme addRelation(pFS->getOutputStream(),