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:
committed by
Tomaž Vajngerl
parent
6d8c6e8d60
commit
b53a03d1d5
@@ -87,6 +87,8 @@ namespace com::sun::star {
|
||||
}
|
||||
namespace comphelper { class UnoInterfaceToUniqueIdentifierMapper; }
|
||||
|
||||
namespace model { class Theme; }
|
||||
|
||||
enum class SvXMLExportFlags {
|
||||
NONE = 0,
|
||||
META = 0x0001,
|
||||
@@ -260,6 +262,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:
|
||||
|
||||
|
@@ -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;
|
||||
|
@@ -40,9 +40,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>
|
||||
@@ -183,22 +181,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");
|
||||
@@ -210,43 +207,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()
|
||||
|
@@ -87,6 +87,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>
|
||||
@@ -1067,6 +1070,7 @@ void SvXMLExport::ImplExportSettings()
|
||||
|
||||
void SvXMLExport::ImplExportStyles()
|
||||
{
|
||||
printf ("SvXMLExport::ImplExportStyles\n");
|
||||
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()
|
||||
{
|
||||
return new XMLTextParagraphExport( *this, *GetAutoStylePool() );
|
||||
|
@@ -2301,7 +2301,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())
|
||||
@@ -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)
|
||||
{
|
||||
@@ -2382,46 +2382,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)
|
||||
|
@@ -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
|
||||
|
Reference in New Issue
Block a user