[Libreoffice-commits] core.git: Branch 'libreoffice-7-0' - oox/source sd/qa
Miklos Vajna (via logerrit)
logerrit at kemper.freedesktop.org
Wed Sep 30 16:24:12 UTC 2020
oox/source/drawingml/diagram/diagramlayoutatoms.cxx | 11 ++++++--
sd/qa/unit/data/pptx/smartart-snake-rows.pptx |binary
sd/qa/unit/import-tests-smartart.cxx | 26 ++++++++++++++++++++
3 files changed, 35 insertions(+), 2 deletions(-)
New commits:
commit e342038e3e9c2e592a91c9c29153381f49290f00
Author: Miklos Vajna <vmiklos at collabora.com>
AuthorDate: Fri Sep 25 17:27:03 2020 +0200
Commit: Caolán McNamara <caolanm at redhat.com>
CommitDate: Wed Sep 30 18:23:36 2020 +0200
oox smartart: snake algo: consider child's aspect ratio request for cols/rows
If the child's aspect ratio request will shrink the width, then take
that into account when calculating how many rows / cols we need.
This reduces the number of columns for the bugdoc from 4 to 3, which is
needed, but not enough to render it correctly.
(cherry picked from commit acc9aead3cc5162379d34a455aa15f7b13907cf1)
Change-Id: I1d02df4834b8a2ce97d5e006db0e3135d3d42917
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/103694
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm at redhat.com>
diff --git a/oox/source/drawingml/diagram/diagramlayoutatoms.cxx b/oox/source/drawingml/diagram/diagramlayoutatoms.cxx
index e68f4e4bdf44..7dc5c5d70cd2 100644
--- a/oox/source/drawingml/diagram/diagramlayoutatoms.cxx
+++ b/oox/source/drawingml/diagram/diagramlayoutatoms.cxx
@@ -1321,11 +1321,18 @@ void AlgAtom::layoutShape(const ShapePtr& rShape, const std::vector<Constraint>&
nRow = nCount;
else
{
+ double fShapeHeight = rShape->getSize().Height;
+ double fShapeWidth = rShape->getSize().Width;
+ // Check if we have a child aspect ratio. If so, need to shrink one dimension to
+ // achieve that ratio.
+ if (fChildAspectRatio && fShapeHeight && fChildAspectRatio < (fShapeWidth/fShapeHeight))
+ {
+ fShapeWidth = fShapeHeight * fChildAspectRatio;
+ }
+
for ( ; nRow<nCount; nRow++)
{
nCol = (nCount+nRow-1) / nRow;
- const double fShapeHeight = rShape->getSize().Height;
- const double fShapeWidth = rShape->getSize().Width;
if ((fShapeHeight / nCol) / (fShapeWidth / nRow) >= fAspectRatio)
break;
}
diff --git a/sd/qa/unit/data/pptx/smartart-snake-rows.pptx b/sd/qa/unit/data/pptx/smartart-snake-rows.pptx
new file mode 100644
index 000000000000..7f5e82df3eaf
Binary files /dev/null and b/sd/qa/unit/data/pptx/smartart-snake-rows.pptx differ
diff --git a/sd/qa/unit/import-tests-smartart.cxx b/sd/qa/unit/import-tests-smartart.cxx
index 187b8a9fea56..70f11844a0fd 100644
--- a/sd/qa/unit/import-tests-smartart.cxx
+++ b/sd/qa/unit/import-tests-smartart.cxx
@@ -111,6 +111,7 @@ public:
void testFillColorList();
void testLinearRule();
void testAutofitSync();
+ void testSnakeRows();
CPPUNIT_TEST_SUITE(SdImportTestSmartArt);
@@ -159,6 +160,7 @@ public:
CPPUNIT_TEST(testFillColorList);
CPPUNIT_TEST(testLinearRule);
CPPUNIT_TEST(testAutofitSync);
+ CPPUNIT_TEST(testSnakeRows);
CPPUNIT_TEST_SUITE_END();
};
@@ -1589,6 +1591,30 @@ void SdImportTestSmartArt::testAutofitSync()
xDocShRef->DoClose();
}
+void SdImportTestSmartArt::testSnakeRows()
+{
+ // Load a smartart which contains a snake algorithm.
+ // The expected layout of the 6 children is a 3x2 grid.
+ sd::DrawDocShellRef xDocShRef = loadURL(
+ m_directories.getURLFromSrc("/sd/qa/unit/data/pptx/smartart-snake-rows.pptx"), PPTX);
+
+ uno::Reference<drawing::XShapes> xDiagram(getShapeFromPage(0, 0, xDocShRef), uno::UNO_QUERY);
+ std::set<sal_Int32> aYPositions;
+ for (sal_Int32 nChild = 0; nChild < xDiagram->getCount(); ++nChild)
+ {
+ uno::Reference<drawing::XShape> xChild(xDiagram->getByIndex(nChild), uno::UNO_QUERY);
+ aYPositions.insert(xChild->getPosition().Y);
+ }
+
+ // Without the accompanying fix in place, this test would have failed with:
+ // - Expected: 3
+ // - Actual : 4
+ // i.e. one more unwanted row appeared. This is better, but the ideal would be just 2 rows.
+ CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(3), aYPositions.size());
+
+ xDocShRef->DoClose();
+}
+
CPPUNIT_TEST_SUITE_REGISTRATION(SdImportTestSmartArt);
CPPUNIT_PLUGIN_IMPLEMENT();
More information about the Libreoffice-commits
mailing list