xref: /aoo41x/main/vcl/inc/fontcache.hxx (revision ebfcd9af)
1*ebfcd9afSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*ebfcd9afSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*ebfcd9afSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*ebfcd9afSAndrew Rist  * distributed with this work for additional information
6*ebfcd9afSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*ebfcd9afSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*ebfcd9afSAndrew Rist  * "License"); you may not use this file except in compliance
9*ebfcd9afSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*ebfcd9afSAndrew Rist  *
11*ebfcd9afSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*ebfcd9afSAndrew Rist  *
13*ebfcd9afSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*ebfcd9afSAndrew Rist  * software distributed under the License is distributed on an
15*ebfcd9afSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*ebfcd9afSAndrew Rist  * KIND, either express or implied.  See the License for the
17*ebfcd9afSAndrew Rist  * specific language governing permissions and limitations
18*ebfcd9afSAndrew Rist  * under the License.
19*ebfcd9afSAndrew Rist  *
20*ebfcd9afSAndrew Rist  *************************************************************/
21*ebfcd9afSAndrew Rist 
22*ebfcd9afSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef _PSPRINT_FONTCACHE_HXX
25cdf0e10cSrcweir #define _PSPRINT_FONTCACHE_HXX
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "vcl/dllapi.h"
28cdf0e10cSrcweir #include "vcl/fontmanager.hxx"
29cdf0e10cSrcweir 
30cdf0e10cSrcweir #include "tools/string.hxx"
31cdf0e10cSrcweir 
32cdf0e10cSrcweir #include <hash_map>
33cdf0e10cSrcweir 
34cdf0e10cSrcweir namespace psp
35cdf0e10cSrcweir {
36cdf0e10cSrcweir 
37cdf0e10cSrcweir class VCL_PLUGIN_PUBLIC FontCache
38cdf0e10cSrcweir {
39cdf0e10cSrcweir     struct FontDir;
40cdf0e10cSrcweir     friend class FontDir;
41cdf0e10cSrcweir     struct FontFile;
42cdf0e10cSrcweir     friend class FontFile;
43cdf0e10cSrcweir 
44cdf0e10cSrcweir     typedef std::list< PrintFontManager::PrintFont* > FontCacheEntry;
45cdf0e10cSrcweir     struct FontFile
46cdf0e10cSrcweir     {
47cdf0e10cSrcweir         FontCacheEntry		m_aEntry;
48cdf0e10cSrcweir     };
49cdf0e10cSrcweir 
50cdf0e10cSrcweir     typedef std::hash_map< ::rtl::OString, FontFile, ::rtl::OStringHash > FontDirMap;
51cdf0e10cSrcweir     struct FontDir
52cdf0e10cSrcweir     {
53cdf0e10cSrcweir         sal_Int64	m_nTimestamp;
54cdf0e10cSrcweir         bool		m_bNoFiles;
55cdf0e10cSrcweir         bool        m_bUserOverrideOnly;
56cdf0e10cSrcweir         FontDirMap	m_aEntries;
57cdf0e10cSrcweir 
58cdf0e10cSrcweir         FontDir() : m_nTimestamp(0), m_bNoFiles(false), m_bUserOverrideOnly( false ) {}
59cdf0e10cSrcweir     };
60cdf0e10cSrcweir 
61cdf0e10cSrcweir     typedef std::hash_map< int, FontDir > FontCacheData;
62cdf0e10cSrcweir     FontCacheData	m_aCache;
63cdf0e10cSrcweir     String			m_aCacheFile;
64cdf0e10cSrcweir     bool			m_bDoFlush;
65cdf0e10cSrcweir 
66cdf0e10cSrcweir     void read();
67cdf0e10cSrcweir     void clearCache();
68cdf0e10cSrcweir 
69cdf0e10cSrcweir     void copyPrintFont( const PrintFontManager::PrintFont* pFrom, PrintFontManager::PrintFont* pTo ) const;
70cdf0e10cSrcweir     bool equalsPrintFont( const PrintFontManager::PrintFont* pLeft, PrintFontManager::PrintFont* pRight ) const;
71cdf0e10cSrcweir     PrintFontManager::PrintFont* clonePrintFont( const PrintFontManager::PrintFont* pFont ) const;
72cdf0e10cSrcweir 
73cdf0e10cSrcweir     void createCacheDir( int nDirID );
74cdf0e10cSrcweir public:
75cdf0e10cSrcweir     FontCache();
76cdf0e10cSrcweir     ~FontCache();
77cdf0e10cSrcweir 
78cdf0e10cSrcweir     bool getFontCacheFile( int nDirID, const rtl::OString& rFile, std::list< PrintFontManager::PrintFont* >& rNewFonts ) const;
79cdf0e10cSrcweir     void updateFontCacheEntry( const PrintFontManager::PrintFont*, bool bFlush );
80cdf0e10cSrcweir     void markEmptyDir( int nDirID, bool bNoFiles = true );
81cdf0e10cSrcweir 
82cdf0e10cSrcweir     // returns false for non cached directory
83cdf0e10cSrcweir     // a cached but empty directory will return true but not append anything
84cdf0e10cSrcweir     bool listDirectory( const rtl::OString& rDir, std::list< PrintFontManager::PrintFont* >& rNewFonts ) const;
85cdf0e10cSrcweir     // returns true for directoris that contain only user overridden fonts
86cdf0e10cSrcweir     bool scanAdditionalFiles( const rtl::OString& rDir );
87cdf0e10cSrcweir 
88cdf0e10cSrcweir     void flush();
89cdf0e10cSrcweir 
90cdf0e10cSrcweir     void updateDirTimestamp( int nDirID );
91cdf0e10cSrcweir };
92cdf0e10cSrcweir 
93cdf0e10cSrcweir } // namespace psp
94cdf0e10cSrcweir 
95cdf0e10cSrcweir #endif // _PSPRINT_FONTCACHE_HXX
96