fix: bug fix in `char_in_font` detection
Browse files- font_dataset/helper.py +9 -6
font_dataset/helper.py
CHANGED
|
@@ -5,9 +5,12 @@ __all__ = ["char_in_font"]
|
|
| 5 |
|
| 6 |
|
| 7 |
def char_in_font(unicode_char, font_path):
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
if
|
| 12 |
-
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
|
| 7 |
def char_in_font(unicode_char, font_path):
|
| 8 |
+
try:
|
| 9 |
+
font = TTFont(font_path, fontNumber=0)
|
| 10 |
+
for cmap in font["cmap"].tables:
|
| 11 |
+
if cmap.isUnicode():
|
| 12 |
+
if ord(unicode_char) in cmap.cmap:
|
| 13 |
+
return True
|
| 14 |
+
return False
|
| 15 |
+
except Exception as e:
|
| 16 |
+
return False
|