sw/inc/doc.hxx                     |    3 +++
 sw/source/core/bastyp/init.cxx     |    2 +-
 sw/source/core/doc/doc.cxx         |   21 +++++++++++++++++++++
 sw/source/filter/ww8/rtfexport.cxx |   21 ++++++++++++++++-----
 4 files changed, 41 insertions(+), 6 deletions(-)

New commits:
commit b6a5cdc0f753c8ed6ed080f9189ac2e2601dce9d
Author:     Noel Grandin <noelgran...@gmail.com>
AuthorDate: Tue Sep 17 20:19:06 2024 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Wed Sep 18 09:24:18 2024 +0200

    dont use GetItemSurrogates for gathering SvxBrushItem
    
    which is very expensive these days
    
    Change-Id: I010d174fbd256da0b220e13cbc50d9b4d8c6b1bd
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/173576
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>
    Tested-by: Jenkins

diff --git a/sw/inc/doc.hxx b/sw/inc/doc.hxx
index 9b6e56db50d9..1f5ec0e53094 100644
--- a/sw/inc/doc.hxx
+++ b/sw/inc/doc.hxx
@@ -1449,6 +1449,9 @@ public:
     /// Iterate over all RES_CHRATR_UNDERLINE SvxUnderlineItem, if the 
function returns false, iteration is stopped
     SW_DLLPUBLIC void ForEachCharacterUnderlineItem(const 
std::function<bool(const SvxUnderlineItem&)>&  ) const;
 
+    /// Iterate over all RES_CHRATR_BACKGROUND SvxBrushItem, if the function 
returns false, iteration is stopped
+    SW_DLLPUBLIC void ForEachCharacterBrushItem(const std::function<bool(const 
SvxBrushItem&)>&  ) const;
+
     // Call into intransparent Basic; expect possible Return String.
     void ExecMacro( const SvxMacro& rMacro, OUString* pRet, SbxArray* pArgs );
 
diff --git a/sw/source/core/bastyp/init.cxx b/sw/source/core/bastyp/init.cxx
index daca2f32d7c4..0920842909e4 100644
--- a/sw/source/core/bastyp/init.cxx
+++ b/sw/source/core/bastyp/init.cxx
@@ -297,7 +297,7 @@ ItemInfoPackage& getItemInfoPackageSwAttributes()
             { RES_CHRATR_BLINK, new SvxBlinkItem( false, RES_CHRATR_BLINK ), 
SID_ATTR_FLASH, SFX_ITEMINFOFLAG_NONE },
             { RES_CHRATR_NOHYPHEN, new SvxNoHyphenItem( false, 
RES_CHRATR_NOHYPHEN ), 0, SFX_ITEMINFOFLAG_NONE },
             { RES_CHRATR_UNUSED2, new SfxVoidItem( RES_CHRATR_UNUSED2 ), 0, 
SFX_ITEMINFOFLAG_NONE },
-            { RES_CHRATR_BACKGROUND, new SvxBrushItem( RES_CHRATR_BACKGROUND 
), SID_ATTR_BRUSH_CHAR, SFX_ITEMINFOFLAG_SUPPORT_SURROGATE },
+            { RES_CHRATR_BACKGROUND, new SvxBrushItem( RES_CHRATR_BACKGROUND 
), SID_ATTR_BRUSH_CHAR, SFX_ITEMINFOFLAG_NONE },
 
             // CJK-Attributes
             { RES_CHRATR_CJK_FONT, nullptr, SID_ATTR_CHAR_CJK_FONT, 
SFX_ITEMINFOFLAG_SUPPORT_SURROGATE },
diff --git a/sw/source/core/doc/doc.cxx b/sw/source/core/doc/doc.cxx
index bc5ec45973eb..58bb026e1c7e 100644
--- a/sw/source/core/doc/doc.cxx
+++ b/sw/source/core/doc/doc.cxx
@@ -1473,6 +1473,27 @@ void SwDoc::ForEachCharacterUnderlineItem( const 
std::function<bool(const SvxUnd
     }
 }
 
