Pyrogenesis  13997
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
unifont.h
Go to the documentation of this file.
1 /* Copyright (c) 2012 Wildfire Games
2  *
3  * Permission is hereby granted, free of charge, to any person obtaining
4  * a copy of this software and associated documentation files (the
5  * "Software"), to deal in the Software without restriction, including
6  * without limitation the rights to use, copy, modify, merge, publish,
7  * distribute, sublicense, and/or sell copies of the Software, and to
8  * permit persons to whom the Software is furnished to do so, subject to
9  * the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included
12  * in all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
18  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
20  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21  */
22 
23 /*
24  * Unicode OpenGL texture font.
25  */
26 
27 #ifndef INCLUDED_UNIFONT
28 #define INCLUDED_UNIFONT
29 
30 #include <stdarg.h> // va_list
31 #include <map>
32 
33 #include "lib/res/handle.h"
34 #include "lib/file/vfs/vfs.h"
35 
36 /**
37  * Load a font.
38  *
39  * @param vfs
40  * @param pathname path and basename of the font definition file
41  * (.fnt) and its texture (.png)
42  * @param flags
43  **/
44 extern Handle unifont_load(const PIVFS& vfs, const VfsPath& pathname, size_t flags = 0);
45 
46 /**
47  * Release a handle to a previously loaded font
48  * (subject to reference counting).
49  **/
50 extern Status unifont_unload(Handle& h);
51 
52 /**
53  * Determine pixel extents of a string.
54  *
55  * @param h
56  * @param text string in question.
57  * @param width
58  * @param height is roughly the pixel height of a capital letter, for use
59  * when aligning text in an aesthetically pleasing way.
60  *
61  * note: This is intended for the GUI (hence Unicode).
62  **/
63 Status unifont_stringsize(const Handle h, const wchar_t* text, int& width, int& height);
64 
65 /**
66  * @return whether the font is an RGBA texture, not an ALPHA texture.
67  **/
68 bool unifont_has_rgb(const Handle h);
69 
70 /**
71  * @return height [pixels] of the font.
72  **/
73 int unifont_height(const Handle h);
74 
75 /**
76  * @return width [pixels] of a certain character.
77  **/
78 int unifont_character_width(const Handle h, wchar_t c);
79 
80 /**
81  * @return spacing in pixels from one line of text to the next.
82  **/
83 int unifont_linespacing(const Handle h);
84 
85 // Raw access to font data (since it's convenient to move as much of the
86 // processing as possible to outside lib/):
87 
89 {
90  float u0, v0, u1, v1;
91  i16 x0, y0, x1, y1;
93 };
94 
95 /**
96  * @return glyph data for all glyphs in this font.
97  */
98 const std::map<u16, UnifontGlyphData>& unifont_get_glyphs(const Handle h);
99 
100 /**
101  * @return texture handle for this font.
102  */
104 
105 #endif // INCLUDED_UNIFONT
bool unifont_has_rgb(const Handle h)
Definition: unifont.cpp:228
const glyphmap & unifont_get_glyphs(const Handle h)
Definition: unifont.cpp:276
int unifont_linespacing(const Handle h)
Definition: unifont.cpp:214
shared_ptr< IVFS > PIVFS
Definition: vfs.h:226
int unifont_character_width(const Handle h, wchar_t c)
Definition: unifont.cpp:237
#define i16
Definition: types.h:35
Status unifont_stringsize(const Handle h, const wchar_t *text, int &width, int &height)
Determine pixel extents of a string.
Definition: unifont.cpp:248
Definition: path.h:75
i64 Status
Error handling system.
Definition: status.h:171
i64 Handle
`handle&#39; representing a reference to a resource (sound, texture, etc.)
Definition: handle.h:41
Handle unifont_load(const PIVFS &vfs, const VfsPath &pathname, size_t flags)
Load a font.
Definition: unifont.cpp:201
int unifont_height(const Handle h)
Definition: unifont.cpp:221
Status unifont_unload(Handle &h)
Release a handle to a previously loaded font (subject to reference counting).
Definition: unifont.cpp:207
Handle unifont_get_texture(const Handle h)
Definition: unifont.cpp:289