editeng/source/editeng/editobj.cxx            |    4 ++
 include/oox/drawingml/clrscheme.hxx           |    4 ++
 include/svx/svdpage.hxx                       |    4 ++
 oox/qa/unit/data/theme.pptx                   |binary
 oox/qa/unit/drawingml.cxx                     |   35 ++++++++++++++++++++++++++
 oox/source/drawingml/theme.cxx                |    1 
 oox/source/drawingml/themeelementscontext.cxx |    4 ++
 sd/qa/unit/tiledrendering/tiledrendering.cxx  |    8 +++--
 svx/source/styles/ColorSets.cxx               |   21 ++++++++++++---
 svx/source/svdraw/svdmodel.cxx                |   19 +++++++++++---
 svx/source/svdraw/svdpage.cxx                 |   26 +++++++++++++++++++
 11 files changed, 115 insertions(+), 11 deletions(-)

New commits:
commit 32ae1ed7504d58f9216593cb87f25c480a0e623b
Author:     Miklos Vajna <vmik...@collabora.com>
AuthorDate: Fri Nov 19 13:44:40 2021 +0100
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Fri Nov 19 15:28:42 2021 +0100

    PPTX import: handle <a:clrScheme name="...">
    
    We had doc model for this, but the UNO API and the PPTX import was
    missing.
    
    Change-Id: I199e9cc235a783d91700ce74f17d442f41d3c3f8
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/125532
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>
    Tested-by: Jenkins

diff --git a/editeng/source/editeng/editobj.cxx 
b/editeng/source/editeng/editobj.cxx
index 6e0982b27dc0..62ed45b20988 100644
--- a/editeng/source/editeng/editobj.cxx
+++ b/editeng/source/editeng/editobj.cxx
@@ -147,7 +147,9 @@ void ContentInfo::dumpAsXml(xmlTextWriterPtr pWriter) const
     (void)xmlTextWriterStartElement(pWriter, BAD_CAST("ContentInfo"));
     (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("style"), 
BAD_CAST(aStyle.toUtf8().getStr()));
     (void)xmlTextWriterStartElement(pWriter, BAD_CAST("text"));
-    (void)xmlTextWriterWriteString(pWriter, 
BAD_CAST(GetText().toUtf8().getStr()));
+    OUString aText = GetText();
+    // TODO share code with sax_fastparser::FastSaxSerializer::write().
+    (void)xmlTextWriterWriteString(pWriter, BAD_CAST(aText.replaceAll("", 
"&#9;").toUtf8().getStr()));
     (void)xmlTextWriterEndElement(pWriter);
     aParaAttribs.dumpAsXml(pWriter);
     for (size_t i=0; i<maCharAttribs.size(); ++i)
diff --git a/include/oox/drawingml/clrscheme.hxx 
b/include/oox/drawingml/clrscheme.hxx
index 21553aafe2fe..fbb107601940 100644
--- a/include/oox/drawingml/clrscheme.hxx
+++ b/include/oox/drawingml/clrscheme.hxx
@@ -80,6 +80,7 @@ typedef std::shared_ptr< ClrMap > ClrMapPtr;
 class OOX_DLLPUBLIC ClrScheme
 {
     std::vector< std::pair<sal_Int32, ::Color> > maClrScheme;
+    OUString maName;
 
 public:
 
@@ -88,6 +89,9 @@ public:
 
     bool     getColorByIndex(size_t nIndex,
             ::Color& rColor) const;
+
+    void SetName(const OUString& rName) { maName = rName; }
+    const OUString& GetName() const { return maName; }
 };
 
 }
diff --git a/include/svx/svdpage.hxx b/include/svx/svdpage.hxx
index 540002eb7d14..065590e85b9a 100644
--- a/include/svx/svdpage.hxx
+++ b/include/svx/svdpage.hxx
@@ -344,6 +344,8 @@ public:
 
     void SetTheme(std::unique_ptr<svx::Theme> pTheme);
     svx::Theme* GetTheme();
+
+    void dumpAsXml(xmlTextWriterPtr pWriter) const;
 };
 
 
@@ -535,6 +537,8 @@ public:
         const sdr::contact::ViewObjectContact& rOriginal,
         const sdr::contact::DisplayInfo& rDisplayInfo,
         bool bEdit );
