@@ -685,6 +685,70 @@ def test_point_size_method(self):
685685 self .assertRaises (ValueError , f .set_point_size , - 500 )
686686 self .assertRaises (TypeError , f .set_point_size , "15" )
687687
688+ def test_outline_property (self ):
689+ if pygame_font .__name__ == "pygame.ftfont" :
690+ return # not a pygame.ftfont feature
691+
692+ pygame_font .init ()
693+ font_path = os .path .join (
694+ os .path .split (pygame .__file__ )[0 ], pygame_font .get_default_font ()
695+ )
696+ f = pygame_font .Font (pathlib .Path (font_path ), 25 )
697+
698+ ttf_version = pygame_font .get_sdl_ttf_version ()
699+ if ttf_version < (2 , 0 , 12 ):
700+ with self .assertRaises (pygame .error ):
701+ f .outline = 0
702+ with self .assertRaises (pygame .error ):
703+ _ = f .outline
704+ return
705+
706+ # Default outline should be an integer >= 0 (typically 0)
707+ self .assertIsInstance (f .outline , int )
708+ self .assertGreaterEqual (f .outline , 0 )
709+
710+ orig = f .outline
711+ f .outline = orig + 1
712+ self .assertEqual (orig + 1 , f .outline )
713+ f .outline += 2
714+ self .assertEqual (orig + 3 , f .outline )
715+ f .outline -= 1
716+ self .assertEqual (orig + 2 , f .outline )
717+
718+ def test_neg ():
719+ f .outline = - 1
720+
721+ def test_incorrect_type ():
722+ f .outline = "2"
723+
724+ self .assertRaises (ValueError , test_neg )
725+ self .assertRaises (TypeError , test_incorrect_type )
726+
727+ def test_outline_method (self ):
728+ if pygame_font .__name__ == "pygame.ftfont" :
729+ return # not a pygame.ftfont feature
730+
731+ pygame_font .init ()
732+ font_path = os .path .join (
733+ os .path .split (pygame .__file__ )[0 ], pygame_font .get_default_font ()
734+ )
735+ f = pygame_font .Font (pathlib .Path (font_path ), 25 )
736+
737+ ttf_version = pygame_font .get_sdl_ttf_version ()
738+ if ttf_version < (2 , 0 , 12 ):
739+ self .assertRaises (pygame .error , f .get_outline )
740+ self .assertRaises (pygame .error , f .set_outline , 1 )
741+ return
742+
743+ val0 = f .get_outline ()
744+ self .assertIsInstance (val0 , int )
745+ self .assertGreaterEqual (val0 , 0 )
746+
747+ f .set_outline (5 )
748+ self .assertEqual (5 , f .get_outline ())
749+ self .assertRaises (ValueError , f .set_outline , - 1 )
750+ self .assertRaises (TypeError , f .set_outline , "2" )
751+
688752 def test_font_name (self ):
689753 f = pygame_font .Font (None , 20 )
690754 self .assertEqual (f .name , "FreeSans" )
@@ -933,6 +997,14 @@ def test_font_method_should_raise_exception_after_quit(self):
933997 ]
934998 skip_methods = set ()
935999 version = pygame .font .get_sdl_ttf_version ()
1000+
1001+ if version >= (2 , 0 , 12 ):
1002+ methods .append (("get_outline" , ()))
1003+ methods .append (("set_outline" , (2 ,)))
1004+ else :
1005+ skip_methods .add ("get_outline" )
1006+ skip_methods .add ("set_outline" )
1007+
9361008 if version >= (2 , 0 , 18 ):
9371009 methods .append (("get_point_size" , ()))
9381010 methods .append (("set_point_size" , (34 ,)))
@@ -1032,6 +1104,11 @@ def test_font_property_should_raise_exception_after_quit(self):
10321104 else :
10331105 skip_properties .add ("point_size" )
10341106
1107+ if version >= (2 , 0 , 12 ):
1108+ properties .append (("outline" , 1 ))
1109+ else :
1110+ skip_properties .add ("outline" )
1111+
10351112 font = pygame_font .Font (None , 10 )
10361113 actual_names = []
10371114
@@ -1096,6 +1173,7 @@ def query(
10961173 underline = False ,
10971174 strikethrough = False ,
10981175 antialiase = False ,
1176+ outline = 0
10991177 ):
11001178 if self .aborted :
11011179 return False
@@ -1106,7 +1184,7 @@ def query(
11061184 screen = self .screen
11071185 screen .fill ((255 , 255 , 255 ))
11081186 pygame .display .flip ()
1109- if not (bold or italic or underline or strikethrough or antialiase ):
1187+ if not (bold or italic or underline or strikethrough or antialiase or outline ):
11101188 text = "normal"
11111189 else :
11121190 modes = []
@@ -1120,18 +1198,22 @@ def query(
11201198 modes .append ("strikethrough" )
11211199 if antialiase :
11221200 modes .append ("antialiased" )
1201+ if outline :
1202+ modes .append ("outlined" )
11231203 text = f"{ '-' .join (modes )} (y/n):"
11241204 f .set_bold (bold )
11251205 f .set_italic (italic )
11261206 f .set_underline (underline )
11271207 f .set_strikethrough (strikethrough )
1208+ f .set_outline (outline )
11281209 s = f .render (text , antialiase , (0 , 0 , 0 ))
11291210 screen .blit (s , (offset , y ))
11301211 y += s .get_size ()[1 ] + spacing
11311212 f .set_bold (False )
11321213 f .set_italic (False )
11331214 f .set_underline (False )
11341215 f .set_strikethrough (False )
1216+ f .set_outline (0 )
11351217 s = f .render ("(some comparison text)" , False , (0 , 0 , 0 ))
11361218 screen .blit (s , (offset , y ))
11371219 pygame .display .flip ()
@@ -1173,6 +1255,9 @@ def test_italic_underline(self):
11731255 def test_bold_strikethrough (self ):
11741256 self .assertTrue (self .query (bold = True , strikethrough = True ))
11751257
1258+ def test_outline (self ):
1259+ self .assertTrue (self .query (outline = 1 ))
1260+
11761261
11771262if __name__ == "__main__" :
11781263 unittest .main ()
0 commit comments