[Libreoffice-commits] core.git: oox/source sd/qa

Tibor Nagy (via logerrit) logerrit at kemper.freedesktop.org
Tue Sep 14 13:24:03 UTC 2021


 oox/source/ppt/pptshape.cxx         |   80 ++++++++++++++++++++++++++++++++++++
 sd/qa/unit/data/pptx/tdf141704.pptx |binary
 sd/qa/unit/import-tests.cxx         |   59 ++++++++++++++++++++++++++
 3 files changed, 139 insertions(+)

New commits:
commit 9bb91441b46d677860530d8bf9597c96561a1b0a
Author:     Tibor Nagy <nagy.tibor2 at nisz.hu>
AuthorDate: Tue Aug 31 13:15:01 2021 +0200
Commit:     László Németh <nemeth at numbertext.org>
CommitDate: Tue Sep 14 15:23:27 2021 +0200

    tdf#141704 PPTX import: fix hyperlinks on images
    
    Hyperlinks on images pointing to the "first/last/
    previous/next" slides and "exit presentation/go to
    the website/go to the slide" weren't imported.
    
    Note: images added via the Content placeholder
    will be fixed later.
    
    Change-Id: Idda1ff6fd3243b06262637c7c8e579e78309e317
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/121369
    Tested-by: László Németh <nemeth at numbertext.org>
    Reviewed-by: László Németh <nemeth at numbertext.org>

diff --git a/oox/source/ppt/pptshape.cxx b/oox/source/ppt/pptshape.cxx
index 80f165d6f085..757aab1bb3e0 100644
--- a/oox/source/ppt/pptshape.cxx
+++ b/oox/source/ppt/pptshape.cxx
@@ -34,10 +34,14 @@
 #include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
 #include <com/sun/star/drawing/XShapes.hpp>
 #include <com/sun/star/text/XText.hpp>
+#include <com/sun/star/document/XEventsSupplier.hpp>
+#include <com/sun/star/container/XNameReplace.hpp>
+#include <com/sun/star/presentation/ClickAction.hpp>
 #include <basegfx/matrix/b2dhommatrix.hxx>
 #include <sal/log.hxx>
 #include <oox/ppt/slidepersist.hxx>
 #include <oox/token/tokens.hxx>
+#include <oox/token/properties.hxx>
 
 using namespace ::oox::core;
 using namespace ::oox::drawingml;
@@ -47,6 +51,9 @@ using namespace ::com::sun::star::uno;
 using namespace ::com::sun::star::beans;
 using namespace ::com::sun::star::text;
 using namespace ::com::sun::star::drawing;
+using namespace ::com::sun::star::document;
+using namespace ::com::sun::star::container;
+using namespace ::com::sun::star::presentation;
 
 namespace oox::ppt {
 
@@ -531,6 +538,79 @@ void PPTShape::addShape(
                 keepDiagramCompatibilityInfo();
                 syncDiagramFontHeights();
             }
+
+            if (getShapeProperties().hasProperty(PROP_URL))
+            {
+                Reference<XEventsSupplier> xEventsSupplier(xShape, UNO_QUERY);
+                if (!xEventsSupplier.is())
+                    return;
+
+                Reference<XNameReplace> xEvents(xEventsSupplier->getEvents());
+                if (!xEvents.is())
+                    return;
+
+                OUString sURL;
+                OUString sAPIEventName;
+                sal_Int32 nPropertyCount = 2;
+                css::presentation::ClickAction meClickAction;
+                uno::Sequence<beans::PropertyValue> aProperties;
+
+                std::map<OUString, css::presentation::ClickAction> ActionMap = {
+                    { "#action?jump=nextslide", ClickAction_NEXTPAGE },
+                    { "#action?jump=previousslide", ClickAction_PREVPAGE },
+                    { "#action?jump=firstslide", ClickAction_FIRSTPAGE },
+                    { "#action?jump=lastslide", ClickAction_LASTPAGE },
+                    { "#action?jump=endshow", ClickAction_STOPPRESENTATION },
+                };
+
+                getShapeProperties().getProperty(PROP_URL) >>= sURL;
+                std::map<OUString, css::presentation::ClickAction>::const_iterator aIt
+                    = ActionMap.find(sURL);
+                aIt != ActionMap.end() ? meClickAction = aIt->second
+                                       : meClickAction = ClickAction_BOOKMARK;
+
+                // ClickAction_BOOKMARK and ClickAction_DOCUMENT share the same event
+                // so check here if it's a bookmark or a document
+                if (meClickAction == ClickAction_BOOKMARK)
+                {
+                    if (!sURL.startsWith("#"))
+                        meClickAction = ClickAction_DOCUMENT;
+                    else
+                        sURL = sURL.copy(1);
+                    nPropertyCount += 1;
+                }
+
+                aProperties.realloc(nPropertyCount);
+                beans::PropertyValue* pProperties = aProperties.getArray();
+
+                pProperties->Name = "EventType";
+                pProperties->Handle = -1;
+                pProperties->Value <<= OUString("Presentation");
+                pProperties->State = beans::PropertyState_DIRECT_VALUE;
+                pProperties++;
+
+                pProperties->Name = "ClickAction";
+                pProperties->Handle = -1;
+                pProperties->Value <<= meClickAction;
+                pProperties->State = beans::PropertyState_DIRECT_VALUE;
+                pProperties++;
+
+                switch (meClickAction)
+                {
+                    case ClickAction_BOOKMARK:
+                    case ClickAction_DOCUMENT:
+                        pProperties->Name = "Bookmark";
+                        pProperties->Handle = -1;
+                        pProperties->Value <<= sURL;
+                        pProperties->State = beans::PropertyState_DIRECT_VALUE;
+                        break;
+                    default:
+                        break;
+                }
+
+                sAPIEventName = "OnClick";
+                xEvents->replaceByName(sAPIEventName, uno::Any(aProperties));
+            }
         }
     }
     catch (const Exception&)
