sw/inc/node.hxx                     |   13 +++++++++++++
 sw/source/core/inc/swfntcch.hxx     |    5 +++--
 sw/source/core/text/frmpaint.cxx    |    2 +-
 sw/source/core/text/porrst.cxx      |    2 +-
 sw/source/core/text/redlnitr.cxx    |    2 +-
 sw/source/core/txtnode/swfntcch.cxx |   13 ++++++-------
 6 files changed, 25 insertions(+), 12 deletions(-)

New commits:
commit e40c363049cc6264e7b074c13e8194c70b46772b
Author:     Noel Grandin <[email protected]>
AuthorDate: Thu Oct 9 16:40:52 2025 +0200
Commit:     Noel Grandin <[email protected]>
CommitDate: Fri Oct 10 09:03:17 2025 +0200

    make SwFontObj/SwFontAccess more explicit
    
    we are already static casting the owner to SwTextFormatColl,
    so make that explicit, which reveals that the callers actually
    want SwTextFormatColl and not just any SwFormatColl.
    
    Change-Id: If52b7b76878392595ad567bff30937487f6cb0af
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/192109
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <[email protected]>

diff --git a/sw/inc/node.hxx b/sw/inc/node.hxx
index 456dc8e8a1e9..2e481d794d93 100644
--- a/sw/inc/node.hxx
+++ b/sw/inc/node.hxx
@@ -501,6 +501,7 @@ public:
     SwFormatColl* GetFormatColl() const { return 
const_cast<SwFormatColl*>(static_cast<const SwFormatColl*>(GetRegisteredIn())); 
}
 
     inline SwFormatColl& GetAnyFormatColl() const;
+    inline SwTextFormatColl& GetTextFormatColl() const;
     void SetCondFormatColl( SwFormatColl* );
     inline SwFormatColl* GetCondFormatColl() const;
 
@@ -728,6 +729,18 @@ inline SwFormatColl& SwContentNode::GetAnyFormatColl() 
const
             : *const_cast<SwFormatColl*>(static_cast<const 
SwFormatColl*>(GetRegisteredIn()));
 }
 
+inline SwTextFormatColl& SwContentNode::GetTextFormatColl() const
+{
+    if (m_pCondColl)
+    {
+        assert(dynamic_cast<SwTextFormatColl*>(m_pCondColl));
+        return *static_cast<SwTextFormatColl*>(m_pCondColl);
+    }
+    auto pRegistered = GetRegisteredIn();
+    assert(dynamic_cast<const SwTextFormatColl*>(pRegistered));
+    return *const_cast<SwTextFormatColl*>(static_cast<const 
SwTextFormatColl*>(pRegistered));
+}
+
 inline const SwAttrSet& SwContentNode::GetSwAttrSet() const
 {
     return mpAttrSet ? *GetpSwAttrSet() : GetAnyFormatColl().GetAttrSet();
diff --git a/sw/source/core/inc/swfntcch.hxx b/sw/source/core/inc/swfntcch.hxx
index 75716db3143d..844e9f3590a2 100644
--- a/sw/source/core/inc/swfntcch.hxx
+++ b/sw/source/core/inc/swfntcch.hxx
@@ -26,6 +26,7 @@
 
 class SwViewShell;
 class SfxPoolItem;
+class SwTextFormatColl;
 
 class SwFontCache : public SwCache
 {
@@ -51,7 +52,7 @@ private:
     const SfxPoolItem* m_pDefaultArray[ NUM_DEFAULT_VALUES ];
 
 public:
-    SwFontObj( const void* pOwner, SwViewShell *pSh );
+    SwFontObj( const SwTextFormatColl* pOwner, SwViewShell *pSh );
 
     virtual ~SwFontObj() override;
 
@@ -67,7 +68,7 @@ class SwFontAccess final : public SwCacheAccess
     virtual SwCacheObj *NewObj( ) override;
 
 public:
-    SwFontAccess( const void *pOwner, SwViewShell *pSh );
+    SwFontAccess( const SwTextFormatColl *pOwner, SwViewShell *pSh );
     SwFontObj *Get();
 };
 
diff --git a/sw/source/core/text/frmpaint.cxx b/sw/source/core/text/frmpaint.cxx
index e7b35b8a49ff..007e0dfda7d3 100644
--- a/sw/source/core/text/frmpaint.cxx
+++ b/sw/source/core/text/frmpaint.cxx
@@ -537,7 +537,7 @@ bool SwTextFrame::PaintEmpty( const SwRect &rRect, bool 
bCheck ) const
             }
             else
             {
-                SwFontAccess aFontAccess( &rTextNode.GetAnyFormatColl(), pSh );
+                SwFontAccess aFontAccess( &rTextNode.GetTextFormatColl(), pSh 
);
                 pFnt.reset(new SwFont( aFontAccess.Get()->GetFont() ));
             }
 
