[Libreoffice-commits] core.git: Branch 'distro/lhm/libreoffice-6-4+backports' - sw/inc sw/qa sw/source

Michael Stahl (via logerrit) logerrit at kemper.freedesktop.org
Fri May 14 10:32:54 UTC 2021


 sw/inc/unosett.hxx                                 |    5 +--
 sw/qa/extras/unowriter/unowriter.cxx               |   33 +++++++++++++++++++++
 sw/source/core/unocore/unosett.cxx                 |   20 ++++++++----
 sw/source/uibase/config/StoredChapterNumbering.cxx |    2 -
 4 files changed, 50 insertions(+), 10 deletions(-)

New commits:
commit 4e7095c31180a6c67c9bd766bcc42db925b549dd
Author:     Michael Stahl <michael.stahl at allotropia.de>
AuthorDate: Wed May 12 14:59:43 2021 +0200
Commit:     Michael Stahl <michael.stahl at allotropia.de>
CommitDate: Fri May 14 12:32:21 2021 +0200

    tdf#137810 sw: fix SwXNumberingRules setting CharStyleName
    
    During ODF import, due to removal of the pDocShell parameter, this hits
    
                else
                    rCharStyleName = sCharFormatName;
    
    while setting the "CharStyleName" property and later
    GetNumberingRuleByIndex() prefers m_sNewCharStyleNames over the
    format set in the SwCharFormat??
    
    Also, "BulletFontName" has a similar problem; otoh "HeadingStyleName"
    only makes sense on chapter numbering.
    
    The m_pDoc and m_pDocShell members are such a WTF.
    
    (regression from ae0e4a6ba9be2fa99ac2be8e20157806e36209b2)
    
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/115495
    Tested-by: Jenkins
    Reviewed-by: Michael Stahl <michael.stahl at allotropia.de>
    (cherry picked from commit c5e5467f6a13aba68b4706a4d7feb130e824bcc6)
    
    Change-Id: I9d4d4cd7aeb7e6e29221d53facaff213fd4e35a5
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/115506
    Tested-by: Michael Stahl <michael.stahl at allotropia.de>
    Reviewed-by: Michael Stahl <michael.stahl at allotropia.de>

diff --git a/sw/inc/unosett.hxx b/sw/inc/unosett.hxx
index ac7e7b8d9690..a3b64bc1966e 100644
--- a/sw/inc/unosett.hxx
+++ b/sw/inc/unosett.hxx
@@ -147,16 +147,16 @@ private:
     OUString                    m_sNewCharStyleNames[MAXLEVEL];
     OUString                    m_sNewBulletFontNames[MAXLEVEL];
     OUString                    m_sCreatedNumRuleName; //connects to a numbering in SwDoc
-    SwDoc*                      m_pDoc;
+    SwDoc*                      m_pDoc; // Only if *not* used as chapter numbering.
     SwDocShell*                 m_pDocShell; // Only if used as chapter numbering.
     SwNumRule*                  m_pNumRule;
     const SfxItemPropertySet*   m_pPropertySet;
     bool const                  m_bOwnNumRuleCreated;
 protected:
+    SwXNumberingRules(SwDocShell& rDocSh);  // chapter numbering
     virtual ~SwXNumberingRules() override;
 
 public:
-    SwXNumberingRules(SwDocShell& rDocSh);  // chapter numbering
     SwXNumberingRules(const SwNumRule& rRule, SwDoc* doc = nullptr); // NumRule for paragraphs, numbering styles
     SwXNumberingRules(SwDoc& rDoc); //create a new instance
 
@@ -218,6 +218,7 @@ public:
             OUString *const pHeadingStyleName,
             OUString *const pParagraphStyleName,
             SwDoc *const pDoc,
+            SwDocShell *const pDocShell,
             css::uno::Sequence<css::beans::PropertyValue> const& rProperties);
 
 };
