File tree Expand file tree Collapse file tree 3 files changed +42
-0
lines changed Expand file tree Collapse file tree 3 files changed +42
-0
lines changed Original file line number Diff line number Diff line change @@ -70,6 +70,7 @@ with open("fonts/MyFont.ttf") as fh:
70
70
- [ ` get_vertical_metrics ` ] ( #get_vertical_metrics )
71
71
- [ ` get_weight ` ] ( #get_weight )
72
72
- [ ` get_width ` ] ( #get_width )
73
+ - [ ` is_monospace ` ] ( #is_monospace )
73
74
- [ ` is_static ` ] ( #is_static )
74
75
- [ ` is_variable ` ] ( #is_variable )
75
76
- [ ` rename ` ] ( #rename )
@@ -557,6 +558,17 @@ Gets the font width value and name.
557
558
width = font.get_width()
558
559
```
559
560
561
+ #### ` is_monospace `
562
+ ``` python
563
+ """
564
+ Determines if the font is a monospace font.
565
+
566
+ :returns: True if monospace font, False otherwise.
567
+ :rtype: bool
568
+ """
569
+ mono = font.is_monospace()
570
+ ```
571
+
560
572
#### ` is_static `
561
573
``` python
562
574
"""
Original file line number Diff line number Diff line change @@ -1241,6 +1241,19 @@ def get_width(
1241
1241
width ["value" ] = width_value
1242
1242
return width
1243
1243
1244
+ def is_monospace (
1245
+ self ,
1246
+ ) -> bool :
1247
+ """
1248
+ Determines if the font is a monospace font.
1249
+
1250
+ :returns: True if monospace font, False otherwise.
1251
+ :rtype: bool
1252
+ """
1253
+ font = self .get_ttfont ()
1254
+ widths = {metrics [0 ] for metrics in font ["hmtx" ].metrics .values ()}
1255
+ return len (widths ) == 1
1256
+
1244
1257
def is_static (
1245
1258
self ,
1246
1259
) -> bool :
Original file line number Diff line number Diff line change
1
+ from tests import AbstractTestCase
2
+
3
+
4
+ class MonospaceTestCase (AbstractTestCase ):
5
+ """
6
+ This class describes a monospace test case.
7
+ """
8
+
9
+ def test_is_monospace (self ):
10
+ with self ._get_font ("/Inter/static/Inter-Regular.ttf" ) as font :
11
+ self .assertFalse (font .is_monospace ())
12
+ with self ._get_font ("/Noto_Sans_TC/NotoSansTC-Regular.otf" ) as font :
13
+ self .assertFalse (font .is_monospace ())
14
+ with self ._get_font ("/Open_Sans/static/OpenSans-Regular.ttf" ) as font :
15
+ self .assertFalse (font .is_monospace ())
16
+ with self ._get_font ("/Roboto_Mono/static/RobotoMono-Regular.ttf" ) as font :
17
+ self .assertTrue (font .is_monospace ())
You can’t perform that action at this time.
0 commit comments