[Libreoffice-commits] core.git: editeng/source include/editeng

Noel Grandin (via logerrit) logerrit at kemper.freedesktop.org
Mon May 31 08:35:46 UTC 2021


 editeng/source/rtf/svxrtf.cxx |   36 +++++++++++++++++-------------------
 include/editeng/svxrtf.hxx    |    2 +-
 2 files changed, 18 insertions(+), 20 deletions(-)

New commits:
commit 8371ae143ef31c332bdcf753ca1dff722a531229
Author:     Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Sun May 30 17:04:59 2021 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Mon May 31 10:35:08 2021 +0200

    vcl::Font is already a copy-on-write structure
    
    with an impl pointer, no need to use unique_ptr when storing in a map
    
    Change-Id: I9fa13133df4a8acfb7fd973509ec2b0e194fc5d6
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/116423
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/editeng/source/rtf/svxrtf.cxx b/editeng/source/rtf/svxrtf.cxx
index 17ef94553ec5..4bf5c3811bdc 100644
--- a/editeng/source/rtf/svxrtf.cxx
+++ b/editeng/source/rtf/svxrtf.cxx
@@ -442,13 +442,13 @@ void SvxRTFParser::ReadColorTable()
 void SvxRTFParser::ReadFontTable()
 {
     int _nOpenBrakets = 1;      // the first was already detected earlier!!
-    std::unique_ptr<vcl::Font> pFont(new vcl::Font);
+    vcl::Font aFont;
     short nFontNo(0), nInsFontNo (0);
     OUString sAltNm, sFntNm;
     bool bIsAltFntNm = false;
 
     rtl_TextEncoding nSystemChar = lcl_GetDefaultTextEncodingForRTF();
-    pFont->SetCharSet( nSystemChar );
+    aFont.SetCharSet( nSystemChar );
     SetEncoding( nSystemChar );
 
     while( _nOpenBrakets && IsParserWorking() )
@@ -487,33 +487,33 @@ void SvxRTFParser::ReadFontTable()
                 ++_nOpenBrakets;
                 break;
             case RTF_FROMAN:
-                pFont->SetFamily( FAMILY_ROMAN );
+                aFont.SetFamily( FAMILY_ROMAN );
                 break;
             case RTF_FSWISS:
-                pFont->SetFamily( FAMILY_SWISS );
+                aFont.SetFamily( FAMILY_SWISS );
                 break;
             case RTF_FMODERN:
-                pFont->SetFamily( FAMILY_MODERN );
+                aFont.SetFamily( FAMILY_MODERN );
                 break;
             case RTF_FSCRIPT:
-                pFont->SetFamily( FAMILY_SCRIPT );
+                aFont.SetFamily( FAMILY_SCRIPT );
                 break;
             case RTF_FDECOR:
-                pFont->SetFamily( FAMILY_DECORATIVE );
+                aFont.SetFamily( FAMILY_DECORATIVE );
                 break;
             // for technical/symbolic font of the rtl_TextEncoding is changed!
             case RTF_FTECH:
-                pFont->SetCharSet( RTL_TEXTENCODING_SYMBOL );
+                aFont.SetCharSet( RTL_TEXTENCODING_SYMBOL );
                 [[fallthrough]];
             case RTF_FNIL:
-                pFont->SetFamily( FAMILY_DONTKNOW );
+                aFont.SetFamily( FAMILY_DONTKNOW );
                 break;
             case RTF_FCHARSET:
                 if (-1 != nTokenValue)
                 {
                     rtl_TextEncoding nrtl_TextEncoding = rtl_getTextEncodingFromWindowsCharset(
                         static_cast<sal_uInt8>(nTokenValue));
-                    pFont->SetCharSet(nrtl_TextEncoding);
+                    aFont.SetCharSet(nrtl_TextEncoding);
                     //When we're in a font, the fontname is in the font
                     //charset, except for symbol fonts I believe
                     if (nrtl_TextEncoding == RTL_TEXTENCODING_SYMBOL)
@@ -525,10 +525,10 @@ void SvxRTFParser::ReadFontTable()
                 switch( nTokenValue )
                 {
                     case 1:
-                        pFont->SetPitch( PITCH_FIXED );
+                        aFont.SetPitch( PITCH_FIXED );
                         break;
                     case 2:
-                        pFont->SetPitch( PITCH_VARIABLE );
+                        aFont.SetPitch( PITCH_VARIABLE );
                         break;
                 }
                 break;
@@ -558,16 +558,14 @@ void SvxRTFParser::ReadFontTable()
             if (!sAltNm.isEmpty())
                 sFntNm += ";" + sAltNm;
 
-            pFont->SetFamilyName( sFntNm );
-            m_FontTable.insert(std::make_pair(nInsFontNo, std::move(pFont)));
-            pFont.reset(new vcl::Font);
-            pFont->SetCharSet( nSystemChar );
+            aFont.SetFamilyName( sFntNm );
+            m_FontTable.insert(std::make_pair(nInsFontNo, aFont));
+            aFont = vcl::Font();
+            aFont.SetCharSet( nSystemChar );
             sAltNm.clear();
             sFntNm.clear();
         }
     }
-    // the last one we have to delete manually
-    pFont.reset();
     SkipToken();        // the closing brace is evaluated "above"
 
     // set the default font in the Document
@@ -602,7 +600,7 @@ const vcl::Font& SvxRTFParser::GetFont( sal_uInt16 nId )
     SvxRTFFontTbl::const_iterator it = m_FontTable.find( nId );
     if (it != m_FontTable.end())
     {
-        return *it->second;
+        return it->second;
     }
     const SvxFontItem& rDfltFont = static_cast<const SvxFontItem&>(
                     pAttrPool->GetDefaultItem( aPlainMap.nFont ));
diff --git a/include/editeng/svxrtf.hxx b/include/editeng/svxrtf.hxx
index faff107c1496..a711f79fd8ed 100644
--- a/include/editeng/svxrtf.hxx
+++ b/include/editeng/svxrtf.hxx
@@ -74,7 +74,7 @@ public:
     std::unique_ptr<EditNodeIdx> MakeNodeIdx() const;
 };
 
-typedef std::map<short, std::unique_ptr<vcl::Font>> SvxRTFFontTbl;
+typedef std::map<short, vcl::Font> SvxRTFFontTbl;
 typedef std::map<sal_uInt16, std::unique_ptr<SvxRTFStyleType>> SvxRTFStyleTbl;
 
 // own helper classes for the RTF Parser


More information about the Libreoffice-commits mailing list