Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/graphics/text_engine/font_data.h @ 8764

Last change on this file since 8764 was 8764, checked in by bensch, 18 years ago

load-implementation of font in font-data

File size: 2.7 KB
Line 
1/*!
2 * @file font_data.h
3 * @brief Contains the font-data class, that handles the reading of Images into Texutre-files.
4 */
5
6#ifndef _FONT_DATA_H
7#define _FONT_DATA_H
8
9#include "base_object.h"
10
11#include "glincl.h"
12#include "texture_data.h"
13
14#ifdef HAVE_SDL_TTF_H
15#include <SDL_ttf.h>
16#else
17#include <SDL/SDL_ttf.h>
18#endif
19
20
21
22/* some default values */
23#define FONT_NUM_COLORS              256           //!< number of colors.
24
25#define FONT_HIGHEST_KNOWN_CHAR      128           //!< The highest character known to the textEngine.
26#define FONT_DEFAULT_RENDER_SIZE     50            //!< At what Resolution to render fonts.
27
28//! A struct for handling glyphs
29/**
30 * a Glyph is one letter of a certain font
31 */
32struct Glyph
33{
34  // Glyph-specific (size and so on)
35  Uint16   character;         //!< The character
36  float    minX;              //!< The minimum distance from the origin in X
37  float    maxX;              //!< The maximum distance from the origin in X
38  float    minY;              //!< The minimum distance from the origin in Y
39  float    maxY;              //!< The maximum distance from the origin in Y
40  float    width;             //!< The width of the Glyph
41  float    height;            //!< The height of the Glyph
42  float    bearingX;          //!< How much is right of the Origin
43  float    bearingY;          //!< How much is above the Origin
44  float    advance;           //!< How big a Glyph would be in monospace-mode
45
46  GLfloat texCoord[4];        //!< Texture coordinates: 0:left, 1:right, 2: top, 3: bottom.
47};
48
49
50class FontData
51{
52  friend class Font;
53public:
54  ~FontData();
55
56
57  /// LOADING new Fonts
58  bool loadFontFromTTF(const std::string& fontFile, unsigned int renderSize);
59  bool loadFontFromSDL_Surface(SDL_Surface* surface);
60
61  void setStyle(const std::string& renderStyle);
62
63
64
65  /** @returns a Pointer to the Array of Glyphs */
66  inline Glyph** getGlyphArray() const { return this->glyphArray; };
67  /** @returns the a pointer to the TTF */
68  inline TTF_Font* getTTF() const { return this->fontTTF; };
69
70  int getMaxHeight() const;
71  int getMaxAscent() const;
72  int getMaxDescent() const;
73
74
75  bool rebuild();
76
77
78
79
80
81private:
82  FontData();
83
84  void initGlyphs(Uint16 from, Uint16 count);
85  bool getGlyphMetrics(Glyph* glyph, Uint16 character);
86
87  int findOptimalFastTextureSize();
88  bool createFastTexture();
89
90private:
91  TTF_Font*     fontTTF;             //!< The font we use for this.
92  int           renderStyle;         //!< The Renderstyle
93  unsigned int  renderSize;          //!< How big the Font should be rendered.
94
95  Glyph**       glyphArray;          //!< An Array of all the Glyphs stored in the Array of Glyphs.
96
97  TextureDataPointer   texData;
98};
99
100typedef CountPointer<FontData> FontDataPointer;
101
102#endif /* _FONT_DATA_H */
Note: See TracBrowser for help on using the repository browser.