File bsc1172054.diff of Package libreoffice

From 9dbabd8c6c0249f2da7f236384b3b226978af279 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?G=C3=BCl=C5=9Fah=20K=C3=B6se?= <gulsah.kose@collabora.com>
Date: Thu, 23 Jul 2020 13:45:51 +0300
Subject: [PATCH] bsc1172054.diff

Change-Id: Ie2f1b84e73e5b228039657da2f2d01bb6a2087eb
---
 include/oox/ppt/pptimport.hxx                 |  3 ++
 include/oox/ppt/pptshape.hxx                  |  3 +-
 include/oox/ppt/slidepersist.hxx              |  1 +
 oox/inc/drawingml/table/tableproperties.hxx   |  2 +-
 .../drawingml/table/tableproperties.cxx       | 26 ++++++++++----
 oox/source/ppt/pptimport.cxx                  |  1 +
 oox/source/ppt/pptshape.cxx                   | 18 ++++++++--
 oox/source/ppt/slidepersist.cxx               | 34 ++++++++++++++++++-
 8 files changed, 76 insertions(+), 12 deletions(-)

diff --git a/include/oox/ppt/pptimport.hxx b/include/oox/ppt/pptimport.hxx
index 2ea62da02c1b..c8b71f29297f 100644
--- a/include/oox/ppt/pptimport.hxx
+++ b/include/oox/ppt/pptimport.hxx
@@ -31,6 +31,7 @@
 #include <oox/drawingml/drawingmltypes.hxx>
 #include <oox/drawingml/theme.hxx>
 #include <oox/ppt/slidepersist.hxx>
+#include <oox/ppt/pptshape.hxx>
 #include <rtl/ustring.hxx>
 #include <sal/types.h>
 
@@ -76,6 +77,8 @@ public:
 
     ::Color getSchemeColor( sal_Int32 nToken ) const;
 
+    static std::vector< PPTShape* > maPPTShapes;
+
 #if OSL_DEBUG_LEVEL > 0
     static XmlFilterBase* mpDebugFilterBase;
 #endif
diff --git a/include/oox/ppt/pptshape.hxx b/include/oox/ppt/pptshape.hxx
index fac28f7616c3..c5d9e7be5548 100644
--- a/include/oox/ppt/pptshape.hxx
+++ b/include/oox/ppt/pptshape.hxx
@@ -66,7 +66,8 @@ public:
             const oox::drawingml::Theme* pTheme,
             const css::uno::Reference< css::drawing::XShapes >& rxShapes,
             basegfx::B2DHomMatrix& aTransformation,
-            ::oox::drawingml::ShapeIdMap* pShapeMap );
+            ::oox::drawingml::ShapeIdMap* pShapeMap,
+            bool bhasSameSubTypeIndex = false );
 
     ShapeLocation getShapeLocation() const { return meShapeLocation; };
     void setReferenced( bool bReferenced ){ mbReferenced = bReferenced; };
diff --git a/include/oox/ppt/slidepersist.hxx b/include/oox/ppt/slidepersist.hxx
index 8ef8515757bf..c291932fe5b7 100644
--- a/include/oox/ppt/slidepersist.hxx
+++ b/include/oox/ppt/slidepersist.hxx
@@ -67,6 +67,7 @@ public:
                     oox::drawingml::ShapePtr const & pShapesPtr, const ::oox::drawingml::TextListStylePtr & );
     ~SlidePersist();
 
+
     const css::uno::Reference< css::drawing::XDrawPage >& getPage() const { return mxPage; };
 
 #if OSL_DEBUG_LEVEL > 0
diff --git a/oox/inc/drawingml/table/tableproperties.hxx b/oox/inc/drawingml/table/tableproperties.hxx
index 010fc67df416..5434ce5a9e32 100644
--- a/oox/inc/drawingml/table/tableproperties.hxx
+++ b/oox/inc/drawingml/table/tableproperties.hxx
@@ -61,7 +61,7 @@ public:
         const ::oox::drawingml::TextListStylePtr& pMasterTextListStyle );
 
     /// Distributes text body with multiple columns in table cells.
-    void pullFromTextBody(oox::drawingml::TextBodyPtr pTextBody, sal_Int32 nShapeWidth);
+    void pullFromTextBody(oox::drawingml::TextBodyPtr pTextBody, sal_Int32 nShapeWidth, bool bhasSameSubTypeIndex, bool bMaster);
 
 private:
 
