summaryrefslogtreecommitdiff
path: root/Build/source/libs/graphite/src/segment/FontCache.h
blob: 56da5ab26b8e6f3ad052bb9eadadc655916530a0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/*--------------------------------------------------------------------*//*:Ignore this sentence.
Copyright (C) 1999, 2001 SIL International. All rights reserved.

Distributable under the terms of either the Common Public License or the
GNU Lesser General Public License, as specified in the LICENSING.txt file.

File: FontCache.h
Responsibility: Sharon Correll
Last reviewed: Not yet.

Description:
    A cache of all the font-face objects known to mankind. There is exactly one instance
	of a FontCache.
----------------------------------------------------------------------------------------------*/
#ifdef _MSC_VER
#pragma once
#endif
#ifndef FONTCACHE_INCLUDED
#define FONTCACHE_INCLUDED

//:End Ignore

namespace gr
{

class FontFace;
class FontMemoryUsage;

/*----------------------------------------------------------------------------------------------
	TODO: change from a sorted list to a hash table, if performance so requires.
----------------------------------------------------------------------------------------------*/
class FontCache {
	friend class FontMemoryUsage;

public:
	FontCache()
	{
		m_cfci = 0;
		m_prgfci = NULL;
		m_cfciMax = 0;
		m_cfface = 0;
		m_flush = kflushAuto;
	}

	~FontCache()
	{
		delete[] m_prgfci;
		m_prgfci = NULL;
		m_cfci = 0;
		m_cfciMax = 0;
		m_cfface = 0;
	}

	void Initialize()
	{
		m_cfci = 0;
		m_prgfci = new CacheItem[12];
		m_cfciMax = 12;
		m_cfface = 0;
	}

	struct CacheItem
	{
		wchar_t szFaceName[32];	// type should match std::wstring
		FontFace * pffaceRegular;
		FontFace * pffaceBold;
		FontFace * pffaceItalic;
		FontFace * pffaceBI;
	};

	void GetFontFace(std::wstring strFaceName, bool fBold, bool fItalic, FontFace ** ppfface);
	void CacheFontFace(std::wstring strFaceName, bool fBold, bool fItalic, FontFace * pfface);
	bool RemoveFontFace(std::wstring strFaceName, bool fBold, bool fItalic, bool fZapCache = true);
	void DeleteIfEmpty();
	void AssertEmpty();

	int GetFlushMode()
	{
		return m_flush;
	}
	void SetFlushMode(int);

	// Debugging:
	//bool DbgCheckFontCache();

	void calculateMemoryUsage(FontMemoryUsage & fmu);

protected:
	int FindCacheItem(std::wstring strFaceName);
	void InsertCacheItem(int ifci);

protected:
	// member variables;
	int m_cfci;			// number of items (font-families)
	int m_cfciMax;		// amount of space available
	int m_cfface;		// number of font-faces
	CacheItem * m_prgfci;

	int m_flush;
};

} // namespace gr


#endif // !FONTCACHE_INCLUDED