[Libreoffice-commits] core.git: vcl/inc vcl/source

Noel Grandin noel.grandin at collabora.co.uk
Fri Feb 2 06:44:19 UTC 2018


 vcl/inc/PhysicalFontFamily.hxx         |    2 +-
 vcl/source/font/PhysicalFontFamily.cxx |   23 +++++++++--------------
 2 files changed, 10 insertions(+), 15 deletions(-)

New commits:
commit d60d2973eca003b46860bf5effe9d0e638268f94
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date:   Mon Jan 29 09:11:44 2018 +0200

    loplugin:useuniqueptr in PhysicalFontFamily
    
    Change-Id: I010339eaf7874e61b5d0e5d41574c54e98ea1921
    Reviewed-on: https://gerrit.libreoffice.org/49094
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>
    Tested-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/vcl/inc/PhysicalFontFamily.hxx b/vcl/inc/PhysicalFontFamily.hxx
index b782c4fe69f4..e88db8203809 100644
--- a/vcl/inc/PhysicalFontFamily.hxx
+++ b/vcl/inc/PhysicalFontFamily.hxx
@@ -78,7 +78,7 @@ static void             CalcType( ImplFontAttrs& rType, FontWeight& rWeight, Fon
                                   FontFamily eFamily, const utl::FontNameAttr* pFontAttr );
 
 private:
-    std::vector< PhysicalFontFace* > maFontFaces;
+    std::vector< std::unique_ptr<PhysicalFontFace> > maFontFaces;
 
     OUString            maFamilyName;       // original font family name
     OUString            maSearchName;       // normalized font family name
diff --git a/vcl/source/font/PhysicalFontFamily.cxx b/vcl/source/font/PhysicalFontFamily.cxx
index f52e31438f23..34ad038a38a7 100644
--- a/vcl/source/font/PhysicalFontFamily.cxx
+++ b/vcl/source/font/PhysicalFontFamily.cxx
@@ -98,10 +98,6 @@ PhysicalFontFamily::PhysicalFontFamily( const OUString& rSearchName )
 
 PhysicalFontFamily::~PhysicalFontFamily()
 {
-    // release all physical font faces
-    for (auto const& font : maFontFaces)
-        delete font;
-    maFontFaces.clear();
 }
 
 bool PhysicalFontFamily::AddFontFace( PhysicalFontFace* pNewFontFace )
@@ -157,7 +153,7 @@ bool PhysicalFontFamily::AddFontFace( PhysicalFontFace* pNewFontFace )
     auto it(maFontFaces.begin());
     for (; it != maFontFaces.end(); ++it)
     {
-        PhysicalFontFace* pFoundFontFace = *it;
+        PhysicalFontFace* pFoundFontFace = it->get();
         sal_Int32 eComp = pNewFontFace->CompareWithSize( *pFoundFontFace );
         if( eComp > 0 )
             continue;
@@ -173,12 +169,11 @@ bool PhysicalFontFamily::AddFontFace( PhysicalFontFace* pNewFontFace )
             return false;
 
         // replace existing font face with a better one
-        delete pFoundFontFace;
-        *it = pNewFontFace; // insert at sort position
+        it->reset(pNewFontFace); // insert at sort position
         return true;
     }
 
-    maFontFaces.insert(it, pNewFontFace); // insert at sort position
+    maFontFaces.emplace(it, pNewFontFace); // insert at sort position
     return true;
 }
 
@@ -206,7 +201,7 @@ PhysicalFontFace* PhysicalFontFamily::FindBestFontFace( const FontSelectPattern&
     if( maFontFaces.empty() )
         return nullptr;
     if( maFontFaces.size() == 1)
-        return maFontFaces[0];
+        return maFontFaces[0].get();
 
     // FontName+StyleName should map to FamilyName+StyleName
     const OUString& rSearchName = rFSD.maTargetName;
@@ -220,11 +215,11 @@ PhysicalFontFace* PhysicalFontFamily::FindBestFontFace( const FontSelectPattern&
     }
 
     // TODO: linear search improve!
-    PhysicalFontFace* pBestFontFace = maFontFaces[0];
+    PhysicalFontFace* pBestFontFace = maFontFaces[0].get();
     FontMatchStatus aFontMatchStatus = {0,0,0, pTargetStyleName};
     for (auto const& font : maFontFaces)
     {
-        PhysicalFontFace* pFoundFontFace = font;
+        PhysicalFontFace* pFoundFontFace = font.get();
         if( pFoundFontFace->IsBetterMatch( rFSD, aFontMatchStatus ) )
             pBestFontFace = pFoundFontFace;
     }
@@ -239,7 +234,7 @@ void PhysicalFontFamily::UpdateDevFontList( ImplDeviceFontList& rDevFontList ) c
     PhysicalFontFace* pPrevFace = nullptr;
     for (auto const& font : maFontFaces)
     {
-        PhysicalFontFace* pFoundFontFace = font;
+        PhysicalFontFace* pFoundFontFace = font.get();
         if( !pPrevFace || pFoundFontFace->CompareIgnoreSize( *pPrevFace ) )
             rDevFontList.Add( pFoundFontFace );
         pPrevFace = pFoundFontFace;
@@ -251,7 +246,7 @@ void PhysicalFontFamily::GetFontHeights( std::set<int>& rHeights ) const
     // add all available font heights
     for (auto const& font : maFontFaces)
     {
-        PhysicalFontFace *pFoundFontFace = font;
+        PhysicalFontFace *pFoundFontFace = font.get();
         rHeights.insert( pFoundFontFace->GetHeight() );
     }
 }
@@ -263,7 +258,7 @@ void PhysicalFontFamily::UpdateCloneFontList(PhysicalFontCollection& rFontCollec
 
     for (auto const& font : maFontFaces)
     {
-        PhysicalFontFace *pFoundFontFace = font;
+        PhysicalFontFace *pFoundFontFace = font.get();
 
         if (!pFamily)
         {   // tdf#98989 lazy create as family without faces won't work


More information about the Libreoffice-commits mailing list