oox smartart, cycle matrix: fix too large height in composite algo

The user-level problem was that the height of the entire smartart was
too large. The reason for this was that:

- composite algorithm gets the constraint height should be 77% of width,
  this means 6096000 -> 4693920 EMUs

- at the same time the parent container is already smaller, 4064000 EMUs

- a few lines later we already limit the max height with std::min(), but
  in the meantime an incorrect y position is calculated, exactly due to
  the lack of early limited height

Solve the problem by making sure composite algorithm never works with a
height (even when using it to calculate vertical center) that exceeds
the height of the parent.

Change-Id: Iba29ed8b6e376bf379c40f1cddfce3ae45beff0a
Reviewed-on: https://gerrit.libreoffice.org/67970
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Tested-by: Jenkins
diff --git a/oox/source/drawingml/diagram/diagramlayoutatoms.cxx b/oox/source/drawingml/diagram/diagramlayoutatoms.cxx
index b306376..dc52680 100644
--- a/oox/source/drawingml/diagram/diagramlayoutatoms.cxx
+++ b/oox/source/drawingml/diagram/diagramlayoutatoms.cxx
@@ -533,9 +533,9 @@ void AlgAtom::layoutShape( const ShapePtr& rShape,
                    LayoutProperty::const_iterator it, it2;

                    if ( (it = rProp.find(XML_w)) != rProp.end() )
                        aSize.Width = it->second;
                        aSize.Width = std::min(it->second, rShape->getSize().Width);
                    if ( (it = rProp.find(XML_h)) != rProp.end() )
                        aSize.Height = it->second;
                        aSize.Height = std::min(it->second, rShape->getSize().Height);

                    if ( (it = rProp.find(XML_l)) != rProp.end() )
                        aPos.X = it->second;
diff --git a/sd/qa/unit/import-tests-smartart.cxx b/sd/qa/unit/import-tests-smartart.cxx
index 221f739..9acf64e 100644
--- a/sd/qa/unit/import-tests-smartart.cxx
+++ b/sd/qa/unit/import-tests-smartart.cxx
@@ -821,6 +821,10 @@ void SdImportTestSmartArt::testCycleMatrix()
    uno::Reference<drawing::XShape> xGroup(getShapeFromPage(0, 0, xDocShRef), uno::UNO_QUERY);
    CPPUNIT_ASSERT(xGroup.is());

    // Without the accompanying fix in place, this test would have failed: the height was 12162,
    // which is not the mm100 equivalent of the 4064000 EMU in the input file.
    CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(11287), xGroup->getSize().Height);

    uno::Reference<text::XText> xA1(getChildShape(getChildShape(xGroup, 1), 0), uno::UNO_QUERY);
    CPPUNIT_ASSERT(xA1.is());
    CPPUNIT_ASSERT_EQUAL(OUString("A1"), xA1->getString());