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/imagemanager.h"
41 #include "video/renderbackend.h"
43 #include "subimagefont.h"
46 static Logger _log(LM_GUI);
51 FL_LOG(_log,
LMsg(
"guichan_image_font, loading ") << filename <<
" glyphs " << glyphs);
54 ImagePtr img = ImageManager::instance()->load(filename);
55 int32_t image_id = img->getHandle();
56 SDL_Surface* surface = img->getSurface();
57 m_colorkey = RenderBackend::instance()->getColorKey();
60 throw CannotOpenFile(filename);
65 SDL_Surface *tmp = SDL_CreateRGBSurface(SDL_SWSURFACE,
66 surface->w,surface->h,32,
67 RMASK, GMASK, BMASK ,NULLMASK);
69 SDL_BlitSurface(surface,0,tmp,0);
73 uint32_t *pixels =
reinterpret_cast<uint32_t*
>(surface->pixels);
83 uint32_t separator = pixels[0];
84 uint32_t colorkey = SDL_MapRGB(surface->format, m_colorkey.r, m_colorkey.g, m_colorkey.b);
87 if (!RenderBackend::instance()->isColorKeyEnabled()) {
88 while(x < surface->w && pixels[x] == separator) {
96 SDL_SetAlpha(surface,0,255);
97 SDL_SetColorKey(surface,SDL_SRCCOLORKEY,colorkey);
99 FL_DBG(_log,
LMsg(
"image_font")
100 <<
" glyph separator is "
101 <<
pprint(reinterpret_cast<void*>(separator))
102 <<
" transparent color is "
103 <<
pprint(reinterpret_cast<void*>(colorkey)));
106 std::string::const_iterator text_it = glyphs.begin();
107 while(text_it != glyphs.end()) {
109 while(x < surface->w && pixels[x] == separator)
111 if( x == surface->w )
114 while(x + w < surface->w && pixels[x + w] != separator)
120 tmp = SDL_CreateRGBSurface(SDL_SWSURFACE,
122 RMASK, GMASK, BMASK ,NULLMASK);
124 SDL_FillRect(tmp,0,colorkey);
125 SDL_BlitSurface(surface,&src,tmp,0);
128 SDL_SetAlpha(tmp,0,255);
129 SDL_SetColorKey(tmp,SDL_SRCCOLORKEY,colorkey);
132 uint32_t codepoint = utf8::next(text_it, glyphs.end());
133 m_glyphs[ codepoint ].surface = tmp;
140 if( m_glyphs.find(
'?') != m_glyphs.end() ) {
141 m_placeholder = m_glyphs[
'?'];
143 m_placeholder.surface = 0;
146 mHeight = surface->h;
147 SDL_FreeSurface(surface);
SubImageFont(const std::string &filename, const std::string &glyphs)