vcl/qa/cppunit/pdfexport/data/tdf142133.docx |binary vcl/qa/cppunit/pdfexport/pdfexport.cxx | 35 ++++++++++++++++++++++ writerfilter/source/dmapper/DomainMapper_Impl.cxx | 23 ++++++++------ writerfilter/source/dmapper/DomainMapper_Impl.hxx | 3 + 4 files changed, 52 insertions(+), 9 deletions(-)
New commits: commit 5f025f9bab12d0f08c23cca08d12c15cca95e9ed Author: Xisco Fauli <xiscofa...@libreoffice.org> AuthorDate: Fri Mar 8 14:23:08 2024 +0100 Commit: Xisco Fauli <xiscofa...@libreoffice.org> CommitDate: Tue Mar 19 18:48:11 2024 +0100 tdf#142133: partially revert 576611895e5 if 'Internet Link' character style doens't exist then apply the hyperlink style This also reverts 023285158bde72dcd73b965ce205cf8550e7a5e2 "tdf#128504 save DOCX as ODT: don't color not highlighted hyperlinks" which is no longer necessary Change-Id: Id100af5fddb10745af9d56c0ba75cb2366ecbe55 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/164576 Tested-by: Jenkins Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org> (cherry picked from commit 03ca7031f3bf4c2a3e841b18c8f9e00004046098) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/164509 Reviewed-by: Stéphane Guillou <stephane.guil...@libreoffice.org> Signed-off-by: Xisco Fauli <xiscofa...@libreoffice.org> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/164711 diff --git a/vcl/qa/cppunit/pdfexport/data/tdf142133.docx b/vcl/qa/cppunit/pdfexport/data/tdf142133.docx new file mode 100644 index 000000000000..fa1e155b873e Binary files /dev/null and b/vcl/qa/cppunit/pdfexport/data/tdf142133.docx differ diff --git a/vcl/qa/cppunit/pdfexport/pdfexport.cxx b/vcl/qa/cppunit/pdfexport/pdfexport.cxx index 4113e160f1e7..d6ae5f527ab8 100644 --- a/vcl/qa/cppunit/pdfexport/pdfexport.cxx +++ b/vcl/qa/cppunit/pdfexport/pdfexport.cxx @@ -2706,6 +2706,41 @@ CPPUNIT_TEST_FIXTURE(PdfExportTest, testTdf157816Link) CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(4), pAnnots->GetElements().size()); } +CPPUNIT_TEST_FIXTURE(PdfExportTest, testTdf142133) +{ + vcl::filter::PDFDocument aDocument; + load(u"tdf142133.docx", aDocument); + + // 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")); + CPPUNIT_ASSERT(pAnnots); + + // There should be one annotation + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), pAnnots->GetElements().size()); + auto pAnnotReference + = dynamic_cast<vcl::filter::PDFReferenceElement*>(pAnnots->GetElements()[0]); + CPPUNIT_ASSERT(pAnnotReference); + vcl::filter::PDFObjectElement* pAnnot = pAnnotReference->LookupObject(); + CPPUNIT_ASSERT(pAnnot); + // We're expecting something like /Type /Annot /A << /Type /Action /S /URI /URI (path) + CPPUNIT_ASSERT_EQUAL( + OString("Annot"), + static_cast<vcl::filter::PDFNameElement*>(pAnnot->Lookup("Type"))->GetValue()); + CPPUNIT_ASSERT_EQUAL( + OString("Link"), + static_cast<vcl::filter::PDFNameElement*>(pAnnot->Lookup("Subtype"))->GetValue()); + auto pAction = dynamic_cast<vcl::filter::PDFDictionaryElement*>(pAnnot->Lookup("A")); + CPPUNIT_ASSERT(pAction); + auto pURIElem + = dynamic_cast<vcl::filter::PDFLiteralStringElement*>(pAction->LookupElement("URI")); + CPPUNIT_ASSERT(pURIElem); + // Check it matches + CPPUNIT_ASSERT_EQUAL(OString("https://google.com/"), pURIElem->GetValue()); +} + CPPUNIT_TEST_FIXTURE(PdfExportTest, testTdf142806) { aMediaDescriptor["FilterName"] <<= OUString("writer_pdf_Export"); diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx index bbdbb117556b..8997fc72637d 100644 --- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx +++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx @@ -3245,6 +3245,15 @@ void DomainMapper_Impl::applyToggleAttributes(const PropertyMapPtr& pPropertyMap } else { + if (IsOpenField() && GetTopFieldContext()->GetFieldId() == FIELD_HYPERLINK) + { + // It is content of hyperlink field. We need to create and remember + // character style for later applying to hyperlink + PropertyValueVector_t aProps = comphelper::sequenceToContainer< PropertyValueVector_t >(GetTopContext()->GetPropertyValues()); + OUString sHyperlinkStyleName = GetStyleSheetTable()->getOrCreateCharStyle(aProps, /*bAlwaysCreate=*/false); + GetTopFieldContext()->SetHyperlinkStyle(sHyperlinkStyleName); + } + #if !defined(MACOSX) // TODO: check layout differences and support all platforms, if needed sal_Int32 nPos = 0; OUString sFontName; @@ -8460,25 +8469,21 @@ void DomainMapper_Impl::PopFieldContext() xCrsrProperties->setPropertyValue("VisitedCharStyleName",uno::Any(sDisplayName)); xCrsrProperties->setPropertyValue("UnvisitedCharStyleName",uno::Any(sDisplayName)); } - else + else if (!pContext->GetHyperlinkStyle().isEmpty()) { uno::Any aAny = xCrsrProperties->getPropertyValue("CharStyleName"); OUString charStyle; if (css::uno::fromAny(aAny, &charStyle)) { - if (charStyle.isEmpty()) - { - xCrsrProperties->setPropertyValue("VisitedCharStyleName", uno::Any(OUString("Default Style"))); - xCrsrProperties->setPropertyValue("UnvisitedCharStyleName", uno::Any(OUString("Default Style"))); - } - else if (charStyle.equalsIgnoreAsciiCase("Internet Link")) + if (!charStyle.isEmpty() && charStyle.equalsIgnoreAsciiCase("Internet Link")) { xCrsrProperties->setPropertyValue("CharStyleName", uno::Any(OUString("Default Style"))); } else { - xCrsrProperties->setPropertyValue("VisitedCharStyleName", aAny); - xCrsrProperties->setPropertyValue("UnvisitedCharStyleName", aAny); + xCrsrProperties->setPropertyValue("VisitedCharStyleName", uno::Any(pContext->GetHyperlinkStyle())); + xCrsrProperties->setPropertyValue("UnvisitedCharStyleName", uno::Any(pContext->GetHyperlinkStyle())); + } } } diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.hxx b/writerfilter/source/dmapper/DomainMapper_Impl.hxx index ee17ac183a2a..0b025fb89b4e 100644 --- a/writerfilter/source/dmapper/DomainMapper_Impl.hxx +++ b/writerfilter/source/dmapper/DomainMapper_Impl.hxx @@ -232,6 +232,7 @@ class FieldContext : public virtual SvRefBase OUString m_sHyperlinkURL; /// A frame for the hyperlink when one exists. OUString m_sHyperlinkTarget; + OUString m_sHyperlinkStyle; FFDataHandler::Pointer_t m_pFFDataHandler; FormControlHelper::Pointer_t m_pFormControlHelper; @@ -283,6 +284,8 @@ public: const OUString& GetHyperlinkURL() const { return m_sHyperlinkURL; } void SetHyperlinkTarget(const OUString& rTarget) { m_sHyperlinkTarget = rTarget; } const OUString& GetHyperlinkTarget() const { return m_sHyperlinkTarget; } + void SetHyperlinkStyle(const OUString& rStyle) { m_sHyperlinkStyle = rStyle; } + const OUString& GetHyperlinkStyle() const { return m_sHyperlinkStyle; } void setFFDataHandler(FFDataHandler::Pointer_t pFFDataHandler) { m_pFFDataHandler = pFFDataHandler; } const FFDataHandler::Pointer_t& getFFDataHandler() const { return m_pFFDataHandler; }