sw/inc/ToxLinkProcessor.hxx | 2 +- sw/qa/core/test_ToxLinkProcessor.cxx | 14 +++++++------- sw/source/core/tox/ToxLinkProcessor.cxx | 3 ++- sw/source/core/tox/ToxTextGenerator.cxx | 30 ++++++++++++++++++------------ 4 files changed, 28 insertions(+), 21 deletions(-)
New commits: commit a2efe54a1d813b852763479a351a1045bc5c9027 Author: Tomaž Vajngerl <[email protected]> AuthorDate: Wed Jul 9 10:13:55 2025 +0200 Commit: Xisco Fauli <[email protected]> CommitDate: Wed Jul 9 22:25:44 2025 +0200 tdf#167409 set alt. text to the internal hyperlinks in a TOC The alt. text that is set is the TOC entry text. Change-Id: I8a9012cd7a6155f0672e0e8019ec1183d01cdcb6 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/187556 Reviewed-by: Tomaž Vajngerl <[email protected]> Tested-by: Jenkins (cherry picked from commit e2be650d97765945538614463b9269acb164947c) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/187598 Reviewed-by: Xisco Fauli <[email protected]> diff --git a/sw/inc/ToxLinkProcessor.hxx b/sw/inc/ToxLinkProcessor.hxx index 86521cb42632..d3b800ca7050 100644 --- a/sw/inc/ToxLinkProcessor.hxx +++ b/sw/inc/ToxLinkProcessor.hxx @@ -41,7 +41,7 @@ public: * STR_POOLCHR_TOXJUMP. */ void - CloseLink(sal_Int32 endPosition, const OUString& url, bool bRelative); + CloseLink(sal_Int32 endPosition, const OUString& url, const OUString& sText, bool bRelative); /** Insert the found links as attributes to a text node */ void diff --git a/sw/qa/core/test_ToxLinkProcessor.cxx b/sw/qa/core/test_ToxLinkProcessor.cxx index b143806cdc59..a44626fe7540 100644 --- a/sw/qa/core/test_ToxLinkProcessor.cxx +++ b/sw/qa/core/test_ToxLinkProcessor.cxx @@ -56,11 +56,11 @@ ToxLinkProcessorTest::NoExceptionIsThrownIfTooManyLinksAreClosed() { ToxLinkProcessor sut; sut.StartNewLink(0, UIName(STYLE_NAME_1)); - sut.CloseLink(1, URL_1, /*bRelative=*/true); + sut.CloseLink(1, URL_1, OUString(), /*bRelative=*/true); // fdo#85872 actually it turns out the UI does something like this // so an exception must not be thrown! // should not succeed either (for backward compatibility) - sut.CloseLink(2, URL_1, /*bRelative=*/true); + sut.CloseLink(2, URL_1, OUString(), /*bRelative=*/true); CPPUNIT_ASSERT_EQUAL(1u, static_cast<unsigned>(sut.m_ClosedLinks.size())); CPPUNIT_ASSERT_EQUAL(1u, static_cast<unsigned>(sut.m_ClosedLinks.at(0)->mEndTextPos)); CPPUNIT_ASSERT_MESSAGE("no links are open", !sut.m_oStartedLink); @@ -72,10 +72,10 @@ ToxLinkProcessorTest::AddingAndClosingTwoOverlappingLinksResultsInOneClosedLink( ToxLinkProcessor sut; sut.StartNewLink(0, UIName(STYLE_NAME_1)); sut.StartNewLink(0, UIName(STYLE_NAME_2)); - sut.CloseLink(1, URL_1, /*bRelative=*/true); + sut.CloseLink(1, URL_1, OUString(), /*bRelative=*/true); // this should not cause an error, and should not succeed either // (for backward compatibility) - sut.CloseLink(1, URL_2, /*bRelative=*/true); + sut.CloseLink(1, URL_2, OUString(), /*bRelative=*/true); CPPUNIT_ASSERT_EQUAL(1u, static_cast<unsigned>(sut.m_ClosedLinks.size())); CPPUNIT_ASSERT_MESSAGE("no links are open", !sut.m_oStartedLink); // backward compatibility: the last start is closed by the first end @@ -108,7 +108,7 @@ ToxLinkProcessorTest::LinkIsCreatedCorrectly() ToxLinkProcessorWithOverriddenObtainPoolId sut; sut.StartNewLink(0, UIName(STYLE_NAME_1)); - sut.CloseLink(1, URL_1, /*bRelative=*/true); + sut.CloseLink(1, URL_1, OUString(), /*bRelative=*/true); CPPUNIT_ASSERT_EQUAL_MESSAGE("Style is stored correctly in link", STYLE_NAME_1, sut.m_ClosedLinks.at(0)->mINetFormat.GetVisitedFormat().toString()); CPPUNIT_ASSERT_EQUAL_MESSAGE("Url is stored correctly in link", URL_1, sut.m_ClosedLinks.at(0)->mINetFormat.GetValue()); @@ -122,9 +122,9 @@ ToxLinkProcessorTest::LinkSequenceIsPreserved() ToxLinkProcessorWithOverriddenObtainPoolId sut; sut.StartNewLink(0, UIName(STYLE_NAME_2)); - sut.CloseLink(1, URL_2, /*bRelative=*/true); + sut.CloseLink(1, URL_2, OUString(), /*bRelative=*/true); sut.StartNewLink(1, UIName(STYLE_NAME_1)); - sut.CloseLink(2, URL_1, /*bRelative=*/true); + sut.CloseLink(2, URL_1, OUString(), /*bRelative=*/true); // check first closed element CPPUNIT_ASSERT_EQUAL_MESSAGE("Style is stored correctly in link", diff --git a/sw/source/core/tox/ToxLinkProcessor.cxx b/sw/source/core/tox/ToxLinkProcessor.cxx index 062bab30a6b8..498294eefe09 100644 --- a/sw/source/core/tox/ToxLinkProcessor.cxx +++ b/sw/source/core/tox/ToxLinkProcessor.cxx @@ -24,7 +24,7 @@ ToxLinkProcessor::StartNewLink(sal_Int32 startPosition, const UIName& characterS m_oStartedLink.emplace(startPosition, characterStyle); } -void ToxLinkProcessor::CloseLink(sal_Int32 endPosition, const OUString& url, bool bRelative) +void ToxLinkProcessor::CloseLink(sal_Int32 endPosition, const OUString& url, const OUString& sAltText, bool bRelative) { if (!m_oStartedLink) { @@ -58,6 +58,7 @@ void ToxLinkProcessor::CloseLink(sal_Int32 endPosition, const OUString& url, boo sal_uInt16 poolId = ObtainPoolId(characterStyle); pClosedLink->mINetFormat.SetVisitedFormatAndId(characterStyle, poolId); pClosedLink->mINetFormat.SetINetFormatAndId(characterStyle, poolId); + pClosedLink->mINetFormat.SetName(sAltText); m_ClosedLinks.push_back(std::move(pClosedLink)); m_oStartedLink.reset(); diff --git a/sw/source/core/tox/ToxTextGenerator.cxx b/sw/source/core/tox/ToxTextGenerator.cxx index 2ee7533cebdc..6c19a6cd54d0 100644 --- a/sw/source/core/tox/ToxTextGenerator.cxx +++ b/sw/source/core/tox/ToxTextGenerator.cxx @@ -178,6 +178,7 @@ ToxTextGenerator::GenerateText(SwDoc& rDoc, // FIXME this operates directly on the node text OUString & rText = const_cast<OUString&>(pTOXNd->GetText()); rText.clear(); + OUString rAltText; for(sal_uInt16 nIndex = indexOfEntryToProcess; nIndex < indexOfEntryToProcess + numberOfEntriesToProcess; nIndex++) { if(nIndex > indexOfEntryToProcess) @@ -210,22 +211,26 @@ ToxTextGenerator::GenerateText(SwDoc& rDoc, i < aPattern.size() - 1 && aPattern[i + 1].eTokenType == TOKEN_ENTRY_TEXT); break; - case TOKEN_ENTRY_TEXT: { + case TOKEN_ENTRY_TEXT: + { HandledTextToken htt = HandleTextToken(rBase, rDoc.GetAttrPool(), pLayout); ApplyHandledTextToken(htt, *pTOXNd); + rAltText += htt.text; } - break; + break; case TOKEN_ENTRY: - { - // for TOC numbering - rText += GetNumStringOfFirstNode(rBase, true, MAXLEVEL, pLayout); - HandledTextToken htt = HandleTextToken(rBase, rDoc.GetAttrPool(), pLayout); - ApplyHandledTextToken(htt, *pTOXNd); - } - break; + { + // for TOC numbering + rText += GetNumStringOfFirstNode(rBase, true, MAXLEVEL, pLayout); + HandledTextToken htt = HandleTextToken(rBase, rDoc.GetAttrPool(), pLayout); + ApplyHandledTextToken(htt, *pTOXNd); + rAltText += htt.text; + } + break; - case TOKEN_TAB_STOP: { + case TOKEN_TAB_STOP: + { ToxTabStopTokenHandler::HandledTabStopToken htst = mTabStopTokenHandler->HandleTabStopToken(aToken, *pTOXNd); rText += htst.text; @@ -247,6 +252,7 @@ ToxTextGenerator::GenerateText(SwDoc& rDoc, case TOKEN_LINK_START: mLinkProcessor->StartNewLink(rText.getLength(), aToken.sCharStyleName); + rAltText = ""; break; case TOKEN_LINK_END: @@ -259,7 +265,7 @@ ToxTextGenerator::GenerateText(SwDoc& rDoc, ++iter->second; url = "#" + OUString::number(iter->second) + url; } - mLinkProcessor->CloseLink(rText.getLength(), url, /*bRelative=*/true); + mLinkProcessor->CloseLink(rText.getLength(), url, rAltText, /*bRelative=*/true); } break; @@ -280,7 +286,7 @@ ToxTextGenerator::GenerateText(SwDoc& rDoc, OUString aURL = SwTOXAuthority::GetSourceURL( rAuthority.GetText(AUTH_FIELD_URL, pLayout)); - mLinkProcessor->CloseLink(rText.getLength(), aURL, /*bRelative=*/false); + mLinkProcessor->CloseLink(rText.getLength(), aURL, rAltText, /*bRelative=*/false); } } break;
