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

oox smartart, cycle matrix: handle aspect ratio in composite algo

This way the 4 quadrant shapes in the center of the SmartArt form a
circle, as width is shrinking.

It's not height growing, as OOXML spec clearly says "ar" always just
shrinks one axis.

(>1 and <1 "ar" is to be handled when they are seen in action in an
actual document.)

Change-Id: I69f2390ee881253151cccc336ecbf1806a1216dc
Reviewed-on: https://gerrit.libreoffice.org/67980Reviewed-by: 's avatarMiklos Vajna <vmiklos@collabora.com>
Tested-by: Jenkins
üst c02a78b5
...@@ -489,12 +489,29 @@ void AlgAtom::layoutShape( const ShapePtr& rShape, ...@@ -489,12 +489,29 @@ void AlgAtom::layoutShape( const ShapePtr& rShape,
LayoutPropertyMap aProperties; LayoutPropertyMap aProperties;
LayoutProperty& rParent = aProperties[""]; LayoutProperty& rParent = aProperties[""];
rParent[XML_w] = rShape->getSize().Width;
rParent[XML_h] = rShape->getSize().Height; sal_Int32 nParentXOffset = 0;
rParent[XML_l] = 0; if (mfAspectRatio != 1.0)
rParent[XML_t] = 0; {
rParent[XML_r] = rShape->getSize().Width; rParent[XML_w] = rShape->getSize().Width;
rParent[XML_b] = rShape->getSize().Height; rParent[XML_h] = rShape->getSize().Height;
rParent[XML_l] = 0;
rParent[XML_t] = 0;
rParent[XML_r] = rShape->getSize().Width;
rParent[XML_b] = rShape->getSize().Height;
}
else
{
// Shrink width to be only as large as height.
rParent[XML_w] = std::min(rShape->getSize().Width, rShape->getSize().Height);
rParent[XML_h] = rShape->getSize().Height;
if (rParent[XML_w] < rShape->getSize().Width)
nParentXOffset = (rShape->getSize().Width - rParent[XML_w]) / 2;
rParent[XML_l] = nParentXOffset;
rParent[XML_t] = 0;
rParent[XML_r] = rShape->getSize().Width - rParent[XML_l];
rParent[XML_b] = rShape->getSize().Height;
}
for (const auto & rConstr : rConstraints) for (const auto & rConstr : rConstraints)
{ {
...@@ -556,6 +573,7 @@ void AlgAtom::layoutShape( const ShapePtr& rShape, ...@@ -556,6 +573,7 @@ void AlgAtom::layoutShape( const ShapePtr& rShape,
if ( (it = rProp.find(XML_t)) != rProp.end() && (it2 = rProp.find(XML_b)) != rProp.end() ) if ( (it = rProp.find(XML_t)) != rProp.end() && (it2 = rProp.find(XML_b)) != rProp.end() )
aSize.Height = it2->second - it->second; aSize.Height = it2->second - it->second;
aPos.X += nParentXOffset;
aSize.Width = std::min(aSize.Width, rShape->getSize().Width - aPos.X); aSize.Width = std::min(aSize.Width, rShape->getSize().Width - aPos.X);
aSize.Height = std::min(aSize.Height, rShape->getSize().Height - aPos.Y); aSize.Height = std::min(aSize.Height, rShape->getSize().Height - aPos.Y);
} }
......
...@@ -169,9 +169,13 @@ public: ...@@ -169,9 +169,13 @@ public:
/// Gives access to <dgm:param type="..." val="..."/>. /// Gives access to <dgm:param type="..." val="..."/>.
const ParamMap& getMap() const { return maMap; } const ParamMap& getMap() const { return maMap; }
void setAspectRatio(double fAspectRatio) { mfAspectRatio = fAspectRatio; }
private: private:
sal_Int32 mnType; sal_Int32 mnType;
ParamMap maMap; ParamMap maMap;
/// Aspect ratio is not integer, so not part of maMap.
double mfAspectRatio = 0;
}; };
typedef std::shared_ptr< AlgAtom > AlgAtomPtr; typedef std::shared_ptr< AlgAtom > AlgAtomPtr;
......
...@@ -67,10 +67,18 @@ public: ...@@ -67,10 +67,18 @@ public:
{ {
case DGM_TOKEN( param ): case DGM_TOKEN( param ):
{ {
const sal_Int32 nValTok = rAttribs.getToken( XML_val, 0 ); sal_Int32 nType = rAttribs.getToken(XML_type, 0);
mpNode->addParam( switch (nType)
rAttribs.getToken( XML_type, 0 ), {
nValTok>0 ? nValTok : rAttribs.getInteger( XML_val, 0 ) ); case XML_ar:
mpNode->setAspectRatio(rAttribs.getDouble(XML_val, 0));
break;
default:
const sal_Int32 nValTok = rAttribs.getToken(XML_val, 0);
mpNode->addParam(nType, nValTok > 0 ? nValTok
: rAttribs.getInteger(XML_val, 0));
break;
}
break; break;
} }
default: default:
......
...@@ -874,6 +874,12 @@ void SdImportTestSmartArt::testCycleMatrix() ...@@ -874,6 +874,12 @@ void SdImportTestSmartArt::testCycleMatrix()
CPPUNIT_ASSERT_EQUAL(xA2Shape->getPosition().X, xD2Shape->getPosition().X); CPPUNIT_ASSERT_EQUAL(xA2Shape->getPosition().X, xD2Shape->getPosition().X);
CPPUNIT_ASSERT_GREATER(xA2Shape->getPosition().Y, xD2Shape->getPosition().Y); CPPUNIT_ASSERT_GREATER(xA2Shape->getPosition().Y, xD2Shape->getPosition().Y);
// Without the accompanying fix in place, this test would have failed: width was expected to be
// 4887, was actually 7331.
uno::Reference<drawing::XShape> xA1Shape(xA1, uno::UNO_QUERY);
CPPUNIT_ASSERT(xA1Shape.is());
CPPUNIT_ASSERT_EQUAL(xA1Shape->getSize().Height, xA1Shape->getSize().Width);
xDocShRef->DoClose(); xDocShRef->DoClose();
} }
......
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