def test_TTF_GetSetFontStyle(self): font = sdlttf.TTF_OpenFont(fontfile, 10) self.assertIsInstance(font.contents, sdlttf.TTF_Font) self.assertEqual(sdlttf.TTF_GetFontStyle(font), sdlttf.TTF_STYLE_NORMAL) sdlttf.TTF_SetFontStyle(font, sdlttf.TTF_STYLE_BOLD) self.assertEqual(sdlttf.TTF_GetFontStyle(font), sdlttf.TTF_STYLE_BOLD) sdlttf.TTF_SetFontStyle(font, sdlttf.TTF_STYLE_BOLD | sdlttf.TTF_STYLE_ITALIC) self.assertEqual(sdlttf.TTF_GetFontStyle(font), sdlttf.TTF_STYLE_BOLD | sdlttf.TTF_STYLE_ITALIC) sdlttf.TTF_SetFontStyle(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.TTF_CloseFont(font)
def test_TTF_FontLineSkip(self): last = cur = 0 for ptsize in range(-10, 10): font = sdlttf.TTF_OpenFont(fontfile, ptsize) cur = sdlttf.TTF_FontLineSkip(font) self.assertGreaterEqual(cur, last) last = cur sdlttf.TTF_CloseFont(font)
def test_TTF_FontDescent(self): last = cur = 0 for ptsize in range(-10, 10): font = sdlttf.TTF_OpenFont(fontfile, ptsize) cur = sdlttf.TTF_FontDescent(font) self.assertLessEqual(cur, last) last = cur sdlttf.TTF_CloseFont(font)
def test_TTF_FontFaces(self): font = sdlttf.TTF_OpenFont(fontfile, 10) self.assertGreaterEqual(sdlttf.TTF_FontFaces(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.TTF_CloseFont(font)
def test_TTF_FontAscent(self): last = cur = 0 for ptsize in range(6, 26): font = sdlttf.TTF_OpenFont(fontfile, ptsize) cur = sdlttf.TTF_FontAscent(font) self.assertGreaterEqual(cur, last) last = cur sdlttf.TTF_CloseFont(font)
def printD(self, size, x, y, text, font="SanFranciscoRegular", color=[0, 0, 0]): pas = size L = [] k = 0 MOD = 20 i = len(text) - 1 while i > 0: if text[i] == '\t' or text[i] == '\n': text = text[:i] + text[i + 1:] i = i - 1 M = "" for i in range(len(text)): M += text[i] if i % MOD == 0 and i != 0: if text[i] != ' ' and text[i + 1] != ' ': M += '-' M += '\n' text = M while k < len(text): if text[k] == '\n': L.append(text[:k]) text = text[(k + 1):] k = 0 if L[-1][0] == " ": L[-1] = L[-1][1:] else: k += 1 L.append(text) for i in range(len(L)): if L[i] == '': del L[i] police = sdlttf.TTF_OpenFont(str.encode("Fonts/" + font + ".ttf"), size) P = 0 for elem in L: Text = sdlttf.TTF_RenderUTF8_Blended( police, str.encode(elem), SDL_Color(color[0], color[1], color[2])) a = [Text, SDL_Rect(x, y + P)] self.elmt_afficher.append(a) P += pas sdlttf.TTF_CloseFont(police)
def test_TTF_OpenFontIndexRW(self): fp = open(fontfile, "rb") fontrw = rwops.rw_from_object(fp) for x in range(-10, 15): fp.seek(0) font = sdlttf.TTF_OpenFontIndexRW(fontrw, 0, x, 0) self.assertIsInstance(font.contents, sdlttf.TTF_Font) sdlttf.TTF_CloseFont(font) fp.close()
def test_TTF_FontFaceIsFixedWidth(self): font = sdlttf.TTF_OpenFont(fontfile, 10) self.assertFalse(sdlttf.TTF_FontFaceIsFixedWidth(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.TTF_CloseFont(font)
def test_TTF_FontFaceStyleName(self): font = sdlttf.TTF_OpenFont(fontfile, 10) self.assertEqual(sdlttf.TTF_FontFaceStyleName(font), b"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.TTF_CloseFont(font)
def test_TTF_FontFaceFamilyName(self): font = sdlttf.TTF_OpenFont(fontfile, 10) self.assertEqual(sdlttf.TTF_FontFaceFamilyName(font), b"Tuffy") # self.assertRaises((AttributeError, TypeError), # sdlttf.font_face_family_name, None) # self.assertRaises((AttributeError, TypeError), # sdlttf.font_face_family_name, "test") # self.assertRaises((AttributeError, TypeError), # sdlttf.font_face_family_name, 1234) sdlttf.TTF_CloseFont(font)
def Start(self, ischeck, repete): '''function which calls the starting function of the game''' self.r.w.show() n = 1 if repete else 0 rep = self.StartGame(ischeck) and repete self.__print_update_score(n) while rep: n += 1 self.ResetGame() rep = self.StartGame(ischeck) and repete self.__print_update_score(n) self.r.w.hide() ttf.TTF_CloseFont(self.r.t)
def test_TTF_GetSetFontOutline(self): font = sdlttf.TTF_OpenFont(fontfile, 10) self.assertEqual(sdlttf.TTF_GetFontOutline(font), 0) for x in range(-10, 10): sdlttf.TTF_SetFontOutline(font, x) self.assertEqual(sdlttf.TTF_GetFontOutline(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.TTF_CloseFont(font)
def printT(self, size, x, y, text, font="SanFranciscoRegular", color=[0, 0, 0]): pas = size L = [] k = 0 while k < len(text): if text[k] == '\n': L.append(text[:k]) text = text[(k + 1):] k = 0 if L[-1][0] == " ": L[-1] = L[-1][1:] else: k += 1 L.append(text) try: if L[-1][0] == " ": L[-1] = L[-1][1:] except: pass police = sdlttf.TTF_OpenFont(str.encode("Fonts/" + font + ".ttf"), size) P = 0 for elem in L: Text = sdlttf.TTF_RenderUTF8_Blended( police, str.encode(elem), SDL_Color(color[0], color[1], color[2])) a = [Text, SDL_Rect(x, y + P)] self.elmt_afficher.append(a) P += pas sdlttf.TTF_CloseFont(police)
def test_TTF_GetSetFontHinting(self): font = sdlttf.TTF_OpenFont(fontfile, 10) self.assertEqual(sdlttf.TTF_GetFontHinting(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.TTF_SetFontHinting(font, hint) self.assertEqual(sdlttf.TTF_GetFontHinting(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.TTF_CloseFont(font)
def test_TTF_GetSetFontKerning(self): font = sdlttf.TTF_OpenFont(fontfile, 10) self.assertEqual(sdlttf.TTF_GetFontKerning(font), 1) sdlttf.TTF_SetFontKerning(font, 0) self.assertEqual(sdlttf.TTF_GetFontKerning(font), 0) sdlttf.TTF_SetFontKerning(font, 1) self.assertEqual(sdlttf.TTF_GetFontKerning(font), 1) sdlttf.TTF_SetFontKerning(font, 0) self.assertEqual(sdlttf.TTF_GetFontKerning(font), 0) # 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.TTF_CloseFont(font)
def printTexte(self, size, text, font="SanFranciscoRegular", color=[0, 0, 0]): definition = [] mots_definie = [] pas = size L = [] k = 0 MOD = 45 Deb = 100 Deby = 120 i = len(text) - 1 while i > 0: if text[i] == '\t' or text[i] == '\n': text = text[:i] + text[i + 1:] i = i - 1 if "<def" in text: a = text.find("<def") b = text.find(">") definition.append(text[(a + 6):].split( text[b:])[0]) #on recupere la definition et le mot associé c = text.find("</def>") mots_definie.append(text[(b + 1):].split(text[c:])[0]) text = text[:a] + text[(b + 1):] #on supprime les balises du texte c = text.find("</def>") text = text[:c] + text[(c + 6):] M = "" for i in range(len(text)): M += text[i] if i % MOD == 0 and i != 0: try: if text[i] != ' ' and text[i + 1] != ' ': M += '-' except: pass M += '\n' text = M while k < len(text): if text[k] == '\n': L.append(text[:k]) text = text[(k + 1):] k = 0 if L[-1][0] == " ": L[-1] = L[-1][1:] else: k += 1 L.append(text) for i in range(len(L)): if L[i] == '': del L[i] #print(L) if L[-1][0] == " ": L[-1] = L[-1][1:] police = sdlttf.TTF_OpenFont(str.encode("Fonts/" + font + ".ttf"), size) P = 0 #print(L) for elem in L: afficher = False for i in range(len(mots_definie)): if mots_definie[i] in elem: mots = mots_definie[i] afficher = True #print(mots) position = elem.find(mots) fin_mots = len(mots) + position Text = sdlttf.TTF_RenderUTF8_Blended( police, str.encode(elem[:position]), SDL_Color(0, 0, 0)) a = [Text, SDL_Rect(Deb, Deby + P)] self.elmt_afficher.append(a) Text = sdlttf.TTF_RenderUTF8_Blended( police, str.encode(elem[position:].split(elem[fin_mots:])[0]), SDL_Color(50, 50, 150)) pos = Deb + int(position * 8.5) a = [Text, SDL_Rect(pos, Deby + P)] self.elmt_afficher.append(a) self.definitions.append([ definition[i], pos, Deby + P + 2, Deb + fin_mots * 9 + 2, P + pas + Deby ]) Text = sdlttf.TTF_RenderUTF8_Blended( police, str.encode(elem[fin_mots:]), SDL_Color(color[0], color[1], color[2])) a = [Text, SDL_Rect(Deb + fin_mots * 9 + 2, Deby + P)] self.elmt_afficher.append(a) P += pas if not afficher: #print(elem) Text = sdlttf.TTF_RenderUTF8_Blended( police, str.encode(elem), SDL_Color(color[0], color[1], color[2])) a = [Text, SDL_Rect(Deb, Deby + P)] self.elmt_afficher.append(a) P += pas sdlttf.TTF_CloseFont(police)
def test_TTF_OpenFontIndex(self): for x in range(-10, 15): font = sdlttf.TTF_OpenFontIndex(fontfile, x, 0) self.assertIsInstance(font.contents, sdlttf.TTF_Font) sdlttf.TTF_CloseFont(font)
def test_TTF_OpenCloseFont(self): for x in range(6, 26): font = sdlttf.TTF_OpenFont(fontfile, x) self.assertIsInstance(font.contents, sdlttf.TTF_Font) sdlttf.TTF_CloseFont(font)