[Libreoffice-commits] core.git: oox/source sd/qa
Serge Krot (via logerrit)
logerrit at kemper.freedesktop.org
Mon Apr 20 20:18:15 UTC 2020
oox/source/ppt/pptshape.cxx | 125 +++++++++++++++++++++++-------------
sd/qa/unit/data/pptx/tdf119187.pptx |binary
sd/qa/unit/import-tests.cxx | 27 +++++++
3 files changed, 108 insertions(+), 44 deletions(-)
New commits:
commit 912217285b3058efa54c2336f91fda4efdad6ff0
Author: Serge Krot <Serge.Krot at cib.de>
AuthorDate: Fri Apr 10 20:08:37 2020 +0200
Commit: Thorsten Behrens <Thorsten.Behrens at CIB.de>
CommitDate: Mon Apr 20 22:17:42 2020 +0200
tdf#119187 fix: Top-aligned text in PPTX becomes bottom-aligned
Change-Id: Ic6c03e512ce3f6e240d86186fb16e24c86942343
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/92051
Tested-by: Jenkins
Reviewed-by: Thorsten Behrens <Thorsten.Behrens at CIB.de>
diff --git a/oox/source/ppt/pptshape.cxx b/oox/source/ppt/pptshape.cxx
index 335e37335879..a781aa5e4a6e 100644
--- a/oox/source/ppt/pptshape.cxx
+++ b/oox/source/ppt/pptshape.cxx
@@ -425,65 +425,102 @@ namespace
oox::drawingml::ShapePtr PPTShape::findPlaceholder( sal_Int32 nFirstSubType, sal_Int32 nSecondSubType,
const OptValue< sal_Int32 >& oSubTypeIndex, std::vector< oox::drawingml::ShapePtr >& rShapes, bool bMasterOnly )
{
- oox::drawingml::ShapePtr aShapePtr;
- oox::drawingml::ShapePtr aChoiceShapePtr1;
- oox::drawingml::ShapePtr aChoiceShapePtr2;
- oox::drawingml::ShapePtr aChoiceShapePtr3;
- oox::drawingml::ShapePtr aChoiceShapePtr4;
- std::vector< oox::drawingml::ShapePtr >::reverse_iterator aRevIter( rShapes.rbegin() );
- while (aRevIter != rShapes.rend())
+ class Placeholders
{
- if (!bMasterOnly || ShapeLocationIsMaster((*aRevIter).get()))
+ public:
+ Placeholders()
+ : aChoice(5) // resize to 5
{
- if ((*aRevIter)->getSubTypeIndex() == oSubTypeIndex)
+ }
+
+ void add(const oox::drawingml::ShapePtr& aShape, sal_Int32 nFirstSubType, sal_Int32 nSecondSubType, const OptValue< sal_Int32 >& oSubTypeIndex)
+ {
+ if (!aShape.get())
+ return;
+
+ // get flags
+ const bool bSameFirstSubType = aShape->getSubType() == nFirstSubType;
+ const bool bSameSecondSubType = aShape->getSubType() == nSecondSubType;
+ const bool bSameIndex = aShape->getSubTypeIndex() == oSubTypeIndex;
+
+ // get prio
+ int aPrioIndex = -1;
+ if (bSameIndex && bSameFirstSubType)
+ aPrioIndex = 0;
+ else if (!bSameIndex && bSameFirstSubType)
+ aPrioIndex = 1;
+ else if (bSameIndex && bSameSecondSubType)
+ aPrioIndex = 2;
+ else if (!bSameIndex && bSameSecondSubType)
+ aPrioIndex = 3;
+ else if (bSameIndex)
+ aPrioIndex = 4;
+
+ // add
+ if (aPrioIndex != -1)
{
- if ((*aRevIter)->getSubType() == nFirstSubType)
+ if (!aChoice.at(aPrioIndex).get())
{
- aShapePtr = *aRevIter;
- break;
+ aChoice.at(aPrioIndex) = aShape;
}
- else if ((*aRevIter)->getSubType() == nSecondSubType && !aChoiceShapePtr2.get())
- aChoiceShapePtr2 = *aRevIter;
- else if (!aChoiceShapePtr4.get())
- aChoiceShapePtr4 = *aRevIter;
}
- else if ((*aRevIter)->getSubType() == nFirstSubType && !aChoiceShapePtr1.get())
- aChoiceShapePtr1 = *aRevIter;
- else if ((*aRevIter)->getSubType() == nSecondSubType && !aChoiceShapePtr3.get())
- aChoiceShapePtr3 = *aRevIter;
}
- std::vector< oox::drawingml::ShapePtr >& rChildren = (*aRevIter)->getChildren();
- aChoiceShapePtr4 = findPlaceholder( nFirstSubType, nSecondSubType, oSubTypeIndex, rChildren, bMasterOnly );
- if (aChoiceShapePtr4.get())
+
+ // return according to prio
+ oox::drawingml::ShapePtr getByPrio() const
{
- if (aChoiceShapePtr4->getSubType() == nFirstSubType)
+ for (const oox::drawingml::ShapePtr& aShape : aChoice)
{
- if (aChoiceShapePtr4->getSubTypeIndex() == oSubTypeIndex)
- aShapePtr = aChoiceShapePtr4;
- else
- aChoiceShapePtr1 = aChoiceShapePtr4;
+ if (aShape.get())
+ {
+ return aShape;
+ }
}
- else if (aChoiceShapePtr4->getSubType() == nSecondSubType)
+
+ return oox::drawingml::ShapePtr();
+ }
+
+ bool hasByPrio(size_t aIndex) const
+ {
+ return aChoice.at(aIndex).get();
+ }
+
+ private:
+ std::vector< oox::drawingml::ShapePtr > aChoice;
+
+ } aPlaceholders;
+
+ // check all shapes
+ std::vector< oox::drawingml::ShapePtr >::reverse_iterator aRevIter( rShapes.rbegin() );
+ for (; aRevIter != rShapes.rend(); ++aRevIter)
+ {
+ // check shape
+ if (!bMasterOnly || ShapeLocationIsMaster((*aRevIter).get()))
+ {
+ const oox::drawingml::ShapePtr& aShape = *aRevIter;
+ aPlaceholders.add(aShape, nFirstSubType, nSecondSubType, oSubTypeIndex);
+ }
+
+ // check children
+ std::vector< oox::drawingml::ShapePtr >& rChildren = (*aRevIter)->getChildren();
+ if (!rChildren.empty())
+ {
+ const oox::drawingml::ShapePtr aShape = findPlaceholder( nFirstSubType, nSecondSubType, oSubTypeIndex, rChildren, bMasterOnly );
+ if (aShape.get())
{
- if (aChoiceShapePtr4->getSubTypeIndex() == oSubTypeIndex)
- aChoiceShapePtr2 = aChoiceShapePtr4;
- else
- aChoiceShapePtr3 = aChoiceShapePtr4;
+ aPlaceholders.add(aShape, nFirstSubType, nSecondSubType, oSubTypeIndex);
}
}
- if (aShapePtr.get() || aChoiceShapePtr2.get())
+
+ if (aPlaceholders.hasByPrio(0) ||
+ aPlaceholders.hasByPrio(2))
+ {
break;
- ++aRevIter;
+ }
}
- if (aShapePtr.get())
- return aShapePtr;
- if (aChoiceShapePtr1.get())
- return aChoiceShapePtr1;
- if (aChoiceShapePtr2.get())
- return aChoiceShapePtr2;
- if (aChoiceShapePtr3.get())
- return aChoiceShapePtr3;
- return aChoiceShapePtr4;
+
+ // return something according to prio
+ return aPlaceholders.getByPrio();
}
oox::drawingml::ShapePtr PPTShape::findPlaceholderByIndex( const sal_Int32 nIdx, std::vector< oox::drawingml::ShapePtr >& rShapes, bool bMasterOnly )
diff --git a/sd/qa/unit/data/pptx/tdf119187.pptx b/sd/qa/unit/data/pptx/tdf119187.pptx
new file mode 100644
index 000000000000..0c4501abbc30
Binary files /dev/null and b/sd/qa/unit/data/pptx/tdf119187.pptx differ
diff --git a/sd/qa/unit/import-tests.cxx b/sd/qa/unit/import-tests.cxx
index bccfc56dc392..ef032087e4ac 100644
--- a/sd/qa/unit/import-tests.cxx
+++ b/sd/qa/unit/import-tests.cxx
@@ -208,6 +208,7 @@ public:
void testTdf77747();
void testTdf116266();
void testTdf128684();
+ void testTdf119187();
void testShapeGlowEffectPPTXImpoer();
bool checkPattern(sd::DrawDocShellRef const & rDocRef, int nShapeNumber, std::vector<sal_uInt8>& rExpected);
@@ -327,6 +328,7 @@ public:
CPPUNIT_TEST(testTdf106638);
CPPUNIT_TEST(testTdf128684);
CPPUNIT_TEST(testTdf113198);
+ CPPUNIT_TEST(testTdf119187);
CPPUNIT_TEST(testShapeGlowEffectPPTXImpoer);
CPPUNIT_TEST_SUITE_END();
@@ -3080,6 +3082,31 @@ void SdImportTest::testTdf113198()
CPPUNIT_ASSERT_EQUAL(style::ParagraphAdjust_CENTER, static_cast<style::ParagraphAdjust>(nParaAdjust));
}
+void SdImportTest::testTdf119187()
+{
+ std::vector< sd::DrawDocShellRef > xDocShRef;
+ // load document
+ xDocShRef.push_back(loadURL(m_directories.getURLFromSrc("sd/qa/unit/data/pptx/tdf119187.pptx"), PPTX));
+ // load resaved document
+ xDocShRef.push_back(saveAndReload( xDocShRef.at(0).get(), PPTX ));
+
+ // check documents
+ for (const sd::DrawDocShellRef& xDoc : xDocShRef)
+ {
+ // get shape properties
+ const SdrPage* pPage = GetPage(1, xDoc);
+ CPPUNIT_ASSERT(pPage);
+ SdrObject* pObj = pPage->GetObj(0);
+ CPPUNIT_ASSERT(pObj);
+ const sdr::properties::BaseProperties & rProperties = pObj->GetProperties();
+
+ // chcek text vertical alignment
+ const SdrTextVertAdjustItem& rSdrTextVertAdjustItem = rProperties.GetItem(SDRATTR_TEXT_VERTADJUST);
+ const SdrTextVertAdjust eTVA = rSdrTextVertAdjustItem.GetValue();
+ CPPUNIT_ASSERT_EQUAL(SDRTEXTVERTADJUST_TOP, eTVA);
+ }
+}
+
void SdImportTest::testShapeGlowEffectPPTXImpoer()
{
sd::DrawDocShellRef xDocShRef
More information about the Libreoffice-commits
mailing list