/
ifonts.h
145 lines (116 loc) · 3.42 KB
/
ifonts.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
137
138
139
140
141
142
143
144
145
#pragma once
#include "imodule.h"
#include "irenderable.h"
#include <iostream>
class Material;
typedef std::shared_ptr<Material> MaterialPtr;
namespace fonts
{
namespace q3font
{
// Default values of Quake 3 sourcecode. Don't change!
const std::size_t GLYPH_COUNT_PER_FONT = 256;
} // namespace
// Container-class for Glyphs (== single font characters).
class IGlyphInfo
{
public:
int height; // number of scan lines
int top; // top of glyph in buffer
int bottom; // bottom of glyph in buffer
int pitch; // width for copying
int xSkip; // x adjustment
int imageWidth; // width of actual image
int imageHeight; // height of actual image
float s; // x offset in image where glyph starts
float t; // y offset in image where glyph starts
float s2;
float t2;
std::string texture; // the texture name without extension, e.g. carleton_1_24
// The shader this glyph is associated with
// this is NULL until the font is actually used
ShaderPtr shader;
};
typedef std::shared_ptr<IGlyphInfo> IGlyphInfoPtr;
// Each D3 font has three resolutions
enum Resolution
{
Resolution12,
Resolution24,
Resolution48,
NumResolutions
};
inline std::ostream& operator<< (std::ostream& os, Resolution res)
{
switch (res)
{
case Resolution12:
os << "12";
break;
case Resolution24:
os << "24";
break;
case Resolution48:
os << "48";
break;
default:
assert(false);
os << "Unrecognised";
break;
}
return os;
}
// Each font resolution has its own set of glyphs
class IGlyphSet
{
public:
virtual ~IGlyphSet() {}
// 12, 24, 48
virtual Resolution getResolution() const = 0;
// each set has 256 glyphs (q3font::GLYPH_COUNT_PER_FONT)
virtual IGlyphInfoPtr getGlyph(std::size_t glyphIndex) const = 0;
// Gets the scale for calculating the render font size
virtual float getGlyphScale() const = 0;
// Gets the maximum width of a glyph in this set
virtual std::size_t getMaxGlyphWidth() const = 0;
// Gets the maximum height of a glyph in this set
virtual std::size_t getMaxGlyphHeight() const = 0;
// Ensures that each glyph has a valid Shader
virtual void realiseShaders() = 0;
};
typedef std::shared_ptr<IGlyphSet> IGlyphSetPtr;
/**
* Holds information about one specific font.
* A font consists of three resolutions.
*/
class IFontInfo
{
public:
virtual ~IFontInfo() {}
// The name of the font, e.g. "carleton"
virtual const std::string& getName() const = 0;
// The language of this font
virtual const std::string& getLanguage() const = 0;
// Returns the glyphset for the specified resolution
virtual IGlyphSetPtr getGlyphSet(Resolution resolution) = 0;
};
typedef std::shared_ptr<IFontInfo> IFontInfoPtr;
/**
* greebo: Use the FontManager to load a specific font. The returned FontInfo structure
* contains all the necessary info about the glyphs, as found in the font's DAT file.
*/
class IFontManager :
public RegisterableModule
{
public:
// Returns the info structure of a specific font (current language),
// returns NULL if no font info is available yet
virtual IFontInfoPtr findFontInfo(const std::string& name) = 0;
};
}
const char* const MODULE_FONTMANAGER("FontManager");
inline fonts::IFontManager& GlobalFontManager()
{
static module::InstanceReference<fonts::IFontManager> _reference(MODULE_FONTMANAGER);
return _reference;
}