sw/inc/redline.hxx                                      |    8 ++++----
 sw/source/core/doc/DocumentContentOperationsManager.cxx |    6 ++++--
 sw/source/core/doc/DocumentRedlineManager.cxx           |    7 ++++++-
 sw/source/core/doc/docfmt.cxx                           |    5 ++++-
 sw/source/core/doc/docredln.cxx                         |   12 ++++++------
 sw/source/core/unocore/unocrsrhelper.cxx                |    5 ++++-
 sw/source/filter/ww8/docxattributeoutput.cxx            |    4 ++--
 7 files changed, 30 insertions(+), 17 deletions(-)

New commits:
commit 2db0a779944f9496371b3ba68f7494c635ad431d
Author:     Miklos Vajna <[email protected]>
AuthorDate: Wed Aug 13 09:40:40 2025 +0200
Commit:     Miklos Vajna <[email protected]>
CommitDate: Wed Aug 13 18:16:47 2025 +0200

    tdf#167761 sw format redline: register the item set in the autostyle pool
    
    Load the DOCX bugdoc, save to ODT, open it, go to the 36pt font size
    format redline, click reject, should be 24th, but it's now 12pt instead.
    
    What happens is that SwRedlineExtraData_FormatColl SfxItemSet is not
    part of the autoformat mechanism, so the ODF markup can't even refer to
    it. So reject works correctly after DOCX open, but not after ODF
    roundtrip.
    
    The first step here is to replace the std::unique_ptr<SfxItemSet> with a
    shared pointer, similar to what SwFormatAutoFormat does for normal
    character direct formatting (the redline just stores the old direct
    formatting).
    
    This allows producing the std::shared_ptr<SfxItemSet> in the autostyle
    pool, so the ODF export will be able to export the old direct formatting
    as a next step (not yet done here.)
    
    Change-Id: I1f7a8083ce766bd2ec06bb8e19bfce0eaebfe405
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/189509
    Tested-by: Jenkins
    Reviewed-by: Miklos Vajna <[email protected]>

diff --git a/sw/inc/redline.hxx b/sw/inc/redline.hxx
index 1eb738e370bb..0eca2fb5481f 100644
--- a/sw/inc/redline.hxx
+++ b/sw/inc/redline.hxx
@@ -54,20 +54,20 @@ public:
 class SW_DLLPUBLIC SwRedlineExtraData_FormatColl final : public 
SwRedlineExtraData
 {
     UIName m_sFormatNm;
-    std::unique_ptr<SfxItemSet> m_pSet;
+    std::shared_ptr<SfxItemSet> m_pSet;
     sal_uInt16 m_nPoolId;
     bool m_bFormatAll; // don't strip the last paragraph mark
 public:
     SwRedlineExtraData_FormatColl( UIName aColl, sal_uInt16 nPoolFormatId,
-                                const SfxItemSet* pSet = nullptr, bool 
bFormatAll = true );
+                                const std::shared_ptr<SfxItemSet>& pSet = 
nullptr, bool bFormatAll = true );
     virtual ~SwRedlineExtraData_FormatColl() override;
     virtual SwRedlineExtraData* CreateNew() const override;
     virtual void Reject( SwPaM& rPam ) const override;
     virtual bool operator == ( const SwRedlineExtraData& ) const override;
 
     const UIName& GetFormatName() const        { return m_sFormatNm; }
-    void SetItemSet( const SfxItemSet& rSet );
-    SfxItemSet* GetItemSet( ) const { return m_pSet.get(); }
+    void SetItemSet( const std::shared_ptr<SfxItemSet>& pSet );
+    std::shared_ptr<SfxItemSet> GetItemSet( ) const { return m_pSet; }
     void SetFormatAll( bool bAll )               { m_bFormatAll = bAll; }
 
     void dumpAsXml(xmlTextWriterPtr pWriter) const override;
diff --git a/sw/source/core/doc/DocumentContentOperationsManager.cxx 
b/sw/source/core/doc/DocumentContentOperationsManager.cxx
index c85591483dc9..912ea1eb33cd 100644
--- a/sw/source/core/doc/DocumentContentOperationsManager.cxx
+++ b/sw/source/core/doc/DocumentContentOperationsManager.cxx
@@ -1281,7 +1281,7 @@ namespace //local functions originally from docfmt.cxx
                         if (pFormattingChanges)
                         {
                             // Get the item set that holds all the changes 
properties
-                            const SfxItemSet *pChangesSet = 
pFormattingChanges->GetItemSet();
+                            std::shared_ptr<SfxItemSet> pChangesSet = 
pFormattingChanges->GetItemSet();
                             xExtra.reset(new 
SwRedlineExtraData_FormatColl(UIName(u""_ustr), USHRT_MAX, pChangesSet));
                             break;
                         }
