[Libreoffice-commits] core.git: include/unotools unotools/Library_utl.mk unotools/source vcl/inc vcl/unx

Khaled Hosny khaledhosny at eglug.org
Fri Dec 2 17:12:10 UTC 2016


 include/unotools/atom.hxx                   |   62 -------------------
 unotools/Library_utl.mk                     |    1 
 unotools/source/misc/atom.cxx               |   87 ----------------------------
 vcl/inc/unx/fontmanager.hxx                 |   16 +----
 vcl/unx/generic/fontmanager/fontconfig.cxx  |    5 -
 vcl/unx/generic/fontmanager/fontmanager.cxx |   62 ++++++-------------
 6 files changed, 27 insertions(+), 206 deletions(-)

New commits:
commit 5d7a1ddf36eb0774a3d11e9c0dba59562d3e0c11
Author: Khaled Hosny <khaledhosny at eglug.org>
Date:   Fri Dec 2 05:45:58 2016 +0200

    Simplify FontManager a bit
    
    There does not seem to be any need for that atom thing as we are
    perfectly happy using plain OUStrings in the same struct, not to mention
    that font names are supposed to be unique so I don’t see what we are
    saving here.
    
    As this was the only use for unotools/atom, it goes with it.
    
    Change-Id: If9d58d84fff0403f9b2c41fe594b99028b30c2f4
    Reviewed-on: https://gerrit.libreoffice.org/31520
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Khaled Hosny <khaledhosny at eglug.org>

diff --git a/include/unotools/atom.hxx b/include/unotools/atom.hxx
deleted file mode 100644
index c91dc87..0000000
--- a/include/unotools/atom.hxx
+++ /dev/null
@@ -1,62 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*
- * This file is part of the LibreOffice project.
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- *
- * This file incorporates work covered by the following license notice:
- *
- *   Licensed to the Apache Software Foundation (ASF) under one or more
- *   contributor license agreements. See the NOTICE file distributed
- *   with this work for additional information regarding copyright
- *   ownership. The ASF licenses this file to you under the Apache
- *   License, Version 2.0 (the "License"); you may not use this file
- *   except in compliance with the License. You may obtain a copy of
- *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
- */
-#ifndef INCLUDED_UNOTOOLS_ATOM_HXX
-#define INCLUDED_UNOTOOLS_ATOM_HXX
-
-#include <unotools/unotoolsdllapi.h>
-#include <rtl/ustring.hxx>
-#include <osl/mutex.hxx>
-#include <com/sun/star/util/XAtomServer.hpp>
-#include <cppuhelper/implbase1.hxx>
-#include <list>
-#include <unordered_map>
-
-#define INVALID_ATOM 0
-
-namespace utl {
-
-    class AtomProvider
-    {
-        int                               m_nAtoms;
-        std::unordered_map<int, OUString> m_aStringMap;
-        std::unordered_map<OUString, int, OUStringHash>           m_aAtomMap;
-    public:
-        AtomProvider();
-        ~AtomProvider();
-
-        int getAtom( const OUString& );
-        const OUString& getString( int ) const;
-    };
-
-    class UNOTOOLS_DLLPUBLIC MultiAtomProvider
-    {
-        std::unordered_map<int, AtomProvider*> m_aAtomLists;
-    public:
-        MultiAtomProvider();
-        ~MultiAtomProvider();
-
-        int getAtom( int atomClass, const OUString& rString );
-
-        const OUString& getString( int atomClass, int atom ) const;
-    };
-}
-
-#endif
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/unotools/Library_utl.mk b/unotools/Library_utl.mk
index 237a188..75a4029 100644
--- a/unotools/Library_utl.mk
+++ b/unotools/Library_utl.mk
@@ -90,7 +90,6 @@ $(eval $(call gb_Library_add_exception_objects,utl,\
     unotools/source/i18n/readwritemutexguard \
     unotools/source/i18n/textsearch \
     unotools/source/i18n/transliterationwrapper \
-    unotools/source/misc/atom \
     unotools/source/misc/closeveto \
     unotools/source/misc/componentresmodule \
     unotools/source/misc/datetime \
diff --git a/unotools/source/misc/atom.cxx b/unotools/source/misc/atom.cxx
deleted file mode 100644
index 84c2de0..0000000
--- a/unotools/source/misc/atom.cxx
+++ /dev/null
@@ -1,87 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*
- * This file is part of the LibreOffice project.
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- *
- * This file incorporates work covered by the following license notice:
- *
- *   Licensed to the Apache Software Foundation (ASF) under one or more
- *   contributor license agreements. See the NOTICE file distributed
- *   with this work for additional information regarding copyright
- *   ownership. The ASF licenses this file to you under the Apache
- *   License, Version 2.0 (the "License"); you may not use this file
- *   except in compliance with the License. You may obtain a copy of
- *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
- */
-
-#include <unotools/atom.hxx>
-
-using namespace utl;
-using namespace ::com::sun::star::uno;
-using namespace ::com::sun::star::util;
-
-AtomProvider::AtomProvider()
-{
-    m_nAtoms = 1;
-}
-
-AtomProvider::~AtomProvider()
-{
-}
-
-int AtomProvider::getAtom( const OUString& rString )
-{
-    std::unordered_map< OUString, int, OUStringHash >::iterator it = m_aAtomMap.find( rString );
-    if( it != m_aAtomMap.end() )
-        return it->second;
-    m_aAtomMap[ rString ] = m_nAtoms;
-    m_aStringMap[ m_nAtoms ] = rString;
-    m_nAtoms++;
-    return m_nAtoms-1;
-}
-
-const OUString& AtomProvider::getString( int nAtom ) const
-{
-    static OUString aEmpty;
-    std::unordered_map<int, OUString>::const_iterator it = m_aStringMap.find( nAtom );
-
-    return it == m_aStringMap.end() ? aEmpty : it->second;
-}
-
-MultiAtomProvider::MultiAtomProvider()
-{
-}
-
-MultiAtomProvider::~MultiAtomProvider()
-{
-    for( std::unordered_map<int, AtomProvider*>::iterator it = m_aAtomLists.begin(); it != m_aAtomLists.end(); ++it )
-        delete it->second;
-}
-
-int MultiAtomProvider::getAtom( int atomClass, const OUString& rString )
-{
-    std::unordered_map<int, AtomProvider*>::iterator it =
-          m_aAtomLists.find( atomClass );
-    if( it != m_aAtomLists.end() )
-        return it->second->getAtom( rString );
-
-    AtomProvider* pNewClass;
-    m_aAtomLists[ atomClass ] = pNewClass = new AtomProvider();
-    return pNewClass->getAtom( rString );
-}
-
-const OUString& MultiAtomProvider::getString( int atomClass, int atom ) const
-{
-    std::unordered_map<int, AtomProvider*>::const_iterator it =
-          m_aAtomLists.find( atomClass );
-    if( it != m_aAtomLists.end() )
-        return it->second->getString( atom );
-
-    static OUString aEmpty;
-    return aEmpty;
-}
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/inc/unx/fontmanager.hxx b/vcl/inc/unx/fontmanager.hxx
index 9c05f43..d922301 100644
--- a/vcl/inc/unx/fontmanager.hxx
+++ b/vcl/inc/unx/fontmanager.hxx
@@ -36,16 +36,11 @@
 
 #include "config_dbus.h"
 
-#define ATOM_FAMILYNAME                     2
-#define ATOM_PSNAME                         3
-
 /*
  *  some words on metrics: every length returned by PrintFontManager and
  *  friends are PostScript afm style, that is they are 1/1000 font height
  */
 
-namespace utl { class MultiAtomProvider; }
-
 class FontSubsetInfo;
 class FontConfigFontOptions;
 class FontSelectPattern;
@@ -128,10 +123,11 @@ class VCL_PLUGIN_PUBLIC PrintFontManager
     struct PrintFont
     {
         // font attributes
-        int               m_nFamilyName;  // atom
-        std::vector<int>  m_aAliases;
-        int               m_nPSName;      // atom
+        OUString          m_aFamilyName;
+        std::vector<OUString> m_aAliases;
+        OUString          m_aPSName;
         OUString          m_aStyleName;
+        FontFamily        m_eFamilyStyle;
         FontItalic        m_eItalic;
         FontWidth         m_eWidth;
         FontWeight        m_eWeight;
@@ -158,8 +154,6 @@ class VCL_PLUGIN_PUBLIC PrintFontManager
 
     fontID                                      m_nNextFontID;
     std::unordered_map< fontID, PrintFont* >    m_aFonts;
-    std::unordered_map< int, FontFamily >       m_aFamilyTypes;
-    utl::MultiAtomProvider*                     m_pAtoms;
     // for speeding up findFontFileID
     std::unordered_map< OString, std::set< fontID >, OStringHash >
                                                 m_aFontFileToFontID;
@@ -190,7 +184,7 @@ class VCL_PLUGIN_PUBLIC PrintFontManager
         it = m_aFonts.find( nID );
         return it == m_aFonts.end() ? nullptr : it->second;
     }
-    void fillPrintFontInfo( PrintFont* pFont, FastPrintFontInfo& rInfo ) const;
+    static void fillPrintFontInfo(PrintFont* pFont, FastPrintFontInfo& rInfo);
     void fillPrintFontInfo( PrintFont* pFont, PrintFontInfo& rInfo ) const;
 
     OString getDirectory( int nAtom ) const;
diff --git a/vcl/unx/generic/fontmanager/fontconfig.cxx b/vcl/unx/generic/fontmanager/fontconfig.cxx
index 217ac0f..3c594f5 100644
--- a/vcl/unx/generic/fontmanager/fontconfig.cxx
+++ b/vcl/unx/generic/fontmanager/fontconfig.cxx
@@ -44,7 +44,6 @@ using namespace psp;
 #include <cstdio>
 #include <cstdarg>
 
-#include <unotools/atom.hxx>
 #include <unotools/configmgr.hxx>
 
 #include "osl/module.h"
@@ -579,7 +578,7 @@ void PrintFontManager::countFontconfigFonts( std::unordered_map<OString, int, OS
                 continue;
             }
 
-            int nFamilyName = m_pAtoms->getAtom( ATOM_FAMILYNAME, OStringToOUString( OString( reinterpret_cast<char*>(family) ), RTL_TEXTENCODING_UTF8 ) );
+            OUString aFamilyName = OStringToOUString(OString(reinterpret_cast<char*>(family)), RTL_TEXTENCODING_UTF8);
             PrintFont* pUpdate = aFonts.front();
             std::list<PrintFont*>::const_iterator second_font = aFonts.begin();
             ++second_font;
@@ -617,7 +616,7 @@ void PrintFontManager::countFontconfigFonts( std::unordered_map<OString, int, OS
             if( pUpdate )
             {
                 // set family name
-                if( pUpdate->m_nFamilyName != nFamilyName )
+                if( pUpdate->m_aFamilyName != aFamilyName )
                 {
                 }
                 if( eWeightRes == FcResultMatch )
diff --git a/vcl/unx/generic/fontmanager/fontmanager.cxx b/vcl/unx/generic/fontmanager/fontmanager.cxx
index 612aa97..8a3af66 100644
--- a/vcl/unx/generic/fontmanager/fontmanager.cxx
+++ b/vcl/unx/generic/fontmanager/fontmanager.cxx
@@ -23,8 +23,6 @@
 #include <stdlib.h>
 #include <osl/thread.h>
 
-#include "unotools/atom.hxx"
-
 #include "unx/fontmanager.hxx"
 #include "fontsubset.hxx"
 #include "impfontcharmap.hxx"
@@ -95,8 +93,7 @@ inline sal_uInt16 getUInt16BE( const sal_uInt8*& pBuffer )
  *  PrintFont implementations
  */
 PrintFontManager::PrintFont::PrintFont()
-:   m_nFamilyName(0)
-,   m_nPSName(0)
+:   m_eFamilyStyle(FAMILY_DONTKNOW)
 ,   m_eItalic(ITALIC_DONTKNOW)
 ,   m_eWidth(WIDTH_DONTKNOW)
 ,   m_eWeight(WEIGHT_DONTKNOW)
@@ -137,7 +134,6 @@ PrintFontManager& PrintFontManager::get()
 
 PrintFontManager::PrintFontManager()
     : m_nNextFontID( 1 )
-    , m_pAtoms( new MultiAtomProvider() )
     , m_nNextDirAtom( 1 )
 {
 #if ENABLE_DBUS
@@ -152,7 +148,6 @@ PrintFontManager::~PrintFontManager()
     deinitFontconfig();
     for( std::unordered_map< fontID, PrintFont* >::const_iterator it = m_aFonts.begin(); it != m_aFonts.end(); ++it )
         delete (*it).second;
-    delete m_pAtoms;
 }
 
 OString PrintFontManager::getDirectory( int nAtom ) const
@@ -586,11 +581,11 @@ bool PrintFontManager::analyzeSfntFile( PrintFont* pFont ) const
         analyzeSfntFamilyName( pTTFont, aNames );
 
         // set family name from XLFD if possible
-        if( ! pFont->m_nFamilyName )
+        if (pFont->m_aFamilyName.isEmpty())
         {
             if( !aNames.empty() )
             {
-                pFont->m_nFamilyName = m_pAtoms->getAtom( ATOM_FAMILYNAME, aNames.front() );
+                pFont->m_aFamilyName = aNames.front();
                 aNames.pop_front();
             }
             else
@@ -603,20 +598,18 @@ bool PrintFontManager::analyzeSfntFile( PrintFont* pFont ) const
                  if ( dotIndex == -1 )
                      dotIndex = pFont->m_aFontFile.getLength();
 
-                 pFont->m_nFamilyName = m_pAtoms->getAtom( ATOM_FAMILYNAME, OStringToOUString( pFont->m_aFontFile.copy( 0, dotIndex ), aEncoding ) );
+                 pFont->m_aFamilyName = OStringToOUString(pFont->m_aFontFile.copy(0, dotIndex), aEncoding);
             }
         }
-        for( ::std::list< OUString >::iterator it = aNames.begin(); it != aNames.end(); ++it )
+        for (auto const& aAlias : aNames)
         {
-            if( !it->isEmpty() )
+            if (!aAlias.isEmpty())
             {
-                int nAlias = m_pAtoms->getAtom( ATOM_FAMILYNAME, *it );
-                if( nAlias != pFont->m_nFamilyName )
+                if (pFont->m_aFamilyName != aAlias)
                 {
-                    std::vector< int >::const_iterator al_it =
-                        std::find( pFont->m_aAliases.begin(), pFont->m_aAliases.end(), nAlias );
+                    auto al_it = std::find(pFont->m_aAliases.begin(), pFont->m_aAliases.end(), aAlias);
                     if( al_it == pFont->m_aAliases.end() )
-                        pFont->m_aAliases.push_back( nAlias );
+                        pFont->m_aAliases.push_back(aAlias);
                 }
             }
         }
@@ -626,11 +619,11 @@ bool PrintFontManager::analyzeSfntFile( PrintFont* pFont ) const
 
         SAL_WARN_IF( !aInfo.psname, "vcl", "No PostScript name in font:" << aFile.getStr() );
 
-        OUString sPSName = aInfo.psname ?
+        pFont->m_aPSName = aInfo.psname ?
             OUString(aInfo.psname, rtl_str_getLength(aInfo.psname), aEncoding) :
-            m_pAtoms->getString(ATOM_FAMILYNAME, pFont->m_nFamilyName); // poor font does not have a postscript name
+            pFont->m_aFamilyName; // poor font does not have a postscript name
 
-        pFont->m_nPSName = m_pAtoms->getAtom( ATOM_PSNAME, sPSName );
+        pFont->m_eFamilyStyle = matchFamilyName(pFont->m_aFamilyName);
 
         switch( aInfo.weight )
         {
@@ -788,20 +781,6 @@ void PrintFontManager::initialize()
     aStep1 = times( &tms );
 #endif
 
-    // part three - fill in family styles
-    std::unordered_map< fontID, PrintFont* >::iterator font_it;
-    for (font_it = m_aFonts.begin(); font_it != m_aFonts.end(); ++font_it)
-    {
-        std::unordered_map< int, FontFamily >::const_iterator it =
-              m_aFamilyTypes.find( font_it->second->m_nFamilyName );
-        if (it != m_aFamilyTypes.end())
-            continue;
-        const OUString& rFamily =
-            m_pAtoms->getString( ATOM_FAMILYNAME, font_it->second->m_nFamilyName);
-        FontFamily eType = matchFamilyName( rFamily );
-        m_aFamilyTypes[ font_it->second->m_nFamilyName ] = eType;
-    }
-
 #if OSL_DEBUG_LEVEL > 1
     aStep2 = times( &tms );
     fprintf( stderr, "PrintFontManager::initialize: collected %" SAL_PRI_SIZET "u fonts\n", m_aFonts.size() );
@@ -825,13 +804,11 @@ void PrintFontManager::getFontList( ::std::list< fontID >& rFontIDs )
         rFontIDs.push_back( it->first );
 }
 
-void PrintFontManager::fillPrintFontInfo( PrintFont* pFont, FastPrintFontInfo& rInfo ) const
+void PrintFontManager::fillPrintFontInfo(PrintFont* pFont, FastPrintFontInfo& rInfo)
 {
-    std::unordered_map< int, FontFamily >::const_iterator style_it =
-          m_aFamilyTypes.find( pFont->m_nFamilyName );
-    rInfo.m_aFamilyName     = m_pAtoms->getString( ATOM_FAMILYNAME, pFont->m_nFamilyName );
+    rInfo.m_aFamilyName     = pFont->m_aFamilyName;
     rInfo.m_aStyleName      = pFont->m_aStyleName;
-    rInfo.m_eFamilyStyle    = style_it != m_aFamilyTypes.end() ? style_it->second : FAMILY_DONTKNOW;
+    rInfo.m_eFamilyStyle    = pFont->m_eFamilyStyle;
     rInfo.m_eItalic         = pFont->m_eItalic;
     rInfo.m_eWidth          = pFont->m_eWidth;
     rInfo.m_eWeight         = pFont->m_eWeight;
@@ -841,8 +818,8 @@ void PrintFontManager::fillPrintFontInfo( PrintFont* pFont, FastPrintFontInfo& r
     rInfo.m_bSubsettable    = true;
 
     rInfo.m_aAliases.clear();
-    for( int i : pFont->m_aAliases )
-        rInfo.m_aAliases.push_back( m_pAtoms->getString( ATOM_FAMILYNAME, i ) );
+    for (auto const& aAlias : pFont->m_aAliases)
+        rInfo.m_aAliases.push_back(aAlias);
 }
 
 void PrintFontManager::fillPrintFontInfo( PrintFont* pFont, PrintFontInfo& rInfo ) const
@@ -992,13 +969,14 @@ OString PrintFontManager::getFontFile( PrintFont* pFont ) const
 
 const OUString& PrintFontManager::getPSName( fontID nFontID ) const
 {
+    static OUString aEmpty;
     PrintFont* pFont = getFont( nFontID );
-    if( pFont && pFont->m_nPSName == 0 )
+    if (pFont && pFont->m_aPSName.isEmpty())
     {
         analyzeSfntFile(pFont);
     }
 
-    return m_pAtoms->getString( ATOM_PSNAME, pFont ? pFont->m_nPSName : INVALID_ATOM );
+    return pFont ? pFont->m_aPSName : aEmpty;
 }
 
 int PrintFontManager::getFontAscend( fontID nFontID ) const


More information about the Libreoffice-commits mailing list