[4838] | 1 | /*! |
---|
[5343] | 2 | * @file font.h |
---|
| 3 | * brief Definition of the FONT-loading class |
---|
[5344] | 4 | * |
---|
| 5 | * !! IMPORTANT !! When using ttf fonts clear the license issues prior to |
---|
| 6 | * adding them to orxonox. This is really important, because we do not want |
---|
| 7 | * to offend anyone. |
---|
[5343] | 8 | */ |
---|
[1853] | 9 | |
---|
[5343] | 10 | #ifndef _FONT_H |
---|
| 11 | #define _FONT_H |
---|
[1853] | 12 | |
---|
[3543] | 13 | #include "base_object.h" |
---|
[1853] | 14 | |
---|
[5343] | 15 | #include "glincl.h" |
---|
| 16 | |
---|
| 17 | |
---|
| 18 | #ifdef HAVE_SDL_TTF_H |
---|
| 19 | #include <SDL_ttf.h> |
---|
| 20 | #else |
---|
| 21 | #include <SDL/SDL_ttf.h> |
---|
| 22 | #endif |
---|
| 23 | |
---|
| 24 | /* some default values */ |
---|
[5369] | 25 | #define FONT_NUM_COLORS 256 //!< number of colors. |
---|
[5343] | 26 | |
---|
[5369] | 27 | #define FONT_HIGHEST_KNOWN_CHAR 128 //!< The highest character known to the textEngine. |
---|
| 28 | #define FONT_DEFAULT_RENDER_SIZE 50 //!< At what Resolution to render fonts. |
---|
[4838] | 29 | // FORWARD DECLARATION |
---|
[3543] | 30 | |
---|
[5343] | 31 | //! A struct for handling glyphs |
---|
| 32 | /** |
---|
[5347] | 33 | * a Glyph is one letter of a certain font |
---|
[5343] | 34 | */ |
---|
| 35 | struct Glyph |
---|
| 36 | { |
---|
| 37 | // Glyph-specific (size and so on) |
---|
| 38 | Uint16 character; //!< The character |
---|
[5368] | 39 | float minX; //!< The minimum distance from the origin in X |
---|
| 40 | float maxX; //!< The maximum distance from the origin in X |
---|
| 41 | float minY; //!< The minimum distance from the origin in Y |
---|
| 42 | float maxY; //!< The maximum distance from the origin in Y |
---|
| 43 | float width; //!< The width of the Glyph |
---|
| 44 | float height; //!< The height of the Glyph |
---|
| 45 | float bearingX; //!< How much is right of the Origin |
---|
| 46 | float bearingY; //!< How much is above the Origin |
---|
| 47 | float advance; //!< How big a Glyph would be in monospace-mode |
---|
[3543] | 48 | |
---|
[5367] | 49 | GLfloat texCoord[4]; //!< Texture coordinates: 0:left, 1:right, 2: top, 3: bottom. |
---|
[5343] | 50 | }; |
---|
[2036] | 51 | |
---|
[1853] | 52 | |
---|
[5347] | 53 | //! A class to handle a Font of a certain ttf-File/image-file, Size. |
---|
[5343] | 54 | class Font : public BaseObject |
---|
| 55 | { |
---|
| 56 | friend class Text; |
---|
[1853] | 57 | |
---|
[5343] | 58 | public: |
---|
| 59 | Font(const char* fontFile, |
---|
[5368] | 60 | unsigned int renderSize); |
---|
[5347] | 61 | Font(const char* imageFile); |
---|
[5343] | 62 | Font(char** xpmArray); |
---|
| 63 | virtual ~Font(); |
---|
[3245] | 64 | |
---|
[5343] | 65 | void init(); |
---|
[3245] | 66 | |
---|
[5343] | 67 | // font |
---|
[5368] | 68 | bool loadFontFromTTF(const char* fontFile); |
---|
[5343] | 69 | bool loadFontFromSDL_Surface(SDL_Surface* surface); |
---|
| 70 | |
---|
| 71 | void setStyle(const char* renderStyle); |
---|
| 72 | |
---|
| 73 | /** @returns a Pointer to the Array of Glyphs */ |
---|
| 74 | inline Glyph** getGlyphArray() const { return this->glyphArray; }; |
---|
| 75 | /** @returns the texture to the fast-texture */ |
---|
| 76 | inline GLuint getFastTextureID() const { return this->fastTextureID; }; |
---|
| 77 | /** @returns the default Font */ |
---|
[5421] | 78 | inline static Font* getDefaultFont() { if (Font::defaultFont == NULL) initDefaultFont(); return Font::defaultFont; }; |
---|
[5343] | 79 | |
---|
| 80 | void createAsciiImage(const char* fileName); |
---|
| 81 | static void initDefaultFont(); |
---|
| 82 | static void removeDefaultFont(); |
---|
| 83 | |
---|
[5368] | 84 | |
---|
[5343] | 85 | private: |
---|
| 86 | int getMaxHeight(); |
---|
| 87 | int getMaxAscent(); |
---|
| 88 | int getMaxDescent(); |
---|
| 89 | Glyph* getGlyphMetrics(Uint16 character); |
---|
| 90 | |
---|
| 91 | GLuint createFastTexture(); |
---|
| 92 | |
---|
| 93 | void initGlyphs(Uint16 from, Uint16 count); |
---|
| 94 | int findOptimalFastTextureSize(); |
---|
| 95 | |
---|
| 96 | void debug(); |
---|
| 97 | |
---|
| 98 | private: |
---|
| 99 | static Font* defaultFont; //!< a default font, that is used, if other fonts were unable to be loaded. |
---|
[5347] | 100 | // information about the Font |
---|
[5368] | 101 | TTF_Font* fontTTF; //!< The font we use for this. |
---|
[5343] | 102 | int renderStyle; //!< The Renderstyle |
---|
[5368] | 103 | unsigned int renderSize; //!< How big the Font should be rendered. |
---|
[5343] | 104 | |
---|
| 105 | Glyph** glyphArray; //!< An Array of all the Glyphs stored in the Array of Glyphs. |
---|
| 106 | GLuint fastTextureID; //!< The fast textureID. |
---|
[1853] | 107 | }; |
---|
| 108 | |
---|
[5343] | 109 | #endif /* _FONT_H */ |
---|