Debian Codegraph @

include/ifonts.h

raw
1 #pragma once
2
3 #include "imodule.h"
4 #include "irenderable.h"
5
6 #include <iostream>
7
8 class Material;
9 typedef std::shared_ptr<Material> MaterialPtr;
10
11 namespace fonts
12 {
13
14 namespace q3font
15 {
16 // Default values of Quake 3 sourcecode. Don't change!
17 const std::size_t GLYPH_COUNT_PER_FONT = 256;
18
19 } // namespace
20
21 // Container-class for Glyphs (== single font characters).
22 class IGlyphInfo
23 {
24 public:
25 int height; // number of scan lines
26 int top; // top of glyph in buffer
27 int bottom; // bottom of glyph in buffer
28 int pitch; // width for copying
29 int xSkip; // x adjustment
30 int imageWidth; // width of actual image
31 int imageHeight; // height of actual image
32 float s; // x offset in image where glyph starts
33 float t; // y offset in image where glyph starts
34 float s2;
35 float t2;
36 std::string texture; // the texture name without extension, e.g. carleton_1_24
37
38 // The shader this glyph is associated with
39 // this is NULL until the font is actually used
40 ShaderPtr shader;
41 };
42 typedef std::shared_ptr<IGlyphInfo> IGlyphInfoPtr;
43
44 // Each D3 font has three resolutions
45 enum Resolution
46 {
47 Resolution12,
48 Resolution24,
49 Resolution48,
50 NumResolutions
51 };
52
53 inline std::ostream& operator<< (std::ostream& os, Resolution res)
54 {
55 switch (res)
56 {
57 case Resolution12:
58 os << "12";
59 break;
60
61 case Resolution24:
62 os << "24";
63 break;
64
65 case Resolution48:
66 os << "48";
67 break;
68
69 default:
70 assert(false);
71 os << "Unrecognised";
72 break;
73 }
74
75 return os;
76 }
77
78 // Each font resolution has its own set of glyphs
79 class IGlyphSet
80 {
81 public:
82 virtual ~IGlyphSet() {}
83
84 // 12, 24, 48
85 virtual Resolution getResolution() const = 0;
86
87 // each set has 256 glyphs (q3font::GLYPH_COUNT_PER_FONT)
88 virtual IGlyphInfoPtr getGlyph(std::size_t glyphIndex) const = 0;
89
90 // Gets the scale for calculating the render font size
91 virtual float getGlyphScale() const = 0;
92
93 // Gets the maximum width of a glyph in this set
94 virtual std::size_t getMaxGlyphWidth() const = 0;
95
96 // Gets the maximum height of a glyph in this set
97 virtual std::size_t getMaxGlyphHeight() const = 0;
98
99 // Ensures that each glyph has a valid Shader
100 virtual void realiseShaders() = 0;
101 };
102 typedef std::shared_ptr<IGlyphSet> IGlyphSetPtr;
103
104 /**
105 * Holds information about one specific font.
106 * A font consists of three resolutions.
107 */
108 class IFontInfo
109 {
110 public:
111 virtual ~IFontInfo() {}
112
113 // The name of the font, e.g. "carleton"
114 virtual const std::string& getName() const = 0;
115
116 // The language of this font
117 virtual const std::string& getLanguage() const = 0;
118
119 // Returns the glyphset for the specified resolution
120 virtual IGlyphSetPtr getGlyphSet(Resolution resolution) = 0;
121 };
122 typedef std::shared_ptr<IFontInfo> IFontInfoPtr;
123
124 /**
125 * greebo: Use the FontManager to load a specific font. The returned FontInfo structure
126 * contains all the necessary info about the glyphs, as found in the font's DAT file.
127 */
128 class IFontManager :
129 public RegisterableModule
130 {
131 public:
132 // Returns the info structure of a specific font (current language),
133 // returns NULL if no font info is available yet
134 virtual IFontInfoPtr findFontInfo(const std::string& name) = 0;
135 };
136
137 }
138
139 const char* const MODULE_FONTMANAGER("FontManager");
140
141 inline fonts::IFontManager& GlobalFontManager()
142 {
143 static module::InstanceReference<fonts::IFontManager> _reference(MODULE_FONTMANAGER);
144 return _reference;
145 }