@@ -685,6 +685,70 @@ def test_point_size_method(self):
685
685
self .assertRaises (ValueError , f .set_point_size , - 500 )
686
686
self .assertRaises (TypeError , f .set_point_size , "15" )
687
687
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
+
688
752
def test_font_name (self ):
689
753
f = pygame_font .Font (None , 20 )
690
754
self .assertEqual (f .name , "FreeSans" )
@@ -933,6 +997,14 @@ def test_font_method_should_raise_exception_after_quit(self):
933
997
]
934
998
skip_methods = set ()
935
999
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
+
936
1008
if version >= (2 , 0 , 18 ):
937
1009
methods .append (("get_point_size" , ()))
938
1010
methods .append (("set_point_size" , (34 ,)))
@@ -1032,6 +1104,11 @@ def test_font_property_should_raise_exception_after_quit(self):
1032
1104
else :
1033
1105
skip_properties .add ("point_size" )
1034
1106
1107
+ if version >= (2 , 0 , 12 ):
1108
+ properties .append (("outline" , 1 ))
1109
+ else :
1110
+ skip_properties .add ("outline" )
1111
+
1035
1112
font = pygame_font .Font (None , 10 )
1036
1113
actual_names = []
1037
1114
@@ -1096,6 +1173,7 @@ def query(
1096
1173
underline = False ,
1097
1174
strikethrough = False ,
1098
1175
antialiase = False ,
1176
+ outline = 0
1099
1177
):
1100
1178
if self .aborted :
1101
1179
return False
@@ -1106,7 +1184,7 @@ def query(
1106
1184
screen = self .screen
1107
1185
screen .fill ((255 , 255 , 255 ))
1108
1186
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 ):
1110
1188
text = "normal"
1111
1189
else :
1112
1190
modes = []
@@ -1120,18 +1198,22 @@ def query(
1120
1198
modes .append ("strikethrough" )
1121
1199
if antialiase :
1122
1200
modes .append ("antialiased" )
1201
+ if outline :
1202
+ modes .append ("outlined" )
1123
1203
text = f"{ '-' .join (modes )} (y/n):"
1124
1204
f .set_bold (bold )
1125
1205
f .set_italic (italic )
1126
1206
f .set_underline (underline )
1127
1207
f .set_strikethrough (strikethrough )
1208
+ f .set_outline (outline )
1128
1209
s = f .render (text , antialiase , (0 , 0 , 0 ))
1129
1210
screen .blit (s , (offset , y ))
1130
1211
y += s .get_size ()[1 ] + spacing
1131
1212
f .set_bold (False )
1132
1213
f .set_italic (False )
1133
1214
f .set_underline (False )
1134
1215
f .set_strikethrough (False )
1216
+ f .set_outline (0 )
1135
1217
s = f .render ("(some comparison text)" , False , (0 , 0 , 0 ))
1136
1218
screen .blit (s , (offset , y ))
1137
1219
pygame .display .flip ()
@@ -1173,6 +1255,9 @@ def test_italic_underline(self):
1173
1255
def test_bold_strikethrough (self ):
1174
1256
self .assertTrue (self .query (bold = True , strikethrough = True ))
1175
1257
1258
+ def test_outline (self ):
1259
+ self .assertTrue (self .query (outline = 1 ))
1260
+
1176
1261
1177
1262
if __name__ == "__main__" :
1178
1263
unittest .main ()
0 commit comments