diff options
-rw-r--r-- | vcl/qa/cppunit/pdfexport/data/tdf142133.docx | bin | 0 -> 12078 bytes | |||
-rw-r--r-- | vcl/qa/cppunit/pdfexport/pdfexport.cxx | 35 | ||||
-rw-r--r-- | writerfilter/source/dmapper/DomainMapper_Impl.cxx | 23 | ||||
-rw-r--r-- | writerfilter/source/dmapper/DomainMapper_Impl.hxx | 3 |
4 files changed, 52 insertions, 9 deletions
diff --git a/vcl/qa/cppunit/pdfexport/data/tdf142133.docx b/vcl/qa/cppunit/pdfexport/data/tdf142133.docx Binary files differnew file mode 100644 index 000000000000..fa1e155b873e --- /dev/null +++ b/vcl/qa/cppunit/pdfexport/data/tdf142133.docx diff --git a/vcl/qa/cppunit/pdfexport/pdfexport.cxx b/vcl/qa/cppunit/pdfexport/pdfexport.cxx index d362a3855303..e9a8530c3cce 100644 --- a/vcl/qa/cppunit/pdfexport/pdfexport.cxx +++ b/vcl/qa/cppunit/pdfexport/pdfexport.cxx @@ -2740,6 +2740,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"_ostr)); + 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( + "Annot"_ostr, + static_cast<vcl::filter::PDFNameElement*>(pAnnot->Lookup("Type"_ostr))->GetValue()); + CPPUNIT_ASSERT_EQUAL( + "Link"_ostr, + static_cast<vcl::filter::PDFNameElement*>(pAnnot->Lookup("Subtype"_ostr))->GetValue()); + auto pAction = dynamic_cast<vcl::filter::PDFDictionaryElement*>(pAnnot->Lookup("A"_ostr)); + CPPUNIT_ASSERT(pAction); + auto pURIElem + = dynamic_cast<vcl::filter::PDFLiteralStringElement*>(pAction->LookupElement("URI"_ostr)); + CPPUNIT_ASSERT(pURIElem); + // Check it matches + CPPUNIT_ASSERT_EQUAL("https://google.com/"_ostr, 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 05f3fae6751f..2b9091452dde 100644 --- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx +++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx @@ -3314,6 +3314,15 @@ void DomainMapper_Impl::MergeAtContentImageRedlineWithNext(const css::uno::Refer } 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; @@ -8793,25 +8802,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 8bd51d0add2e..8916193bcab9 100644 --- a/writerfilter/source/dmapper/DomainMapper_Impl.hxx +++ b/writerfilter/source/dmapper/DomainMapper_Impl.hxx @@ -249,6 +249,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; @@ -300,6 +301,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; } |