Commits

Lenard Lindstrom committed 636a34b

freetype: make handling of undefined character codes consistent with font module

  • Participants
  • Parent commits 4bebf24

Comments (0)

Files changed (3)

File docs/reST/ref/freetype.rst

 You can load fonts from the system by using the ``pygame.freetype.SysFont()``
 function. There are a few other functions to help lookup the system fonts.
 
+For now undefined character codes are replaced with the ``undefined character``.
+How undefined codes are handled may become configurable in a future release.
+
 Pygame comes with a builtin default font. This can always be accessed by
 passing None as the font name to the Font constructor.
 

File src/freetype/ft_text.c

     gindex = FTC_CMapCache_Lookup(context->charmap, context->id,
                                   -1, (FT_UInt32)character);
 
-    if (!gindex)
-    {
-        goto cleanup;
-    }
     glyph->glyph_index = gindex;
 
     /*

File test/freetype_font_test.py

     except AttributeError:
         del test_freetype_Font_cache
 
+    def test_undefined_character_code(self):
+        # To be consistent with pygame.font.Font, undefined codes
+        # are rendered as the undefined character.
+        font = self._TEST_FONTS['sans']
+
+        img, size1 = font.render(None, unichr_(1), (0, 0, 0), ptsize=24)
+        img, size0 = font.render(None, "", (0, 0, 0), ptsize=24)
+        self.assertTrue(size1.width > size0.width )
+
+        metrics = font.get_metrics(unichr_(1) + unichr_(48), ptsize=24)
+        self.assertEqual(len(metrics), 2)
+        self.assertTrue(isinstance(metrics[0], tuple))
+
 class FreeTypeFont(unittest.TestCase):
 
     def test_resolution(self):