Kaydet (Commit) 0fb3bdc5 authored tarafından Tushar Bende's avatar Tushar Bende Kaydeden (comit) Miklos Vajna

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.
- Also added <w:webHidden /> tag for PAGEREF
- Earlier pushed code changes was corrupting some documents.
- Verified this patch on large set of Docx containing different combination of hyperlinks.

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

Change-Id: I2331a33100ed77e15a39ecc6db01b0e696ea62de
üst a4f0d096
......@@ -2413,7 +2413,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"));
......@@ -3683,6 +3683,19 @@ DECLARE_OOXMLEXPORT_TEST(testAlphabeticalIndex_MultipleColumns,"alphabeticalInde
assertXPath(pXmlDoc, "/w:document/w:body/w:p[9]/w:pPr/w:sectPr/w:type","val","continuous");
}
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();
......
......@@ -682,6 +682,39 @@ void DocxAttributeOutput::EndRun()
DoWriteBookmarks( );
DoWriteAnnotationMarks( );
if( m_closeHyperlinkInThisRun && m_startedHyperlink && m_hyperLinkAnchor != "" && m_hyperLinkAnchor.startsWith("_Toc"))
{
OUString sToken;
m_pSerializer->startElementNS( XML_w, XML_r, FSEND );
m_pSerializer->startElementNS( XML_w, XML_rPr, FSEND );
m_pSerializer->singleElementNS( XML_w, XML_webHidden, FSEND );
m_pSerializer->endElementNS( XML_w, XML_rPr );
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 );
m_pSerializer->startElementNS( XML_w, XML_rPr, FSEND );
m_pSerializer->singleElementNS( XML_w, XML_webHidden, FSEND );
m_pSerializer->endElementNS( XML_w, XML_rPr );
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->startElementNS( XML_w, XML_rPr, FSEND );
m_pSerializer->singleElementNS( XML_w, XML_webHidden, FSEND );
m_pSerializer->endElementNS( XML_w, XML_rPr );
m_pSerializer->singleElementNS( XML_w, XML_fldChar,
FSNS( XML_w, XML_fldCharType ), "separate",
FSEND );
m_pSerializer->endElementNS( XML_w, XML_r );
}
m_pSerializer->startElementNS( XML_w, XML_r, FSEND );
if(GetExport().bTabInTOC && m_pHyperlinkAttrList)
{
......@@ -691,7 +724,6 @@ 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 );
......@@ -712,6 +744,21 @@ 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->startElementNS( XML_w, XML_rPr, FSEND );
m_pSerializer->singleElementNS( XML_w, XML_webHidden, FSEND );
m_pSerializer->endElementNS( XML_w, XML_rPr );
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_hyperLinkAnchor = "";
}
m_pSerializer->endElementNS( XML_w, XML_hyperlink );
m_startedHyperlink = false;
}
......@@ -946,6 +993,7 @@ void DocxAttributeOutput::CmdField_Impl( FieldInfos& rInfos )
sToken = sToken.replaceAll("NNNN", "dddd");
sToken = sToken.replaceAll("NN", "ddd");
}
// Write the Field command
DoWriteCmd( sToken );
......@@ -1573,6 +1621,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 );
......@@ -1632,6 +1682,10 @@ bool DocxAttributeOutput::StartURL( const OUString& rUrl, const OUString& rTarge
bool DocxAttributeOutput::EndURL()
{
m_closeHyperlinkInThisRun = true;
if(m_hyperLinkAnchor != "" && m_hyperLinkAnchor.startsWith("_Toc"))
{
m_endPageRef = true;
}
return true;
}
......@@ -6614,6 +6668,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 ),
......
......@@ -690,7 +690,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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment