fdo#72563 : PAGEREF field tag not preserved during Roundtrip

There was a problem that in case of TOC,PAGEREF field tag was not preserved inside <hyperlink> during Roundtrip.
Reason found, there was no code support to handle PAGEREF in export.
Added code support in export code to handle PAGEREF.

Conflicts:
	sw/qa/extras/ooxmlexport/ooxmlexport.cxx
Reviewed on:
	https://gerrit.libreoffice.org/7605

Change-Id: I1785360684d8772b71c3f45fdd2c654f94777067
This commit is contained in:
Tushar Bende 2014-01-22 20:00:17 +05:30 committed by Miklos Vajna
parent 0443d29672
commit 138bd3d656
4 changed files with 63 additions and 3 deletions

Binary file not shown.

View File

@ -2292,7 +2292,7 @@ DECLARE_OOXMLEXPORT_TEST(testFdo69649, "fdo69649.docx")
xmlDocPtr pXmlDoc = parseExport("word/document.xml");
if (!pXmlDoc)
return;
xmlNodeSetPtr pXmlNodes = getXPathNode(pXmlDoc,"/w:document/w:body/w:p[21]/w:hyperlink/w:r[2]/w:t");
xmlNodeSetPtr pXmlNodes = getXPathNode(pXmlDoc,"/w:document/w:body/w:p[21]/w:hyperlink/w:r[5]/w:t");
xmlNodePtr pXmlNode = pXmlNodes->nodeTab[0];
OUString contents = OUString::createFromAscii((const char*)((pXmlNode->children[0]).content));
CPPUNIT_ASSERT(contents.match("15"));
@ -2845,6 +2845,20 @@ DECLARE_OOXMLEXPORT_TEST(testGradientFillPreservation, "gradient-fill-preservati
"/w:document/w:body/w:p/w:r/mc:AlternateContent[2]/mc:Choice/w:drawing/wp:anchor/a:graphic/a:graphicData/wps:wsp/wps:spPr/a:gradFill/a:gsLst/a:gs[@pos='50000']/a:schemeClr/a:satMod",
"val", "160000");
}
DECLARE_OOXMLEXPORT_TEST(testPageref, "testPageref.docx")
{
// fdo#72563 : There was a problem that in case of TOC,PAGEREF field tag was not preserved during Roundtrip
// This test case is to verify that PAGEREF tag is coming with proper values inside <hyperlink> tag.
xmlDocPtr pXmlDoc = parseExport();
if (!pXmlDoc)
return;
xmlNodeSetPtr pXmlNodes = getXPathNode(pXmlDoc,"/w:document/w:body/w:p[2]/w:hyperlink/w:r[3]/w:instrText");
xmlNodePtr pXmlNode = pXmlNodes->nodeTab[0];
OUString contents = OUString::createFromAscii((const char*)((pXmlNode->children[0]).content));
CPPUNIT_ASSERT(contents.match("PAGEREF _Toc355095261 \\h"));
}
#endif
CPPUNIT_PLUGIN_IMPLEMENT();

View File

@ -685,10 +685,35 @@ void DocxAttributeOutput::EndRun()
// write the run start + the run content
m_pSerializer->mergeTopMarks(); // merges the "actual run start"
// append the actual run end
m_pSerializer->endElementNS( XML_w, XML_r );
if(m_startedHyperlink && m_hyperLinkAnchor != "")
{
OUString sToken;
m_pSerializer->startElementNS( XML_w, XML_r, FSEND );
m_pSerializer->startElementNS( XML_w, XML_fldChar,
FSNS( XML_w, XML_fldCharType ), "begin",
FSEND );
m_pSerializer->endElementNS( XML_w, XML_fldChar );
m_pSerializer->endElementNS( XML_w, XML_r );
m_pSerializer->startElementNS( XML_w, XML_r, FSEND );
sToken = "PAGEREF " + m_hyperLinkAnchor + " \\h"; // '\h' Creates a hyperlink to the bookmarked paragraph.
DoWriteCmd( sToken );
m_pSerializer->endElementNS( XML_w, XML_r );
// Write the Field separator
m_pSerializer->startElementNS( XML_w, XML_r, FSEND );
m_pSerializer->singleElementNS( XML_w, XML_fldChar,
FSNS( XML_w, XML_fldCharType ), "separate",
FSEND );
m_pSerializer->endElementNS( XML_w, XML_r );
}
WritePostponedMath();
WritePendingPlaceholder();
@ -701,6 +726,17 @@ void DocxAttributeOutput::EndRun()
{
if ( m_startedHyperlink )
{
if( m_endPageRef )
{
// Hyperlink is started and fldchar "end" needs to be written for PAGEREF
m_pSerializer->startElementNS( XML_w, XML_r, FSEND );
m_pSerializer->singleElementNS( XML_w, XML_fldChar,
FSNS( XML_w, XML_fldCharType ), "end",
FSEND );
m_pSerializer->endElementNS( XML_w, XML_r );
m_endPageRef = false;
}
m_pSerializer->endElementNS( XML_w, XML_hyperlink );
m_startedHyperlink = false;
}
@ -935,6 +971,7 @@ void DocxAttributeOutput::CmdField_Impl( FieldInfos& rInfos )
sToken = sToken.replaceAll("NNNN", "dddd");
sToken = sToken.replaceAll("NN", "ddd");
}
// Write the Field command
DoWriteCmd( sToken );
@ -1402,6 +1439,8 @@ bool DocxAttributeOutput::StartURL( const OUString& rUrl, const OUString& rTarge
bool bBookmarkOnly = AnalyzeURL( rUrl, rTarget, &sUrl, &sMark );
m_hyperLinkAnchor = sMark;
if ( !sMark.isEmpty() && !bBookmarkOnly )
{
m_rExport.OutputField( NULL, ww::eHYPERLINK, sUrl );
@ -1461,6 +1500,11 @@ bool DocxAttributeOutput::StartURL( const OUString& rUrl, const OUString& rTarge
bool DocxAttributeOutput::EndURL()
{
m_closeHyperlinkInThisRun = true;
if(m_hyperLinkAnchor != "")
{
m_endPageRef = true;
m_hyperLinkAnchor = "";
}
return true;
}
@ -6172,6 +6216,7 @@ DocxAttributeOutput::DocxAttributeOutput( DocxExport &rExport, FSHelperPtr pSeri
m_pHyperlinkAttrList( NULL ),
m_pColorAttrList( NULL ),
m_pBackgroundAttrList( NULL ),
m_endPageRef( false ),
m_pFootnotesList( new ::docx::FootnotesList() ),
m_pEndnotesList( new ::docx::FootnotesList() ),
m_footnoteEndnoteRefTag( 0 ),

View File

@ -685,7 +685,8 @@ private:
::sax_fastparser::FastAttributeList *m_pColorAttrList;
/// Attributes of the paragraph background
::sax_fastparser::FastAttributeList *m_pBackgroundAttrList;
OUString m_hyperLinkAnchor;
bool m_endPageRef;
::docx::FootnotesList *m_pFootnotesList;
::docx::FootnotesList *m_pEndnotesList;
int m_footnoteEndnoteRefTag;