- Timestamp:
- Jun 24, 2006, 3:49:33 AM (18 years ago)
- Location:
- trunk/src/lib/graphics/text_engine
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/graphics/text_engine/font.cc
r8764 r8765 192 192 void Font::setStyle(const std::string& renderStyle) 193 193 { 194 this->data->setStyle(renderStyle); 194 /// FIXME 195 //this->data->setStyle(renderStyle); 195 196 } 196 197 … … 207 208 * @param fileName the File to write the image into. 208 209 */ 209 void Font::createAsciiImage(const std::string& fileName, unsigned int size) const 210 { 211 if (this->data->fontTTF == NULL) 210 void Font::createAsciiImage(const std::string& ttfFile, const std::string& fileName, unsigned int size) 211 { 212 TTF_Font* fontTTF = TTF_OpenFont(ttfFile.c_str(), size); 213 214 if (fontTTF == NULL) 212 215 return; 213 int height = this->getMaxHeight();216 int height = TTF_FontHeight(fontTTF); 214 217 215 218 // … … 241 244 { 242 245 SDL_Surface* glyphSurf = NULL; 243 if (likely(this->data->fontTTF != NULL)) 244 { 245 SDL_Color white = {255, 255, 255}; 246 glyphSurf = TTF_RenderGlyph_Blended(this->data->fontTTF, posX+size*posY, white); 247 } 246 SDL_Color white = {255, 255, 255}; 247 glyphSurf = TTF_RenderGlyph_Blended(fontTTF, posX+size*posY, white); 248 248 249 if( glyphSurf != NULL ) 249 250 { … … 259 260 SDL_SaveBMP(tmpSurf, fileName.c_str()); 260 261 SDL_FreeSurface(tmpSurf); 262 263 TTF_CloseFont(fontTTF); 261 264 } 262 265 … … 273 276 PRINT(0)("TEST %p and %p\n", this->data.get(), this->data->texData.get()); 274 277 // print the loaded font's style 275 int style = TTF_STYLE_NORMAL;278 /* int style = TTF_STYLE_NORMAL; 276 279 if (likely(this->data->fontTTF != NULL)) 277 280 style = TTF_GetFontStyle(this->data->fontTTF); … … 286 289 PRINTF(0)(" italic"); 287 290 if(style&TTF_STYLE_UNDERLINE) 288 PRINTF(0)(" underline"); 289 }291 PRINTF(0)(" underline");*/ 292 // } 290 293 PRINTF(0)("\n"); 291 294 } -
trunk/src/lib/graphics/text_engine/font.h
r8764 r8765 40 40 /** @returns a Pointer to the Array of Glyphs */ 41 41 inline Glyph** getGlyphArray() const { return this->data->getGlyphArray(); }; 42 /** @returns the a pointer to the TTF */43 inline TTF_Font* getTTF() const { return this->data->getTTF(); };44 42 45 43 inline int getMaxHeight() const { return data->getMaxHeight(); }; … … 48 46 49 47 50 void createAsciiImage(const std::string& fileName, unsigned int size) const;48 static void createAsciiImage(const std::string& ttfFile, const std::string& fileName, unsigned int size); 51 49 52 50 void debug() const; -
trunk/src/lib/graphics/text_engine/font_data.cc
r8764 r8765 28 28 */ 29 29 FontData::FontData() 30 : texData(new TextureData) 31 { 32 printf("CREATE FONT_DATA\n"); 33 this->fontTTF = NULL; 30 : texData(new TextureData) 31 { 34 32 this->glyphArray = NULL; 35 33 this->renderStyle = TTF_STYLE_NORMAL; 36 34 this->renderSize = FONT_DEFAULT_RENDER_SIZE; 35 36 this->maxHeight = 0; 37 this->maxAscent = 0; 38 this->maxDescent = 0; 37 39 } 38 40 … … 60 62 // if(glIsTexture(this->fastTextureID)) 61 63 // glDeleteTextures(1, &this->fastTextureID); 62 63 // erease this font out of the memory. 64 if (likely(this->fontTTF != NULL)) 65 TTF_CloseFont(this->fontTTF); 66 } 67 68 /** 69 * @returns the maximum height of the Font, if the font was initialized, 0 otherwise 70 */ 71 int FontData::getMaxHeight() const 72 { 73 if (likely (this->fontTTF != NULL)) 74 return TTF_FontHeight(this->fontTTF); 75 else 76 return 1; 77 } 78 79 /** 80 * @returns the maximum ascent of the Font, if the font was initialized, 0 otherwise 81 * 82 * the ascent is the pixels of the font above the baseline 83 */ 84 int FontData::getMaxAscent() const 85 { 86 if (likely(this->fontTTF != NULL)) 87 return TTF_FontAscent(this->fontTTF); 88 else 89 return 0; 90 } 91 92 /** 93 * @returns the maximum descent of the Font, if the font was initialized, 0 otherwise 94 * 95 * the descent is the pixels of the font below the baseline 96 */ 97 int FontData::getMaxDescent() const 98 { 99 if (likely(this->fontTTF != NULL)) 100 return TTF_FontDescent(this->fontTTF); 101 else 102 return 0; 103 } 104 64 } 105 65 106 66 … … 112 72 bool FontData::loadFontFromTTF(const std::string& fontFile, unsigned int renderSize) 113 73 { 74 TTF_Font* fontTTF; 114 75 //this->setName(fontFile); 115 this->fontTTF = TTF_OpenFont(fontFile.c_str(), renderSize);76 fontTTF = TTF_OpenFont(fontFile.c_str(), renderSize); 116 77 this->renderSize = renderSize; 117 78 118 if(this->fontTTF != NULL) 119 { 120 this->setStyle("c"); 121 if (this->createFastTexture()) 79 if(fontTTF != NULL) 80 { 81 this->maxHeight = TTF_FontHeight(fontTTF); 82 this->maxAscent = TTF_FontAscent(fontTTF); 83 this->maxDescent = TTF_FontDescent(fontTTF); 84 85 this->setStyle(fontTTF, "c"); 86 if (this->createFastTexture(fontTTF)) 87 { 88 TTF_CloseFont(fontTTF); 122 89 return true; 90 } 91 123 92 else 124 93 { 94 TTF_CloseFont(fontTTF); 95 PRINTF(1)("Unable to createa a Fast Texture fot %s\n", fontFile.c_str() ); 125 96 return false; 126 97 } … … 128 99 else 129 100 { 130 PRINTF(1)("TTF_OpenFont: %s \n", TTF_GetError());101 PRINTF(1)("TTF_OpenFont: %s for %s\n", TTF_GetError(), fontFile.c_str()); 131 102 return false; 132 103 } … … 194 165 * i: italic, b: bold, u, underline 195 166 */ 196 void FontData::setStyle( const std::string& renderStyle)167 void FontData::setStyle(TTF_Font* font, const std::string& renderStyle) 197 168 { 198 169 this->renderStyle = TTF_STYLE_NORMAL; … … 207 178 this->renderStyle |= TTF_STYLE_UNDERLINE; 208 179 } 209 if (likely(this->fontTTF != NULL)) 210 TTF_SetFontStyle(this->fontTTF, this->renderStyle); 180 181 /// !TODO REBUILD THE FONT 182 183 if (likely(font != NULL)) 184 TTF_SetFontStyle(font, this->renderStyle); 211 185 // else 212 186 // PRINTF(2)("Font was not initialized, please do so before setting the Font-Style.\n"); … … 225 199 * for more info about vertical Fonts 226 200 */ 227 bool FontData::getGlyphMetrics( Glyph* glyph, Uint16 character)201 bool FontData::getGlyphMetrics(TTF_Font* font, Glyph* glyph, Uint16 character) 228 202 { 229 203 glyph->character = character; 230 if (likely ( this->fontTTF!= NULL))204 if (likely (font != NULL)) 231 205 { 232 206 int miX, maX, miY, maY, adv; 233 if (TTF_GlyphMetrics( this->fontTTF, glyph->character,234 &miX, &maX,235 &miY, &maY,236 &adv) == -1)207 if (TTF_GlyphMetrics(font, glyph->character, 208 &miX, &maX, 209 &miY, &maY, 210 &adv) == -1) 237 211 return false; 238 212 glyph->minX = (float)miX / (float)this->renderSize; … … 259 233 * @brief creates a Fast-Texture of this Font 260 234 */ 261 bool FontData::createFastTexture( )235 bool FontData::createFastTexture(TTF_Font* fontTTF) 262 236 { 263 237 /* interesting GLYPHS: … … 271 245 int numberOfGlyphs = 91; 272 246 273 this->initGlyphs( 32, numberOfGlyphs);247 this->initGlyphs(fontTTF, 32, numberOfGlyphs); 274 248 // this->glyphArray[32]->width = .5f; //!< @todo find out the real size of a Space 275 249 … … 281 255 SDL_Rect tmpRect; // this represents a Rectangle for blitting. 282 256 SDL_Surface* tmpSurf = SDL_CreateRGBSurface(SDL_HWSURFACE, 283 284 257 rectSize, rectSize, 258 32, 285 259 #if SDL_BYTEORDER == SDL_LIL_ENDIAN /* OpenGL RGBA masks */ 286 260 0x000000FF, … … 289 263 0xFF000000 290 264 #else 291 265 0xFF000000, 292 266 0x00FF0000, 293 267 0x0000FF00, … … 321 295 } 322 296 // reading in the new Glyph 323 if (likely( this->fontTTF != NULL))297 if (likely(fontTTF != NULL)) 324 298 { 325 299 SDL_Color white = {255, 255, 255}; 326 glyphSurf = TTF_RenderGlyph_Blended( this->fontTTF, i, white);300 glyphSurf = TTF_RenderGlyph_Blended(fontTTF, i, white); 327 301 } 328 302 if( glyphSurf != NULL ) … … 344 318 } 345 319 // outputting the GLYPH-table 346 // char outName[1024];347 // sprintf( outName, "%s-glyphs.bmp", this->getName());348 // SDL_SaveBMP(tmpSurf, outName);320 // char outName[1024]; 321 // sprintf( outName, "%s-glyphs.bmp", this->getName()); 322 // SDL_SaveBMP(tmpSurf, outName); 349 323 this->texData->setAlpha(true); 350 324 if (this->texData->setSurface(tmpSurf)) … … 358 332 * @param count The number of Glyphs to start From. 359 333 */ 360 void FontData::initGlyphs( Uint16 from, Uint16 count)334 void FontData::initGlyphs(TTF_Font* font, Uint16 from, Uint16 count) 361 335 { 362 336 /* initialize the Array, and set all its entries to NULL … … 376 350 // setting up all the Glyphs we like. 377 351 Glyph* newGlyph = new Glyph; 378 if (getGlyphMetrics( newGlyph, i))352 if (getGlyphMetrics(font, newGlyph, i)) 379 353 this->glyphArray[i] = newGlyph; 380 354 else -
trunk/src/lib/graphics/text_engine/font_data.h
r8764 r8765 59 59 bool loadFontFromSDL_Surface(SDL_Surface* surface); 60 60 61 void setStyle( const std::string& renderStyle);61 void setStyle(TTF_Font* font, const std::string& renderStyle); 62 62 63 63 … … 65 65 /** @returns a Pointer to the Array of Glyphs */ 66 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 67 70 int getMaxHeight() const ;71 int getMaxAscent() const ;72 int getMaxDescent() const ;68 int getMaxHeight() const { return maxHeight; }; 69 int getMaxAscent() const { return maxAscent; }; 70 int getMaxDescent() const { return maxDescent; }; 73 71 74 72 … … 82 80 FontData(); 83 81 84 void initGlyphs( Uint16 from, Uint16 count);85 bool getGlyphMetrics( Glyph* glyph, Uint16 character);82 void initGlyphs(TTF_Font* font, Uint16 from, Uint16 count); 83 bool getGlyphMetrics(TTF_Font* font, Glyph* glyph, Uint16 character); 86 84 87 85 int findOptimalFastTextureSize(); 88 bool createFastTexture( );86 bool createFastTexture(TTF_Font* font); 89 87 90 88 private: 91 TTF_Font* fontTTF; //!< The font we use for this. 89 std::string fontFile; //!< The FileName the Font was loaded from. 90 92 91 int renderStyle; //!< The Renderstyle 93 92 unsigned int renderSize; //!< How big the Font should be rendered. 94 93 95 94 Glyph** glyphArray; //!< An Array of all the Glyphs stored in the Array of Glyphs. 95 96 int maxHeight; //!< Max Height of the Font. 97 int maxAscent; //!< Max Ascent of the Font. 98 int maxDescent; //!< Max Desent of the Font. 96 99 97 100 TextureDataPointer texData;
Note: See TracChangeset
for help on using the changeset viewer.