xref: /aoo42x/main/vcl/inc/fontcache.hxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef _PSPRINT_FONTCACHE_HXX
29 #define _PSPRINT_FONTCACHE_HXX
30 
31 #include "vcl/dllapi.h"
32 #include "vcl/fontmanager.hxx"
33 
34 #include "tools/string.hxx"
35 
36 #include <hash_map>
37 
38 namespace psp
39 {
40 
41 class VCL_PLUGIN_PUBLIC FontCache
42 {
43     struct FontDir;
44     friend class FontDir;
45     struct FontFile;
46     friend class FontFile;
47 
48     typedef std::list< PrintFontManager::PrintFont* > FontCacheEntry;
49     struct FontFile
50     {
51         FontCacheEntry		m_aEntry;
52     };
53 
54     typedef std::hash_map< ::rtl::OString, FontFile, ::rtl::OStringHash > FontDirMap;
55     struct FontDir
56     {
57         sal_Int64	m_nTimestamp;
58         bool		m_bNoFiles;
59         bool        m_bUserOverrideOnly;
60         FontDirMap	m_aEntries;
61 
62         FontDir() : m_nTimestamp(0), m_bNoFiles(false), m_bUserOverrideOnly( false ) {}
63     };
64 
65     typedef std::hash_map< int, FontDir > FontCacheData;
66     FontCacheData	m_aCache;
67     String			m_aCacheFile;
68     bool			m_bDoFlush;
69 
70     void read();
71     void clearCache();
72 
73     void copyPrintFont( const PrintFontManager::PrintFont* pFrom, PrintFontManager::PrintFont* pTo ) const;
74     bool equalsPrintFont( const PrintFontManager::PrintFont* pLeft, PrintFontManager::PrintFont* pRight ) const;
75     PrintFontManager::PrintFont* clonePrintFont( const PrintFontManager::PrintFont* pFont ) const;
76 
77     void createCacheDir( int nDirID );
78 public:
79     FontCache();
80     ~FontCache();
81 
82     bool getFontCacheFile( int nDirID, const rtl::OString& rFile, std::list< PrintFontManager::PrintFont* >& rNewFonts ) const;
83     void updateFontCacheEntry( const PrintFontManager::PrintFont*, bool bFlush );
84     void markEmptyDir( int nDirID, bool bNoFiles = true );
85 
86     // returns false for non cached directory
87     // a cached but empty directory will return true but not append anything
88     bool listDirectory( const rtl::OString& rDir, std::list< PrintFontManager::PrintFont* >& rNewFonts ) const;
89     // returns true for directoris that contain only user overridden fonts
90     bool scanAdditionalFiles( const rtl::OString& rDir );
91 
92     void flush();
93 
94     void updateDirTimestamp( int nDirID );
95 };
96 
97 } // namespace psp
98 
99 #endif // _PSPRINT_FONTCACHE_HXX
100