xref: /aoo42x/main/vcl/inc/fontcache.hxx (revision ebfcd9af)
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     struct FontDir;
40     friend class FontDir;
41     struct FontFile;
42     friend class FontFile;
43 
44     typedef std::list< PrintFontManager::PrintFont* > FontCacheEntry;
45     struct FontFile
46     {
47         FontCacheEntry		m_aEntry;
48     };
49 
50     typedef std::hash_map< ::rtl::OString, FontFile, ::rtl::OStringHash > FontDirMap;
51     struct FontDir
52     {
53         sal_Int64	m_nTimestamp;
54         bool		m_bNoFiles;
55         bool        m_bUserOverrideOnly;
56         FontDirMap	m_aEntries;
57 
58         FontDir() : m_nTimestamp(0), m_bNoFiles(false), m_bUserOverrideOnly( false ) {}
59     };
60 
61     typedef std::hash_map< int, FontDir > FontCacheData;
62     FontCacheData	m_aCache;
63     String			m_aCacheFile;
64     bool			m_bDoFlush;
65 
66     void read();
67     void clearCache();
68 
69     void copyPrintFont( const PrintFontManager::PrintFont* pFrom, PrintFontManager::PrintFont* pTo ) const;
70     bool equalsPrintFont( const PrintFontManager::PrintFont* pLeft, PrintFontManager::PrintFont* pRight ) const;
71     PrintFontManager::PrintFont* clonePrintFont( const PrintFontManager::PrintFont* pFont ) const;
72 
73     void createCacheDir( int nDirID );
74 public:
75     FontCache();
76     ~FontCache();
77 
78     bool getFontCacheFile( int nDirID, const rtl::OString& rFile, std::list< PrintFontManager::PrintFont* >& rNewFonts ) const;
79     void updateFontCacheEntry( const PrintFontManager::PrintFont*, bool bFlush );
80     void markEmptyDir( int nDirID, bool bNoFiles = true );
81 
82     // returns false for non cached directory
83     // a cached but empty directory will return true but not append anything
84     bool listDirectory( const rtl::OString& rDir, std::list< PrintFontManager::PrintFont* >& rNewFonts ) const;
85     // returns true for directoris that contain only user overridden fonts
86     bool scanAdditionalFiles( const rtl::OString& rDir );
87 
88     void flush();
89 
90     void updateDirTimestamp( int nDirID );
91 };
92 
93 } // namespace psp
94 
95 #endif // _PSPRINT_FONTCACHE_HXX
96