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 <quikee@gmail.com>
This commit is contained in:
Tomaž Vajngerl
2023-08-31 13:47:27 +02:00
committed by Tomaž Vajngerl
parent 6d8c6e8d60
commit b53a03d1d5
6 changed files with 68 additions and 94 deletions

View File

@@ -87,6 +87,8 @@ namespace com::sun::star {
} }
namespace comphelper { class UnoInterfaceToUniqueIdentifierMapper; } namespace comphelper { class UnoInterfaceToUniqueIdentifierMapper; }
namespace model { class Theme; }
enum class SvXMLExportFlags { enum class SvXMLExportFlags {
NONE = 0, NONE = 0,
META = 0x0001, META = 0x0001,
@@ -260,6 +262,8 @@ protected:
void SetDocHandler( const css::uno::Reference< css::xml::sax::XDocumentHandler > &rHandler ); void SetDocHandler( const css::uno::Reference< css::xml::sax::XDocumentHandler > &rHandler );
void ExportThemeElement(std::shared_ptr<model::Theme> const& pTheme);
bool mbAutoStylesCollected; bool mbAutoStylesCollected;
public: public:

View File

@@ -90,8 +90,7 @@ class SwXMLExport : public SvXMLExport
SwXMLTableInfo_Impl& rTableInfo, SwXMLTableInfo_Impl& rTableInfo,
sal_uInt32 nHeaderRows = 0 ); sal_uInt32 nHeaderRows = 0 );
void ExportThemeElement(const css::uno::Reference<css::drawing::XDrawPage>& xDrawPage); void exportTheme();
virtual void ExportMeta_() override; virtual void ExportMeta_() override;
virtual void ExportFontDecls_() override; virtual void ExportFontDecls_() override;

View File

@@ -40,9 +40,7 @@
#include <SwStyleNameMapper.hxx> #include <SwStyleNameMapper.hxx>
#include <osl/diagnose.h> #include <osl/diagnose.h>
#include <comphelper/sequenceashashmap.hxx> #include <comphelper/sequenceashashmap.hxx>
#include <sax/tools/converter.hxx>
#include <o3tl/enumrange.hxx>
#include <svx/unoapi.hxx> #include <svx/unoapi.hxx>
#include <svx/svdpage.hxx> #include <svx/svdpage.hxx>
#include <svx/svdmodel.hxx> #include <svx/svdmodel.hxx>
@@ -183,22 +181,21 @@ void SwXMLExport::ExportStyles_( bool bUsed )
GetPageExport()->exportDefaultStyle(); GetPageExport()->exportDefaultStyle();
// Theme // Theme
uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(GetModel(), UNO_QUERY); exportTheme();
if (xDrawPageSupplier.is())
{
uno::Reference<drawing::XDrawPage> xPage = xDrawPageSupplier->getDrawPage();
if (xPage.is())
ExportThemeElement(xPage);
}
} }
void SwXMLExport::ExportThemeElement(const uno::Reference<drawing::XDrawPage>& xDrawPage) void SwXMLExport::exportTheme()
{ {
if ((getSaneDefaultVersion() & SvtSaveOptions::ODFSVER_EXTENDED) == 0) if ((getSaneDefaultVersion() & SvtSaveOptions::ODFSVER_EXTENDED) == 0)
{
// Do not export in standard ODF 1.3 or older.
return; 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); SdrPage* pPage = GetSdrPageFromXDrawPage(xDrawPage);
SAL_WARN_IF(!pPage, "oox", "Can't get SdrPage from XDrawPage"); SAL_WARN_IF(!pPage, "oox", "Can't get SdrPage from XDrawPage");
@@ -210,43 +207,7 @@ void SwXMLExport::ExportThemeElement(const uno::Reference<drawing::XDrawPage>& x
if (!pTheme) if (!pTheme)
return; return;
if (!pTheme->GetName().isEmpty()) ExportThemeElement(pTheme);
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);
}
} }
void SwXMLExport::collectAutoStyles() void SwXMLExport::collectAutoStyles()

View File

@@ -87,6 +87,9 @@
#include <comphelper/extract.hxx> #include <comphelper/extract.hxx>
#include <comphelper/SetFlagContextHelper.hxx> #include <comphelper/SetFlagContextHelper.hxx>
#include <PropertySetMerger.hxx> #include <PropertySetMerger.hxx>
#include <docmodel/theme/Theme.hxx>
#include <o3tl/enumrange.hxx>
#include <sax/tools/converter.hxx>
#include <unotools/docinfohelper.hxx> #include <unotools/docinfohelper.hxx>
#include <com/sun/star/document/XDocumentProperties.hpp> #include <com/sun/star/document/XDocumentProperties.hpp>
@@ -1067,6 +1070,7 @@ void SvXMLExport::ImplExportSettings()
void SvXMLExport::ImplExportStyles() void SvXMLExport::ImplExportStyles()
{ {
printf ("SvXMLExport::ImplExportStyles\n");
CheckAttrList(); CheckAttrList();
{ {
@@ -1663,6 +1667,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() XMLTextParagraphExport* SvXMLExport::CreateTextParagraphExport()
{ {
return new XMLTextParagraphExport( *this, *GetAutoStylePool() ); return new XMLTextParagraphExport( *this, *GetAutoStylePool() );

View File

@@ -2301,7 +2301,7 @@ void SdXMLExport::ExportMasterStyles_()
exportFormsElement( xMasterPage ); exportFormsElement( xMasterPage );
// write optional loext:theme // write optional loext:theme
ExportThemeElement(xMasterPage); exportTheme(xMasterPage);
// write graphic objects on this master page (if any) // write graphic objects on this master page (if any)
if(xMasterPage.is() && xMasterPage->getCount()) if(xMasterPage.is() && xMasterPage->getCount())
@@ -2358,7 +2358,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) if ((getSaneDefaultVersion() & SvtSaveOptions::ODFSVER_EXTENDED) == 0)
{ {
@@ -2382,46 +2382,8 @@ void SdXMLExport::ExportThemeElement(const uno::Reference<drawing::XDrawPage>& x
auto pTheme = pUnoTheme->getTheme(); auto pTheme = pUnoTheme->getTheme();
if (!pTheme) if (!pTheme)
return; return;
auto pColorSet = pTheme->getColorSet();
if (!pColorSet)
return;
if (!pTheme->GetName().isEmpty()) ExportThemeElement(pTheme);
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);
}
} }
void SdXMLExport::GetViewSettings(uno::Sequence<beans::PropertyValue>& rProps) void SdXMLExport::GetViewSettings(uno::Sequence<beans::PropertyValue>& rProps)

View File

@@ -135,7 +135,7 @@ class SdXMLExport : public SvXMLExport
void ImplExportHeaderFooterDeclAttributes( const HeaderFooterPageSettingsImpl& aSettings ); void ImplExportHeaderFooterDeclAttributes( const HeaderFooterPageSettingsImpl& aSettings );
void exportFormsElement( const css::uno::Reference< css::drawing::XDrawPage >& xDrawPage ); 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(); void exportPresentationSettings();
// #82003# helper function for recursive object count // #82003# helper function for recursive object count