Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/graphics/text_engine/font.h @ 5343

Last change on this file since 5343 was 5343, checked in by bensch, 19 years ago

orxonox/trunk: split open the text-engine

File size: 3.2 KB
Line 
1/*!
2 * @file font.h
3 * brief Definition of the FONT-loading class
4 */
5
6#ifndef _FONT_H
7#define _FONT_H
8
9#include "base_object.h"
10
11#include "glincl.h"
12
13
14#ifdef HAVE_SDL_TTF_H
15#include <SDL_ttf.h>
16#else
17#include <SDL/SDL_ttf.h>
18#endif
19
20/* some default values */
21#define FONT_NUM_COLORS              256                        //!< number of colors.
22
23#define FONT_HIGHEST_KNOWN_CHAR      128                        //!< The highest character known to the textEngine.
24
25// FORWARD DECLARATION
26
27//! A struct for handling glyphs
28/**
29   a Glyph is one letter of a certain font
30 */
31struct Glyph
32{
33  // Glyph-specific (size and so on)
34  Uint16   character;         //!< The character
35  int      minX;              //!< The minimum distance from the origin in X
36  int      maxX;              //!< The maximum distance from the origin in X
37  int      minY;              //!< The minimum distance from the origin in Y
38  int      maxY;              //!< The maximum distance from the origin in Y
39  int      width;             //!< The width of the Glyph
40  int      height;            //!< The height of the Glyph
41  int      bearingX;          //!< How much is right of the Origin
42  int      bearingY;          //!< How much is above the Origin
43  int      advance;           //!< How big a Glyph would be in monospace-mode
44
45  // OpenGL-specific
46  //  TexCoord texCoord;      //!< A Texture Coordinate for this glyph.
47  GLuint   displayList;       //!< DiplayList to render this Glyph.
48};
49
50
51////////////
52/// FONT ///
53////////////
54//! A class to handle a Font of a certain ttf-File, Size and Color.
55class Font : public BaseObject
56{
57  friend class Text;
58
59  public:
60    Font(const char* fontFile,
61         unsigned int fontSize);
62    Font(char** xpmArray);
63    virtual ~Font();
64
65    void init();
66
67  // font
68    bool loadFont(const char* fontFile);
69    bool loadFontFromSDL_Surface(SDL_Surface* surface);
70
71    void setSize(unsigned int fontSize);
72    void setStyle(const char* renderStyle);
73
74    /** @returns a Pointer to the Array of Glyphs */
75    inline Glyph** getGlyphArray() const { return this->glyphArray; };
76    /** @returns the texture to the fast-texture */
77    inline GLuint getFastTextureID() const { return this->fastTextureID; };
78    /** @returns the default Font */
79    inline static Font* getDefaultFont() { return Font::defaultFont; };
80
81    void createAsciiImage(const char* fileName);
82    static void initDefaultFont();
83    static void removeDefaultFont();
84
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.
100  // information about the Font
101    TTF_Font*     font;                //!< The font we use for this.
102    unsigned int  fontSize;            //!< The size of the font in pixels. each Font has one size.
103    int           renderStyle;         //!< The Renderstyle
104
105    Glyph**       glyphArray;          //!< An Array of all the Glyphs stored in the Array of Glyphs.
106    GLuint        fastTextureID;       //!< The fast textureID.
107};
108
109#endif /* _FONT_H */
Note: See TracBrowser for help on using the repository browser.