summaryrefslogtreecommitdiffstats
path: root/writerfilter
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 05:03:13 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 05:03:13 +0000
commit26f6ae4122fcce6bafa71c064f5e645c39022082 (patch)
treeb0e0916f682785b3a983b71950c4623988ca6eef /writerfilter
parentAdding upstream version 4:24.2.2. (diff)
downloadlibreoffice-upstream/4%24.2.3.tar.xz
libreoffice-upstream/4%24.2.3.zip
Adding upstream version 4:24.2.3.upstream/4%24.2.3
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'writerfilter')
-rw-r--r--writerfilter/qa/cppunittests/dmapper/PropertyMap.cxx40
-rw-r--r--writerfilter/source/dmapper/DomainMapper_Impl.cxx45
-rw-r--r--writerfilter/source/dmapper/DomainMapper_Impl.hxx3
-rw-r--r--writerfilter/source/dmapper/PropertyMap.cxx2
4 files changed, 63 insertions, 27 deletions
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 <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/drawing/XDrawPageSupplier.hpp>
#include <com/sun/star/table/BorderLine2.hpp>
+#include <com/sun/star/text/XTextDocument.hpp>
+#include <com/sun/star/document/XFilter.hpp>
+#include <com/sun/star/document/XImporter.hpp>
+
+#include <unotools/streamwrap.hxx>
+#include <comphelper/propertyvalue.hxx>
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<sal_Int32>(-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<style::XStyleFamiliesSupplier> xStyleFamiliesSupplier(mxComponent,
+ uno::UNO_QUERY);
+ uno::Reference<container::XNameAccess> xStyleFamilies
+ = xStyleFamiliesSupplier->getStyleFamilies();
+ uno::Reference<container::XNameAccess> xStyleFamily(xStyleFamilies->getByName("PageStyles"),
+ uno::UNO_QUERY);
+ uno::Reference<beans::XPropertySet> xStyle(xStyleFamily->getByName("Standard"), uno::UNO_QUERY);
+ xStyle->setPropertyValue("HeaderIsOn", uno::Any(true));
+
+ // When pasting RTF content:
+ uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY);
+ uno::Reference<text::XTextRange> xText = xTextDocument->getText();
+ uno::Reference<text::XTextRange> xBodyEnd = xText->getEnd();
+ uno::Reference<document::XFilter> xFilter(
+ m_xSFactory->createInstance("com.sun.star.comp.Writer.RtfFilter"), uno::UNO_QUERY);
+ uno::Reference<document::XImporter> xImporter(xFilter, uno::UNO_QUERY);
+ xImporter->setTargetDocument(mxComponent);
+ std::unique_ptr<SvStream> pStream(new SvMemoryStream);
+ pStream->WriteOString("{\\rtf1 paste}");
+ pStream->Seek(0);
+ uno::Reference<io::XStream> 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<bool>());
+}
}
/* 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<text::XText> const& xText, uno::Reference<text::XTextDocument> const& xTextDocument)
+bool isContentEmpty(uno::Reference<text::XText> const& xText)
{
if (!xText.is())
return true; // no XText means it's empty
- uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(xTextDocument, uno::UNO_QUERY);
- auto xDrawPage = xDrawPageSupplier->getDrawPage();
- if (xDrawPage && xDrawPage->hasElements())
- {
- for (sal_Int32 i = 0; i < xDrawPage->getCount(); ++i)
- {
- uno::Reference<text::XTextContent> xShape(xDrawPage->getByIndex(i), uno::UNO_QUERY);
- if (xShape.is())
- {
- uno::Reference<text::XTextRange> xAnchor = xShape->getAnchor();
- if (xAnchor.is() && xAnchor->getText() == xText)
- return false;
- }
- }
- }
+ uno::Reference<css::lang::XServiceInfo> xTextServiceInfo(xText, uno::UNO_QUERY);
+ if (xTextServiceInfo && xTextServiceInfo->getImplementationName() == "SwXHeadFootText")
+ return false;
uno::Reference<container::XEnumerationAccess> xEnumAccess(xText->getText(), uno::UNO_QUERY);
uno::Reference<container::XEnumeration> 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));
}