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@collabora.com>
Signed-off-by: Xisco Fauli <xiscofauli@libreoffice.org>
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/101747
diff --git a/include/oox/ppt/pptimport.hxx b/include/oox/ppt/pptimport.hxx
index 28ae6df..e96f04b 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 f452e58..e67a776 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 3dd9d65..c09e5f0 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 67a08f4..dcdf41b 100644
--- a/oox/inc/drawingml/table/tableproperties.hxx
+++ b/oox/inc/drawingml/table/tableproperties.hxx
@@ -59,7 +59,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 1c59b4e..1ecea13 100644
--- a/oox/source/drawingml/table/tableproperties.cxx
+++ b/oox/source/drawingml/table/tableproperties.cxx
@@ -207,16 +207,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();
@@ -229,7 +238,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 = std::make_shared<TextBody>();
rTableCell.setTextBody(pCellTextBody);
diff --git a/oox/source/ppt/pptimport.cxx b/oox/source/ppt/pptimport.cxx
index dea04a9..f7d0092 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 edf527b..53e429d 100644
--- a/oox/source/ppt/pptshape.cxx
+++ b/oox/source/ppt/pptshape.cxx
@@ -114,7 +114,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
@@ -235,7 +236,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 6f4be01..dc18ec0 100644
--- a/oox/source/ppt/slidepersist.cxx
+++ b/oox/source/ppt/slidepersist.cxx
@@ -23,6 +23,7 @@
#include <com/sun/star/frame/XModel.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>
@@ -34,6 +35,7 @@
#include <oox/core/xmlfilterbase.hxx>
#include <drawingml/textliststyle.hxx>
#include <drawingml/textparagraphproperties.hxx>
#include <drawingml/textbody.hxx>
#include <osl/diagnose.h>
@@ -49,8 +51,11 @@ using namespace ::com::sun::star::drawing;
using namespace ::com::sun::star::container;
using namespace ::com::sun::star::animations;
namespace oox::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 )
@@ -127,13 +132,30 @@ 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 );
Reference< XShapes > xShapes( getPage() );
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() );
@@ -142,7 +164,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() );
}