1. Marcus von Appen
  2. py-sdl2

Commits

Marcel Rodrigues  committed 1834266

- accept ' ' as blank character by default on BitmapFont

  • Participants
  • Parent commits 0e325f4
  • Branches fix-bitmapfont

Comments (0)

Files changed (1)

File sdl2/ext/font.py

View file
             x = 0
             for c in line:
                 dstr.x = x
-                blit_surface(fontsf, offsets[c], target, dstr)
+                if c in offsets:
+                    blit_surface(fontsf, offsets[c], target, dstr)
+                #elif c != ' ':
+                #    TODO: raise an exception for unknown char?
                 x += w
             y += h
         return imgsurface
             x = offset[0]
             for c in line:
                 dstr.x = x
-                blit_surface(fontsf, offsets[c], target, dstr)
+                if c in offsets:
+                    blit_surface(fontsf, offsets[c], target, dstr)
+                #elif c != ' ':
+                #    TODO: raise an exception for unknown char?
                 x += w
             y += h
         return (offset[0], offset[1], x + w, y + h)
 
     def contains(self, c):
         """Checks, whether a certain character exists in the font."""
-        return c in self.offsets
+        return c == ' ' or c in self.offsets
 
     def can_render(self, text):
         """Checks, whether all characters in the passed text can be rendered.
         lines = text.split(os.linesep)
         for line in lines:
             for c in line:
-                if c not in self.offsets:
+                if c != ' ' and c not in self.offsets:
                     return False
         return True