diff --git a/oox/source/drawingml/table/tableproperties.cxx b/oox/source/drawingml/table/tableproperties.cxx
index f867ee144003..9e7b8d8e7f30 100644
--- a/oox/source/drawingml/table/tableproperties.cxx
+++ b/oox/source/drawingml/table/tableproperties.cxx
@@ -151,7 +151,7 @@ void TableProperties::pushToPropSet(const ::oox::core::XmlFilterBase& rFilterBas
     for (auto& tableRow : mvTableRows)
     {
         sal_Int32 nColumn = 0;
-        sal_Int32 nColumnSize = tableRow.getTableCells().size();
+        sal_Int32 nColumnSize = mvTableGrid.size();
         sal_Int32 nRemovedColumn = 0; //
 
         for (sal_Int32 nColIndex = 0; nColIndex < nColumnSize; nColIndex++)
@@ -213,16 +213,25 @@ void TableProperties::pushToPropSet(const ::oox::core::XmlFilterBase& rFilterBas
     xTableStyleToDelete.reset();
 }
 
-void TableProperties::pullFromTextBody(oox::drawingml::TextBodyPtr pTextBody, sal_Int32 nShapeWidth)
+void TableProperties::pullFromTextBody(oox::drawingml::TextBodyPtr pTextBody, sal_Int32 nShapeWidth, bool bhasSameSubTypeIndex, bool bMaster)
 {
     // Create table grid and a single row.
     sal_Int32 nNumCol = pTextBody->getTextProperties().mnNumCol;
     std::vector<sal_Int32>& rTableGrid(getTableGrid());
-    sal_Int32 nColWidth = nShapeWidth / nNumCol;
-    for (sal_Int32 nCol = 0; nCol < nNumCol; ++nCol)
-        rTableGrid.push_back(nColWidth);
     std::vector<drawingml::table::TableRow>& rTableRows(getTableRows());
-    rTableRows.emplace_back();
+    sal_Int32 nColWidth = nShapeWidth / nNumCol;
+
+    if(!bhasSameSubTypeIndex)
+    {
+        for (sal_Int32 nCol = 0; nCol < nNumCol; ++nCol)
+            rTableGrid.push_back(nColWidth);
+
+        rTableRows.emplace_back();
+    }
+
+    if(rTableRows.empty())
+        rTableRows.emplace_back();
+
     oox::drawingml::table::TableRow& rTableRow = rTableRows.back();
     std::vector<oox::drawingml::table::TableCell>& rTableCells = rTableRow.getTableCells();
 
@@ -235,13 +244,16 @@ void TableProperties::pullFromTextBody(oox::drawingml::TextBodyPtr pTextBody, sa
     for (sal_Int32 nCol = 0; nCol < nNumCol; ++nCol)
     {
         rTableCells.emplace_back();
-        oox::drawingml::table::TableCell& rTableCell = rTableCells.back();
+        oox::drawingml::table::TableCell& rTableCell = rTableCells.at(nCol);
         TextBodyPtr pCellTextBody(new TextBody);
         rTableCell.setTextBody(pCellTextBody);
 
         // Copy properties provided by <a:lstStyle>.
         pCellTextBody->getTextListStyle() = pTextBody->getTextListStyle();
 
+        if (bMaster)
+            continue;
+
         for (sal_Int32 nParaInCol = 0; nParaInCol < nParaPerCol; ++nParaInCol)
         {
             if (nPara < pTextBody->getParagraphs().size())
diff --git a/oox/source/ppt/pptimport.cxx b/oox/source/ppt/pptimport.cxx
index 01f572a54dcf..99c528071226 100644
--- a/oox/source/ppt/pptimport.cxx
+++ b/oox/source/ppt/pptimport.cxx
@@ -70,6 +70,7 @@ PowerPointImport::PowerPointImport( const Reference< XComponentContext >& rxCont
 
 PowerPointImport::~PowerPointImport()
 {
+    maPPTShapes.clear();
 }
 
 /// Visits the relations from pRelations which are of type rType.
diff --git a/oox/source/ppt/pptshape.cxx b/oox/source/ppt/pptshape.cxx
index af7324485c65..88277219d0b0 100644
--- a/oox/source/ppt/pptshape.cxx
+++ b/oox/source/ppt/pptshape.cxx
@@ -116,7 +116,8 @@ void PPTShape::addShape(
         const oox::drawingml::Theme* pTheme,
         const Reference< XShapes >& rxShapes,
         basegfx::B2DHomMatrix& aTransformation,
-        ::oox::drawingml::ShapeIdMap* pShapeMap )
+        ::oox::drawingml::ShapeIdMap* pShapeMap,
+        bool bhasSameSubTypeIndex )
 {
     SAL_INFO("oox.ppt","add shape id: " << msId << " location: " << ((meShapeLocation == Master) ? "master" : ((meShapeLocation == Slide) ? "slide" : ((meShapeLocation == Layout) ? "layout" : "other"))) << " subtype: " << mnSubType << " service: " << msServiceName);
     // only placeholder from layout are being inserted
@@ -230,6 +231,19 @@ void PPTShape::addShape(
         {
             if (TextBodyPtr pTextBody = getTextBody())
             {
+                // If slide shape has not numCol but placeholder has we should inherit from placeholder.
+                if (pTextBody->getTextProperties().mnNumCol == 1 &&
+                    mnSubType &&
+                    getSubTypeIndex().has() &&
+                    rSlidePersist.getMasterPersist())
+                {
+                    oox::drawingml::ShapePtr pPlaceholder = PPTShape::findPlaceholderByIndex(
+                                                                            getSubTypeIndex().get(),
+                                                                            rSlidePersist.getMasterPersist()->getShapes()->getChildren());
+                    if (pPlaceholder && pPlaceholder->getTableProperties())
+                        pTextBody->getTextProperties().mnNumCol = pPlaceholder->getTableProperties()->getTableGrid().size();
+                }
+
                 sal_Int32 nNumCol = pTextBody->getTextProperties().mnNumCol;
                 if (nNumCol > 1)
                 {
@@ -237,7 +251,7 @@ void PPTShape::addShape(
                     // represent that as a table.
                     sServiceName = "com.sun.star.drawing.TableShape";
                     oox::drawingml::table::TablePropertiesPtr pTableProperties = getTableProperties();
-                    pTableProperties->pullFromTextBody(pTextBody, maSize.Width);
+                    pTableProperties->pullFromTextBody(pTextBody, maSize.Width, bhasSameSubTypeIndex, meShapeLocation == Layout);
                     setTextBody(nullptr);
                 }
             }
diff --git a/oox/source/ppt/slidepersist.cxx b/oox/source/ppt/slidepersist.cxx
index 247831677dfd..f46dd1b498d0 100644
--- a/oox/source/ppt/slidepersist.cxx
+++ b/oox/source/ppt/slidepersist.cxx
@@ -21,6 +21,7 @@
 #include <com/sun/star/drawing/XShapes.hpp>
 #include <oox/ppt/timenode.hxx>
 #include <oox/ppt/pptshape.hxx>
+#include <oox/ppt/pptimport.hxx>
 #include <oox/ppt/slidepersist.hxx>
 #include <drawingml/fillproperties.hxx>
 #include <oox/drawingml/shapepropertymap.hxx>
@@ -32,6 +33,7 @@
 #include <oox/core/xmlfilterbase.hxx>
 #include <drawingml/textliststyle.hxx>
 #include <drawingml/textparagraphproperties.hxx>
+#include <drawingml/textbody.hxx>
 
 #include <osl/diagnose.h>
 
@@ -50,6 +52,8 @@ using namespace ::com::sun::star::animations;
 
 namespace oox { namespace ppt {
 
+std::vector< PPTShape* > PowerPointImport::maPPTShapes;
+
 SlidePersist::SlidePersist( XmlFilterBase& rFilter, bool bMaster, bool bNotes,
     const css::uno::Reference< css::drawing::XDrawPage >& rxPage,
         oox::drawingml::ShapePtr const & pShapesPtr, const drawingml::TextListStylePtr & pDefaultTextStyle )
@@ -126,6 +130,21 @@ sal_Int16 SlidePersist::getLayoutFromValueToken() const
     return nLayout;
 }
 
+static bool hasSameSubTypeIndex(sal_Int32 checkSubTypeIndex)
+{
+    sal_Int32 nSubTypeIndex = -1;
+    for(PPTShape* pPPTShape : PowerPointImport::maPPTShapes)
+    {
+        if(!pPPTShape->getSubTypeIndex().has())
+            continue;
+
+        nSubTypeIndex = pPPTShape->getSubTypeIndex().get();
+
+        if( nSubTypeIndex == checkSubTypeIndex )
+            return true;
+    }
+    return false;
+}
 void SlidePersist::createXShapes( XmlFilterBase& rFilterBase )
 {
     applyTextStyles( rFilterBase );
@@ -133,6 +152,9 @@ void SlidePersist::createXShapes( XmlFilterBase& rFilterBase )
     Reference< XShapes > xShapes( getPage(), UNO_QUERY );
 
     std::vector< oox::drawingml::ShapePtr >& rShapes( maShapesPtr->getChildren() );
+    bool bhasSameSubTypeIndex = false;
+    sal_Int32 nNumCol = 1;
+
     for (auto const& shape : rShapes)
     {
         std::vector< oox::drawingml::ShapePtr >& rChildren( shape->getChildren() );
@@ -141,7 +163,17 @@ void SlidePersist::createXShapes( XmlFilterBase& rFilterBase )
             PPTShape* pPPTShape = dynamic_cast< PPTShape* >( child.get() );
             basegfx::B2DHomMatrix aTransformation;
             if ( pPPTShape )
-                pPPTShape->addShape( rFilterBase, *this, getTheme().get(), xShapes, aTransformation, &getShapeMap() );
+            {
+                bhasSameSubTypeIndex = hasSameSubTypeIndex( pPPTShape->getSubTypeIndex().get());
+
+                if(pPPTShape->getTextBody())
+                    nNumCol = pPPTShape->getTextBody()->getTextProperties().mnNumCol;
+
+                if(pPPTShape->getSubTypeIndex().has() && nNumCol > 1 )
+                    PowerPointImport::maPPTShapes.push_back(pPPTShape);
+
+                pPPTShape->addShape( rFilterBase, *this, getTheme().get(), xShapes, aTransformation, &getShapeMap(), bhasSameSubTypeIndex );
+            }
             else
                 child->addShape( rFilterBase, getTheme().get(), xShapes, aTransformation, maShapesPtr->getFillProperties(), &getShapeMap() );
         }
-- 
2.26.2

openSUSE Build Service is sponsored by