+ char_count = ((int) glyph_surface->get_height() / char_height) * 16;
+
+ if (glyph_width == FIXED)
+ {
+ for(uint32_t i = 0; i < char_count; ++i)
+ {
+ float x = (i % 16) * char_width;
+ float y = (i / 16) * char_height;
+
+ Glyph glyph;
+ glyph.advance = char_width;
+ glyph.offset = Vector(0, 0);
+ glyph.rect = Rect(x, y, x + char_width, y + char_height);
+
+ glyphs.push_back(glyph);
+ shadow_glyphs.push_back(glyph);
+ }
+ }
+ else // glyph_width == VARIABLE
+ {
+ // Load the surface into RAM and scan the pixel data for characters
+ SDL_Surface* surface = IMG_Load_RW(get_physfs_SDLRWops(filename), 1);
+ if(surface == NULL) {
+ std::ostringstream msg;
+ msg << "Couldn't load image '" << filename << "' :" << SDL_GetError();
+ throw std::runtime_error(msg.str());
+ }
+
+ SDL_LockSurface(surface);
+
+ for(uint32_t i = 0; i < char_count; ++i)
+ {
+ int x = (i % 16) * char_width;
+ int y = (i / 16) * char_height;
+
+ 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;
+
+ Glyph glyph;
+ glyph.offset = Vector(0, 0);
+
+ if (left <= right)
+ glyph.rect = Rect(left, y, right+1, y + char_height);
+ else // glyph is completly transparent
+ glyph.rect = Rect(x, y, x + char_width, y + char_height);
+
+ glyph.advance = glyph.rect.get_width() + 1; // FIXME: might be usefull to make spacing configurable
+
+ glyphs.push_back(glyph);
+ shadow_glyphs.push_back(glyph);
+ }
+
+ SDL_UnlockSurface(surface);
+
+ SDL_FreeSurface(surface);
+ }