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

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Thu Oct 18 15:52:13 UTC 2018


 oox/inc/drawingml/diagram/diagram.hxx               |    3 
 oox/source/drawingml/diagram/diagram.cxx            |   67 +++++++++++++++++++-
 oox/source/drawingml/graphicshapecontext.cxx        |    3 
 oox/source/ppt/dgmimport.cxx                        |    4 -
 sd/qa/unit/data/pptx/smartart-vertial-box-list.pptx |binary
 sd/qa/unit/import-tests-smartart.cxx                |   15 ++++
 6 files changed, 86 insertions(+), 6 deletions(-)

New commits:
commit a7e86beb00e9635ea4556ef4f8f8e24ff9965391
Author:     Miklos Vajna <vmiklos at collabora.co.uk>
AuthorDate: Thu Oct 18 14:43:23 2018 +0200
Commit:     Miklos Vajna <vmiklos at collabora.co.uk>
CommitDate: Thu Oct 18 17:51:00 2018 +0200

    oox: ignore SmartArt "fallback" with empty shape list
    
    This way at least something shows up in the import result. Far from
    perfect, though.
    
    Change-Id: Iae5a073d458598e7b5059ebdf435d50ce7c7df80
    Reviewed-on: https://gerrit.libreoffice.org/61925
    Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>
    Tested-by: Jenkins

