[Libreoffice-commits] core.git: vcl/inc vcl/Library_vcl.mk vcl/unx

Khaled Hosny khaledhosny at eglug.org
Fri Dec 2 00:59:49 UTC 2016


 vcl/Library_vcl.mk                          |    1 
 vcl/inc/unx/fontcache.hxx                   |   88 ---
 vcl/inc/unx/fontmanager.hxx                 |    7 
 vcl/unx/generic/fontmanager/fontcache.cxx   |  625 ----------------------------
 vcl/unx/generic/fontmanager/fontconfig.cxx  |   34 -
 vcl/unx/generic/fontmanager/fontmanager.cxx |   58 --
 vcl/unx/generic/fontmanager/helper.cxx      |    2 
 7 files changed, 11 insertions(+), 804 deletions(-)

New commits:
commit babf6d5e53516e80e8e3f2485796ebfaeb20e9c1
Author: Khaled Hosny <khaledhosny at eglug.org>
Date:   Fri Dec 2 02:14:21 2016 +0200

    Drop font cache on UNX
    
    On my system reading the ~400 fonts I have takes ~0.07 seconds, which
    does not really justify all this complexity. We don’t have such cache on
    other platforms as well.
    
    It might have been slower in the past with all PFB and AFM parsing, but
    this is gone already.
    
    Killing this ugly fontmanager over engineering one piece at a time.
    
    Change-Id: I41fe3db48dc3de0cf8939c2120403f7d243d6096
    Reviewed-on: https://gerrit.libreoffice.org/31511
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Khaled Hosny <khaledhosny at eglug.org>

diff --git a/vcl/Library_vcl.mk b/vcl/Library_vcl.mk
index 435e8cf..759d903 100644
--- a/vcl/Library_vcl.mk
+++ b/vcl/Library_vcl.mk
@@ -540,7 +540,6 @@ vcl_headless_freetype_code=\
     vcl/unx/generic/glyphs/freetype_glyphcache \
     vcl/unx/generic/glyphs/glyphcache \
     vcl/unx/generic/fontmanager/fontsubst \
-    vcl/unx/generic/fontmanager/fontcache \
     vcl/unx/generic/fontmanager/fontconfig \
     vcl/unx/generic/fontmanager/fontmanager \
     vcl/unx/generic/fontmanager/helper \
diff --git a/vcl/inc/unx/fontcache.hxx b/vcl/inc/unx/fontcache.hxx
deleted file mode 100644
index 4332d41..0000000
--- a/vcl/inc/unx/fontcache.hxx
+++ /dev/null
@@ -1,88 +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_VCL_INC_UNX_FONTCACHE_HXX
-#define INCLUDED_VCL_INC_UNX_FONTCACHE_HXX
-
-#include <rtl/ustring.hxx>
-#include <vcl/dllapi.h>
-#include <unordered_map>
-
-#include "unx/fontmanager.hxx"
-
-namespace psp
-{
-
-class VCL_PLUGIN_PUBLIC FontCache
-{
-    struct FontDir;
-    friend struct FontDir;
-    struct FontFile;
-    friend struct FontFile;
-
-    struct FontFile
-    {
-        std::list< PrintFontManager::PrintFont* >      m_aEntry;
-    };
-
-    typedef std::unordered_map< OString, FontFile, OStringHash > FontDirMap;
-    struct FontDir
-    {
-        sal_Int64   m_nTimestamp;
-        bool        m_bNoFiles;
-        bool        m_bUserOverrideOnly;
-        FontDirMap  m_aEntries;
-
-        FontDir() : m_nTimestamp(0), m_bNoFiles(false), m_bUserOverrideOnly( false ) {}
-    };
-
-    typedef std::unordered_map< int, FontDir > FontCacheData;
-    FontCacheData   m_aCache;
-    OUString        m_aCacheFile;
-    bool            m_bDoFlush;
-
-    void read();
-    void clearCache();
-
-    static void copyPrintFont( const PrintFontManager::PrintFont* pFrom, PrintFontManager::PrintFont* pTo );
-    static bool equalsPrintFont( const PrintFontManager::PrintFont* pLeft, PrintFontManager::PrintFont* pRight );
-    static PrintFontManager::PrintFont* clonePrintFont( const PrintFontManager::PrintFont* pFont );
-
-    void createCacheDir( int nDirID );
-public:
-    FontCache();
-    ~FontCache();
-
-    bool getFontCacheFile( int nDirID, const OString& rFile, std::list< PrintFontManager::PrintFont* >& rNewFonts ) const;
-    void updateFontCacheEntry( const PrintFontManager::PrintFont*, bool bFlush );
-
-    // returns false for non cached directory
-    // a cached but empty directory will return true but not append anything
-    bool listDirectory( const OString& rDir, std::list< PrintFontManager::PrintFont* >& rNewFonts ) const;
-    // returns true for directories that contain only user overridden fonts
-    bool scanAdditionalFiles( const OString& rDir );
-
-    void flush();
-};
-
-} // namespace psp
-
-#endif // INCLUDED_VCL_INC_UNX_FONTCACHE_HXX
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/inc/unx/fontmanager.hxx b/vcl/inc/unx/fontmanager.hxx
index 86d946a..01419dc 100644
--- a/vcl/inc/unx/fontmanager.hxx
+++ b/vcl/inc/unx/fontmanager.hxx
@@ -118,17 +118,12 @@ struct CharacterMetric
     { return rOther.width != width || rOther.height != height; }
 };
 
