writerfilter/CppunitTest_writerfilter_rtftok.mk           |    1 
 writerfilter/qa/cppunittests/rtftok/data/follow-style.rtf |    7 +
 writerfilter/qa/cppunittests/rtftok/rtfdispatchvalue.cxx  |   77 ++++++++++++++
 writerfilter/source/rtftok/rtfdispatchvalue.cxx           |    4 
 4 files changed, 89 insertions(+)

New commits:
commit 926ac3c5e4b8eb425bc2db0366594acc0cf2c1ed
Author:     Miklos Vajna <[email protected]>
AuthorDate: Mon Nov 8 19:56:36 2021 +0100
Commit:     Miklos Vajna <[email protected]>
CommitDate: Tue Nov 9 08:22:41 2021 +0100

    RTF import: handle \snext
    
    I.e. pressing enter at the end of a heading 1 paragraph should switch to
    body text.
    
    Change-Id: Idde9da3e2c058869a2ae4a9c61b3b43165121f5e
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/124883
    Tested-by: Jenkins
    Reviewed-by: Miklos Vajna <[email protected]>

diff --git a/writerfilter/CppunitTest_writerfilter_rtftok.mk 
b/writerfilter/CppunitTest_writerfilter_rtftok.mk
index 6cad1e4c7b8d..0fe9083c6560 100644
--- a/writerfilter/CppunitTest_writerfilter_rtftok.mk
+++ b/writerfilter/CppunitTest_writerfilter_rtftok.mk
@@ -16,6 +16,7 @@ $(eval $(call 
gb_CppunitTest_use_externals,writerfilter_rtftok,\
 ))
 
 $(eval $(call gb_CppunitTest_add_exception_objects,writerfilter_rtftok, \
+    writerfilter/qa/cppunittests/rtftok/rtfdispatchvalue \
     writerfilter/qa/cppunittests/rtftok/rtfdocumentimpl \
     writerfilter/qa/cppunittests/rtftok/rtfsdrimport \
     writerfilter/qa/cppunittests/rtftok/rtfsprm \
diff --git a/writerfilter/qa/cppunittests/rtftok/data/follow-style.rtf 
b/writerfilter/qa/cppunittests/rtftok/data/follow-style.rtf
new file mode 100644
index 000000000000..6e627c784e6b
--- /dev/null
+++ b/writerfilter/qa/cppunittests/rtftok/data/follow-style.rtf
@@ -0,0 +1,7 @@
+{\rtf1
+{\stylesheet
+{\s0\ql Normal;}
+{\s1\snext0 Heading 1;}
+}
+\pard\plain\s1 x\par
+}
diff --git a/writerfilter/qa/cppunittests/rtftok/rtfdispatchvalue.cxx 
b/writerfilter/qa/cppunittests/rtftok/rtfdispatchvalue.cxx
new file mode 100644
index 000000000000..662e65d75166
--- /dev/null
+++ b/writerfilter/qa/cppunittests/rtftok/rtfdispatchvalue.cxx
@@ -0,0 +1,77 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <test/bootstrapfixture.hxx>
+#include <unotest/macros_test.hxx>
+
+#include <com/sun/star/beans/XPropertySet.hpp>
+#include <com/sun/star/frame/Desktop.hpp>
+#include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
+
+using namespace ::com::sun::star;
+
+namespace
+{
+/// Tests for writerfilter/source/rtftok/rtfdispatchvalue.cxx.
+class Test : public test::BootstrapFixture, public unotest::MacrosTest
+{
+private:
+    uno::Reference<lang::XComponent> mxComponent;
+
+public:
+    void setUp() override;
+    void tearDown() override;
+    uno::Reference<lang::XComponent>& getComponent() { return mxComponent; }
+};
+
+void Test::setUp()
+{
+    test::BootstrapFixture::setUp();
+
+    mxDesktop.set(frame::Desktop::create(mxComponentContext));
+}
+
+void Test::tearDown()
+{
+    if (mxComponent.is())
+        mxComponent->dispose();
+
+    test::BootstrapFixture::tearDown();
+}
+
+constexpr OUStringLiteral DATA_DIRECTORY = 
u"/writerfilter/qa/cppunittests/rtftok/data/";
+
+CPPUNIT_TEST_FIXTURE(Test, testFollowStyle)
+{
+    // Given a file with \snext:
+    OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + 
"follow-style.rtf";
+
+    // When loading that file:
+    getComponent() = loadFromDesktop(aURL);
+
+    // Then make sure we set the follow of the para style correctly:
+    uno::Reference<style::XStyleFamiliesSupplier> 
xStyleFamiliesSupplier(getComponent(),
+                                                                         
uno::UNO_QUERY);
+    uno::Reference<container::XNameAccess> xStyleFamilies
+        = xStyleFamiliesSupplier->getStyleFamilies();
+    uno::Reference<container::XNameAccess> xStyleFamily(
+        xStyleFamilies->getByName("ParagraphStyles"), uno::UNO_QUERY);
+    uno::Reference<beans::XPropertySet> 
xStyle(xStyleFamily->getByName("Heading 1"),
+                                               uno::UNO_QUERY);
+    OUString aFollowStyle;
+    xStyle->getPropertyValue("FollowStyle") >>= aFollowStyle;
+    // Without the accompanying fix in place, this test would have failed with:
+    // - Expected: Standard
+    // - Actual  : Heading 1
+    // i.e. \snext was ignored.
+    CPPUNIT_ASSERT_EQUAL(OUString("Standard"), aFollowStyle);
+}
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/writerfilter/source/rtftok/rtfdispatchvalue.cxx 
b/writerfilter/source/rtftok/rtfdispatchvalue.cxx
index 135e2395f34c..14d0b3993a54 100644
--- a/writerfilter/source/rtftok/rtfdispatchvalue.cxx
+++ b/writerfilter/source/rtftok/rtfdispatchvalue.cxx
@@ -131,6 +131,10 @@ bool RTFDocumentImpl::dispatchTableSprmValue(RTFKeyword 
nKeyword, int nParam)
             nSprm = NS_ooxml::LN_CT_Style_basedOn;
             pIntValue = new RTFValue(getStyleName(nParam));
             break;
+        case RTFKeyword::SNEXT:
+            nSprm = NS_ooxml::LN_CT_Style_next;
+            pIntValue = new RTFValue(getStyleName(nParam));
+            break;
         default:
             break;
     }

Reply via email to