summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXisco Fauli <xiscofauli@libreoffice.org>2024-03-08 14:23:08 +0100
committerXisco Fauli <xiscofauli@libreoffice.org>2024-03-08 21:09:31 +0100
commitb56678ae967bb1e09b52930a0b1d59a5e68bb7be (patch)
treed056f7ef86972940ba70a08e1b08e06f5bb1c2e0
parent61b1d3a17ff784b7c79a92cbe069a90ce4932535 (diff)
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 <xiscofauli@libreoffice.org>
-rw-r--r--vcl/qa/cppunit/pdfexport/data/tdf142133.docxbin0 -> 12078 bytes
-rw-r--r--vcl/qa/cppunit/pdfexport/pdfexport.cxx35
-rw-r--r--writerfilter/source/dmapper/DomainMapper_Impl.cxx23
-rw-r--r--writerfilter/source/dmapper/DomainMapper_Impl.hxx3
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
new file mode 100644
index 000000000000..fa1e155b873e
--- /dev/null
+++ b/vcl/qa/cppunit/pdfexport/data/tdf142133.docx
Binary files differ
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 bbdfbd35c34a..f4943c60c88c 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
@@ -3304,6 +3304,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;
@@ -8787,25 +8796,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 4f4f09e58b1f..94ab42de3f98 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.hxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.hxx
@@ -301,6 +301,7 @@ private:
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;
@@ -352,6 +353,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(const FFDataHandler::Pointer_t& pFFDataHandler) { m_pFFDataHandler = pFFDataHandler; }
const FFDataHandler::Pointer_t& getFFDataHandler() const { return m_pFFDataHandler; }