+ 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;
+ int x = col * char_width;
+ 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 ) {
+ glyph.rect = Rect(x, y, x + char_width, y + char_height);
+ glyph.offset = Vector(0, 0);
+ glyph.advance = char_width;
+ }
+ else {
+ 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.rect = Rect(left, y, right+1, y + char_height);
+ else // glyph is completely transparent
+ glyph.rect = Rect(x, y, x + char_width, y + char_height);
+
+ glyph.offset = Vector(0, 0);
+ glyph.advance = glyph.rect.get_width() + 1; // FIXME: might be useful to make spacing configurable
+ }