00001
00002
00003
#ifndef FONT_H
00004
#define FONT_H
00005
00006
#include "RageTextureID.h"
00007
#include "RageUtil.h"
00008
#include "RageTypes.h"
00009
#include <map>
00010
00011
class FontPage;
00012
class RageTexture;
00013
class IniFile;
00014
00015 struct glyph {
00016 FontPage *
fp;
00017 RageTexture *
Texture;
00018 RageTexture *
GetTexture()
const {
return const_cast<RageTexture *>(
Texture); }
00019
00020
00021 int hadvance;
00022
00023
00024 float width,
height;
00025
00026
00027 float hshift;
00028
00029
00030 RectF rect;
00031 };
00032
00033 struct FontPageSettings
00034 {
00035 CString TexturePath;
00036
00037 int DrawExtraPixelsLeft,
00038
DrawExtraPixelsRight,
00039
AddToAllWidths,
00040
LineSpacing,
00041
Top,
00042
Baseline,
00043
DefaultWidth,
00044
AdvanceExtraPixels;
00045 float ScaleAllWidthsBy;
00046 CString TextureHints;
00047
00048 map<longchar,int>
CharToGlyphNo;
00049
00050 map<int,int>
GlyphWidths;
00051
00052 FontPageSettings():
00053
DrawExtraPixelsLeft(0),
DrawExtraPixelsRight(0),
00054
AddToAllWidths(0),
00055
LineSpacing(-1),
00056
Top(-1),
00057
Baseline(-1),
00058
DefaultWidth(-1),
00059
AdvanceExtraPixels(1),
00060
ScaleAllWidthsBy(1),
00061
TextureHints("default")
00062 { }
00063
00064
00065
00066
CString MapRange(CString Mapping,
int map_offset,
int glyph_offset,
int cnt);
00067 };
00068
00069 class FontPage
00070 {
00071
public:
00072 RageTexture*
m_pTexture;
00073
00074 CString m_sTexturePath;
00075
00076
00077 vector<glyph>
glyphs;
00078
00079 map<longchar,int>
m_iCharToGlyphNo;
00080
00081
FontPage();
00082
~FontPage();
00083
00084
void Load(
FontPageSettings cfg );
00085
00086
00087 int height;
00088 int LineSpacing;
00089 float vshift;
00090 int GetCenter()
const {
return height/2; }
00091
00092
private:
00093
void SetExtraPixels(
int DrawExtraPixelsLeft,
int DrawExtraPixelsRight);
00094
void SetTextureCoords(
const vector<int> &widths,
int AdvanceExtraPixels);
00095 };
00096
00097 class Font
00098 {
00099
public:
00100 int m_iRefCount;
00101 CString path;
00102
00103
Font();
00104
~Font();
00105
00106
const glyph &
GetGlyph(
wchar_t c )
const;
00107
00108
int GetLineWidthInSourcePixels(
const wstring &szLine )
const;
00109
int GetLineHeightInSourcePixels(
const wstring &szLine )
const;
00110
00111
bool FontCompleteForString(
const wstring &str )
const;
00112
00113
00114
void AddPage(
FontPage *fp);
00115
00116
00117
void MergeFont(
Font &f);
00118
00119
void Load(
const CString &sFontOrTextureFilePath, CString sChars);
00120
void Unload();
00121
void Reload();
00122
00123
00124
void CapsOnly();
00125
00126 int GetHeight()
const {
return def->
height; }
00127 int GetCenter()
const {
return def->
GetCenter(); }
00128 int GetLineSpacing()
const {
return def->
LineSpacing; }
00129
00130
void SetDefaultGlyph(
FontPage *fp);
00131
00132
static const wchar_t DEFAULT_GLYPH;
00133
00134
static CString GetFontName(CString FileName);
00135
00136
static void WeedFontNames(vector<CString> &v,
const CString &FileName);
00137
00138
private:
00139
00140 vector<FontPage *>
pages;
00141
00142
00143
00144 FontPage *
def;
00145
00146
00147 map<longchar,glyph*>
m_iCharToGlyph;
00148 glyph *
m_iCharToGlyphCache[128];
00149
00150
00151 CString Chars;
00152
00153
void LoadFontPageSettings(
FontPageSettings &cfg,
IniFile &ini,
const CString &TexturePath,
const CString &PageName, CString sChars);
00154
static void GetFontPaths(
const CString &sFontOrTextureFilePath,
00155 CStringArray &TexturePaths, CString &IniPath);
00156
CString GetPageNameFromFileName(
const CString &fn);
00157 };
00158
00159
#endif
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184