Changeset 7203 in orxonox.OLD for branches/std/src/lib/graphics/text_engine/font.cc
- Timestamp:
- Mar 9, 2006, 5:28:10 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/std/src/lib/graphics/text_engine/font.cc
r6609 r7203 37 37 * @param fontSize the Size of the Font in Pixels 38 38 */ 39 Font::Font(const char*fontFile, unsigned int renderSize)39 Font::Font(const std::string& fontFile, unsigned int renderSize) 40 40 { 41 41 this->init(); … … 44 44 this->setStyle("c"); 45 45 46 if ( fontFile != NULL)46 if (!fontFile.empty()) 47 47 this->loadFontFromTTF(fontFile); 48 48 } … … 52 52 * @param imageFile the ImageFile to load the Font From. 53 53 */ 54 Font::Font(const char*imageFile)54 Font::Font(const std::string& imageFile) 55 55 { 56 56 this->init(); … … 58 58 // this->setSize(fontSize); 59 59 SDL_Surface* image = NULL; 60 if ( imageFile != NULL)61 image = IMG_Load(imageFile );60 if (!imageFile.empty()) 61 image = IMG_Load(imageFile.c_str()); 62 62 else 63 63 return; … … 68 68 } 69 69 else 70 PRINTF(1)("loading from surface %s failed: %s\n", imageFile , IMG_GetError());70 PRINTF(1)("loading from surface %s failed: %s\n", imageFile.c_str(), IMG_GetError()); 71 71 } 72 72 … … 114 114 115 115 //! @todo check if we really do not need to delete the fastTextureID here. 116 // if (this->fastTextureID != 0)117 // if(glIsTexture(this->fastTextureID))118 // glDeleteTextures(1, &this->fastTextureID);116 // if (this->fastTextureID != 0) 117 // if(glIsTexture(this->fastTextureID)) 118 // glDeleteTextures(1, &this->fastTextureID); 119 119 120 120 // erease this font out of the memory. … … 140 140 * @returns true if loaded, false if something went wrong, or if a font was loaded before. 141 141 */ 142 bool Font::loadFontFromTTF(const char*fontFile)142 bool Font::loadFontFromTTF(const std::string& fontFile) 143 143 { 144 144 // checking for existent Font. … … 222 222 * i: italic, b: bold, u, underline 223 223 */ 224 void Font::setStyle(const char*renderStyle)224 void Font::setStyle(const std::string& renderStyle) 225 225 { 226 226 this->renderStyle = TTF_STYLE_NORMAL; 227 227 228 for (int i = 0; i < strlen(renderStyle); i++) 229 if (strncmp(renderStyle+i, "b", 1) == 0) 228 for (int i = 0; i < renderStyle.size(); i++) 229 { 230 if (renderStyle[i] == 'b') 230 231 this->renderStyle |= TTF_STYLE_BOLD; 231 else if (strncmp(renderStyle+i, "i", 1) == 0)232 this->renderStyle |= TTF_STYLE_ITALIC;233 else if (strncmp(renderStyle+i, "u", 1) == 0)234 this->renderStyle |= TTF_STYLE_UNDERLINE;235 232 else if (renderStyle[i] == 'i') 233 this->renderStyle |= TTF_STYLE_ITALIC; 234 else if (renderStyle[i] == 'u') 235 this->renderStyle |= TTF_STYLE_UNDERLINE; 236 } 236 237 if (likely(this->fontTTF != NULL)) 237 238 TTF_SetFontStyle(this->fontTTF, this->renderStyle); 238 // else239 // PRINTF(2)("Font was not initialized, please do so before setting the Font-Style.\n");239 // else 240 // PRINTF(2)("Font was not initialized, please do so before setting the Font-Style.\n"); 240 241 } 241 242 … … 247 248 * @param fileName the File to write the image into. 248 249 */ 249 void Font::createAsciiImage(const char*fileName, unsigned int size) const250 void Font::createAsciiImage(const std::string& fileName, unsigned int size) const 250 251 { 251 252 if (this->fontTTF == NULL) … … 258 259 SDL_Rect tmpRect; // this represents a Rectangle for blitting. 259 260 SDL_Surface* tmpSurf = SDL_CreateRGBSurface(SDL_SWSURFACE, 260 261 261 height*size, height*size, 262 32, 262 263 #if SDL_BYTEORDER == SDL_LIL_ENDIAN /* OpenGL RGBA masks */ 263 264 265 266 264 0x000000FF, 265 0x0000FF00, 266 0x00FF0000, 267 0xFF000000 267 268 #else 268 269 270 271 269 0xFF000000, 270 0x00FF0000, 271 0x0000FF00, 272 0x000000FF 272 273 #endif 273 274 ); … … 299 300 } 300 301 } 301 SDL_SaveBMP(tmpSurf, fileName );302 SDL_SaveBMP(tmpSurf, fileName.c_str()); 302 303 SDL_FreeSurface(tmpSurf); 303 304 } … … 409 410 410 411 this->initGlyphs(32, numberOfGlyphs); 411 // this->glyphArray[32]->width = .5f; //!< @todo find out the real size of a Space412 // this->glyphArray[32]->width = .5f; //!< @todo find out the real size of a Space 412 413 413 414 int rectSize = this->findOptimalFastTextureSize(); … … 418 419 SDL_Rect tmpRect; // this represents a Rectangle for blitting. 419 420 SDL_Surface* tmpSurf = SDL_CreateRGBSurface(SDL_SWSURFACE, 420 421 421 rectSize, rectSize, 422 32, 422 423 #if SDL_BYTEORDER == SDL_LIL_ENDIAN /* OpenGL RGBA masks */ 423 424 425 426 424 0x000000FF, 425 0x0000FF00, 426 0x00FF0000, 427 0xFF000000 427 428 #else 428 429 430 431 429 0xFF000000, 430 0x00FF0000, 431 0x0000FF00, 432 0x000000FF 432 433 #endif 433 434 ); … … 457 458 break; 458 459 } 459 460 // reading in the new Glyph 460 461 if (likely(this->fontTTF != NULL)) 461 462 { … … 521 522 for (int i = from; i <= lastGlyph; i++) 522 523 { 523 524 // setting up all the Glyphs we like. 524 525 glyphArray[i] = getGlyphMetrics(i); 525 526 } … … 555 556 if((tmpGlyph = this->glyphArray[i]) != NULL) 556 557 { 557 558 // getting the height of the highest Glyph in the Line. 558 559 if (tmpGlyph->height*this->renderSize > maxLineHeight) 559 560 maxLineHeight = (int)(tmpGlyph->height*this->renderSize); … … 563 564 x = 0; 564 565 y = y + maxLineHeight; 565 566 //maxLineHeight = 0; 566 567 } 567 568 if (y + maxLineHeight + 1 > size) … … 592 593 if(style==TTF_STYLE_NORMAL) 593 594 PRINTF(0)(" normal"); 594 else { 595 else 596 { 595 597 if(style&TTF_STYLE_BOLD) 596 598 PRINTF(0)(" bold");
Note: See TracChangeset
for help on using the changeset viewer.