Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members

Font.h

Go to the documentation of this file.
00001 /* Font - stores a font, used by BitmapText. */ 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 /* Number of pixels to advance horizontally after drawing this character. */ 00021 int hadvance; 00022 00023 /* Size of the actual rendered character. */ 00024 float width, height; 00025 00026 /* Number of pixels to offset this character when rendering. */ 00027 float hshift; // , vshift; 00028 00029 /* Texture coordinate rect. */ 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 /* If a value is missing, the width of the texture frame is used. */ 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 /* Map a range from a character map to glyphs. If cnt is -1, map the 00065 * whole map. Returns "" or an error message. */ 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 /* All glyphs in this list will point to m_pTexture. */ 00077 vector<glyph> glyphs; 00078 00079 map<longchar,int> m_iCharToGlyphNo; 00080 00081 FontPage(); 00082 ~FontPage(); 00083 00084 void Load( FontPageSettings cfg ); 00085 00086 /* Page-global properties. */ 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 /* Add a FontPage to this font. */ 00114 void AddPage(FontPage *fp); 00115 00116 /* Steal all of a font's pages. */ 00117 void MergeFont(Font &f); 00118 00119 void Load(const CString &sFontOrTextureFilePath, CString sChars); 00120 void Unload(); 00121 void Reload(); 00122 00123 /* Load font-wide settings. */ 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 /* Remove filenames in 'v' that aren't in the same font as "FileName". */ 00136 static void WeedFontNames(vector<CString> &v, const CString &FileName); 00137 00138 private: 00139 /* List of pages and fonts that we use (and are responsible for freeing). */ 00140 vector<FontPage *> pages; 00141 00142 /* This is the primary fontpage of this font; font-wide height, center, 00143 * etc. is pulled from it. (This is one of pages[].) */ 00144 FontPage *def; 00145 00146 /* Map from characters to glyphs. (Each glyph* is part of one of pages[].) */ 00147 map<longchar,glyph*> m_iCharToGlyph; 00148 glyph *m_iCharToGlyphCache[128]; 00149 00150 /* We keep this around only for reloading. */ 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 * (c) 2001-2004 Glenn Maynard, Chris Danford 00163 * All rights reserved. 00164 * 00165 * Permission is hereby granted, free of charge, to any person obtaining a 00166 * copy of this software and associated documentation files (the 00167 * "Software"), to deal in the Software without restriction, including 00168 * without limitation the rights to use, copy, modify, merge, publish, 00169 * distribute, and/or sell copies of the Software, and to permit persons to 00170 * whom the Software is furnished to do so, provided that the above 00171 * copyright notice(s) and this permission notice appear in all copies of 00172 * the Software and that both the above copyright notice(s) and this 00173 * permission notice appear in supporting documentation. 00174 * 00175 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 00176 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00177 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF 00178 * THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS 00179 * INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT 00180 * OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS 00181 * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR 00182 * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 00183 * PERFORMANCE OF THIS SOFTWARE. 00184 */

Generated on Thu Jan 27 20:57:20 2005 for StepMania by doxygen 1.3.7