[Libreoffice-commits] core.git: Branch 'distro/collabora/co-2021' - 2 commits - sd/qa sd/source

Sarper Akdemir (via logerrit) logerrit at kemper.freedesktop.org
Wed Jun 23 09:51:54 UTC 2021


 sd/qa/unit/data/pptx/tdf59323.pptx       |binary
 sd/qa/unit/export-tests-ooxml2.cxx       |   37 ++++
 sd/source/filter/eppt/epptooxml.hxx      |    3 
 sd/source/filter/eppt/pptx-epptooxml.cxx |  240 ++++++++++++++++++++++++++++++-
 4 files changed, 279 insertions(+), 1 deletion(-)

New commits:
commit f34cf6a2e67e75f83498b3a1890668784416bde2
Author:     Sarper Akdemir <sarper.akdemir at collabora.com>
AuthorDate: Wed Jun 9 08:24:12 2021 +0300
Commit:     Mike Kaganski <mike.kaganski at collabora.com>
CommitDate: Wed Jun 23 11:51:30 2021 +0200

    tdf#59323: pptx export: slide footers roundtrip unit test
    
    Roundtrip test that checks the slide footers, and their placeholder indexes.
    
    Change-Id: I9c4b819092ac6699617d71538c35b066d6e6f974
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/117013
    Tested-by: Jenkins
    Reviewed-by: Miklos Vajna <vmiklos at collabora.com>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/117631
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice at gmail.com>
    Reviewed-by: Mike Kaganski <mike.kaganski at collabora.com>

diff --git a/sd/qa/unit/data/pptx/tdf59323.pptx b/sd/qa/unit/data/pptx/tdf59323.pptx
new file mode 100755
index 000000000000..0660c0af4f23
Binary files /dev/null and b/sd/qa/unit/data/pptx/tdf59323.pptx differ
diff --git a/sd/qa/unit/export-tests-ooxml2.cxx b/sd/qa/unit/export-tests-ooxml2.cxx
index c4a4bfd28b2b..ec756b19d7bb 100644
--- a/sd/qa/unit/export-tests-ooxml2.cxx
+++ b/sd/qa/unit/export-tests-ooxml2.cxx
@@ -211,6 +211,7 @@ public:
     void testTdf96061_textHighlight();
     void testTextColumns_tdf140852();
     void testTextColumns_3columns();
+    void testTdf59323_slideFooters();
 
     CPPUNIT_TEST_SUITE(SdOOXMLExportTest2);
 
@@ -336,6 +337,7 @@ public:
     CPPUNIT_TEST(testTdf96061_textHighlight);
     CPPUNIT_TEST(testTextColumns_tdf140852);
     CPPUNIT_TEST(testTextColumns_3columns);
+    CPPUNIT_TEST(testTdf59323_slideFooters);
 
     CPPUNIT_TEST_SUITE_END();
 
@@ -3245,6 +3247,41 @@ void SdOOXMLExportTest2::testTextColumns_3columns()
     tempFile.EnableKillingFile();
 }
 
+void SdOOXMLExportTest2::testTdf59323_slideFooters()
+{
+    ::sd::DrawDocShellRef xDocShRef
+        = loadURL(m_directories.getURLFromSrc(u"/sd/qa/unit/data/pptx/tdf59323.pptx"), PPTX);
+
+    utl::TempFile tempFile;
+    xDocShRef = saveAndReload(xDocShRef.get(), PPTX, &tempFile);
+
+    uno::Reference<drawing::XDrawPagesSupplier> xDoc(xDocShRef->GetDoc()->getUnoModel(),
+                                                     uno::UNO_QUERY_THROW);
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(3), xDoc->getDrawPages()->getCount());
+
+    for (int nPageIndex = 0; nPageIndex < 3; nPageIndex++)
+    {
+        uno::Reference<drawing::XDrawPage> xPage(getPage(0, xDocShRef));
+        uno::Reference<beans::XPropertySet> xPropSet(xPage, uno::UNO_QUERY);
+        CPPUNIT_ASSERT_EQUAL(true, xPropSet->getPropertyValue("IsFooterVisible").get<bool>());
+        CPPUNIT_ASSERT_EQUAL(true, xPropSet->getPropertyValue("IsDateTimeVisible").get<bool>());
+        CPPUNIT_ASSERT_EQUAL(true, xPropSet->getPropertyValue("IsPageNumberVisible").get<bool>());
+    }
+
+    // Test placeholder indexes
+    xmlDocUniquePtr pXmlDocMaster = parseExport(tempFile, "ppt/slideMasters/slideMaster1.xml");
+    assertXPath(pXmlDocMaster, "//p:ph [@type='dt']", "idx", "1");
+    assertXPath(pXmlDocMaster, "//p:ph [@type='ftr']", "idx", "2");
+    assertXPath(pXmlDocMaster, "//p:ph [@type='sldNum']", "idx", "3");
+
+    xmlDocUniquePtr pXmlDocSlide1 = parseExport(tempFile, "ppt/slides/slide1.xml");
+    assertXPath(pXmlDocSlide1, "//p:ph [@type='dt']", "idx", "1");
+    assertXPath(pXmlDocSlide1, "//p:ph [@type='ftr']", "idx", "2");
+    assertXPath(pXmlDocSlide1, "//p:ph [@type='sldNum']", "idx", "3");
+
+    xDocShRef->DoClose();
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(SdOOXMLExportTest2);
 
 CPPUNIT_PLUGIN_IMPLEMENT();
commit 3dab66894615fde0891027a04788238d679b13f5
Author:     Sarper Akdemir <sarper.akdemir at collabora.com>
AuthorDate: Wed Jun 9 08:21:27 2021 +0300
Commit:     Mike Kaganski <mike.kaganski at collabora.com>
CommitDate: Wed Jun 23 11:51:16 2021 +0200

    tdf#59323: pptx export: add support for slide footers
    
    Adds support for exporting slide footers to PPTX.
    
    Slide footers are exported as shapes that use placeholder indexes to refer to
    the shapes on master.
    
    To make the references work they are exported to layout slides too.
    
    Change-Id: I8bfde520b0aec66405523c719844e69c6fc15b79
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/117012
    Tested-by: Jenkins
    Reviewed-by: Miklos Vajna <vmiklos at collabora.com>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/117630
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice at gmail.com>
    Reviewed-by: Mike Kaganski <mike.kaganski at collabora.com>

diff --git a/sd/source/filter/eppt/epptooxml.hxx b/sd/source/filter/eppt/epptooxml.hxx
index c745c432203b..1c31ccdee87c 100644
--- a/sd/source/filter/eppt/epptooxml.hxx
+++ b/sd/source/filter/eppt/epptooxml.hxx
@@ -123,6 +123,9 @@ private:
         @returns Placeholder index
     */
     unsigned CreateNewPlaceholderIndex(const css::uno::Reference<css::drawing::XShape>& rXShape);
+    css::uno::Reference<css::drawing::XShape> GetReferencedPlaceholderXShape(const PlaceholderType eType, PageType ePageType) const;
+    void WritePlaceholderReferenceShapes(PowerPointShapeExport& rDML, PageType ePageType);
+
     /// Should we export as .pptm, ie. do we contain macros?
     bool mbPptm;
 
diff --git a/sd/source/filter/eppt/pptx-epptooxml.cxx b/sd/source/filter/eppt/pptx-epptooxml.cxx
index b3d68353f8e9..9299dad777df 100644
--- a/sd/source/filter/eppt/pptx-epptooxml.cxx
+++ b/sd/source/filter/eppt/pptx-epptooxml.cxx
@@ -28,6 +28,7 @@
 
 #include <comphelper/sequenceashashmap.hxx>
 #include <comphelper/storagehelper.hxx>
+#include <comphelper/xmltools.hxx>
 #include <sax/fshelper.hxx>
 #include <rtl/ustrbuf.hxx>
 #include <sal/log.hxx>
@@ -52,6 +53,10 @@
 #include "pptx-animations.hxx"
 #include "../ppt/pptanimations.hxx"
 
+#include <svx/svdpage.hxx>
+#include <svx/unoapi.hxx>
+#include <sdpage.hxx>
+
 #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
 #include <com/sun/star/document/XStorageBasedDocument.hpp>
 #include <utility>
