include/xmloff/xmlexp.hxx | 4 ++ sw/source/filter/xml/xmlexp.hxx | 3 - sw/source/filter/xml/xmlfmte.cxx | 61 ++++++----------------------------- xmloff/source/core/xmlexp.cxx | 48 +++++++++++++++++++++++++++ xmloff/source/draw/sdxmlexp.cxx | 44 +------------------------ xmloff/source/draw/sdxmlexp_impl.hxx | 2 - 6 files changed, 68 insertions(+), 94 deletions(-)
New commits: commit 0d99720641f733372516fa579094dca13601efdd Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> AuthorDate: Thu Aug 31 13:47:27 2023 +0200 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Mon Sep 4 09:12:54 2023 +0200 move theme element export to xmloff to remove code duplication Both Impress/Draw and Writer export the model::Theme in a similar way, but the code is duplicated. Remove duplication and move the code to a common place (on the SwXMLExport class) so it can be reused at both places. Change-Id: Id93acfafb0dd4ab0168b3228079f6ce6f64e6b55 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/156362 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <qui...@gmail.com> (cherry picked from commit b53a03d1d55de7fd04efc47c4a57baa11d72dd85) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/156455 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Reviewed-by: Miklos Vajna <vmik...@collabora.com> diff --git a/include/xmloff/xmlexp.hxx b/include/xmloff/xmlexp.hxx index 37a9096a0b32..2fb4bb6c3062 100644 --- a/include/xmloff/xmlexp.hxx +++ b/include/xmloff/xmlexp.hxx @@ -88,6 +88,8 @@ namespace com::sun::star { } namespace comphelper { class UnoInterfaceToUniqueIdentifierMapper; } +namespace model { class Theme; } + enum class SvXMLExportFlags { NONE = 0, META = 0x0001, @@ -262,6 +264,8 @@ protected: void SetDocHandler( const css::uno::Reference< css::xml::sax::XDocumentHandler > &rHandler ); + void ExportThemeElement(std::shared_ptr<model::Theme> const& pTheme); + bool mbAutoStylesCollected; public: diff --git a/sw/source/filter/xml/xmlexp.hxx b/sw/source/filter/xml/xmlexp.hxx index 3ba34a5cced4..b87051d0c8a5 100644 --- a/sw/source/filter/xml/xmlexp.hxx +++ b/sw/source/filter/xml/xmlexp.hxx @@ -90,8 +90,7 @@ class SwXMLExport : public SvXMLExport SwXMLTableInfo_Impl& rTableInfo, sal_uInt32 nHeaderRows = 0 ); - void ExportThemeElement(const css::uno::Reference<css::drawing::XDrawPage>& xDrawPage); - + void exportTheme(); virtual void ExportMeta_() override; virtual void ExportFontDecls_() override; diff --git a/sw/source/filter/xml/xmlfmte.cxx b/sw/source/filter/xml/xmlfmte.cxx index 6da12046665b..74782536b1dd 100644 --- a/sw/source/filter/xml/xmlfmte.cxx +++ b/sw/source/filter/xml/xmlfmte.cxx @@ -41,9 +41,7 @@ #include <SwStyleNameMapper.hxx> #include <osl/diagnose.h> #include <comphelper/sequenceashashmap.hxx> -#include <sax/tools/converter.hxx> -#include <o3tl/enumrange.hxx> #include <svx/unoapi.hxx> #include <svx/svdpage.hxx> #include <svx/svdmodel.hxx> @@ -184,22 +182,21 @@ void SwXMLExport::ExportStyles_( bool bUsed ) GetPageExport()->exportDefaultStyle(); // Theme - uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(GetModel(), UNO_QUERY); - if (xDrawPageSupplier.is()) - { - uno::Reference<drawing::XDrawPage> xPage = xDrawPageSupplier->getDrawPage(); - if (xPage.is()) - ExportThemeElement(xPage); - } + exportTheme(); } -void SwXMLExport::ExportThemeElement(const uno::Reference<drawing::XDrawPage>& xDrawPage) +void SwXMLExport::exportTheme() { if ((getSaneDefaultVersion() & SvtSaveOptions::ODFSVER_EXTENDED) == 0) - { - // Do not export in standard ODF 1.3 or older. return; - } + + uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(GetModel(), UNO_QUERY); + if (!xDrawPageSupplier.is()) + return; + + uno::Reference<drawing::XDrawPage> xDrawPage = xDrawPageSupplier->getDrawPage(); + if (!xDrawPage.is()) + return; SdrPage* pPage = GetSdrPageFromXDrawPage(xDrawPage); SAL_WARN_IF(!pPage, "oox", "Can't get SdrPage from XDrawPage"); @@ -211,43 +208,7 @@ void SwXMLExport::ExportThemeElement(const uno::Reference<drawing::XDrawPage>& x if (!pTheme) return; - if (!pTheme->GetName().isEmpty()) - AddAttribute(XML_NAMESPACE_LO_EXT, XML_NAME, pTheme->GetName()); - SvXMLElementExport aTheme(*this, XML_NAMESPACE_LO_EXT, XML_THEME, true, true); - - auto pColorSet = pTheme->getColorSet(); - if (!pColorSet->getName().isEmpty()) - AddAttribute(XML_NAMESPACE_LO_EXT, XML_NAME, pColorSet->getName()); - SvXMLElementExport aColorTable(*this, XML_NAMESPACE_LO_EXT, XML_THEME_COLORS, true, true); - - static const XMLTokenEnum aColorTokens[] = - { - XML_DARK1, // Text 1 - XML_LIGHT1, // Background 1 - XML_DARK2, // Text 2 - XML_LIGHT2, // Background 2 - XML_ACCENT1, - XML_ACCENT2, - XML_ACCENT3, - XML_ACCENT4, - XML_ACCENT5, - XML_ACCENT6, - XML_HYPERLINK, // Hyperlink - XML_FOLLOWED_HYPERLINK, // Followed hyperlink - }; - - for (auto eThemeColorType : o3tl::enumrange<model::ThemeColorType>()) - { - if (eThemeColorType == model::ThemeColorType::Unknown) - continue; - - auto nColor = size_t(eThemeColorType); - AddAttribute(XML_NAMESPACE_LO_EXT, XML_NAME, GetXMLToken(aColorTokens[nColor])); - OUStringBuffer sValue; - sax::Converter::convertColor(sValue, pColorSet->getColor(eThemeColorType)); - AddAttribute(XML_NAMESPACE_LO_EXT, XML_COLOR, sValue.makeStringAndClear()); - SvXMLElementExport aColor(*this, XML_NAMESPACE_LO_EXT, XML_COLOR, true, true); - } + ExportThemeElement(pTheme); } void SwXMLExport::collectAutoStyles() diff --git a/xmloff/source/core/xmlexp.cxx b/xmloff/source/core/xmlexp.cxx index 552b6edf8073..5a3bb5cf7285 100644 --- a/xmloff/source/core/xmlexp.cxx +++ b/xmloff/source/core/xmlexp.cxx @@ -88,6 +88,9 @@ #include <comphelper/extract.hxx> #include <comphelper/SetFlagContextHelper.hxx> #include <PropertySetMerger.hxx> +#include <docmodel/theme/Theme.hxx> +#include <o3tl/enumrange.hxx> +#include <sax/tools/converter.hxx> #include <unotools/docinfohelper.hxx> #include <com/sun/star/document/XDocumentProperties.hpp> @@ -1071,6 +1074,7 @@ void SvXMLExport::ImplExportSettings() void SvXMLExport::ImplExportStyles() { + printf ("SvXMLExport::ImplExportStyles\n"); CheckAttrList(); { @@ -1667,6 +1671,50 @@ void SvXMLExport::ExportStyles_( bool ) } } +void SvXMLExport::ExportThemeElement(std::shared_ptr<model::Theme> const& pTheme) +{ + if (!pTheme) + return; + + if (!pTheme->GetName().isEmpty()) + AddAttribute(XML_NAMESPACE_LO_EXT, XML_NAME, pTheme->GetName()); + SvXMLElementExport aTheme(*this, XML_NAMESPACE_LO_EXT, XML_THEME, true, true); + + auto pColorSet = pTheme->getColorSet(); + if (!pColorSet->getName().isEmpty()) + AddAttribute(XML_NAMESPACE_LO_EXT, XML_NAME, pColorSet->getName()); + SvXMLElementExport aColorTable(*this, XML_NAMESPACE_LO_EXT, XML_THEME_COLORS, true, true); + + static const XMLTokenEnum aColorTokens[] = + { + XML_DARK1, // Text 1 + XML_LIGHT1, // Background 1 + XML_DARK2, // Text 2 + XML_LIGHT2, // Background 2 + XML_ACCENT1, + XML_ACCENT2, + XML_ACCENT3, + XML_ACCENT4, + XML_ACCENT5, + XML_ACCENT6, + XML_HYPERLINK, // Hyperlink + XML_FOLLOWED_HYPERLINK, // Followed hyperlink + }; + + for (auto eThemeColorType : o3tl::enumrange<model::ThemeColorType>()) + { + if (eThemeColorType == model::ThemeColorType::Unknown) + continue; + + auto nColor = size_t(eThemeColorType); + AddAttribute(XML_NAMESPACE_LO_EXT, XML_NAME, GetXMLToken(aColorTokens[nColor])); + OUStringBuffer sValue; + sax::Converter::convertColor(sValue, pColorSet->getColor(eThemeColorType)); + AddAttribute(XML_NAMESPACE_LO_EXT, XML_COLOR, sValue.makeStringAndClear()); + SvXMLElementExport aColor(*this, XML_NAMESPACE_LO_EXT, XML_COLOR, true, true); + } +} + XMLTextParagraphExport* SvXMLExport::CreateTextParagraphExport() { return new XMLTextParagraphExport( *this, *GetAutoStylePool() ); diff --git a/xmloff/source/draw/sdxmlexp.cxx b/xmloff/source/draw/sdxmlexp.cxx index 4dfd2195bc49..df8d5c4f086f 100644 --- a/xmloff/source/draw/sdxmlexp.cxx +++ b/xmloff/source/draw/sdxmlexp.cxx @@ -2306,7 +2306,7 @@ void SdXMLExport::ExportMasterStyles_() exportFormsElement( xMasterPage ); // write optional loext:theme - ExportThemeElement(xMasterPage); + exportTheme(xMasterPage); // write graphic objects on this master page (if any) if(xMasterPage.is() && xMasterPage->getCount()) @@ -2363,7 +2363,7 @@ void SdXMLExport::exportFormsElement( const Reference< XDrawPage >& xDrawPage ) } } -void SdXMLExport::ExportThemeElement(const uno::Reference<drawing::XDrawPage>& xDrawPage) +void SdXMLExport::exportTheme(const uno::Reference<drawing::XDrawPage>& xDrawPage) { if ((getSaneDefaultVersion() & SvtSaveOptions::ODFSVER_EXTENDED) == 0) { @@ -2387,46 +2387,8 @@ void SdXMLExport::ExportThemeElement(const uno::Reference<drawing::XDrawPage>& x auto pTheme = pUnoTheme->getTheme(); if (!pTheme) return; - auto pColorSet = pTheme->getColorSet(); - if (!pColorSet) - return; - if (!pTheme->GetName().isEmpty()) - AddAttribute(XML_NAMESPACE_LO_EXT, XML_NAME, pTheme->GetName()); - SvXMLElementExport aTheme(*this, XML_NAMESPACE_LO_EXT, XML_THEME, true, true); - - if (!pColorSet->getName().isEmpty()) - AddAttribute(XML_NAMESPACE_LO_EXT, XML_NAME, pColorSet->getName()); - SvXMLElementExport aColorTable(*this, XML_NAMESPACE_LO_EXT, XML_THEME_COLORS, true, true); - - static const XMLTokenEnum aColorTokens[] = - { - XML_DARK1, // Text 1 - XML_LIGHT1, // Background 1 - XML_DARK2, // Text 2 - XML_LIGHT2, // Background 2 - XML_ACCENT1, - XML_ACCENT2, - XML_ACCENT3, - XML_ACCENT4, - XML_ACCENT5, - XML_ACCENT6, - XML_HYPERLINK, // Hyperlink - XML_FOLLOWED_HYPERLINK, // Followed hyperlink - }; - - for (auto eThemeColorType : o3tl::enumrange<model::ThemeColorType>()) - { - if (eThemeColorType == model::ThemeColorType::Unknown) - continue; - - auto nColor = size_t(eThemeColorType); - AddAttribute(XML_NAMESPACE_LO_EXT, XML_NAME, GetXMLToken(aColorTokens[nColor])); - OUStringBuffer sValue; - sax::Converter::convertColor(sValue, pColorSet->getColor(eThemeColorType)); - AddAttribute(XML_NAMESPACE_LO_EXT, XML_COLOR, sValue.makeStringAndClear()); - SvXMLElementExport aColor(*this, XML_NAMESPACE_LO_EXT, XML_COLOR, true, true); - } + ExportThemeElement(pTheme); } void SdXMLExport::GetViewSettings(uno::Sequence<beans::PropertyValue>& rProps) diff --git a/xmloff/source/draw/sdxmlexp_impl.hxx b/xmloff/source/draw/sdxmlexp_impl.hxx index 9808c738120e..8207d64e3b9e 100644 --- a/xmloff/source/draw/sdxmlexp_impl.hxx +++ b/xmloff/source/draw/sdxmlexp_impl.hxx @@ -135,7 +135,7 @@ class SdXMLExport : public SvXMLExport void ImplExportHeaderFooterDeclAttributes( const HeaderFooterPageSettingsImpl& aSettings ); void exportFormsElement( const css::uno::Reference< css::drawing::XDrawPage >& xDrawPage ); - void ExportThemeElement(const css::uno::Reference<css::drawing::XDrawPage>& xDrawPage); + void exportTheme(const css::uno::Reference<css::drawing::XDrawPage>& xDrawPage); void exportPresentationSettings(); // #82003# helper function for recursive object count