illume avatar illume committed 6cc8196

Font.render can set backgound to None. Fixes #49.
Thanks John and Marco Chieppa!

Comments (0)

Files changed (2)

     foreg.b = rgba[2];
     if (bg_rgba_obj != NULL) {
         if (!RGBAFromColorObj(bg_rgba_obj, rgba)) {
-            return RAISE(PyExc_TypeError, "Invalid background RGBA argument");
+            bg_rgba_obj = NULL;
+            backg.r = 0;
+            backg.g = 0;
+            backg.b = 0;
+            backg.unused = 0;
         }
-        backg.r = rgba[0];
-        backg.g = rgba[1];
-        backg.b = rgba[2];
-        backg.unused = 0;
+        else
+        {
+            backg.r = rgba[0];
+            backg.g = rgba[1];
+            backg.b = rgba[2];
+            backg.unused = 0;
+        }
     }
     else {
         backg.r = 0;

test/font_test.py

         pygame_font.quit()
 
 
+
+
+
+class FontTest(unittest.TestCase):
+    def setUp(self):
+        pygame_font.init()
+
+    def tearDown(self):
+        pygame_font.quit()
+
+
+    def test_render_args(self):
+        screen = pygame.display.set_mode((600, 400))
+        rect = screen.get_rect()
+        f = pygame.font.Font(None, 20)
+        screen.fill((10, 10, 10))
+        font_surface = f.render("   bar", True, (0, 0, 0), (255, 255, 255))
+        font_rect = font_surface.get_rect()
+        font_rect.topleft = rect.topleft
+        self.assertTrue(font_surface)
+        screen.blit(font_surface, font_rect, font_rect)
+        pygame.display.update()
+        self.assertEqual(tuple(screen.get_at((0,0)))[:3], (255, 255, 255))        
+        self.assertEqual(tuple(screen.get_at(font_rect.topleft))[:3], (255, 255, 255))        
+        screen.fill((10, 10, 10))
+        font_surface = f.render("   bar", True, (0, 0, 0), None)
+        font_rect = font_surface.get_rect()
+        font_rect.topleft = rect.topleft
+        self.assertTrue(font_surface)
+        screen.blit(font_surface, font_rect, font_rect)
+        pygame.display.update()
+        self.assertEqual(tuple(screen.get_at((0,0)))[:3], (10, 10, 10))
+        self.assertEqual(tuple(screen.get_at(font_rect.topleft))[:3], (10, 10, 10))        
+        screen.fill((10, 10, 10))
+        font_surface = f.render("   bar", True, (0, 0, 0))
+        font_rect = font_surface.get_rect()
+        font_rect.topleft = rect.topleft
+        self.assertTrue(font_surface)
+        screen.blit(font_surface, font_rect, font_rect)
+        pygame.display.update(rect)
+        self.assertEqual(tuple(screen.get_at((0,0)))[:3], (10, 10, 10))
+        self.assertEqual(tuple(screen.get_at(font_rect.topleft))[:3], (10, 10, 10))
+
+
+
+
+
+
+
 class FontTypeTest( unittest.TestCase ):
     def setUp(self):
         pygame_font.init()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.