@@ -106,7 +111,11 @@ public:
     ShapeExport&        WriteTextShape(const Reference< XShape >& xShape) override;
     ShapeExport&        WriteUnknownShape(const Reference< XShape >& xShape) override;
     ShapeExport&        WritePlaceholderShape(const Reference< XShape >& xShape, PlaceholderType ePlaceholder);
+    /** Writes a placeholder shape that references the placeholder on the master slide */
+    ShapeExport&        WritePlaceholderReferenceShape(PlaceholderType ePlaceholder, unsigned nReferencedPlaceholderIdx, PageType ePageType, Reference<XPropertySet>& rXPagePropSet);
     ShapeExport&        WritePageShape(const Reference< XShape >& xShape, PageType ePageType, bool bPresObj);
+    /** Writes textbody of a placeholder that references the placeholder on the master slide */
+    ShapeExport&        WritePlaceholderReferenceTextBody(PlaceholderType ePlaceholder, PageType ePageType, const Reference<XPropertySet> xPagePropSet);
 
     // helper parts
     bool WritePlaceholder(const Reference< XShape >& xShape, PlaceholderType ePlaceholder, bool bMaster);
@@ -1452,6 +1461,8 @@ void PowerPointExport::WriteShapeTree(const FSHelperPtr& pFS, PageType ePageType
         }
     }
 
+    if ( ePageType == NORMAL || ePageType == LAYOUT )
+        WritePlaceholderReferenceShapes(aDML, ePageType);
     pFS->endElementNS(XML_p, XML_spTree);
 }
 
@@ -1517,13 +1528,146 @@ ShapeExport& PowerPointShapeExport::WritePlaceholderShape(const Reference< XShap
         WriteBlipFill(xProps, "Graphic");
     mpFS->endElementNS(XML_p, XML_spPr);
 
-    WriteTextBox(xShape, XML_p);
+    WriteTextBox(xShape, XML_p, bUsePlaceholderIndex);
+
+    mpFS->endElementNS(XML_p, XML_sp);
+
+    return *this;
+}
+
+ShapeExport& PowerPointShapeExport::WritePlaceholderReferenceShape(
+    PlaceholderType ePlaceholder, unsigned nReferencedPlaceholderIdx, PageType ePageType,
+    Reference<XPropertySet>& rXPagePropSet)
+{
+    mpFS->startElementNS(XML_p, XML_sp);
+
+    // non visual shape properties
+    mpFS->startElementNS(XML_p, XML_nvSpPr);
+    const OString aPlaceholderID("PlaceHolder " + OString::number(mnShapeIdMax++));
+    GetFS()->singleElementNS(XML_p, XML_cNvPr, XML_id, OString::number(mnShapeIdMax), XML_name,
+                             aPlaceholderID.getStr());
+
+    mpFS->startElementNS(XML_p, XML_cNvSpPr);
+    mpFS->singleElementNS(XML_a, XML_spLocks, XML_noGrp, "1");
+    mpFS->endElementNS(XML_p, XML_cNvSpPr);
+    mpFS->startElementNS(XML_p, XML_nvPr);
+
+    const char* pType = getPlaceholderTypeName(ePlaceholder);
+    mpFS->singleElementNS(XML_p, XML_ph, XML_type, pType, XML_idx,
+                          OString::number(nReferencedPlaceholderIdx));
+    mpFS->endElementNS(XML_p, XML_nvPr);
+    mpFS->endElementNS(XML_p, XML_nvSpPr);
+
+    // visual shape properties
+    mpFS->startElementNS(XML_p, XML_spPr);
+    mpFS->endElementNS(XML_p, XML_spPr);
+
+    WritePlaceholderReferenceTextBody(ePlaceholder, ePageType, rXPagePropSet);
 
     mpFS->endElementNS(XML_p, XML_sp);
 
     return *this;
 }
 
