diff options
author | Tushar Bende <tushar.bende@synerzip.com> | 2014-01-22 20:00:17 +0530 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.co.uk> | 2014-02-07 10:43:52 +0100 |
commit | 138bd3d656c30911d5f45a8b6804e50857f6b30c (patch) | |
tree | 587267e0f86bc23b1cf0260a57a682056ed65824 /sw | |
parent | 0443d296720971697c48453912cc9ffb742f8640 (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.
Conflicts:
sw/qa/extras/ooxmlexport/ooxmlexport.cxx
Reviewed on:
https://gerrit.libreoffice.org/7605
Change-Id: I1785360684d8772b71c3f45fdd2c654f94777067
Diffstat (limited to 'sw')
-rw-r--r-- | sw/qa/extras/ooxmlexport/data/testPageref.docx | bin | 0 -> 26321 bytes | |||
-rw-r--r-- | sw/qa/extras/ooxmlexport/ooxmlexport.cxx | 16 | ||||
-rw-r--r-- | sw/source/filter/ww8/docxattributeoutput.cxx | 47 | ||||
-rw-r--r-- | sw/source/filter/ww8/docxattributeoutput.hxx | 3 |
4 files changed, 63 insertions, 3 deletions
diff --git a/sw/qa/extras/ooxmlexport/data/testPageref.docx b/sw/qa/extras/ooxmlexport/data/testPageref.docx Binary files differnew file mode 100644 index 000000000000..65ca38aedd57 --- /dev/null +++ b/sw/qa/extras/ooxmlexport/data/testPageref.docx diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx index 3c1d9d81383c..a192a3d6cc35 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx @@ -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(); diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx index 6e0b428896a1..46d862e322ce 100644 --- a/sw/source/filter/ww8/docxattributeoutput.cxx +++ b/sw/source/filter/ww8/docxattributeoutput.cxx @@ -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 ), diff --git a/sw/source/filter/ww8/docxattributeoutput.hxx b/sw/source/filter/ww8/docxattributeoutput.hxx index 3466f3dd2dfc..5c628c6f50ad 100644 --- a/sw/source/filter/ww8/docxattributeoutput.hxx +++ b/sw/source/filter/ww8/docxattributeoutput.hxx @@ -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; |