diff --git a/oox/inc/drawingml/diagram/diagram.hxx b/oox/inc/drawingml/diagram/diagram.hxx
index 5277d98d2dee..a528668c08b4 100644
--- a/oox/inc/drawingml/diagram/diagram.hxx
+++ b/oox/inc/drawingml/diagram/diagram.hxx
@@ -39,7 +39,8 @@ void loadDiagram( ShapePtr const & pShape,
                   const OUString& rDataModelPath,
                   const OUString& rLayoutPath,
                   const OUString& rQStylePath,
-                  const OUString& rColorStylePath );
+                  const OUString& rColorStylePath,
+                  const oox::core::Relations& rRelations );
 
 void loadDiagram( const ShapePtr& pShape,
                   core::XmlFilterBase& rFilter,
diff --git a/oox/source/drawingml/diagram/diagram.cxx b/oox/source/drawingml/diagram/diagram.cxx
index 901995bc2039..edbb6b4ebf59 100644
--- a/oox/source/drawingml/diagram/diagram.cxx
+++ b/oox/source/drawingml/diagram/diagram.cxx
@@ -31,6 +31,7 @@
 #include <drawingml/fillproperties.hxx>
 #include <oox/ppt/pptshapegroupcontext.hxx>
 #include <oox/ppt/pptshape.hxx>
+#include <oox/token/namespaces.hxx>
 
 #include "diagramlayoutatoms.hxx"
 #include "layoutatomvisitors.hxx"
@@ -376,12 +377,57 @@ static void importFragment( core::XmlFilterBase& rFilter,
     rFilter.importFragment( rxHandler, xSerializer );
 }
 
+namespace
+{
+/**
+ * A fragment handler that just counts the number of <dsp:sp> elements in a
+ * fragment.
+ */
+class DiagramShapeCounter : public oox::core::FragmentHandler2
+{
+public:
+    DiagramShapeCounter(oox::core::XmlFilterBase& rFilter, const OUString& rFragmentPath,
+                        sal_Int32& nCounter);
+    oox::core::ContextHandlerRef onCreateContext(sal_Int32 nElement,
+                                                 const AttributeList& rAttribs) override;
+
+private:
+    sal_Int32& m_nCounter;
+};
+
+DiagramShapeCounter::DiagramShapeCounter(oox::core::XmlFilterBase& rFilter,
+                                         const OUString& rFragmentPath, sal_Int32& nCounter)
+    : FragmentHandler2(rFilter, rFragmentPath)
+    , m_nCounter(nCounter)
+{
+}
+
+oox::core::ContextHandlerRef DiagramShapeCounter::onCreateContext(sal_Int32 nElement,
+                                                                  const AttributeList& /*rAttribs*/)
+{
+    switch (nElement)
+    {
+        case DSP_TOKEN(drawing):
+        case DSP_TOKEN(spTree):
+            return this;
+        case DSP_TOKEN(sp):
+            ++m_nCounter;
+            break;
+        default:
+            break;
+    }
+
+    return nullptr;
+}
+}
+
 void loadDiagram( ShapePtr const & pShape,
                   core::XmlFilterBase& rFilter,
                   const OUString& rDataModelPath,
                   const OUString& rLayoutPath,
                   const OUString& rQStylePath,
-                  const OUString& rColorStylePath )
+                  const OUString& rColorStylePath,
+                  const oox::core::Relations& rRelations )
 {
     DiagramPtr pDiagram( new Diagram );
 
@@ -408,11 +454,26 @@ void loadDiagram( ShapePtr const & pShape,
 
         // Pass the info to pShape
         for (auto const& extDrawing : pData->getExtDrawings())
-                pShape->addExtDrawingRelId(extDrawing);
+        {
+            OUString aFragmentPath = rRelations.getFragmentPathFromRelId(extDrawing);
+            // Ignore RelIds which don't resolve to a fragment path.
+            if (aFragmentPath.isEmpty())
+                continue;
+
+            sal_Int32 nCounter = 0;
+            rtl::Reference<core::FragmentHandler> xCounter(
+                new DiagramShapeCounter(rFilter, aFragmentPath, nCounter));
+            rFilter.importFragment(xCounter);
+            // Ignore ext drawings which don't actually have any shapes.
+            if (nCounter == 0)
+                continue;
+
+            pShape->addExtDrawingRelId(extDrawing);
+        }
     }
 
     // extLst is present, lets bet on that and ignore the rest of the data from here
-    if( pData->getExtDrawings().empty() )
+    if( pShape->getExtDrawings().empty() )
     {
         // layout
         if( !rLayoutPath.isEmpty() )
diff --git a/oox/source/drawingml/graphicshapecontext.cxx b/oox/source/drawingml/graphicshapecontext.cxx
index 9047b0beebd1..01b14237e9c9 100644
--- a/oox/source/drawingml/graphicshapecontext.cxx
+++ b/oox/source/drawingml/graphicshapecontext.cxx
@@ -263,7 +263,8 @@ ContextHandlerRef DiagramGraphicDataContext::onCreateContext( ::sal_Int32 aEleme
                     getFragmentPathFromRelId( msDm ),
                     getFragmentPathFromRelId( msLo ),
                     getFragmentPathFromRelId( msQs ),
-                    getFragmentPathFromRelId( msCs ));
+                    getFragmentPathFromRelId( msCs ),
+                    getRelations());
         SAL_INFO("oox.drawingml", "DiagramGraphicDataContext::onCreateContext: added shape " << mpShapePtr->getName()
                  << " of type " << mpShapePtr->getServiceName()
                  << ", position: " << mpShapePtr->getPosition().X
diff --git a/oox/source/ppt/dgmimport.cxx b/oox/source/ppt/dgmimport.cxx
index 04e6e0a90788..2a06c4b66011 100644
--- a/oox/source/ppt/dgmimport.cxx
+++ b/oox/source/ppt/dgmimport.cxx
@@ -49,6 +49,7 @@ bool QuickDiagrammingImport::importDocument()
 
     Reference<drawing::XShapes> xParentShape(getParentShape(),
                                              UNO_QUERY_THROW);
+    oox::core::Relations aRelations("");
     oox::drawingml::ShapePtr pShape(
         new oox::drawingml::Shape( "com.sun.star.drawing.DiagramShape" ) );
     drawingml::loadDiagram(pShape,
@@ -56,7 +57,8 @@ bool QuickDiagrammingImport::importDocument()
                            "",
                            aFragmentPath,
                            "",
-                           "");
+                           "",
+                           aRelations);
     oox::drawingml::ThemePtr pTheme(
         new oox::drawingml::Theme());
     basegfx::B2DHomMatrix aMatrix;
diff --git a/sd/qa/unit/data/pptx/smartart-vertial-box-list.pptx b/sd/qa/unit/data/pptx/smartart-vertial-box-list.pptx
new file mode 100644
index 000000000000..b67d99e700c3
Binary files /dev/null and b/sd/qa/unit/data/pptx/smartart-vertial-box-list.pptx differ
diff --git a/sd/qa/unit/import-tests-smartart.cxx b/sd/qa/unit/import-tests-smartart.cxx
index e4960ada1121..1c2ef31f2958 100644
--- a/sd/qa/unit/import-tests-smartart.cxx
+++ b/sd/qa/unit/import-tests-smartart.cxx
@@ -40,6 +40,7 @@ public:
     void testEquation();
     void testSegmentedCycle();
     void testBaseRtoL();
+    void testVertialBoxList();
 
     CPPUNIT_TEST_SUITE(SdImportTestSmartArt);
 
@@ -64,6 +65,7 @@ public:
     CPPUNIT_TEST(testEquation);
     CPPUNIT_TEST(testSegmentedCycle);
     CPPUNIT_TEST(testBaseRtoL);
+    CPPUNIT_TEST(testVertialBoxList);
 
     CPPUNIT_TEST_SUITE_END();
 };
@@ -359,6 +361,19 @@ void SdImportTestSmartArt::testBaseRtoL()
     xDocShRef->DoClose();
 }
 
+void SdImportTestSmartArt::testVertialBoxList()
+{
+    sd::DrawDocShellRef xDocShRef = loadURL(
+        m_directories.getURLFromSrc("/sd/qa/unit/data/pptx/smartart-vertial-box-list.pptx"), PPTX);
+    uno::Reference<drawing::XShapes> xShapeGroup(getShapeFromPage(0, 0, xDocShRef),
+                                                 uno::UNO_QUERY_THROW);
+    // Without the accompanying fix in place, this test would have failed with
+    // 'actual: 0'.
+    CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(2), xShapeGroup->getCount());
+
+    xDocShRef->DoClose();
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(SdImportTestSmartArt);
 
 CPPUNIT_PLUGIN_IMPLEMENT();


More information about the Libreoffice-commits mailing list