[Libreoffice-commits] core.git: oox/source sd/qa
Libreoffice Gerrit user
logerrit at kemper.freedesktop.org
Fri Dec 21 20:40:14 UTC 2018
oox/source/drawingml/diagram/diagramlayoutatoms.cxx | 20 ++++++
sd/qa/unit/data/pptx/smartart-org-chart.pptx |binary
sd/qa/unit/import-tests-smartart.cxx | 59 ++++++++++++++++++++
3 files changed, 79 insertions(+)
New commits:
commit 3103f9f9461f6eabb61a70be73862ef4be98010e
Author: Miklos Vajna <vmiklos at collabora.com>
AuthorDate: Fri Dec 21 17:51:17 2018 +0100
Commit: Miklos Vajna <vmiklos at collabora.com>
CommitDate: Fri Dec 21 21:39:44 2018 +0100
oox smartart, org chart: add initial hierChild/Root algorithms
hierChild is supposed to align and position its child layout nodes in a
linear path under the hierRoot layout node, so initially just use a
simple vertical layout algorithm.
Change-Id: Ie0090a724f8fbd2068fa2e08d8bc342290dcc2f0
Reviewed-on: https://gerrit.libreoffice.org/65554
Reviewed-by: Miklos Vajna <vmiklos at collabora.com>
Tested-by: Jenkins
diff --git a/oox/source/drawingml/diagram/diagramlayoutatoms.cxx b/oox/source/drawingml/diagram/diagramlayoutatoms.cxx
index 1aa8d6753a4a..6af12ed4d26f 100644
--- a/oox/source/drawingml/diagram/diagramlayoutatoms.cxx
+++ b/oox/source/drawingml/diagram/diagramlayoutatoms.cxx
@@ -523,7 +523,27 @@ void AlgAtom::layoutShape( const ShapePtr& rShape,
case XML_hierChild:
case XML_hierRoot:
+ {
+ if (rShape->getChildren().empty() || rShape->getSize().Width == 0
+ || rShape->getSize().Height == 0)
+ break;
+
+ sal_Int32 nCount = rShape->getChildren().size();
+
+ awt::Size aChildSize = rShape->getSize();
+ aChildSize.Height /= nCount;
+
+ awt::Point aChildPos(0, 0);
+ for (auto& pChild : rShape->getChildren())
+ {
+ pChild->setPosition(aChildPos);
+ pChild->setSize(aChildSize);
+ pChild->setChildSize(aChildSize);
+ aChildPos.Y += aChildSize.Height;
+ }
+
break;
+ }
case XML_lin:
{
diff --git a/sd/qa/unit/data/pptx/smartart-org-chart.pptx b/sd/qa/unit/data/pptx/smartart-org-chart.pptx
new file mode 100644
index 000000000000..332d401fa641
Binary files /dev/null and b/sd/qa/unit/data/pptx/smartart-org-chart.pptx differ
diff --git a/sd/qa/unit/import-tests-smartart.cxx b/sd/qa/unit/import-tests-smartart.cxx
index c54fdb873036..999b26d7c422 100644
--- a/sd/qa/unit/import-tests-smartart.cxx
+++ b/sd/qa/unit/import-tests-smartart.cxx
@@ -18,6 +18,23 @@
using namespace ::com::sun::star;
+namespace
+{
+/// Gets one child of xShape, which one is specified by nIndex.
+uno::Reference<drawing::XShape> getChildShape(const uno::Reference<drawing::XShape>& xShape, sal_Int32 nIndex)
+{
+ uno::Reference<container::XIndexAccess> xGroup(xShape, uno::UNO_QUERY);
+ CPPUNIT_ASSERT(xGroup.is());
+
+ CPPUNIT_ASSERT(xGroup->getCount() > nIndex);
+
+ uno::Reference<drawing::XShape> xRet(xGroup->getByIndex(nIndex), uno::UNO_QUERY);
+ CPPUNIT_ASSERT(xRet.is());
+
+ return xRet;
+}
+}
+
class SdImportTestSmartArt : public SdModelTestBase
{
public:
@@ -48,6 +65,7 @@ public:
void testTableList();
void testAccentProcess();
void testContinuousBlockProcess();
+ void testOrgChart();
CPPUNIT_TEST_SUITE(SdImportTestSmartArt);
@@ -78,6 +96,7 @@ public:
CPPUNIT_TEST(testTableList);
CPPUNIT_TEST(testAccentProcess);
CPPUNIT_TEST(testContinuousBlockProcess);
+ CPPUNIT_TEST(testOrgChart);
CPPUNIT_TEST_SUITE_END();
};
@@ -667,6 +686,46 @@ void SdImportTestSmartArt::testContinuousBlockProcess()
xDocShRef->DoClose();
}
+void SdImportTestSmartArt::testOrgChart()
+{
+ // Simple org chart with 1 manager and 1 employee only.
+ sd::DrawDocShellRef xDocShRef = loadURL(
+ m_directories.getURLFromSrc("/sd/qa/unit/data/pptx/smartart-org-chart.pptx"),
+ PPTX);
+ uno::Reference<drawing::XShape> xGroup(getShapeFromPage(0, 0, xDocShRef), uno::UNO_QUERY);
+ CPPUNIT_ASSERT(xGroup.is());
+
+ uno::Reference<text::XText> xManager(
+ getChildShape(getChildShape(getChildShape(xGroup, 0), 0), 0), uno::UNO_QUERY);
+ CPPUNIT_ASSERT(xManager.is());
+ CPPUNIT_ASSERT_EQUAL(OUString("Manager"), xManager->getString());
+
+ uno::Reference<drawing::XShape> xManagerShape(xManager, uno::UNO_QUERY);
+ CPPUNIT_ASSERT(xManagerShape.is());
+
+ awt::Point aManagerPos = xManagerShape->getPosition();
+
+ uno::Reference<text::XText> xEmployee(
+ getChildShape(
+ getChildShape(getChildShape(getChildShape(getChildShape(xGroup, 0), 1), 0), 0), 0),
+ uno::UNO_QUERY);
+ CPPUNIT_ASSERT(xEmployee.is());
+ CPPUNIT_ASSERT_EQUAL(OUString("Employee"), xEmployee->getString());
+
+ uno::Reference<drawing::XShape> xEmployeeShape(xEmployee, uno::UNO_QUERY);
+ CPPUNIT_ASSERT(xEmployeeShape.is());
+
+ awt::Point aEmployeePos = xEmployeeShape->getPosition();
+
+ CPPUNIT_ASSERT_EQUAL(aManagerPos.X, aEmployeePos.X);
+
+ // Without the accompanying fix in place, this test would have failed: the
+ // two shapes were overlapping, i.e. "manager" was not above "employee".
+ CPPUNIT_ASSERT_GREATER(aManagerPos.Y, aEmployeePos.Y);
+
+ xDocShRef->DoClose();
+}
+
CPPUNIT_TEST_SUITE_REGISTRATION(SdImportTestSmartArt);
CPPUNIT_PLUGIN_IMPLEMENT();
More information about the Libreoffice-commits
mailing list