sw/qa/extras/ooxmlexport/data/testPageref.docx |binary sw/qa/extras/ooxmlexport/ooxmlexport.cxx | 15 ++++++ sw/source/filter/ww8/docxattributeoutput.cxx | 57 ++++++++++++++++++++++++- sw/source/filter/ww8/docxattributeoutput.hxx | 3 - 4 files changed, 72 insertions(+), 3 deletions(-)
New commits: commit 0fb3bdc5d3aa47a61affc67b20bdbb775808fb66 Author: Tushar Bende <tushar.be...@synerzip.com> Date: Fri Feb 14 15:29:30 2014 +0530 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 diff --git a/sw/qa/extras/ooxmlexport/data/testPageref.docx b/sw/qa/extras/ooxmlexport/data/testPageref.docx new file mode 100644 index 0000000..65ca38a Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/testPageref.docx differ diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx index 6826a4d..db7811c 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 77ee13e..44372b6 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 dd24e2f..b311f1d 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; _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits