Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: some build-efficiency-issues

File size: 3.4 KB
RevLine 
[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 */
25#define FONT_NUM_COLORS              256                        //!< number of colors.
26
27#define FONT_HIGHEST_KNOWN_CHAR      128                        //!< The highest character known to the textEngine.
28
[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 */
35struct Glyph
36{
37  // Glyph-specific (size and so on)
38  Uint16   character;         //!< The character
39  int      minX;              //!< The minimum distance from the origin in X
40  int      maxX;              //!< The maximum distance from the origin in X
41  int      minY;              //!< The minimum distance from the origin in Y
42  int      maxY;              //!< The maximum distance from the origin in Y
43  int      width;             //!< The width of the Glyph
44  int      height;            //!< The height of the Glyph
45  int      bearingX;          //!< How much is right of the Origin
46  int      bearingY;          //!< How much is above the Origin
47  int      advance;           //!< How big a Glyph would be in monospace-mode
[3543]48
[5343]49  // OpenGL-specific
50  //  TexCoord texCoord;      //!< A Texture Coordinate for this glyph.
51  GLuint   displayList;       //!< DiplayList to render this Glyph.
52};
[2036]53
[1853]54
[5347]55//! A class to handle a Font of a certain ttf-File/image-file, Size.
[5343]56class Font : public BaseObject
57{
58  friend class Text;
[1853]59
[5343]60  public:
61    Font(const char* fontFile,
62         unsigned int fontSize);
[5347]63    Font(const char* imageFile);
[5343]64    Font(char** xpmArray);
65    virtual ~Font();
[3245]66
[5343]67    void init();
[3245]68
[5343]69  // font
70    bool loadFont(const char* fontFile);
71    bool loadFontFromSDL_Surface(SDL_Surface* surface);
72
73    void setSize(unsigned int fontSize);
74    void setStyle(const char* renderStyle);
75
76    /** @returns a Pointer to the Array of Glyphs */
77    inline Glyph** getGlyphArray() const { return this->glyphArray; };
78    /** @returns the texture to the fast-texture */
79    inline GLuint getFastTextureID() const { return this->fastTextureID; };
80    /** @returns the default Font */
81    inline static Font* getDefaultFont() { return Font::defaultFont; };
82
83    void createAsciiImage(const char* fileName);
84    static void initDefaultFont();
85    static void removeDefaultFont();
86
87  private:
88    int getMaxHeight();
89    int getMaxAscent();
90    int getMaxDescent();
91    Glyph* getGlyphMetrics(Uint16 character);
92
93    GLuint createFastTexture();
94
95    void initGlyphs(Uint16 from, Uint16 count);
96    int findOptimalFastTextureSize();
97
98    void debug();
99
100  private:
101    static Font*  defaultFont;         //!< a default font, that is used, if other fonts were unable to be loaded.
[5347]102    // information about the Font
[5343]103    TTF_Font*     font;                //!< The font we use for this.
104    unsigned int  fontSize;            //!< The size of the font in pixels. each Font has one size.
105    int           renderStyle;         //!< The Renderstyle
106
107    Glyph**       glyphArray;          //!< An Array of all the Glyphs stored in the Array of Glyphs.
108    GLuint        fastTextureID;       //!< The fast textureID.
[1853]109};
110
[5343]111#endif /* _FONT_H */
Note: See TracBrowser for help on using the repository browser.