Kaydet (Commit) ee6787fc authored tarafından Miklos Vajna's avatar Miklos Vajna

oox smartart, continuous block process: read space width from constraint

The information is needed by the linear layout, but it's provided by a
child algorithm of type "space", with possibly multiple foreach atoms
in-between.

So start supporting a custom space factor by reading it from
constraints, but still assume a fixed layout node name, as it's tricky
to look that up.

Change-Id: I2aa8db8823694618d8ca6707ddcd71715a65b831
Reviewed-on: https://gerrit.libreoffice.org/65049Reviewed-by: 's avatarMiklos Vajna <vmiklos@collabora.com>
Tested-by: Jenkins
üst ec3ab1c6
...@@ -536,22 +536,9 @@ void AlgAtom::layoutShape( const ShapePtr& rShape, ...@@ -536,22 +536,9 @@ void AlgAtom::layoutShape( const ShapePtr& rShape,
const sal_Int32 nIncX = nDir==XML_fromL ? 1 : (nDir==XML_fromR ? -1 : 0); const sal_Int32 nIncX = nDir==XML_fromL ? 1 : (nDir==XML_fromR ? -1 : 0);
const sal_Int32 nIncY = nDir==XML_fromT ? 1 : (nDir==XML_fromB ? -1 : 0); const sal_Int32 nIncY = nDir==XML_fromT ? 1 : (nDir==XML_fromB ? -1 : 0);
// TODO: get values from constraints
sal_Int32 nCount = rShape->getChildren().size(); sal_Int32 nCount = rShape->getChildren().size();
double fSpace = 0.3; double fSpace = 0.3;
awt::Size aChildSize = rShape->getSize();
if (nDir == XML_fromL || nDir == XML_fromR)
aChildSize.Width /= (nCount + (nCount-1)*fSpace);
else if (nDir == XML_fromT || nDir == XML_fromB)
aChildSize.Height /= (nCount + (nCount-1)*fSpace);
awt::Point aCurrPos(0, 0);
if (nIncX == -1)
aCurrPos.X = rShape->getSize().Width - aChildSize.Width;
if (nIncY == -1)
aCurrPos.Y = rShape->getSize().Height - aChildSize.Height;
// Find out which constraint is relevant for which (internal) name. // Find out which constraint is relevant for which (internal) name.
LayoutPropertyMap aProperties; LayoutPropertyMap aProperties;
for (const auto& rConstraint : rConstraints) for (const auto& rConstraint : rConstraints)
...@@ -562,8 +549,24 @@ void AlgAtom::layoutShape( const ShapePtr& rShape, ...@@ -562,8 +549,24 @@ void AlgAtom::layoutShape( const ShapePtr& rShape,
LayoutProperty& rProperty = aProperties[rConstraint.msForName]; LayoutProperty& rProperty = aProperties[rConstraint.msForName];
if (rConstraint.mnType == XML_w) if (rConstraint.mnType == XML_w)
rProperty[XML_w] = rShape->getSize().Width * rConstraint.mfFactor; rProperty[XML_w] = rShape->getSize().Width * rConstraint.mfFactor;
// TODO: get values from differently named constraints as well
if (rConstraint.msForName == "sibTrans" && rConstraint.mnType == XML_w)
fSpace = rConstraint.mfFactor;
} }
awt::Size aChildSize = rShape->getSize();
if (nDir == XML_fromL || nDir == XML_fromR)
aChildSize.Width /= (nCount + (nCount-1)*fSpace);
else if (nDir == XML_fromT || nDir == XML_fromB)
aChildSize.Height /= (nCount + (nCount-1)*fSpace);
awt::Point aCurrPos(0, 0);
if (nIncX == -1)
aCurrPos.X = rShape->getSize().Width - aChildSize.Width;
if (nIncY == -1)
aCurrPos.Y = rShape->getSize().Height - aChildSize.Height;
// See if children requested more than 100% space in total: scale // See if children requested more than 100% space in total: scale
// down in that case. // down in that case.
sal_Int32 nTotalWidth = 0; sal_Int32 nTotalWidth = 0;
......
...@@ -47,6 +47,7 @@ public: ...@@ -47,6 +47,7 @@ public:
void testVertialBracketList(); void testVertialBracketList();
void testTableList(); void testTableList();
void testAccentProcess(); void testAccentProcess();
void testContinuousBlockProcess();
CPPUNIT_TEST_SUITE(SdImportTestSmartArt); CPPUNIT_TEST_SUITE(SdImportTestSmartArt);
...@@ -76,6 +77,7 @@ public: ...@@ -76,6 +77,7 @@ public:
CPPUNIT_TEST(testVertialBracketList); CPPUNIT_TEST(testVertialBracketList);
CPPUNIT_TEST(testTableList); CPPUNIT_TEST(testTableList);
CPPUNIT_TEST(testAccentProcess); CPPUNIT_TEST(testAccentProcess);
CPPUNIT_TEST(testContinuousBlockProcess);
CPPUNIT_TEST_SUITE_END(); CPPUNIT_TEST_SUITE_END();
}; };
...@@ -619,6 +621,35 @@ void SdImportTestSmartArt::testAccentProcess() ...@@ -619,6 +621,35 @@ void SdImportTestSmartArt::testAccentProcess()
xDocShRef->DoClose(); xDocShRef->DoClose();
} }
void SdImportTestSmartArt::testContinuousBlockProcess()
{
sd::DrawDocShellRef xDocShRef = loadURL(
m_directories.getURLFromSrc("/sd/qa/unit/data/pptx/smartart-continuous-block-process.pptx"),
PPTX);
uno::Reference<drawing::XShapes> xGroup(getShapeFromPage(0, 0, xDocShRef), uno::UNO_QUERY);
CPPUNIT_ASSERT(xGroup.is());
// 2 children: background, foreground.
CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(2), xGroup->getCount());
uno::Reference<drawing::XShapes> xLinear(xGroup->getByIndex(1), uno::UNO_QUERY);
CPPUNIT_ASSERT(xLinear.is());
// 3 children: A, B and C.
CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(3), xLinear->getCount());
uno::Reference<text::XText> xA(xLinear->getByIndex(0), uno::UNO_QUERY);
CPPUNIT_ASSERT(xA.is());
CPPUNIT_ASSERT_EQUAL(OUString("A"), xA->getString());
uno::Reference<drawing::XShape> xAShape(xA, uno::UNO_QUERY);
CPPUNIT_ASSERT(xAShape.is());
// Without the accompanying fix in place, this test would have failed: the
// theoretically correct value is 5462 mm100 (16933 is the total width, and
// need to divide that to 1, 0.5, 1, 0.5 and 1 units), while the old value
// was 4703 and the new one is 5461.
CPPUNIT_ASSERT_GREATER(static_cast<sal_Int32>(5000), xAShape->getSize().Width);
xDocShRef->DoClose();
}
CPPUNIT_TEST_SUITE_REGISTRATION(SdImportTestSmartArt); CPPUNIT_TEST_SUITE_REGISTRATION(SdImportTestSmartArt);
CPPUNIT_PLUGIN_IMPLEMENT(); CPPUNIT_PLUGIN_IMPLEMENT();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment