[Libreoffice-commits] core.git: oox/source sd/qa
Libreoffice Gerrit user
logerrit at kemper.freedesktop.org
Wed Nov 7 18:38:03 UTC 2018
oox/source/drawingml/diagram/diagramlayoutatoms.cxx | 61 +++++++++++++++++---
sd/qa/unit/data/pptx/table-list.pptx |binary
sd/qa/unit/import-tests-smartart.cxx | 34 +++++++++++
3 files changed, 87 insertions(+), 8 deletions(-)
New commits:
commit 924f01fdef73af88284e6629c6d3604f33d27f24
Author: Miklos Vajna <vmiklos at collabora.co.uk>
AuthorDate: Wed Nov 7 17:35:50 2018 +0100
Commit: Miklos Vajna <vmiklos at collabora.co.uk>
CommitDate: Wed Nov 7 19:36:12 2018 +0100
oox smartart, table list: fix too large width of children
It's possible all children request 100% of space, need to scale down in
that case. This means that children other than the first one is now
readable in the layout result.
Change-Id: I86a05cd77510bbb6686a53e33f13a60034c8e8f6
Reviewed-on: https://gerrit.libreoffice.org/63037
Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>
Tested-by: Jenkins
diff --git a/oox/source/drawingml/diagram/diagramlayoutatoms.cxx b/oox/source/drawingml/diagram/diagramlayoutatoms.cxx
index 2ef5ffef2151..763eca855d91 100644
--- a/oox/source/drawingml/diagram/diagramlayoutatoms.cxx
+++ b/oox/source/drawingml/diagram/diagramlayoutatoms.cxx
@@ -36,6 +36,27 @@ using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::xml::sax;
using namespace ::oox::core;
+namespace
+{
+/// Looks up the value of the rInternalName -> nProperty key in rProperties.
+oox::OptValue<sal_Int32> findProperty(const oox::drawingml::LayoutPropertyMap& rProperties,
+ const OUString& rInternalName, sal_Int32 nProperty)
+{
+ oox::OptValue<sal_Int32> oRet;
+
+ auto it = rProperties.find(rInternalName);
+ if (it != rProperties.end())
+ {
+ const oox::drawingml::LayoutProperty& rProperty = it->second;
+ auto itProperty = rProperty.find(nProperty);
+ if (itProperty != rProperty.end())
+ oRet = itProperty->second;
+ }
+
+ return oRet;
+}
+}
+
namespace oox { namespace drawingml {
IteratorAttr::IteratorAttr( )
@@ -436,24 +457,48 @@ void AlgAtom::layoutShape( const ShapePtr& rShape,
rProperty[XML_w] = rShape->getSize().Width * rConstraint.mfFactor;
}
+ // See if children requested more than 100% space in total: scale
+ // down in that case.
+ sal_Int32 nTotalWidth = 0;
+ bool bSpaceFromConstraints = false;
for (auto & aCurrShape : rShape->getChildren())
{
- // Extract properties relevant for this shape from constraints.
- oox::OptValue<sal_Int32> oWidth;
- auto it = aProperties.find(aCurrShape->getInternalName());
- if (it != aProperties.end())
+ oox::OptValue<sal_Int32> oWidth
+ = findProperty(aProperties, aCurrShape->getInternalName(), XML_w);
+
+ awt::Size aSize = aChildSize;
+ if (oWidth.has())
{
- LayoutProperty& rProperty = it->second;
- auto itProperty = rProperty.find(XML_w);
- if (itProperty != rProperty.end())
- oWidth = itProperty->second;
+ aSize.Width = oWidth.get();
+ bSpaceFromConstraints = true;
}
+ if (nDir == XML_fromL || nDir == XML_fromR)
+ nTotalWidth += aSize.Width;
+ }
+
+ double fWidthScale = 1.0;
+ if (nTotalWidth > rShape->getSize().Width && nTotalWidth)
+ {
+ fWidthScale = rShape->getSize().Width;
+ fWidthScale /= nTotalWidth;
+ }
+
+ // Don't add automatic space if we take space from constraints.
+ if (bSpaceFromConstraints)
+ fSpace = 0;
+
+ for (auto& aCurrShape : rShape->getChildren())
+ {
+ // Extract properties relevant for this shape from constraints.
+ oox::OptValue<sal_Int32> oWidth
+ = findProperty(aProperties, aCurrShape->getInternalName(), XML_w);
aCurrShape->setPosition(aCurrPos);
awt::Size aSize = aChildSize;
if (oWidth.has())
aSize.Width = oWidth.get();
+ aSize.Width *= fWidthScale;
aCurrShape->setSize(aSize);
aCurrShape->setChildSize(aChildSize);
diff --git a/sd/qa/unit/data/pptx/table-list.pptx b/sd/qa/unit/data/pptx/table-list.pptx
new file mode 100644
index 000000000000..bc5fe7418e02
Binary files /dev/null and b/sd/qa/unit/data/pptx/table-list.pptx differ
diff --git a/sd/qa/unit/import-tests-smartart.cxx b/sd/qa/unit/import-tests-smartart.cxx
index 223b105181d5..3e3c6c3691b2 100644
--- a/sd/qa/unit/import-tests-smartart.cxx
+++ b/sd/qa/unit/import-tests-smartart.cxx
@@ -42,6 +42,7 @@ public:
void testBaseRtoL();
void testVertialBoxList();
void testVertialBracketList();
+ void testTableList();
CPPUNIT_TEST_SUITE(SdImportTestSmartArt);
@@ -68,6 +69,7 @@ public:
CPPUNIT_TEST(testBaseRtoL);
CPPUNIT_TEST(testVertialBoxList);
CPPUNIT_TEST(testVertialBracketList);
+ CPPUNIT_TEST(testTableList);
CPPUNIT_TEST_SUITE_END();
};
@@ -416,6 +418,38 @@ void SdImportTestSmartArt::testVertialBracketList()
xDocShRef->DoClose();
}
+void SdImportTestSmartArt::testTableList()
+{
+ sd::DrawDocShellRef xDocShRef = loadURL(
+ m_directories.getURLFromSrc("/sd/qa/unit/data/pptx/table-list.pptx"), PPTX);
+ uno::Reference<drawing::XShapes> xShapeGroup(getShapeFromPage(0, 0, xDocShRef), uno::UNO_QUERY);
+ CPPUNIT_ASSERT(xShapeGroup.is());
+ CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(3), xShapeGroup->getCount());
+
+ uno::Reference<text::XText> xParentText(xShapeGroup->getByIndex(0), uno::UNO_QUERY);
+ CPPUNIT_ASSERT(xParentText.is());
+ CPPUNIT_ASSERT_EQUAL(OUString("Parent"), xParentText->getString());
+ uno::Reference<drawing::XShape> xParent(xParentText, uno::UNO_QUERY);
+ CPPUNIT_ASSERT(xParent.is());
+ int nParentRight = xParent->getPosition().X + xParent->getSize().Width;
+
+ uno::Reference<drawing::XShapes> xChildren(xShapeGroup->getByIndex(1), uno::UNO_QUERY);
+ CPPUNIT_ASSERT(xChildren.is());
+ uno::Reference<text::XText> xChild2Text(xChildren->getByIndex(1), uno::UNO_QUERY);
+ CPPUNIT_ASSERT(xChild2Text.is());
+ CPPUNIT_ASSERT_EQUAL(OUString("Child 2"), xChild2Text->getString());
+ uno::Reference<drawing::XShape> xChild2(xChild2Text, uno::UNO_QUERY);
+ CPPUNIT_ASSERT(xChild2.is());
+ int nChild2Right = xChild2->getPosition().X + xChild2->getSize().Width;
+
+ // Without the accompanying fix in place, this test would have failed with
+ // 'Expected less than: 100, Actual : 22014', i.e. the second child was
+ // shifted to the right too much.
+ CPPUNIT_ASSERT_LESS(100, abs(nChild2Right - nParentRight));
+
+ xDocShRef->DoClose();
+}
+
CPPUNIT_TEST_SUITE_REGISTRATION(SdImportTestSmartArt);
CPPUNIT_PLUGIN_IMPLEMENT();
More information about the Libreoffice-commits
mailing list