diff options
author | Grzegorz Araminowicz <grzegorz.araminowicz@collabora.com> | 2019-03-08 12:45:24 +0100 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2019-05-21 09:29:26 +0200 |
commit | 3807fb7c541632a4d21afba88c27865957036f0a (patch) | |
tree | cc8dc7048124f83ce009f32a4b05b14667cb2d2e | |
parent | 5e3a3e7d37aecd353ebab78f24e7b32a66a7df83 (diff) |
PPTX import: save SmartArt markup into InteropGrabBag
it will allow to preserve SmartArt when saving PPTX files
Change-Id: I9bb66c59d202b4ce426864599014d042d4aa04b0
Reviewed-on: https://gerrit.libreoffice.org/68916
Tested-by: Jenkins
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Reviewed-on: https://gerrit.libreoffice.org/72471
-rw-r--r-- | include/oox/drawingml/shape.hxx | 23 | ||||
-rw-r--r-- | oox/source/drawingml/shape.cxx | 35 | ||||
-rw-r--r-- | oox/source/ppt/pptshape.cxx | 4 | ||||
-rw-r--r-- | sd/qa/unit/data/pptx/smartart-interopgrabbag.pptx | bin | 0 -> 39419 bytes | |||
-rw-r--r-- | sd/qa/unit/import-tests-smartart.cxx | 21 |
5 files changed, 62 insertions, 21 deletions
diff --git a/include/oox/drawingml/shape.hxx b/include/oox/drawingml/shape.hxx index 88fe31d2dd02..aaade775c00c 100644 --- a/include/oox/drawingml/shape.hxx +++ b/include/oox/drawingml/shape.hxx @@ -227,6 +227,15 @@ public: protected: + enum FrameType + { + FRAMETYPE_GENERIC, ///< Generic shape, no special type. + FRAMETYPE_OLEOBJECT, ///< OLE object embedded in a shape. + FRAMETYPE_CHART, ///< Chart embedded in a shape. + FRAMETYPE_DIAGRAM, ///< Complex diagram drawing shape. + FRAMETYPE_TABLE ///< A table embedded in a shape. + }; + css::uno::Reference< css::drawing::XShape > const & createAndInsert( ::oox::core::XmlFilterBase& rFilterBase, @@ -247,7 +256,8 @@ protected: ShapeIdMap* pShapeMap, const basegfx::B2DHomMatrix& aTransformation ); - void keepDiagramCompatibilityInfo( ::oox::core::XmlFilterBase const & rFilterBase ); + void keepDiagramCompatibilityInfo(); + void convertSmartArtToMetafile( ::oox::core::XmlFilterBase const& rFilterBase ); css::uno::Reference< css::drawing::XShape > renderDiagramToGraphic( ::oox::core::XmlFilterBase const & rFilterBase ); @@ -306,20 +316,13 @@ protected: ::std::vector<OUString> maExtDrawings; Color maFontRefColorForNodes; + FrameType meFrameType; ///< Type for graphic frame shapes. + private: - enum FrameType - { - FRAMETYPE_GENERIC, ///< Generic shape, no special type. - FRAMETYPE_OLEOBJECT, ///< OLE object embedded in a shape. - FRAMETYPE_CHART, ///< Chart embedded in a shape. - FRAMETYPE_DIAGRAM, ///< Complex diagram drawing shape. - FRAMETYPE_TABLE ///< A table embedded in a shape. - }; typedef std::shared_ptr< ::oox::vml::OleObjectInfo > OleObjectInfoRef; typedef std::shared_ptr< ChartShapeInfo > ChartShapeInfoRef; - FrameType meFrameType; ///< Type for graphic frame shapes. OleObjectInfoRef mxOleObjectInfo; ///< Additional data for OLE objects. ChartShapeInfoRef mxChartShapeInfo; ///< Additional data for chart shapes. diff --git a/oox/source/drawingml/shape.cxx b/oox/source/drawingml/shape.cxx index d45a88a692cf..3e04f3b7494e 100644 --- a/oox/source/drawingml/shape.cxx +++ b/oox/source/drawingml/shape.cxx @@ -284,8 +284,9 @@ void Shape::addShape( if( meFrameType == FRAMETYPE_DIAGRAM ) { + keepDiagramCompatibilityInfo(); if( !SvtFilterOptions::Get().IsSmartArt2Shape() ) - keepDiagramCompatibilityInfo( rFilterBase ); + convertSmartArtToMetafile( rFilterBase ); } } } @@ -1393,7 +1394,7 @@ Reference< XShape > const & Shape::createAndInsert( return mxShape; } -void Shape::keepDiagramCompatibilityInfo( XmlFilterBase const & rFilterBase ) +void Shape::keepDiagramCompatibilityInfo() { try { @@ -1424,21 +1425,33 @@ void Shape::keepDiagramCompatibilityInfo( XmlFilterBase const & rFilterBase ) xSet->setPropertyValue( aGrabBagPropName, Any( aGrabBag ) ); } else xSet->setPropertyValue( aGrabBagPropName, Any( maDiagramDoms ) ); + } + catch( const Exception& e ) + { + SAL_WARN( "oox.drawingml", "Shape::keepDiagramCompatibilityInfo: " << e ); + } +} - xSet->setPropertyValue( "MoveProtect", Any( true ) ); - xSet->setPropertyValue( "SizeProtect", Any( true ) ); +void Shape::convertSmartArtToMetafile(XmlFilterBase const & rFilterBase) +{ + try + { + Reference<XPropertySet> xSet(mxShape, UNO_QUERY_THROW); + + xSet->setPropertyValue("MoveProtect", Any(true)); + xSet->setPropertyValue("SizeProtect", Any(true)); // Replace existing shapes with a new Graphic Object rendered // from them - Reference < XShape > xShape( renderDiagramToGraphic( rFilterBase ) ); - Reference < XShapes > xShapes( mxShape, UNO_QUERY_THROW ); - while( xShapes->hasElements() ) - xShapes->remove( Reference < XShape > ( xShapes->getByIndex( 0 ), UNO_QUERY_THROW ) ); - xShapes->add( xShape ); + Reference<XShape> xShape(renderDiagramToGraphic(rFilterBase)); + Reference<XShapes> xShapes(mxShape, UNO_QUERY_THROW); + while (xShapes->hasElements()) + xShapes->remove(Reference<XShape>(xShapes->getByIndex(0), UNO_QUERY_THROW)); + xShapes->add(xShape); } - catch( const Exception& e ) + catch (const Exception& e) { - SAL_WARN( "oox.drawingml", "Shape::keepDiagramCompatibilityInfo: " << e ); + SAL_WARN("oox.drawingml", "Shape::convertSmartArtToMetafile: " << e); } } diff --git a/oox/source/ppt/pptshape.cxx b/oox/source/ppt/pptshape.cxx index 92c573b6f5ea..0121f8905e3d 100644 --- a/oox/source/ppt/pptshape.cxx +++ b/oox/source/ppt/pptshape.cxx @@ -33,6 +33,7 @@ #include <sal/log.hxx> #include <oox/ppt/slidepersist.hxx> #include <oox/token/tokens.hxx> +#include <unotools/fltrcfg.hxx> using namespace ::oox::core; using namespace ::oox::drawingml; @@ -397,6 +398,9 @@ void PPTShape::addShape( Reference<XShapes> xShapes(xShape, UNO_QUERY); if (xShapes.is()) addChildren( rFilterBase, *this, pTheme, xShapes, pShapeMap, aTransformation ); + + if (meFrameType == FRAMETYPE_DIAGRAM) + keepDiagramCompatibilityInfo(); } } catch (const Exception&) diff --git a/sd/qa/unit/data/pptx/smartart-interopgrabbag.pptx b/sd/qa/unit/data/pptx/smartart-interopgrabbag.pptx Binary files differnew file mode 100644 index 000000000000..ef678b6c3398 --- /dev/null +++ b/sd/qa/unit/data/pptx/smartart-interopgrabbag.pptx diff --git a/sd/qa/unit/import-tests-smartart.cxx b/sd/qa/unit/import-tests-smartart.cxx index e4a2fafd9df3..fc09e270247f 100644 --- a/sd/qa/unit/import-tests-smartart.cxx +++ b/sd/qa/unit/import-tests-smartart.cxx @@ -68,6 +68,7 @@ public: void testOrgChart(); void testCycleMatrix(); void testPictureStrip(); + void testInteropGrabBag(); CPPUNIT_TEST_SUITE(SdImportTestSmartArt); @@ -100,6 +101,7 @@ public: CPPUNIT_TEST(testOrgChart); CPPUNIT_TEST(testCycleMatrix); CPPUNIT_TEST(testPictureStrip); + CPPUNIT_TEST(testInteropGrabBag); CPPUNIT_TEST_SUITE_END(); }; @@ -899,6 +901,25 @@ void SdImportTestSmartArt::testPictureStrip() xDocShRef->DoClose(); } +void SdImportTestSmartArt::testInteropGrabBag() +{ + sd::DrawDocShellRef xDocShRef = loadURL( + m_directories.getURLFromSrc("/sd/qa/unit/data/pptx/smartart-interopgrabbag.pptx"), PPTX); + uno::Reference<drawing::XShape> xGroup(getShapeFromPage(0, 0, xDocShRef), uno::UNO_QUERY); + CPPUNIT_ASSERT(xGroup.is()); + + uno::Reference<beans::XPropertySet> xPropertySet(xGroup, uno::UNO_QUERY_THROW); + uno::Sequence<beans::PropertyValue> aGrabBagSeq; + xPropertySet->getPropertyValue("InteropGrabBag") >>= aGrabBagSeq; + comphelper::SequenceAsHashMap aGrabBag(aGrabBagSeq); + CPPUNIT_ASSERT(aGrabBag.find("OOXData") != aGrabBag.end()); + CPPUNIT_ASSERT(aGrabBag.find("OOXLayout") != aGrabBag.end()); + CPPUNIT_ASSERT(aGrabBag.find("OOXStyle") != aGrabBag.end()); + CPPUNIT_ASSERT(aGrabBag.find("OOXColor") != aGrabBag.end()); + + xDocShRef->DoClose(); +} + CPPUNIT_TEST_SUITE_REGISTRATION(SdImportTestSmartArt); CPPUNIT_PLUGIN_IMPLEMENT(); |