diff options
author | nd101 <Fong@nd.com.cn> | 2020-03-25 13:17:48 +0800 |
---|---|---|
committer | Thorsten Behrens <Thorsten.Behrens@CIB.de> | 2020-04-23 21:41:48 +0200 |
commit | 6ae88e7b2711321783fb756a4796c89b70497db5 (patch) | |
tree | 1a6eaf95bb89661e18c5842eb65b4eda4a7cf7ff | |
parent | 715612b80942205ac3aad7ec72c615cf964fc7d2 (diff) |
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@CIB.de>
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/92725
-rw-r--r-- | oox/source/ppt/pptshape.cxx | 125 | ||||
-rw-r--r-- | sd/qa/unit/data/pptx/tdf119187.pptx | bin | 0 -> 18886 bytes | |||
-rw-r--r-- | sd/qa/unit/import-tests.cxx | 27 |
3 files changed, 108 insertions, 44 deletions
diff --git a/oox/source/ppt/pptshape.cxx b/oox/source/ppt/pptshape.cxx index 39b0c2eb4abc..440103acff12 100644 --- a/oox/source/ppt/pptshape.cxx +++ b/oox/source/ppt/pptshape.cxx @@ -429,65 +429,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 Binary files differnew file mode 100644 index 000000000000..0c4501abbc30 --- /dev/null +++ b/sd/qa/unit/data/pptx/tdf119187.pptx diff --git a/sd/qa/unit/import-tests.cxx b/sd/qa/unit/import-tests.cxx index 57a8b83c9fff..489e05d7774d 100644 --- a/sd/qa/unit/import-tests.cxx +++ b/sd/qa/unit/import-tests.cxx @@ -203,6 +203,7 @@ public: void testTdf116266(); void testTdf126324(); void testTdf128684(); + void testTdf119187(); bool checkPattern(sd::DrawDocShellRef const & rDocRef, int nShapeNumber, std::vector<sal_uInt8>& rExpected); void testPatternImport(); @@ -324,6 +325,7 @@ public: CPPUNIT_TEST(testTdf106638); CPPUNIT_TEST(testTdf128684); CPPUNIT_TEST(testTdf113198); + CPPUNIT_TEST(testTdf119187); CPPUNIT_TEST_SUITE_END(); }; @@ -3086,6 +3088,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); + } +} + CPPUNIT_TEST_SUITE_REGISTRATION(SdImportTest); CPPUNIT_PLUGIN_IMPLEMENT(); |