From dd873175affb7926befb1b8a0a881540d00160df Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Mon, 25 Mar 2024 07:47:15 +0200 Subject: try to use more reliable mechanism in AddLinkTarget MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The commit that introduces this code says commit 89ffe6149a0e14bcde89d7981362aa1556849ab0 Author: Tünde Tóth Date: Wed Sep 18 10:13:50 2019 +0200 tdf#127605 DOCX export: fix internal hyperlinks to image target jumping to the paragraph anchored by the image as a workaround. But using the SwNodeIndex ring to do this only works by accident, there is no guarantee that the SwNodeIndex is organised in any way at all. Change-Id: I9f886522ddf83b6799da9dd3d1f27e4b6c44bdc0 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/165264 Tested-by: Jenkins Reviewed-by: Noel Grandin --- sw/source/filter/ww8/wrtww8.cxx | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'sw/source') diff --git a/sw/source/filter/ww8/wrtww8.cxx b/sw/source/filter/ww8/wrtww8.cxx index 72ed190b4ec2..b252e4d1533d 100644 --- a/sw/source/filter/ww8/wrtww8.cxx +++ b/sw/source/filter/ww8/wrtww8.cxx @@ -118,6 +118,7 @@ #include #include #include +#include using namespace css; using namespace sw::util; @@ -3280,8 +3281,11 @@ void MSWordExportBase::AddLinkTarget(std::u16string_view rURL) { OUString aName(BookmarkToWriter(aURL.subView(0, nPos))); if (const SwFlyFrameFormat* pFormat = m_rDoc.FindFlyByName(aName, SwNodeType::Grf)) - if (const SwNodeIndex* pIdx = pFormat->GetContent().GetContentIdx()) - m_aImplicitBookmarks.emplace_back(aURL, pIdx->GetNext()->GetIndex()); + { + const SwFormatAnchor& rFormatAnchor = pFormat->GetAnchor(); + if (SwNode* pAnchorNode = rFormatAnchor.GetAnchorNode()) + m_aImplicitBookmarks.emplace_back(aURL, pAnchorNode->GetIndex()); + } } else if( sCmp == "frame" ) { @@ -3294,8 +3298,11 @@ void MSWordExportBase::AddLinkTarget(std::u16string_view rURL) { OUString aName(BookmarkToWriter(aURL.subView(0, nPos))); if (const SwFlyFrameFormat* pFormat = m_rDoc.FindFlyByName(aName, SwNodeType::Ole)) - if (const SwNodeIndex* pIdx = pFormat->GetContent().GetContentIdx()) - m_aImplicitBookmarks.emplace_back(aURL, pIdx->GetNext()->GetIndex()); + { + const SwFormatAnchor& rFormatAnchor = pFormat->GetAnchor(); + if (SwNode* pAnchorNode = rFormatAnchor.GetAnchorNode()) + m_aImplicitBookmarks.emplace_back(aURL, pAnchorNode->GetIndex()); + } } else if( sCmp == "region" ) { -- cgit