summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRegina Henschel <rb.henschel@t-online.de>2023-08-29 22:18:29 +0200
committerTomaž Vajngerl <quikee@gmail.com>2023-08-30 16:02:51 +0200
commitcf1cdc00e1e2d2684cfe57ac002a37c5f3d100c5 (patch)
treefa92b6f07db1022bda5e7c0742afe396e6bdb4d4
parent9254fbce6b9e20a75aa2a379bcf2fc9dc41a5b44 (diff)
tdf#156975 Save a Theme in Draw too not only in Impress
Draw and Impress have many things in common and should therefore be treated equally where possible. Only if the theme colors are present in the document, colors can be recognized as theme colors during import. Change-Id: Ia1fae2aff989ae305c210efa3f925a80898880e7 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/156267 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
-rw-r--r--xmloff/qa/unit/draw.cxx57
-rw-r--r--xmloff/source/draw/sdxmlexp.cxx5
2 files changed, 58 insertions, 4 deletions
diff --git a/xmloff/qa/unit/draw.cxx b/xmloff/qa/unit/draw.cxx
index 4daef2603a9f..18e5137307f6 100644
--- a/xmloff/qa/unit/draw.cxx
+++ b/xmloff/qa/unit/draw.cxx
@@ -719,6 +719,63 @@ CPPUNIT_TEST_FIXTURE(XmloffDrawTest, testTextRotationPlusPre)
// But reload catches it.
saveAndReload("writer8");
}
+
+CPPUNIT_TEST_FIXTURE(XmloffDrawTest, testTdf156975_ThemeExport)
+{
+ // It tests, that a theme is written to master page in Draw documents.
+ // Without fix for tdf#156975 it was not written at all.
+ // The test needs to be adapted, when themes are available in ODF.
+
+ mxComponent = loadFromDesktop("private:factory/sdraw");
+ // generate a theme to be sure we have got one and know the values
+ uno::Reference<drawing::XDrawPagesSupplier> xDrawPagesSupplier(mxComponent, uno::UNO_QUERY);
+ uno::Reference<drawing::XMasterPageTarget> xDrawPage(
+ xDrawPagesSupplier->getDrawPages()->getByIndex(0), uno::UNO_QUERY);
+ uno::Reference<beans::XPropertySet> xMasterPageProps(xDrawPage->getMasterPage(),
+ uno::UNO_QUERY);
+
+ auto pTheme = std::make_shared<model::Theme>("Custom");
+ auto pColorSet = std::make_shared<model::ColorSet>("My Colors");
+ pColorSet->add(model::ThemeColorType::Dark1, 0x000000);
+ pColorSet->add(model::ThemeColorType::Light1, 0xffff11);
+ pColorSet->add(model::ThemeColorType::Dark2, 0x002200);
+ pColorSet->add(model::ThemeColorType::Light2, 0xff33ff);
+ pColorSet->add(model::ThemeColorType::Accent1, 0x440000);
+ pColorSet->add(model::ThemeColorType::Accent2, 0x005500);
+ pColorSet->add(model::ThemeColorType::Accent3, 0x000066);
+ pColorSet->add(model::ThemeColorType::Accent4, 0x777700);
+ pColorSet->add(model::ThemeColorType::Accent5, 0x880088);
+ pColorSet->add(model::ThemeColorType::Accent6, 0x009999);
+ pColorSet->add(model::ThemeColorType::Hyperlink, 0x0a0a0a);
+ pColorSet->add(model::ThemeColorType::FollowedHyperlink, 0xb0b0b0);
+ pTheme->setColorSet(pColorSet);
+
+ uno::Reference<util::XTheme> xTheme = model::theme::createXTheme(pTheme);
+ xMasterPageProps->setPropertyValue("Theme", uno::Any(xTheme));
+
+ // save as odg
+ save("draw8");
+
+ // and check the markup.
+ xmlDocUniquePtr pXmlDoc = parseExport("styles.xml");
+ static constexpr OStringLiteral sThemePath
+ = "//office:master-styles/style:master-page/loext:theme";
+ assertXPath(pXmlDoc, sThemePath, 1);
+ assertXPath(pXmlDoc, sThemePath + "[@loext:name='Custom']");
+
+ const OString sThemeColorsPath = sThemePath + "/loext:theme-colors";
+ assertXPath(pXmlDoc, sThemeColorsPath, 1);
+ assertXPath(pXmlDoc, sThemeColorsPath + "[@loext:name='My Colors']");
+
+ const OString sThemeColorPath = sThemeColorsPath + "/loext:color";
+ assertXPath(pXmlDoc, sThemeColorPath, 12);
+ assertXPath(pXmlDoc, sThemeColorPath + "[3]", "name", "dark2");
+ assertXPath(pXmlDoc, sThemeColorPath + "[3]", "color", "#002200");
+ assertXPath(pXmlDoc, sThemeColorPath + "[9]", "name", "accent5");
+ assertXPath(pXmlDoc, sThemeColorPath + "[9]", "color", "#880088");
+ assertXPath(pXmlDoc, sThemeColorPath + "[12]", "name", "followed-hyperlink");
+ assertXPath(pXmlDoc, sThemeColorPath + "[12]", "color", "#b0b0b0");
+}
CPPUNIT_PLUGIN_IMPLEMENT();
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/xmloff/source/draw/sdxmlexp.cxx b/xmloff/source/draw/sdxmlexp.cxx
index 6384f8bec396..f0d7fc6c220f 100644
--- a/xmloff/source/draw/sdxmlexp.cxx
+++ b/xmloff/source/draw/sdxmlexp.cxx
@@ -2301,10 +2301,7 @@ void SdXMLExport::ExportMasterStyles_()
exportFormsElement( xMasterPage );
// write optional loext:theme
- if (IsImpress())
- {
- ExportThemeElement(xMasterPage);
- }
+ ExportThemeElement(xMasterPage);
// write graphic objects on this master page (if any)
if(xMasterPage.is() && xMasterPage->getCount())