diff options
author | Grzegorz Araminowicz <g.araminowicz@gmail.com> | 2017-08-20 20:40:51 +0200 |
---|---|---|
committer | Thorsten Behrens <Thorsten.Behrens@CIB.de> | 2017-08-23 01:15:08 +0200 |
commit | cf53f243d411b199ebf06661273c71de3b89753c (patch) | |
tree | 8b1b3bdbe1f42fbd4f88d1fe3288ea4c935a9a68 | |
parent | 7d42e4b4c4fc3813eeb0f72807ffd17f47a86a64 (diff) |
SmartArt: shape rotation support
Change-Id: I13bfbd3fafff5335ce8bc23b2579182aa5a94a80
Reviewed-on: https://gerrit.libreoffice.org/41393
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Thorsten Behrens <Thorsten.Behrens@CIB.de>
-rw-r--r-- | include/oox/drawingml/shape.hxx | 3 | ||||
-rw-r--r-- | oox/source/drawingml/diagram/diagramlayoutatoms.cxx | 15 | ||||
-rw-r--r-- | oox/source/drawingml/diagram/layoutnodecontext.cxx | 2 | ||||
-rw-r--r-- | oox/source/drawingml/shape.cxx | 11 | ||||
-rwxr-xr-x | sd/qa/unit/data/pptx/smartart-rotation.pptx | bin | 0 -> 43886 bytes | |||
-rw-r--r-- | sd/qa/unit/import-tests.cxx | 19 |
6 files changed, 47 insertions, 3 deletions
diff --git a/include/oox/drawingml/shape.hxx b/include/oox/drawingml/shape.hxx index 55675c190986..7c3a8934e42a 100644 --- a/include/oox/drawingml/shape.hxx +++ b/include/oox/drawingml/shape.hxx @@ -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 diff --git a/oox/source/drawingml/diagram/diagramlayoutatoms.cxx b/oox/source/drawingml/diagram/diagramlayoutatoms.cxx index 672cfee8aff9..7bfe4996edef 100644 --- a/oox/source/drawingml/diagram/diagramlayoutatoms.cxx +++ b/oox/source/drawingml/diagram/diagramlayoutatoms.cxx @@ -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); diff --git a/oox/source/drawingml/diagram/layoutnodecontext.cxx b/oox/source/drawingml/diagram/layoutnodecontext.cxx index ca41a568781b..77a3fa3b8ed8 100644 --- a/oox/source/drawingml/diagram/layoutnodecontext.cxx +++ b/oox/source/drawingml/diagram/layoutnodecontext.cxx @@ -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 ); diff --git a/oox/source/drawingml/shape.cxx b/oox/source/drawingml/shape.cxx index ada0aa35476e..8e418d19e22a 100644 --- a/oox/source/drawingml/shape.cxx +++ b/oox/source/drawingml/shape.cxx @@ -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. */ diff --git a/sd/qa/unit/data/pptx/smartart-rotation.pptx b/sd/qa/unit/data/pptx/smartart-rotation.pptx Binary files differnew file mode 100755 index 000000000000..e938d9a299f5 --- /dev/null +++ b/sd/qa/unit/data/pptx/smartart-rotation.pptx diff --git a/sd/qa/unit/import-tests.cxx b/sd/qa/unit/import-tests.cxx index 839d90db74a8..8040997bc8a7 100644 --- a/sd/qa/unit/import-tests.cxx +++ b/sd/qa/unit/import-tests.cxx @@ -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 |