-class FontCache;
-
 // a class to manage printable fonts
 
-class FontCache;
-
 class VCL_PLUGIN_PUBLIC PrintFontManager
 {
     struct PrintFont;
     friend struct PrintFont;
-    friend class FontCache;
 
     struct PrintFont
     {
@@ -176,8 +171,6 @@ class VCL_PLUGIN_PUBLIC PrintFontManager
     std::unordered_map< int, OString >          m_aAtomToDir;
     int                                         m_nNextDirAtom;
 
-    mutable FontCache*                         m_pFontCache;
-
     OString getFontFile( PrintFont* pFont ) const;
 
     bool analyzeFontFile( int nDirID, const OString& rFileName, std::list< PrintFont* >& rNewFonts, const char *pFormat=nullptr ) const;
diff --git a/vcl/unx/generic/fontmanager/fontcache.cxx b/vcl/unx/generic/fontmanager/fontcache.cxx
deleted file mode 100644
index 4c26e4e..0000000
--- a/vcl/unx/generic/fontmanager/fontcache.cxx
+++ /dev/null
@@ -1,625 +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 <cstdlib>
-#include <cstring>
-
-#include "unx/fontcache.hxx"
-
-#include "osl/thread.h"
-
-#include "unotools/atom.hxx"
-
-#include "tools/stream.hxx"
-
-#include <rtl/strbuf.hxx>
-
-#include <unistd.h>
-#include <sys/stat.h>
-
-#if OSL_DEBUG_LEVEL >1
-#include <cstdio>
-#endif
-
-#define CACHE_MAGIC "LibreOffice PspFontCacheFile format 9"
-
-using namespace std;
-using namespace psp;
-using namespace utl;
-
-/*
- *  FontCache constructor
- */
-
-FontCache::FontCache()
-{
-    m_bDoFlush = false;
-    m_aCacheFile = getOfficePath( whichOfficePath::UserPath );
-    if( !m_aCacheFile.isEmpty() )
-    {
-        m_aCacheFile += "/user/psprint/pspfontcache";
-        read();
-    }
-}
-
-/*
- *  FontCache destructor
- */
-
-FontCache::~FontCache()
-{
-    clearCache();
-}
-
-/*
- *  FontCache::clearCache
- */
-void FontCache::clearCache()
-{
-    for( FontCacheData::iterator dir_it = m_aCache.begin(); dir_it != m_aCache.end(); ++dir_it )
-    {
-        for( FontDirMap::iterator entry_it = dir_it->second.m_aEntries.begin(); entry_it != dir_it->second.m_aEntries.end(); ++entry_it )
-        {
-            for( std::list< PrintFontManager::PrintFont* >::iterator font_it = entry_it->second.m_aEntry.begin(); font_it != entry_it->second.m_aEntry.end(); ++font_it )
-                delete *font_it;
-        }
-    }
-    m_aCache.clear();
-}
-
-/*
- *  FontCache::Commit
- */
-
-void FontCache::flush()
-{
-    if( ! m_bDoFlush || m_aCacheFile.isEmpty() )
-        return;
-
-    SvFileStream aStream;
-    aStream.Open( m_aCacheFile, StreamMode::WRITE | StreamMode::TRUNC );
-    if( ! (aStream.IsOpen() && aStream.IsWritable()) )
-    {
-#if OSL_DEBUG_LEVEL > 1
-        fprintf( stderr, "FontCache::flush: opening cache file %s failed\n", OUStringToOString(m_aCacheFile, osl_getThreadTextEncoding()).getStr() );
-#endif
-        return;
-    }
-
-    aStream.SetLineDelimiter( LINEEND_LF );
-    aStream.WriteLine( CACHE_MAGIC );
-
-    PrintFontManager& rManager( PrintFontManager::get() );
-    MultiAtomProvider* pAtoms = rManager.m_pAtoms;
-
-    for( FontCacheData::const_iterator dir_it = m_aCache.begin(); dir_it != m_aCache.end(); ++ dir_it )
-    {
-        const FontDirMap& rDir( dir_it->second.m_aEntries );
-
-        OString aDirectory(rManager.getDirectory(dir_it->first));
-        OStringBuffer aLine("FontCacheDirectory:");
-        aLine.append(dir_it->second.m_nTimestamp);
-        aLine.append(':');
-        aLine.append(aDirectory);
-        if( rDir.empty() && dir_it->second.m_bNoFiles )
-            aLine.insert(0, "Empty");
-        aStream.WriteLine(aLine.makeStringAndClear());
-
-        for( FontDirMap::const_iterator entry_it = rDir.begin(); entry_it != rDir.end(); ++entry_it )
-        {
-            // insert cache entries
-            const std::list< PrintFontManager::PrintFont* >& rEntry( entry_it->second.m_aEntry );
-            if( rEntry.empty() )
-                continue;
-
-            aLine.append("File:");
-            aLine.append(entry_it->first);
-            aStream.WriteLine(aLine.makeStringAndClear());
-
-            int nEntrySize = entry_it->second.m_aEntry.size();
-            // write: nfonts
-            aLine.append(static_cast<sal_Int32>(nEntrySize));
-            aStream.WriteLine(aLine.makeStringAndClear());
-
-            sal_Int32 nSubEntry = 0;
-            for( std::list< PrintFontManager::PrintFont* >::const_iterator it = rEntry.begin(); it != rEntry.end(); ++it, nSubEntry++ )
-            {
-                /*
-                 *  for each font entry write:
-                 *  name[;name[;name]]
-                 *  fontnr;PSName;italic;weight;width;pitch;encoding;ascend;descend;leading;vsubst;gxw;gxh;gyw;gyh;useroverride;embed;antialias[;{metricfile,typeflags}][;stylename]
-                 */
-                if( nEntrySize > 1 )
-                    nSubEntry = (*it)->m_nCollectionEntry;
-                else
-                    nSubEntry = 0;
-
-                aLine.append(OUStringToOString(pAtoms->getString( ATOM_FAMILYNAME, (*it)->m_nFamilyName), RTL_TEXTENCODING_UTF8));
-                for( int name : (*it)->m_aAliases )
-                {
-                    const OUString& rAdd( pAtoms->getString( ATOM_FAMILYNAME, name ) );
-                    if( !rAdd.isEmpty() )
-                    {
-                        aLine.append(';');
-                        aLine.append(OUStringToOString(rAdd, RTL_TEXTENCODING_UTF8));
-                    }
-                }
-                aStream.WriteLine(aLine.makeStringAndClear());
-
-                const OUString& rPSName( pAtoms->getString( ATOM_PSNAME, (*it)->m_nPSName ) );
-                aLine.append(nSubEntry);
-                aLine.append(';');
-                aLine.append(OUStringToOString(rPSName, RTL_TEXTENCODING_UTF8));
-                aLine.append(';');
-                aLine.append(static_cast<sal_Int32>((*it)->m_eItalic));
-                aLine.append(';');
-                aLine.append(static_cast<sal_Int32>((*it)->m_eWeight));
-                aLine.append(';');
-                aLine.append(static_cast<sal_Int32>((*it)->m_eWidth));
-                aLine.append(';');
-                aLine.append(static_cast<sal_Int32>((*it)->m_ePitch));
-                aLine.append(';');
-                aLine.append(static_cast<sal_Int32>((*it)->m_aEncoding));
-                aLine.append(';');
-                aLine.append(static_cast<sal_Int32>((*it)->m_nAscend));
-                aLine.append(';');
-                aLine.append(static_cast<sal_Int32>((*it)->m_nDescend));
-                aLine.append(';');
-                aLine.append(static_cast<sal_Int32>((*it)->m_nLeading));
-                aLine.append(';');
-                aLine.append('0');
-                aLine.append(';');
-                aLine.append(static_cast<sal_Int32>((*it)->m_aGlobalMetricX.width ));
-                aLine.append(';');
-                aLine.append(static_cast<sal_Int32>((*it)->m_aGlobalMetricX.height));
-                aLine.append(';');
-                aLine.append(static_cast<sal_Int32>((*it)->m_aGlobalMetricY.width ));
-                aLine.append(';');
-                aLine.append(static_cast<sal_Int32>((*it)->m_aGlobalMetricY.height));
-                aLine.append(';');
-                aLine.append((*it)->m_bUserOverride ? '1' : '0');
-                aLine.append(';');
-                aLine.append(static_cast<sal_Int32>(0));
-                aLine.append(';');
-                aLine.append(static_cast<sal_Int32>(0));
-                aLine.append(';');
-                aLine.append(static_cast<sal_Int32>((*it)->m_nTypeFlags));
-                if( !(*it)->m_aStyleName.isEmpty() )
-                {
-                    aLine.append(';');
-                    aLine.append(OUStringToOString((*it)->m_aStyleName, RTL_TEXTENCODING_UTF8));
-                }
-                aStream.WriteLine(aLine.makeStringAndClear());
-            }
-            aStream.WriteLine(OString());
-        }
-    }
-    m_bDoFlush = false;
-}
-
-/*
- * FontCache::read
- */
-
-void FontCache::read()
-{
-    PrintFontManager& rManager( PrintFontManager::get() );
-    MultiAtomProvider* pAtoms = rManager.m_pAtoms;
-
-    SvFileStream aStream( m_aCacheFile, StreamMode::READ );
-    if( ! aStream.IsOpen() )
-    {
-#if OSL_DEBUG_LEVEL > 1
-        fprintf( stderr, "FontCache::read: opening cache file %s failed\n", OUStringToOString(m_aCacheFile, osl_getThreadTextEncoding()).getStr() );
-#endif
-        return;
-    }
-
-    OString aLine;
-    aStream.ReadLine( aLine );
-    if ( !(aLine == CACHE_MAGIC) )
-    {
-        #if OSL_DEBUG_LEVEL >1
-        fprintf( stderr, "FontCache::read: cache file %s fails magic test\n", OUStringToOString(m_aCacheFile, osl_getThreadTextEncoding()).getStr() );
-        #endif
-        return;
-    }
-
-    int nDir = 0;
-    FontDirMap* pDir = nullptr;
-    bool bKeepOnlyUserOverridden = false;
-    do
-    {
-        aStream.ReadLine( aLine );
-        if( aLine.startsWith("FontCacheDirectory:") ||
-            aLine.startsWith("EmptyFontCacheDirectory:") )
-        {
-            bool bEmpty = aLine.startsWith("Empty");
-            sal_Int32 nSearchIndex = bEmpty ? 24 : 19;
-
-            OString aDir;
-            sal_Int64 nTimestamp = 0;
-            sal_Int32 nTEnd = aLine.indexOf( ':', nSearchIndex );
-            if( nTEnd != -1 )
-            {
-                OString aTimeStamp = aLine.copy( nSearchIndex, nTEnd - nSearchIndex );
-                nTimestamp = aTimeStamp.toInt64();
-                aDir = aLine.copy( nTEnd+1 );
-            }
-            else
-            {
-                // invalid format, remove
-                pDir = nullptr;
-                nDir = 0;
-                m_bDoFlush = true;
-                continue;
-            }
-
-            // is the directory modified ?
-            struct stat aStat;
-            if( stat( aDir.getStr(), &aStat )               ||
-                ! S_ISDIR(aStat.st_mode) )
-            {
-                // remove outdated cache data
-                pDir = nullptr;
-                nDir = 0;
-                m_bDoFlush = true;
-                continue;
-            }
-            else
-            {
-                nDir = rManager.getDirectoryAtom( aDir, true );
-                m_aCache[ nDir ].m_nTimestamp = (sal_Int64)aStat.st_mtime;
-                m_aCache[ nDir ].m_bNoFiles = bEmpty;
-                pDir = bEmpty ? nullptr : &m_aCache[ nDir ].m_aEntries;
-                bKeepOnlyUserOverridden = ((sal_Int64)aStat.st_mtime != nTimestamp);
-                m_aCache[ nDir ].m_bUserOverrideOnly = bKeepOnlyUserOverridden;
-            }
-        }
-        else if( pDir && aLine.startsWith("File:") )
-        {
-            OString aFile( aLine.copy( 5 ) );
-            aStream.ReadLine( aLine );
-
-            const char* pLine = aLine.getStr();
-
-            sal_Int32 nFonts = atoi( pLine );
-            for( int n = 0; n < nFonts; n++ )
-            {
-                aStream.ReadLine( aLine );
-                pLine = aLine.getStr();
-                int nLen = aLine.getLength();
-
-                PrintFontManager::PrintFont* pFont = new PrintFontManager::PrintFont();
-
-                sal_Int32 nIndex;
-
-                for( nIndex = 0; nIndex < nLen && pLine[nIndex] != ';'; nIndex++ )
-                    ;
-
-                pFont->m_nFamilyName = pAtoms->getAtom( ATOM_FAMILYNAME,
-                                                        OUString( pLine, nIndex, RTL_TEXTENCODING_UTF8 ) );
-                while( nIndex < nLen )
-                {
-                    sal_Int32 nLastIndex = nIndex+1;
-                    for( nIndex = nLastIndex ; nIndex < nLen && pLine[nIndex] != ';'; nIndex++ )
-                        ;
-                    if( nIndex - nLastIndex )
-                    {
-                        OUString aAlias( pLine+nLastIndex, nIndex-nLastIndex, RTL_TEXTENCODING_UTF8 );
-                        pFont->m_aAliases.push_back( pAtoms->getAtom( ATOM_FAMILYNAME, aAlias ) );
-                    }
-                }
-                aStream.ReadLine( aLine );
-                pLine = aLine.getStr();
-                nLen = aLine.getLength();
-
-                // get up to 20 token positions
-                const int nMaxTokens = 20;
-                int nTokenPos[nMaxTokens];
-                nTokenPos[0] = 0;
-                int nTokens = 1;
-                for( int i = 0; i < nLen; i++ )
-                {
-                    if( pLine[i] == ';' )
-                    {
-                        nTokenPos[nTokens++] = i+1;
-                        if( nTokens == nMaxTokens )
-                            break;
-                    }
-                }
-                if( nTokens < 18 )
-                {
-                    delete pFont;
-                    continue;
-                }
-                int nCollEntry      = atoi( pLine );
-                pFont->m_nPSName    = pAtoms->getAtom( ATOM_PSNAME, OUString( pLine + nTokenPos[1], nTokenPos[2]-nTokenPos[1]-1, RTL_TEXTENCODING_UTF8 ) );
-                pFont->m_eItalic    = (FontItalic)atoi( pLine+nTokenPos[2] );
-                pFont->m_eWeight    = (FontWeight)atoi( pLine+nTokenPos[3] );
-                pFont->m_eWidth     = (FontWidth)atoi( pLine+nTokenPos[4] );
-                pFont->m_ePitch     = (FontPitch)atoi( pLine+nTokenPos[5] );
-                pFont->m_aEncoding  = (rtl_TextEncoding)atoi( pLine+nTokenPos[6] );
-                pFont->m_nAscend    = atoi( pLine + nTokenPos[7] );
-                pFont->m_nDescend   = atoi( pLine + nTokenPos[8] );
-                pFont->m_nLeading   = atoi( pLine + nTokenPos[9] );
-                /* removed */   (void)atoi( pLine + nTokenPos[10] );
-                pFont->m_aGlobalMetricX.width
-                                    = atoi( pLine + nTokenPos[11] );
-                pFont->m_aGlobalMetricX.height
-                                    = atoi( pLine + nTokenPos[12] );
-                pFont->m_aGlobalMetricY.width
-                                    = atoi( pLine + nTokenPos[13] );
-                pFont->m_aGlobalMetricY.height
-                                    = atoi( pLine + nTokenPos[14] );
-                pFont->m_bUserOverride
-                                    = (atoi( pLine + nTokenPos[15] ) != 0);
-                int nStyleTokenNr = 18;
-                pFont->m_nTypeFlags = atoi( pLine + nTokenPos[18] );
-                pFont->m_nCollectionEntry = nCollEntry;
-                pFont->m_nDirectory = nDir;
-                pFont->m_aFontFile = aFile;
-                nStyleTokenNr++;
-                if( nTokens > nStyleTokenNr )
-                    pFont->m_aStyleName = OUString::intern( pLine + nTokenPos[nStyleTokenNr],
-                                                            nLen - nTokenPos[nStyleTokenNr],
-                                                            RTL_TEXTENCODING_UTF8 );
-
-                bool bObsolete = false;
-                if( bKeepOnlyUserOverridden )
-                {
-                    if( pFont->m_bUserOverride )
-                    {
-                        OStringBuffer aFilePath(rManager.getDirectory(nDir));
-                        aFilePath.append('/').append(aFile);
-                        struct stat aStat;
-                        if( stat( aFilePath.getStr(), &aStat )   ||
-                            ! S_ISREG( aStat.st_mode )              ||
-                            aStat.st_size < 16 )
-                        {
-                            bObsolete = true;
-                        }
-                        #if OSL_DEBUG_LEVEL > 2
-                        else
-                            fprintf( stderr, "keeping file %s in outdated cache entry due to user override\n",
-                                     aFilePath.getStr() );
-                        #endif
-                    }
-                    else
-                        bObsolete = true;
-                }
-                if( bObsolete )
-                {
-                    m_bDoFlush = true;
-#if OSL_DEBUG_LEVEL > 2
-                    fprintf( stderr, "removing obsolete font %s\n", aFile.getStr() );
-#endif
-                    delete pFont;
-                    continue;
-                }
-
-                std::list< PrintFontManager::PrintFont* >& rEntry = (*pDir)[aFile].m_aEntry;
-                rEntry.push_back( pFont );
-            }
-        }
-    } while( ! aStream.IsEof() );
-}
-
-/*
- *  FontCache::copyPrintFont
- */
-void FontCache::copyPrintFont( const PrintFontManager::PrintFont* pFrom, PrintFontManager::PrintFont* pTo )
-{
-    pTo->m_nDirectory       = pFrom->m_nDirectory;
-    pTo->m_aFontFile        = pFrom->m_aFontFile;
-    pTo->m_nCollectionEntry = pFrom->m_nCollectionEntry;
-    pTo->m_nTypeFlags       = pFrom->m_nTypeFlags;
-    pTo->m_nFamilyName      = pFrom->m_nFamilyName;
-    pTo->m_aStyleName       = pFrom->m_aStyleName;
-    pTo->m_aAliases         = pFrom->m_aAliases;
-    pTo->m_nPSName          = pFrom->m_nPSName;
-    pTo->m_eItalic          = pFrom->m_eItalic;
-    pTo->m_eWeight          = pFrom->m_eWeight;
-    pTo->m_eWidth           = pFrom->m_eWidth;
-    pTo->m_ePitch           = pFrom->m_ePitch;
-    pTo->m_aEncoding        = pFrom->m_aEncoding;
-    pTo->m_aGlobalMetricX   = pFrom->m_aGlobalMetricX;
-    pTo->m_aGlobalMetricY   = pFrom->m_aGlobalMetricY;
-    pTo->m_nAscend          = pFrom->m_nAscend;
-    pTo->m_nDescend         = pFrom->m_nDescend;
-    pTo->m_nLeading         = pFrom->m_nLeading;
-    pTo->m_nXMin            = pFrom->m_nXMin;
-    pTo->m_nYMin            = pFrom->m_nYMin;
-    pTo->m_nXMax            = pFrom->m_nXMax;
-    pTo->m_nYMax            = pFrom->m_nYMax;
-    pTo->m_bUserOverride    = pFrom->m_bUserOverride;
-}
-
-/*
- *  FontCache::equalsPrintFont
- */
-bool FontCache::equalsPrintFont( const PrintFontManager::PrintFont* pLeft, PrintFontManager::PrintFont* pRight )
-{
-    if (pRight->m_nDirectory        != pLeft->m_nDirectory      ||
-        pRight->m_aFontFile         != pLeft->m_aFontFile       ||
-        pRight->m_nCollectionEntry  != pLeft->m_nCollectionEntry ||
-        pRight->m_nTypeFlags        != pLeft->m_nTypeFlags      ||
-        pRight->m_nFamilyName       != pLeft->m_nFamilyName     ||
-        pRight->m_aStyleName        != pLeft->m_aStyleName      ||
-        pRight->m_nPSName           != pLeft->m_nPSName         ||
-        pRight->m_eItalic           != pLeft->m_eItalic         ||
-        pRight->m_eWeight           != pLeft->m_eWeight         ||
-        pRight->m_eWidth            != pLeft->m_eWidth          ||
-        pRight->m_ePitch            != pLeft->m_ePitch          ||
-        pRight->m_aEncoding         != pLeft->m_aEncoding       ||
-        pRight->m_aGlobalMetricX    != pLeft->m_aGlobalMetricX  ||
-        pRight->m_aGlobalMetricY    != pLeft->m_aGlobalMetricY  ||
-        pRight->m_nAscend           != pLeft->m_nAscend         ||
-        pRight->m_nDescend          != pLeft->m_nDescend        ||
-        pRight->m_nLeading          != pLeft->m_nLeading        ||
-        pRight->m_nXMin             != pLeft->m_nXMin           ||
-        pRight->m_nYMin             != pLeft->m_nYMin           ||
-        pRight->m_nXMax             != pLeft->m_nXMax           ||
-        pRight->m_nYMax             != pLeft->m_nYMax           ||
-        pRight->m_bUserOverride     != pLeft->m_bUserOverride
-        )
-        return false;
-    std::vector< int >::const_iterator lit, rit;
-    for( lit = pLeft->m_aAliases.begin(), rit = pRight->m_aAliases.begin();
-         lit != pLeft->m_aAliases.end() && rit != pRight->m_aAliases.end() && (*lit) == (*rit);
-         ++lit, ++rit )
-        ;
-    return lit == pLeft->m_aAliases.end() && rit == pRight->m_aAliases.end();
-}
-
-/*
- *  FontCache::clonePrintFont
- */
-PrintFontManager::PrintFont* FontCache::clonePrintFont( const PrintFontManager::PrintFont* pOldFont )
-{
-    PrintFontManager::PrintFont* pFont = new PrintFontManager::PrintFont();
-    copyPrintFont( pOldFont, pFont );
-    return pFont;
- }
-
-/*
- *  FontCache::getFontCacheFile
- */
-bool FontCache::getFontCacheFile( int nDirID, const OString& rFile, list< PrintFontManager::PrintFont* >& rNewFonts ) const
-{
-    bool bSuccess = false;
-
-    FontCacheData::const_iterator dir = m_aCache.find( nDirID );
-    if( dir != m_aCache.end() )
-    {
-        FontDirMap::const_iterator entry = dir->second.m_aEntries.find( rFile );
-        if( entry != dir->second.m_aEntries.end() )
-        {
-            for( std::list< PrintFontManager::PrintFont* >::const_iterator font = entry->second.m_aEntry.begin(); font != entry->second.m_aEntry.end(); ++font )
-            {
-                bSuccess = true;
-                PrintFontManager::PrintFont* pFont = clonePrintFont( *font );
-                rNewFonts.push_back( pFont );
-            }
-        }
-    }
-    return bSuccess;
-}
-
-/*
- *  FontCache::updateFontCacheEntry
- */
-void FontCache::updateFontCacheEntry( const PrintFontManager::PrintFont* pFont, bool bFlush )
-{
-    OString aFile;
-    int nDirID = 0;
-    nDirID = pFont->m_nDirectory;
-    aFile  = pFont->m_aFontFile;
-    FontCacheData::const_iterator dir = m_aCache.find( nDirID );
-    FontDirMap::const_iterator entry;
-    std::list< PrintFontManager::PrintFont* >::const_iterator font;
-    PrintFontManager::PrintFont* pCacheFont = nullptr;
-
-    if( dir != m_aCache.end() )
-    {
-        entry = dir->second.m_aEntries.find( aFile );
-        if( entry != dir->second.m_aEntries.end() )
-        {
-            for( font = entry->second.m_aEntry.begin(); font != entry->second.m_aEntry.end(); ++font )
-            {
-                if ((*font)->m_nCollectionEntry == pFont->m_nCollectionEntry)
-                    break;
-            }
-            if( font != entry->second.m_aEntry.end() )
-                pCacheFont = *font;
-        }
-    }
-    else
-        createCacheDir( nDirID );
-
-    if( pCacheFont )
-    {
-        if( ! equalsPrintFont( pFont, pCacheFont ) )
-        {
-            copyPrintFont( pFont, pCacheFont );
-            m_bDoFlush = true;
-        }
-    }
-    else
-    {
-        pCacheFont = clonePrintFont( pFont );
-        m_aCache[nDirID].m_aEntries[aFile].m_aEntry.push_back( pCacheFont );
-        m_bDoFlush = true;
-    }
-    if( bFlush )
-        flush();
-}
-
-/*
- *  FontCache::listDirectory
- */
-bool FontCache::listDirectory( const OString& rDir, std::list< PrintFontManager::PrintFont* >& rNewFonts ) const
-{
-    PrintFontManager& rManager( PrintFontManager::get() );
-    int nDirID = rManager.getDirectoryAtom( rDir );
-
-    FontCacheData::const_iterator dir = m_aCache.find( nDirID );
-    bool bFound = (dir != m_aCache.end());
-
-    if( bFound && !dir->second.m_bNoFiles )
-    {
-        for( FontDirMap::const_iterator file = dir->second.m_aEntries.begin(); file != dir->second.m_aEntries.end(); ++file )
-        {
-            for( std::list< PrintFontManager::PrintFont* >::const_iterator font = file->second.m_aEntry.begin(); font != file->second.m_aEntry.end(); ++font )
-            {
-                PrintFontManager::PrintFont* pFont = clonePrintFont( *font );
-                rNewFonts.push_back( pFont );
-            }
-        }
-    }
-    return bFound;
-}
-
-/*
- *  FontCache::listDirectory
- */
-bool FontCache::scanAdditionalFiles( const OString& rDir )
-{
-    PrintFontManager& rManager( PrintFontManager::get() );
-    int nDirID = rManager.getDirectoryAtom( rDir );
-    FontCacheData::const_iterator dir = m_aCache.find( nDirID );
-    bool bFound = (dir != m_aCache.end());
-
-    return (bFound && dir->second.m_bUserOverrideOnly);
-}
-
-/*
- *  FontCache::createCacheDir
- */
-void FontCache::createCacheDir( int nDirID )
-{
-    PrintFontManager& rManager( PrintFontManager::get() );
-
-    const OString& rDir = rManager.getDirectory( nDirID );
-    struct stat aStat;
-    if( ! stat( rDir.getStr(), &aStat ) )
-        m_aCache[nDirID].m_nTimestamp = (sal_Int64)aStat.st_mtime;
-}
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/unx/generic/fontmanager/fontconfig.cxx b/vcl/unx/generic/fontmanager/fontconfig.cxx
index 538bdba..217ac0f 100644
--- a/vcl/unx/generic/fontmanager/fontconfig.cxx
+++ b/vcl/unx/generic/fontmanager/fontconfig.cxx
@@ -17,9 +17,8 @@
  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
  */
 
-#include "unx/fontcache.hxx"
-#include "impfont.hxx"
 #include "unx/fontmanager.hxx"
+#include "impfont.hxx"
 #include <vcl/svapp.hxx>
 #include <vcl/sysdata.hxx>
 #include <vcl/vclenum.hxx>
@@ -555,21 +554,19 @@ void PrintFontManager::countFontconfigFonts( std::unordered_map<OString, int, OS
             o_rVisitedPaths[aDir] = 1;
 
             int nDirID = getDirectoryAtom( aDir, true );
-            if( ! m_pFontCache->getFontCacheFile( nDirID, aBase, aFonts ) )
-            {
 #if OSL_DEBUG_LEVEL > 2
-                fprintf( stderr, "file %s not cached\n", aBase.getStr() );
+            fprintf( stderr, "file %s not cached\n", aBase.getStr() );
 #endif
-                // not known, analyze font file to get attributes
-                // not described by fontconfig (e.g. alias names, PSName)
-                if (eFormatRes != FcResultMatch)
-                    format = nullptr;
-                analyzeFontFile( nDirID, aBase, aFonts, reinterpret_cast<char*>(format) );
+            // not known, analyze font file to get attributes
+            // not described by fontconfig (e.g. alias names, PSName)
+            if (eFormatRes != FcResultMatch)
+                format = nullptr;
+            analyzeFontFile( nDirID, aBase, aFonts, reinterpret_cast<char*>(format) );
 #if OSL_DEBUG_LEVEL > 1
-                if( aFonts.empty() )
-                    fprintf( stderr, "Warning: file \"%s\" is unusable to psprint\n", aOrgPath.getStr() );
+            if( aFonts.empty() )
+                fprintf( stderr, "Warning: file \"%s\" is unusable to psprint\n", aOrgPath.getStr() );
 #endif
-            }
+
             if( aFonts.empty() )
             {
                 //remove font, reuse index
@@ -636,8 +633,6 @@ void PrintFontManager::countFontconfigFonts( std::unordered_map<OString, int, OS
                     pUpdate->m_aStyleName = OStringToOUString( OString( reinterpret_cast<char*>(style) ), RTL_TEXTENCODING_UTF8 );
                 }
 
-                // update font cache
-                m_pFontCache->updateFontCacheEntry( pUpdate, false );
                 // sort into known fonts
                 fontID aFont = m_nNextFontID++;
                 m_aFonts[ aFont ] = pUpdate;
@@ -649,15 +644,6 @@ void PrintFontManager::countFontconfigFonts( std::unordered_map<OString, int, OS
                 fprintf( stderr, "inserted font %s as fontID %d\n", family, aFont );
 #endif
             }
-            // clean up the fonts we did not put into the list
-            for( std::list< PrintFont* >::iterator it = aFonts.begin(); it != aFonts.end(); ++it )
-            {
-                if( *it != pUpdate )
-                {
-                    m_pFontCache->updateFontCacheEntry( *it, false ); // prepare a cache entry for a collection item
-                    delete *it;
-                }
-            }
         }
     }
 
diff --git a/vcl/unx/generic/fontmanager/fontmanager.cxx b/vcl/unx/generic/fontmanager/fontmanager.cxx
index 30f1d0a..ce06a65 100644
--- a/vcl/unx/generic/fontmanager/fontmanager.cxx
+++ b/vcl/unx/generic/fontmanager/fontmanager.cxx
@@ -25,7 +25,7 @@
 
 #include "unotools/atom.hxx"
 
-#include "unx/fontcache.hxx"
+#include "unx/fontmanager.hxx"
 #include "fontsubset.hxx"
 #include "impfontcharmap.hxx"
 #include "svdata.hxx"
@@ -139,7 +139,6 @@ PrintFontManager::PrintFontManager()
     : m_nNextFontID( 1 )
     , m_pAtoms( new MultiAtomProvider() )
     , m_nNextDirAtom( 1 )
-    , m_pFontCache( nullptr )
 {
 #if ENABLE_DBUS
     m_aFontInstallerTimer.SetTimeoutHdl(LINK(this, PrintFontManager, autoInstallFontLangSupport));
@@ -154,7 +153,6 @@ PrintFontManager::~PrintFontManager()
     for( std::unordered_map< fontID, PrintFont* >::const_iterator it = m_aFonts.begin(); it != m_aFonts.end(); ++it )
         delete (*it).second;
     delete m_pAtoms;
-    delete m_pFontCache;
 }
 
 OString PrintFontManager::getDirectory( int nAtom ) const
@@ -200,7 +198,6 @@ std::vector<fontID> PrintFontManager::addFontFile( const OString& rFileName )
                 fontID nFontId = m_nNextFontID++;
                 m_aFonts[nFontId] = *it;
                 m_aFontFileToFontID[ aName ].insert( nFontId );
-                m_pFontCache->updateFontCacheEntry( *it, true );
                 aFontIds.push_back(nFontId);
             }
         }
@@ -737,21 +734,6 @@ void PrintFontManager::initialize()
     CALLGRIND_ZERO_STATS();
     #endif
 
-    if( ! m_pFontCache )
-    {
-#if OSL_DEBUG_LEVEL > 1
-        fprintf( stderr, "creating font cache ... " );
-        clock_t aStart;
-        struct tms tms;
-        aStart = times( &tms );
-#endif
-        m_pFontCache = new FontCache();
-#if OSL_DEBUG_LEVEL > 1
-        clock_t aStop = times( &tms );
-        fprintf( stderr, "done in %lf s\n", (double)(aStop - aStart)/(double)sysconf( _SC_CLK_TCK ) );
-#endif
-    }
-
     // initialize can be called more than once, e.g.
     // gtk-fontconfig-timestamp changes to reflect new font installed and
     // PrintFontManager::initialize called again
@@ -813,42 +795,6 @@ void PrintFontManager::initialize()
     // Don't search directories that fontconfig already did
     countFontconfigFonts( visited_dirs );
 
-    // search for font files in each path
-    std::list< OString >::iterator dir_it;
-    for( dir_it = m_aFontDirectories.begin(); dir_it != m_aFontDirectories.end(); ++dir_it )
-    {
-        OString aPath( *dir_it );
-        // see if we were here already
-        if( visited_dirs.find( aPath ) != visited_dirs.end() )
-            continue;
-        visited_dirs[ aPath ] = 1;
-
-        // there may be ":unscaled" directories (see XFree86)
-        // it should be safe to ignore them since they should not
-        // contain any of our recognizeable fonts
-
-        // ask the font cache whether it handles this directory
-        std::list< PrintFont* > aCacheFonts;
-        if( m_pFontCache->listDirectory( aPath, aCacheFonts ) )
-        {
-#if OSL_DEBUG_LEVEL > 1
-            fprintf( stderr, "adding cache directory: %s\n", aPath.getStr() );
-#endif
-            for( ::std::list< PrintFont* >::iterator it = aCacheFonts.begin(); it != aCacheFonts.end(); ++it )
-            {
-                fontID aFont = m_nNextFontID++;
-                m_aFonts[ aFont ] = *it;
-                m_aFontFileToFontID[(*it)->m_aFontFile].insert(aFont);
-#if OSL_DEBUG_LEVEL > 2
-                fprintf( stderr, "adding cached font %d: %s\n", aFont, getFontFileSysPath( aFont ).getStr() );
-#endif
-            }
-            if( ! m_pFontCache->scanAdditionalFiles( aPath ) )
-                continue;
-        }
-
-    }
-
 #if OSL_DEBUG_LEVEL > 1
     aStep1 = times( &tms );
 #endif
@@ -875,8 +821,6 @@ void PrintFontManager::initialize()
     fprintf( stderr, "Step 2 took %lf seconds\n", (double)(aStep2 - aStep1)/fTick );
 #endif
 
-    m_pFontCache->flush();
-
     #ifdef CALLGRIND_COMPILE
     CALLGRIND_DUMP_STATS();
     CALLGRIND_TOGGLE_COLLECT();
diff --git a/vcl/unx/generic/fontmanager/helper.cxx b/vcl/unx/generic/fontmanager/helper.cxx
index 2f83b96..17d74d2 100644
--- a/vcl/unx/generic/fontmanager/helper.cxx
+++ b/vcl/unx/generic/fontmanager/helper.cxx
@@ -219,8 +219,6 @@ OUString const & psp::getFontPath()
             {
                 aPathBuffer.append( aInstallationRootPath );
                 aPathBuffer.append( "/" LIBO_SHARE_FOLDER "/fonts/truetype;");
-                aPathBuffer.append( aInstallationRootPath );
-                aPathBuffer.append( "/" LIBO_SHARE_FOLDER "/fonts/type1;" );
             }
             if( !aUserPath.isEmpty() )
             {


More information about the Libreoffice-commits mailing list