sw/qa/core/theme/ThemeTest.cxx | 29 ++++++++++++++- sw/qa/core/theme/data/ThemeColorInHeading.odt |binary xmloff/CppunitTest_xmloff_text.mk | 1 xmloff/qa/unit/text.cxx | 49 ++++++++++++++++++++++++++ xmloff/source/style/xmlstyle.cxx | 21 ++++++++--- 5 files changed, 94 insertions(+), 6 deletions(-)
New commits: commit ff9a1ba9bf55b8dac59670648d58bf78df16a982 Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> AuthorDate: Sat Jan 28 18:43:51 2023 +0900 Commit: Tomaž Vajngerl <qui...@gmail.com> CommitDate: Fri Feb 17 05:24:01 2023 +0000 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 <qui...@gmail.com> (cherry picked from commit d8de2dc3c55a9013a71167c8058a333e7221a6a0) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/146452 Tested-by: Tomaž Vajngerl <qui...@gmail.com> diff --git a/sw/qa/core/theme/ThemeTest.cxx b/sw/qa/core/theme/ThemeTest.cxx index 8f12e8bdacbd..e3ed5548f528 100644 --- a/sw/qa/core/theme/ThemeTest.cxx +++ b/sw/qa/core/theme/ThemeTest.cxx @@ -42,7 +42,7 @@ CPPUNIT_TEST_FIXTURE(SwCoreThemeTest, testThemeColorInHeading) CPPUNIT_ASSERT_EQUAL(model::ThemeColorType::Accent1, aThemeColor.getType()); } -CPPUNIT_TEST_FIXTURE(SwCoreThemeTest, testDrawPageThemeExists) +CPPUNIT_TEST_FIXTURE(SwCoreThemeTest, testDrawPageThemeExistsDOCX) { createSwDoc("ThemeColorInHeading.docx"); SwDoc* pDoc = getSwDoc(); @@ -83,6 +83,33 @@ CPPUNIT_TEST_FIXTURE(SwCoreThemeTest, testDrawPageThemeExists) rFontScheme.findMinorSupplementalTypeface(u"Thai")); } +CPPUNIT_TEST_FIXTURE(SwCoreThemeTest, testDrawPageThemeExistsODT) +{ + createSwDoc("ThemeColorInHeading.odt"); + SwDoc* pDoc = getSwDoc(); + CPPUNIT_ASSERT(pDoc); + + SdrPage* pPage = pDoc->getIDocumentDrawModelAccess().GetDrawModel()->GetPage(0); + model::Theme* pTheme = pPage->getSdrPageProperties().GetTheme(); + CPPUNIT_ASSERT(pTheme); + CPPUNIT_ASSERT_EQUAL(OUString(u"Office Theme"), pTheme->GetName()); + + model::ColorSet* pColorSet = pTheme->GetColorSet(); + CPPUNIT_ASSERT(pColorSet); + CPPUNIT_ASSERT_EQUAL(OUString(u"Orange"), pColorSet->getName()); + + CPPUNIT_ASSERT_EQUAL(Color(0xE48312), pTheme->GetColor(model::ThemeColorType::Accent1)); + CPPUNIT_ASSERT_EQUAL(Color(0xBD582C), pTheme->GetColor(model::ThemeColorType::Accent2)); + CPPUNIT_ASSERT_EQUAL(Color(0x865640), pTheme->GetColor(model::ThemeColorType::Accent3)); + CPPUNIT_ASSERT_EQUAL(Color(0x9B8357), pTheme->GetColor(model::ThemeColorType::Accent4)); + CPPUNIT_ASSERT_EQUAL(Color(0xC2BC80), pTheme->GetColor(model::ThemeColorType::Accent5)); + CPPUNIT_ASSERT_EQUAL(Color(0x94A088), pTheme->GetColor(model::ThemeColorType::Accent6)); + CPPUNIT_ASSERT_EQUAL(Color(0x000000), pTheme->GetColor(model::ThemeColorType::Dark1)); + CPPUNIT_ASSERT_EQUAL(Color(0x637052), pTheme->GetColor(model::ThemeColorType::Dark2)); + CPPUNIT_ASSERT_EQUAL(Color(0xFFFFFF), pTheme->GetColor(model::ThemeColorType::Light1)); + CPPUNIT_ASSERT_EQUAL(Color(0xCCDDEA), pTheme->GetColor(model::ThemeColorType::Light2)); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/qa/core/theme/data/ThemeColorInHeading.odt b/sw/qa/core/theme/data/ThemeColorInHeading.odt new file mode 100644 index 000000000000..9931ac4e2dc1 Binary files /dev/null and b/sw/qa/core/theme/data/ThemeColorInHeading.odt differ 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; }