1 /*---------------------------------------------------------------------------*
2 Project: Horizon
3 File: font_ResFontBase.h
4
5 Copyright (C)2009-2012 Nintendo Co., Ltd./HAL Laboratory, Inc. All rights reserved.
6
7 These coded instructions, statements, and computer programs contain
8 proprietary information of Nintendo of America Inc. and/or Nintendo
9 Company Ltd., and are protected by Federal copyright law. They may
10 not be disclosed to third parties or copied or duplicated in any form,
11 in whole or in part, without the prior written consent of Nintendo.
12
13 $Revision: 46347 $
14 *---------------------------------------------------------------------------*/
15
16 #ifndef NN_FONT_FONT_RES_FONT_BASE_H_
17 #define NN_FONT_FONT_RES_FONT_BASE_H_
18
19 #include <nn/types.h>
20 #include <nn/font/font_Font.h>
21 #include <nn/font/font_ResourceFormat.h>
22
23
24 namespace nn {
25 namespace font {
26
27 //---------------------------------------------------------------------------
28 //
29 //---------------------------------------------------------------------------
30 class ResFontBase : public Font
31 {
32 public:
33 /* ------------------------------------------------------------------------
34 Functions
35 ------------------------------------------------------------------------ */
36
37 //
38 //
39
40 //
41 ResFontBase();
42
43 //
44 virtual ~ResFontBase();
45
46 //
47
48 //
49 //
50
51 virtual int GetWidth() const;
52
53 virtual int GetHeight() const;
54
55 virtual int GetAscent() const;
56
57 virtual int GetDescent() const;
58
59 virtual int GetMaxCharWidth() const;
60
61 virtual Type GetType() const;
62
63 virtual TexFmt GetTextureFormat() const;
64
65 virtual int GetLineFeed() const;
66
67 virtual const CharWidths
68 GetDefaultCharWidths() const;
69
70 //
71 //
72
73 virtual void SetLineFeed(int linefeed);
74
75 virtual void SetDefaultCharWidths(const CharWidths& widths);
76
77 virtual bool SetAlternateChar(CharCode c);
78
79 //
80
81 //
82 //
83
84 virtual int GetCharWidth(CharCode c) const;
85
86 virtual const CharWidths
87 GetCharWidths(CharCode c) const;
88
89 virtual void GetGlyph(
90 Glyph* pGlyph,
91 CharCode c
92 ) const;
93
94 virtual bool HasGlyph(CharCode c) const;
95
96 //
97
98 //
99 //
100
101 virtual CharacterCode GetCharacterCode() const;
102
103 //
104
105 //
106 //
107
108 virtual int GetBaselinePos() const;
109 virtual int GetCellHeight() const;
110 virtual int GetCellWidth() const;
111
112 //
113
114
115 //
116 //
117
118 virtual void EnableLinearFilter(
119 bool atSmall,
120 bool atLarge);
121
122 virtual bool IsLinearFilterEnableAtSmall() const;
123
124 virtual bool IsLinearFilterEnableAtLarge() const;
125
126 virtual u32 GetTextureWrapFilterValue() const;
127
128 //
129
130 protected:
131 /* ------------------------------------------------------------------------
132 Types
133 ------------------------------------------------------------------------ */
134 typedef u16 GlyphIndex;
135
136 /* ------------------------------------------------------------------------
137 Constants
138 ------------------------------------------------------------------------ */
139 static const GlyphIndex GLYPH_INDEX_NOT_FOUND = INVALID_GLYPH_INDEX;
140
141
142 /* ------------------------------------------------------------------------
143 Functions
144 ------------------------------------------------------------------------ */
145 //---- Member access
146
GetFINF()147 FontInformation* GetFINF() { return m_pFontInfo; }
148
GetFINF()149 const FontInformation* GetFINF() const { return m_pFontInfo; }
150
151 //
152 //
153 //
154 //
155 //
156 //
157 //
IsManaging(const void * ptr)158 bool IsManaging(const void* ptr) const { return m_pResource == ptr; }
159
160 //
161 //
162 //
163 //
164 //
165 //
166 void SetResourceBuffer(
167 void* pUserBuffer,
168 FontInformation* pFontInfo);
169
170 //
171 //
172 //
173 //
174 //
175 void* RemoveResourceBuffer();
176
177
178 //---- glyph index
179
180
181 //
182 //
183 //
184 //
185 //
186 //
187 //
188 //
189 GlyphIndex GetGlyphIndex(CharCode c) const;
190
191 //
192 //
193 //
194 //
195 //
196 //
197 //
198 //
199 GlyphIndex FindGlyphIndex(CharCode c) const;
200
201 //
202 //
203 //
204 //
205 //
206 //
207 //
208 //
209 //
210 GlyphIndex FindGlyphIndex(
211 const FontCodeMap* pMap,
212 CharCode c
213 ) const;
214
215 //
216 //
217 //
218 //
219 //
220 //
221 const CharWidths& GetCharWidthsFromIndex(GlyphIndex index) const;
222
223 //
224 //
225 //
226 //
227 //
228 //
229 //
230 //
231 const CharWidths& GetCharWidthsFromIndex(
232 const FontWidth* pWidth,
233 GlyphIndex index
234 ) const;
235
236 //
237 //
238 //
239 //
240 //
241 void GetGlyphFromIndex(
242 Glyph* glyph,
243 GlyphIndex index
244 ) const;
245
246
247 //
248 //
249 //
250 //
251 //
252 //
253 static void SetGlyphMember(
254 Glyph* glyph,
255 GlyphIndex index,
256 const FontTextureGlyph& tg);
257
258
259 //
260 //
261
262 //
263 //
264 //
265 //
266 virtual int GetActiveSheetNum() const;
267
268 //
269 //
270 //
271 //
272 internal::TextureObject*
GetTextureObjectsBufferPtr()273 GetTextureObjectsBufferPtr()
274 {
275 return m_pTexObjs;
276 }
277
278 //
279 //
280 //
281 //
282 const internal::TextureObject*
GetTextureObjectsBufferPtr()283 GetTextureObjectsBufferPtr() const
284 {
285 return m_pTexObjs;
286 }
287
288 //
289 //
290 //
291 //
SetTextureObjectsBufferPtr(void * buffer)292 void SetTextureObjectsBufferPtr(void* buffer)
293 {
294 m_pTexObjs = static_cast<internal::TextureObject*>(buffer);
295 }
296
297 //
298 //
299 //
300 //
301 //
302 //
303 const internal::TextureObject*
GetTextureObject(int index)304 GetTextureObject(int index) const
305 {
306 NN_POINTER_ASSERT(GetTextureObjectsBufferPtr());
307 return &GetTextureObjectsBufferPtr()[index];
308 }
309
310 //
311 void GenTextureNames();
312
313 // Destroys the texture name.
314 void DeleteTextureNames();
315
316 //
317
318 private:
319 /* ------------------------------------------------------------------------
320 Variables
321 ------------------------------------------------------------------------ */
322
323 void* m_pResource; //
324
325 //
326 FontInformation* m_pFontInfo;
327
328 internal::TextureObject*
329 m_pTexObjs; //
330 u32 m_WrapFilter; //
331
332 //
333 mutable CharCode m_LastCharCode;
334
335 //
336 mutable GlyphIndex m_LastGlyphIndex;
337 };
338
339 namespace internal {
340
341 //---------------------------------------------------------------------------
342 //
343 //
344 //
345 //
346 //
347 //---------------------------------------------------------------------------
348 inline
349 u32
GetCellsInASheet(const FontTextureGlyph & tg)350 GetCellsInASheet(const FontTextureGlyph& tg)
351 {
352 return static_cast<u32>(tg.sheetRow * tg.sheetLine);
353 }
354
355
356 } // namespace internal
357
358 } // namespace font
359 } // namespace nn
360
361 #endif // NN_FONT_FONT_RES_FONT_BASE_H_
362