[Libreoffice-commits] core.git: Branch 'libreoffice-7-2' - editeng/source include/editeng sw/inc sw/qa sw/source

Vasily Melenchuk (via logerrit) logerrit at kemper.freedesktop.org
Thu Aug 12 12:04:21 UTC 2021


 editeng/source/items/numitem.cxx                    |   21 ++++++++++
 include/editeng/numitem.hxx                         |    1 
 sw/inc/chpfld.hxx                                   |    1 
 sw/qa/core/fields/data/chapter_field_followedby.odt |binary
 sw/qa/core/fields/fields.cxx                        |   41 ++++++++++++++++++--
 sw/source/core/fields/chpfld.cxx                    |    9 ++--
 sw/source/core/txtnode/ndtxt.cxx                    |   28 -------------
 7 files changed, 68 insertions(+), 33 deletions(-)

New commits:
commit 9bbc9e75f20937913b5d6f4f09b1d5b54e26bf20
Author:     Vasily Melenchuk <vasily.melenchuk at cib.de>
AuthorDate: Fri Jul 23 20:15:08 2021 +0300
Commit:     Thorsten Behrens <thorsten.behrens at allotropia.de>
CommitDate: Thu Aug 12 14:03:12 2021 +0200

    sw: use followby parameter of outline in Chapter field
    
    When Chapter field with format "Chapter number and name" is used
    it does not insert any delimiter between number and name. Best is
    to use outline/list property LabelFollowBy.
    
    But since it is done inside field we are limited with supported
    characters, so practically only space and nothing are correctly
    supported. Tab and newline are replaced by space.
    
    Change-Id: I4583b7051ae5ad963132980443fa70b5a19354e7
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/119428
    Tested-by: Jenkins
    Reviewed-by: Thorsten Behrens <thorsten.behrens at allotropia.de>
    (cherry picked from commit b67b3e2be0c80c3667ad2cb633e7e932d51d63a8)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/120355

diff --git a/editeng/source/items/numitem.cxx b/editeng/source/items/numitem.cxx
index a726e70d7101..9ce62c11dc16 100644
--- a/editeng/source/items/numitem.cxx
+++ b/editeng/source/items/numitem.cxx
@@ -483,6 +483,27 @@ void SvxNumberFormat::SetLabelFollowedBy( const LabelFollowedBy eLabelFollowedBy
 {
     meLabelFollowedBy = eLabelFollowedBy;
 }
+
+OUString SvxNumberFormat::GetLabelFollowedByAsString() const
+{
+    switch (meLabelFollowedBy)
+    {
+        case LISTTAB:
+            return "\t";
+        case SPACE:
+            return " ";
+        case NEWLINE:
+            return "\n";
+        case NOTHING:
+            // intentionally left blank.
+            return OUString();
+        default:
+            SAL_WARN("editeng", "Unknown SvxNumberFormat::GetLabelFollowedBy() return value");
+            assert(false);
+    }
+    return OUString();
+}
+
 void SvxNumberFormat::SetListtabPos( const tools::Long nListtabPos )
 {
     mnListtabPos = nListtabPos;
diff --git a/include/editeng/numitem.hxx b/include/editeng/numitem.hxx
index 19cfd3922c1e..f9c838cb6264 100644
--- a/include/editeng/numitem.hxx
+++ b/include/editeng/numitem.hxx
@@ -213,6 +213,7 @@ public:
 
     void SetLabelFollowedBy( const LabelFollowedBy eLabelFollowedBy );
     LabelFollowedBy GetLabelFollowedBy() const { return meLabelFollowedBy;}
+    OUString GetLabelFollowedByAsString() const;
     void SetListtabPos( const tools::Long nListtabPos );
     tools::Long GetListtabPos() const { return mnListtabPos;}
     void SetFirstLineIndent( const tools::Long nFirstLineIndent );
diff --git a/sw/inc/chpfld.hxx b/sw/inc/chpfld.hxx
index 305831911b5f..1032f19b4abe 100644
--- a/sw/inc/chpfld.hxx
+++ b/sw/inc/chpfld.hxx
@@ -55,6 +55,7 @@ class SW_DLLPUBLIC SwChapterField final : public SwField
         sal_uInt8 nLevel;
         OUString sTitle;
         OUString sNumber;
+        OUString sLabelFollowedBy;
         OUString sPre;
         OUString sPost;
         State() : nLevel(0) {}
diff --git a/sw/qa/core/fields/data/chapter_field_followedby.odt b/sw/qa/core/fields/data/chapter_field_followedby.odt
new file mode 100644
index 000000000000..b2086f2591b3
Binary files /dev/null and b/sw/qa/core/fields/data/chapter_field_followedby.odt differ
diff --git a/sw/qa/core/fields/fields.cxx b/sw/qa/core/fields/fields.cxx
index 7f59597831ea..a0c5a2c86c7e 100644
--- a/sw/qa/core/fields/fields.cxx
+++ b/sw/qa/core/fields/fields.cxx
@@ -84,9 +84,7 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf143424)
 
     // Field: Chapter Format: Chapter number and name
     xField.set(xFields->nextElement(), uno::UNO_QUERY);
-    CPPUNIT_ASSERT_EQUAL(OUString("Chapter 2 -Another title"), xField->getPresentation(false));
-    //                                       ^^ seems here must be a separator
-    // Please modify this testcase once this behavior will be fixed. For now I just fix and check this behavior
+    CPPUNIT_ASSERT_EQUAL(OUString("Chapter 2 - Another title"), xField->getPresentation(false));
 
     // Field: Chapter Format: Chapter number
     xField.set(xFields->nextElement(), uno::UNO_QUERY);
@@ -96,6 +94,43 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf143424)
     xField.set(xFields->nextElement(), uno::UNO_QUERY);
     CPPUNIT_ASSERT_EQUAL(OUString("2"), xField->getPresentation(false));
 }
+
+CPPUNIT_TEST_FIXTURE(Test, testChapterFieldsFollowedBy)
+{
+    createSwDoc(DATA_DIRECTORY, "chapter_field_followedby.odt");
+
+    uno::Reference<text::XTextFieldsSupplier> xTextFieldsSupplier(mxComponent, uno::UNO_QUERY);
+    uno::Reference<container::XEnumerationAccess> xFieldsAccess(
+        xTextFieldsSupplier->getTextFields());
+    uno::Reference<container::XEnumeration> xFields(xFieldsAccess->createEnumeration());
+
+    // TODO: I have no idea why fields are enumerated in invalid order, not like in document
+    std::vector<OUString> aFieldValues = {
+        "Followed by tab", // #1
+        "I.I.I.I", // #16
+        ">I.I.I.I< Followed by newline", // #15 Linefeed is replaced by space
+        ">I.I.I.I<", // #14
+        "Followed by newline", // #13
+        "I.I.I", // #12
+        ">I.I.I<Followed by nothing", // #11 Nothing between text & outline
+        ">I.I.I<", // #10
+        "Followed by nothing", // #9
+        "I.I", // #8
+        ">I.I< Followed by space", // #7 Space as is
+        ">I.I<", // #6
+        "Followed by space", // #5
+        "I", // #4
+        ">I< Followed by tab", // #3 Here is a tab, but replaced by space in field
+        ">I<", // #2
+    };
+
+    for (const auto& sValue : aFieldValues)
+    {
+        CPPUNIT_ASSERT(xFields->hasMoreElements());
+        uno::Reference<text::XTextField> xField(xFields->nextElement(), uno::UNO_QUERY);
+        CPPUNIT_ASSERT_EQUAL(sValue, xField->getPresentation(false));
+    }
+}
 }
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/sw/source/core/fields/chpfld.cxx b/sw/source/core/fields/chpfld.cxx
index 191c1de85110..229e6c96154c 100644
--- a/sw/source/core/fields/chpfld.cxx
+++ b/sw/source/core/fields/chpfld.cxx
@@ -37,7 +37,8 @@ namespace
 
 OUString removeControlChars(const OUString& sIn)
 {
-    OUStringBuffer aBuf(sIn.replace('\n', ' '));
+    OUStringBuffer aBuf(sIn);
+    aBuf = aBuf.replace('\n', ' ').replace('\t', ' ');
     sal_Int32 nLen = aBuf.getLength();
     for (sal_Int32 i = 0; i < nLen; ++i)
     {
@@ -106,9 +107,9 @@ OUString SwChapterField::ExpandImpl(SwRootFrame const*const pLayout) const
         case CF_NUMBER:
             return rState.sPre + rState.sNumber + rState.sPost;
         case CF_NUM_TITLE:
-            return rState.sPre + rState.sNumber + rState.sPost + rState.sTitle;
+            return rState.sPre + rState.sNumber + rState.sPost + rState.sLabelFollowedBy + rState.sTitle;
         case CF_NUM_NOPREPST_TITLE:
-            return rState.sNumber + rState.sTitle;
+            return rState.sNumber + rState.sLabelFollowedBy + rState.sTitle;
     }
     // CF_NUMBER_NOPREPST
     return rState.sNumber;
@@ -149,6 +150,7 @@ void SwChapterField::ChangeExpansion(const SwTextNode &rTextNd, bool bSrchNum,
 {
     State & rState(pLayout && pLayout->IsHideRedlines() ? m_StateRLHidden : m_State);
     rState.sNumber.clear();
+    rState.sLabelFollowedBy.clear();
     rState.sTitle.clear();
     rState.sPost.clear();
     rState.sPre.clear();
@@ -209,6 +211,7 @@ void SwChapterField::ChangeExpansion(const SwTextNode &rTextNd, bool bSrchNum,
             const SwNumFormat& rNFormat = pRule->Get(nListLevel);
             rState.sPost = rNFormat.GetSuffix();
             rState.sPre = rNFormat.GetPrefix();
+            rState.sLabelFollowedBy = removeControlChars(rNFormat.GetLabelFollowedByAsString());
         }
     }
     else
diff --git a/sw/source/core/txtnode/ndtxt.cxx b/sw/source/core/txtnode/ndtxt.cxx
index cb3a7d9830b2..da69da7209d3 100644
--- a/sw/source/core/txtnode/ndtxt.cxx
+++ b/sw/source/core/txtnode/ndtxt.cxx
@@ -4499,33 +4499,7 @@ OUString SwTextNode::GetLabelFollowedBy() const
         const SwNumFormat& rFormat = pNumRule->Get( o3tl::narrowing<sal_uInt16>(GetActualListLevel()) );
         if ( rFormat.GetPositionAndSpaceMode() == SvxNumberFormat::LABEL_ALIGNMENT )
         {
-            switch ( rFormat.GetLabelFollowedBy() )
-            {
-                case SvxNumberFormat::LISTTAB:
-                {
-                    return "\t";
-                }
-                break;
-                case SvxNumberFormat::SPACE:
-                {
-                    return " ";
-                }
-                break;
-                case SvxNumberFormat::NEWLINE:
-                {
-                    return "\n";
-                }
-                break;
-                case SvxNumberFormat::NOTHING:
-                {
-                    // intentionally left blank.
-                }
-                break;
-                default:
-                {
-                    OSL_FAIL( "<SwTextNode::GetLabelFollowedBy()> - unknown SvxNumberFormat::GetLabelFollowedBy() return value" );
-                }
-            }
+            return rFormat.GetLabelFollowedByAsString();
         }
     }
 


More information about the Libreoffice-commits mailing list