[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-6.4' - include/oox oox/inc oox/source

Gülşah Köse (via logerrit) logerrit at kemper.freedesktop.org
Sun Aug 16 21:42:58 UTC 2020


 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 -
 oox/source/drawingml/table/tableproperties.cxx |   21 +++++++++++----
 oox/source/ppt/pptimport.cxx                   |    1 
 oox/source/ppt/pptshape.cxx                    |    5 ++-
 oox/source/ppt/slidepersist.cxx                |   34 ++++++++++++++++++++++++-
 8 files changed, 59 insertions(+), 11 deletions(-)

New commits:
commit d8db387729092f5010d50ece4406a48517cd7917
Author:     Gülşah Köse <gulsah.kose at collabora.com>
AuthorDate: Thu Jul 23 13:45:51 2020 +0300
Commit:     Gülşah Köse <gulsah.kose at collabora.com>
CommitDate: Sun Aug 16 23:42:26 2020 +0200

    tdf#133015 Fix duplicated row and column problem.
    
    LibreOffice imports multicolumn texboxes as tables. When
    document has numCols=2 (or more) attribute at slidelayout and slide,
    the table rows and columns duplicates.
    
    maPPTShapes vector holds our PPTShape objects, hasSameSubTypeIndex
    function finds the status that I mention above. So that we can prevent
    that duplication.
    
    Change-Id: Iee03d130452a16e9b46d471a9b6ed5910e6351ab
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/99279
    Tested-by: Jenkins
    Reviewed-by: Gülşah Köse <gulsah.kose at collabora.com>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/100826
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice at gmail.com>

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..40a0cc8efe0b 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);
 
 private:
 
diff --git a/oox/source/drawingml/table/tableproperties.cxx b/oox/source/drawingml/table/tableproperties.cxx
index f867ee144003..3b1bbfb6514b 100644
--- a/oox/source/drawingml/table/tableproperties.cxx
+++ b/oox/source/drawingml/table/tableproperties.cxx
@@ -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)
 {
     // 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,7 +244,7 @@ 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);
 
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..e8182142c459 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
@@ -237,7 +238,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);
                     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() );
         }


More information about the Libreoffice-commits mailing list