summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTushar Bende <tushar.bende@synerzip.com>2014-02-14 15:29:30 +0530
committerMiklos Vajna <vmiklos@collabora.co.uk>2014-02-26 11:43:53 +0100
commit0fb3bdc5d3aa47a61affc67b20bdbb775808fb66 (patch)
tree6316631b8abc066e903a5aafe4d2c01e3336b4b7
parenta4f0d096058709f89860178d88e4bad97e458995 (diff)
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
-rw-r--r--sw/qa/extras/ooxmlexport/data/testPageref.docxbin0 -> 26321 bytes
-rw-r--r--sw/qa/extras/ooxmlexport/ooxmlexport.cxx15
-rw-r--r--sw/source/filter/ww8/docxattributeoutput.cxx57
-rw-r--r--sw/source/filter/ww8/docxattributeoutput.hxx3
4 files changed, 72 insertions, 3 deletions
diff --git a/sw/qa/extras/ooxmlexport/data/testPageref.docx b/sw/qa/extras/ooxmlexport/data/testPageref.docx
new file mode 100644
index 000000000000..65ca38aedd57
--- /dev/null
+++ b/sw/qa/extras/ooxmlexport/data/testPageref.docx
Binary files differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
index 6826a4df9d67..db7811c1c016 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
@@ -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();
diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx
index 77ee13e97dd5..44372b6a3729 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -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 ),
diff --git a/sw/source/filter/ww8/docxattributeoutput.hxx b/sw/source/filter/ww8/docxattributeoutput.hxx
index dd24e2f6c353..b311f1ddc8d6 100644
--- a/sw/source/filter/ww8/docxattributeoutput.hxx
+++ b/sw/source/filter/ww8/docxattributeoutput.hxx
@@ -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;