diff options
author | Tünde Tóth <tundeth@gmail.com> | 2019-09-18 10:13:50 +0200 |
---|---|---|
committer | László Németh <nemeth@numbertext.org> | 2019-09-23 13:12:41 +0200 |
commit | 89ffe6149a0e14bcde89d7981362aa1556849ab0 (patch) | |
tree | a2badebbf25021269e45eaadfac5897bf2aa34b1 /sw | |
parent | e265c9134ce0fc227781303f2bbffabcbe322ded (diff) |
tdf#127605 DOCX export: fix internal hyperlinks to image target
jumping to the paragraph anchored by the image as a workaround.
Change-Id: Iff4feacca0cc9c790028d72fb834e8cf066c95e1
Reviewed-on: https://gerrit.libreoffice.org/79081
Reviewed-by: László Németh <nemeth@numbertext.org>
Tested-by: László Németh <nemeth@numbertext.org>
Diffstat (limited to 'sw')
-rw-r--r-- | sw/inc/ndindex.hxx | 1 | ||||
-rw-r--r-- | sw/qa/extras/ooxmlexport/data/tdf127605.odt | bin | 0 -> 9958 bytes | |||
-rw-r--r-- | sw/qa/extras/ooxmlexport/ooxmlexport13.cxx | 11 | ||||
-rw-r--r-- | sw/source/filter/ww8/docxattributeoutput.cxx | 2 | ||||
-rw-r--r-- | sw/source/filter/ww8/wrtw8nds.cxx | 3 | ||||
-rw-r--r-- | sw/source/filter/ww8/wrtww8.cxx | 32 |
6 files changed, 40 insertions, 9 deletions
diff --git a/sw/inc/ndindex.hxx b/sw/inc/ndindex.hxx index 95f1f7354ac5..274bc4b2014c 100644 --- a/sw/inc/ndindex.hxx +++ b/sw/inc/ndindex.hxx @@ -115,6 +115,7 @@ public: inline const SwNodes& GetNodes() const; inline SwNodes& GetNodes(); + SwNodeIndex* GetNext() { return GetNextInRing(); } SwNode& GetNode() const { return *m_pNode; } }; diff --git a/sw/qa/extras/ooxmlexport/data/tdf127605.odt b/sw/qa/extras/ooxmlexport/data/tdf127605.odt Binary files differnew file mode 100644 index 000000000000..583f7fdeeb42 --- /dev/null +++ b/sw/qa/extras/ooxmlexport/data/tdf127605.odt diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx index ad5aec4e6d39..dc237f18ac4d 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx @@ -753,6 +753,17 @@ DECLARE_OOXMLEXPORT_TEST(testTdf127362, "tdf127362.odt") CPPUNIT_ASSERT_EQUAL(anchor, bookmarkName); } +DECLARE_OOXMLEXPORT_TEST(testTdf127605, "tdf127605.odt") +{ + xmlDocPtr pXmlDoc = parseExport("word/document.xml"); + if (!pXmlDoc) + return; + + OUString bookmarkName = getXPath(pXmlDoc, "/w:document/w:body/w:p[2]/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 77f12ac20a7c..f4812c4613ec 100644 --- a/sw/source/filter/ww8/docxattributeoutput.cxx +++ b/sw/source/filter/ww8/docxattributeoutput.cxx @@ -2914,7 +2914,7 @@ bool DocxAttributeOutput::StartURL( const OUString& rUrl, const OUString& rTarge } } } - if (sMark.indexOf(' ') != -1 && !sMark.endsWith("|table") && !sMark.endsWith("|frame") && !sMark.endsWith("|graphic") && !sMark.endsWith("|ole") && !sMark.endsWith("|region")) + if (sMark.indexOf(' ') != -1 && !sMark.endsWith("|table") && !sMark.endsWith("|frame") && !sMark.endsWith("|ole") && !sMark.endsWith("|region")) { // Spaces are prohibited in bookmark name. sMark = sMark.replace(' ', '_'); diff --git a/sw/source/filter/ww8/wrtw8nds.cxx b/sw/source/filter/ww8/wrtw8nds.cxx index da3726c980e3..eb81d0105db3 100644 --- a/sw/source/filter/ww8/wrtw8nds.cxx +++ b/sw/source/filter/ww8/wrtw8nds.cxx @@ -917,7 +917,7 @@ bool AttributeOutputBase::AnalyzeURL( const OUString& rUrl, const OUString& /*rT OUString()); // #i21465# Only interested in outline references - if ( sRefType == "outline" ) + if ( sRefType == "outline" || sRefType == "graphic" ) { OUString sLink = sMark.copy(0, nPos); for ( const auto& rBookmarkPair : GetExport().m_aImplicitBookmarks ) @@ -925,6 +925,7 @@ bool AttributeOutputBase::AnalyzeURL( const OUString& rUrl, const OUString& /*rT if ( rBookmarkPair.first == sLink ) { sMark = "_toc" + OUString::number( rBookmarkPair.second ); + break; } } } diff --git a/sw/source/filter/ww8/wrtww8.cxx b/sw/source/filter/ww8/wrtww8.cxx index 42f7b7e4f29f..763038abcb4d 100644 --- a/sw/source/filter/ww8/wrtww8.cxx +++ b/sw/source/filter/ww8/wrtww8.cxx @@ -3066,23 +3066,41 @@ void MSWordExportBase::AddLinkTarget(const OUString& rURL) return; sCmp = sCmp.toAsciiLowerCase(); + OUString aName; + sal_uLong nIdx = 0; + bool noBookmark = false; if( sCmp == "outline" ) { SwPosition aPos( *m_pCurPam->GetPoint() ); - OUString aOutline( BookmarkToWriter(aURL.copy( 0, nPos )) ); + aName = BookmarkToWriter(aURL.copy(0, nPos)); // If we can find the outline this bookmark refers to // save the name of the bookmark and the // node index number of where it points to - if( m_pDoc->GotoOutline( aPos, aOutline ) ) + if( m_pDoc->GotoOutline( aPos, aName ) ) { - sal_uLong nIdx = aPos.nNode.GetIndex(); - aBookmarkPair aImplicitBookmark; - aImplicitBookmark.first = aOutline; - aImplicitBookmark.second = nIdx; - m_aImplicitBookmarks.push_back(aImplicitBookmark); + nIdx = aPos.nNode.GetIndex(); + noBookmark = true; } } + else if( sCmp == "graphic" ) + { + SwNodeIndex* pIdx; + aName = BookmarkToWriter(aURL.copy( 0, nPos )); + const SwFlyFrameFormat* pFormat = m_pDoc->FindFlyByName(aName, SwNodeType::Grf); + if (pFormat && nullptr != (pIdx = const_cast<SwNodeIndex*>(pFormat->GetContent().GetContentIdx()))) + { + nIdx = pIdx->GetNext()->GetIndex(); + noBookmark = true; + } + } + if (noBookmark) + { + aBookmarkPair aImplicitBookmark; + aImplicitBookmark.first = aName; + aImplicitBookmark.second = nIdx; + m_aImplicitBookmarks.push_back(aImplicitBookmark); + } } void MSWordExportBase::CollectOutlineBookmarks(const SwDoc &rDoc) |