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

SFontLoader.h

00001 00002 00003 #ifndef MOD_SFONTLOADER_H 00004 #define MOD_SFONTLOADER_H 00005 00006 //Licence: LGPL 00007 //Copyright: Visti Andresen 00008 00009 #include <string> 00010 00011 using namespace std; 00012 /**A class for loading a SFont stored in a .ppm image.*/ 00013 class SFontLoader 00014 { 00015 public: 00016 /**An enum defining the way to obtain alpha data from the ppm image*/ 00017 enum AlphaLoadingType{ 00018 /**Don't fake an alpha channel.*/ 00019 NONE, 00020 /**Every thing black is transparent (colour is actually definable).*/ 00021 BLACK_MASK, 00022 /**Use the grey (r+g+b)/3 value as alpha 0 is 100% transparent.*/ 00023 GREY_COLOUR 00024 }; 00025 00026 SFontLoader(); 00027 ~SFontLoader(); 00028 00029 /**Load a font .ppm file (may contain path).*/ 00030 void loadFont(const string &name); 00031 00032 /**Sets the way to get the alpha channel when load is called, default is 00033 GREY_COLOUR.*/ 00034 void setAlphaLoadingType(AlphaLoadingType type){alphaType_ = type;} 00035 /**Sets the alpha colour to use with alphaType=BLACK_MASK, default 0,0,0.*/ 00036 void setAlpha(unsigned char r, unsigned char g, unsigned char b); 00037 /**Sets the colour used to separate characters in the SFont file, default 00038 255,0,255.*/ 00039 void setSeperatorColour(unsigned char r, unsigned char g, unsigned char b); 00040 00041 /**Sets the fontDefinition to use for the next loadFont 00042 00043 fontDefinition is a string containing the letters in the SFont.*/ 00044 void setFontDefinition(const string &definition) 00045 {fontDefinition_ = definition;} 00046 00047 /**Returns a pointer to a raw image of a character, the format is 00048 RBGA and the width and height can be found using 00049 getFontWidth() and getFontHeight().*/ 00050 unsigned char *getDataForCharacter(char character); 00051 00052 /**Returns the width of a specific character <=getFontWidth() (in pixels).*/ 00053 int getCharacterWidth(char character); 00054 /**Returns the height of the font <=getFontHeight() (in pixels).*/ 00055 int getCharacterHeight(){return fontDataHeight_-1;} 00056 /**Returns the height of a character data image (in pixels). Always = 2^n*/ 00057 int getFontHeight(){return fontCellHeight_;} 00058 /**Returns the width of a character data image (in pixels). Always = 2^m*/ 00059 int getFontWidth(){return fontCellWidth_;} 00060 00061 private: 00062 void findCharWidths(unsigned char *result); 00063 void unloadGfx(); 00064 void loadCharacter(unsigned char number, unsigned char *inputData, 00065 unsigned char *outputData); 00066 void readNumber(ifstream &file, int &number); 00067 unsigned char *loadPpm(const string &fileName, int &width, int &height); 00068 void findCellSizes(); 00069 inline bool isSpaceColour(unsigned char* data); 00070 00071 unsigned char alphaR_, alphaG_, alphaB_; 00072 unsigned char seperatorR_, seperatorG_, seperatorB_; 00073 AlphaLoadingType alphaType_; 00074 string fontDefinition_; 00075 00076 unsigned char *fontData_; 00077 int fontCellHeight_; 00078 int fontDataHeight_; 00079 int fontCellWidth_; 00080 int fontDataWidth_; 00081 00082 unsigned char * fontGfxTiles[256]; 00083 int charWidth_[256]; 00084 int definitionFontWidths_[256]; 00085 int numberOfCharsInFont_; 00086 }; 00087 00088 bool SFontLoader::isSpaceColour(unsigned char* data) 00089 { 00090 return (seperatorR_ == data[0] && seperatorG_ == data[1] && 00091 seperatorB_ == data[2]); 00092 } 00093 00094 00095 00096 #endif

Generated on Wed Sep 1 14:46:57 2004 by doxygen 1.3.7