diff options
author | Serge Krot <Serge.Krot@cib.de> | 2020-04-10 20:08:37 +0200 |
---|---|---|
committer | Thorsten Behrens <Thorsten.Behrens@CIB.de> | 2020-04-20 22:17:42 +0200 |
commit | 912217285b3058efa54c2336f91fda4efdad6ff0 (patch) | |
tree | 943ba044e685f9affa51d6ad86fd82348c5c8499 /oox/source | |
parent | 43f0452e174d21c5d71dbb26e1243326eb9ed22e (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>
Diffstat (limited to 'oox/source')
-rw-r--r-- | oox/source/ppt/pptshape.cxx | 125 |
1 files changed, 81 insertions, 44 deletions
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 ) |