Added 1-pixel transparent border around glyphs to avoid GL blending artifacts when...
[supertux.git] / src / video / font.cpp
index d9ccd08..f3ce635 100644 (file)
@@ -62,6 +62,7 @@ Font::Font(GlyphWidth glyph_width_,
   shadow_surfaces(),
   char_height(),
   shadowsize(shadowsize_),
+  border(0),
   glyphs(65536)
 {
   for(unsigned int i=0; i<65536;i++) glyphs[i].surface_idx = -1;
@@ -106,6 +107,8 @@ Font::loadFontFile(const std::string &filename)
     throw std::runtime_error(msg.str());
   }
 
+  config_l->get("glyph-border", border);
+
   lisp::ListIterator iter(config_l);
   while(iter.next()) {
     const std::string& token = iter.item();
@@ -190,8 +193,8 @@ Font::loadFontSurface(
 
   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;
+      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;
         
@@ -206,6 +209,12 @@ Font::loadFontSurface(
       }
       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;
@@ -234,7 +243,8 @@ Font::loadFontSurface(
       row++;
     }
   }
-  
+abort:
+
   if( surface != NULL ) {
     SDL_UnlockSurface(surface);
     SDL_FreeSurface(surface);