+
+    void dumpAsXml(xmlTextWriterPtr pWriter) const override;
 };
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/oox/qa/unit/data/theme.pptx b/oox/qa/unit/data/theme.pptx
new file mode 100644
index 000000000000..6d9ffc00bbbb
Binary files /dev/null and b/oox/qa/unit/data/theme.pptx differ
diff --git a/oox/qa/unit/drawingml.cxx b/oox/qa/unit/drawingml.cxx
index 57e02545eb62..b220170f3edc 100644
--- a/oox/qa/unit/drawingml.cxx
+++ b/oox/qa/unit/drawingml.cxx
@@ -27,6 +27,7 @@
 #include <com/sun/star/chart2/XDataPointCustomLabelField.hpp>
 #include <com/sun/star/style/ParagraphAdjust.hpp>
 #include <com/sun/star/drawing/TextHorizontalAdjust.hpp>
+#include <com/sun/star/drawing/XMasterPageTarget.hpp>
 #include <com/sun/star/text/XTextRange.hpp>
 
 #include <unotools/mediadescriptor.hxx>
@@ -397,6 +398,40 @@ CPPUNIT_TEST_FIXTURE(OoxDrawingmlTest, 
testChartThemeOverride)
     CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(0x4472C4), nActual);
 }
 
+CPPUNIT_TEST_FIXTURE(OoxDrawingmlTest, testPptxTheme)
+{
+    // Given a PPTX file with a slide -> master slide -> theme:
+    OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "theme.pptx";
+
+    // When importing the document:
+    load(aURL);
+
+    // Then make sure the theme + referring to that theme is imported:
+    // Check the imported theme of the master page:
+    uno::Reference<drawing::XDrawPagesSupplier> 
xDrawPagesSupplier(getComponent(), 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(xMasterpage->getPropertyValue("Theme"));
+    CPPUNIT_ASSERT_EQUAL(OUString("Office Theme"), 
aMap["Name"].get<OUString>());
+    // Without the accompanying fix in place, this test would have failed with:
+    // - Cannot extract an Any(void) to string!
+    // i.e. the name of the color scheme was lost on import.
+    CPPUNIT_ASSERT_EQUAL(OUString("Office"), 
aMap["ColorSchemeName"].get<OUString>());
+
+    // Check the reference to that theme:
+    uno::Reference<drawing::XShapes> xDrawPageShapes(xDrawPage, 
uno::UNO_QUERY);
+    uno::Reference<text::XTextRange> xShape(xDrawPageShapes->getByIndex(0), 
uno::UNO_QUERY);
+    uno::Reference<container::XEnumerationAccess> xText(xShape->getText(), 
uno::UNO_QUERY);
+    uno::Reference<container::XEnumerationAccess> 
xPara(xText->createEnumeration()->nextElement(),
+                                                        uno::UNO_QUERY);
+    uno::Reference<beans::XPropertySet> 
xPortion(xPara->createEnumeration()->nextElement(),
+                                                 uno::UNO_QUERY);
+    // 4 is accent1, see oox::drawingml::Color::getSchemeColorIndex().
+    CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(4),
+                         
xPortion->getPropertyValue("CharColorTheme").get<sal_Int32>());
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/oox/source/drawingml/theme.cxx b/oox/source/drawingml/theme.cxx
index be9f199ff8f8..ba1761311154 100644
--- a/oox/source/drawingml/theme.cxx
+++ b/oox/source/drawingml/theme.cxx
@@ -107,6 +107,7 @@ void Theme::addTheme(const 
css::uno::Reference<css::drawing::XDrawPage>& xDrawPa
 {
     beans::PropertyValues aValues = {
         comphelper::makePropertyValue("Name", maThemeName),
+        comphelper::makePropertyValue("ColorSchemeName", 
maClrScheme.GetName()),
     };
     uno::Reference<beans::XPropertySet> xPropertySet(xDrawPage, 
uno::UNO_QUERY);
     xPropertySet->setPropertyValue("Theme", uno::makeAny(aValues));
diff --git a/oox/source/drawingml/themeelementscontext.cxx 
b/oox/source/drawingml/themeelementscontext.cxx
index 6fbd62e91d18..0922c4b61939 100644
--- a/oox/source/drawingml/themeelementscontext.cxx
+++ b/oox/source/drawingml/themeelementscontext.cxx
@@ -214,6 +214,10 @@ ContextHandlerRef ThemeElementsContext::onCreateContext( 
sal_Int32 nElement, con
     switch( nElement )
     {
         case A_TOKEN( clrScheme ):  // CT_ColorScheme
+            if (rAttribs.hasAttribute(XML_name))
+            {
+                
mrTheme.getClrScheme().SetName(rAttribs.getString(XML_name).get());
+            }
             return new clrSchemeContext( *this, mrTheme.getClrScheme() );
         case A_TOKEN( fontScheme ): // CT_FontScheme
             return new FontSchemeContext( *this, mrTheme.getFontScheme() );
diff --git a/sd/qa/unit/tiledrendering/tiledrendering.cxx 
b/sd/qa/unit/tiledrendering/tiledrendering.cxx
index 44d84207683f..571eafb0b08c 100644
--- a/sd/qa/unit/tiledrendering/tiledrendering.cxx
+++ b/sd/qa/unit/tiledrendering/tiledrendering.cxx
@@ -393,7 +393,9 @@ xmlDocUniquePtr SdTiledRenderingTest::parseXmlDump()
     (void)xmlTextWriterEndDocument(pXmlWriter);
     xmlFreeTextWriter(pXmlWriter);
 
-    return xmlDocUniquePtr(xmlParseMemory(reinterpret_cast<const 
char*>(xmlBufferContent(m_pXmlBuffer)), xmlBufferLength(m_pXmlBuffer)));
+    auto pCharBuffer = reinterpret_cast<const 
xmlChar*>(xmlBufferContent(m_pXmlBuffer));
+    SAL_INFO("test", "SdTiledRenderingTest::parseXmlDump: pCharBuffer is '" << 
pCharBuffer << "'");
+    return xmlDocUniquePtr(xmlParseDoc(pCharBuffer));
 }
 
 void SdTiledRenderingTest::testCreateDestroy()
@@ -861,7 +863,7 @@ void SdTiledRenderingTest::testResizeTableColumn()
 
     // Remember the original cell widths.
     xmlDocUniquePtr pXmlDoc = parseXmlDump();
-    OString aPrefix = 
"/SdDrawDocument/SdrModel/SdPage/SdrObjList/SdrTableObj/SdrTableObjImpl/TableLayouter/columns/";
+    OString aPrefix = 
"/SdDrawDocument/SdrModel/maPages/SdPage/SdrPage/SdrObjList/SdrTableObj/SdrTableObjImpl/TableLayouter/columns/";
     sal_Int32 nExpectedColumn1 = getXPath(pXmlDoc, aPrefix + 
"TableLayouter_Layout[1]", "size").toInt32();
     sal_Int32 nExpectedColumn2 = getXPath(pXmlDoc, aPrefix + 
"TableLayouter_Layout[2]", "size").toInt32();
     pXmlDoc = nullptr;
@@ -1704,7 +1706,7 @@ void SdTiledRenderingTest::testTdf104405()
         OUString("2"),
         getXPath(
             pXmlDoc,
-            
"/SdDrawDocument/SdrModel/SdPage/SdrObjList/SdrTableObj/SdrTableObjImpl"
+            
"/SdDrawDocument/SdrModel/maPages/SdPage/SdrPage/SdrObjList/SdrTableObj/SdrTableObjImpl"
                 
"/TableModel/Cell[1]/DefaultProperties/SfxItemSet/SdrTextVertAdjustItem",
             "value"));
 }
diff --git a/svx/source/styles/ColorSets.cxx b/svx/source/styles/ColorSets.cxx
index 8ab3d939ef5a..fbcf4bd4a889 100644
--- a/svx/source/styles/ColorSets.cxx
+++ b/svx/source/styles/ColorSets.cxx
@@ -164,11 +164,15 @@ void Theme::dumpAsXml(xmlTextWriterPtr pWriter) const
 
 void Theme::ToAny(css::uno::Any& rVal) const
 {
-    beans::PropertyValues aValues = {
-        comphelper::makePropertyValue("Name", maName)
-    };
+    comphelper::SequenceAsHashMap aMap;
+    aMap["Name"] <<= maName;
 
-    rVal <<= aValues;
+    if (mpColorSet)
+    {
+        aMap["ColorSchemeName"] <<= mpColorSet->getName();
+    }
+
+    rVal <<= aMap.getAsConstPropertyValueList();
 }
 
 std::unique_ptr<Theme> Theme::FromAny(const css::uno::Any& rVal)
@@ -184,6 +188,15 @@ std::unique_ptr<Theme> Theme::FromAny(const css::uno::Any& 
rVal)
         pTheme = std::make_unique<Theme>(aName);
     }
 
+    it = aMap.find("ColorSchemeName");
+    if (it != aMap.end() && pTheme)
+    {
+        OUString aName;
+        it->second >>= aName;
+        auto pColorSet = std::make_unique<ColorSet>(aName);
+        pTheme->SetColorSet(std::move(pColorSet));
+    }
+
     return pTheme;
 }
 
