oox/source/drawingml/shape.cxx | 48 ++++++++++++++++++++++++++++++------ sd/qa/unit/data/pptx/tdf160490.pptx |binary sd/qa/unit/data/xml/n819614_0.xml | 2 - sd/qa/unit/import-tests2.cxx | 31 ++++++++++++++++++++--- sd/source/ui/unoidl/unopage.cxx | 8 +++--- 5 files changed, 73 insertions(+), 16 deletions(-)
New commits: commit 7e13d34086d67ecfe47db5a85a4877b5ba96f874 Author: Tibor Nagy <tibor.nagy.ext...@allotropia.de> AuthorDate: Wed Jun 19 16:07:13 2024 +0200 Commit: Nagy Tibor <tibor.nagy.ext...@allotropia.de> CommitDate: Wed Jun 19 23:18:59 2024 +0200 tdf#160490 PPTX import: fix automatically resized placeholder height See also commit Ia7f94d7452d1a1c3f004aebd73b6ed5cbfd9b43b "tdf#157285 PPTX import: fix placeholder height". Change-Id: I6203af3fe86a60e29121685ffeb435f4ff25368a Reviewed-on: https://gerrit.libreoffice.org/c/core/+/169206 Tested-by: Jenkins Reviewed-by: Nagy Tibor <tibor.nagy.ext...@allotropia.de> diff --git a/oox/source/drawingml/shape.cxx b/oox/source/drawingml/shape.cxx index 81abf10cf108..2513db943b73 100644 --- a/oox/source/drawingml/shape.cxx +++ b/oox/source/drawingml/shape.cxx @@ -1254,14 +1254,48 @@ Reference< XShape > const & Shape::createAndInsert( xSet->setPropertyValue(u"Decorative"_ustr, Any(m_isDecorative)); } - // set the placeholder height to "0" if it has the 'TextAutoGrowHeight' property - // the placeholder height is set later to the correct size. - bool bAutoGrowHeight = false; - xSet->getPropertyValue(u"TextAutoGrowHeight"_ustr) >>= bAutoGrowHeight; - if (bAutoGrowHeight && mxShape->getShapeType().startsWith("com.sun.star.presentation.")) + // Placeholder uses the height set on the slide instead of the height from the master slide, + // if it has the "TextAutoGrowHeight" property + if (getTextBody() && mxShape->getShapeType().startsWith("com.sun.star.presentation.")) { - awt::Size aSize(mxShape->getSize().Width, 0); - mxShape->setSize(aSize); + bool bAutoGrowHeight = getTextBody() + ->getTextProperties() + .maPropertyMap.getProperty(PROP_TextAutoGrowHeight) + .get<bool>(); + if (bAutoGrowHeight) + { + ppt::PowerPointImport* pPPT = dynamic_cast<ppt::PowerPointImport*>(&rFilterBase); + if (!pPPT->getActualSlidePersist()->isMasterPage()) + { + // There is no support for change the shape of the drawing in LO, but we check, + // if the placeholder changes its shape, top and bottom margins won't be used. + bool bIsChangePlaceholderShape + = !mpCustomShapePropertiesPtr->getAdjustmentGuideList().empty(); + + sal_Int32 nUpper = 0; + sal_Int32 nLower = 0; + sal_Int32 nHeight = maSize.Height / 360; + if (getTextBody()->getTextProperties().moInsets[1].value() != 0 + && getTextBody()->getTextProperties().moInsets[3].value() != 0) + { + if (!bIsChangePlaceholderShape) + { + nUpper = *getTextBody()->getTextProperties().moInsets[1]; + nLower = *getTextBody()->getTextProperties().moInsets[3]; + nHeight -= (nUpper + nLower); + } + } + else + { + maDefaultShapeProperties.getProperty(PROP_TextUpperDistance) >>= nUpper; + maDefaultShapeProperties.getProperty(PROP_TextLowerDistance) >>= nLower; + nHeight += (nUpper + nLower); + } + mxShape->setSize(awt::Size(0, nHeight)); + } + } + else // the placeholder uses the height set on the master slide + mxShape->setSize(awt::Size(0, 0)); } if (aServiceName != "com.sun.star.text.TextFrame") diff --git a/sd/qa/unit/data/pptx/tdf160490.pptx b/sd/qa/unit/data/pptx/tdf160490.pptx new file mode 100644 index 000000000000..be1b316433f9 Binary files /dev/null and b/sd/qa/unit/data/pptx/tdf160490.pptx differ diff --git a/sd/qa/unit/data/xml/n819614_0.xml b/sd/qa/unit/data/xml/n819614_0.xml index 0fa127c07d9b..c889b00c343a 100644 --- a/sd/qa/unit/data/xml/n819614_0.xml +++ b/sd/qa/unit/data/xml/n819614_0.xml @@ -1,6 +1,6 @@ <?xml version="1.0"?> <XShapes> - <XShape positionX="1270" positionY="763" sizeX="21166" sizeY="1564" type="com.sun.star.presentation.TitleTextShape" name="Title 1" text="Test" fontHeight="44.000000" fontColor="000000" textAutoGrowHeight="false" textAutoGrowWidth="false" textContourFrame="false" textFitToSize="AUTOFIT" textHorizontalAdjust="BLOCK" textVerticalAdjust="CENTER" textLeftDistance="254" textRightDistance="254" textUpperDistance="127" textLowerDistance="127" textMaximumFrameHeight="0" textMaximumFrameWidth="0" textMinimumFrameHeight="1" textMinimumFrameWidth="0" textAnimationAmount="0" textAnimationCount="0" textAnimationDelay="0" textAnimationDirection="LEFT" textAnimationKind="NONE" textAnimationStartInside="false" textAnimationStopInside="false" textWritingMode="LR_TB" fillStyle="NONE" fillColor="729fcf" fillTransparence="0" fillTransparenceGradientName=""> + <XShape positionX="1270" positionY="763" sizeX="21166" sizeY="1564" type="com.sun.star.presentation.TitleTextShape" name="Title 1" text="Test" fontHeight="44.000000" fontColor="000000" textAutoGrowHeight="false" textAutoGrowWidth="false" textContourFrame="false" textFitToSize="AUTOFIT" textHorizontalAdjust="BLOCK" textVerticalAdjust="CENTER" textLeftDistance="254" textRightDistance="254" textUpperDistance="127" textLowerDistance="127" textMaximumFrameHeight="0" textMaximumFrameWidth="0" textMinimumFrameHeight="3181" textMinimumFrameWidth="0" textAnimationAmount="0" textAnimationCount="0" textAnimationDelay="0" textAnimationDirection="LEFT" textAnimationKind="NONE" textAnimationStartInside="false" textAnimationStopInside="false" textWritingMode="LR_TB" fillStyle="NONE" fillColor="729fcf" fillTransparence="0" fillTransparenceGradientName=""> <FillTransparenceGradient style="LINEAR" startColor="000000" endColor="000000" angle="0" border="0" xOffset="50" yOffset="50" startIntensity="100" endIntensity="100" stepCount="0"/> <FillGradient style="LINEAR" startColor="000000" endColor="ffffff" angle="0" border="0" xOffset="50" yOffset="50" startIntensity="100" endIntensity="100" stepCount="0"/> <FillHatch style="SINGLE" color="3465a4" distance="20" angle="0"/> diff --git a/sd/qa/unit/import-tests2.cxx b/sd/qa/unit/import-tests2.cxx index e5c2a0dcc132..aa4517fb97f6 100644 --- a/sd/qa/unit/import-tests2.cxx +++ b/sd/qa/unit/import-tests2.cxx @@ -77,6 +77,29 @@ protected: bool checkPattern(int nShapeNumber, std::vector<sal_uInt8>& rExpected); }; +CPPUNIT_TEST_FIXTURE(SdImportTest2, testTdf160490) +{ + createSdImpressDoc("pptx/tdf160490.pptx"); + + uno::Reference<drawing::XShape> xShape1(getShapeFromPage(0, 0), uno::UNO_QUERY); + CPPUNIT_ASSERT(xShape1.is()); + sal_Int32 nHeight1 = xShape1->getSize().Height; + + // Without the fix in place, this test would have failed with + // Expected: placeholder height: 3730 + // Actual : placeholder height: 2627 + CPPUNIT_ASSERT_EQUAL(sal_Int32(3730), nHeight1); + + uno::Reference<drawing::XShape> xShape2(getShapeFromPage(0, 1), uno::UNO_QUERY); + CPPUNIT_ASSERT(xShape2.is()); + sal_Int32 nHeight2 = xShape2->getSize().Height; + + // Without the fix in place, this test would have failed with + // Expected: placeholder height: 3366 + // Actual : placeholder height: 2373 + CPPUNIT_ASSERT_EQUAL(sal_Int32(3366), nHeight2); +} + CPPUNIT_TEST_FIXTURE(SdImportTest2, testTdf157285) { createSdImpressDoc("pptx/tdf157285.pptx"); @@ -86,18 +109,18 @@ CPPUNIT_TEST_FIXTURE(SdImportTest2, testTdf157285) sal_Int32 nHeight1 = xShape1->getSize().Height; // Without the fix in place, this test would have failed with - // Expected: placeholder height: 2541 + // Expected: placeholder height: 2565 // Actual : placeholder height: 3435 - CPPUNIT_ASSERT_EQUAL(sal_Int32(2541), nHeight1); + CPPUNIT_ASSERT_EQUAL(sal_Int32(2565), nHeight1); uno::Reference<drawing::XShape> xShape2(getShapeFromPage(1, 0), uno::UNO_QUERY); CPPUNIT_ASSERT(xShape2.is()); sal_Int32 nHeight2 = xShape2->getSize().Height; // Without the fix in place, this test would have failed with - // Expected: placeholder height: 1169 + // Expected: placeholder height: 1180 // Actual : placeholder height: 11303 - CPPUNIT_ASSERT_EQUAL(sal_Int32(1169), nHeight2); + CPPUNIT_ASSERT_EQUAL(sal_Int32(1180), nHeight2); } CPPUNIT_TEST_FIXTURE(SdImportTest2, testTdf152186) diff --git a/sd/source/ui/unoidl/unopage.cxx b/sd/source/ui/unoidl/unopage.cxx index 8f89dc0def6a..931ed7b5656e 100644 --- a/sd/source/ui/unoidl/unopage.cxx +++ b/sd/source/ui/unoidl/unopage.cxx @@ -486,10 +486,10 @@ rtl::Reference<SdrObject> SdGenericDrawPage::CreateSdrObject_( const Reference< ::tools::Rectangle aRect( eObjKind == PresObjKind::Title ? GetPage()->GetTitleRect() : GetPage()->GetLayoutRect() ); - // OOXML placeholder with auto grow height - // do not set the height here yet - if (xShape->getSize().Height == 0) - aRect.setHeight(0); + // OOXML placeholder with "TextAutoGrowHeight" use the height set on the slide + sal_Int32 nHeight = xShape->getSize().Height; + if (nHeight != 0) + aRect.setHeight(nHeight); const awt::Point aPos( aRect.Left(), aRect.Top() ); xShape->setPosition( aPos );