@@ -1202,3 +1202,45 @@ def test_ytick_rotation_mode():
1202
1202
tick .set_rotation (angle )
1203
1203
1204
1204
plt .subplots_adjust (left = 0.4 , right = 0.6 , top = .99 , bottom = .01 )
1205
+
1206
+
1207
+ @pytest .mark .parametrize (
1208
+ 'input, match' ,
1209
+ [
1210
+ ([1 , 2 , 3 ], 'must be list of tuple' ),
1211
+ ([(1 , 2 )], 'must be list of tuple' ),
1212
+ ([('en' , 'foo' , 2 )], 'start location must be int' ),
1213
+ ([('en' , 1 , 'foo' )], 'end location must be int' ),
1214
+ ],
1215
+ )
1216
+ def test_text_language_invalid (input , match ):
1217
+ with pytest .raises (TypeError , match = match ):
1218
+ Text (0 , 0 , 'foo' , language = input )
1219
+
1220
+
1221
+ @image_comparison (baseline_images = ['language.png' ], remove_text = False , style = 'mpl20' )
1222
+ def test_text_language ():
1223
+ fig = plt .figure (figsize = (5 , 3 ))
1224
+
1225
+ fig .text (0 , 0.8 , 'Default' , fontsize = 32 )
1226
+ fig .text (0 , 0.55 , 'Lang A' , fontsize = 32 )
1227
+ fig .text (0 , 0.3 , 'Lang B' , fontsize = 32 )
1228
+ fig .text (0 , 0.05 , 'Mixed' , fontsize = 32 )
1229
+
1230
+ # DejaVu Sans supports language-specific glyphs in the Serbian and Macedonian
1231
+ # languages in the Cyrillic alphabet.
1232
+ cyrillic = '\U00000431 '
1233
+ fig .text (0.4 , 0.8 , cyrillic , fontsize = 32 )
1234
+ fig .text (0.4 , 0.55 , cyrillic , fontsize = 32 , language = 'sr' )
1235
+ fig .text (0.4 , 0.3 , cyrillic , fontsize = 32 ).set_language ('ru' )
1236
+ fig .text (0.4 , 0.05 , cyrillic * 4 , fontsize = 32 ,
1237
+ language = [('ru' , 0 , 1 ), ('sr' , 1 , 2 ), ('ru' , 2 , 3 ), ('sr' , 3 , 4 )])
1238
+
1239
+ # Or the Sámi family of languages in the Latin alphabet.
1240
+ latin = '\U0000014a '
1241
+ fig .text (0.7 , 0.8 , latin , fontsize = 32 )
1242
+ fig .text (0.7 , 0.55 , latin , fontsize = 32 , language = 'en' )
1243
+ fig .text (0.7 , 0.3 , latin , fontsize = 32 , language = 'smn' )
1244
+ # Tuples are not documented, but we'll allow it.
1245
+ fig .text (0.7 , 0.05 , latin * 4 , fontsize = 32 ).set_language (
1246
+ (('en' , 0 , 1 ), ('smn' , 1 , 2 ), ('en' , 2 , 3 ), ('smn' , 3 , 4 )))
0 commit comments