From f7c61b08d526c79ecd1522dff79386059b6125e0 Mon Sep 17 00:00:00 2001 From: Tamás Zolnai Date: Tue, 25 Oct 2016 01:51:25 +0000 Subject: tdf#103389: Resaving a DOCX document with two canvases leads to a broken file. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Make custom shape export more robust. In case of the test document, WriteCustomGeometry is called, but this call does not export anything, and so we get a shape without any geometry in the DOCX file, which causes problem to MS Word. Change-Id: Ie7a4e2b8a18bfddaeeb81425ae5f1de04140d43f Reviewed-on: https://gerrit.libreoffice.org/30241 Reviewed-by: Tamás Zolnai Tested-by: Tamás Zolnai --- oox/source/export/drawingml.cxx | 15 ++++++++------- oox/source/export/shapes.cxx | 4 +++- 2 files changed, 11 insertions(+), 8 deletions(-) (limited to 'oox') diff --git a/oox/source/export/drawingml.cxx b/oox/source/export/drawingml.cxx index a70b8d6f1dcf..292564649e3c 100644 --- a/oox/source/export/drawingml.cxx +++ b/oox/source/export/drawingml.cxx @@ -2298,23 +2298,23 @@ void DrawingML::WritePresetShape( const char* pShape, MSO_SPT eShapeType, bool b mpFS->endElementNS( XML_a, XML_prstGeom ); } -void DrawingML::WriteCustomGeometry( const Reference< XShape >& rXShape ) +bool DrawingML::WriteCustomGeometry( const Reference< XShape >& rXShape ) { uno::Reference< beans::XPropertySet > aXPropSet; uno::Any aAny( rXShape->queryInterface(cppu::UnoType::get())); if ( ! (aAny >>= aXPropSet) ) - return; + return false; try { aAny = aXPropSet->getPropertyValue( "CustomShapeGeometry" ); if ( !aAny.hasValue() ) - return; + return false; } catch( const ::uno::Exception& ) { - return; + return false; } @@ -2345,7 +2345,7 @@ void DrawingML::WriteCustomGeometry( const Reference< XShape >& rXShape ) } if ( !aPairs.hasElements() ) - return; + return false; if ( !aSegments.hasElements() ) { @@ -2369,7 +2369,7 @@ void DrawingML::WriteCustomGeometry( const Reference< XShape >& rXShape ) if ( nExpectedPairCount > aPairs.getLength() ) { SAL_WARN("oox", "Segments need " << nExpectedPairCount << " coordinates, but Coordinates have only " << aPairs.getLength() << " pairs."); - return; + return false; } mpFS->startElementNS( XML_a, XML_custGeom, FSEND ); @@ -2531,10 +2531,11 @@ void DrawingML::WriteCustomGeometry( const Reference< XShape >& rXShape ) mpFS->endElementNS( XML_a, XML_path ); mpFS->endElementNS( XML_a, XML_pathLst ); mpFS->endElementNS( XML_a, XML_custGeom ); + return true; } } } - + return false; } void DrawingML::WritePolyPolygon( const tools::PolyPolygon& rPolyPolygon ) diff --git a/oox/source/export/shapes.cxx b/oox/source/export/shapes.cxx index 62b8b34aa2c7..a44f2ee25b40 100644 --- a/oox/source/export/shapes.cxx +++ b/oox/source/export/shapes.cxx @@ -834,7 +834,9 @@ ShapeExport& ShapeExport::WriteCustomShape( const Reference< XShape >& xShape ) else if (bCustGeom) { WriteShapeTransformation( xShape, XML_a, bFlipH, bFlipV ); - WriteCustomGeometry( xShape ); + bool bSuccess = WriteCustomGeometry( xShape ); + if (!bSuccess) + WritePresetShape( sPresetShape ); } else if (bOnBlacklist && bHasHandles && nAdjustmentValuesIndex !=-1 && !sShapeType.startsWith("mso-spt")) { -- cgit