diff --git a/svx/source/svdraw/svdmodel.cxx b/svx/source/svdraw/svdmodel.cxx
index 6dcebf3ef541..8a19ce2b27a7 100644
--- a/svx/source/svdraw/svdmodel.cxx
+++ b/svx/source/svdraw/svdmodel.cxx
@@ -1874,12 +1874,25 @@ void SdrModel::dumpAsXml(xmlTextWriterPtr pWriter) const
     (void)xmlTextWriterStartElement(pWriter, BAD_CAST("SdrModel"));
     (void)xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("ptr"), "%p", 
this);
 
-    sal_uInt16 nPageCount = GetPageCount();
-    for (sal_uInt16 i = 0; i < nPageCount; ++i)
+    (void)xmlTextWriterStartElement(pWriter, BAD_CAST("maMasterPages"));
+    for (size_t i = 0; i < maMasterPages.size(); ++i)
     {
-        if (const SdrPage* pPage = GetPage(i))
+        if (const SdrPage* pPage = maMasterPages[i].get())
+        {
+            pPage->dumpAsXml(pWriter);
+        }
+    }
+    (void)xmlTextWriterEndElement(pWriter);
+
+    (void)xmlTextWriterStartElement(pWriter, BAD_CAST("maPages"));
+    for (size_t i = 0; i < maPages.size(); ++i)
+    {
+        if (const SdrPage* pPage = maPages[i].get())
+        {
             pPage->dumpAsXml(pWriter);
+        }
     }