+/// Iterate over all SvxBrushItem, if the function returns false, iteration is 
stopped
+void SwDoc::ForEachCharacterBrushItem( const std::function<bool(const 
SvxBrushItem&)>& rFunc ) const
+{
+    for(SwCharFormat* pFormat : *GetCharFormats())
+    {
+        const SwAttrSet& rAttrSet = pFormat->GetAttrSet();
+        if (const SvxBrushItem* pItem = 
rAttrSet.GetItemIfSet(RES_CHRATR_BACKGROUND))
+            if (!rFunc(*pItem))
+                return;
+    }
+    std::vector<std::shared_ptr<SfxItemSet>> aStyles;
+    for (auto eFamily : { IStyleAccess::AUTO_STYLE_CHAR, 
IStyleAccess::AUTO_STYLE_RUBY, IStyleAccess::AUTO_STYLE_PARA, 
IStyleAccess::AUTO_STYLE_NOTXT })
+    {
+        const_cast<SwDoc*>(this)->GetIStyleAccess().getAllStyles(aStyles, 
eFamily);
+        for (const auto & rxItemSet : aStyles)
+            if (const SvxBrushItem* pItem = 
rxItemSet->GetItemIfSet(RES_CHRATR_BACKGROUND))
+                if (!rFunc(*pItem))
+                    return;
+    }
+}
+
 void SwDoc::Summary(SwDoc& rExtDoc, sal_uInt8 nLevel, sal_uInt8 nPara, bool 
bImpress)
 {
     const SwOutlineNodes& rOutNds = GetNodes().GetOutLineNds();
diff --git a/sw/source/filter/ww8/rtfexport.cxx 
b/sw/source/filter/ww8/rtfexport.cxx
index ee490d562013..d7bbeb6bfb53 100644
--- a/sw/source/filter/ww8/rtfexport.cxx
+++ b/sw/source/filter/ww8/rtfexport.cxx
@@ -1346,18 +1346,16 @@ void RtfExport::OutColorTable()
     }
 
     // background color
-    static const sal_uInt16 aBrushIds[] = { RES_BACKGROUND, 
RES_CHRATR_BACKGROUND, 0 };
 
-    for (const sal_uInt16* pIds = aBrushIds; *pIds; ++pIds)
     {
-        auto pBackground = static_cast<const 
SvxBrushItem*>(GetDfltAttr(*pIds));
+        const SvxBrushItem* pBackground = GetDfltAttr(RES_BACKGROUND);
         InsColor(pBackground->GetColor());
-        pBackground = static_cast<const 
SvxBrushItem*>(rPool.GetUserDefaultItem(*pIds));
+        pBackground = rPool.GetUserDefaultItem(RES_BACKGROUND);
         if (pBackground)
         {
             InsColor(pBackground->GetColor());
         }
-        rPool.GetItemSurrogates(aSurrogates, *pIds);
+        rPool.GetItemSurrogates(aSurrogates, RES_BACKGROUND);
         for (const SfxPoolItem* pItem : aSurrogates)
         {
             pBackground = static_cast<const SvxBrushItem*>(pItem);
@@ -1367,6 +1365,19 @@ void RtfExport::OutColorTable()
             }
         }
     }
+    {
+        const SvxBrushItem* pBackground = GetDfltAttr(RES_CHRATR_BACKGROUND);
+        InsColor(pBackground->GetColor());
+        pBackground = rPool.GetUserDefaultItem(RES_CHRATR_BACKGROUND);
+        if (pBackground)
+        {
+            InsColor(pBackground->GetColor());
+        }
+        m_rDoc.ForEachCharacterBrushItem([this](const SvxBrushItem& rBrush) -> 
bool {
+            InsColor(rBrush.GetColor());
+            return true;
+        });
+    }
 
     // shadow color
     {

Reply via email to