[Libreoffice-commits] core.git: sw/source
Miklos Vajna (via logerrit)
logerrit at kemper.freedesktop.org
Tue Apr 20 13:25:48 UTC 2021
sw/source/core/tox/ToxTextGenerator.cxx | 6 +++++-
sw/source/core/tox/txmsrt.cxx | 31 +++++++++++++++++++++++++++++++
2 files changed, 36 insertions(+), 1 deletion(-)
New commits:
commit 0ae159cc40b837a6a47acaf9240dc350fe68d49d
Author: Miklos Vajna <vmiklos at collabora.com>
AuthorDate: Tue Apr 20 11:03:19 2021 +0200
Commit: Miklos Vajna <vmiklos at collabora.com>
CommitDate: Tue Apr 20 15:25:01 2021 +0200
sw bibliography table, text generator: handle relative URLs
Now that the doc model always contains absolute URLs, it is possible to
decide when it does and when it doesn't make sense to convert to
relative URLs.
The bibliography table does a mixed approach: the document text depends
on configuration (relative by default), but the underlying URL is an
absolute one. This way it's always clickable and the ODT filter can save
it as a relative one (again, depending on configuration).
With this, all fields are meant to be clickable: biblio field vs biblio
table, relative or absolute ones, with or with a (page) fragment, Writer
UI vs PDF export.
Change-Id: Ib6879709314fa127094faf7fa615fe57289b41f1
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/114299
Reviewed-by: Miklos Vajna <vmiklos at collabora.com>
Tested-by: Jenkins
diff --git a/sw/source/core/tox/ToxTextGenerator.cxx b/sw/source/core/tox/ToxTextGenerator.cxx
index 95952aa06cd2..df37f294796b 100644
--- a/sw/source/core/tox/ToxTextGenerator.cxx
+++ b/sw/source/core/tox/ToxTextGenerator.cxx
@@ -268,7 +268,11 @@ ToxTextGenerator::GenerateText(SwDoc* pDoc,
rBase.FillText( *pTOXNd, aIdx, static_cast<sal_uInt16>(eField), pLayout );
if (eField == ToxAuthorityField::AUTH_FIELD_URL)
{
- OUString aURL(rText.subView(nStartCharStyle));
+ // Get the absolute URL, the text may be a relative one.
+ const auto& rAuthority = static_cast<const SwTOXAuthority&>(rBase);
+ OUString aURL = SwTOXAuthority::GetSourceURL(
+ rAuthority.GetText(AUTH_FIELD_URL, pLayout));
+
mLinkProcessor->CloseLink(rText.getLength(), aURL, /*bRelative=*/false);
}
}
diff --git a/sw/source/core/tox/txmsrt.cxx b/sw/source/core/tox/txmsrt.cxx
index 193dc1d48a71..e0ffc1922701 100644
--- a/sw/source/core/tox/txmsrt.cxx
+++ b/sw/source/core/tox/txmsrt.cxx
@@ -23,6 +23,7 @@
#include <osl/diagnose.h>
#include <tools/urlobj.hxx>
#include <comphelper/processfactory.hxx>
+#include <officecfg/Office/Common.hxx>
#include <txtfld.hxx>
#include <doc.hxx>
#include <IDocumentLayoutAccess.hxx>
@@ -878,6 +879,36 @@ void SwTOXAuthority::FillText(SwTextNode& rNd, const SwIndex& rInsPos, sal_uInt1
if (nAuthField == AUTH_FIELD_URL)
{
aText = GetSourceURL(aText);
+
+ // Convert URL to a relative one if requested.
+ SwDoc* pDoc = static_cast<SwAuthorityFieldType*>(m_rField.GetField()->GetTyp())->GetDoc();
+ SwDocShell* pDocShell = pDoc->GetDocShell();
+ OUString aBaseURL = pDocShell->getDocumentBaseURL();
+ OUString aBaseURIScheme;
+ sal_Int32 nSep = aBaseURL.indexOf(':');
+ if (nSep != -1)
+ {
+ aBaseURIScheme = aBaseURL.copy(0, nSep);
+ }
+
+ uno::Reference<uri::XUriReferenceFactory> xUriReferenceFactory
+ = uri::UriReferenceFactory::create(comphelper::getProcessComponentContext());
+ uno::Reference<uri::XUriReference> xUriRef;
+ try
+ {
+ xUriRef = xUriReferenceFactory->parse(aText);
+ }
+ catch (const uno::Exception& rException)
+ {
+ SAL_WARN("sw.core",
+ "SwTOXAuthority::FillText: failed to parse url: " << rException.Message);
+ }
+
+ bool bSaveRelFSys = officecfg::Office::Common::Save::URL::FileSystem::get();
+ if (xUriRef.is() && bSaveRelFSys && xUriRef->getScheme() == aBaseURIScheme)
+ {
+ aText = INetURLObject::GetRelURL(aBaseURL, aText);
+ }
}
rNd.InsertText(aText, rInsPos);
More information about the Libreoffice-commits
mailing list