+ }
+}
+
+void
+Font::loadFontSurface(
+ const std::string &glyphimage,
+ const std::string &shadowimage,
+ const std::vector<std::string> &chars,
+ GlyphWidth glyph_width_,
+ int char_width
+ )
+{
+ SurfacePtr glyph_surface = Surface::create("images/engine/fonts/" + glyphimage);
+ SurfacePtr shadow_surface = Surface::create("images/engine/fonts/" + shadowimage);
+
+ int surface_idx = glyph_surfaces.size();
+ glyph_surfaces.push_back(glyph_surface);
+ shadow_surfaces.push_back(shadow_surface);
+
+ int row=0, col=0;
+ int wrap = glyph_surface->get_width() / char_width;
+
+ SDL_Surface *surface = NULL;
+
+ if( glyph_width_ == VARIABLE ) {
+ //this does not work:
+ // surface = ((SDL::Texture *)glyph_surface.get_texture())->get_texture();
+ surface = IMG_Load_RW(get_physfs_SDLRWops("images/engine/fonts/"+glyphimage), 1);
+ if(surface == NULL) {
+ std::ostringstream msg;
+ msg << "Couldn't load image '" << glyphimage << "' :" << SDL_GetError();
+ throw std::runtime_error(msg.str());
+ }
+ SDL_LockSurface(surface);
+ }
+
+ for( unsigned int i = 0; i < chars.size(); i++) {
+ for(UTF8Iterator chr(chars[i]); !chr.done(); ++chr) {
+ int y = row * (char_height + 2*border) + border;
+ int x = col * (char_width + 2*border) + border;
+ if( ++col == wrap ) { col=0; row++; }
+ if( *chr == 0x0020 && glyphs[0x20].surface_idx != -1) continue;
+
+ Glyph glyph;
+ glyph.surface_idx = surface_idx;
+
+ if( glyph_width_ == FIXED || isdigit(*chr) )
+ {
+ glyph.rect = Rectf(x, y, x + char_width, y + char_height);
+ glyph.offset = Vector(0, 0);
+ glyph.advance = char_width;
+ }
+ else
+ {
+ if (y + char_height > surface->h)
+ {
+ log_warning << "error: font definition contains more letter then the images: " << glyphimage << std::endl;
+ goto abort;
+ }
+
+ int left = x;
+ while (left < x + char_width && vline_empty(surface, left, y, y + char_height, 64))
+ left += 1;
+ int right = x + char_width - 1;
+ while (right > left && vline_empty(surface, right, y, y + char_height, 64))
+ right -= 1;
+
+ if (left <= right)
+ {
+ glyph.offset = Vector(x-left, 0);
+ glyph.advance = right - left + 1 + 1; // FIXME: might be useful to make spacing configurable
+ }
+ else
+ { // glyph is completly transparent
+ glyph.offset = Vector(0, 0);
+ glyph.advance = char_width + 1; // FIXME: might be useful to make spacing configurable
+ }
+
+ glyph.rect = Rectf(x, y, x + char_width, y + char_height);
+ }
+
+ glyphs[*chr] = glyph;
+ }
+ if( col>0 && col <= wrap ) {
+ col = 0;
+ row++;
+ }
+ }
+abort:
+
+ if( surface != NULL ) {
+ SDL_UnlockSurface(surface);
+ SDL_FreeSurface(surface);