Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/water/src/lib/graphics/text_engine/font.h @ 7574

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

orxonox/trunk: added MultiLineText a Text for multiple line-input, that should automatically shilft position

File size: 3.4 KB
Line 
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 "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#define FONT_DEFAULT_RENDER_SIZE     50            //!< At what Resolution to render fonts.
29// FORWARD DECLARATION
30
31//! A struct for handling glyphs
32/**
33 * a Glyph is one letter of a certain font
34 */
35struct Glyph
36{
37  // Glyph-specific (size and so on)
38  Uint16   character;         //!< The character
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
48
49  GLfloat texCoord[4];        //!< Texture coordinates: 0:left, 1:right, 2: top, 3: bottom.
50};
51
52
53//! A class to handle a Font of a certain ttf-File/image-file, Size.
54class Font : public Texture
55{
56  public:
57    Font(const std::string& fontFile,
58         unsigned int renderSize);
59    Font(const std::string& imageFile);
60    Font(char** xpmArray);
61    virtual ~Font();
62
63  //  font
64    bool loadFontFromTTF(const std::string& fontFile);
65    bool loadFontFromSDL_Surface(SDL_Surface* surface);
66
67    void setStyle(const std::string& renderStyle);
68
69    /** @returns a Pointer to the Array of Glyphs */
70    inline Glyph** getGlyphArray() const { return this->glyphArray; };
71    /** @returns the a pointer to the TTF */
72    inline TTF_Font* getTTF() const { return this->fontTTF; };
73
74    int getMaxHeight() const;
75    int getMaxAscent() const;
76    int getMaxDescent() const;
77
78    /** @returns the default Font */
79    inline static Font* getDefaultFont() { if (Font::defaultFont == NULL) initDefaultFont(); return Font::defaultFont; };
80
81    void createAsciiImage(const std::string& fileName, unsigned int size) const;
82    static void initDefaultFont();
83    static void removeDefaultFont();
84
85  private:
86    void init();
87    bool getGlyphMetrics(Glyph* glyph, Uint16 character);
88
89    bool createFastTexture();
90
91    void initGlyphs(Uint16 from, Uint16 count);
92    int findOptimalFastTextureSize();
93
94    void debug();
95
96  private:
97    static Font*  defaultFont;         //!< a default font, that is used, if other fonts were unable to be loaded.
98    // information about the Font
99    TTF_Font*     fontTTF;             //!< The font we use for this.
100    int           renderStyle;         //!< The Renderstyle
101    unsigned int  renderSize;          //!< How big the Font should be rendered.
102
103    Glyph**       glyphArray;          //!< An Array of all the Glyphs stored in the Array of Glyphs.
104};
105
106#endif /* _FONT_H */
Note: See TracBrowser for help on using the repository browser.