From 97ac77f067910fa5e8206d75160fa63546a9358d Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 4 May 2024 07:03:24 +0200 Subject: Merging upstream version 4:24.2.3. Signed-off-by: Daniel Baumann --- .../qa/cppunittests/dmapper/PropertyMap.cxx | 40 +++++++++++++++++++ writerfilter/source/dmapper/DomainMapper_Impl.cxx | 45 +++++++++------------- writerfilter/source/dmapper/DomainMapper_Impl.hxx | 3 ++ writerfilter/source/dmapper/PropertyMap.cxx | 2 +- 4 files changed, 63 insertions(+), 27 deletions(-) (limited to 'writerfilter') diff --git a/writerfilter/qa/cppunittests/dmapper/PropertyMap.cxx b/writerfilter/qa/cppunittests/dmapper/PropertyMap.cxx index dae6e387ee..2952f1f933 100644 --- a/writerfilter/qa/cppunittests/dmapper/PropertyMap.cxx +++ b/writerfilter/qa/cppunittests/dmapper/PropertyMap.cxx @@ -15,6 +15,12 @@ #include #include #include +#include +#include +#include + +#include +#include using namespace ::com::sun::star; @@ -135,6 +141,40 @@ CPPUNIT_TEST_FIXTURE(Test, testNegativePageBorderNoMargin) // i.e. the border negative distance was lost. CPPUNIT_ASSERT_EQUAL(static_cast(-1147), nTopBorderDistance); } + +CPPUNIT_TEST_FIXTURE(Test, testPasteHeaderDisable) +{ + // Given an empty document with a turned on header: + mxComponent = loadFromDesktop("private:factory/swriter", "com.sun.star.text.TextDocument"); + uno::Reference xStyleFamiliesSupplier(mxComponent, + uno::UNO_QUERY); + uno::Reference xStyleFamilies + = xStyleFamiliesSupplier->getStyleFamilies(); + uno::Reference xStyleFamily(xStyleFamilies->getByName("PageStyles"), + uno::UNO_QUERY); + uno::Reference xStyle(xStyleFamily->getByName("Standard"), uno::UNO_QUERY); + xStyle->setPropertyValue("HeaderIsOn", uno::Any(true)); + + // When pasting RTF content: + uno::Reference xTextDocument(mxComponent, uno::UNO_QUERY); + uno::Reference xText = xTextDocument->getText(); + uno::Reference xBodyEnd = xText->getEnd(); + uno::Reference xFilter( + m_xSFactory->createInstance("com.sun.star.comp.Writer.RtfFilter"), uno::UNO_QUERY); + uno::Reference xImporter(xFilter, uno::UNO_QUERY); + xImporter->setTargetDocument(mxComponent); + std::unique_ptr pStream(new SvMemoryStream); + pStream->WriteOString("{\\rtf1 paste}"); + pStream->Seek(0); + uno::Reference xStream(new utl::OStreamWrapper(std::move(pStream))); + uno::Sequence aDescriptor{ comphelper::makePropertyValue("InputStream", xStream), + comphelper::makePropertyValue("InsertMode", true), + comphelper::makePropertyValue("TextInsertModeRange", xBodyEnd) }; + CPPUNIT_ASSERT(xFilter->filter(aDescriptor)); + + // Then make sure the header stays on: + CPPUNIT_ASSERT(xStyle->getPropertyValue("HeaderIsOn").get()); +} } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx index 05f3fae675..028b4b4c9a 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; @@ -3784,26 +3793,14 @@ void DomainMapper_Impl::ConvertHeaderFooterToTextFrame(bool bDynamicHeightTop, b namespace { // Determines if the XText content is empty (no text, no shapes, no tables) -bool isContentEmpty(uno::Reference const& xText, uno::Reference const& xTextDocument) +bool isContentEmpty(uno::Reference const& xText) { if (!xText.is()) return true; // no XText means it's empty - uno::Reference xDrawPageSupplier(xTextDocument, uno::UNO_QUERY); - auto xDrawPage = xDrawPageSupplier->getDrawPage(); - if (xDrawPage && xDrawPage->hasElements()) - { - for (sal_Int32 i = 0; i < xDrawPage->getCount(); ++i) - { - uno::Reference xShape(xDrawPage->getByIndex(i), uno::UNO_QUERY); - if (xShape.is()) - { - uno::Reference xAnchor = xShape->getAnchor(); - if (xAnchor.is() && xAnchor->getText() == xText) - return false; - } - } - } + uno::Reference xTextServiceInfo(xText, uno::UNO_QUERY); + if (xTextServiceInfo && xTextServiceInfo->getImplementationName() == "SwXHeadFootText") + return false; uno::Reference xEnumAccess(xText->getText(), uno::UNO_QUERY); uno::Reference xEnum = xEnumAccess->createEnumeration(); @@ -3950,7 +3947,7 @@ void DomainMapper_Impl::checkIfHeaderFooterIsEmpty(PagePartType ePagePartType, P if (!xPageStyle.is()) return; - bool bEmpty = isContentEmpty(m_aTextAppendStack.top().xTextAppend, GetTextDocument()); + bool bEmpty = isContentEmpty(m_aTextAppendStack.top().xTextAppend); if (eType == PageType::FIRST && bEmpty) { @@ -8793,25 +8790,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 8bd51d0add..8916193bca 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; } diff --git a/writerfilter/source/dmapper/PropertyMap.cxx b/writerfilter/source/dmapper/PropertyMap.cxx index 8f7a301986..af07ba1cdd 100644 --- a/writerfilter/source/dmapper/PropertyMap.cxx +++ b/writerfilter/source/dmapper/PropertyMap.cxx @@ -570,7 +570,7 @@ void SectionPropertyMap::setHeaderFooterProperties(DomainMapper_Impl& rDM_Impl) m_aPageStyle->setPropertyValue(getPropertyName(PROP_FIRST_IS_SHARED), uno::Any(!m_bTitlePage)); bool bHadFirstHeader = m_bHadFirstHeader && m_bTitlePage; - if (bHasHeader && !bHadFirstHeader && !m_bHadLeftHeader && !m_bHadRightHeader) + if (bHasHeader && !bHadFirstHeader && !m_bHadLeftHeader && !m_bHadRightHeader && rDM_Impl.IsNewDoc()) { m_aPageStyle->setPropertyValue(sHeaderIsOn, uno::Any(false)); } -- cgit v1.2.3