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

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: 's avatarMiklos Vajna <vmiklos@collabora.com>
üst 4c4ccdf7
......@@ -229,6 +229,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,
......@@ -250,7 +259,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 );
......@@ -310,20 +320,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.
......
......@@ -283,8 +283,9 @@ void Shape::addShape(
if( meFrameType == FRAMETYPE_DIAGRAM )
{
keepDiagramCompatibilityInfo();
if( !SvtFilterOptions::Get().IsSmartArt2Shape() )
keepDiagramCompatibilityInfo( rFilterBase );
convertSmartArtToMetafile( rFilterBase );
}
}
}
......@@ -1387,7 +1388,7 @@ Reference< XShape > const & Shape::createAndInsert(
return mxShape;
}
void Shape::keepDiagramCompatibilityInfo( XmlFilterBase const & rFilterBase )
void Shape::keepDiagramCompatibilityInfo()
{
try
{
......@@ -1418,21 +1419,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);
}
}
......
......@@ -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&)
......
......@@ -69,6 +69,7 @@ public:
void testOrgChart();
void testCycleMatrix();
void testPictureStrip();
void testInteropGrabBag();
CPPUNIT_TEST_SUITE(SdImportTestSmartArt);
......@@ -102,6 +103,7 @@ public:
CPPUNIT_TEST(testOrgChart);
CPPUNIT_TEST(testCycleMatrix);
CPPUNIT_TEST(testPictureStrip);
CPPUNIT_TEST(testInteropGrabBag);
CPPUNIT_TEST_SUITE_END();
};
......@@ -990,6 +992,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();
......
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