Font.h
Go to the documentation of this file.00001 00011 #ifndef __Font_H__ 00012 #define __Font_H__ 00013 00014 // Includes 00015 #include "XMLObject.h" 00016 #include "Array.h" 00017 00018 // Forward declares 00019 class Bitmap; 00020 class Filename; 00021 00022 // Font 00023 class Font:XMLObject 00024 { 00025 public: 00026 Font(); 00027 00028 Font( 00029 const Asset& asset 00030 ); 00031 00032 Font( 00033 const Filename& filename 00034 ); 00035 00036 00037 ~Font(); 00038 00039 void Blit( 00040 Bitmap& bitmap, 00041 int x, 00042 int y, 00043 const char* text, 00044 int spacing = 0, 00045 unsigned short modulate = 0xffff, 00046 unsigned char alpha = 255 00047 ) const; 00048 00049 void BlitWrap( 00050 Bitmap& bitmap, 00051 int x, 00052 int y, 00053 const char* text, 00054 int width, 00055 int hspacing = 0, 00056 int vspacing = 0, 00057 unsigned short modulate = 0xffff, 00058 unsigned char alpha = 255 00059 ) const; 00060 00061 00062 struct Bounds 00063 { 00064 int width; 00065 int height; 00066 }; 00067 00068 Bounds GetBounds( 00069 const char* text, 00070 int spacing = 0 00071 ) const; 00072 00073 Bounds GetBoundsWrap( 00074 const char* text, 00075 int width, 00076 int hspacing = 0, 00077 int vspacing = 0 00078 ) const; 00079 00080 int GetBaseline() const; 00081 00082 int GetSize() const; 00083 00084 int GetGlyphHeight() const; 00085 00086 void WriteToAsset(Asset* asset); 00087 void ReadFromAsset(const Asset* asset); 00088 void ReadFromAssetNew(const Asset* asset); 00089 00090 private: 00091 struct Character; 00092 const Character& GetCharacter(int ascii) const; 00093 int GetKerning(int first, int second) const; 00094 00095 00096 bool WillWordFit(int xp, int maxX, const char* text, int hspacing) const; 00097 00098 void LoadFont(const Filename& filename); 00099 00101 virtual XMLObject* XML_Element(StringId _name, const XMLAttributeList& _attributes); 00102 00104 virtual void XML_Attribute(StringId _name, const XMLVariant& _value); 00105 00106 private: 00107 struct Character 00108 { 00109 int ascii; 00110 int spacing; 00111 int x; 00112 int y; 00113 int width; 00114 int height; 00115 int xoffset; 00116 int yoffset; 00117 bool isBlank; 00118 Array<Bitmap*> layers; 00119 00120 Character(): 00121 ascii(0), 00122 spacing(0), 00123 x(0), 00124 y(0), 00125 width(0), 00126 height(0), 00127 xoffset(0), 00128 yoffset(0), 00129 isBlank(false) 00130 { } 00131 }; 00132 00133 struct Kerning 00134 { 00135 char first; 00136 char second; 00137 int amount; 00138 00139 Kerning(): 00140 first(0), 00141 second(0), 00142 amount(0) 00143 { } 00144 00145 }; 00146 00147 StringId name_; 00148 int size_; 00149 int lineSpacing_; 00150 int baseline_; 00151 int layerCount_; 00152 00153 Character characters_[256]; 00154 Kerning kerning_[256]; 00155 00156 Array<char*> layers_; 00157 }; 00158 00159 #endif /* __Font_H__ */ 00160
Reproduction/republishing of any material on this site without permission is strictly prohibited.
