summaryrefslogtreecommitdiff
path: root/xmloff
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2023-01-27 15:03:09 +0900
committerTomaž Vajngerl <quikee@gmail.com>2023-02-17 05:23:43 +0000
commit126d0db2c2315565d45e3b0408576d40ab97a443 (patch)
treed4a541c53ad3b9675dc51712f53978f0625bb8d3 /xmloff
parent7ba71ec27f9eca53cf0645d2b6bbfb37155efac4 (diff)
sd: use XTheme to transport the theme to xmloff import/export
Refactor the existing places and tests in Impress code (sd) to use it instead. Also keep the old property of construction and view of the theme with a sequence of property values, but under the new property named "ThemeUnoRepresentation". This is needed by the UI tests currently. Change-Id: I484567f4a603f1a5e2e03955fdd2b63132dcc66e Reviewed-on: https://gerrit.libreoffice.org/c/core/+/146225 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <quikee@gmail.com> (cherry picked from commit 75c0d7827625c683d52a9e2f3a7c514df890107b) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/146450 Tested-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'xmloff')
-rw-r--r--xmloff/inc/XMLThemeContext.hxx13
-rw-r--r--xmloff/qa/unit/draw.cxx52
-rw-r--r--xmloff/source/draw/sdxmlexp.cxx78
-rw-r--r--xmloff/source/style/XMLThemeContext.cxx72
4 files changed, 133 insertions, 82 deletions
diff --git a/xmloff/inc/XMLThemeContext.hxx b/xmloff/inc/XMLThemeContext.hxx
index 706c1251a534..50889a0ddf98 100644
--- a/xmloff/inc/XMLThemeContext.hxx
+++ b/xmloff/inc/XMLThemeContext.hxx
@@ -14,14 +14,14 @@
#include <com/sun/star/util/Color.hpp>
#include <com/sun/star/container/XNameContainer.hpp>
-#include <comphelper/sequenceashashmap.hxx>
-#include <comphelper/namecontainer.hxx>
+#include <docmodel/theme/Theme.hxx>
+#include <docmodel/theme/ColorSet.hxx>
/// Imports the theme
class XMLThemeContext : public SvXMLImportContext
{
css::uno::Reference<css::drawing::XDrawPage> m_xPage;
- comphelper::SequenceAsHashMap m_aTheme;
+ model::Theme maTheme;
public:
XMLThemeContext(SvXMLImport& rImport,
@@ -37,13 +37,14 @@ public:
/// Imports the color table of a theme
class XMLColorTableContext : public SvXMLImportContext
{
- comphelper::SequenceAsHashMap& m_rTheme;
+ model::Theme& mrTheme;
+ std::unique_ptr<model::ColorSet> mpColorSet;
std::vector<css::util::Color> m_aColorScheme;
public:
XMLColorTableContext(SvXMLImport& rImport,
css::uno::Reference<css::xml::sax::XFastAttributeList> const& xAttrList,
- comphelper::SequenceAsHashMap& rTheme);
+ model::Theme& mrTheme);
~XMLColorTableContext();
css::uno::Reference<css::xml::sax::XFastContextHandler> SAL_CALL createFastChildContext(
@@ -57,7 +58,7 @@ class XMLColorContext : public SvXMLImportContext
public:
XMLColorContext(SvXMLImport& rImport,
css::uno::Reference<css::xml::sax::XFastAttributeList> const& xAttrList,
- std::vector<css::util::Color>& rColorScheme);
+ std::unique_ptr<model::ColorSet>& rpColorSet);
};
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/xmloff/qa/unit/draw.cxx b/xmloff/qa/unit/draw.cxx
index d66a96e1350c..c4671d95859b 100644
--- a/xmloff/qa/unit/draw.cxx
+++ b/xmloff/qa/unit/draw.cxx
@@ -30,6 +30,7 @@
#include <svx/svdpage.hxx>
#include <svx/svdomedia.hxx>
#include <docmodel/uno/UnoThemeColor.hxx>
+#include <docmodel/uno/UnoTheme.hxx>
using namespace ::com::sun::star;
@@ -130,14 +131,25 @@ CPPUNIT_TEST_FIXTURE(XmloffDrawTest, testThemeExport)
uno::Reference<drawing::XMasterPageTarget> xDrawPage(
xDrawPagesSupplier->getDrawPages()->getByIndex(0), uno::UNO_QUERY);
uno::Reference<beans::XPropertySet> xMasterPage(xDrawPage->getMasterPage(), uno::UNO_QUERY);
- comphelper::SequenceAsHashMap aMap;
- aMap["Name"] <<= OUString("mytheme");
- aMap["ColorSchemeName"] <<= OUString("mycolorscheme");
- uno::Sequence<util::Color> aColorScheme
- = { 0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb };
- aMap["ColorScheme"] <<= aColorScheme;
- uno::Any aTheme(aMap.getAsConstPropertyValueList());
- xMasterPage->setPropertyValue("Theme", aTheme);
+
+ model::Theme aTheme("mytheme");
+ std::unique_ptr<model::ColorSet> pColorSet(new model::ColorSet("mycolorscheme"));
+ pColorSet->add(model::ThemeColorType::Dark1, 0x0);
+ pColorSet->add(model::ThemeColorType::Light1, 0x1);
+ pColorSet->add(model::ThemeColorType::Dark2, 0x2);
+ pColorSet->add(model::ThemeColorType::Light2, 0x3);
+ pColorSet->add(model::ThemeColorType::Accent1, 0x4);
+ pColorSet->add(model::ThemeColorType::Accent2, 0x5);
+ pColorSet->add(model::ThemeColorType::Accent3, 0x6);
+ pColorSet->add(model::ThemeColorType::Accent4, 0x7);
+ pColorSet->add(model::ThemeColorType::Accent5, 0x8);
+ pColorSet->add(model::ThemeColorType::Accent6, 0x9);
+ pColorSet->add(model::ThemeColorType::Hyperlink, 0xa);
+ pColorSet->add(model::ThemeColorType::FollowedHyperlink, 0xb);
+ aTheme.SetColorSet(std::move(pColorSet));
+
+ uno::Reference<util::XTheme> xTheme = model::theme::createXTheme(aTheme);
+ xMasterPage->setPropertyValue("Theme", uno::Any(xTheme));
// Export to ODP:
save("impress8");
@@ -205,15 +217,21 @@ CPPUNIT_TEST_FIXTURE(XmloffDrawTest, testThemeImport)
uno::Reference<drawing::XMasterPageTarget> xDrawPage(
xDrawPagesSupplier->getDrawPages()->getByIndex(0), uno::UNO_QUERY);
uno::Reference<beans::XPropertySet> xMasterpage(xDrawPage->getMasterPage(), uno::UNO_QUERY);
- comphelper::SequenceAsHashMap aMap(xMasterpage->getPropertyValue("Theme"));
- // Without the accompanying fix in place, this test would have failed with:
- // Cannot extract an Any(void) to string!
- // i.e. the master page had no theme.
- CPPUNIT_ASSERT_EQUAL(OUString("Office Theme"), aMap["Name"].get<OUString>());
- CPPUNIT_ASSERT_EQUAL(OUString("Office"), aMap["ColorSchemeName"].get<OUString>());
- auto aColorScheme = aMap["ColorScheme"].get<uno::Sequence<util::Color>>();
- CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(12), aColorScheme.getLength());
- CPPUNIT_ASSERT_EQUAL(static_cast<util::Color>(0x954F72), aColorScheme[11]);
+
+ uno::Reference<util::XTheme> xTheme;
+ xMasterpage->getPropertyValue("Theme") >>= xTheme;
+
+ // We expect the theme to be set on the master page
+ CPPUNIT_ASSERT(xTheme.is());
+ auto* pUnoTheme = dynamic_cast<UnoTheme*>(xTheme.get());
+ CPPUNIT_ASSERT(pUnoTheme);
+ auto const& rTheme = pUnoTheme->getTheme();
+
+ CPPUNIT_ASSERT_EQUAL(OUString("Office Theme"), rTheme.GetName());
+ CPPUNIT_ASSERT_EQUAL(OUString("Office"), rTheme.GetColorSet()->getName());
+
+ CPPUNIT_ASSERT_EQUAL(Color(0x954F72),
+ rTheme.GetColorSet()->getColor(model::ThemeColorType::FollowedHyperlink));
}
CPPUNIT_TEST_FIXTURE(XmloffDrawTest, testThemeColorExportImport)
diff --git a/xmloff/source/draw/sdxmlexp.cxx b/xmloff/source/draw/sdxmlexp.cxx
index df0c7e45aa27..0e7fc6160867 100644
--- a/xmloff/source/draw/sdxmlexp.cxx
+++ b/xmloff/source/draw/sdxmlexp.cxx
@@ -73,8 +73,8 @@
#include <com/sun/star/document/XDocumentProperties.hpp>
#include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
#include <com/sun/star/util/Color.hpp>
-
-#include <comphelper/sequenceashashmap.hxx>
+#include <docmodel/uno/UnoTheme.hxx>
+#include <o3tl/enumrange.hxx>
using namespace ::com::sun::star;
using namespace ::com::sun::star::uno;
@@ -2367,56 +2367,42 @@ void SdXMLExport::exportFormsElement( const Reference< XDrawPage >& xDrawPage )
void SdXMLExport::ExportThemeElement(const uno::Reference<drawing::XDrawPage>& xDrawPage)
{
+ if ((getSaneDefaultVersion() & SvtSaveOptions::ODFSVER_EXTENDED) == 0)
+ {
+ // Do not export in standard ODF 1.3 or older.
+ return;
+ }
+
uno::Reference<beans::XPropertySet> xPropertySet(xDrawPage, uno::UNO_QUERY);
if (!xPropertySet.is())
return;
- comphelper::SequenceAsHashMap aMap(xPropertySet->getPropertyValue("Theme"));
- if (aMap.empty())
- {
+ uno::Reference<util::XTheme> xTheme;
+ xPropertySet->getPropertyValue("Theme") >>= xTheme;
+ if (!xTheme.is())
return;
- }
- if ((getSaneDefaultVersion() & SvtSaveOptions::ODFSVER_EXTENDED) == 0)
- {
- // Do not export in standard ODF 1.3 or older.
+ auto* pUnoTheme = dynamic_cast<UnoTheme*>(xTheme.get());
+ if (!pUnoTheme)
return;
- }
- auto it = aMap.find("Name");
- if (it != aMap.end())
- {
- OUString aName;
- it->second >>= aName;
- AddAttribute(XML_NAMESPACE_LO_EXT, XML_NAME, aName);
- }
- SvXMLElementExport aTheme(*this, XML_NAMESPACE_LO_EXT, XML_THEME, true, true);
+ auto const& rTheme = pUnoTheme->getTheme();
- uno::Sequence<util::Color> aColors;
- it = aMap.find("ColorScheme");
- if (it != aMap.end())
- {
- it->second >>= aColors;
- }
- if (!aColors.hasElements())
- {
- return;
- }
+ if (!rTheme.GetName().isEmpty())
+ AddAttribute(XML_NAMESPACE_LO_EXT, XML_NAME, rTheme.GetName());
+ SvXMLElementExport aTheme(*this, XML_NAMESPACE_LO_EXT, XML_THEME, true, true);
- it = aMap.find("ColorSchemeName");
- if (it != aMap.end())
- {
- OUString aName;
- it->second >>= aName;
- AddAttribute(XML_NAMESPACE_LO_EXT, XML_NAME, aName);
- }
+ auto* pColorSet = rTheme.GetColorSet();
+ if (!pColorSet->getName().isEmpty())
+ AddAttribute(XML_NAMESPACE_LO_EXT, XML_NAME, pColorSet->getName());
SvXMLElementExport aColorTable(*this, XML_NAMESPACE_LO_EXT, XML_COLOR_TABLE, true, true);
- static const XMLTokenEnum aColorTokens[] = {
- XML_DK1, // Background 1
- XML_LT1, // Text 1
- XML_DK2, // Background 2
- XML_LT2, // Text 2
+ static const XMLTokenEnum aColorTokens[] =
+ {
+ XML_DK1, // Text 1
+ XML_LT1, // Background 1
+ XML_DK2, // Text 2
+ XML_LT2, // Background 2
XML_ACCENT1,
XML_ACCENT2,
XML_ACCENT3,
@@ -2426,17 +2412,17 @@ void SdXMLExport::ExportThemeElement(const uno::Reference<drawing::XDrawPage>& x
XML_HLINK, // Hyperlink
XML_FOLHLINK, // Followed hyperlink
};
- for (size_t nColor = 0; nColor < aColors.size(); ++nColor)
+
+ for (auto eThemeColorType : o3tl::enumrange<model::ThemeColorType>())
{
- // Import goes via model::Theme::FromAny(), which sanitizes user input.
- assert(nColor < SAL_N_ELEMENTS(aColorTokens));
+ 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, aColors[nColor]);
+ 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);
}
}
diff --git a/xmloff/source/style/XMLThemeContext.cxx b/xmloff/source/style/XMLThemeContext.cxx
index 41602665a06b..8a9a5cdbc558 100644
--- a/xmloff/source/style/XMLThemeContext.cxx
+++ b/xmloff/source/style/XMLThemeContext.cxx
@@ -25,6 +25,8 @@
#include <sax/tools/converter.hxx>
#include <comphelper/sequence.hxx>
+#include <docmodel/uno/UnoTheme.hxx>
+
using namespace css;
using namespace xmloff::token;
@@ -40,7 +42,8 @@ XMLThemeContext::XMLThemeContext(SvXMLImport& rImport,
{
case XML_ELEMENT(LO_EXT, XML_NAME):
{
- m_aTheme["Name"] <<= rAttribute.toString();
+ OUString aName = rAttribute.toString();
+ maTheme.SetName(aName);
break;
}
}
@@ -49,9 +52,9 @@ XMLThemeContext::XMLThemeContext(SvXMLImport& rImport,
XMLThemeContext::~XMLThemeContext()
{
- uno::Any aTheme(m_aTheme.getAsConstPropertyValueList());
uno::Reference<beans::XPropertySet> xPropertySet(m_xPage, uno::UNO_QUERY);
- xPropertySet->setPropertyValue("Theme", aTheme);
+ uno::Reference<util::XTheme> xTheme(new UnoTheme(maTheme));
+ xPropertySet->setPropertyValue("Theme", uno::Any(xTheme));
}
uno::Reference<xml::sax::XFastContextHandler> SAL_CALL XMLThemeContext::createFastChildContext(
@@ -59,7 +62,7 @@ uno::Reference<xml::sax::XFastContextHandler> SAL_CALL XMLThemeContext::createFa
{
if (nElement == XML_ELEMENT(LO_EXT, XML_COLOR_TABLE))
{
- return new XMLColorTableContext(GetImport(), xAttribs, m_aTheme);
+ return new XMLColorTableContext(GetImport(), xAttribs, maTheme);
}
return nullptr;
@@ -67,9 +70,9 @@ uno::Reference<xml::sax::XFastContextHandler> SAL_CALL XMLThemeContext::createFa
XMLColorTableContext::XMLColorTableContext(
SvXMLImport& rImport, const uno::Reference<xml::sax::XFastAttributeList>& xAttrList,
- comphelper::SequenceAsHashMap& rTheme)
+ model::Theme& rTheme)
: SvXMLImportContext(rImport)
- , m_rTheme(rTheme)
+ , mrTheme(rTheme)
{
for (const auto& rAttribute : sax_fastparser::castToFastAttributeList(xAttrList))
{
@@ -77,7 +80,8 @@ XMLColorTableContext::XMLColorTableContext(
{
case XML_ELEMENT(LO_EXT, XML_NAME):
{
- m_rTheme["ColorSchemeName"] <<= rAttribute.toString();
+ OUString aName = rAttribute.toString();
+ mpColorSet.reset(new model::ColorSet(aName));
break;
}
}
@@ -86,7 +90,8 @@ XMLColorTableContext::XMLColorTableContext(
XMLColorTableContext::~XMLColorTableContext()
{
- m_rTheme["ColorScheme"] <<= comphelper::containerToSequence(m_aColorScheme);
+ if (mpColorSet)
+ mrTheme.SetColorSet(std::move(mpColorSet));
}
uno::Reference<xml::sax::XFastContextHandler> SAL_CALL XMLColorTableContext::createFastChildContext(
@@ -94,7 +99,8 @@ uno::Reference<xml::sax::XFastContextHandler> SAL_CALL XMLColorTableContext::cre
{
if (nElement == XML_ELEMENT(LO_EXT, XML_COLOR))
{
- return new XMLColorContext(GetImport(), xAttribs, m_aColorScheme);
+ if (mpColorSet)
+ return new XMLColorContext(GetImport(), xAttribs, mpColorSet);
}
return nullptr;
@@ -102,22 +108,62 @@ uno::Reference<xml::sax::XFastContextHandler> SAL_CALL XMLColorTableContext::cre
XMLColorContext::XMLColorContext(SvXMLImport& rImport,
const uno::Reference<xml::sax::XFastAttributeList>& xAttrList,
- std::vector<util::Color>& rColorScheme)
+ std::unique_ptr<model::ColorSet>& rpColorSet)
: SvXMLImportContext(rImport)
{
+ OUString aName;
+ ::Color aColor;
+
for (const auto& rAttribute : sax_fastparser::castToFastAttributeList(xAttrList))
{
switch (rAttribute.getToken())
{
+ case XML_ELEMENT(LO_EXT, XML_NAME):
+ {
+ aName = rAttribute.toString();
+ break;
+ }
case XML_ELEMENT(LO_EXT, XML_COLOR):
{
- util::Color nColor;
- sax::Converter::convertColor(nColor, rAttribute.toView());
- rColorScheme.push_back(nColor);
+ sax::Converter::convertColor(aColor, rAttribute.toView());
break;
}
}
}
+
+ if (!aName.isEmpty())
+ {
+ auto eType = model::ThemeColorType::Unknown;
+ if (aName == u"dk1")
+ eType = model::ThemeColorType::Dark1;
+ else if (aName == u"lt1")
+ eType = model::ThemeColorType::Light1;
+ else if (aName == u"dk2")
+ eType = model::ThemeColorType::Dark2;
+ else if (aName == u"lt2")
+ eType = model::ThemeColorType::Light2;
+ else if (aName == u"accent1")
+ eType = model::ThemeColorType::Accent1;
+ else if (aName == u"accent2")
+ eType = model::ThemeColorType::Accent2;
+ else if (aName == u"accent3")
+ eType = model::ThemeColorType::Accent3;
+ else if (aName == u"accent4")
+ eType = model::ThemeColorType::Accent4;
+ else if (aName == u"accent5")
+ eType = model::ThemeColorType::Accent5;
+ else if (aName == u"accent6")
+ eType = model::ThemeColorType::Accent6;
+ else if (aName == u"hlink")
+ eType = model::ThemeColorType::Hyperlink;
+ else if (aName == u"folHlink")
+ eType = model::ThemeColorType::FollowedHyperlink;
+
+ if (eType != model::ThemeColorType::Unknown)
+ {
+ rpColorSet->add(eType, aColor);
+ }
+ }
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */