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