diff options
author | Gülşah Köse <gulsah.kose@collabora.com> | 2020-07-23 13:45:51 +0300 |
---|---|---|
committer | Gülşah Köse <gulsah.kose@collabora.com> | 2020-07-24 09:47:05 +0200 |
commit | c50ae6a282ed83762bf634fed5c91033eb305c88 (patch) | |
tree | 69901fbdb22ff1248673e73ceb6e4e31fe51d4ea /oox/source | |
parent | 785312dc11a78f72784c04a2e8e3183162a1e28b (diff) |
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>
Diffstat (limited to 'oox/source')
-rw-r--r-- | oox/source/drawingml/table/tableproperties.cxx | 21 | ||||
-rw-r--r-- | oox/source/ppt/pptimport.cxx | 1 | ||||
-rw-r--r-- | oox/source/ppt/pptshape.cxx | 5 | ||||
-rw-r--r-- | oox/source/ppt/slidepersist.cxx | 36 |
4 files changed, 53 insertions, 10 deletions
diff --git a/oox/source/drawingml/table/tableproperties.cxx b/oox/source/drawingml/table/tableproperties.cxx index 1c59b4ef47f2..1ecea1363659 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 dea04a98e9a3..f7d00920705e 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 b28c9d07b223..d4d251d2ceb0 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 6f4be017c605..dc18ec06e128 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() ); } |