diff options
author | Sarper Akdemir <sarper.akdemir@collabora.com> | 2022-08-17 16:23:29 +0300 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2022-08-31 08:05:21 +0200 |
commit | a5126a21351c87138ff86a6636326eb6cd6a0f8c (patch) | |
tree | eb211306f04e98f041aab3d26ef790b56596211a /oox | |
parent | 4f738840d804a03c44fc9f468f3470688a43f926 (diff) |
tdf#144092 pptx import: correct table height during import
It appears PowerPoint can export rows of a table with row heights that
is less than the minimum height (for that row). And also export the
total table height wrong with it.
If PowerPoint imports such a table, those rows are individually
expanded to the minimum height. (Also increasing the table's total
height)
In Impress import we calculate table height by adding up individual
row heights. Table layouting code depends on the table height being
correct. This is why rows with less than minimum height lead to
layouting problems.
To compensate for this, while importing tables, layouting is skipped
until the table height is updated with the corrected height.
The correct height is calculated by layouting the table without
fitting to an area (i.e with bFit = false).
Change-Id: I79187882470a4e285b45bca1eabb469a084067f5
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/138652
Tested-by: Jenkins
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Diffstat (limited to 'oox')
-rw-r--r-- | oox/source/drawingml/shape.cxx | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/oox/source/drawingml/shape.cxx b/oox/source/drawingml/shape.cxx index 3e81a1b95a27..1e7a702b25e6 100644 --- a/oox/source/drawingml/shape.cxx +++ b/oox/source/drawingml/shape.cxx @@ -94,6 +94,7 @@ #include <com/sun/star/chart2/data/XDataReceiver.hpp> #include <com/sun/star/text/GraphicCrop.hpp> #include <svx/svdobj.hxx> +#include <svx/svdotable.hxx> #include <svx/svdtrans.hxx> #include <tools/stream.hxx> #include <unotools/streamwrap.hxx> @@ -834,6 +835,8 @@ Reference< XShape > const & Shape::createAndInsert( maSize.Height = 0; for (auto const& elem : mpTablePropertiesPtr->getTableRows()) { + // WARN: When less then minimum sized rows exist, calculated height here + // is corrected before layouting takes place maSize.Height = o3tl::saturating_add(maSize.Height, elem.getHeight()); } } @@ -1256,7 +1259,14 @@ Reference< XShape > const & Shape::createAndInsert( mpGraphicPropertiesPtr->pushToPropMap( aShapeProps, rGraphicHelper, mbFlipH, mbFlipV ); } if ( mpTablePropertiesPtr && aServiceName == "com.sun.star.drawing.TableShape" ) + { mpTablePropertiesPtr->pushToPropSet( rFilterBase, xSet, mpMasterTextListStyle ); + if ( auto* pTableShape = dynamic_cast<sdr::table::SdrTableObj*>(SdrObject::getSdrObjectFromXShape(mxShape)) ) + { + // Disable layouting until an attempt at correcting faulty table height is made + pTableShape->SetSkipChangeLayout(true); + } + } FillProperties aFillProperties = getActualFillProperties(pTheme, &rShapeOrParentShapeFillProps); if (getFillProperties().moFillType.has_value() && getFillProperties().moFillType.value() == XML_grpFill) @@ -1488,6 +1498,21 @@ Reference< XShape > const & Shape::createAndInsert( } PropertySet( xSet ).setProperties( aShapeProps ); + + if (mpTablePropertiesPtr && aServiceName == "com.sun.star.drawing.TableShape") + { + // Powerpoint sometimes export row heights less than the minimum size, + // which during import expanded to the minimum + if (auto* pTableShape = dynamic_cast<sdr::table::SdrTableObj*>(SdrObject::getSdrObjectFromXShape(mxShape))) + { + sal_Int32 nCorrectedHeight = pTableShape->getHeightWithoutFitting(); + const auto& aShapeSize = mxShape->getSize(); + if( nCorrectedHeight > aShapeSize.Height ) + mxShape->setSize( {aShapeSize.Width, nCorrectedHeight} ); + pTableShape->SetSkipChangeLayout(false); + } + } + if (mbLockedCanvas) { putPropertyToGrabBag( "LockedCanvas", Any( true ) ); |