From f176c9ba7be7f3051a52b9f57b56124038c0cfd6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubo=C5=A1=20Lu=C5=88=C3=A1k?= Date: Mon, 12 Dec 2011 18:11:17 +0100 Subject: [PATCH] fix docx hyperlink writing This is a rewrite of the fix for fdo#35826, needed for writing the document from bnc#706138 as docx. The sequence there is startURL(), runText(), endRun(), endUrl(), startUrl(), runText(), endUrl(), endRun(), so by the second endRun(), it is needed to close both the previous and current hyperlink run. --- sw/source/filter/ww8/docxattributeoutput.cxx | 28 +++++++++++--------- sw/source/filter/ww8/docxattributeoutput.hxx | 10 ++----- 2 files changed, 17 insertions(+), 21 deletions(-) diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx index 42a132d638b6..d9f33762d60a 100644 --- a/sw/source/filter/ww8/docxattributeoutput.cxx +++ b/sw/source/filter/ww8/docxattributeoutput.cxx @@ -516,8 +516,6 @@ void DocxAttributeOutput::StartRun( const SwRedlineData* pRedlineData ) void DocxAttributeOutput::EndRun() { - if ( m_nCloseHyperlinkStatus == Detected ) - m_nCloseHyperlinkStatus = EndInThisRun; // Write field starts for ( std::vector::iterator pIt = m_Fields.begin(); pIt != m_Fields.end(); ++pIt ) { @@ -543,6 +541,11 @@ void DocxAttributeOutput::EndRun() // before "postponed run start") m_pSerializer->mark(); // let's call it "actual run start" + if ( m_closeHyperlinkInPreviousRun ) + { + m_pSerializer->endElementNS( XML_w, XML_hyperlink ); + m_closeHyperlinkInPreviousRun = false; + } // prepend the actual run start if ( m_pHyperlinkAttrList ) { @@ -551,11 +554,6 @@ void DocxAttributeOutput::EndRun() m_pSerializer->startElementNS( XML_w, XML_hyperlink, xAttrList ); m_pHyperlinkAttrList = NULL; } - if ( m_nCloseHyperlinkStatus == EndInPrevRun) - { - m_pSerializer->endElementNS( XML_w, XML_hyperlink ); - m_nCloseHyperlinkStatus = Undetected; - } // Write the hyperlink and toc fields starts for ( std::vector::iterator pIt = m_Fields.begin(); pIt != m_Fields.end(); ) @@ -592,10 +590,10 @@ void DocxAttributeOutput::EndRun() EndField_Impl( m_Fields.front( ) ); m_Fields.erase( m_Fields.begin( ) ); } - if ( m_nCloseHyperlinkStatus == EndInThisRun) + if ( m_closeHyperlinkInThisRun ) { m_pSerializer->endElementNS( XML_w, XML_hyperlink ); - m_nCloseHyperlinkStatus = Undetected; + m_closeHyperlinkInThisRun = false; } // if there is some redlining in the document, output it @@ -1043,8 +1041,11 @@ static void impl_WriteRunText( FSHelperPtr pSerializer, sal_Int32 nTextToken, void DocxAttributeOutput::RunText( const String& rText, rtl_TextEncoding /*eCharSet*/ ) { - if ( m_nCloseHyperlinkStatus == Detected ) - m_nCloseHyperlinkStatus = EndInPrevRun; + if( m_closeHyperlinkInThisRun ) + { + m_closeHyperlinkInPreviousRun = true; + m_closeHyperlinkInThisRun = false; + } OUString aText( rText ); // one text can be split into more blah's by line breaks etc. @@ -1232,7 +1233,7 @@ bool DocxAttributeOutput::StartURL( const String& rUrl, const String& rTarget ) bool DocxAttributeOutput::EndURL() { - m_nCloseHyperlinkStatus = Detected; + m_closeHyperlinkInThisRun = true; return true; } @@ -4350,7 +4351,8 @@ DocxAttributeOutput::DocxAttributeOutput( DocxExport &rExport, FSHelperPtr pSeri m_bParagraphOpened( false ), m_nColBreakStatus( COLBRK_NONE ), m_pParentFrame( NULL ), - m_nCloseHyperlinkStatus( Undetected ), + m_closeHyperlinkInThisRun( false ), + m_closeHyperlinkInPreviousRun( false ), m_postponedGraphic( NULL ), m_postponedMath( NULL ), m_postitFieldsMaxId( 0 ) diff --git a/sw/source/filter/ww8/docxattributeoutput.hxx b/sw/source/filter/ww8/docxattributeoutput.hxx index 10ee7cd96a94..79c8b026ae42 100644 --- a/sw/source/filter/ww8/docxattributeoutput.hxx +++ b/sw/source/filter/ww8/docxattributeoutput.hxx @@ -588,14 +588,8 @@ private: const sw::Frame *m_pParentFrame; // close of hyperlink needed - enum HyperLinkCloseState - { - Undetected = 0, - Detected, - EndInPrevRun, - EndInThisRun - }; - HyperLinkCloseState m_nCloseHyperlinkStatus; + bool m_closeHyperlinkInThisRun; + bool m_closeHyperlinkInPreviousRun; struct PostponedGraphic {