diff --git a/sd/qa/unit/data/pptx/tdf141704.pptx b/sd/qa/unit/data/pptx/tdf141704.pptx
new file mode 100644
index 000000000000..2aef7c3f9e93
Binary files /dev/null and b/sd/qa/unit/data/pptx/tdf141704.pptx differ
diff --git a/sd/qa/unit/import-tests.cxx b/sd/qa/unit/import-tests.cxx
index 482520908849..7bad28a80c86 100644
--- a/sd/qa/unit/import-tests.cxx
+++ b/sd/qa/unit/import-tests.cxx
@@ -123,6 +123,7 @@ public:
 
     void testDocumentLayout();
     void testTdf142645();
+    void testTdf141704();
     void testTdf142915();
     void testTdf142913();
     void testTdf142590();
@@ -246,6 +247,7 @@ public:
 
     CPPUNIT_TEST(testDocumentLayout);
     CPPUNIT_TEST(testTdf142645);
+    CPPUNIT_TEST(testTdf141704);
     CPPUNIT_TEST(testTdf142915);
     CPPUNIT_TEST(testTdf142913);
     CPPUNIT_TEST(testTdf142590);
@@ -458,6 +460,63 @@ void SdImportTest::testTdf142645()
     xDocShRef->DoClose();
 }
 
+void SdImportTest::testTdf141704()
+{
+    sd::DrawDocShellRef xDocShRef
+        = loadURL(m_directories.getURLFromSrc(u"sd/qa/unit/data/pptx/tdf141704.pptx"), PPTX);
+
+    for (sal_Int32 i = 0; i < 7; i++)
+    {
+        uno::Reference<beans::XPropertySet> xShape(getShapeFromPage(1, i, xDocShRef));
+        uno::Reference<document::XEventsSupplier> xEventsSupplier(xShape, uno::UNO_QUERY);
+        uno::Reference<container::XNameAccess> xEvents(xEventsSupplier->getEvents());
+
+        uno::Sequence<beans::PropertyValue> props;
+        xEvents->getByName("OnClick") >>= props;
+        comphelper::SequenceAsHashMap map(props);
+        auto iter(map.find("ClickAction"));
+        switch (i)
+        {
+            case 0:
+                CPPUNIT_ASSERT_EQUAL(css::presentation::ClickAction_LASTPAGE,
+                                     iter->second.get<css::presentation::ClickAction>());
+                break;
+            case 1:
+                CPPUNIT_ASSERT_EQUAL(css::presentation::ClickAction_NEXTPAGE,
+                                     iter->second.get<css::presentation::ClickAction>());
+                break;
+            case 2:
+                CPPUNIT_ASSERT_EQUAL(css::presentation::ClickAction_PREVPAGE,
+                                     iter->second.get<css::presentation::ClickAction>());
+                break;
+            case 3:
+            {
+                auto iter1(map.find("Bookmark"));
+                CPPUNIT_ASSERT_EQUAL(OUString("http://www.example.com/"), iter1->second.get<OUString>());
+            }
+            break;
+            case 4:
+            {
+                auto iter2(map.find("Bookmark"));
+                CPPUNIT_ASSERT_EQUAL(OUString("End Show"), iter2->second.get<OUString>());
+            }
+            break;
+            case 5:
+                CPPUNIT_ASSERT_EQUAL(css::presentation::ClickAction_STOPPRESENTATION,
+                                     iter->second.get<css::presentation::ClickAction>());
+                break;
+            case 6:
+                CPPUNIT_ASSERT_EQUAL(css::presentation::ClickAction_FIRSTPAGE,
+                                     iter->second.get<css::presentation::ClickAction>());
+                break;
+            default:
+                break;
+        }
+    }
+
+    xDocShRef->DoClose();
+}
+
 void SdImportTest::testTdf142915()
 {
     ::sd::DrawDocShellRef xDocShRef


More information about the Libreoffice-commits mailing list