+    (void)xmlTextWriterEndElement(pWriter);
 
     if (mpImpl->mpTheme)
     {
diff --git a/svx/source/svdraw/svdpage.cxx b/svx/source/svdraw/svdpage.cxx
index a0acaba2ee5f..1ebfe6cad4ac 100644
--- a/svx/source/svdraw/svdpage.cxx
+++ b/svx/source/svdraw/svdpage.cxx
@@ -1291,6 +1291,19 @@ void 
SdrPageProperties::SetTheme(std::unique_ptr<svx::Theme> pTheme) { mpTheme =
 
 svx::Theme* SdrPageProperties::GetTheme() { return mpTheme.get(); }
 
+void SdrPageProperties::dumpAsXml(xmlTextWriterPtr pWriter) const
+{
+    (void)xmlTextWriterStartElement(pWriter, BAD_CAST("SdrPageProperties"));
+    (void)xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("ptr"), "%p", 
this);
+
+    if (mpTheme)
+    {
+        mpTheme->dumpAsXml(pWriter);
+    }
+
+    (void)xmlTextWriterEndElement(pWriter);
+}
+
 SdrPage::SdrPage(SdrModel& rModel, bool bMasterPage)
 :   mrSdrModelFromSdrPage(rModel),
     mnWidth(10),
@@ -1817,6 +1830,19 @@ bool SdrPage::checkVisibility(
     return true;
 }
 
+void SdrPage::dumpAsXml(xmlTextWriterPtr pWriter) const
+{
+    (void)xmlTextWriterStartElement(pWriter, BAD_CAST("SdrPage"));
+    SdrObjList::dumpAsXml(pWriter);
+
+    if (mpSdrPageProperties)
+    {
+        mpSdrPageProperties->dumpAsXml(pWriter);
+    }
+
+    (void)xmlTextWriterEndElement(pWriter);
+}
+
 // DrawContact support: Methods for handling Page changes
 void SdrPage::ActionChanged()
 {

Reply via email to