Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

trunk: font: cleaner draw() of Texts

File size: 3.1 KB
RevLine 
[3341]1/*!
[8751]2 * @file font_data.h
3 * @brief Contains the font-data class, that handles the reading of Images into Texutre-files.
[5768]4 */
[3341]5
[8751]6#ifndef _FONT_DATA_H
7#define _FONT_DATA_H
[3341]8
[5304]9#include "base_object.h"
[3548]10
[5768]11#include "glincl.h"
[8751]12#include "texture_data.h"
[3548]13
[8751]14#ifdef HAVE_SDL_TTF_H
15#include <SDL_ttf.h>
16#else
17#include <SDL/SDL_ttf.h>
18#endif
[5239]19
[7785]20
[8751]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
[7785]33{
[8751]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
[7785]45
[8751]46  GLfloat texCoord[4];        //!< Texture coordinates: 0:left, 1:right, 2: top, 3: bottom.
47};
[7785]48
49
[8761]50class FontData
[8751]51{
52public:
[8766]53  FontData();
[8751]54  ~FontData();
[7785]55
[8764]56  /// LOADING new Fonts
57  bool loadFontFromTTF(const std::string& fontFile, unsigned int renderSize);
58  bool loadFontFromSDL_Surface(SDL_Surface* surface);
59
[8765]60  void setStyle(TTF_Font* font, const std::string& renderStyle);
[8764]61
[8751]62  /** @returns a Pointer to the Array of Glyphs */
63  inline Glyph** getGlyphArray() const { return this->glyphArray; };
64
[8765]65  int getMaxHeight() const { return maxHeight; };
66  int getMaxAscent() const { return maxAscent; };
67  int getMaxDescent() const { return maxDescent; };
[8764]68
[8766]69  /** @returns the Texture-Data of this FontData */
70  const TextureDataPointer& textureData() const { return texData; };
[8764]71
[8768]72  bool rebuild() { return texData->rebuild(); };
[8751]73
74private:
[8765]75  void initGlyphs(TTF_Font* font, Uint16 from, Uint16 count);
76  bool getGlyphMetrics(TTF_Font* font, Glyph* glyph, Uint16 character);
[8764]77
78  int findOptimalFastTextureSize();
[8765]79  bool createFastTexture(TTF_Font* font);
[8764]80
[8766]81
[8761]82private:
[8765]83  std::string   fontFile;            //!< The FileName the Font was loaded from.
[8751]84  int           renderStyle;         //!< The Renderstyle
85  unsigned int  renderSize;          //!< How big the Font should be rendered.
86
87  Glyph**       glyphArray;          //!< An Array of all the Glyphs stored in the Array of Glyphs.
[8761]88
[8765]89  int           maxHeight;           //!< Max Height of the Font.
90  int           maxAscent;           //!< Max Ascent of the Font.
91  int           maxDescent;          //!< Max Desent of the Font.
92
[8761]93  TextureDataPointer   texData;
[7785]94};
95
[8761]96typedef CountPointer<FontData> FontDataPointer;
[8751]97
98#endif /* _FONT_DATA_H */
Note: See TracBrowser for help on using the repository browser.