Kaydet (Commit) 0a29c928 authored tarafından Miklos Vajna's avatar Miklos Vajna

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/68397Reviewed-by: 's avatarMiklos Vajna <vmiklos@collabora.com>
Tested-by: Jenkins
üst aebc79b6
......@@ -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;
......
......@@ -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();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment