32 #include "util/base/exception.h"
33 #include "util/structures/rect.h"
34 #include "util/utf8/utf8.h"
35 #include "video/image.h"
36 #include "video/renderbackend.h"
38 #include "truetypefont.h"
47 mFont = TTF_OpenFont(filename.c_str(), size);
50 throw FIFE::CannotOpenFile(filename +
" (" + TTF_GetError() +
")");
52 mColor.r = mColor.g = mColor.b = mColor.unused = 255;
61 assert( utf8::is_valid(text.begin(), text.end()) );
62 TTF_SizeUTF8(mFont, text.c_str(), &w, &h);
70 SDL_Surface* TrueTypeFont::renderString(
const std::string& text) {
72 SDL_Surface *surface = SDL_CreateRGBSurface(SDL_SWSURFACE,
74 RMASK, GMASK, BMASK ,AMASK);
75 SDL_FillRect(surface,0,0x00000000);
79 SDL_Surface* renderedText = 0;
81 renderedText = TTF_RenderUTF8_Blended(mFont, text.c_str(), mColor);
83 renderedText = TTF_RenderUTF8_Solid(mFont, text.c_str(), mColor);
87 if (renderedText == 0 && !m_antiAlias) {
88 renderedText = TTF_RenderUTF8_Blended(mFont, text.c_str(), mColor);
91 if (renderedText == 0) {
92 throw FIFE::SDLException(TTF_GetError());
97 void TrueTypeFont::setColor(Uint8 r, Uint8 g, Uint8 b, Uint8 a) {