@@ -688,6 +688,70 @@ def test_point_size_method(self):
688688 self .assertRaises (ValueError , f .set_point_size , - 500 )
689689 self .assertRaises (TypeError , f .set_point_size , "15" )
690690
691+ def test_outline_property (self ):
692+ if pygame_font .__name__ == "pygame.ftfont" :
693+ return # not a pygame.ftfont feature
694+
695+ pygame_font .init ()
696+ font_path = os .path .join (
697+ os .path .split (pygame .__file__ )[0 ], pygame_font .get_default_font ()
698+ )
699+ f = pygame_font .Font (pathlib .Path (font_path ), 25 )
700+
701+ ttf_version = pygame_font .get_sdl_ttf_version ()
702+ if ttf_version < (2 , 0 , 12 ):
703+ with self .assertRaises (pygame .error ):
704+ f .outline = 0
705+ with self .assertRaises (pygame .error ):
706+ _ = f .outline
707+ return
708+
709+ # Default outline should be an integer >= 0 (typically 0)
710+ self .assertIsInstance (f .outline , int )
711+ self .assertGreaterEqual (f .outline , 0 )
712+
713+ orig = f .outline
714+ f .outline = orig + 1
715+ self .assertEqual (orig + 1 , f .outline )
716+ f .outline += 2
717+ self .assertEqual (orig + 3 , f .outline )
718+ f .outline -= 1
719+ self .assertEqual (orig + 2 , f .outline )
720+
721+ def test_neg ():
722+ f .outline = - 1
723+
724+ def test_incorrect_type ():
725+ f .outline = "2"
726+
727+ self .assertRaises (ValueError , test_neg )
728+ self .assertRaises (TypeError , test_incorrect_type )
729+
730+ def test_outline_method (self ):
731+ if pygame_font .__name__ == "pygame.ftfont" :
732+ return # not a pygame.ftfont feature
733+
734+ pygame_font .init ()
735+ font_path = os .path .join (
736+ os .path .split (pygame .__file__ )[0 ], pygame_font .get_default_font ()
737+ )
738+ f = pygame_font .Font (pathlib .Path (font_path ), 25 )
739+
740+ ttf_version = pygame_font .get_sdl_ttf_version ()
741+ if ttf_version < (2 , 0 , 12 ):
742+ self .assertRaises (pygame .error , f .get_outline )
743+ self .assertRaises (pygame .error , f .set_outline , 1 )
744+ return
745+
746+ val0 = f .get_outline ()
747+ self .assertIsInstance (val0 , int )
748+ self .assertGreaterEqual (val0 , 0 )
749+
750+ f .set_outline (5 )
751+ self .assertEqual (5 , f .get_outline ())
752+ self .assertRaises (ValueError , f .set_outline , - 1 )
753+ self .assertRaises (TypeError , f .set_outline , "2" )
754+
691755 def test_font_name (self ):
692756 f = pygame_font .Font (None , 20 )
693757 self .assertEqual (f .name , "FreeSans" )
@@ -936,6 +1000,14 @@ def test_font_method_should_raise_exception_after_quit(self):
9361000 ]
9371001 skip_methods = set ()
9381002 version = pygame .font .get_sdl_ttf_version ()
1003+
1004+ if version >= (2 , 0 , 12 ):
1005+ methods .append (("get_outline" , ()))
1006+ methods .append (("set_outline" , (2 ,)))
1007+ else :
1008+ skip_methods .add ("get_outline" )
1009+ skip_methods .add ("set_outline" )
1010+
9391011 if version >= (2 , 0 , 18 ):
9401012 methods .append (("get_point_size" , ()))
9411013 methods .append (("set_point_size" , (34 ,)))
@@ -1035,6 +1107,11 @@ def test_font_property_should_raise_exception_after_quit(self):
10351107 else :
10361108 skip_properties .add ("point_size" )
10371109
1110+ if version >= (2 , 0 , 12 ):
1111+ properties .append (("outline" , 1 ))
1112+ else :
1113+ skip_properties .add ("outline" )
1114+
10381115 font = pygame_font .Font (None , 10 )
10391116 actual_names = []
10401117
@@ -1099,6 +1176,7 @@ def query(
10991176 underline = False ,
11001177 strikethrough = False ,
11011178 antialiase = False ,
1179+ outline = 0
11021180 ):
11031181 if self .aborted :
11041182 return False
@@ -1109,7 +1187,7 @@ def query(
11091187 screen = self .screen
11101188 screen .fill ((255 , 255 , 255 ))
11111189 pygame .display .flip ()
1112- if not (bold or italic or underline or strikethrough or antialiase ):
1190+ if not (bold or italic or underline or strikethrough or antialiase or outline ):
11131191 text = "normal"
11141192 else :
11151193 modes = []
@@ -1123,18 +1201,22 @@ def query(
11231201 modes .append ("strikethrough" )
11241202 if antialiase :
11251203 modes .append ("antialiased" )
1204+ if outline :
1205+ modes .append ("outlined" )
11261206 text = f"{ '-' .join (modes )} (y/n):"
11271207 f .set_bold (bold )
11281208 f .set_italic (italic )
11291209 f .set_underline (underline )
11301210 f .set_strikethrough (strikethrough )
1211+ f .set_outline (outline )
11311212 s = f .render (text , antialiase , (0 , 0 , 0 ))
11321213 screen .blit (s , (offset , y ))
11331214 y += s .get_size ()[1 ] + spacing
11341215 f .set_bold (False )
11351216 f .set_italic (False )
11361217 f .set_underline (False )
11371218 f .set_strikethrough (False )
1219+ f .set_outline (0 )
11381220 s = f .render ("(some comparison text)" , False , (0 , 0 , 0 ))
11391221 screen .blit (s , (offset , y ))
11401222 pygame .display .flip ()
@@ -1176,6 +1258,9 @@ def test_italic_underline(self):
11761258 def test_bold_strikethrough (self ):
11771259 self .assertTrue (self .query (bold = True , strikethrough = True ))
11781260
1261+ def test_outline (self ):
1262+ self .assertTrue (self .query (outline = 1 ))
1263+
11791264
11801265if __name__ == "__main__" :
11811266 unittest .main ()
0 commit comments