diff --git a/sw/source/core/text/porrst.cxx b/sw/source/core/text/porrst.cxx
index e7054c6a6d27..5d5146e2f8c1 100644
--- a/sw/source/core/text/porrst.cxx
+++ b/sw/source/core/text/porrst.cxx
@@ -372,7 +372,7 @@ SwTwips SwTextFrame::EmptyHeight() const
     }
     else
     {
-        SwFontAccess aFontAccess( &rTextNode.GetAnyFormatColl(), pSh);
+        SwFontAccess aFontAccess( &rTextNode.GetTextFormatColl(), pSh);
         pFnt.reset(new SwFont( aFontAccess.Get()->GetFont() ));
         pFnt->CheckFontCacheId( pSh, pFnt->GetActual() );
     }
diff --git a/sw/source/core/text/redlnitr.cxx b/sw/source/core/text/redlnitr.cxx
index 5c88502ed2c9..ff03cc5452ce 100644
--- a/sw/source/core/text/redlnitr.cxx
+++ b/sw/source/core/text/redlnitr.cxx
@@ -594,7 +594,7 @@ void SwAttrIter::InitFontAndAttrHandler(
         bool const*const pbVertLayoutLRBT)
 {
     // Build a font matching the default paragraph style:
-    SwFontAccess aFontAccess( &rPropsNode.GetAnyFormatColl(), m_pViewShell );
+    SwFontAccess aFontAccess( &rPropsNode.GetTextFormatColl(), m_pViewShell );
     // It is possible that Init is called more than once, e.g., in a
     // SwTextFrame::FormatOnceMore situation or (since sw_redlinehide)
     // from SwAttrIter::Seek(); in the latter case SwTextSizeInfo::m_pFnt
diff --git a/sw/source/core/txtnode/swfntcch.cxx 
b/sw/source/core/txtnode/swfntcch.cxx
index 100a0e7a7965..34c796d4fbd0 100644
--- a/sw/source/core/txtnode/swfntcch.cxx
+++ b/sw/source/core/txtnode/swfntcch.cxx
@@ -32,12 +32,12 @@ extern const sal_uInt8 StackPos[];
 // FontCache is created in txtinit.cxx TextInit_ and deleted in TextFinit
 SwFontCache *pSwFontCache = nullptr;
 
-SwFontObj::SwFontObj( const void *pOwn, SwViewShell *pSh ) :
+SwFontObj::SwFontObj( const SwTextFormatColl *pOwn, SwViewShell *pSh ) :
     SwCacheObj( pOwn ),
-    m_aSwFont( &static_cast<SwTextFormatColl const *>(pOwn)->GetAttrSet(), pSh 
? &pSh->getIDocumentSettingAccess() : nullptr )
+    m_aSwFont( &pOwn->GetAttrSet(), pSh ? &pSh->getIDocumentSettingAccess() : 
nullptr )
 {
     m_aSwFont.AllocFontCacheId( pSh, m_aSwFont.GetActual() );
-    const SwAttrSet& rAttrSet = static_cast<SwTextFormatColl const 
*>(pOwn)->GetAttrSet();
+    const SwAttrSet& rAttrSet = pOwn->GetAttrSet();
     for (sal_uInt16 i = RES_CHRATR_BEGIN; i < RES_CHRATR_END; i++)
         m_pDefaultArray[ StackPos[ i ] ] = &rAttrSet.Get( i );
 }
@@ -46,9 +46,8 @@ SwFontObj::~SwFontObj()
 {
 }
 
-SwFontAccess::SwFontAccess( const void *pOwn, SwViewShell *pSh ) :
-    SwCacheAccess( *pSwFontCache, pOwn,
-            static_cast<const SwTextFormatColl*>(pOwn)->IsInSwFntCache() ),
+SwFontAccess::SwFontAccess( const SwTextFormatColl *pOwn, SwViewShell *pSh ) :
+    SwCacheAccess( *pSwFontCache, pOwn, pOwn->IsInSwFntCache() ),
     m_pShell( pSh )
 {
 }
@@ -61,7 +60,7 @@ SwFontObj *SwFontAccess::Get( )
 SwCacheObj *SwFontAccess::NewObj( )
 {
     const_cast<SwTextFormatColl*>(static_cast<const 
SwTextFormatColl*>(m_pOwner))->SetInSwFntCache();
-    return new SwFontObj( m_pOwner, m_pShell );
+    return new SwFontObj( static_cast<const SwTextFormatColl*>(m_pOwner), 
m_pShell );
 }
 
 SAL_DLLPUBLIC_EXPORT void FlushFontCache()

Reply via email to