diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2022-05-24 20:11:47 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2022-05-25 08:11:51 +0200 |
commit | 4a54a24c207f3040390e2fefec41cbbf0edd5eca (patch) | |
tree | 8f864651173971bbe6e33b146cb2d5230217514c /sd | |
parent | 4bd8b4e469a4084eee0ec467721704ae51f82301 (diff) |
tdf#149205 sd theme: fix PPTX export loosing dk1 and lt1 colors
Document theme of Impress documents were exported to PPTX only
partially: dk1 and lt1 was hardcoded to the SYS_COLOR_SCHEMES define,
while the rest was written from master-slide-specific svx::Theme.
The benefit of this is that our theme is just a set of colors
(<a:srgbClr> markup in OOXML), while dk1 and lt1 is more dynamic by
default in PowerPoint (<a:sysClr> in OOXML). The downside is that this
way a custom dk1 and lt1 color was lost on export.
Fix the problem by switching to <a:srgbClr> markup even for dk1 and lt1:
not using the <a:sysClr> markup doesn't seem to be a problem in
practice, or at least much less problematic than rendering with bad
colors.
If there is a need, dedicated <a:sysClr> markup support can be still
added later by extending svx::ColorSet::maColors to not only store a
list of colors, but also some additional properties of those colors.
Change-Id: I26df3fd8c891c217df0d36382f6599805198f4bc
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/134883
Tested-by: Jenkins
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Diffstat (limited to 'sd')
-rw-r--r-- | sd/CppunitTest_sd_filter_eppt.mk | 1 | ||||
-rw-r--r-- | sd/qa/filter/eppt/eppt.cxx | 51 | ||||
-rw-r--r-- | sd/source/filter/eppt/pptx-epptooxml.cxx | 26 |
3 files changed, 64 insertions, 14 deletions
diff --git a/sd/CppunitTest_sd_filter_eppt.mk b/sd/CppunitTest_sd_filter_eppt.mk index 1a58e113643e..72b7b4d4dbb7 100644 --- a/sd/CppunitTest_sd_filter_eppt.mk +++ b/sd/CppunitTest_sd_filter_eppt.mk @@ -13,6 +13,7 @@ $(eval $(call gb_CppunitTest_CppunitTest,sd_filter_eppt)) $(eval $(call gb_CppunitTest_use_externals,sd_filter_eppt,\ boost_headers \ + libxml2 \ )) $(eval $(call gb_CppunitTest_add_exception_objects,sd_filter_eppt, \ diff --git a/sd/qa/filter/eppt/eppt.cxx b/sd/qa/filter/eppt/eppt.cxx index d27713da20b0..1e8e2c7e1491 100644 --- a/sd/qa/filter/eppt/eppt.cxx +++ b/sd/qa/filter/eppt/eppt.cxx @@ -9,20 +9,25 @@ #include <test/bootstrapfixture.hxx> #include <unotest/macros_test.hxx> +#include <test/xmltesttools.hxx> +#include <com/sun/star/beans/XPropertySet.hpp> #include <com/sun/star/drawing/XDrawPagesSupplier.hpp> +#include <com/sun/star/drawing/XMasterPageTarget.hpp> #include <com/sun/star/frame/Desktop.hpp> #include <com/sun/star/frame/XStorable.hpp> +#include <com/sun/star/util/Color.hpp> #include <unotools/mediadescriptor.hxx> #include <unotools/tempfile.hxx> +#include <test/xmldocptr.hxx> using namespace ::com::sun::star; namespace { /// Covers sd/source/filter/eppt/ fixes. -class Test : public test::BootstrapFixture, public unotest::MacrosTest +class Test : public test::BootstrapFixture, public unotest::MacrosTest, public XmlTestTools { private: uno::Reference<lang::XComponent> mxComponent; @@ -30,6 +35,7 @@ private: public: void setUp() override; void tearDown() override; + void registerNamespaces(xmlXPathContextPtr& pXmlXpathCtx) override; uno::Reference<lang::XComponent>& getComponent() { return mxComponent; } }; @@ -48,6 +54,11 @@ void Test::tearDown() test::BootstrapFixture::tearDown(); } +void Test::registerNamespaces(xmlXPathContextPtr& pXmlXpathCtx) +{ + XmlTestTools::registerOOXMLNamespaces(pXmlXpathCtx); +} + constexpr OUStringLiteral DATA_DIRECTORY = u"/sd/qa/filter/eppt/data/"; CPPUNIT_TEST_FIXTURE(Test, testOOXMLCustomShapeBitmapFill) @@ -76,6 +87,44 @@ CPPUNIT_TEST_FIXTURE(Test, testOOXMLCustomShapeBitmapFill) CPPUNIT_ASSERT_EQUAL(OUString("com.sun.star.drawing.GraphicObjectShape"), xShape->getShapeType()); } + +CPPUNIT_TEST_FIXTURE(Test, testThemeExport) +{ + // Given a document with a master slide and a theme, lt1 is set to 0x000002: + uno::Reference<lang::XComponent> xComponent = loadFromDesktop("private:factory/simpress"); + uno::Reference<drawing::XDrawPagesSupplier> xDrawPagesSupplier(xComponent, uno::UNO_QUERY); + 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 + = { 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc }; + aMap["ColorScheme"] <<= aColorScheme; + uno::Any aTheme(aMap.getAsConstPropertyValueList()); + xMasterPage->setPropertyValue("Theme", aTheme); + + // When exporting to PPTX: + utl::TempFile aTempFile; + uno::Reference<frame::XStorable> xStorable(xComponent, uno::UNO_QUERY); + utl::MediaDescriptor aMediaDescriptor; + aMediaDescriptor["FilterName"] <<= OUString("Impress Office Open XML"); + aTempFile.EnableKillingFile(); + xStorable->storeToURL(aTempFile.GetURL(), aMediaDescriptor.getAsConstPropertyValueList()); + validate(aTempFile.GetFileName(), test::OOXML); + + // Then verify that this color is not lost: + std::unique_ptr<SvStream> pStream = parseExportStream(aTempFile, "ppt/theme/theme1.xml"); + xmlDocUniquePtr pXmlDoc = parseXmlStream(pStream.get()); + assertXPath(pXmlDoc, "//a:clrScheme/a:lt1/a:srgbClr", "val", "000002"); + // Without the fix in place, this test would have failed with: + // - Expected: 1 + // - Actual : 0 + // - XPath '//a:clrScheme/a:lt1/a:srgbClr' number of nodes is incorrect + // i.e. the RGB color was lost on export. + xComponent->dispose(); +} } CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/sd/source/filter/eppt/pptx-epptooxml.cxx b/sd/source/filter/eppt/pptx-epptooxml.cxx index e9b923264390..444c765a8914 100644 --- a/sd/source/filter/eppt/pptx-epptooxml.cxx +++ b/sd/source/filter/eppt/pptx-epptooxml.cxx @@ -2154,7 +2154,8 @@ bool PowerPointExport::WriteColorSets(const FSHelperPtr& pFS, svx::Theme* pTheme { static std::map<PredefinedClrSchemeId, sal_Int32> aPredefinedClrTokens = { - // dk1 and lt1 is intentionally missing. + { dk1, XML_dk1 }, + { lt1, XML_lt1 }, { dk2, XML_dk2 }, { lt2, XML_lt2 }, { accent1, XML_accent1 }, @@ -2178,14 +2179,11 @@ bool PowerPointExport::WriteColorSets(const FSHelperPtr& pFS, svx::Theme* pTheme return false; } - for (int nId = PredefinedClrSchemeId::dk2; nId < PredefinedClrSchemeId::Count; nId++) + for (int nId = PredefinedClrSchemeId::dk1; nId < PredefinedClrSchemeId::Count; nId++) { - // dk1 and lt1 are not written here. - int nIndex = nId + 2; - sal_Int32 nToken = aPredefinedClrTokens[static_cast<PredefinedClrSchemeId>(nId)]; pFS->startElementNS(XML_a, nToken); - pFS->singleElementNS(XML_a, XML_srgbClr, XML_val, I32SHEX(static_cast<sal_Int32>(pColorSet->getColor(nIndex)))); + pFS->singleElementNS(XML_a, XML_srgbClr, XML_val, I32SHEX(static_cast<sal_Int32>(pColorSet->getColor(nId)))); pFS->endElementNS(XML_a, nToken); } @@ -2277,15 +2275,17 @@ void PowerPointExport::WriteTheme(sal_Int32 nThemeNum, svx::Theme* pTheme) } pFS->startElementNS(XML_a, XML_clrScheme, XML_name, aColorSchemeName); - pFS->write(SYS_COLOR_SCHEMES); - - if (!WriteColorSets(pFS, pTheme) && !WriteColorSchemes(pFS, sThemePath)) + if (!WriteColorSets(pFS, pTheme)) { - // if style is not defined, try to use first one - if (!WriteColorSchemes(pFS, "ppt/theme/theme1.xml")) + pFS->write(SYS_COLOR_SCHEMES); + if (!WriteColorSchemes(pFS, sThemePath)) { - // color schemes are required - use default values - WriteDefaultColorSchemes(pFS); + // if style is not defined, try to use first one + if (!WriteColorSchemes(pFS, "ppt/theme/theme1.xml")) + { + // color schemes are required - use default values + WriteDefaultColorSchemes(pFS); + } } } |