-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGT_Font.h
136 lines (99 loc) · 2.46 KB
/
GT_Font.h
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
#ifndef GT_FONT_H
#define GT_FONT_H
#include <map>
#include "GT_Image.h"
#include "GT_Color.h"
// Comment this in when compiling for font tool, otherwise you
// can comment out
#define GT_FONT_TOOL
const int kGTFontVersionNumber = 3;
const int kMaxFontChars = 256;
class CAtlas
{
public:
CAtlas()
{
ulx = uly = brx = bry = 0.0f;
}
CAtlas(float _ulx, float _uly, float _brx, float _bry)
{
ulx = _ulx;
uly = _uly;
brx = _brx;
bry = _bry;
}
int ULX() const { return F2I(ulx); }
int ULY() const { return F2I(uly); }
int BRX() const { return F2I(brx); }
int BRY() const { return F2I(bry); }
bool isEmpty() const { return (ulx == 0.0f) && (uly == 0.0f) && (brx == 0.0f) && (bry == 0.0f); }
// Public data
float ulx, uly;
float brx, bry;
};
class CFont
{
public:
typedef std::map<int,CAtlas>::iterator Iter;
typedef std::map<int,CAtlas>::const_iterator ConstIter;
typedef std::pair<int, CAtlas> Pair;
CFont() : mImg(NULL) {}
// Loads both the .bmp and .gtft file with name "font"
// "font" should not have either extension appended to it
// Returns true on success, false otherwise
virtual bool loadFont(const char *font);
// Loads only the font .bmp
virtual bool loadFontImg(const char *imgName);
// Loads only the font .gtft
virtual bool loadFontInfo(const char *infoName);
#ifdef GT_FONT_TOOL
struct SSaveFontInfo
{
CColor outline;
CColor colorKey;
bool isOutlined;
};
virtual bool saveFontImg(const char *imgName, const SSaveFontInfo &info); // Save image
virtual bool saveFontInfo(const char *infoName); // Save font information
virtual void drawDebugLines(); // Draw alternating red/green boxes around each character
#endif
void clearGlphys()
{
mGlyphMap.clear();
}
void addGlyph(int c, const CAtlas &atlas)
{
Iter i = mGlyphMap.find(c);
if (i == mGlyphMap.end())
{
mGlyphMap.insert(Pair(c, atlas));
}
else
{
i->second = atlas;
}
}
// Data Access ***
const CAtlas& getInfo(int c)
{
Iter i = mGlyphMap.find(c);
if (i != mGlyphMap.end())
{
return i->second;
}
else
{
return mDefaultAtlas;
}
}
const CImage* getFontImg() const { return mImg; }
CImage* getFontImg() { return mImg; }
int getGlyphCount() { return mGlyphMap.size(); }
// *** End Data Access
virtual ~CFont();
protected:
CAtlas mDefaultAtlas;
std::map<int, CAtlas> mGlyphMap;
CImage *mImg;
};
#endif