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@collabora.co.uk> Tested-by: Jenkins
This commit is contained in:
@@ -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);
|
||||
|
||||
Binary file not shown.
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user