Example #1
0
 def test_render_blended(self):
     filename = RESOURCES.get_path("tuffy.ttf")
     font = sdlttf.open_font(filename, 10)
     color = SDL_Color(0, 0, 0)
     sf = sdlttf.render_blended(font, "Example", color)
     self.assertIsInstance(sf, surface.SDL_Surface)
     surface.free_surface(sf)
Example #2
0
 def test_get_set_font_style(self):
     filename = RESOURCES.get_path("tuffy.ttf")
     font = sdlttf.open_font(filename, 10)
     self.assertIsInstance(font, sdlttf.TTF_Font)
     self.assertEqual(sdlttf.get_font_style(font), sdlttf.TTF_STYLE_NORMAL)
     sdlttf.set_font_style(font, sdlttf.TTF_STYLE_BOLD)
     self.assertEqual(sdlttf.get_font_style(font), sdlttf.TTF_STYLE_BOLD)
     sdlttf.set_font_style(font, sdlttf.TTF_STYLE_BOLD |
                           sdlttf.TTF_STYLE_ITALIC)
     self.assertEqual(sdlttf.get_font_style(font), sdlttf.TTF_STYLE_BOLD |
                      sdlttf.TTF_STYLE_ITALIC)
     sdlttf.set_font_style(font, sdlttf.TTF_STYLE_BOLD |
                           sdlttf.TTF_STYLE_UNDERLINE)
     self.assertRaises((AttributeError, TypeError),
                       sdlttf.get_font_style, None)
     self.assertRaises((AttributeError, TypeError),
                       sdlttf.get_font_style, "test")
     self.assertRaises((AttributeError, TypeError),
                       sdlttf.get_font_style, 1234)
     self.assertRaises(ArgumentError, sdlttf.set_font_style, font, None)
     self.assertRaises((AttributeError, TypeError),
                       sdlttf.set_font_style, "test", None)
     self.assertRaises((AttributeError, TypeError),
                       sdlttf.set_font_style, 1234, None)
     self.assertRaises((AttributeError, TypeError),
                       sdlttf.set_font_style, "test", 3)
     self.assertRaises((AttributeError, TypeError),
                       sdlttf.set_font_style, 1234, 4)
     self.assertRaises(ArgumentError, sdlttf.set_font_style, font, "test")
     sdlttf.close_font(font)
Example #3
0
 def test_font_faces(self):
     filename = RESOURCES.get_path("tuffy.ttf")
     font = sdlttf.open_font(filename, 10)
     self.assertGreaterEqual(sdlttf.font_faces(font), 1)
     self.assertRaises((AttributeError, TypeError), sdlttf.font_faces, None)
     self.assertRaises((AttributeError, TypeError),
                       sdlttf.font_faces, "test")
     self.assertRaises((AttributeError, TypeError), sdlttf.font_faces, 1234)
     sdlttf.close_font(font)
Example #4
0
 def test_open_close_font(self):
     filename = RESOURCES.get_path("tuffy.ttf")
     for x in range(-10, 15):
         font = sdlttf.open_font(filename, x)
         self.assertIsInstance(font, sdlttf.TTF_Font)
         sdlttf.close_font(font)
     self.assertRaises(TypeError, sdlttf.open_font, None, None)
     self.assertRaises(TypeError, sdlttf.open_font, filename, None)
     self.assertRaises(ValueError, sdlttf.open_font, filename, "abcd")
     self.assertRaises(ValueError, sdlttf.open_font, None, "abcd")
     self.assertRaises(sdl.SDLError, sdlttf.open_font, "test", 10)
Example #5
0
 def test_font_face_style_name(self):
     filename = RESOURCES.get_path("tuffy.ttf")
     font = sdlttf.open_font(filename, 10)
     self.assertEqual(sdlttf.font_face_style_name(font), "Regular")
     self.assertRaises((AttributeError, TypeError),
                       sdlttf.font_face_style_name, None)
     self.assertRaises((AttributeError, TypeError),
                       sdlttf.font_face_style_name, "test")
     self.assertRaises((AttributeError, TypeError),
                       sdlttf.font_face_style_name, 1234)
     sdlttf.close_font(font)
Example #6
0
 def test_font_face_is_fixed_width(self):
     filename = RESOURCES.get_path("tuffy.ttf")
     font = sdlttf.open_font(filename, 10)
     self.assertFalse(sdlttf.font_face_is_fixed_width(font))
     self.assertRaises((AttributeError, TypeError),
                       sdlttf.font_face_is_fixed_width, None)
     self.assertRaises((AttributeError, TypeError),
                       sdlttf.font_face_is_fixed_width, "test")
     self.assertRaises((AttributeError, TypeError),
                       sdlttf.font_face_is_fixed_width, 1234)
     sdlttf.close_font(font)
Example #7
0
File: gl.py Project: lxnt/fgtestbed
def a_mono_font(pref = None, size = 23):
    monoes = ['ntu mono', 'vu sans mono', 'ion mono', 'reemono', 'bus mono', 'mono', ]
    if pref is None:
        pref = monoes
    elif ',' in pref:
        pref, size =  pref.split(',')
        size = int(size)
        pref = [ pref ] if pref else monoes
    else:
        pref = [ pref ]
    ttfname, unused = findafont(pref)
    return sdlttf.open_font(ttfname, size)
