diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2021-12-01 11:48:17 +0100 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2021-12-01 13:14:27 +0100 |
commit | 5b253b2197e957fb5e42e3d0e233c10ac83afc10 (patch) | |
tree | ca5b12164c34c196bcc7efed62294331a49e40b7 | |
parent | e050b09c7ef193da9da4441d9984c793e35b5a8a (diff) |
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).
Change-Id: I162eb7275d5a69d66db71fc5cd6e2e3ec94725bb
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/126164
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Tested-by: Jenkins
-rw-r--r-- | sd/qa/unit/export-tests-ooxml2.cxx | 7 | ||||
-rw-r--r-- | sd/source/filter/eppt/epptooxml.hxx | 13 | ||||
-rw-r--r-- | sd/source/filter/eppt/pptx-epptooxml.cxx | 75 |
3 files changed, 88 insertions, 7 deletions
diff --git a/sd/qa/unit/export-tests-ooxml2.cxx b/sd/qa/unit/export-tests-ooxml2.cxx index 1951d2f9eae6..4b980cafdfa6 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 d5787d6f4cb7..ef36db9b4ac4 100644 --- a/sd/source/filter/eppt/pptx-epptooxml.cxx +++ b/sd/source/filter/eppt/pptx-epptooxml.cxx @@ -1482,8 +1482,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(), @@ -2130,6 +2137,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 @@ -2187,23 +2236,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")) @@ -2260,7 +2323,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(), |