Penjin::ERRORS Text::load(CRstring name,CRuint fontSize) { ErrorHandler* eMan = ErrorMan::getInstance(); // check if fontSize is not the same as loaded font if(this->fontSize != fontSize || name != getFileName()) { clear(); #if PLATFORM_WII font = TTF_OpenFont((Penjin::getWorkingDirectory() + name).c_str(), fontSize); #else font = TTF_OpenFont(name.c_str(), fontSize); #endif } if(font) { setFileName(name); // check if we already have Glyphs for this fontSize if(glyphs.size() >= fontSize) { if(glyphs.at(fontSize-1).size()) { // if the fontSize checks out... if(glyphs.at(fontSize-1)[0]->getFontSize() == fontSize) { this->fontSize = fontSize; #ifdef _DEBUG eMan->print(PENJIN_OK,"Text: font loaded, Size: " + StringUtility::intToString(fontSize) + "Font: " + name); #endif return PENJIN_OK; } } } else { //Setup enough glyphs for fontSize glyphs.resize(fontSize); } // create Dummy Char for spacing calcs glyphs[fontSize-1].push_back(NULL); glyphs[fontSize-1][0] = new Glyph(); glyphs[fontSize-1][0]->setFontSize(fontSize); glyphs[fontSize-1][0]->setFont(font); glyphs[fontSize-1][0]->setCharacter('-'); // picked because a nice square char to give us a "standard surface width" glyphs[fontSize-1][0]->setPosition(cursorPos.getPosition()); glyphs[fontSize-1][0]->refresh(); setFileName(name); this->fontSize = fontSize; #ifdef _DEBUG eMan->print(PENJIN_OK,"Text: font loaded, Size: " + StringUtility::intToString(fontSize) + "Font: " + name); #endif return PENJIN_OK; } eMan->print(PENJIN_TTF_UNABLE_TO_OPEN,"Text: Size: " + StringUtility::intToString(fontSize) + "Font: " + name); return PENJIN_TTF_UNABLE_TO_OPEN; }
Penjin::ERRORS Penjin::TextClass::init() { ErrorHandler* eMan = ErrorMan::getInstance(); if(isInitialised()) { #ifdef _DEBUG eMan->print(PENJIN_OK, "TextClass: SDL_TTF Initialised."); #endif return PENJIN_OK; } int result = TTF_Init(); if(result != 0) { result = PENJIN_ERROR; } else { result = PENJIN_OK; } eMan->print((Penjin::ERRORS)result,"TextClass::init()"); return (Penjin::ERRORS)result; }