Kaydet (Commit) cf53f243 authored tarafından Grzegorz Araminowicz's avatar Grzegorz Araminowicz Kaydeden (comit) Thorsten Behrens

SmartArt: shape rotation support

Change-Id: I13bfbd3fafff5335ce8bc23b2579182aa5a94a80
Reviewed-on: https://gerrit.libreoffice.org/41393Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarThorsten Behrens <Thorsten.Behrens@CIB.de>
üst 7d42e4b4
......@@ -136,6 +136,8 @@ public:
const css::awt::Size& getSize() const { return maSize; }
void setRotation( sal_Int32 nRotation ) { mnRotation = nRotation; }
sal_Int32 getRotation() const { return mnRotation; }
void setDiagramRotation( sal_Int32 nRotation ) { mnDiagramRotation = nRotation; }
void setFlip( bool bFlipH, bool bFlipV ) { mbFlipH = bFlipH; mbFlipV = bFlipV; }
void applyParentTextFlipV(bool bTextFlipV) { mbInheritedTextFlipV = bTextFlipV; }
void addChild( const ShapePtr& rChildPtr ) { maChildren.push_back( rChildPtr ); }
......@@ -312,6 +314,7 @@ private:
ChartShapeInfoRef mxChartShapeInfo; ///< Additional data for chart shapes.
sal_Int32 mnRotation;
sal_Int32 mnDiagramRotation; // rotates shape prior to sizing, does not affect text rotation
bool mbFlipH;
bool mbFlipV;
bool mbInheritedTextFlipV; // Used by group shapes only
......
......@@ -284,23 +284,29 @@ void AlgAtom::layoutShape( const ShapePtr& rShape,
const sal_Int32 nStartAngle = maMap.count(XML_stAng) ? maMap.find(XML_stAng)->second : 0;
const sal_Int32 nSpanAngle = maMap.count(XML_spanAng) ? maMap.find(XML_spanAng)->second : 360;
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 sal_Int32 r = std::min(
const sal_Int32 nRadius = std::min(
(rShape->getSize().Width - aChildSize.Width) / 2,
(rShape->getSize().Height - aChildSize.Height) / 2);
sal_Int32 idx = 0;
for (auto & aCurrShape : rShape->getChildren())
{
const double fAngle = (double)idx*nSpanAngle/nShapes + nStartAngle;
const awt::Point aCurrPos(
aCenter.Width + r*sin( (double(idx)*nSpanAngle/nShapes + nStartAngle)*F_PI180 ) - aChildSize.Width/2,
aCenter.Height - r*cos( (double(idx)*nSpanAngle/nShapes + nStartAngle)*F_PI180 ) - aChildSize.Height/2);
aCenter.Width + nRadius*sin(fAngle*F_PI180) - aChildSize.Width/2,
aCenter.Height - nRadius*cos(fAngle*F_PI180) - aChildSize.Height/2);
aCurrShape->setPosition(aCurrPos);
aCurrShape->setSize(aChildSize);
aCurrShape->setChildSize(aChildSize);
if (nRotationPath == XML_alongPath)
aCurrShape->setRotation(fAngle * PER_DEGREE);
idx++;
}
break;
......@@ -414,6 +420,9 @@ void AlgAtom::layoutShape( const ShapePtr& rShape,
break;
}
if (rShape->getRotation())
pTextBody->getTextProperties().moRotation = -rShape->getRotation();
// text centered vertically by default
pTextBody->getTextProperties().meVA = css::drawing::TextVerticalAdjust_CENTER;
pTextBody->getTextProperties().maPropertyMap.setProperty(PROP_TextVerticalAdjust, css::drawing::TextVerticalAdjust_CENTER);
......
......@@ -263,6 +263,8 @@ LayoutNodeContext::onCreateContext( ::sal_Int32 aElement,
pShape.reset( new Shape("com.sun.star.drawing.GroupShape") );
}
pShape->setDiagramRotation(rAttribs.getInteger(XML_rot, 0) * PER_DEGREE);
ShapeAtomPtr pAtom( new ShapeAtom(mpNode->getLayoutNode(), pShape) );
mpNode->addChild( pAtom );
return new ShapeContext( *this, ShapePtr(), pShape );
......
......@@ -113,6 +113,7 @@ Shape::Shape( const sal_Char* pServiceName, bool bDefaultHeight )
, mnSubType( 0 )
, meFrameType( FRAMETYPE_GENERIC )
, mnRotation( 0 )
, mnDiagramRotation( 0 )
, mbFlipH( false )
, mbFlipV( false )
, mbInheritedTextFlipV(false)
......@@ -156,6 +157,7 @@ Shape::Shape( const ShapePtr& pSourceShape )
, maPosition( pSourceShape->maPosition )
, meFrameType( pSourceShape->meFrameType )
, mnRotation( pSourceShape->mnRotation )
, mnDiagramRotation( pSourceShape->mnDiagramRotation )
, mbFlipH( pSourceShape->mbFlipH )
, mbFlipV( pSourceShape->mbFlipV )
, mbInheritedTextFlipV(pSourceShape->mbInheritedTextFlipV)
......@@ -474,6 +476,14 @@ Reference< XShape > const & Shape::createAndInsert(
basegfx::B2DHomMatrix aTransformation;
if (bUseRotationTransform && mnDiagramRotation != 0)
{
// rotate diagram's shape around object's center before sizing
aTransformation.translate(-0.5, -0.5);
aTransformation.rotate(F_PI180 * (mnDiagramRotation / 60000.0));
aTransformation.translate(0.5, 0.5);
}
if( maSize.Width != 1 || maSize.Height != 1)
{
// take care there are no zeros used by error
......@@ -1085,6 +1095,7 @@ Reference< XShape > const & Shape::createAndInsert(
sal_Int32 nTextRotateAngle = static_cast< sal_Int32 >( getTextBody()->getTextProperties().moRotation.get( 0 ) );
if(mbInheritedTextFlipV)
nTextRotateAngle -= 180 * 60000;
nTextRotateAngle -= mnDiagramRotation;
/* OOX measures text rotation clockwise in 1/60000th degrees,
relative to the containing shape. setTextRotateAngle wants
degrees anticlockwise. */
......
......@@ -166,6 +166,7 @@ public:
void testSmartArtChildren();
void testSmartArtText();
void testSmartArtCnt();
void testSmartArtRotation();
void testTdf109223();
void testTdf109187();
......@@ -242,6 +243,7 @@ public:
CPPUNIT_TEST(testSmartArtChildren);
CPPUNIT_TEST(testSmartArtText);
CPPUNIT_TEST(testSmartArtCnt);
CPPUNIT_TEST(testSmartArtRotation);
CPPUNIT_TEST(testTdf109223);
CPPUNIT_TEST(testTdf109187);
......@@ -2334,6 +2336,23 @@ void SdImportTest::testSmartArtCnt()
xDocShRef->DoClose();
}
void SdImportTest::testSmartArtRotation()
{
sd::DrawDocShellRef xDocShRef = loadURL(m_directories.getURLFromSrc("sd/qa/unit/data/pptx/smartart-rotation.pptx"), PPTX);
uno::Reference<drawing::XShapes> xShapeGroup(getShapeFromPage(0, 0, xDocShRef), uno::UNO_QUERY_THROW);
uno::Reference<beans::XPropertySet> xShape0(xShapeGroup->getByIndex(0), uno::UNO_QUERY_THROW);
CPPUNIT_ASSERT_EQUAL(sal_Int32(0), xShape0->getPropertyValue("RotateAngle").get<sal_Int32>());
uno::Reference<beans::XPropertySet> xShape1(xShapeGroup->getByIndex(1), uno::UNO_QUERY_THROW);
CPPUNIT_ASSERT_EQUAL(sal_Int32(24000), xShape1->getPropertyValue("RotateAngle").get<sal_Int32>());
uno::Reference<beans::XPropertySet> xShape2(xShapeGroup->getByIndex(2), uno::UNO_QUERY_THROW);
CPPUNIT_ASSERT_EQUAL(sal_Int32(12000), xShape2->getPropertyValue("RotateAngle").get<sal_Int32>());
xDocShRef->DoClose();
}
void SdImportTest::testTdf109223()
{
// In the test document flipV attribute is defined for a group shape
......
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