1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
11 #include <ToxLinkProcessor.hxx>
13 #include <SwStyleNameMapper.hxx>
15 #include <sal/log.hxx>
16 #include <rtl/uri.hxx>
21 ToxLinkProcessor::StartNewLink(sal_Int32 startPosition
, const OUString
& characterStyle
)
23 SAL_INFO_IF(m_oStartedLink
, "sw.core", "ToxLinkProcessor: LS without LE");
24 m_oStartedLink
.emplace(startPosition
, characterStyle
);
27 void ToxLinkProcessor::CloseLink(sal_Int32 endPosition
, const OUString
& url
, bool bRelative
)
31 SAL_INFO("sw.core", "ToxLinkProcessor: LE without LS");
42 // url contains '|' which must be encoded; also in some cases contains
43 // arbitrary strings that need to be encoded
44 assert(url
[0] == '#'); // all links are internal
46 + rtl::Uri::encode(url
.copy(1), rtl_UriCharClassUricNoSlash
,
47 rtl_UriEncodeIgnoreEscapes
, RTL_TEXTENCODING_UTF8
);
54 std::unique_ptr
<ClosedLink
> pClosedLink(
55 new ClosedLink(uri
, m_oStartedLink
->mStartPosition
, endPosition
));
57 const OUString
& characterStyle
= m_oStartedLink
->mCharacterStyle
;
58 sal_uInt16 poolId
= ObtainPoolId(characterStyle
);
59 pClosedLink
->mINetFormat
.SetVisitedFormatAndId(characterStyle
, poolId
);
60 pClosedLink
->mINetFormat
.SetINetFormatAndId(characterStyle
, poolId
);
62 m_ClosedLinks
.push_back(std::move(pClosedLink
));
63 m_oStartedLink
.reset();
67 ToxLinkProcessor::ObtainPoolId(const OUString
& characterStyle
) const
69 if (characterStyle
.isEmpty()) {
73 return SwStyleNameMapper::GetPoolIdFromUIName(characterStyle
, SwGetPoolIdFromName::ChrFmt
);
79 ToxLinkProcessor::InsertLinkAttributes(SwTextNode
& node
)
81 for (auto const& clink
: m_ClosedLinks
)
83 node
.InsertItem(clink
->mINetFormat
, clink
->mStartTextPos
, clink
->mEndTextPos
);
89 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */