diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2023-01-28 18:43:51 +0900 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2023-02-01 08:41:30 +0000 |
commit | d8de2dc3c55a9013a71167c8058a333e7221a6a0 (patch) | |
tree | 1419829f0f77b8ce692bb31823d148d4ffa75c85 /xmloff | |
parent | 7ab51def766ad6bfdcf5111e7b751bbc2bbf1d73 (diff) |
xmloff: import of theme structure + import/export/round-trip tests
Change-Id: I50e8c53c534895098613e81fd97b346fd3d7d05f
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/146287
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'xmloff')
-rw-r--r-- | xmloff/CppunitTest_xmloff_text.mk | 1 | ||||
-rw-r--r-- | xmloff/qa/unit/text.cxx | 49 | ||||
-rw-r--r-- | xmloff/source/style/xmlstyle.cxx | 21 |
3 files changed, 66 insertions, 5 deletions
diff --git a/xmloff/CppunitTest_xmloff_text.mk b/xmloff/CppunitTest_xmloff_text.mk index a611aa428af7..7fc0fa394950 100644 --- a/xmloff/CppunitTest_xmloff_text.mk +++ b/xmloff/CppunitTest_xmloff_text.mk @@ -24,6 +24,7 @@ $(eval $(call gb_CppunitTest_use_libraries,xmloff_text, \ comphelper \ cppu \ cppuhelper \ + docmodel \ embobj \ sal \ subsequenttest \ diff --git a/xmloff/qa/unit/text.cxx b/xmloff/qa/unit/text.cxx index f7155f546df3..5dfd52010a09 100644 --- a/xmloff/qa/unit/text.cxx +++ b/xmloff/qa/unit/text.cxx @@ -16,11 +16,13 @@ #include <com/sun/star/text/BibliographyDataType.hpp> #include <com/sun/star/text/TextContentAnchorType.hpp> #include <com/sun/star/style/XStyleFamiliesSupplier.hpp> +#include <com/sun/star/drawing/XDrawPageSupplier.hpp> #include <comphelper/propertysequence.hxx> #include <comphelper/propertyvalue.hxx> #include <comphelper/sequenceashashmap.hxx> #include <unotools/tempfile.hxx> +#include <docmodel/uno/UnoTheme.hxx> using namespace ::com::sun::star; @@ -907,6 +909,53 @@ CPPUNIT_TEST_FIXTURE(XmloffStyleTest, testScaleWidthRedline) assertXPath(pXmlDoc, "//draw:frame[@draw:name='Image45']", "width", "6.1728in"); } +CPPUNIT_TEST_FIXTURE(XmloffStyleTest, testThemeExport) +{ + mxComponent = loadFromDesktop("private:factory/swriter"); + + uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference<drawing::XDrawPage> xDrawPage = xDrawPageSupplier->getDrawPage(); + uno::Reference<beans::XPropertySet> xPageProps(xDrawPage, uno::UNO_QUERY); + + model::Theme aTheme("My Theme"); + std::unique_ptr<model::ColorSet> pColorSet(new model::ColorSet("My Color Scheme")); + pColorSet->add(model::ThemeColorType::Dark1, 0x101010); + pColorSet->add(model::ThemeColorType::Light1, 0x202020); + pColorSet->add(model::ThemeColorType::Dark2, 0x303030); + pColorSet->add(model::ThemeColorType::Light2, 0x404040); + pColorSet->add(model::ThemeColorType::Accent1, 0x505050); + pColorSet->add(model::ThemeColorType::Accent2, 0x606060); + pColorSet->add(model::ThemeColorType::Accent3, 0x707070); + pColorSet->add(model::ThemeColorType::Accent4, 0x808080); + pColorSet->add(model::ThemeColorType::Accent5, 0x909090); + pColorSet->add(model::ThemeColorType::Accent6, 0xa0a0a0); + pColorSet->add(model::ThemeColorType::Hyperlink, 0xb0b0b0); + pColorSet->add(model::ThemeColorType::FollowedHyperlink, 0xc0c0c0); + aTheme.SetColorSet(std::move(pColorSet)); + + uno::Reference<util::XTheme> xTheme = model::theme::createXTheme(aTheme); + xPageProps->setPropertyValue("Theme", uno::Any(xTheme)); + + // Export to ODT: + save("writer8"); + + // Check if the 12 colors are written in the XML: + xmlDocUniquePtr pXmlDoc = parseExport("styles.xml"); + assertXPath(pXmlDoc, "//office:styles/loext:theme/loext:color-table/loext:color", 12); + assertXPath(pXmlDoc, "//office:styles/loext:theme/loext:color-table/loext:color[1]", "name", + "dk1"); + assertXPath(pXmlDoc, "//office:styles/loext:theme/loext:color-table/loext:color[1]", "color", + "#101010"); + assertXPath(pXmlDoc, "//office:styles/loext:theme/loext:color-table/loext:color[2]", "name", + "lt1"); + assertXPath(pXmlDoc, "//office:styles/loext:theme/loext:color-table/loext:color[2]", "color", + "#202020"); + assertXPath(pXmlDoc, "//office:styles/loext:theme/loext:color-table/loext:color[12]", "name", + "folHlink"); + assertXPath(pXmlDoc, "//office:styles/loext:theme/loext:color-table/loext:color[12]", "color", + "#c0c0c0"); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/xmlstyle.cxx b/xmloff/source/style/xmlstyle.cxx index bd4273056c98..c72684102a5f 100644 --- a/xmloff/source/style/xmlstyle.cxx +++ b/xmloff/source/style/xmlstyle.cxx @@ -27,6 +27,7 @@ #include <com/sun/star/style/XStyleFamiliesSupplier.hpp> #include <com/sun/star/style/XAutoStylesSupplier.hpp> #include <com/sun/star/style/XAutoStyleFamily.hpp> +#include <com/sun/star/drawing/XDrawPageSupplier.hpp> #include <PageMasterPropMapper.hxx> #include <sal/log.hxx> #include <svl/style.hxx> @@ -44,6 +45,7 @@ #include <xmloff/xmlnumfi.hxx> #include <XMLChartStyleContext.hxx> #include <XMLChartPropertySetMapper.hxx> +#include <XMLThemeContext.hxx> #include <xmloff/XMLShapeStyleContext.hxx> #include "FillStyleContext.hxx" #include <XMLFootnoteConfigurationImportContext.hxx> @@ -708,14 +710,23 @@ SvXMLStylesContext::~SvXMLStylesContext() css::uno::Reference< css::xml::sax::XFastContextHandler > SvXMLStylesContext::createFastChildContext( sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) { - SvXMLStyleContext *pStyle = - CreateStyleChildContext( nElement, xAttrList ); - if( pStyle ) + SvXMLStyleContext* pStyle = CreateStyleChildContext( nElement, xAttrList ); + if (pStyle) { - if( !pStyle->IsTransient() ) - mpImpl->AddStyle( pStyle ); + if (!pStyle->IsTransient()) + mpImpl->AddStyle(pStyle); return pStyle; } + else if (nElement == XML_ELEMENT(LO_EXT, XML_THEME)) + { + uno::Reference<drawing::XDrawPageSupplier> const xDrawPageSupplier(GetImport().GetModel(), uno::UNO_QUERY); + if (xDrawPageSupplier.is()) + { + uno::Reference<drawing::XDrawPage> xPage = xDrawPageSupplier->getDrawPage(); + if (xPage.is()) + return new XMLThemeContext(GetImport(), xAttrList, xPage); + } + } return nullptr; } |