@@ -1318,7 +1318,9 @@ namespace //local functions originally from docfmt.cxx
             // which doesn't handle invalid/dontcare items so clear them here
             aSet.ClearInvalidItems();
 
-            xExtra.reset(new SwRedlineExtraData_FormatColl(UIName(u""_ustr), 
USHRT_MAX, &aSet));
+            IStyleAccess& rStyleAccess = rDoc.GetIStyleAccess();
+            std::shared_ptr<SfxItemSet> pAutoStyle = 
rStyleAccess.getAutomaticStyle(aSet, IStyleAccess::AUTO_STYLE_CHAR);
+            xExtra.reset(new SwRedlineExtraData_FormatColl(UIName(u""_ustr), 
USHRT_MAX, pAutoStyle));
         }
 
         pRedline->SetExtraData(xExtra.get() );
diff --git a/sw/source/core/doc/DocumentRedlineManager.cxx 
b/sw/source/core/doc/DocumentRedlineManager.cxx
index 9771d1bbbd66..d05a4b38b013 100644
--- a/sw/source/core/doc/DocumentRedlineManager.cxx
+++ b/sw/source/core/doc/DocumentRedlineManager.cxx
@@ -43,6 +43,7 @@
 #include <editeng/prntitem.hxx>
 #include <comphelper/lok.hxx>
 #include <svl/itemiter.hxx>
+#include <istyleaccess.hxx>
 
 using namespace com::sun::star;
 
@@ -454,7 +455,11 @@ namespace
             if (bCopy && !bSameSet)
                 rDoc.getIDocumentContentOperations().InsertItemSet(aPam, 
aTmp2);
             else if (!bCopy && (!bSameSet || pFromColl != pToColl))
-                return std::make_unique<SwRedlineExtraData_FormatColl>( 
pFromColl->GetName(), USHRT_MAX, &aTmp2 );
+            {
+                IStyleAccess& rStyleAccess = rDoc.GetIStyleAccess();
+                std::shared_ptr<SfxItemSet> pAutoStyle = 
rStyleAccess.getAutomaticStyle(aTmp2, IStyleAccess::AUTO_STYLE_CHAR);
+                return std::make_unique<SwRedlineExtraData_FormatColl>( 
pFromColl->GetName(), USHRT_MAX, pAutoStyle );
+            }
         }
         return nullptr;
     }
diff --git a/sw/source/core/doc/docfmt.cxx b/sw/source/core/doc/docfmt.cxx
index 5cf75cdf5613..6c69ac91129f 100644
--- a/sw/source/core/doc/docfmt.cxx
+++ b/sw/source/core/doc/docfmt.cxx
@@ -80,6 +80,7 @@
 #include <memory>
 #include <algorithm>
 #include <functional>
+#include <istyleaccess.hxx>
 
 using namespace ::com::sun::star::i18n;
 using namespace ::com::sun::star::uno;
@@ -1831,7 +1832,9 @@ void SwDoc::SetTextFormatCollByAutoFormat( const 
SwPosition& rPos, sal_uInt16 nP
             if( SfxItemState::SET == pTNd->GetpSwAttrSet()->GetItemState(
                     RES_PARATR_ADJUST, false, &pItem ))
                 aTmp.Put( *pItem );
-            aExtraData.SetItemSet( aTmp );
+            IStyleAccess& rStyleAccess = pTNd->GetDoc().GetIStyleAccess();
+            std::shared_ptr<SfxItemSet> pAutoStyle = 
rStyleAccess.getAutomaticStyle(aTmp, IStyleAccess::AUTO_STYLE_CHAR);
+            aExtraData.SetItemSet( pAutoStyle );
         }
         pRedl->SetExtraData( &aExtraData );
 
diff --git a/sw/source/core/doc/docredln.cxx b/sw/source/core/doc/docredln.cxx
index f9e35eb42581..60216e7f46b5 100644
--- a/sw/source/core/doc/docredln.cxx
+++ b/sw/source/core/doc/docredln.cxx
@@ -1130,12 +1130,12 @@ void SwRedlineExtraData::dumpAsXml(xmlTextWriterPtr 
pWriter) const
 
 SwRedlineExtraData_FormatColl::SwRedlineExtraData_FormatColl( UIName aColl,
                                                 sal_uInt16 nPoolFormatId,
-                                                const SfxItemSet* pItemSet,
+                                                const 
std::shared_ptr<SfxItemSet>& pItemSet,
                                                 bool bFormatAll )
     : m_sFormatNm(std::move(aColl)), m_nPoolId(nPoolFormatId), 
m_bFormatAll(bFormatAll)
 {
     if( pItemSet && pItemSet->Count() )
-        m_pSet.reset( new SfxItemSet( *pItemSet ) );
+        m_pSet = pItemSet;
 }
 
 SwRedlineExtraData_FormatColl::~SwRedlineExtraData_FormatColl()
@@ -1144,7 +1144,7 @@ 
SwRedlineExtraData_FormatColl::~SwRedlineExtraData_FormatColl()
 
 SwRedlineExtraData* SwRedlineExtraData_FormatColl::CreateNew() const
 {
-    return new SwRedlineExtraData_FormatColl( m_sFormatNm, m_nPoolId, 
m_pSet.get(), m_bFormatAll );
+    return new SwRedlineExtraData_FormatColl( m_sFormatNm, m_nPoolId, m_pSet, 
m_bFormatAll );
 }
 
 void SwRedlineExtraData_FormatColl::Reject( SwPaM& rPam ) const
@@ -1202,10 +1202,10 @@ bool SwRedlineExtraData_FormatColl::operator == ( const 
SwRedlineExtraData& r) c
                ( m_pSet && rCmp.m_pSet && *m_pSet == *rCmp.m_pSet ) );
 }
 
-void SwRedlineExtraData_FormatColl::SetItemSet( const SfxItemSet& rSet )
+void SwRedlineExtraData_FormatColl::SetItemSet( const 
std::shared_ptr<SfxItemSet>& pSet )
 {
-    if( rSet.Count() )
-        m_pSet.reset( new SfxItemSet( rSet ) );
+    if( pSet && pSet->Count() )
+        m_pSet = pSet;
     else
         m_pSet.reset();
 }
diff --git a/sw/source/core/unocore/unocrsrhelper.cxx 
b/sw/source/core/unocore/unocrsrhelper.cxx
index 71dcdea44d76..defa0496db1a 100644
--- a/sw/source/core/unocore/unocrsrhelper.cxx
+++ b/sw/source/core/unocore/unocrsrhelper.cxx
@@ -94,6 +94,7 @@
 #include <paratr.hxx>
 #include <sal/log.hxx>
 #include <names.hxx>
+#include <istyleaccess.hxx>
 
 using namespace ::com::sun::star;
 using namespace ::com::sun::star::uno;
@@ -1392,8 +1393,10 @@ void makeRedline( SwPaM const & rPaM,
                 // tdf#149747 Get UI style name from programmatic style name
                 SwStyleNameMapper::FillUIName(ProgName(sParaStyleName), 
sUIStyle,
                                               SwGetPoolIdFromName::TxtColl);
+                IStyleAccess& rStyleAccess = rDoc.GetIStyleAccess();
+                std::shared_ptr<SfxItemSet> pAutoStyle = 
rStyleAccess.getAutomaticStyle(aItemSet, IStyleAccess::AUTO_STYLE_CHAR);
                 xRedlineExtraData.reset(new SwRedlineExtraData_FormatColl(
-                    sUIStyle.isEmpty() ? UIName(sParaStyleName) : 
std::move(sUIStyle), nStylePoolId, &aItemSet));
+                    sUIStyle.isEmpty() ? UIName(sParaStyleName) : 
std::move(sUIStyle), nStylePoolId, pAutoStyle));
             }
             else if (eType == RedlineType::ParagraphFormat)
                 xRedlineExtraData.reset(new SwRedlineExtraData_FormatColl( 
UIName(u""_ustr), RES_POOLCOLL_STANDARD, nullptr ));
diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx 
b/sw/source/filter/ww8/docxattributeoutput.cxx
index 034522181382..2ec27ab4f10f 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -4208,7 +4208,7 @@ void DocxAttributeOutput::Redline( const SwRedlineData* 
pRedlineData)
             if (pFormattingChanges)
             {
                  // Get the item set that holds all the changes properties
-                const SfxItemSet *pChangesSet = 
pFormattingChanges->GetItemSet();
+                std::shared_ptr<SfxItemSet> pChangesSet = 
pFormattingChanges->GetItemSet();
                 if (pChangesSet)
                 {
                     m_pSerializer->mark(Tag_Redline_1);
@@ -4251,7 +4251,7 @@ void DocxAttributeOutput::Redline( const SwRedlineData* 
pRedlineData)
             if (pFormattingChanges)
             {
                 // Get the item set that holds all the changes properties
-                const SfxItemSet *pChangesSet = 
pFormattingChanges->GetItemSet();
+                std::shared_ptr<SfxItemSet> pChangesSet = 
pFormattingChanges->GetItemSet();
                 const UIName & sParaStyleName = 
pFormattingChanges->GetFormatName();
                 if (pChangesSet || !sParaStyleName.isEmpty())
                 {

Reply via email to