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.
This commit is contained in:
@@ -516,8 +516,6 @@ void DocxAttributeOutput::StartRun( const SwRedlineData* pRedlineData )
|
|||||||
|
|
||||||
void DocxAttributeOutput::EndRun()
|
void DocxAttributeOutput::EndRun()
|
||||||
{
|
{
|
||||||
if ( m_nCloseHyperlinkStatus == Detected )
|
|
||||||
m_nCloseHyperlinkStatus = EndInThisRun;
|
|
||||||
// Write field starts
|
// Write field starts
|
||||||
for ( std::vector<FieldInfos>::iterator pIt = m_Fields.begin(); pIt != m_Fields.end(); ++pIt )
|
for ( std::vector<FieldInfos>::iterator pIt = m_Fields.begin(); pIt != m_Fields.end(); ++pIt )
|
||||||
{
|
{
|
||||||
@@ -543,6 +541,11 @@ void DocxAttributeOutput::EndRun()
|
|||||||
// before "postponed run start")
|
// before "postponed run start")
|
||||||
m_pSerializer->mark(); // let's call it "actual 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
|
// prepend the actual run start
|
||||||
if ( m_pHyperlinkAttrList )
|
if ( m_pHyperlinkAttrList )
|
||||||
{
|
{
|
||||||
@@ -551,11 +554,6 @@ void DocxAttributeOutput::EndRun()
|
|||||||
m_pSerializer->startElementNS( XML_w, XML_hyperlink, xAttrList );
|
m_pSerializer->startElementNS( XML_w, XML_hyperlink, xAttrList );
|
||||||
m_pHyperlinkAttrList = NULL;
|
m_pHyperlinkAttrList = NULL;
|
||||||
}
|
}
|
||||||
if ( m_nCloseHyperlinkStatus == EndInPrevRun)
|
|
||||||
{
|
|
||||||
m_pSerializer->endElementNS( XML_w, XML_hyperlink );
|
|
||||||
m_nCloseHyperlinkStatus = Undetected;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Write the hyperlink and toc fields starts
|
// Write the hyperlink and toc fields starts
|
||||||
for ( std::vector<FieldInfos>::iterator pIt = m_Fields.begin(); pIt != m_Fields.end(); )
|
for ( std::vector<FieldInfos>::iterator pIt = m_Fields.begin(); pIt != m_Fields.end(); )
|
||||||
@@ -592,10 +590,10 @@ void DocxAttributeOutput::EndRun()
|
|||||||
EndField_Impl( m_Fields.front( ) );
|
EndField_Impl( m_Fields.front( ) );
|
||||||
m_Fields.erase( m_Fields.begin( ) );
|
m_Fields.erase( m_Fields.begin( ) );
|
||||||
}
|
}
|
||||||
if ( m_nCloseHyperlinkStatus == EndInThisRun)
|
if ( m_closeHyperlinkInThisRun )
|
||||||
{
|
{
|
||||||
m_pSerializer->endElementNS( XML_w, XML_hyperlink );
|
m_pSerializer->endElementNS( XML_w, XML_hyperlink );
|
||||||
m_nCloseHyperlinkStatus = Undetected;
|
m_closeHyperlinkInThisRun = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// if there is some redlining in the document, output it
|
// 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*/ )
|
void DocxAttributeOutput::RunText( const String& rText, rtl_TextEncoding /*eCharSet*/ )
|
||||||
{
|
{
|
||||||
if ( m_nCloseHyperlinkStatus == Detected )
|
if( m_closeHyperlinkInThisRun )
|
||||||
m_nCloseHyperlinkStatus = EndInPrevRun;
|
{
|
||||||
|
m_closeHyperlinkInPreviousRun = true;
|
||||||
|
m_closeHyperlinkInThisRun = false;
|
||||||
|
}
|
||||||
OUString aText( rText );
|
OUString aText( rText );
|
||||||
|
|
||||||
// one text can be split into more <w:t>blah</w:t>'s by line breaks etc.
|
// one text can be split into more <w:t>blah</w:t>'s by line breaks etc.
|
||||||
@@ -1232,7 +1233,7 @@ bool DocxAttributeOutput::StartURL( const String& rUrl, const String& rTarget )
|
|||||||
|
|
||||||
bool DocxAttributeOutput::EndURL()
|
bool DocxAttributeOutput::EndURL()
|
||||||
{
|
{
|
||||||
m_nCloseHyperlinkStatus = Detected;
|
m_closeHyperlinkInThisRun = true;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -4350,7 +4351,8 @@ DocxAttributeOutput::DocxAttributeOutput( DocxExport &rExport, FSHelperPtr pSeri
|
|||||||
m_bParagraphOpened( false ),
|
m_bParagraphOpened( false ),
|
||||||
m_nColBreakStatus( COLBRK_NONE ),
|
m_nColBreakStatus( COLBRK_NONE ),
|
||||||
m_pParentFrame( NULL ),
|
m_pParentFrame( NULL ),
|
||||||
m_nCloseHyperlinkStatus( Undetected ),
|
m_closeHyperlinkInThisRun( false ),
|
||||||
|
m_closeHyperlinkInPreviousRun( false ),
|
||||||
m_postponedGraphic( NULL ),
|
m_postponedGraphic( NULL ),
|
||||||
m_postponedMath( NULL ),
|
m_postponedMath( NULL ),
|
||||||
m_postitFieldsMaxId( 0 )
|
m_postitFieldsMaxId( 0 )
|
||||||
|
@@ -588,14 +588,8 @@ private:
|
|||||||
|
|
||||||
const sw::Frame *m_pParentFrame;
|
const sw::Frame *m_pParentFrame;
|
||||||
// close of hyperlink needed
|
// close of hyperlink needed
|
||||||
enum HyperLinkCloseState
|
bool m_closeHyperlinkInThisRun;
|
||||||
{
|
bool m_closeHyperlinkInPreviousRun;
|
||||||
Undetected = 0,
|
|
||||||
Detected,
|
|
||||||
EndInPrevRun,
|
|
||||||
EndInThisRun
|
|
||||||
};
|
|
||||||
HyperLinkCloseState m_nCloseHyperlinkStatus;
|
|
||||||
|
|
||||||
struct PostponedGraphic
|
struct PostponedGraphic
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user