Changeset 8765 in orxonox.OLD for trunk/src/lib/graphics/text_engine/font_data.cc
- Timestamp:
- Jun 24, 2006, 3:49:33 AM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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
Note: See TracChangeset
for help on using the changeset viewer.