Commits

Anonymous committed bb63a56

pygame.font passes unit test

Comments (0)

Files changed (2)

         if background:
             background = SDL_Color(*pygame.base._rgba_from_obj(background))
 
-        if antialias:
+        if not text:
+            # Pygame returns a 1 pixel wide surface if given empty string.
+            height = TTF_FontHeight(font)
+            surf = SDL_CreateRGBSurface(SDL_SWSURFACE, 1, height, 32,
+                                        0x00ff0000, 0x0000ff00, 0x000000ff, 0)
+            if background:
+                c = SDL_MapRGB(surf.format, background.r, background.g,
+                               background.b)
+                SDL_FillRect(surf, None, c)
+            else:
+                SDL_SetColorKey(surf, SDL_SRCCOLORKEY, 0)
+        elif antialias:
             if not background:
                 surf = TTF_RenderText_Blended(font, text, foreground)
             else:
         else:
             surf = TTF_RenderText_Solid(font, text, foreground)
 
-        if not antialias and background:
+        if text and not antialias and background:
             # Add color key
             SDL_SetColorKey(surf, 0, 0)
             surf.format.palette.colors[0].r = background.r
         if pitch == w:
             result = pixels # easy exit
         else:
-            flipped = False
+            flipped = False # Flipping taken care of by h_range
             for y in h_range:
                 rows.append(pixels[y*pitch:y*pitch + w])
     elif surf.format.BytesPerPixel == len(format) and format != 'RGBX':
                           for c in surf.pixels]
         surface.unlock()
         pitch /= surf.format.BytesPerPixel
-        flipped = False
+        flipped = False  # Flipping taken care of by h_range
         if format == 'RGB':
             for y in h_range:
                 rows.append(''.join([ chr(c[0]) + chr(c[1]) + chr(c[2]) \
     if surface._surf.flags & SDL_OPENGL:
         SDL_FreeSurface(surf)
 
+    # Is pixel data already one big string?
     if result:
         if flipped:
+            # Split it into rows so it can be flipped vertically.
             rows = re.findall('.' * w * len(format), result, re.DOTALL)
         else:
             return result