Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: merged the new_class_id branche back to the trunk.
merged with command:
svn merge https://svn.orxonox.net/orxonox/branches/new_class_id trunk -r9683:HEAD
no conflicts… puh..

File size: 3.1 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
28class FontData
29{
30
31
32public:
33
34//! A struct for handling glyphs
35/**
36 * a Glyph is one letter of a certain font
37 */
38  struct Glyph
39  {
40  // Glyph-specific (size and so on)
41    Uint16   character;         //!< The character
42    float    minX;              //!< The minimum distance from the origin in X
43    float    maxX;              //!< The maximum distance from the origin in X
44    float    minY;              //!< The minimum distance from the origin in Y
45    float    maxY;              //!< The maximum distance from the origin in Y
46    float    width;             //!< The width of the Glyph
47    float    height;            //!< The height of the Glyph
48    float    bearingX;          //!< How much is right of the Origin
49    float    bearingY;          //!< How much is above the Origin
50    float    advance;           //!< How big a Glyph would be in monospace-mode
51
52    GLfloat texCoord[4];        //!< Texture coordinates: 0:left, 1:right, 2: top, 3: bottom.
53  };
54
55  typedef CountPointer<FontData> Pointer;
56public:
57  FontData();
58  ~FontData();
59
60  /// LOADING new Fonts
61  bool loadFontFromTTF(const std::string& fontFile, unsigned int renderSize);
62  bool loadFontFromSDL_Surface(SDL_Surface* surface);
63
64  void setStyle(TTF_Font* font, const std::string& renderStyle);
65
66  /** @returns a Pointer to the Array of Glyphs */
67  inline const Glyph* const * const getGlyphArray() const { return this->glyphArray; };
68
69  int getMaxHeight() const { return maxHeight; };
70  int getMaxAscent() const { return maxAscent; };
71  int getMaxDescent() const { return maxDescent; };
72
73  /** @returns the Texture-Data of this FontData */
74  const TextureData::Pointer& textureData() const { return texData; };
75
76  bool rebuild() { return texData->rebuild(); };
77
78private:
79  void initGlyphs(TTF_Font* font, Uint16 from, Uint16 count);
80  bool getGlyphMetrics(TTF_Font* font, Glyph* glyph, Uint16 character);
81
82  int findOptimalFastTextureSize();
83  bool createFastTexture(TTF_Font* font);
84
85
86private:
87  std::string   fontFile;            //!< The FileName the Font was loaded from.
88  int           renderStyle;         //!< The Renderstyle
89  unsigned int  renderSize;          //!< How big the Font should be rendered.
90
91  Glyph**       glyphArray;          //!< An Array of all the Glyphs stored in the Array of Glyphs.
92
93  int           maxHeight;           //!< Max Height of the Font.
94  int           maxAscent;           //!< Max Ascent of the Font.
95  int           maxDescent;          //!< Max Desent of the Font.
96
97  TextureData::Pointer   texData;
98};
99
100#endif /* _FONT_DATA_H */
Note: See TracBrowser for help on using the repository browser.