[Libreoffice-commits] core.git: sw/source

Noel Grandin noel.grandin at collabora.co.uk
Fri Jun 29 14:01:47 UTC 2018


 sw/source/core/text/itrform2.cxx |    2 +-
 sw/source/core/text/porfld.cxx   |   36 +++++++++++++++++-------------------
 sw/source/core/text/porfld.hxx   |    6 +++---
 sw/source/core/text/txtftn.cxx   |    2 +-
 4 files changed, 22 insertions(+), 24 deletions(-)

New commits:
commit f422f2bb775e04f64e03d4b65d81add55543513c
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date:   Thu Jun 28 14:36:53 2018 +0200

    loplugin:useuniqueptr in SwFieldPortion
    
    Change-Id: I2ce38d46798627f808dd539a7d74f5c6cf7f509a
    Reviewed-on: https://gerrit.libreoffice.org/56631
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/sw/source/core/text/itrform2.cxx b/sw/source/core/text/itrform2.cxx
index 10aa3be6ff72..3949fc35bb71 100644
--- a/sw/source/core/text/itrform2.cxx
+++ b/sw/source/core/text/itrform2.cxx
@@ -750,7 +750,7 @@ void SwTextFormatter::CalcAscent( SwTextFormatInfo &rInf, SwLinePortion *pPor )
     {
         // Numbering + InterNetFields can keep an own font, then their size is
         // independent from hard attribute values
-        SwFont* pFieldFnt = static_cast<SwFieldPortion*>(pPor)->m_pFont;
+        SwFont* pFieldFnt = static_cast<SwFieldPortion*>(pPor)->m_pFont.get();
         SwFontSave aSave( rInf, pFieldFnt );
         pPor->Height( rInf.GetTextHeight() );
         pPor->SetAscent( rInf.GetAscent() );
diff --git a/sw/source/core/text/porfld.cxx b/sw/source/core/text/porfld.cxx
index d40ff3ed3dc0..9b76c0f5a7a0 100644
--- a/sw/source/core/text/porfld.cxx
+++ b/sw/source/core/text/porfld.cxx
@@ -22,6 +22,7 @@
 #include <com/sun/star/i18n/ScriptType.hpp>
 #include <com/sun/star/i18n/XBreakIterator.hpp>
 #include <vcl/graph.hxx>
+#include <o3tl/make_unique.hxx>
 #include <editeng/brushitem.hxx>
 #include <vcl/metric.hxx>
 #include <vcl/outdev.hxx>
@@ -51,8 +52,8 @@ SwLinePortion *SwFieldPortion::Compress()
 
 SwFieldPortion *SwFieldPortion::Clone( const OUString &rExpand ) const
 {
-    SwFont *pNewFnt;
-    if( nullptr != ( pNewFnt = m_pFont ) )
+    SwFont *pNewFnt = m_pFont.get();
+    if( nullptr != pNewFnt )
     {
         pNewFnt = new SwFont( *m_pFont );
     }
@@ -103,16 +104,14 @@ SwFieldPortion::SwFieldPortion( const SwFieldPortion& rField )
     , m_nAttrFieldType( rField.m_nAttrFieldType)
 {
     if ( rField.HasFont() )
-        m_pFont = new SwFont( *rField.GetFont() );
-    else
-        m_pFont = nullptr;
+        m_pFont.reset( new SwFont( *rField.GetFont() ) );
 
     SetWhichPor( POR_FLD );
 }
 
 SwFieldPortion::~SwFieldPortion()
 {
-    delete m_pFont;
+    m_pFont.reset();
     if( pBlink )
         pBlink->Delete( this );
 }
@@ -283,7 +282,7 @@ void SwFieldPortion::CheckScript( const SwTextSizeInfo &rInf )
     else if ( nTmp != nActual )
     {
         if( !m_pFont )
-            m_pFont = new SwFont( *rInf.GetFont() );
+            m_pFont.reset( new SwFont( *rInf.GetFont() ) );
         m_pFont->SetActual( nTmp );
     }
 
@@ -320,7 +319,7 @@ bool SwFieldPortion::Format( SwTextFormatInfo &rInf )
         if( m_pFont )
             m_pFont->GoMagic( rInf.GetVsh(), m_pFont->GetActual() );
 
-        SwFontSave aSave( rInf, m_pFont );
+        SwFontSave aSave( rInf, m_pFont.get() );
 
         // Length must be 0: the length is set for bFull after format
         // and passed along in nRest. Or else the old length would be
@@ -405,8 +404,7 @@ bool SwFieldPortion::Format( SwTextFormatInfo &rInf )
             SwFieldPortion *pField = Clone( aNew );
             if( !aNew.isEmpty() && !pField->GetFont() )
             {
-                SwFont *pNewFnt = new SwFont( *rInf.GetFont() );
-                pField->SetFont( pNewFnt );
+                pField->SetFont( o3tl::make_unique<SwFont>( *rInf.GetFont() ) );
             }
             pField->SetFollow( true );
             SetHasFollow( true );
@@ -428,7 +426,7 @@ bool SwFieldPortion::Format( SwTextFormatInfo &rInf )
 
 void SwFieldPortion::Paint( const SwTextPaintInfo &rInf ) const
 {
-    SwFontSave aSave( rInf, m_pFont );
+    SwFontSave aSave( rInf, m_pFont.get() );
 
     OSL_ENSURE(GetLen() <= TextFrameIndex(1), "SwFieldPortion::Paint: rest-portion pollution?");
     if( Width() && ( !m_bPlaceHolder || rInf.GetOpt().IsShowPlaceHolderFields() ) )
@@ -459,7 +457,7 @@ void SwFieldPortion::HandlePortion( SwPortionHandler& rPH ) const
         nH = m_pFont->GetSize(m_pFont->GetActual()).Height();
         nW = m_pFont->GetSize(m_pFont->GetActual()).Width();
     }
-    rPH.Special( GetLen(), m_aExpand, GetWhichPor(), nH, nW, m_pFont );
+    rPH.Special( GetLen(), m_aExpand, GetWhichPor(), nH, nW, m_pFont.get() );
     if( GetWhichPor() == POR_FLD )
     {
         rPH.SetAttrFieldType(m_nAttrFieldType);
@@ -468,15 +466,15 @@ void SwFieldPortion::HandlePortion( SwPortionHandler& rPH ) const
 
 SwPosSize SwFieldPortion::GetTextSize( const SwTextSizeInfo &rInf ) const
 {
-    SwFontSave aSave( rInf, m_pFont );
+    SwFontSave aSave( rInf, m_pFont.get() );
     SwPosSize aSize( SwExpandPortion::GetTextSize( rInf ) );
     return aSize;
 }
 
 SwFieldPortion *SwHiddenPortion::Clone(const OUString &rExpand ) const
 {
-    SwFont *pNewFnt;
-    if( nullptr != ( pNewFnt = m_pFont ) )
+    SwFont *pNewFnt = m_pFont.get();
+    if( nullptr != pNewFnt )
         pNewFnt = new SwFont( *m_pFont );
     return new SwHiddenPortion( rExpand, pNewFnt );
 }
@@ -485,7 +483,7 @@ void SwHiddenPortion::Paint( const SwTextPaintInfo &rInf ) const
 {
     if( Width() )
     {
-        SwFontSave aSave( rInf, m_pFont );
+        SwFontSave aSave( rInf, m_pFont.get() );
         rInf.DrawViewOpt( *this, POR_HIDDEN );
         SwExpandPortion::Paint( rInf );
     }
@@ -521,8 +519,8 @@ TextFrameIndex SwNumberPortion::GetCursorOfst(const sal_uInt16) const
 
 SwFieldPortion *SwNumberPortion::Clone( const OUString &rExpand ) const
 {
-    SwFont *pNewFnt;
-    if( nullptr != ( pNewFnt = m_pFont ) )
+    SwFont *pNewFnt = m_pFont.get();
+    if( nullptr != pNewFnt )
         pNewFnt = new SwFont( *m_pFont );
 
     return new SwNumberPortion( rExpand, pNewFnt, IsLeft(), IsCenter(),
@@ -678,7 +676,7 @@ void SwNumberPortion::Paint( const SwTextPaintInfo &rInf ) const
                             STRIKEOUT_NONE != m_pFont->GetStrikeout() ) &&
                             !m_pFont->IsWordLineMode();
 
-        SwFontSave aSave( rInf, m_pFont );
+        SwFontSave aSave( rInf, m_pFont.get() );
 
         if( nFixWidth == Width() && ! HasFollow() )
             SwExpandPortion::Paint( rInf );
diff --git a/sw/source/core/text/porfld.hxx b/sw/source/core/text/porfld.hxx
index d7c06e2ae4b2..28acae3141cd 100644
--- a/sw/source/core/text/porfld.hxx
+++ b/sw/source/core/text/porfld.hxx
@@ -32,7 +32,7 @@ class SwFieldPortion : public SwExpandPortion
     friend class SwTextFormatter;
 protected:
     OUString  m_aExpand;          // The expanded field
-    SwFont  *m_pFont;              // For multi-line fields
+    std::unique_ptr<SwFont> m_pFont;  // For multi-line fields
     TextFrameIndex m_nNextOffset;  // Offset of the follow in the original string
     TextFrameIndex m_nNextScriptChg;
     sal_uInt16  m_nViewWidth;     // Screen width for empty fields
@@ -47,7 +47,7 @@ protected:
     const bool m_bPlaceHolder : 1;
     bool m_bNoLength : 1;       // HACK for meta suffix (no CH_TXTATR)
 
-    void SetFont( SwFont *pNew ) { m_pFont = pNew; }
+    void SetFont( std::unique_ptr<SwFont> pNew ) { m_pFont = std::move(pNew); }
     bool IsNoLength() const  { return m_bNoLength; }
     void SetNoLength()       { m_bNoLength = true; }
 
@@ -61,7 +61,7 @@ public:
     void CheckScript( const SwTextSizeInfo &rInf );
     bool HasFont() const { return nullptr != m_pFont; }
     // #i89179# - made public
-    const SwFont *GetFont() const { return m_pFont; }
+    const SwFont *GetFont() const { return m_pFont.get(); }
 
     const OUString& GetExp() const { return m_aExpand; }
     virtual bool GetExpText( const SwTextSizeInfo &rInf, OUString &rText ) const override;
diff --git a/sw/source/core/text/txtftn.cxx b/sw/source/core/text/txtftn.cxx
index cb0ab2f2fdb4..3df8571b4ed0 100644
--- a/sw/source/core/text/txtftn.cxx
+++ b/sw/source/core/text/txtftn.cxx
@@ -1423,7 +1423,7 @@ void SwQuoVadisPortion::Paint( const SwTextPaintInfo &rInf ) const
     {
         rInf.DrawViewOpt( *this, POR_QUOVADIS );
         SwTextSlot aDiffText( &rInf, this, true, false );
-        SwFontSave aSave( rInf, m_pFont );
+        SwFontSave aSave( rInf, m_pFont.get() );
         rInf.DrawText( *this, rInf.GetLen(), true );
     }
 }


More information about the Libreoffice-commits mailing list