From 5d5ec2a1ffe3862cc9689e667cebf1f9c1a5f330 Mon Sep 17 00:00:00 2001 From: Tünde Tóth Date: Wed, 25 Sep 2019 12:10:16 +0200 Subject: tdf#127735 DOCX export: fix internal hyperlinks to table target MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Hyperlinks with internal table targets didn't work in Microsoft Word. Change-Id: I93b2b38d3d0196939f7aa5021811d2a9d5e482f5 Reviewed-on: https://gerrit.libreoffice.org/79524 Tested-by: Jenkins Reviewed-by: László Németh --- .../extras/ooxmlexport/data/internal_hyperlink_table.odt | Bin 0 -> 8866 bytes sw/qa/extras/ooxmlexport/ooxmlexport13.cxx | 11 +++++++++++ sw/source/filter/ww8/docxattributeoutput.cxx | 7 ++----- sw/source/filter/ww8/wrtw8nds.cxx | 3 ++- sw/source/filter/ww8/wrtww8.cxx | 14 ++++++++++++++ 5 files changed, 29 insertions(+), 6 deletions(-) create mode 100644 sw/qa/extras/ooxmlexport/data/internal_hyperlink_table.odt diff --git a/sw/qa/extras/ooxmlexport/data/internal_hyperlink_table.odt b/sw/qa/extras/ooxmlexport/data/internal_hyperlink_table.odt new file mode 100644 index 000000000000..f3144a30e5a3 Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/internal_hyperlink_table.odt differ diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx index d13b7bf90144..ec8635943f4d 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx @@ -804,6 +804,17 @@ DECLARE_OOXMLEXPORT_TEST(testTdf127734, "internal_hyperlink_region.odt") CPPUNIT_ASSERT_EQUAL(anchor, bookmarkName); } +DECLARE_OOXMLEXPORT_TEST(testTdf127735, "internal_hyperlink_table.odt") +{ + xmlDocPtr pXmlDoc = parseExport("word/document.xml"); + if (!pXmlDoc) + return; + + OUString bookmarkName = getXPath(pXmlDoc, "/w:document/w:body/w:tbl/w:tr[1]/w:tc[1]/w:p/w:bookmarkStart", "name"); + OUString anchor = getXPath(pXmlDoc, "/w:document/w:body/w:p[1]/w:hyperlink", "anchor"); + CPPUNIT_ASSERT_EQUAL(anchor, bookmarkName); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx index f9f7c3c94c14..79d82b72c7a6 100644 --- a/sw/source/filter/ww8/docxattributeoutput.cxx +++ b/sw/source/filter/ww8/docxattributeoutput.cxx @@ -2914,11 +2914,8 @@ bool DocxAttributeOutput::StartURL( const OUString& rUrl, const OUString& rTarge } } } - if (sMark.indexOf(' ') != -1 && !sMark.endsWith("|table")) - { - // Spaces are prohibited in bookmark name. - sMark = sMark.replace(' ', '_'); - } + // Spaces are prohibited in bookmark name. + sMark = sMark.replace(' ', '_'); m_pHyperlinkAttrList->add( FSNS( XML_w, XML_anchor ), OUStringToOString( sMark, RTL_TEXTENCODING_UTF8 ).getStr( ) ); } diff --git a/sw/source/filter/ww8/wrtw8nds.cxx b/sw/source/filter/ww8/wrtw8nds.cxx index b80f94656704..b722b22621d3 100644 --- a/sw/source/filter/ww8/wrtw8nds.cxx +++ b/sw/source/filter/ww8/wrtw8nds.cxx @@ -917,7 +917,8 @@ bool AttributeOutputBase::AnalyzeURL( const OUString& rUrl, const OUString& /*rT OUString()); // #i21465# Only interested in outline references - if ( !sRefType.isEmpty() && (sRefType == "outline" || sRefType == "graphic" || sRefType == "frame" || sRefType == "ole" || sRefType == "region") ) + if ( !sRefType.isEmpty() && + (sRefType == "outline" || sRefType == "graphic" || sRefType == "frame" || sRefType == "ole" || sRefType == "region" || sRefType == "table") ) { for ( const auto& rBookmarkPair : GetExport().m_aImplicitBookmarks ) { diff --git a/sw/source/filter/ww8/wrtww8.cxx b/sw/source/filter/ww8/wrtww8.cxx index fcb168f68bf1..542d24d7a64b 100644 --- a/sw/source/filter/ww8/wrtww8.cxx +++ b/sw/source/filter/ww8/wrtww8.cxx @@ -3130,6 +3130,20 @@ void MSWordExportBase::AddLinkTarget(const OUString& rURL) } } } + else if( sCmp == "table" ) + { + OUString aName(BookmarkToWriter(aURL.copy(0, nPos))); + const SwTable* pTable = SwTable::FindTable(m_pDoc->FindTableFormatByName(aName)); + if (pTable) + { + SwTableNode* pTableNode = const_cast(pTable->GetTabSortBoxes()[1]->GetSttNd()->FindTableNode()); + if (pTableNode) + { + nIdx = pTableNode->GetIndex() + 2; + noBookmark = true; + } + } + } if (noBookmark) { aBookmarkPair aImplicitBookmark; -- cgit