+ShapeExport& PowerPointShapeExport::WritePlaceholderReferenceTextBody(
+    PlaceholderType ePlaceholder, PageType ePageType, const Reference<XPropertySet> xPagePropSet)
+{
+    mpFS->startElementNS(XML_p, XML_txBody);
+    mpFS->singleElementNS(XML_a, XML_bodyPr);
+    mpFS->startElementNS(XML_a, XML_p);
+
+    switch (ePlaceholder)
+    {
+        case Header:
+            break;
+        case Footer:
+        {
+            OUString aFooterText;
+            if (ePageType == LAYOUT)
+            {
+                aFooterText = "Footer";
+            }
+            else
+            {
+                xPagePropSet->getPropertyValue("FooterText") >>= aFooterText;
+            }
+            mpFS->startElementNS(XML_a, XML_r);
+            mpFS->startElementNS(XML_a, XML_t);
+            mpFS->writeEscaped(aFooterText);
+            mpFS->endElementNS(XML_a, XML_t);
+            mpFS->endElementNS(XML_a, XML_r);
+            break;
+        }
+        case SlideNumber:
+        {
+            OUString aSlideNum;
+            sal_Int32 nSlideNum = 0;
+            if (ePageType == LAYOUT)
+            {
+                aSlideNum = "<#>";
+            }
+            else
+            {
+                xPagePropSet->getPropertyValue("Number") >>= nSlideNum;
+                aSlideNum = OUString::number(nSlideNum);
+            }
+            OString aUUID(comphelper::xml::generateGUIDString());
+            mpFS->startElementNS(XML_a, XML_fld, XML_id, aUUID.getStr(), XML_type, "slidenum");
+            mpFS->startElementNS(XML_a, XML_t);
+            mpFS->writeEscaped(aSlideNum);
+            mpFS->endElementNS(XML_a, XML_t);
+            mpFS->endElementNS(XML_a, XML_fld);
+            break;
+        }
+        case DateAndTime:
+        {
+            OUString aDateTimeType = "datetime1";
+            bool bIsDateTimeFixed;
+            xPagePropSet->getPropertyValue("IsDateTimeFixed") >>= bIsDateTimeFixed;
+
+            if(ePageType != LAYOUT && !bIsDateTimeFixed)
+            {
+                sal_Int32 nDateTimeFormat;
+                xPagePropSet->getPropertyValue("DateTimeFormat") >>= nDateTimeFormat;
+
+                // 4 LSBs represent the date
+                SvxDateFormat eDate = static_cast<SvxDateFormat>(nDateTimeFormat & 0x0f);
+                // the 4 bits after the date bits represent the time
+                SvxTimeFormat eTime = static_cast<SvxTimeFormat>(nDateTimeFormat >> 4);
+                aDateTimeType = GetDatetimeTypeFromDateTime(eDate, eTime);
+
+                if (aDateTimeType == "datetime")
+                    aDateTimeType = "datetime1";
+            }
+
+            if(!bIsDateTimeFixed)
+            {
+                OString aUUID(comphelper::xml::generateGUIDString());
+                mpFS->startElementNS(XML_a, XML_fld, XML_id, aUUID.getStr(), XML_type, aDateTimeType);
+                mpFS->endElementNS(XML_a, XML_fld);
+            }
+            else
+            {
+                OUString aDateTimeText;
+                xPagePropSet->getPropertyValue("DateTimeText") >>= aDateTimeText;
+                mpFS->startElementNS(XML_a, XML_r);
+                mpFS->startElementNS(XML_a, XML_t);
+                mpFS->writeEscaped(aDateTimeText);
+                mpFS->endElementNS(XML_a, XML_t);
+                mpFS->endElementNS(XML_a, XML_r);
+            }
+            break;
+        }
+        default:
+            SAL_INFO("sd.eppt", "warning: no defined textbody for referenced placeholder type: "
+                                    << ePlaceholder);
+    }
+    mpFS->endElementNS(XML_a, XML_p);
+    mpFS->endElementNS(XML_p, XML_txBody);
+
+    return *this;
+}
+
 #define SYS_COLOR_SCHEMES "      <a:dk1>\
         <a:sysClr val=\"windowText\" lastClr=\"000000\"/>\
       </a:dk1>\
@@ -2032,12 +2176,106 @@ void PowerPointExport::WriteDiagram(const FSHelperPtr& pFS, PowerPointShapeExpor
     pFS->endElementNS(XML_p, XML_graphicFrame);
 }
 
