@@ -29,6 +29,102 @@ def test_ft2image_draw_rect_filled():
29
29
assert np .sum (a ) == 255 * filled
30
30
31
31
32
+ def test_ft2font_dejavu_attrs ():
33
+ file = fm .findfont ('DejaVu Sans' )
34
+ font = ft2font .FT2Font (file )
35
+ assert font .fname == file
36
+ # Names extracted from FontForge: Font Information → PS Names tab.
37
+ assert font .postscript_name == 'DejaVuSans'
38
+ assert font .family_name == 'DejaVu Sans'
39
+ assert font .style_name == 'Book'
40
+ assert font .num_faces == 1 # Single TTF.
41
+ assert font .num_glyphs == 6241 # From compact encoding view in FontForge.
42
+ assert font .num_fixed_sizes == 0 # All glyphs are scalable.
43
+ assert font .num_charmaps == 5
44
+ # Other internal flags are set, so only check the ones we're allowed to test.
45
+ expected_flags = (ft2font .SCALABLE | ft2font .SFNT | ft2font .HORIZONTAL |
46
+ ft2font .KERNING | ft2font .GLYPH_NAMES )
47
+ assert (font .face_flags & expected_flags ) == expected_flags
48
+ assert font .style_flags == 0 # Not italic or bold.
49
+ assert font .scalable
50
+ # From FontForge: Font Information → General tab → entry name below.
51
+ assert font .units_per_EM == 2048 # Em Size.
52
+ assert font .underline_position == - 175 # Underline position.
53
+ assert font .underline_thickness == 90 # Underline height.
54
+ # From FontForge: Font Information → OS/2 tab → Metrics tab → entry name below.
55
+ assert font .ascender == 1901 # HHead Ascent.
56
+ assert font .descender == - 483 # HHead Descent.
57
+ # Unconfirmed values.
58
+ assert font .height == 2384
59
+ assert font .max_advance_width == 3838
60
+ assert font .max_advance_height == 2384
61
+ assert font .bbox == (- 2090 , - 948 , 3673 , 2524 )
62
+
63
+
64
+ def test_ft2font_cm_attrs ():
65
+ file = fm .findfont ('cmtt10' )
66
+ font = ft2font .FT2Font (file )
67
+ assert font .fname == file
68
+ # Names extracted from FontForge: Font Information → PS Names tab.
69
+ assert font .postscript_name == 'Cmtt10'
70
+ assert font .family_name == 'cmtt10'
71
+ assert font .style_name == 'Regular'
72
+ assert font .num_faces == 1 # Single TTF.
73
+ assert font .num_glyphs == 133 # From compact encoding view in FontForge.
74
+ assert font .num_fixed_sizes == 0 # All glyphs are scalable.
75
+ assert font .num_charmaps == 2
76
+ # Other internal flags are set, so only check the ones we're allowed to test.
77
+ expected_flags = (ft2font .SCALABLE | ft2font .SFNT | ft2font .HORIZONTAL |
78
+ ft2font .GLYPH_NAMES )
79
+ assert (font .face_flags & expected_flags ) == expected_flags , font .face_flags
80
+ assert font .style_flags == 0 # Not italic or bold.
81
+ assert font .scalable
82
+ # From FontForge: Font Information → General tab → entry name below.
83
+ assert font .units_per_EM == 2048 # Em Size.
84
+ assert font .underline_position == - 143 # Underline position.
85
+ assert font .underline_thickness == 20 # Underline height.
86
+ # From FontForge: Font Information → OS/2 tab → Metrics tab → entry name below.
87
+ assert font .ascender == 1276 # HHead Ascent.
88
+ assert font .descender == - 489 # HHead Descent.
89
+ # Unconfirmed values.
90
+ assert font .height == 1765
91
+ assert font .max_advance_width == 1536
92
+ assert font .max_advance_height == 1765
93
+ assert font .bbox == (- 12 , - 477 , 1280 , 1430 )
94
+
95
+
96
+ def test_ft2font_stix_bold_attrs ():
97
+ file = fm .findfont ('STIXSizeTwoSym:bold' )
98
+ font = ft2font .FT2Font (file )
99
+ assert font .fname == file
100
+ # Names extracted from FontForge: Font Information → PS Names tab.
101
+ assert font .postscript_name == 'STIXSizeTwoSym-Bold'
102
+ assert font .family_name == 'STIXSizeTwoSym'
103
+ assert font .style_name == 'Bold'
104
+ assert font .num_faces == 1 # Single TTF.
105
+ assert font .num_glyphs == 20 # From compact encoding view in FontForge.
106
+ assert font .num_fixed_sizes == 0 # All glyphs are scalable.
107
+ assert font .num_charmaps == 3
108
+ # Other internal flags are set, so only check the ones we're allowed to test.
109
+ expected_flags = (ft2font .SCALABLE | ft2font .SFNT | ft2font .HORIZONTAL |
110
+ ft2font .GLYPH_NAMES )
111
+ assert (font .face_flags & expected_flags ) == expected_flags , font .face_flags
112
+ assert font .style_flags == ft2font .BOLD
113
+ assert font .scalable
114
+ # From FontForge: Font Information → General tab → entry name below.
115
+ assert font .units_per_EM == 1000 # Em Size.
116
+ assert font .underline_position == - 133 # Underline position.
117
+ assert font .underline_thickness == 20 # Underline height.
118
+ # From FontForge: Font Information → OS/2 tab → Metrics tab → entry name below.
119
+ assert font .ascender == 2095 # HHead Ascent.
120
+ assert font .descender == - 404 # HHead Descent.
121
+ # Unconfirmed values.
122
+ assert font .height == 2499
123
+ assert font .max_advance_width == 1130
124
+ assert font .max_advance_height == 2499
125
+ assert font .bbox == (4 , - 355 , 1185 , 2095 )
126
+
127
+
32
128
def test_fallback_errors ():
33
129
file_name = fm .findfont ('DejaVu Sans' )
34
130
0 commit comments