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 407ea237e8d63e88a797706705e5e939521e13c6
Author:     Miklos Vajna <[email protected]>
AuthorDate: Wed Aug 13 09:40:40 2025 +0200
Commit:     Caolán McNamara <[email protected]>
CommitDate: Wed Aug 13 12:53:11 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/+/189492
    Tested-by: Jenkins CollaboraOffice <[email protected]>
    Tested-by: Caolán McNamara <[email protected]>
    Reviewed-by: Caolán McNamara <[email protected]>

diff --git a/sw/inc/redline.hxx b/sw/inc/redline.hxx
index 0868e650cf71..989012b11b02 100644
--- a/sw/inc/redline.hxx
+++ b/sw/inc/redline.hxx
@@ -54,20 +54,20 @@ public:
 class SW_DLLPUBLIC SwRedlineExtraData_FormatColl final : public 
SwRedlineExtraData
 {
     OUString 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( OUString 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 OUString& 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 6fd760d1de22..12faf2546917 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(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(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(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 fc079ee9410f..d252c49797e4 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;
 
@@ -455,7 +456,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 3c770da0d520..9d8e1f7d90b0 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;
@@ -1834,7 +1835,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 abe9f9710408..71ce59ae8a40 100644
--- a/sw/source/core/doc/docredln.cxx
+++ b/sw/source/core/doc/docredln.cxx
@@ -1135,12 +1135,12 @@ void SwRedlineExtraData::dumpAsXml(xmlTextWriterPtr 
pWriter) const
 
 SwRedlineExtraData_FormatColl::SwRedlineExtraData_FormatColl( OUString 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()
@@ -1149,7 +1149,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
@@ -1207,10 +1207,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 10c871222a23..b5eec4b97084 100644
--- a/sw/source/core/unocore/unocrsrhelper.cxx
+++ b/sw/source/core/unocore/unocrsrhelper.cxx
@@ -93,6 +93,7 @@
 #include <poolfmt.hxx>
 #include <paratr.hxx>
 #include <sal/log.hxx>
+#include <istyleaccess.hxx>
 
 using namespace ::com::sun::star;
 using namespace ::com::sun::star::uno;
@@ -1391,8 +1392,10 @@ void makeRedline( SwPaM const & rPaM,
                 // tdf#149747 Get UI style name from programmatic style name
                 SwStyleNameMapper::FillUIName(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() ? sParaStyleName : sUIStyle, 
nStylePoolId, &aItemSet));
+                    sUIStyle.isEmpty() ? sParaStyleName : sUIStyle, 
nStylePoolId, pAutoStyle));
             }
             else if (eType == RedlineType::ParagraphFormat)
                 xRedlineExtraData.reset(new SwRedlineExtraData_FormatColl( 
u""_ustr, RES_POOLCOLL_STANDARD, nullptr ));
diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx 
b/sw/source/filter/ww8/docxattributeoutput.cxx
index 03fb72d5c0a3..ec59b6b4e5c0 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -4211,7 +4211,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);
@@ -4254,7 +4254,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 OUString & sParaStyleName = 
pFormattingChanges->GetFormatName();
                 if (pChangesSet || !sParaStyleName.isEmpty())
                 {

Reply via email to