Etterna 0.74.4
Loading...
Searching...
No Matches
Font.h
1
3#ifndef FONT_H
4#define FONT_H
5
6#include "RageUtil/Misc/RageTypes.h"
7#include "RageUtil/Utils/RageUtil.h"
8
9class FontPage;
10class RageTexture;
11class IniFile;
12
30
32struct glyph
33{
38 FontPageTextures* GetFontPageTextures() const
39 {
40 return const_cast<FontPageTextures*>(&m_FontPageTextures);
41 }
42
45 int m_iHadvance{ 0 };
46
48 float m_fWidth{ 0 };
50 float m_fHeight{ 0 };
51
53 float m_fHshift{ 0 }; // , m_fVshift;
54
57
60 : m_pPage(NULL)
62 , m_TexRect()
63 {
64 }
65};
66
69{
70 std::string m_sTexturePath;
71
72 int m_iDrawExtraPixelsLeft{ 0 }, m_iDrawExtraPixelsRight{ 0 },
73 m_iAddToAllWidths{ 0 }, m_iLineSpacing{ -1 }, m_iTop{ -1 },
74 m_iBaseline{ -1 }, m_iDefaultWidth{ -1 }, m_iAdvanceExtraPixels{ 1 };
75 float m_fScaleAllWidthsBy{ 1 };
76 std::string m_sTextureHints;
77
78 std::map<wchar_t, int> CharToGlyphNo;
79 // If a value is missing, the width of the texture frame is used.
80 std::map<int, int> m_mapGlyphWidths;
81
84 : m_sTexturePath("")
85 , m_sTextureHints("default")
86 , CharToGlyphNo()
87 , m_mapGlyphWidths()
88 {
89 }
90
99 std::string MapRange(const std::string& sMapping,
100 int iMapOffset,
101 int iGlyphOffset,
102 int iCount);
103};
104
106{
107 public:
108 FontPage();
109 ~FontPage();
110
111 void Load(const FontPageSettings& cfg);
112
113 // Page-global properties.
114 int m_iHeight{ 0 };
115 int m_iLineSpacing{ 0 };
116 float m_fVshift{ 0 };
117 int GetCenter() const { return m_iHeight / 2; }
118
119 // Remember these only for GetLineWidthInSourcePixels.
120 int m_iDrawExtraPixelsLeft{ 0 }, m_iDrawExtraPixelsRight{ 0 };
121
122 FontPageTextures m_FontPageTextures;
123
124 // XXX: remove?
125 std::string m_sTexturePath;
126
128 std::vector<glyph> m_aGlyphs;
129
130 std::map<wchar_t, int> m_iCharToGlyphNo;
131
132 private:
133 void SetExtraPixels(int iDrawExtraPixelsLeft, int DrawExtraPixelsRight);
134 void SetTextureCoords(const std::vector<int>& aiWidths,
135 int iAdvanceExtraPixels);
136};
137
138class Font
139{
140 public:
141 int m_iRefCount{ 1 };
142 std::string path;
143
144 Font();
145 ~Font();
146
147 const glyph& GetGlyph(wchar_t c) const;
148
149 int GetLineWidthInSourcePixels(const std::wstring& szLine) const;
150 int GetLineHeightInSourcePixels(const std::wstring& szLine) const;
151 int GetGlyphsThatFit(const std::wstring& line, int* width) const;
152
153 bool FontCompleteForString(const std::wstring& str) const;
154
159 void AddPage(FontPage* fp);
160
164 void MergeFont(Font& f);
165
166 void Load(const std::string& sFontOrTextureFilePath,
167 const std::string& sChars);
168 void Unload();
169 void Reload();
170
171 // Load font-wide settings.
172 void CapsOnly();
173
174 int GetHeight() const { return m_pDefault->m_iHeight; }
175 int GetCenter() const { return m_pDefault->GetCenter(); }
176 int GetLineSpacing() const { return m_pDefault->m_iLineSpacing; }
177
178 void SetDefaultGlyph(FontPage* pPage);
179
180 bool IsRightToLeft() const { return m_bRightToLeft; };
181 const RageColor& GetDefaultStrokeColor() const
182 {
183 return m_DefaultStrokeColor;
184 };
185
186 private:
189 std::vector<FontPage*> m_apPages;
190
196 FontPage* m_pDefault;
197
199 std::map<wchar_t, glyph*> m_iCharToGlyph;
201 glyph* m_iCharToGlyphCache[128];
202
208 bool m_bRightToLeft{ false };
209
210 RageColor m_DefaultStrokeColor;
211
213 std::string m_sChars;
214
215 void LoadFontPageSettings(FontPageSettings& cfg,
216 IniFile& ini,
217 const std::string& sTexturePath,
218 const std::string& PageName,
219 const std::string& sChars);
220 static void GetFontPaths(const std::string& sFontOrTextureFilePath,
221 std::vector<std::string>& sTexturePaths);
222 std::string GetPageNameFromFileName(const std::string& sFilename);
223
224 Font(const Font& rhs);
225 Font& operator=(const Font& rhs);
226};
227
232const wchar_t FONT_DEFAULT_GLYPH = 0xF8FF;
233
234#endif
Definition Font.h:106
std::vector< glyph > m_aGlyphs
All glyphs in this list will point to m_pTexture.
Definition Font.h:128
Definition Font.h:139
void AddPage(FontPage *fp)
Add a FontPage to this font.
Definition Font.cpp:345
void MergeFont(Font &f)
Steal all of a font's pages.
Definition Font.cpp:358
The functions to read and write .INI files.
Definition IniFile.h:11
Definition RageTexture.h:14
The settings used for the FontPage.
Definition Font.h:69
std::string MapRange(const std::string &sMapping, int iMapOffset, int iGlyphOffset, int iCount)
Map a range from a character std::map to glyphs.
Definition Font.cpp:744
FontPageSettings()
The initial settings for the FontPage.
Definition Font.h:83
The textures used by the font.
Definition Font.h:15
RageTexture * m_pTextureMain
The primary texture drawn underneath Main.
Definition Font.h:17
RageTexture * m_pTextureStroke
an optional texture drawn underneath Main.
Definition Font.h:21
FontPageTextures()
Set up the initial textures.
Definition Font.h:24
Definition RageTypes.h:332
The components of a glyph (not technically a character).
Definition Font.h:33
float m_fHshift
Number of pixels to offset this character when rendering.
Definition Font.h:53
FontPageTextures m_FontPageTextures
the textures for the glyph.
Definition Font.h:37
glyph()
Set up the glyph with default values.
Definition Font.h:59
RectF m_TexRect
Texture coordinate rect.
Definition Font.h:56
FontPage * m_pPage
the FontPage that is needed.
Definition Font.h:35
int m_iHadvance
Number of pixels to advance horizontally after drawing this character.
Definition Font.h:45
float m_fWidth
Width of the actual rendered character.
Definition Font.h:48
float m_fHeight
Height of the actual rendered character.
Definition Font.h:50