summaryrefslogtreecommitdiff
path: root/Build/source/libs/graphite/src/segment/FontFace.h
blob: 7f2684a5908a8f6d483e46ac08a4f472084adc68 (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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
/*--------------------------------------------------------------------
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: FontFace.h
Responsibility: Sharon Correll
Last reviewed: Not yet.

Description:
	Contains the definition of the FontFace class.
	TODO: Merge with GrEngine.
----------------------------------------------------------------------------------------------*/
#ifdef _MSC_VER
#pragma once
#endif
#ifndef FONTFACE_INCLUDED
#define FONTFACE_INCLUDED
#include <limits>

#ifdef _MSC_VER
#include <crtdbg.h>
#endif

namespace gr
{

class IGrJustifier;
class Segment;


/*----------------------------------------------------------------------------------------------
	The GrEngine serves as the top level object that knows how to run Graphite tables
	and generate Graphite segments.

	Primarily, this class implements IRenderEngine, which allows it to serve as a FW
	rendering engine. It also implements ISimpleInit, a general interface for initializing
	using a string. Finally, it implements ITraceControl, a very simple interface which
	allows a client to flip a flag indicating whether or not we want to output a log of
	the Graphite transduction process.

	Hungarian: greng
----------------------------------------------------------------------------------------------*/
class FontFace
{
	friend class gr::FontMemoryUsage;

public:
	FontFace()
	{
		m_cfonts = 0;
	}

	~FontFace()
	{
		if (s_pFontCache)
			s_pFontCache->RemoveFontFace(m_pgreng->FaceName(), m_pgreng->Bold(), m_pgreng->Italic());
		delete m_pgreng;
	}

	void IncFontCount()
	{
		m_cfonts++;
	}
	void DecFontCount()
	{
		m_cfonts--;
		if (m_cfonts <= 0 && (s_pFontCache == NULL || s_pFontCache->GetFlushMode() == kflushAuto))
			delete this;
	}

	bool NoFonts()
	{
		return (m_cfonts <= 0);
	}

	static FontFace * GetFontFace(Font * pfont,
		std::wstring strFaceName, bool fBold, bool fItalic,
		bool fDumbFallback = false);

	GrResult InitFontFace(Font * pfont,
		std::wstring stuFaceName, bool fBold, bool fItalic,
		bool fDumbLayout);

	FontErrorCode IsValidForGraphite(int * pnVersion, int * pnSubVersion)
	{
		return m_pgreng->IsValidForGraphite(pnVersion, pnSubVersion);
	}

	static void ZapFontCache()
	{
		if (s_pFontCache)
		{
			s_pFontCache->AssertEmpty();
			delete s_pFontCache;
		}
		s_pFontCache = NULL;
	}

	static void SetFlushMode(int flush)
	{
		if (s_pFontCache == NULL)
			s_pFontCache = new FontCache;
		s_pFontCache->SetFlushMode(flush);
	}
	static int GetFlushMode()
	{
		if (s_pFontCache == NULL)
			s_pFontCache = new FontCache;
		return s_pFontCache->GetFlushMode();
	}

	// Temporary, until interface gets thoroughly reworked:
	GrEngine * GraphiteEngine()
	{
		return m_pgreng;
	}

	// Feature access:
	size_t NumberOfFeatures()
	{
		return m_pgreng->NumberOfFeatures_ff();
	}
	featid FeatureID(size_t ifeat)
	{
		return m_pgreng->FeatureID_ff(ifeat);
	}
	size_t FeatureWithID(featid id)
	{
		return m_pgreng->FeatureWithID_ff(id);
	}
	bool GetFeatureLabel(size_t ifeat, lgid language, utf16 * label)
	{
		return m_pgreng->GetFeatureLabel_ff(ifeat, language, label);
	}
	int GetFeatureDefault(size_t ifeat) // index of default setting
	{
		return m_pgreng->GetFeatureDefault_ff(ifeat);
	}
	size_t NumberOfSettings(size_t ifeat)
	{
		return m_pgreng->NumberOfSettings_ff(ifeat);
	}
	int GetFeatureSettingValue(size_t ifeat, size_t ifset)
	{
		return m_pgreng->GetFeatureSettingValue_ff(ifeat, ifset);
	}
	bool GetFeatureSettingLabel(size_t ifeat, size_t ifset, lgid language, utf16 * label)
	{
		return m_pgreng->GetFeatureSettingLabel_ff(ifeat, ifset, language, label);
	}
	// Feature-label language access:
	size_t NumberOfFeatLangs()
	{
		return m_pgreng->NumberOfFeatLangs_ff();
	}
	short FeatLabelLang(int ilang)
	{
		return m_pgreng->GetFeatLabelLang_ff(ilang);
	}
	// Language access:
	size_t NumberOfLanguages()
	{
		return m_pgreng->NumberOfLanguages_ff();
	}
	isocode LanguageCode(size_t ilang)
	{
		return m_pgreng->GetLanguageCode_ff(ilang);
	}

	// Script Direction access:
	ScriptDirCode ScriptDirection() const throw()
	{
		unsigned int script_dirs = 0;
		OLECHAR err_dummy = 0;
		m_pgreng->get_ScriptDirection(&script_dirs, &err_dummy, 1);
		return ScriptDirCode(script_dirs);
	}

	bool BadFont(FontErrorCode * pferr = NULL)
	{
		return m_pgreng->BadFont(pferr);
	}
	bool DumbFallback(FontErrorCode * pferr = NULL)
	{
		return m_pgreng->DumbFallback(pferr);
	}

public:
	// For use in segment creation:
	void RenderLineFillSegment(Segment * pseg, Font * pfont, ITextSource * pts,
		LayoutEnvironment & layout,
		toffset ichStart, toffset ichStop, float xsMaxWidth, bool fBacktracking)
	{
		m_pgreng->MakeSegment(pseg, pfont, pts, NULL, layout,
			ichStart, ichStop, xsMaxWidth, fBacktracking, false, 0, kestMoreLines);
	}
	void RenderRangeSegment(Segment * pseg, Font * pfont,
		ITextSource * pts, LayoutEnvironment & layout,
		toffset ichStart, toffset ichStop)
	{
		m_pgreng->MakeSegment(pseg, pfont, pts, NULL, layout,
			ichStart, ichStop, kPosInfFloat, false, false, 0, kestMoreLines);
	}
	void RenderJustifiedSegment(Segment * pseg, Font * pfont,
		ITextSource * pts, LayoutEnvironment & layout,
		toffset ichStart, toffset ichStop, float xsCurrentWidth, float xsDesiredWidth)
	{
		m_pgreng->MakeSegment(pseg, pfont, pts, NULL, layout,
			ichStart, ichStop, xsCurrentWidth, false, true, xsDesiredWidth, kestMoreLines);
	}

	// Debugging.
	//static bool DbgCheckFontCache()
	//{
	//	if (s_pFontCache)
	//		return s_pFontCache->DbgCheckFontCache();
	//	else
	//		return true;
	//}
	//void DbgCheckFontFace();

	static void calculateAllMemoryUsage(FontMemoryUsage & fmu);
	void calculateMemoryUsage(FontMemoryUsage & fmu);

protected:
	// Number of fonts in existence that use this face; when it goes to zero, delete.
	int m_cfonts;

	// Static variable:
	static FontCache * s_pFontCache;

	// Member variables:
	GrEngine * m_pgreng;
};

} // namespace gr


#if defined(GR_NO_NAMESPACE)
using namespace gr;
#endif


#endif  // !FONTFACE_INCLUDED