1 | /*! |
---|
2 | * @file font.h |
---|
3 | * brief Definition of the FONT-loading class |
---|
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. |
---|
8 | */ |
---|
9 | |
---|
10 | #ifndef _FONT_H |
---|
11 | #define _FONT_H |
---|
12 | |
---|
13 | #include "texture.h" |
---|
14 | |
---|
15 | #include "font_data.h" |
---|
16 | |
---|
17 | |
---|
18 | //! A class to handle a Font of a certain ttf-File/image-file, Size. |
---|
19 | class Font : public Texture |
---|
20 | { |
---|
21 | |
---|
22 | public: |
---|
23 | Font(const std::string& fontFile, |
---|
24 | unsigned int renderSize); |
---|
25 | Font(const std::string& imageFile); |
---|
26 | Font(char** xpmArray); |
---|
27 | virtual ~Font(); |
---|
28 | |
---|
29 | // font |
---|
30 | bool loadFontFromTTF(const std::string& fontFile); |
---|
31 | bool loadFontFromSDL_Surface(SDL_Surface* surface); |
---|
32 | |
---|
33 | void setStyle(const std::string& renderStyle); |
---|
34 | |
---|
35 | /** @returns a Pointer to the Array of Glyphs */ |
---|
36 | inline Glyph** getGlyphArray() const { return this->data->getGlyphArray(); }; |
---|
37 | /** @returns the a pointer to the TTF */ |
---|
38 | inline TTF_Font* getTTF() const { return this->data->getTTF(); }; |
---|
39 | |
---|
40 | int getMaxHeight() const; |
---|
41 | int getMaxAscent() const; |
---|
42 | int getMaxDescent() const; |
---|
43 | |
---|
44 | /** @returns the default Font */ |
---|
45 | inline static Font* getDefaultFont() { if (Font::defaultFont == NULL) initDefaultFont(); return Font::defaultFont; }; |
---|
46 | |
---|
47 | void createAsciiImage(const std::string& fileName, unsigned int size) const; |
---|
48 | static void initDefaultFont(); |
---|
49 | static void removeDefaultFont(); |
---|
50 | |
---|
51 | |
---|
52 | private: |
---|
53 | void init(); |
---|
54 | bool getGlyphMetrics(Glyph* glyph, Uint16 character); |
---|
55 | |
---|
56 | bool createFastTexture(); |
---|
57 | |
---|
58 | void initGlyphs(Uint16 from, Uint16 count); |
---|
59 | int findOptimalFastTextureSize(); |
---|
60 | |
---|
61 | void debug(); |
---|
62 | |
---|
63 | private: |
---|
64 | static Font* defaultFont; //!< a default font, that is used, if other fonts were unable to be loaded. |
---|
65 | |
---|
66 | fontDataPointer data; |
---|
67 | }; |
---|
68 | |
---|
69 | #endif /* _FONT_H */ |
---|