26 #include "util/base/fife_stdint.h"
35 #include "util/base/exception.h"
36 #include "util/log/logger.h"
37 #include "util/structures/rect.h"
38 #include "util/utf8/utf8.h"
39 #include "video/image.h"
40 #include "video/renderbackend.h"
41 #include "video/imagepool.h"
43 #include "subimagefont.h"
46 static Logger _log(LM_GUI);
51 FL_LOG(_log,
LMsg(
"guichan_image_font, loading ") << filename <<
" glyphs " << glyphs);
55 SDL_Surface* surface = img.getSurface();
56 m_colorkey = RenderBackend::instance()->getColorKey();
59 throw CannotOpenFile(filename);
64 SDL_Surface *tmp = SDL_CreateRGBSurface(SDL_SWSURFACE,
65 surface->w,surface->h,32,
66 RMASK, GMASK, BMASK ,NULLMASK);
68 SDL_BlitSurface(surface,0,tmp,0);
72 uint32_t *pixels =
reinterpret_cast<uint32_t*
>(surface->pixels);
82 uint32_t separator = pixels[0];
83 uint32_t colorkey = SDL_MapRGB(surface->format, m_colorkey.r, m_colorkey.g, m_colorkey.b);
86 if (!RenderBackend::instance()->isColorKeyEnabled()) {
87 while(x < surface->w && pixels[x] == separator) {
95 SDL_SetAlpha(surface,0,255);
96 SDL_SetColorKey(surface,SDL_SRCCOLORKEY,colorkey);
98 FL_DBG(_log,
LMsg(
"image_font")
99 <<
" glyph separator is "
100 <<
pprint(reinterpret_cast<void*>(separator))
101 <<
" transparent color is "
102 <<
pprint(reinterpret_cast<void*>(colorkey)));
105 std::string::const_iterator text_it = glyphs.begin();
106 while(text_it != glyphs.end()) {
108 while(x < surface->w && pixels[x] == separator)
110 if( x == surface->w )
113 while(x + w < surface->w && pixels[x + w] != separator)
119 tmp = SDL_CreateRGBSurface(SDL_SWSURFACE,
121 RMASK, GMASK, BMASK ,NULLMASK);
123 SDL_FillRect(tmp,0,colorkey);
124 SDL_BlitSurface(surface,&src,tmp,0);
127 SDL_SetAlpha(tmp,0,255);
128 SDL_SetColorKey(tmp,SDL_SRCCOLORKEY,colorkey);
131 uint32_t codepoint = utf8::next(text_it, glyphs.end());
132 m_glyphs[ codepoint ].surface = tmp;
139 if( m_glyphs.find(
'?') != m_glyphs.end() ) {
140 m_placeholder = m_glyphs[
'?'];
142 m_placeholder.surface = 0;
145 mHeight = surface->h;
146 SDL_FreeSurface(surface);