sw/qa/core/text/data/tdf159924.odt              |binary
 sw/qa/core/text/text.cxx                        |   35 ++++++++++++++++++++++++
 sw/source/core/text/EnhancedPDFExportHelper.cxx |    4 ++
 3 files changed, 38 insertions(+), 1 deletion(-)

New commits:
commit a3ac49ebe78b7fc164dbc766492faee084bad254
Author:     Tibor Nagy <tibor.nagy.ext...@allotropia.de>
AuthorDate: Mon Jun 17 12:29:56 2024 +0200
Commit:     Nagy Tibor <tibor.nagy.ext...@allotropia.de>
CommitDate: Mon Jun 17 15:35:08 2024 +0200

    tdf#159924 sw: fix hyperlink name export to PDF
    
    If there is a Name attribute set for a hyperlink, the text is exported
    to PDF as tooltip.
    
    note: not every PDF reader displays this text
    
    Change-Id: Ib9f1c13403c1555bfae733d662754c0e052378f7
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/168993
    Tested-by: Jenkins
    Reviewed-by: Nagy Tibor <tibor.nagy.ext...@allotropia.de>

diff --git a/sw/qa/core/text/data/tdf159924.odt 
b/sw/qa/core/text/data/tdf159924.odt
new file mode 100644
index 000000000000..91fc53c194d5
Binary files /dev/null and b/sw/qa/core/text/data/tdf159924.odt differ
diff --git a/sw/qa/core/text/text.cxx b/sw/qa/core/text/text.cxx
index bde60587a7bb..933fb30f696f 100644
--- a/sw/qa/core/text/text.cxx
+++ b/sw/qa/core/text/text.cxx
@@ -182,6 +182,41 @@ CPPUNIT_TEST_FIXTURE(SwCoreTextTest, testTdf159903)
     CPPUNIT_ASSERT_EQUAL(SwTwips(2268), tm.Left() - 
pFrame->getFrameArea().Left());
 }
 
+CPPUNIT_TEST_FIXTURE(SwCoreTextTest, testTdf159924)
+{
+    createSwDoc("tdf159924.odt");
+    save(u"writer_pdf_Export"_ustr);
+
+    vcl::filter::PDFDocument aDocument;
+    SvFileStream aStream(maTempFile.GetURL(), StreamMode::READ);
+    CPPUNIT_ASSERT(aDocument.Read(aStream));
+
+    // The document has one page.
+    std::vector<vcl::filter::PDFObjectElement*> aPages = aDocument.GetPages();
+    CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), aPages.size());
+
+    auto pAnnots = 
dynamic_cast<vcl::filter::PDFArrayElement*>(aPages[0]->Lookup("Annots"_ostr));
+    CPPUNIT_ASSERT(pAnnots);
+    CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), 
pAnnots->GetElements().size());
+
+    auto pAnnotRef = 
dynamic_cast<vcl::filter::PDFReferenceElement*>(pAnnots->GetElements()[0]);
+    CPPUNIT_ASSERT(pAnnotRef);
+
+    vcl::filter::PDFObjectElement* pAnnot = pAnnotRef->LookupObject();
+    CPPUNIT_ASSERT(pAnnot);
+
+    auto aType = 
static_cast<vcl::filter::PDFNameElement*>(pAnnot->Lookup("Type"_ostr));
+    CPPUNIT_ASSERT_EQUAL("Annot"_ostr, aType->GetValue());
+
+    auto aSubType = 
static_cast<vcl::filter::PDFNameElement*>(pAnnot->Lookup("Subtype"_ostr));
+    CPPUNIT_ASSERT_EQUAL("Link"_ostr, aSubType->GetValue());
+
+    auto pCont = 
dynamic_cast<vcl::filter::PDFHexStringElement*>(pAnnot->Lookup("Contents"_ostr));
+    CPPUNIT_ASSERT(pCont);
+    OUString sContent = 
::vcl::filter::PDFDocument::DecodeHexStringUTF16BE(*pCont);
+    CPPUNIT_ASSERT_EQUAL(u"This link opens the LibreOffice website"_ustr, 
sContent);
+}
+
 CPPUNIT_TEST_FIXTURE(SwCoreTextTest, testTdf159336)
 {
     createSwDoc("tdf159336.odt");
diff --git a/sw/source/core/text/EnhancedPDFExportHelper.cxx 
b/sw/source/core/text/EnhancedPDFExportHelper.cxx
index e723b033e415..382b08622bbc 100644
--- a/sw/source/core/text/EnhancedPDFExportHelper.cxx
+++ b/sw/source/core/text/EnhancedPDFExportHelper.cxx
@@ -2227,7 +2227,9 @@ void 
SwEnhancedPDFExportHelper::EnhancedPDFExport(LanguageType const eLanguageDe
                     // be deleted again in JumpToSwMark.
                     SwRects const aTmp(GetCursorRectsContainingText(mrSh));
                     OSL_ENSURE( !aTmp.empty(), "Enhanced pdf export - 
rectangles are missing" );
-                    OUString const altText(mrSh.GetSelText());
+                    OUString altText(p->rINetAttr.GetINetFormat().GetName());
+                    if (altText.isEmpty())
+                        altText = mrSh.GetSelText();
 
                     const SwPageFrame* pSelectionPage =
                         static_cast<const SwPageFrame*>( 
mrSh.GetLayout()->Lower() );

Reply via email to