+void PowerPointExport::WritePlaceholderReferenceShapes(PowerPointShapeExport& rDML, PageType ePageType)
+{
+    bool bCheckProps = ePageType == NORMAL;
+    Reference<XShape> xShape;
+    Any aAny;
+    OUString aText;
+    if (ePageType == LAYOUT
+        || (bCheckProps && PropValue::GetPropertyValue(aAny, mXPagePropSet, "IsFooterVisible", true)
+            && aAny == true && GetPropertyValue(aAny, mXPagePropSet, "FooterText", true)
+            && (aAny >>= aText) && !aText.isEmpty()))
+    {
+        if ((xShape = GetReferencedPlaceholderXShape(Footer, ePageType)))
+            rDML.WritePlaceholderReferenceShape(Footer,
+                                                maPlaceholderShapeToIndexMap.find(xShape)->second,
+                                                ePageType, mXPagePropSet);
+    }
+
+    if (ePageType == LAYOUT
+        || (bCheckProps
+            && PropValue::GetPropertyValue(aAny, mXPagePropSet, "IsPageNumberVisible", true)
+            && aAny == true))
+    {
+        if ((xShape = GetReferencedPlaceholderXShape(SlideNumber, ePageType)))
+            rDML.WritePlaceholderReferenceShape(SlideNumber,
+                                                maPlaceholderShapeToIndexMap.find(xShape)->second,
+                                                ePageType, mXPagePropSet);
+    }
+
+    if (ePageType == LAYOUT
+        || (bCheckProps
+            && PropValue::GetPropertyValue(aAny, mXPagePropSet, "IsDateTimeVisible", true)
+            && aAny == true
+            && ((GetPropertyValue(aAny, mXPagePropSet, "DateTimeText", true) && (aAny >>= aText)
+                 && !aText.isEmpty())
+                || mXPagePropSet->getPropertyValue("IsDateTimeFixed") == false)))
+    {
+        if ((xShape = GetReferencedPlaceholderXShape(DateAndTime, ePageType)))
+            rDML.WritePlaceholderReferenceShape(DateAndTime,
+                                                maPlaceholderShapeToIndexMap.find(xShape)->second,
+                                                ePageType, mXPagePropSet);
+    }
+}
+
 unsigned PowerPointExport::CreateNewPlaceholderIndex(const css::uno::Reference<XShape> &rXShape)
 {
     maPlaceholderShapeToIndexMap.insert({rXShape, mnPlaceholderIndexMax});
     return mnPlaceholderIndexMax++;
 }
 
+Reference<XShape> PowerPointExport::GetReferencedPlaceholderXShape(const PlaceholderType eType,
+                                                        PageType ePageType) const
+{
+    PresObjKind ePresObjKind = PresObjKind::NONE;
+    switch (eType)
+    {
+        case oox::core::None:
+            break;
+        case oox::core::SlideImage:
+            break;
+        case oox::core::Notes:
+            break;
+        case oox::core::Header:
+            ePresObjKind = PresObjKind::Header;
+            break;
+        case oox::core::Footer:
+            ePresObjKind = PresObjKind::Footer;
+            break;
+        case oox::core::SlideNumber:
+            ePresObjKind = PresObjKind::SlideNumber;
+            break;
+        case oox::core::DateAndTime:
+            ePresObjKind = PresObjKind::DateTime;
+            break;
+        case oox::core::Outliner:
+            break;
+        case oox::core::Title:
+            ePresObjKind = PresObjKind::Title;
+            break;
+        case oox::core::Subtitle:
+            break;
+    }
+    if (ePresObjKind != PresObjKind::NONE)
+    {
+        SdPage* pMasterPage;
+        if (ePageType == LAYOUT)
+        {
+            // since Layout pages do not have drawpages themselves - mXDrawPage is still the master they reference to..
+            pMasterPage = SdPage::getImplementation(mXDrawPage);
+        }
+        else
+        {
+            pMasterPage
+                = &static_cast<SdPage&>(SdPage::getImplementation(mXDrawPage)->TRG_GetMasterPage());
+        }
+        if (SdrObject* pMasterFooter = pMasterPage->GetPresObj(ePresObjKind))
+            return GetXShapeForSdrObject(pMasterFooter);
+    }
+    return nullptr;
+}
+
 // UNO component
 extern "C" SAL_DLLPUBLIC_EXPORT uno::XInterface*
 css_comp_Impress_oox_PowerPointExport(uno::XComponentContext* rxCtxt,


More information about the Libreoffice-commits mailing list