[Libreoffice-commits] core.git: editeng/source include/editeng sw/qa sw/source

Vasily Melenchuk (via logerrit) logerrit at kemper.freedesktop.org
Mon Jul 26 13:18:52 UTC 2021


 editeng/source/items/numitem.cxx     |   10 ++++++++++
 include/editeng/numitem.hxx          |    2 +-
 sw/qa/core/fields/data/tdf143424.odt |binary
 sw/qa/core/fields/fields.cxx         |   34 ++++++++++++++++++++++++++++++++++
 sw/source/core/doc/number.cxx        |    3 ++-
 sw/source/filter/ww8/wrtw8num.cxx    |    2 +-
 6 files changed, 48 insertions(+), 3 deletions(-)

New commits:
commit d44730148a95933f4a45a70241cb6d1d0546f626
Author:     Vasily Melenchuk <vasily.melenchuk at cib.de>
AuthorDate: Wed Jul 21 12:21:07 2021 +0300
Commit:     Thorsten Behrens <thorsten.behrens at allotropia.de>
CommitDate: Mon Jul 26 15:18:16 2021 +0200

    tdf#143424: support for "Chapter number without separator"
    
    If LO is using list format strings (this is default behavior since
    aa5c6d12) it was not able to show just numbering without all formatting,
    as it used in some fields.
    
    Change-Id: Ib4695b8e1c2d7a451522c7e04af2216d16aceefe
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/119309
    Reviewed-by: Thorsten Behrens <thorsten.behrens at allotropia.de>
    Tested-by: Jenkins

diff --git a/editeng/source/items/numitem.cxx b/editeng/source/items/numitem.cxx
index 41ee6e4cf952..2f30242b911a 100644
--- a/editeng/source/items/numitem.cxx
+++ b/editeng/source/items/numitem.cxx
@@ -608,6 +608,16 @@ void SvxNumberFormat::SetListFormat(std::optional<OUString> oSet)
         sSuffix = sListFormat->copy(nLastReplacement);
 }
 
+OUString SvxNumberFormat::GetListFormat(bool bIncludePrefixSuffix /*= true*/) const
+{
+    assert(sListFormat.has_value());
+
+    if (bIncludePrefixSuffix)
+        return *sListFormat;
+
+    // Strip prefix & suffix from string
+    return sListFormat->copy(sPrefix.getLength(), sListFormat->getLength() - sPrefix.getLength() - sSuffix.getLength());
+}
 
 OUString SvxNumberFormat::GetCharFormatName()const
 {
diff --git a/include/editeng/numitem.hxx b/include/editeng/numitem.hxx
index bbcbecdf4c79..1846e6a8739c 100644
--- a/include/editeng/numitem.hxx
+++ b/include/editeng/numitem.hxx
@@ -175,7 +175,7 @@ public:
     void            SetListFormat(const OUString& rPrefix, const OUString& rSuffix, int nLevel);
     void            SetListFormat(std::optional<OUString> oSet = std::nullopt);
     bool            HasListFormat() const { return sListFormat.has_value(); }
-    const OUString& GetListFormat() const { return *sListFormat; }
+    OUString        GetListFormat(bool bIncludePrefixSuffix = true) const;
 
     void                    SetCharFormatName(const OUString& rSet){ sCharStyleName = rSet; }
     virtual OUString        GetCharFormatName()const;
diff --git a/sw/qa/core/fields/data/tdf143424.odt b/sw/qa/core/fields/data/tdf143424.odt
new file mode 100644
index 000000000000..d485267f12e4
Binary files /dev/null and b/sw/qa/core/fields/data/tdf143424.odt differ
diff --git a/sw/qa/core/fields/fields.cxx b/sw/qa/core/fields/fields.cxx
index 74b94d7a3f8e..7f59597831ea 100644
--- a/sw/qa/core/fields/fields.cxx
+++ b/sw/qa/core/fields/fields.cxx
@@ -10,6 +10,8 @@
 #include <swmodeltestbase.hxx>
 
 #include <com/sun/star/text/XTextDocument.hpp>
+#include <com/sun/star/text/XTextField.hpp>
+#include <com/sun/star/text/XTextFieldsSupplier.hpp>
 
 #include <comphelper/propertyvalue.hxx>
 
@@ -26,6 +28,8 @@ class Test : public SwModelTestBase
 {
 };
 
+constexpr OUStringLiteral DATA_DIRECTORY = u"/sw/qa/core/fields/data/";
+
 CPPUNIT_TEST_FIXTURE(Test, testAuthorityTooltip)
 {
     // Create a document with a bibliography reference in it.
@@ -62,6 +66,36 @@ CPPUNIT_TEST_FIXTURE(Test, testAuthorityTooltip)
     // first inserting an empty bibliography table into the document.
     CPPUNIT_ASSERT_EQUAL(OUString("ARJ00: Ar, J, mytitle, 2020"), aTooltip);
 }
+
+CPPUNIT_TEST_FIXTURE(Test, testTdf143424)
+{
+    createSwDoc(DATA_DIRECTORY, "tdf143424.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
+
+    // Field: Chapter Format: Chapter name
+    uno::Reference<text::XTextField> xField(xFields->nextElement(), uno::UNO_QUERY);
+    CPPUNIT_ASSERT_EQUAL(OUString("Another title"), xField->getPresentation(false));
+
+    // 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
+
+    // Field: Chapter Format: Chapter number
+    xField.set(xFields->nextElement(), uno::UNO_QUERY);
+    CPPUNIT_ASSERT_EQUAL(OUString("Chapter 2 -"), xField->getPresentation(false));
+
+    // Field: Chapter Format: Chapter number without separator
+    xField.set(xFields->nextElement(), uno::UNO_QUERY);
+    CPPUNIT_ASSERT_EQUAL(OUString("2"), xField->getPresentation(false));
+}
 }
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/sw/source/core/doc/number.cxx b/sw/source/core/doc/number.cxx
index 656b4aca04d5..b98b376348f4 100644
--- a/sw/source/core/doc/number.cxx
+++ b/sw/source/core/doc/number.cxx
@@ -666,7 +666,8 @@ OUString SwNumRule::MakeNumString( const SwNumberTree::tNumberVector & rNumVecto
 
             if (rMyNFormat.HasListFormat())
             {
-                OUString sLevelFormat = rMyNFormat.GetListFormat();
+                OUString sLevelFormat = rMyNFormat.GetListFormat(bInclStrings);
+
                 // In this case we are ignoring GetIncludeUpperLevels: we put all
                 // level numbers requested by level format
                 for (SwNumberTree::tNumberVector::size_type i=0; i <= nLevel; ++i)
diff --git a/sw/source/filter/ww8/wrtw8num.cxx b/sw/source/filter/ww8/wrtw8num.cxx
index f1f7654cb124..a5a97854aa4f 100644
--- a/sw/source/filter/ww8/wrtw8num.cxx
+++ b/sw/source/filter/ww8/wrtw8num.cxx
@@ -487,7 +487,7 @@ void MSWordExportBase::NumberingLevel(
             sal_uInt8* pLvlPos = aNumLvlPos;
             // the numbering string has to be restrict
             // to the level currently working on.
-            sNumStr = rRule.MakeNumString(aNumVector, false, true, nLvl);
+            sNumStr = rRule.MakeNumString(aNumVector, true, true, nLvl);
 
             // now search the nums in the string
             for (sal_uInt8 i = 0; i <= nLvl; ++i)


More information about the Libreoffice-commits mailing list