sw/inc/doc.hxx                     |    3 ++
 sw/source/core/bastyp/init.cxx     |    2 -
 sw/source/core/doc/doc.cxx         |   39 +++++++++++++++++++++++++++++++++++++
 sw/source/filter/ww8/rtfexport.cxx |   15 ++++----------
 4 files changed, 48 insertions(+), 11 deletions(-)

New commits:
commit 3d0058306385d0322c18d397fce1cd6e94daa1a3
Author:     Noel Grandin <noelgran...@gmail.com>
AuthorDate: Tue Sep 24 15:43:21 2024 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Mon Sep 30 09:46:47 2024 +0200

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

diff --git a/sw/inc/doc.hxx b/sw/inc/doc.hxx
index a90f82fcd720..8c3adf65c6ec 100644
--- a/sw/inc/doc.hxx
+++ b/sw/inc/doc.hxx
@@ -1474,6 +1474,9 @@ public:
     /// Iterate over all RES_SHADOW SvxShadowItem, if the function returns 
false, iteration is stopped
     SW_DLLPUBLIC void ForEachShadowItem(const std::function<bool(const 
SvxShadowItem&)>&  ) const;
 
+    /// Iterate over all RES_BACKGROUND SvxBrushItem, if the function returns 
false, iteration is stopped
+    SW_DLLPUBLIC void ForEachBackgroundBrushItem(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 3bbfd40268a1..bd69f9689cbc 100644
--- a/sw/source/core/bastyp/init.cxx
+++ b/sw/source/core/bastyp/init.cxx
@@ -407,7 +407,7 @@ ItemInfoPackage& getItemInfoPackageSwAttributes()
             { RES_VERT_ORIENT, new SwFormatVertOrient, FN_VERT_ORIENT, 
SFX_ITEMINFOFLAG_NONE },
             { RES_HORI_ORIENT, new SwFormatHoriOrient, FN_HORI_ORIENT, 
SFX_ITEMINFOFLAG_NONE },
             { RES_ANCHOR, new SwFormatAnchor, 0, SFX_ITEMINFOFLAG_NONE },
-            { RES_BACKGROUND, new SvxBrushItem( RES_BACKGROUND ), 
SID_ATTR_BRUSH, SFX_ITEMINFOFLAG_SUPPORT_SURROGATE },
+            { RES_BACKGROUND, new SvxBrushItem( RES_BACKGROUND ), 
SID_ATTR_BRUSH, SFX_ITEMINFOFLAG_NONE },
             { RES_BOX, new SvxBoxItem( RES_BOX ), SID_ATTR_BORDER_OUTER, 
SFX_ITEMINFOFLAG_NONE },
             { RES_SHADOW, new SvxShadowItem( RES_SHADOW ), 
SID_ATTR_BORDER_SHADOW, SFX_ITEMINFOFLAG_NONE },
             { RES_FRMMACRO, new SvxMacroItem( RES_FRMMACRO ), 
SID_ATTR_MACROITEM, SFX_ITEMINFOFLAG_NONE },
diff --git a/sw/source/core/doc/doc.cxx b/sw/source/core/doc/doc.cxx
index f32c3655b571..6c3db0e7acaa 100644
--- a/sw/source/core/doc/doc.cxx
+++ b/sw/source/core/doc/doc.cxx
@@ -1634,6 +1634,45 @@ void SwDoc::ForEachShadowItem(const 
std::function<bool(const SvxShadowItem&)>& r
     }
 }
 
+/// Iterate over all RES_BACKGROUND SvxBrushItem, if the function returns 
false, iteration is stopped
+void SwDoc::ForEachBackgroundBrushItem(const std::function<bool(const 
SvxBrushItem&)>& rFunc ) const
+{
+    SwNodeOffset nCount = GetNodes().Count();
+    for (SwNodeOffset i(0); i < nCount; ++i)
+    {
+        const SwNode* pNode = GetNodes()[i];
+        if (!pNode->IsTableNode())
+            continue;
+        const SwTableNode* pTableNode = pNode->GetTableNode();
+        const SwTable& rTable = pTableNode->GetTable();
+        if (const SwTableFormat* pFormat = rTable.GetFrameFormat())
+        {
+            const SwAttrSet& rAttrSet = pFormat->GetAttrSet();
+            if (const SvxBrushItem* pItem = 
rAttrSet.GetItemIfSet(RES_BACKGROUND))
+                if (!rFunc(*pItem))
+                    return;
+        }
+        for (const SwTableLine* pTableLine : rTable.GetTabLines())
+        {
+            if (const SwTableLineFormat* pFormat = 
pTableLine->GetFrameFormat())
+            {
+                const SwAttrSet& rAttrSet = pFormat->GetAttrSet();
+                if (const SvxBrushItem* pItem = 
rAttrSet.GetItemIfSet(RES_BACKGROUND))
+                    if (!rFunc(*pItem))
+                        return;
+            }
+            for (const SwTableBox* pTableBox : pTableLine->GetTabBoxes())
+                if (SwTableBoxFormat* pFormat = pTableBox->GetFrameFormat())
+                {
+                    const SwAttrSet& rAttrSet = pFormat->GetAttrSet();
+                    if (const SvxBrushItem* pItem = 
rAttrSet.GetItemIfSet(RES_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 0ce35c6f9c29..ffd36410f4b6 100644
--- a/sw/source/filter/ww8/rtfexport.cxx
+++ b/sw/source/filter/ww8/rtfexport.cxx
@@ -1316,7 +1316,6 @@ void RtfExport::OutColorTable()
     InsColor(COL_BROWN);
     InsColor(COL_GRAY);
     InsColor(COL_LIGHTGRAY);
-    ItemSurrogates aSurrogates;
 
     // char color
     {
@@ -1355,15 +1354,10 @@ void RtfExport::OutColorTable()
         {
             InsColor(pBackground->GetColor());
         }
-        rPool.GetItemSurrogates(aSurrogates, RES_BACKGROUND);
-        for (const SfxPoolItem* pItem : aSurrogates)
-        {
-            pBackground = static_cast<const SvxBrushItem*>(pItem);
-            if (pBackground)
-            {
-                InsColor(pBackground->GetColor());
-            }
-        }
+        m_rDoc.ForEachBackgroundBrushItem([this](const SvxBrushItem& rBrush) 
-> bool {
+            InsColor(rBrush.GetColor());
+            return true;
+        });
     }
     {
         const SvxBrushItem* pBackground = GetDfltAttr(RES_CHRATR_BACKGROUND);
@@ -1416,6 +1410,7 @@ void RtfExport::OutColorTable()
     }
 
     // TextFrame or paragraph background solid fill.
+    ItemSurrogates aSurrogates;
     rPool.GetItemSurrogatesForItem(aSurrogates, 
SfxItemType::XFillColorItemType);
     for (const SfxPoolItem* pItem : aSurrogates)
     {

Reply via email to