diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2019-02-26 18:25:00 +0100 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2019-02-26 20:32:26 +0100 |
commit | 0a29c928afa74123bca05dc089c751603d368467 (patch) | |
tree | 7e2f03bb0c2aaad57f4232042e23064e8ee3d016 | |
parent | aebc79b670fb60c43dd07e8e963abe019754c092 (diff) |
oox smartart, picture strip: fix lack of spacing around the picture list
The snake algorithm in PowerPoint seem to interpret spacing as follows:
if you have N elements, then there should be the requested amount of
spacing between the elements, and also double amount of spacing around
the actual list of elements.
With this, the SmartArt and the title shape in the bugdoc no longer
overlaps.
Change-Id: I5d6885b434bfaff9de9aac595a298a5346524e19
Reviewed-on: https://gerrit.libreoffice.org/68397
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Tested-by: Jenkins
-rw-r--r-- | oox/source/drawingml/diagram/diagramlayoutatoms.cxx | 31 | ||||
-rw-r--r-- | sd/qa/unit/data/pptx/smartart-picture-strip.pptx | bin | 47928 -> 52395 bytes | |||
-rw-r--r-- | sd/qa/unit/import-tests-smartart.cxx | 10 |
3 files changed, 38 insertions, 3 deletions
diff --git a/oox/source/drawingml/diagram/diagramlayoutatoms.cxx b/oox/source/drawingml/diagram/diagramlayoutatoms.cxx index d06661e4f7e0..6893f04d63f7 100644 --- a/oox/source/drawingml/diagram/diagramlayoutatoms.cxx +++ b/oox/source/drawingml/diagram/diagramlayoutatoms.cxx @@ -446,6 +446,10 @@ void ConstraintAtom::accept( LayoutAtomVisitor& rVisitor ) void ConstraintAtom::parseConstraint(std::vector<Constraint>& rConstraints, bool bRequireForName) const { + // The snake algorithm do want a space constraint even without a name. + if (bRequireForName && maConstraint.mnType == XML_sp) + bRequireForName = false; + if (bRequireForName && maConstraint.msForName.isEmpty()) return; @@ -890,6 +894,18 @@ void AlgAtom::layoutShape( const ShapePtr& rShape, if (rShape->getChildren().empty() || rShape->getSize().Width == 0 || rShape->getSize().Height == 0) break; + // Parse constraints, only self spacing from height as a start. + double fSpaceFromConstraint = 0; + for (const auto& rConstr : rConstraints) + { + if (rConstr.mnRefType == XML_h) + { + if (rConstr.mnType == XML_sp && rConstr.msForName.isEmpty()) + fSpaceFromConstraint = rConstr.mfFactor; + } + } + bool bSpaceFromConstraints = fSpaceFromConstraint != 0; + const sal_Int32 nDir = maMap.count(XML_grDir) ? maMap.find(XML_grDir)->second : XML_tL; sal_Int32 nIncX = 1; sal_Int32 nIncY = 1; @@ -901,9 +917,9 @@ void AlgAtom::layoutShape( const ShapePtr& rShape, case XML_bR: nIncX = -1; nIncY = -1; break; } - // TODO: get values from constraints sal_Int32 nCount = rShape->getChildren().size(); - double fSpace = 0.3; + // Defaults in case not provided by constraints. + double fSpace = bSpaceFromConstraints ? fSpaceFromConstraint : 0.3; double fAspectRatio = 0.54; // diagram should not spill outside, earlier it was 0.6 sal_Int32 nCol = 1; @@ -933,7 +949,13 @@ void AlgAtom::layoutShape( const ShapePtr& rShape, { // We have a single column, so count the height based on the parent height, not // based on width. - sal_Int32 nHeight = rShape->getSize().Height / (nRow + (nRow - 1) * fSpace); + // Space occurs inside children; also double amount of space is needed outside (on + // both sides), if the factor comes from a constraint. + sal_Int32 nNumSpaces = -1; + if (bSpaceFromConstraints) + nNumSpaces += 4; + sal_Int32 nHeight + = rShape->getSize().Height / (nRow + (nRow + nNumSpaces) * fSpace); aChildSize = awt::Size(rShape->getSize().Width, nHeight); } @@ -942,6 +964,9 @@ void AlgAtom::layoutShape( const ShapePtr& rShape, aCurrPos.X = rShape->getSize().Width - aChildSize.Width; if (nIncY == -1) aCurrPos.Y = rShape->getSize().Height - aChildSize.Height; + else if (bSpaceFromConstraints) + // Initial vertical offset to have upper spacing (outside, so double amount). + aCurrPos.Y = aChildSize.Height * fSpace * 2; sal_Int32 nStartX = aCurrPos.X; sal_Int32 nColIdx = 0,index = 0; diff --git a/sd/qa/unit/data/pptx/smartart-picture-strip.pptx b/sd/qa/unit/data/pptx/smartart-picture-strip.pptx Binary files differindex b117e4e70cf6..bfb8d4f2c1bd 100644 --- a/sd/qa/unit/data/pptx/smartart-picture-strip.pptx +++ b/sd/qa/unit/data/pptx/smartart-picture-strip.pptx diff --git a/sd/qa/unit/import-tests-smartart.cxx b/sd/qa/unit/import-tests-smartart.cxx index 0d47ad679edb..3d30f576cce0 100644 --- a/sd/qa/unit/import-tests-smartart.cxx +++ b/sd/qa/unit/import-tests-smartart.cxx @@ -955,6 +955,16 @@ void SdImportTestSmartArt::testPictureStrip() CPPUNIT_ASSERT_GREATER(xFirstImageShape->getPosition().Y, xSecondImageShape->getPosition().Y); CPPUNIT_ASSERT_GREATER(xSecondImageShape->getPosition().Y, xThirdImageShape->getPosition().Y); + // Make sure that the title shape doesn't overlap with the diagram. + // Note that real "no overlap" is asserted here, though in fact what we want is a less strict + // condition: that no text part of the title shape and the diagram overlaps. + uno::Reference<drawing::XShape> xTitle(getShapeFromPage(1, 0, xDocShRef), uno::UNO_QUERY); + CPPUNIT_ASSERT(xTitle.is()); + // Without the accompanying fix in place, this test would have failed with 'Expected greater + // than: 2873; Actual : 2320', i.e. the title shape and the diagram overlapped. + CPPUNIT_ASSERT_GREATER(xTitle->getPosition().Y + xTitle->getSize().Height, + xGroup->getPosition().Y); + xDocShRef->DoClose(); } |