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.extern@allotropia.de>
This commit is contained in:
Tibor Nagy 2024-06-19 16:07:13 +02:00 committed by Nagy Tibor
parent f788fe2811
commit 7e13d34086
5 changed files with 73 additions and 16 deletions

View file

@ -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")

Binary file not shown.

View file

@ -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"/>

View file

@ -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)

View file

@ -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 );