summaryrefslogtreecommitdiff
path: root/sw/source/core/text
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2021-03-24 13:36:59 +0100
committerMiklos Vajna <vmiklos@collabora.com>2021-03-24 16:35:40 +0100
commitfb20b6182807885f9fa9b95baa69fed0091fec7d (patch)
tree9b395e46b76453e35ac29592c32bc80b35dece78 /sw/source/core/text
parent31913141d2bcc3b3a8bfb6d018fbf142bd81bf58 (diff)
sw bibliography, refer to a page: add PDF export links
This is similar to hyperlinks or footnote references, but the source rectangle is a field here and still the links are always external. With this, the UI and the PDF export result is consistent, it doesn't happen that you can click on biblio entry fields on the UI, but not in the PDF export result. Change-Id: I655ef6d5f79a7e372cdc8448ddc10af9ca488ac5 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/113035 Reviewed-by: Miklos Vajna <vmiklos@collabora.com> Tested-by: Jenkins
Diffstat (limited to 'sw/source/core/text')
-rw-r--r--sw/source/core/text/EnhancedPDFExportHelper.cxx62
1 files changed, 62 insertions, 0 deletions
diff --git a/sw/source/core/text/EnhancedPDFExportHelper.cxx b/sw/source/core/text/EnhancedPDFExportHelper.cxx
index 29719590dc4c..51785be1a1c4 100644
--- a/sw/source/core/text/EnhancedPDFExportHelper.cxx
+++ b/sw/source/core/text/EnhancedPDFExportHelper.cxx
@@ -79,6 +79,7 @@
#include <frmtool.hxx>
#include <strings.hrc>
#include <frameformats.hxx>
+#include <authfld.hxx>
#include <tools/globname.hxx>
#include <svx/svdobj.hxx>
@@ -1923,6 +1924,8 @@ void SwEnhancedPDFExportHelper::EnhancedPDFExport()
mrSh.SwCursorShell::ClearMark();
}
+ ExportAuthorityEntryLinks();
+
// FOOTNOTES
const size_t nFootnoteCount = pDoc->GetFootnoteIdxs().size();
@@ -2162,6 +2165,65 @@ void SwEnhancedPDFExportHelper::EnhancedPDFExport()
mrOut.Pop();
}
+void SwEnhancedPDFExportHelper::ExportAuthorityEntryLinks()
+{
+ auto pPDFExtOutDevData = dynamic_cast<vcl::PDFExtOutDevData*>(mrOut.GetExtOutDevData());
+ if (!pPDFExtOutDevData)
+ {
+ return;
+ }
+
+ std::vector<SwFormatField*> aFields;
+ SwFieldType* pType = mrSh.GetFieldType(SwFieldIds::TableOfAuthorities, OUString());
+ if (!pType)
+ {
+ return;
+ }
+
+ pType->GatherFields(aFields);
+ const auto pPageFrame = static_cast<const SwPageFrame*>(mrSh.GetLayout()->Lower());
+ for (const auto pFormatField : aFields)
+ {
+ if (!pFormatField->GetTextField() || !pFormatField->IsFieldInDoc())
+ {
+ continue;
+ }
+
+ const auto& rAuthorityField
+ = *static_cast<const SwAuthorityField*>(pFormatField->GetField());
+ if (!rAuthorityField.HasURL())
+ {
+ continue;
+ }
+
+ const OUString& rURL = rAuthorityField.GetAuthEntry()->GetAuthorField(AUTH_FIELD_URL);
+ const SwTextNode& rTextNode = pFormatField->GetTextField()->GetTextNode();
+ if (!lcl_TryMoveToNonHiddenField(mrSh, rTextNode, *pFormatField))
+ {
+ continue;
+ }
+
+ // Select the field.
+ mrSh.SwCursorShell::SetMark();
+ mrSh.SwCursorShell::Right(1, CRSR_SKIP_CHARS);
+
+ // Create the links.
+ for (const auto& rLinkRect : *mrSh.SwCursorShell::GetCursor_())
+ {
+ for (const auto& rLinkPageNum : CalcOutputPageNums(rLinkRect))
+ {
+ tools::Rectangle aRect(SwRectToPDFRect(pPageFrame, rLinkRect.SVRect()));
+ sal_Int32 nLinkId = pPDFExtOutDevData->CreateLink(aRect, rLinkPageNum);
+ IdMapEntry aLinkEntry(rLinkRect, nLinkId);
+ s_aLinkIdMap.push_back(aLinkEntry);
+ pPDFExtOutDevData->SetLinkURL(nLinkId, rURL);
+ }
+ }
+
+ mrSh.SwCursorShell::ClearMark();
+ }
+}
+
// Returns the page number in the output pdf on which the given rect is located.
// If this page is duplicated, method will return first occurrence of it.
sal_Int32 SwEnhancedPDFExportHelper::CalcOutputPageNum( const SwRect& rRect ) const