Example #8
0
 def test_font_line_skip(self):
     filename = RESOURCES.get_path("tuffy.ttf")
     last = cur = 0
     for ptsize in range(-10, 10):
         font = sdlttf.open_font(filename, ptsize)
         cur = sdlttf.font_line_skip(font)
         self.assertGreaterEqual(cur, last)
         last = cur
         sdlttf.close_font(font)
     self.assertRaises((AttributeError, TypeError),
                       sdlttf.font_line_skip, None)
     self.assertRaises((AttributeError, TypeError),
                       sdlttf.font_line_skip, 1234)
     self.assertRaises((AttributeError, TypeError),
                       sdlttf.font_line_skip, "test")
Example #9
0
 def test_get_set_font_outline(self):
     filename = RESOURCES.get_path("tuffy.ttf")
     font = sdlttf.open_font(filename, 10)
     self.assertEqual(sdlttf.get_font_outline(font), 0)
     for x in range(-10, 10):
         sdlttf.set_font_outline(font, x)
         self.assertEqual(sdlttf.get_font_outline(font), x)
     self.assertRaises(TypeError, sdlttf.set_font_outline, None, None)
     self.assertRaises(TypeError, sdlttf.set_font_outline, font, None)
     self.assertRaises(ValueError, sdlttf.set_font_outline, font, "test")
     self.assertRaises(ValueError, sdlttf.set_font_outline, None, "test")
     self.assertRaises((AttributeError, TypeError),
                       sdlttf.set_font_outline, None, 123)
     self.assertRaises((AttributeError, TypeError),
                       sdlttf.get_font_outline, None)
     self.assertRaises((AttributeError, TypeError),
                       sdlttf.get_font_outline, None)
     sdlttf.close_font(font)
Example #10
0
 def test_glyph_is_provided(self):
     filename = RESOURCES.get_path("tuffy.ttf")
     font = sdlttf.open_font(filename, 10)
     self.assertIsInstance(font, sdlttf.TTF_Font)
     for ch in range(32, 127):
         self.assertTrue(sdlttf.glyph_is_provided(font, ch))
         self.assertTrue(sdlttf.glyph_is_provided(font, chr(ch)))
     self.assertFalse(sdlttf.glyph_is_provided(font, 0))
     self.assertFalse(sdlttf.glyph_is_provided(font, 0x0ff9))
     self.assertRaises((AttributeError, TypeError),
                       sdlttf.glyph_is_provided, None, None)
     self.assertRaises((AttributeError, TypeError),
                       sdlttf.glyph_is_provided, "test", None)
     self.assertRaises((AttributeError, TypeError),
                       sdlttf.glyph_is_provided, "test", 1234)
     self.assertRaises((ArgumentError, TypeError),
                       sdlttf.glyph_is_provided, font, None)
     self.assertRaises((AttributeError, TypeError),
                       sdlttf.glyph_is_provided, font, "test")
Example #11
0
 def test_get_set_font_hinting(self):
     filename = RESOURCES.get_path("tuffy.ttf")
     font = sdlttf.open_font(filename, 10)
     self.assertEqual(sdlttf.get_font_hinting(font),
                      sdlttf.TTF_HINTING_NORMAL)
     for hint in (sdlttf.TTF_HINTING_NORMAL, sdlttf.TTF_HINTING_LIGHT,
                  sdlttf.TTF_HINTING_MONO, sdlttf.TTF_HINTING_NONE):
         sdlttf.set_font_hinting(font, hint)
         self.assertEqual(sdlttf.get_font_hinting(font), hint)
     self.assertRaises((AttributeError, TypeError),
                       sdlttf.set_font_hinting, None, None)
     self.assertRaises(ArgumentError, sdlttf.set_font_hinting, font, None)
     self.assertRaises((AttributeError, TypeError),
                       sdlttf.set_font_hinting, None, 1)
     self.assertRaises(ArgumentError, sdlttf.set_font_hinting, font, "test")
     self.assertRaises((AttributeError, TypeError),
                       sdlttf.set_font_hinting, None, "test")
     self.assertRaises((AttributeError, TypeError),
                       sdlttf.get_font_hinting, None)
     sdlttf.close_font(font)
Example #12
0
 def test_get_set_font_kerning(self):
     filename = RESOURCES.get_path("tuffy.ttf")
     font = sdlttf.open_font(filename, 10)
     self.assertEqual(sdlttf.get_font_kerning(font), True)
     sdlttf.set_font_kerning(font, False)
     self.assertEqual(sdlttf.get_font_kerning(font), False)
     sdlttf.set_font_kerning(font, True)
     self.assertEqual(sdlttf.get_font_kerning(font), True)
     sdlttf.set_font_kerning(font, False)
     self.assertEqual(sdlttf.get_font_kerning(font), False)
     self.assertRaises((AttributeError, TypeError),
                       sdlttf.get_font_kerning, None)
     self.assertRaises((AttributeError, TypeError),
                       sdlttf.get_font_kerning, "test")
     self.assertRaises((AttributeError, TypeError),
                       sdlttf.get_font_kerning, 1234)
     self.assertRaises((AttributeError, TypeError),
                       sdlttf.set_font_kerning, None, None)
     self.assertRaises((AttributeError, TypeError),
                       sdlttf.set_font_kerning, "test", "test")
     self.assertRaises((AttributeError, TypeError),
                       sdlttf.set_font_kerning, 1234, None)
     sdlttf.close_font(font)