Kaydet (Commit) c9c9c5ad authored tarafından Grzegorz Araminowicz's avatar Grzegorz Araminowicz Kaydeden (comit) Miklos Vajna

SmartArt: improve cycle algorithm

connector arrows are now correctly positioned and rotated

Change-Id: I6407ec5e2d6e29d250f751f8dc5feae878d3c74c
Reviewed-on: https://gerrit.libreoffice.org/70525
Tested-by: Jenkins
Reviewed-by: 's avatarMiklos Vajna <vmiklos@collabora.com>
üst a293630b
......@@ -672,6 +672,11 @@ void AlgAtom::layoutShape( const ShapePtr& rShape,
awt::Size aSize;
aSize.Width = rParent[XML_w];
aSize.Height = rParent[XML_h];
// keep center position
awt::Point aPos = rShape->getPosition();
aPos.X += (rShape->getSize().Width - aSize.Width) / 2;
aPos.Y += (rShape->getSize().Height - aSize.Height) / 2;
rShape->setPosition(aPos);
rShape->setSize(aSize);
break;
}
......@@ -686,24 +691,35 @@ void AlgAtom::layoutShape( const ShapePtr& rShape,
const sal_Int32 nRotationPath = maMap.count(XML_rotPath) ? maMap.find(XML_rotPath)->second : XML_none;
const sal_Int32 nShapes = rShape->getChildren().size();
const awt::Size aCenter(rShape->getSize().Width / 2, rShape->getSize().Height / 2);
const awt::Size aChildSize(rShape->getSize().Width / 5, rShape->getSize().Height / 5);
const awt::Size aChildSize(rShape->getSize().Width / 4, rShape->getSize().Height / 4);
const awt::Size aConnectorSize(rShape->getSize().Width / 12, rShape->getSize().Height / 12);
const sal_Int32 nRadius = std::min(
(rShape->getSize().Width - aChildSize.Width) / 2,
(rShape->getSize().Height - aChildSize.Height) / 2);
const sal_Int32 nConnectorRadius = nRadius * cos(basegfx::deg2rad(nSpanAngle/nShapes));
sal_Int32 idx = 0;
for (auto & aCurrShape : rShape->getChildren())
{
const double fAngle = static_cast<double>(idx)*nSpanAngle/nShapes + nStartAngle;
awt::Size aCurrSize = aChildSize;
sal_Int32 nCurrRadius = nRadius;
if (aCurrShape->getSubType() == XML_conn)
{
aCurrSize = aConnectorSize;
nCurrRadius = nConnectorRadius;
}
const awt::Point aCurrPos(
aCenter.Width + nRadius*sin(basegfx::deg2rad(fAngle)) - aChildSize.Width/2,
aCenter.Height - nRadius*cos(basegfx::deg2rad(fAngle)) - aChildSize.Height/2);
aCenter.Width + nCurrRadius*sin(basegfx::deg2rad(fAngle)) - aCurrSize.Width/2,
aCenter.Height - nCurrRadius*cos(basegfx::deg2rad(fAngle)) - aCurrSize.Height/2);
aCurrShape->setPosition(aCurrPos);
aCurrShape->setSize(aChildSize);
aCurrShape->setChildSize(aChildSize);
aCurrShape->setSize(aCurrSize);
aCurrShape->setChildSize(aCurrSize);
if (nRotationPath == XML_alongPath)
// connectors should be handled in conn, but we don't have
// reference to previous and next child, so it's easier here
if (nRotationPath == XML_alongPath || aCurrShape->getSubType() == XML_conn)
aCurrShape->setRotation(fAngle * PER_DEGREE);
idx++;
......
......@@ -401,10 +401,25 @@ void SdImportTestSmartArt::testCycle()
m_directories.getURLFromSrc("/sd/qa/unit/data/pptx/smartart-cycle.pptx"), PPTX);
uno::Reference<drawing::XShapes> xGroup(getShapeFromPage(0, 0, xDocShRef), uno::UNO_QUERY);
CPPUNIT_ASSERT(xGroup.is());
// 10 children: 5 shapes, 5 connectors
CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(10), xGroup->getCount());
//FIXME : so far this only introduce the test document, but the actual importer was not fixed yet.
uno::Reference<drawing::XShape> xShape0(xGroup->getByIndex(0), uno::UNO_QUERY_THROW);
uno::Reference<drawing::XShape> xShapeConn(xGroup->getByIndex(1), uno::UNO_QUERY_THROW);
uno::Reference<drawing::XShape> xShape2(xGroup->getByIndex(2), uno::UNO_QUERY_THROW);
uno::Reference<text::XText> xText0(xShape0, uno::UNO_QUERY_THROW);
CPPUNIT_ASSERT_EQUAL(OUString("a"), xText0->getString());
uno::Reference<text::XText> xText2(xShape2, uno::UNO_QUERY_THROW);
CPPUNIT_ASSERT_EQUAL(OUString("b"), xText2->getString());
// xShapeConn is connector between shapes 0 and 2
// it should lay between them and be rotated 0 -> 2
CPPUNIT_ASSERT(xShape0->getPosition().X < xShapeConn->getPosition().X);
CPPUNIT_ASSERT(xShape0->getPosition().Y < xShapeConn->getPosition().Y && xShapeConn->getPosition().Y < xShape2->getPosition().Y);
uno::Reference<beans::XPropertySet> xPropSetConn(xShapeConn, uno::UNO_QUERY_THROW);
CPPUNIT_ASSERT_EQUAL(sal_Int32(32400), xPropSetConn->getPropertyValue("RotateAngle").get<sal_Int32>());
}
void SdImportTestSmartArt::testHierarchy()
......
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