diff --git a/sw/qa/extras/unowriter/unowriter.cxx b/sw/qa/extras/unowriter/unowriter.cxx
index a265bb29e728..985d1171ac4d 100644
--- a/sw/qa/extras/unowriter/unowriter.cxx
+++ b/sw/qa/extras/unowriter/unowriter.cxx
@@ -737,6 +737,39 @@ CPPUNIT_TEST_FIXTURE(SwUnoWriter, testImageCommentAtChar)
     }
 }
 
+CPPUNIT_TEST_FIXTURE(SwUnoWriter, testChapterNumberingCharStyle)
+{
+    loadURL("private:factory/swriter", nullptr);
+
+    uno::Reference<lang::XMultiServiceFactory> xDoc(mxComponent, uno::UNO_QUERY);
+    uno::Reference<beans::XPropertySet> xStyle(
+        xDoc->createInstance("com.sun.star.style.CharacterStyle"), uno::UNO_QUERY);
+    uno::Reference<container::XNamed> xStyleN(xStyle, uno::UNO_QUERY);
+    xStyle->setPropertyValue("CharColor", uno::makeAny(sal_Int32(0x00FF0000)));
+    uno::Reference<style::XStyleFamiliesSupplier> xSFS(mxComponent, uno::UNO_QUERY);
+    uno::Reference<container::XNameContainer> xStyles(
+        xSFS->getStyleFamilies()->getByName("CharacterStyles"), uno::UNO_QUERY);
+    xStyles->insertByName("red", uno::makeAny(xStyle));
+
+    uno::Reference<text::XChapterNumberingSupplier> xCNS(mxComponent, uno::UNO_QUERY);
+    uno::Reference<container::XIndexReplace> xOutline(xCNS->getChapterNumberingRules());
+    {
+        comphelper::SequenceAsHashMap hashMap(xOutline->getByIndex(0));
+        hashMap["CharStyleName"] <<= OUString("red");
+        uno::Sequence<beans::PropertyValue> props;
+        hashMap >> props;
+        xOutline->replaceByIndex(0, uno::makeAny(props));
+    }
+    // now rename the style
+    xStyleN->setName("reddishred");
+    {
+        comphelper::SequenceAsHashMap hashMap(xOutline->getByIndex(0));
+
+        // tdf#137810 this failed, was old value "red"
+        CPPUNIT_ASSERT_EQUAL(OUString("reddishred"), hashMap["CharStyleName"].get<OUString>());
+    }
+}
+
 CPPUNIT_TEST_FIXTURE(SwUnoWriter, testViewCursorPageStyle)
 {
     // Load a document with 2 pages, but a single paragraph.
diff --git a/sw/source/core/unocore/unosett.cxx b/sw/source/core/unocore/unosett.cxx
index 1f68135f7a4a..6d1752881418 100644
--- a/sw/source/core/unocore/unosett.cxx
+++ b/sw/source/core/unocore/unosett.cxx
@@ -1148,6 +1148,7 @@ void SwXNumberingRules::replaceByIndex(sal_Int32 nIndex, const uno::Any& rElemen
         SwXNumberingRules::SetNumberingRuleByIndex( aNumRule,
                             *rProperties, nIndex);
         // set character format if needed
+        // this code appears to be dead - except when a style is assigned for BITMAP numbering?
         const SwCharFormats* pFormats = m_pDocShell->GetDoc()->GetCharFormats();
         const size_t nChCount = pFormats->size();
         for(sal_uInt16 i = 0; i < MAXLEVEL;i++)
@@ -1492,7 +1493,7 @@ void SwXNumberingRules::SetNumberingRuleByIndex(
     SetPropertiesToNumFormat(aFormat, m_sNewCharStyleNames[nIndex],
         &m_sNewBulletFontNames[nIndex],
         &sHeadingStyleName, &sParagraphStyleName,
-        m_pDoc, rProperties);
+        m_pDoc, m_pDocShell, rProperties);
 
 
     if (m_pDoc && !sParagraphStyleName.isEmpty())
@@ -1539,8 +1540,11 @@ void SwXNumberingRules::SetPropertiesToNumFormat(
         OUString *const pHeadingStyleName,
         OUString *const pParagraphStyleName,
         SwDoc *const pDoc,
+        SwDocShell *const pDocShell,
         const uno::Sequence<beans::PropertyValue>& rProperties)
 {
+    assert(pDoc == nullptr || pDocShell == nullptr); // can't be both ordinary and chapter numbering
+
     bool bWrongArg = false;
     std::unique_ptr<SvxBrushItem> pSetBrush;
     std::unique_ptr<Size> pSetSize;
@@ -1588,14 +1592,15 @@ void SwXNumberingRules::SetPropertiesToNumFormat(
             rProp.Value >>= uTmp;
             OUString sCharFormatName;
             SwStyleNameMapper::FillUIName( uTmp, sCharFormatName, SwGetPoolIdFromName::ChrFmt );
+            SwDoc *const pLocalDoc = pDocShell ? pDocShell->GetDoc() : pDoc;
             if (sCharFormatName == UNO_NAME_CHARACTER_FORMAT_NONE)
             {
                 rCharStyleName = aInvalidStyle;
                 aFormat.SetCharFormat(nullptr);
             }
-            else if(pDoc)
+            else if (pLocalDoc)
             {
-                const SwCharFormats* pFormats = pDoc->GetCharFormats();
+                const SwCharFormats* pFormats = pLocalDoc->GetCharFormats();
                 const size_t nChCount = pFormats->size();
 
                 SwCharFormat* pCharFormat = nullptr;
@@ -1614,7 +1619,7 @@ void SwXNumberingRules::SetPropertiesToNumFormat(
                     {
 
                         SfxStyleSheetBase* pBase;
-                        SfxStyleSheetBasePool* pPool = pDoc->GetDocShell()->GetStyleSheetPool();
+                        SfxStyleSheetBasePool* pPool = pLocalDoc->GetDocShell()->GetStyleSheetPool();
                         pBase = pPool->Find(sCharFormatName, SfxStyleFamily::Char);
                         if(!pBase)
                             pBase = &pPool->Make(sCharFormatName, SfxStyleFamily::Char);
@@ -1626,7 +1631,7 @@ void SwXNumberingRules::SetPropertiesToNumFormat(
                 // If the character format has been found its name should not be in the
                 // char style names array
                 rCharStyleName.clear();
-                }
+            }
             else
                 rCharStyleName = sCharFormatName;
         }
@@ -1779,7 +1784,7 @@ void SwXNumberingRules::SetPropertiesToNumFormat(
         {
             OUString sBulletFontName;
             rProp.Value >>= sBulletFontName;
-            SwDocShell* pLclDocShell = pDoc->GetDocShell();
+            SwDocShell *const pLclDocShell = pDocShell ? pDocShell : pDoc ? pDoc->GetDocShell() : nullptr;
             if( !sBulletFontName.isEmpty() && pLclDocShell )
             {
                 const SvxFontListItem* pFontListItem =
@@ -1878,7 +1883,8 @@ void SwXNumberingRules::SetPropertiesToNumFormat(
             }
             pSetVOrient->PutValue(rProp.Value, MID_VERTORIENT_ORIENT);
         }
-        else if (rProp.Name == UNO_NAME_HEADING_STYLE_NAME)
+        else if (rProp.Name == UNO_NAME_HEADING_STYLE_NAME
+                && pDocShell) // only on chapter numbering
         {
             if (pHeadingStyleName)
             {
diff --git a/sw/source/uibase/config/StoredChapterNumbering.cxx b/sw/source/uibase/config/StoredChapterNumbering.cxx
index 5c94fc56110b..eea0c260bbf5 100644
--- a/sw/source/uibase/config/StoredChapterNumbering.cxx
+++ b/sw/source/uibase/config/StoredChapterNumbering.cxx
@@ -152,7 +152,7 @@ public:
         SwXNumberingRules::SetPropertiesToNumFormat(
             aNumberFormat,
             charStyleName,
-            nullptr, nullptr, nullptr, nullptr,
+            nullptr, nullptr, nullptr, nullptr, nullptr,
             props);
         SwNumRulesWithName *const pRules(GetOrCreateRules());
         pRules->SetNumFormat(nIndex, aNumberFormat, charStyleName);


More information about the Libreoffice-commits mailing list