tdf#133687 Fix the placeholders priority order.
When we don't have type attribute on slide but have on
slidelayout we have to use it instead of default type.
Change-Id: Ibb874b5ee39c48641484fe1a8686f66c31695f76
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/99904
Tested-by: Jenkins
Reviewed-by: Gülşah Köse <gulsah.kose@collabora.com>
diff --git a/oox/source/ppt/pptshapecontext.cxx b/oox/source/ppt/pptshapecontext.cxx
index 25bcc92..72c96dd 100644
--- a/oox/source/ppt/pptshapecontext.cxx
+++ b/oox/source/ppt/pptshapecontext.cxx
@@ -65,10 +65,28 @@ ContextHandlerRef PPTShapeContext::onCreateContext( sal_Int32 aElementToken, con
}
case PPT_TOKEN( ph ):
{
SlidePersistPtr pMasterPersist( mpSlidePersistPtr->getMasterPersist() );
OptValue< sal_Int32 > oSubType( rAttribs.getToken( XML_type) );
sal_Int32 nSubType( rAttribs.getToken( XML_type, XML_obj ) );
sal_Int32 nSubTypeIndex;
oox::drawingml::ShapePtr pTmpPlaceholder;
mpShapePtr->setSubType( nSubType );
if( rAttribs.hasAttribute( XML_idx ) )
mpShapePtr->setSubTypeIndex( rAttribs.getString( XML_idx ).get().toInt32() );
{
nSubTypeIndex = rAttribs.getString( XML_idx ).get().toInt32();
mpShapePtr->setSubTypeIndex( nSubTypeIndex );
if(!oSubType.has() && pMasterPersist)
{
pTmpPlaceholder = PPTShape::findPlaceholderByIndex( nSubTypeIndex, pMasterPersist->getShapes()->getChildren() );
if(pTmpPlaceholder)
nSubType = pTmpPlaceholder->getSubType(); // When we don't have type attribute on slide but have on slidelayout we have to use it instead of default type
}
}
if ( nSubType )
{
PPTShape* pPPTShapePtr = dynamic_cast< PPTShape* >( mpShapePtr.get() );
@@ -125,7 +143,6 @@ ContextHandlerRef PPTShapeContext::onCreateContext( sal_Int32 aElementToken, con
}
else if ( eShapeLocation == Slide ) // normal slide shapes have to search within the corresponding master tree for referenced objects
{
SlidePersistPtr pMasterPersist( mpSlidePersistPtr->getMasterPersist() );
if ( pMasterPersist )
{
pPlaceholder = PPTShape::findPlaceholder( nFirstPlaceholder, nSecondPlaceholder,
diff --git a/sd/qa/unit/data/ppt/placeholder-priority.pptx b/sd/qa/unit/data/ppt/placeholder-priority.pptx
new file mode 100644
index 0000000..d11dc47
--- /dev/null
+++ b/sd/qa/unit/data/ppt/placeholder-priority.pptx
Binary files differ
diff --git a/sd/qa/unit/import-tests.cxx b/sd/qa/unit/import-tests.cxx
index c869ce0..d595d3d4 100644
--- a/sd/qa/unit/import-tests.cxx
+++ b/sd/qa/unit/import-tests.cxx
@@ -133,6 +133,7 @@ public:
void testN828390_2();
void testN828390_3();
void testFdo68594();
void testPlaceholderPriority();
void testFdo72998();
void testFdo77027();
void testStrictOOXML();
@@ -241,6 +242,7 @@ public:
CPPUNIT_TEST(testN828390_2);
CPPUNIT_TEST(testN828390_3);
CPPUNIT_TEST(testFdo68594);
CPPUNIT_TEST(testPlaceholderPriority);
CPPUNIT_TEST(testFdo72998);
CPPUNIT_TEST(testFdo77027);
CPPUNIT_TEST(testStrictOOXML);
@@ -688,6 +690,24 @@ void SdImportTest::testFdo68594()
xDocShRef->DoClose();
}
void SdImportTest::testPlaceholderPriority()
{
sd::DrawDocShellRef xDocShRef = loadURL(m_directories.getURLFromSrc("/sd/qa/unit/data/ppt/placeholder-priority.pptx"), PPTX);
const SdrPage* pPage = GetPage( 1, xDocShRef );
CPPUNIT_ASSERT_EQUAL_MESSAGE("Missing placeholder", sal_uInt32(2), sal_uInt32(pPage->GetObjCount()));
tools::Rectangle pObj1Rect(9100, 3500, 29619, 4038);
SdrObject *pObj1 = pPage->GetObj(0);
CPPUNIT_ASSERT_EQUAL_MESSAGE("Placeholder position is wrong, check the placeholder priority", pObj1Rect, pObj1->GetCurrentBoundRect());
tools::Rectangle pObj2Rect(9102, 8643, 29619, 12642);
SdrObject *pObj2 = pPage->GetObj(1);
CPPUNIT_ASSERT_EQUAL_MESSAGE("Placeholder position is wrong, check the placeholder priority", pObj2Rect, pObj2->GetCurrentBoundRect());
// If the placeholder positions are wrong, please check placeholder priority in Placeholders class.
}
void SdImportTest::testPptCrop()
{
sd::DrawDocShellRef xDocShRef