8000 Add `is_color` method. · fabiocaccamo/python-fontbro@ef75f95 · GitHub
[go: up one dir, main page]

Skip to content

Commit ef75f95

Browse files
committed
Add is_color method.
1 parent 15b6a15 commit ef75f95

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

README.md

+12
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ with open("fonts/MyFont.ttf") as fh:
7171
- [`get_vertical_metrics`](#get_vertical_metrics)
7272
- [`get_weight`](#get_weight)
7373
- [`get_width`](#get_width)
74+
- [`is_color`](#is_color)
7475
- [`is_monospace`](#is_monospace)
7576
- [`is_static`](#is_static)
7677
- [`is_variable`](#is_variable)
@@ -580,6 +581,17 @@ Gets the font width value and name.
580581
width = font.get_width()
581582
```
582583

584+
#### `is_color`
585+
```python
586+
"""
587+
Determines if the font is a color font.
588+
589+
:returns: True if color font, False otherwise.
590+
:rtype: bool
591+
"""
592+
color = font.is_color()
593+
```
594+
583595
#### `is_monospace`
584596
```python
585597
"""

fontbro/font.py

+14
Original file line numberDiff line numberDiff line change
@@ -1451,6 +1451,20 @@ def get_width(
14511451
width["value"] = width_value
14521452
return width
14531453

1454+
def is_color(self) -> bool:
1455+
"""
1456+
Determines if the font is a color font.
1457+
1458+
:returns: True if color font, False otherwise.
1459+
:rtype: bool
1460+
"""
1461+
font = self.get_ttfont()
1462+
tables = {"COLR", "CPAL", "CBDT", "CBLC"}
1463+
for table in tables:
1464+
if table in font:
1465+
return True
1466+
return False
1467+
14541468
def is_monospace(
14551469
self,
14561470
threshold: float = 0.85,

0 commit comments

Comments
 (0)
0