Example #1
0
    def test_FontManager_add(self):
        fm = sdl2ext.FontManager(RESOURCES.get_path("tuffy.ttf"))
        assert "tuffy" in fm.aliases
        assert "tuffy" in fm.fonts
        assert 16 in fm.fonts["tuffy"]
        assert isinstance(fm.fonts["tuffy"][16].contents, sdlttf.TTF_Font)

        # Do some metrics tests
        # NOTE: Ascent & other font metrics changed in FreeType 2.10, so we
        # test against both < 2.10 and >= 2.10 values
        font = fm.fonts["tuffy"][16]
        assert sdlttf.TTF_FontAscent(font) in [13, 16]
        fm.add(RESOURCES.get_path("tuffy.ttf"), size=12)
        font = fm.fonts["tuffy"][12]
        assert sdlttf.TTF_FontAscent(font) in [10, 12]

        with pytest.raises(IOError):
            fm.add("inexistent.ttf")
        # I don't find a scenario raising a TTF_Error.
        # self.assertRaises(sdl2ext.SDLError, fm.add, "resources/tuffy.ttf",
        #                   size=-1)

        # Close the font manager and add a new font
        fm.close()
        fm.add(RESOURCES.get_path("tuffy.ttf"), size=12)
        assert isinstance(fm.fonts["tuffy"][12].contents, sdlttf.TTF_Font)
 def test_TTF_FontAscent(self):
     last = cur = 0
     for ptsize in range(-10, 10):
         font = sdlttf.TTF_OpenFont(fontfile, ptsize)
         cur = sdlttf.TTF_FontAscent(font)
         self.assertGreaterEqual(cur, last)
         last = cur
         sdlttf.TTF_CloseFont(font)
Example #3
0
    def test_FontManager_add(self):
        fm = sdl2ext.FontManager(RESOURCES.get_path("tuffy.ttf"))
        self.assertIn("tuffy", fm.aliases)
        self.assertIn("tuffy", fm.fonts)
        self.assertIn(16, fm.fonts["tuffy"])
        self.assertIsInstance(fm.fonts["tuffy"][16].contents, sdlttf.TTF_Font)

        # Do some metrics tests
        font = fm.fonts["tuffy"][16]
        self.assertEqual(16, sdlttf.TTF_FontAscent(font))
        fm.add(RESOURCES.get_path("tuffy.ttf"), size=12)
        font = fm.fonts["tuffy"][12]
        self.assertEqual(12, sdlttf.TTF_FontAscent(font))

        self.assertRaises(IOError, fm.add, "inexistent.ttf")
        # I don't find a scenario raising a TTF_Error.
        # self.assertRaises(sdl2ext.SDLError, fm.add, "resources/tuffy.ttf",
        #                   size=-1)

        # Close the font manager and add a new font
        fm.close()
        fm.add(RESOURCES.get_path("tuffy.ttf"), size=12)
        self.assertIsInstance(fm.fonts["tuffy"][12].contents, sdlttf.TTF_Font)