Index: trunk/src/lib/graphics/text_engine/font.cc
===================================================================
--- trunk/src/lib/graphics/text_engine/font.cc	(revision 8619)
+++ trunk/src/lib/graphics/text_engine/font.cc	(revision 8751)
@@ -37,8 +37,10 @@
  */
 Font::Font(const std::string& fontFile, unsigned int renderSize)
+  : data(new FontData())
 {
   this->init();
 
-  this->renderSize = renderSize;
+
+  this->data->renderSize = renderSize;
   this->setStyle("c");
 
@@ -52,4 +54,5 @@
  */
 Font::Font(const std::string& imageFile)
+  : data(new FontData())
 {
   this->init();
@@ -75,4 +78,5 @@
  */
 Font::Font(char** xpmArray)
+  : data(new FontData())
 {
   this->init();
@@ -99,25 +103,5 @@
  */
 Font::~Font()
-{
-  // deleting all Glyphs
-  if (this->glyphArray != NULL)
-  {
-    for (int i = 0; i < FONT_HIGHEST_KNOWN_CHAR; i++)
-    {
-      if (this->glyphArray[i] != NULL)
-        delete this->glyphArray[i];
-    }
-    delete[] this->glyphArray;
-  }
-
-  //! @todo check if we really do not need to delete the fastTextureID here.
-  //   if (this->fastTextureID != 0)
-  //     if(glIsTexture(this->fastTextureID))
-  //       glDeleteTextures(1, &this->fastTextureID);
-
-  // erease this font out of the memory.
-  if (likely(this->fontTTF != NULL))
-    TTF_CloseFont(this->fontTTF);
-}
+{ }
 
 /**
@@ -127,12 +111,9 @@
 {
   this->setClassID(CL_FONT, "Font");
-  // setting default values.
-  this->fontTTF = NULL;
-  this->glyphArray = NULL;
-}
-
-
-/**
- * sets The Font.
+}
+
+
+/**
+ * @brief sets The Font.
  * @param fontFile The file containing the font.
  * @returns true if loaded, false if something went wrong, or if a font was loaded before.
@@ -141,15 +122,15 @@
 {
   // checking for existent Font.
-  if (this->fontTTF != NULL)
-  {
-    TTF_CloseFont(this->fontTTF);
-    this->fontTTF = NULL;
+  if (this->data->fontTTF != NULL)
+  {
+    TTF_CloseFont(this->data->fontTTF);
+    this->data->fontTTF = NULL;
   }
 
 
   this->setName(fontFile);
-  this->fontTTF = TTF_OpenFont(this->getName(), this->renderSize);
-
-  if(this->fontTTF != NULL)
+  this->data->fontTTF = TTF_OpenFont(this->getName(), this->data->renderSize);
+
+  if(this->data->fontTTF != NULL)
   {
     this->createFastTexture();
@@ -174,8 +155,8 @@
     return false;
 
-  if (this->fontTTF != NULL)
-  {
-    TTF_CloseFont(this->fontTTF);
-    this->fontTTF = NULL;
+  if (this->data->fontTTF != NULL)
+  {
+    TTF_CloseFont(this->data->fontTTF);
+    this->data->fontTTF = NULL;
   }
   bool hasAlpha;
@@ -189,12 +170,12 @@
 
   // initializing the Glyphs.
-  if (this->glyphArray == NULL)
+  if (this->data->glyphArray == NULL)
   {
     float cx,cy;
     Glyph* tmpGlyph;
-    this->glyphArray = new Glyph*[FONT_HIGHEST_KNOWN_CHAR];
+    this->data->glyphArray = new Glyph*[FONT_HIGHEST_KNOWN_CHAR];
     for (int i = 0; i < FONT_HIGHEST_KNOWN_CHAR; i++)
     {
-      tmpGlyph = this->glyphArray[i] = new Glyph;
+      tmpGlyph = this->data->glyphArray[i] = new Glyph;
       cx=(float)(i%16)/16.0f;                  // X Position Of Current Character
       cy=(float)(i/16)/16.0f;                  // Y Position Of Current Character
@@ -220,23 +201,23 @@
 
 /**
- * @brief sets a specific renderStyle
- * @param renderStyle the Style to render: a string (char-array) containing:
+ * @brief sets a specific data->renderStyle
+ * @param data->renderStyle the Style to render: a string (char-array) containing:
  *   i: italic, b: bold, u, underline
  */
 void Font::setStyle(const std::string& renderStyle)
 {
-  this->renderStyle = TTF_STYLE_NORMAL;
+  this->data->renderStyle = TTF_STYLE_NORMAL;
 
   for (unsigned int i = 0; i < renderStyle.size(); i++)
   {
     if (renderStyle[i] == 'b')
-      this->renderStyle |= TTF_STYLE_BOLD;
+      this->data->renderStyle |= TTF_STYLE_BOLD;
     else if (renderStyle[i] == 'i')
-      this->renderStyle |= TTF_STYLE_ITALIC;
+      this->data->renderStyle |= TTF_STYLE_ITALIC;
     else if (renderStyle[i] == 'u')
-      this->renderStyle |= TTF_STYLE_UNDERLINE;
-  }
-  if (likely(this->fontTTF != NULL))
-    TTF_SetFontStyle(this->fontTTF, this->renderStyle);
+      this->data->renderStyle |= TTF_STYLE_UNDERLINE;
+  }
+  if (likely(this->data->fontTTF != NULL))
+    TTF_SetFontStyle(this->data->fontTTF, this->data->renderStyle);
   //  else
   //    PRINTF(2)("Font was not initialized, please do so before setting the Font-Style.\n");
@@ -252,5 +233,5 @@
 void Font::createAsciiImage(const std::string& fileName, unsigned int size) const
 {
-  if (this->fontTTF == NULL)
+  if (this->data->fontTTF == NULL)
     return;
   int height = this->getMaxHeight();
@@ -284,8 +265,8 @@
     {
       SDL_Surface* glyphSurf = NULL;
-      if (likely(this->fontTTF != NULL))
+      if (likely(this->data->fontTTF != NULL))
       {
         SDL_Color white = {255, 255, 255};
-        glyphSurf = TTF_RenderGlyph_Blended(this->fontTTF, posX+size*posY, white);
+        glyphSurf = TTF_RenderGlyph_Blended(this->data->fontTTF, posX+size*posY, white);
       }
       if( glyphSurf != NULL )
@@ -329,6 +310,6 @@
 int Font::getMaxHeight() const
 {
-  if (likely (this->fontTTF != NULL))
-    return TTF_FontHeight(this->fontTTF);
+  if (likely (this->data->fontTTF != NULL))
+    return TTF_FontHeight(this->data->fontTTF);
   else
     return 1;
@@ -342,6 +323,6 @@
 int Font::getMaxAscent() const
 {
-  if (likely(this->fontTTF != NULL))
-    return TTF_FontAscent(this->fontTTF);
+  if (likely(this->data->fontTTF != NULL))
+    return TTF_FontAscent(this->data->fontTTF);
   else
     return 0;
@@ -355,6 +336,6 @@
 int Font::getMaxDescent() const
 {
-  if (likely(this->fontTTF != NULL))
-    return TTF_FontDescent(this->fontTTF);
+  if (likely(this->data->fontTTF != NULL))
+    return TTF_FontDescent(this->data->fontTTF);
   else
     return 0;
@@ -374,17 +355,17 @@
 {
   glyph->character = character;
-  if (likely (this->fontTTF!= NULL))
+  if (likely (this->data->fontTTF!= NULL))
   {
     int miX, maX, miY, maY, adv;
-    if (TTF_GlyphMetrics(this->fontTTF, glyph->character,
+    if (TTF_GlyphMetrics(this->data->fontTTF, glyph->character,
                      &miX, &maX,
                      &miY, &maY,
                      &adv) == -1)
       return false;
-    glyph->minX = (float)miX / (float)this->renderSize;
-    glyph->maxX = (float)maX / (float)this->renderSize;
-    glyph->minY = (float)miY / (float)this->renderSize;
-    glyph->maxY = (float)maY / (float)this->renderSize;
-    glyph->advance = (float)adv / (float)this->renderSize;
+    glyph->minX = (float)miX / (float)this->data->renderSize;
+    glyph->maxX = (float)maX / (float)this->data->renderSize;
+    glyph->minY = (float)miY / (float)this->data->renderSize;
+    glyph->maxY = (float)maY / (float)this->data->renderSize;
+    glyph->advance = (float)adv / (float)this->data->renderSize;
 
     // Calculate the Rest.
@@ -417,5 +398,5 @@
 
   this->initGlyphs(32, numberOfGlyphs);
-  //  this->glyphArray[32]->width = .5f; //!< @todo find out the real size of a Space
+  //  this->data->glyphArray[32]->width = .5f; //!< @todo find out the real size of a Space
 
   int rectSize = this->findOptimalFastTextureSize();
@@ -450,10 +431,10 @@
     Glyph* tmpGlyph;
 
-    if (tmpGlyph = this->glyphArray[i])
+    if (tmpGlyph = this->data->glyphArray[i])
     {
-      if (tmpGlyph->height*this->renderSize > maxLineHeight)
-        maxLineHeight = (int)(tmpGlyph->height*this->renderSize);
-
-      if (tmpRect.x+tmpGlyph->advance*this->renderSize > tmpSurf->w)
+      if (tmpGlyph->height*this->data->renderSize > maxLineHeight)
+        maxLineHeight = (int)(tmpGlyph->height*this->data->renderSize);
+
+      if (tmpRect.x+tmpGlyph->advance*this->data->renderSize > tmpSurf->w)
       {
         tmpRect.x = 0;
@@ -466,8 +447,8 @@
       }
       // reading in the new Glyph
-      if (likely(this->fontTTF != NULL))
+      if (likely(this->data->fontTTF != NULL))
       {
         SDL_Color white = {255, 255, 255};
-        glyphSurf = TTF_RenderGlyph_Blended(this->fontTTF, i, white);
+        glyphSurf = TTF_RenderGlyph_Blended(this->data->fontTTF, i, white);
       }
       if( glyphSurf != NULL )
@@ -475,14 +456,14 @@
         SDL_SetAlpha(glyphSurf, 0, 0);
         int tmpY = tmpRect.y;
-        tmpRect.y += this->getMaxAscent()-(int)((float)tmpGlyph->bearingY*this->renderSize);
+        tmpRect.y += this->getMaxAscent()-(int)((float)tmpGlyph->bearingY*this->data->renderSize);
         SDL_BlitSurface(glyphSurf, NULL, tmpSurf, &tmpRect);
         tmpRect.y = tmpY;
 
         tmpGlyph->texCoord[0] = (float)((float)tmpRect.x )/(float)tmpSurf->w;
-        tmpGlyph->texCoord[1] = (float)((float)tmpRect.x + tmpGlyph->width*(float)this->renderSize)/(float)tmpSurf->w;
+        tmpGlyph->texCoord[1] = (float)((float)tmpRect.x + tmpGlyph->width*(float)this->data->renderSize)/(float)tmpSurf->w;
         tmpGlyph->texCoord[2] = (float)(tmpRect.y)/(float)tmpSurf->w;
         tmpGlyph->texCoord[3] = (float)((float)tmpRect.y+(float)this->getMaxHeight())/(float)tmpSurf->w;
         SDL_FreeSurface(glyphSurf);
-        tmpRect.x += (int)(tmpGlyph->width * this->renderSize) + 1;
+        tmpRect.x += (int)(tmpGlyph->width * this->data->renderSize) + 1;
       }
     }
@@ -508,9 +489,9 @@
   *  only if the Glyph-array has not been initialized
   */
-  if (!this->glyphArray)
-  {
-    this->glyphArray = new Glyph*[FONT_HIGHEST_KNOWN_CHAR];
+  if (!this->data->glyphArray)
+  {
+    this->data->glyphArray = new Glyph*[FONT_HIGHEST_KNOWN_CHAR];
     for (int i = 0; i < FONT_HIGHEST_KNOWN_CHAR; i++)
-      this->glyphArray[i] = NULL;
+      this->data->glyphArray[i] = NULL;
   }
 
@@ -522,9 +503,9 @@
     Glyph* newGlyph = new Glyph;
     if (getGlyphMetrics(newGlyph, i))
-      glyphArray[i] = newGlyph;
+      data->glyphArray[i] = newGlyph;
     else
     {
       delete newGlyph;
-      glyphArray[i] = NULL;
+      data->glyphArray[i] = NULL;
     }
   }
@@ -543,5 +524,5 @@
 int Font::findOptimalFastTextureSize()
 {
-  if (this->glyphArray == NULL)
+  if (this->data->glyphArray == NULL)
     return 0;
 
@@ -558,11 +539,11 @@
     for (i = 0; i < FONT_HIGHEST_KNOWN_CHAR; i++)
     {
-      if((tmpGlyph = this->glyphArray[i]) != NULL)
+      if((tmpGlyph = this->data->glyphArray[i]) != NULL)
       {
         // getting the height of the highest Glyph in the Line.
-        if (tmpGlyph->height*this->renderSize > maxLineHeight)
-          maxLineHeight = (int)(tmpGlyph->height*this->renderSize);
-
-        if (x + tmpGlyph->advance*this->renderSize > size)
+        if (tmpGlyph->height*this->data->renderSize > maxLineHeight)
+          maxLineHeight = (int)(tmpGlyph->height*this->data->renderSize);
+
+        if (x + tmpGlyph->advance*this->data->renderSize > size)
         {
           x = 0;
@@ -572,5 +553,5 @@
         if (y + maxLineHeight + 1 > size)
           break;
-        x += (int)(tmpGlyph->advance*this->renderSize)+1;
+        x += (int)(tmpGlyph->advance*this->data->renderSize)+1;
 
       }
@@ -592,6 +573,6 @@
   // print the loaded font's style
   int style = TTF_STYLE_NORMAL;
-  if (likely(this->fontTTF != NULL))
-    style = TTF_GetFontStyle(this->fontTTF);
+  if (likely(this->data->fontTTF != NULL))
+    style = TTF_GetFontStyle(this->data->fontTTF);
   PRINTF(0)("The font style is:");
   if(style==TTF_STYLE_NORMAL)
Index: trunk/src/lib/graphics/text_engine/font.h
===================================================================
--- trunk/src/lib/graphics/text_engine/font.h	(revision 8619)
+++ trunk/src/lib/graphics/text_engine/font.h	(revision 8751)
@@ -13,40 +13,5 @@
 #include "texture.h"
 
-#include "glincl.h"
-
-
-#ifdef HAVE_SDL_TTF_H
-#include <SDL_ttf.h>
-#else
-#include <SDL/SDL_ttf.h>
-#endif
-
-/* some default values */
-#define FONT_NUM_COLORS              256           //!< number of colors.
-
-#define FONT_HIGHEST_KNOWN_CHAR      128           //!< The highest character known to the textEngine.
-#define FONT_DEFAULT_RENDER_SIZE     50            //!< At what Resolution to render fonts.
-// FORWARD DECLARATION
-
-//! A struct for handling glyphs
-/**
- * a Glyph is one letter of a certain font
- */
-struct Glyph
-{
-  // Glyph-specific (size and so on)
-  Uint16   character;         //!< The character
-  float    minX;              //!< The minimum distance from the origin in X
-  float    maxX;              //!< The maximum distance from the origin in X
-  float    minY;              //!< The minimum distance from the origin in Y
-  float    maxY;              //!< The maximum distance from the origin in Y
-  float    width;             //!< The width of the Glyph
-  float    height;            //!< The height of the Glyph
-  float    bearingX;          //!< How much is right of the Origin
-  float    bearingY;          //!< How much is above the Origin
-  float    advance;           //!< How big a Glyph would be in monospace-mode
-
-  GLfloat texCoord[4];        //!< Texture coordinates: 0:left, 1:right, 2: top, 3: bottom.
-};
+#include "font_data.h"
 
 
@@ -54,52 +19,50 @@
 class Font : public Texture
 {
-  public:
-    Font(const std::string& fontFile,
-         unsigned int renderSize);
-    Font(const std::string& imageFile);
-    Font(char** xpmArray);
-    virtual ~Font();
+
+public:
+  Font(const std::string& fontFile,
+       unsigned int renderSize);
+  Font(const std::string& imageFile);
+  Font(char** xpmArray);
+  virtual ~Font();
 
   //  font
-    bool loadFontFromTTF(const std::string& fontFile);
-    bool loadFontFromSDL_Surface(SDL_Surface* surface);
+  bool loadFontFromTTF(const std::string& fontFile);
+  bool loadFontFromSDL_Surface(SDL_Surface* surface);
 
-    void setStyle(const std::string& renderStyle);
+  void setStyle(const std::string& renderStyle);
 
-    /** @returns a Pointer to the Array of Glyphs */
-    inline Glyph** getGlyphArray() const { return this->glyphArray; };
-    /** @returns the a pointer to the TTF */
-    inline TTF_Font* getTTF() const { return this->fontTTF; };
+  /** @returns a Pointer to the Array of Glyphs */
+  inline Glyph** getGlyphArray() const { return this->data->getGlyphArray(); };
+  /** @returns the a pointer to the TTF */
+  inline TTF_Font* getTTF() const { return this->data->getTTF(); };
 
-    int getMaxHeight() const;
-    int getMaxAscent() const;
-    int getMaxDescent() const;
+  int getMaxHeight() const;
+  int getMaxAscent() const;
+  int getMaxDescent() const;
 
-    /** @returns the default Font */
-    inline static Font* getDefaultFont() { if (Font::defaultFont == NULL) initDefaultFont(); return Font::defaultFont; };
+  /** @returns the default Font */
+  inline static Font* getDefaultFont() { if (Font::defaultFont == NULL) initDefaultFont(); return Font::defaultFont; };
 
-    void createAsciiImage(const std::string& fileName, unsigned int size) const;
-    static void initDefaultFont();
-    static void removeDefaultFont();
+  void createAsciiImage(const std::string& fileName, unsigned int size) const;
+  static void initDefaultFont();
+  static void removeDefaultFont();
 
-  private:
-    void init();
-    bool getGlyphMetrics(Glyph* glyph, Uint16 character);
 
-    bool createFastTexture();
+private:
+  void init();
+  bool getGlyphMetrics(Glyph* glyph, Uint16 character);
 
-    void initGlyphs(Uint16 from, Uint16 count);
-    int findOptimalFastTextureSize();
+  bool createFastTexture();
 
-    void debug();
+  void initGlyphs(Uint16 from, Uint16 count);
+  int findOptimalFastTextureSize();
 
-  private:
-    static Font*  defaultFont;         //!< a default font, that is used, if other fonts were unable to be loaded.
-    // information about the Font
-    TTF_Font*     fontTTF;             //!< The font we use for this.
-    int           renderStyle;         //!< The Renderstyle
-    unsigned int  renderSize;          //!< How big the Font should be rendered.
+  void debug();
 
-    Glyph**       glyphArray;          //!< An Array of all the Glyphs stored in the Array of Glyphs.
+private:
+  static Font*  defaultFont;         //!< a default font, that is used, if other fonts were unable to be loaded.
+
+  fontDataPointer data;
 };
 
Index: trunk/src/lib/graphics/text_engine/font_data.cc
===================================================================
--- trunk/src/lib/graphics/text_engine/font_data.cc	(revision 8751)
+++ trunk/src/lib/graphics/text_engine/font_data.cc	(revision 8751)
@@ -0,0 +1,63 @@
+/*
+   orxonox - the future of 3D-vertical-scrollers
+
+   Copyright (C) 2004 orx
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   ### File Specific:
+   main-programmer: Benjamin Grauer
+   co-programmer: ...
+*/
+
+#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_IMPORTER
+
+#include "font_data.h"
+
+#include "debug.h"
+#include "compiler.h"
+
+#include "sdlincl.h"
+
+/**
+ * @brief creates a new Font Data.
+ */
+FontData::FontData()
+{
+  this->fontTTF = NULL;
+  this->glyphArray = NULL;
+}
+
+
+/**
+ * @brief Destructor of a Font
+ *
+ *  Frees Data, and deletes the fonts from GL
+ */
+FontData::~FontData()
+{
+  // deleting all Glyphs
+  if (this->glyphArray != NULL)
+  {
+    for (int i = 0; i < FONT_HIGHEST_KNOWN_CHAR; i++)
+    {
+      if (this->glyphArray[i] != NULL)
+        delete this->glyphArray[i];
+    }
+    delete[] this->glyphArray;
+  }
+
+  //! @todo check if we really do not need to delete the fastTextureID here.
+  //   if (this->fastTextureID != 0)
+  //     if(glIsTexture(this->fastTextureID))
+  //       glDeleteTextures(1, &this->fastTextureID);
+
+  // erease this font out of the memory.
+  if (likely(this->fontTTF != NULL))
+    TTF_CloseFont(this->fontTTF);
+}
+
+
Index: trunk/src/lib/graphics/text_engine/font_data.h
===================================================================
--- trunk/src/lib/graphics/text_engine/font_data.h	(revision 8751)
+++ trunk/src/lib/graphics/text_engine/font_data.h	(revision 8751)
@@ -0,0 +1,76 @@
+/*!
+ * @file font_data.h
+ * @brief Contains the font-data class, that handles the reading of Images into Texutre-files.
+ */
+
+#ifndef _FONT_DATA_H
+#define _FONT_DATA_H
+
+#include "base_object.h"
+
+#include "glincl.h"
+#include "texture_data.h"
+
+#ifdef HAVE_SDL_TTF_H
+#include <SDL_ttf.h>
+#else
+#include <SDL/SDL_ttf.h>
+#endif
+
+
+
+/* some default values */
+#define FONT_NUM_COLORS              256           //!< number of colors.
+
+#define FONT_HIGHEST_KNOWN_CHAR      128           //!< The highest character known to the textEngine.
+#define FONT_DEFAULT_RENDER_SIZE     50            //!< At what Resolution to render fonts.
+
+//! A struct for handling glyphs
+/**
+ * a Glyph is one letter of a certain font
+ */
+struct Glyph
+{
+  // Glyph-specific (size and so on)
+  Uint16   character;         //!< The character
+  float    minX;              //!< The minimum distance from the origin in X
+  float    maxX;              //!< The maximum distance from the origin in X
+  float    minY;              //!< The minimum distance from the origin in Y
+  float    maxY;              //!< The maximum distance from the origin in Y
+  float    width;             //!< The width of the Glyph
+  float    height;            //!< The height of the Glyph
+  float    bearingX;          //!< How much is right of the Origin
+  float    bearingY;          //!< How much is above the Origin
+  float    advance;           //!< How big a Glyph would be in monospace-mode
+
+  GLfloat texCoord[4];        //!< Texture coordinates: 0:left, 1:right, 2: top, 3: bottom.
+};
+
+
+class FontData : public TextureData
+{
+  friend class Font;
+public:
+  FontData();
+  ~FontData();
+
+
+  /** @returns a Pointer to the Array of Glyphs */
+  inline Glyph** getGlyphArray() const { return this->glyphArray; };
+  /** @returns the a pointer to the TTF */
+  inline TTF_Font* getTTF() const { return this->fontTTF; };
+
+  bool rebuild();
+
+
+private:
+  TTF_Font*     fontTTF;             //!< The font we use for this.
+  int           renderStyle;         //!< The Renderstyle
+  unsigned int  renderSize;          //!< How big the Font should be rendered.
+
+  Glyph**       glyphArray;          //!< An Array of all the Glyphs stored in the Array of Glyphs.
+};
+
+typedef CountPointer<FontData> fontDataPointer;
+
+#endif /* _FONT_DATA_H */
