diff options
author | Miklos Vajna <vmiklos@suse.cz> | 2012-11-09 10:42:47 +0100 |
---|---|---|
committer | Norbert Thiebaud <nthiebaud@gmail.com> | 2012-11-10 09:00:20 +0000 |
commit | fc3f771c1f5fed267298c851e94bef9557278b5b (patch) | |
tree | 7dc7095ed31a2d39a7c0a4a2e226756ea789f62e | |
parent | 78cb2c6368d0fdcdbcd1b2f3e4d033774e1b4b60 (diff) |
fdo#51550 fix DOCX export dataloss on non-math/chart OLE export
This is still not complete, but having the replacement graphic only is
far better than having nothing.
(cherry picked from commit bd6ae389008e110be62a335dfcd82c655d512e63)
Conflicts:
sw/source/filter/ww8/docxattributeoutput.cxx
Change-Id: I141a3de1a449f4261c7086e10f2c141b3f6cdb10
Reviewed-on: https://gerrit.libreoffice.org/1017
Reviewed-by: Norbert Thiebaud <nthiebaud@gmail.com>
Tested-by: Norbert Thiebaud <nthiebaud@gmail.com>
-rw-r--r-- | sw/source/filter/ww8/docxattributeoutput.cxx | 43 | ||||
-rw-r--r-- | sw/source/filter/ww8/docxattributeoutput.hxx | 11 |
2 files changed, 33 insertions, 21 deletions
diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx index 78ee6cf8238d..d075cd43b368 100644 --- a/sw/source/filter/ww8/docxattributeoutput.cxx +++ b/sw/source/filter/ww8/docxattributeoutput.cxx @@ -1013,7 +1013,7 @@ void DocxAttributeOutput::WritePostponedGraphic() for( std::list< PostponedGraphic >::const_iterator it = m_postponedGraphic->begin(); it != m_postponedGraphic->end(); ++it ) - FlyFrameGraphic( *( it->grfNode ), it->size ); + FlyFrameGraphic( it->grfNode, it->size ); delete m_postponedGraphic; m_postponedGraphic = NULL; } @@ -1993,17 +1993,18 @@ void DocxAttributeOutput::DefaultStyle( sal_uInt16 nStyle ) #endif } -void DocxAttributeOutput::FlyFrameGraphic( const SwGrfNode& rGrfNode, const Size& rSize ) +void DocxAttributeOutput::FlyFrameGraphic( const SwGrfNode* pGrfNode, const Size& rSize, const SwFlyFrmFmt* pOLEFrmFmt, SwOLENode* pOLENode ) { - OSL_TRACE( "TODO DocxAttributeOutput::FlyFrameGraphic( const SwGrfNode& rGrfNode, const Size& rSize ) - some stuff still missing" ); + OSL_TRACE( "TODO DocxAttributeOutput::FlyFrameGraphic( const SwGrfNode* pGrfNode, const Size& rSize, const SwFlyFrmFmt* pOLEFrmFmt, SwOLENode* pOLENode ) - some stuff still missing" ); + const SwFrmFmt* pFrmFmt = pGrfNode ? pGrfNode->GetFlyFmt() : pOLEFrmFmt; // create the relation ID OString aRelId; sal_Int32 nImageType; - if ( rGrfNode.IsLinkedFile() ) + if ( pGrfNode && pGrfNode->IsLinkedFile() ) { // linked image, just create the relation String aFileName; - rGrfNode.GetFileFilterNms( &aFileName, 0 ); + pGrfNode->GetFileFilterNms( &aFileName, 0 ); // TODO Convert the file name to relative for better interoperability @@ -2016,10 +2017,14 @@ void DocxAttributeOutput::FlyFrameGraphic( const SwGrfNode& rGrfNode, const Size else { // inline, we also have to write the image itself - Graphic& rGraphic = const_cast< Graphic& >( rGrfNode.GetGrf() ); + Graphic* pGraphic = 0; + if (pGrfNode) + pGraphic = &const_cast< Graphic& >( pGrfNode->GetGrf() ); + else + pGraphic = pOLENode->GetGraphic(); m_rDrawingML.SetFS( m_pSerializer ); // to be sure that we write to the right stream - OUString aImageId = m_rDrawingML.WriteImage( rGraphic ); + OUString aImageId = m_rDrawingML.WriteImage( *pGraphic ); aRelId = OUStringToOString( aImageId, RTL_TEXTENCODING_UTF8 ); @@ -2031,11 +2036,11 @@ void DocxAttributeOutput::FlyFrameGraphic( const SwGrfNode& rGrfNode, const Size m_pSerializer->startElementNS( XML_w, XML_drawing, FSEND ); - bool isAnchor = rGrfNode.GetFlyFmt()->GetAnchor().GetAnchorId() != FLY_AS_CHAR; + bool isAnchor = pFrmFmt->GetAnchor().GetAnchorId() != FLY_AS_CHAR; if( isAnchor ) { ::sax_fastparser::FastAttributeList* attrList = m_pSerializer->createAttrList(); - attrList->add( XML_behindDoc, rGrfNode.GetFlyFmt()->GetOpaque().GetValue() ? "0" : "1" ); + attrList->add( XML_behindDoc, pFrmFmt->GetOpaque().GetValue() ? "0" : "1" ); attrList->add( XML_distT, "0" ); attrList->add( XML_distB, "0" ); attrList->add( XML_distL, "0" ); @@ -2044,13 +2049,13 @@ void DocxAttributeOutput::FlyFrameGraphic( const SwGrfNode& rGrfNode, const Size attrList->add( XML_locked, "0" ); attrList->add( XML_layoutInCell, "1" ); attrList->add( XML_allowOverlap, "1" ); // TODO - if( const SdrObject* pObj = rGrfNode.GetFlyFmt()->FindRealSdrObject()) + if( const SdrObject* pObj = pFrmFmt->FindRealSdrObject()) attrList->add( XML_relativeHeight, OString::valueOf( sal_Int32( pObj->GetOrdNum()))); m_pSerializer->startElementNS( XML_wp, XML_anchor, XFastAttributeListRef( attrList )); m_pSerializer->singleElementNS( XML_wp, XML_simplePos, XML_x, "0", XML_y, "0", FSEND ); // required, unused const char* relativeFromH; const char* relativeFromV; - switch( rGrfNode.GetFlyFmt()->GetAnchor().GetAnchorId()) + switch( pFrmFmt->GetAnchor().GetAnchorId()) { case FLY_AT_PAGE: relativeFromV = relativeFromH = "page"; @@ -2066,7 +2071,7 @@ void DocxAttributeOutput::FlyFrameGraphic( const SwGrfNode& rGrfNode, const Size break; }; Point pos( 0, 0 ); - if( SwFlyFrmFmt* flyfmt = dynamic_cast<SwFlyFrmFmt*>(rGrfNode.GetFlyFmt())) // TODO is always true? + if( const SwFlyFrmFmt* flyfmt = dynamic_cast<const SwFlyFrmFmt*>(pFrmFmt)) // TODO is always true? pos = flyfmt->GetAnchoredObj()->GetCurrRelPos(); OString x( OString::valueOf( TwipsToEMU( pos.X()))); OString y( OString::valueOf( TwipsToEMU( pos.Y()))); @@ -2102,7 +2107,7 @@ void DocxAttributeOutput::FlyFrameGraphic( const SwGrfNode& rGrfNode, const Size if( isAnchor ) { - switch( rGrfNode.GetFlyFmt()->GetSurround().GetValue()) + switch( pFrmFmt->GetSurround().GetValue()) { case SURROUND_NONE: m_pSerializer->singleElementNS( XML_wp, XML_wrapTopAndBottom, FSEND ); @@ -2125,9 +2130,9 @@ void DocxAttributeOutput::FlyFrameGraphic( const SwGrfNode& rGrfNode, const Size ::sax_fastparser::FastAttributeList* docPrattrList = m_pSerializer->createAttrList(); docPrattrList->add( XML_id, OString::valueOf( sal_Int32( m_anchorId++ )).getStr()); docPrattrList->add( XML_name, "Picture" ); - docPrattrList->add( XML_descr, OUStringToOString( rGrfNode.GetDescription(), RTL_TEXTENCODING_UTF8 ).getStr()); + docPrattrList->add( XML_descr, OUStringToOString( pGrfNode ? pGrfNode->GetDescription() : pOLEFrmFmt->GetObjDescription(), RTL_TEXTENCODING_UTF8 ).getStr()); if( GetExport().GetFilter().getVersion( ) != oox::core::ECMA_DIALECT ) - docPrattrList->add( XML_title, OUStringToOString( rGrfNode.GetTitle(), RTL_TEXTENCODING_UTF8 ).getStr()); + docPrattrList->add( XML_title, OUStringToOString( pGrfNode ? pGrfNode->GetTitle() : pOLEFrmFmt->GetObjTitle(), RTL_TEXTENCODING_UTF8 ).getStr()); XFastAttributeListRef docPrAttrListRef( docPrattrList ); m_pSerializer->startElementNS( XML_wp, XML_docPr, docPrAttrListRef ); // TODO hyperlink @@ -2238,12 +2243,14 @@ void DocxAttributeOutput::FlyFrameGraphic( const SwGrfNode& rGrfNode, const Size m_pSerializer->endElementNS( XML_w, XML_drawing ); } -void DocxAttributeOutput::WriteOLE2Obj( const SdrObject* pSdrObj, const SwOLENode& rOLENode, const Size& rSize ) +void DocxAttributeOutput::WriteOLE2Obj( const SdrObject* pSdrObj, SwOLENode& rOLENode, const Size& rSize, const SwFlyFrmFmt* pFlyFrmFmt ) { if( WriteOLEChart( pSdrObj, rSize )) return; if( WriteOLEMath( pSdrObj, rOLENode, rSize )) return; + // Then we fall back to just export the object as a graphic. + FlyFrameGraphic( 0, rSize, pFlyFrmFmt, &rOLENode ); } bool DocxAttributeOutput::WriteOLEChart( const SdrObject* pSdrObj, const Size& rSize ) @@ -2364,7 +2371,7 @@ void DocxAttributeOutput::OutputFlyFrame_Impl( const sw::Frame &rFrame, const Po if ( pGrfNode ) { if( m_postponedGraphic == NULL ) - FlyFrameGraphic( *pGrfNode, rFrame.GetLayoutSize() ); + FlyFrameGraphic( pGrfNode, rFrame.GetLayoutSize() ); else // we are writting out attributes, but w:drawing should not be inside w:rPr, { // so write it out later m_postponedGraphic->push_back( PostponedGraphic( pGrfNode, rFrame.GetLayoutSize())); @@ -2416,7 +2423,7 @@ void DocxAttributeOutput::OutputFlyFrame_Impl( const sw::Frame &rFrame, const Po { SwNodeIndex aIdx(*rFrmFmt.GetCntnt().GetCntntIdx(), 1); SwOLENode& rOLENd = *aIdx.GetNode().GetOLENode(); - WriteOLE2Obj( pSdrObj, rOLENd, rFrame.GetLayoutSize() ); + WriteOLE2Obj( pSdrObj, rOLENd, rFrame.GetLayoutSize(), dynamic_cast<const SwFlyFrmFmt*>( &rFrmFmt )); } } break; diff --git a/sw/source/filter/ww8/docxattributeoutput.hxx b/sw/source/filter/ww8/docxattributeoutput.hxx index 0d176e1cfca4..3cc75b7df54c 100644 --- a/sw/source/filter/ww8/docxattributeoutput.hxx +++ b/sw/source/filter/ww8/docxattributeoutput.hxx @@ -300,9 +300,14 @@ private: /// @see InitCollectedRunProperies(), WriteCollectedParagraphProperties() void WriteCollectedRunProperties(); - /// Output graphic fly frames. - void FlyFrameGraphic( const SwGrfNode& rGrfNode, const Size& rSize ); - void WriteOLE2Obj( const SdrObject* pSdrObj, const SwOLENode& rNode, const Size& rSize ); + /// Output graphic fly frames or replacement graphics for OLE nodes. + /// + /// For graphic frames, just use the first two parameters, for OLE + /// replacement graphics, set the first as 0, and pass the remaining three. + /// + /// @see WriteOLE2Obj() + void FlyFrameGraphic( const SwGrfNode* pGrfNode, const Size& rSize, const SwFlyFrmFmt* pOLEFrmFmt = 0, SwOLENode* pOLENode = 0); + void WriteOLE2Obj( const SdrObject* pSdrObj, SwOLENode& rNode, const Size& rSize, const SwFlyFrmFmt* pFlyFrmFmt); bool WriteOLEChart( const SdrObject* pSdrObj, const Size& rSize ); bool WriteOLEMath( const SdrObject* pSdrObj, const SwOLENode& rNode, const Size& rSize ); |