python-fontbro 0.23.0__tar.gz → 0.24.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {python_fontbro-0.23.0/python_fontbro.egg-info → python_fontbro-0.24.0}/PKG-INFO +34 -1
- {python_fontbro-0.23.0 → python_fontbro-0.24.0}/README.md +33 -0
- {python_fontbro-0.23.0 → python_fontbro-0.24.0}/fontbro/font.py +84 -3
- {python_fontbro-0.23.0 → python_fontbro-0.24.0}/fontbro/metadata.py +1 -1
- {python_fontbro-0.23.0 → python_fontbro-0.24.0/python_fontbro.egg-info}/PKG-INFO +34 -1
- {python_fontbro-0.23.0 → python_fontbro-0.24.0}/python_fontbro.egg-info/SOURCES.txt +2 -0
- python_fontbro-0.24.0/tests/test_color.py +21 -0
- {python_fontbro-0.23.0 → python_fontbro-0.24.0}/tests/test_monospace.py +1 -1
- {python_fontbro-0.23.0 → python_fontbro-0.24.0}/tests/test_sanitize.py +3 -2
- python_fontbro-0.24.0/tests/test_svg.py +20 -0
- {python_fontbro-0.23.0 → python_fontbro-0.24.0}/LICENSE.txt +0 -0
- {python_fontbro-0.23.0 → python_fontbro-0.24.0}/MANIFEST.in +0 -0
- {python_fontbro-0.23.0 → python_fontbro-0.24.0}/fontbro/__init__.py +0 -0
- {python_fontbro-0.23.0 → python_fontbro-0.24.0}/fontbro/data/family-classifications.json +0 -0
- {python_fontbro-0.23.0 → python_fontbro-0.24.0}/fontbro/data/features.json +0 -0
- {python_fontbro-0.23.0 → python_fontbro-0.24.0}/fontbro/data/unicode-blocks.json +0 -0
- {python_fontbro-0.23.0 → python_fontbro-0.24.0}/fontbro/data/unicode-scripts.json +0 -0
- {python_fontbro-0.23.0 → python_fontbro-0.24.0}/fontbro/exceptions.py +0 -0
- {python_fontbro-0.23.0 → python_fontbro-0.24.0}/fontbro/flags.py +0 -0
- {python_fontbro-0.23.0 → python_fontbro-0.24.0}/fontbro/math.py +0 -0
- {python_fontbro-0.23.0 → python_fontbro-0.24.0}/fontbro/py.typed +0 -0
- {python_fontbro-0.23.0 → python_fontbro-0.24.0}/fontbro/subset.py +0 -0
- {python_fontbro-0.23.0 → python_fontbro-0.24.0}/fontbro/utils.py +0 -0
- {python_fontbro-0.23.0 → python_fontbro-0.24.0}/pyproject.toml +0 -0
- {python_fontbro-0.23.0 → python_fontbro-0.24.0}/python_fontbro.egg-info/dependency_links.txt +0 -0
- {python_fontbro-0.23.0 → python_fontbro-0.24.0}/python_fontbro.egg-info/requires.txt +0 -0
- {python_fontbro-0.23.0 → python_fontbro-0.24.0}/python_fontbro.egg-info/top_level.txt +0 -0
- {python_fontbro-0.23.0 → python_fontbro-0.24.0}/setup.cfg +0 -0
- {python_fontbro-0.23.0 → python_fontbro-0.24.0}/setup.py +0 -0
- {python_fontbro-0.23.0 → python_fontbro-0.24.0}/tests/test_characters.py +0 -0
- {python_fontbro-0.23.0 → python_fontbro-0.24.0}/tests/test_clone.py +0 -0
- {python_fontbro-0.23.0 → python_fontbro-0.24.0}/tests/test_close.py +0 -0
- {python_fontbro-0.23.0 → python_fontbro-0.24.0}/tests/test_collection.py +0 -0
- {python_fontbro-0.23.0 → python_fontbro-0.24.0}/tests/test_context_manager.py +0 -0
- {python_fontbro-0.23.0 → python_fontbro-0.24.0}/tests/test_family_classification.py +0 -0
- {python_fontbro-0.23.0 → python_fontbro-0.24.0}/tests/test_family_name.py +0 -0
- {python_fontbro-0.23.0 → python_fontbro-0.24.0}/tests/test_features.py +0 -0
- {python_fontbro-0.23.0 → python_fontbro-0.24.0}/tests/test_filename.py +0 -0
- {python_fontbro-0.23.0 → python_fontbro-0.24.0}/tests/test_fingerprint.py +0 -0
- {python_fontbro-0.23.0 → python_fontbro-0.24.0}/tests/test_format.py +0 -0
- {python_fontbro-0.23.0 → python_fontbro-0.24.0}/tests/test_glyphs.py +0 -0
- {python_fontbro-0.23.0 → python_fontbro-0.24.0}/tests/test_image.py +0 -0
- {python_fontbro-0.23.0 → python_fontbro-0.24.0}/tests/test_init.py +0 -0
- {python_fontbro-0.23.0 → python_fontbro-0.24.0}/tests/test_instantiation.py +0 -0
- {python_fontbro-0.23.0 → python_fontbro-0.24.0}/tests/test_issues.py +0 -0
- {python_fontbro-0.23.0 → python_fontbro-0.24.0}/tests/test_italic_angle.py +0 -0
- {python_fontbro-0.23.0 → python_fontbro-0.24.0}/tests/test_names.py +0 -0
- {python_fontbro-0.23.0 → python_fontbro-0.24.0}/tests/test_rename.py +0 -0
- {python_fontbro-0.23.0 → python_fontbro-0.24.0}/tests/test_save.py +0 -0
- {python_fontbro-0.23.0 → python_fontbro-0.24.0}/tests/test_str.py +0 -0
- {python_fontbro-0.23.0 → python_fontbro-0.24.0}/tests/test_style_flags.py +0 -0
- {python_fontbro-0.23.0 → python_fontbro-0.24.0}/tests/test_style_name.py +0 -0
- {python_fontbro-0.23.0 → python_fontbro-0.24.0}/tests/test_subset.py +0 -0
- {python_fontbro-0.23.0 → python_fontbro-0.24.0}/tests/test_unicode_blocks_and_scripts.py +0 -0
- {python_fontbro-0.23.0 → python_fontbro-0.24.0}/tests/test_update_unicode_data.py +0 -0
- {python_fontbro-0.23.0 → python_fontbro-0.24.0}/tests/test_variable.py +0 -0
- {python_fontbro-0.23.0 → python_fontbro-0.24.0}/tests/test_version.py +0 -0
- {python_fontbro-0.23.0 → python_fontbro-0.24.0}/tests/test_vertical_metrics.py +0 -0
- {python_fontbro-0.23.0 → python_fontbro-0.24.0}/tests/test_weight.py +0 -0
- {python_fontbro-0.23.0 → python_fontbro-0.24.0}/tests/test_width.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: python-fontbro
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.24.0
|
|
4
4
|
Summary: friendly font operations on top of fontTools.
|
|
5
5
|
Author-email: Fabio Caccamo <fabio.caccamo@gmail.com>
|
|
6
6
|
Maintainer-email: Fabio Caccamo <fabio.caccamo@gmail.com>
|
|
@@ -118,6 +118,7 @@ with open("fonts/MyFont.ttf") as fh:
|
|
|
118
118
|
- [`get_style_flag`](#get_style_flag)
|
|
119
119
|
- [`get_style_flags`](#get_style_flags)
|
|
120
120
|
- [`get_style_name`](#get_style_name)
|
|
121
|
+
- [`get_svg`](#get_svg)
|
|
121
122
|
- [`get_ttfont`](#get_ttfont)
|
|
122
123
|
- [`get_unicode_block_by_name`](#get_unicode_block_by_name)
|
|
123
124
|
- [`get_unicode_blocks`](#get_unicode_blocks)
|
|
@@ -133,6 +134,7 @@ with open("fonts/MyFont.ttf") as fh:
|
|
|
133
134
|
- [`get_vertical_metrics`](#get_vertical_metrics)
|
|
134
135
|
- [`get_weight`](#get_weight)
|
|
135
136
|
- [`get_width`](#get_width)
|
|
137
|
+
- [`is_color`](#is_color)
|
|
136
138
|
- [`is_monospace`](#is_monospace)
|
|
137
139
|
- [`is_static`](#is_static)
|
|
138
140
|
- [`is_variable`](#is_variable)
|
|
@@ -449,6 +451,23 @@ Gets the style name reading the name records with priority order (17, 22, 2).
|
|
|
449
451
|
style_name = font.get_style_name()
|
|
450
452
|
```
|
|
451
453
|
|
|
454
|
+
#### `get_svg`
|
|
455
|
+
```python
|
|
456
|
+
"""
|
|
457
|
+
Gets an SVG representation of the font rendering
|
|
458
|
+
some text using the given options.
|
|
459
|
+
|
|
460
|
+
:param text: The text to be rendered as SVG paths.
|
|
461
|
+
:type text: str
|
|
462
|
+
:param size: The size of the font to be used for rendering the text, in points.
|
|
463
|
+
:type size: int
|
|
464
|
+
|
|
465
|
+
:returns: An SVG string that represents the rendered text.
|
|
466
|
+
:rtype: str
|
|
467
|
+
"""
|
|
468
|
+
svg_str = font.get_svg(text="Hello!", size=48)
|
|
469
|
+
```
|
|
470
|
+
|
|
452
471
|
#### `get_ttfont`
|
|
453
472
|
```python
|
|
454
473
|
"""
|
|
@@ -642,11 +661,25 @@ Gets the font width value and name.
|
|
|
642
661
|
width = font.get_width()
|
|
643
662
|
```
|
|
644
663
|
|
|
664
|
+
#### `is_color`
|
|
665
|
+
```python
|
|
666
|
+
"""
|
|
667
|
+
Determines if the font is a color font.
|
|
668
|
+
|
|
669
|
+
:returns: True if color font, False otherwise.
|
|
670
|
+
:rtype: bool
|
|
671
|
+
"""
|
|
672
|
+
color = font.is_color()
|
|
673
|
+
```
|
|
674
|
+
|
|
645
675
|
#### `is_monospace`
|
|
646
676
|
```python
|
|
647
677
|
"""
|
|
648
678
|
Determines if the font is a monospace font.
|
|
649
679
|
|
|
680
|
+
:param threshold: The threshold (0.0 <= n <= 1.0) of glyphs with the same width to consider the font as monospace.
|
|
681
|
+
:type threshold: float
|
|
682
|
+
|
|
650
683
|
:returns: True if monospace font, False otherwise.
|
|
651
684
|
:rtype: bool
|
|
652
685
|
"""
|
|
@@ -56,6 +56,7 @@ with open("fonts/MyFont.ttf") as fh:
|
|
|
56
56
|
- [`get_style_flag`](#get_style_flag)
|
|
57
57
|
- [`get_style_flags`](#get_style_flags)
|
|
58
58
|
- [`get_style_name`](#get_style_name)
|
|
59
|
+
- [`get_svg`](#get_svg)
|
|
59
60
|
- [`get_ttfont`](#get_ttfont)
|
|
60
61
|
- [`get_unicode_block_by_name`](#get_unicode_block_by_name)
|
|
61
62
|
- [`get_unicode_blocks`](#get_unicode_blocks)
|
|
@@ -71,6 +72,7 @@ with open("fonts/MyFont.ttf") as fh:
|
|
|
71
72
|
- [`get_vertical_metrics`](#get_vertical_metrics)
|
|
72
73
|
- [`get_weight`](#get_weight)
|
|
73
74
|
- [`get_width`](#get_width)
|
|
75
|
+
- [`is_color`](#is_color)
|
|
74
76
|
- [`is_monospace`](#is_monospace)
|
|
75
77
|
- [`is_static`](#is_static)
|
|
76
78
|
- [`is_variable`](#is_variable)
|
|
@@ -387,6 +389,23 @@ Gets the style name reading the name records with priority order (17, 22, 2).
|
|
|
387
389
|
style_name = font.get_style_name()
|
|
388
390
|
```
|
|
389
391
|
|
|
392
|
+
#### `get_svg`
|
|
393
|
+
```python
|
|
394
|
+
"""
|
|
395
|
+
Gets an SVG representation of the font rendering
|
|
396
|
+
some text using the given options.
|
|
397
|
+
|
|
398
|
+
:param text: The text to be rendered as SVG paths.
|
|
399
|
+
:type text: str
|
|
400
|
+
:param size: The size of the font to be used for rendering the text, in points.
|
|
401
|
+
:type size: int
|
|
402
|
+
|
|
403
|
+
:returns: An SVG string that represents the rendered text.
|
|
404
|
+
:rtype: str
|
|
405
|
+
"""
|
|
406
|
+
svg_str = font.get_svg(text="Hello!", size=48)
|
|
407
|
+
```
|
|
408
|
+
|
|
390
409
|
#### `get_ttfont`
|
|
391
410
|
```python
|
|
392
411
|
"""
|
|
@@ -580,11 +599,25 @@ Gets the font width value and name.
|
|
|
580
599
|
width = font.get_width()
|
|
581
600
|
```
|
|
582
601
|
|
|
602
|
+
#### `is_color`
|
|
603
|
+
```python
|
|
604
|
+
"""
|
|
605
|
+
Determines if the font is a color font.
|
|
606
|
+
|
|
607
|
+
:returns: True if color font, False otherwise.
|
|
608
|
+
:rtype: bool
|
|
609
|
+
"""
|
|
610
|
+
color = font.is_color()
|
|
611
|
+
```
|
|
612
|
+
|
|
583
613
|
#### `is_monospace`
|
|
584
614
|
```python
|
|
585
615
|
"""
|
|
586
616
|
Determines if the font is a monospace font.
|
|
587
617
|
|
|
618
|
+
:param threshold: The threshold (0.0 <= n <= 1.0) of glyphs with the same width to consider the font as monospace.
|
|
619
|
+
:type threshold: float
|
|
620
|
+
|
|
588
621
|
:returns: True if monospace font, False otherwise.
|
|
589
622
|
:rtype: bool
|
|
590
623
|
"""
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
3
|
import copy
|
|
4
|
+
import math
|
|
4
5
|
import os
|
|
5
6
|
import re
|
|
6
7
|
import sys
|
|
7
8
|
import tempfile
|
|
9
|
+
from collections import Counter
|
|
8
10
|
from curses import ascii
|
|
9
11
|
from io import BytesIO
|
|
10
12
|
from pathlib import Path
|
|
@@ -13,6 +15,7 @@ from typing.io import IO
|
|
|
13
15
|
import fsutil
|
|
14
16
|
import ots
|
|
15
17
|
from fontTools import unicodedata
|
|
18
|
+
from fontTools.pens.svgPathPen import SVGPathPen
|
|
16
19
|
from fontTools.subset import Options as SubsetterOptions
|
|
17
20
|
from fontTools.subset import Subsetter
|
|
18
21
|
from fontTools.ttLib import TTCollection, TTFont, TTLibError
|
|
@@ -812,7 +815,7 @@ class Font:
|
|
|
812
815
|
format_ = ""
|
|
813
816
|
if flavor in [self.FORMAT_WOFF, self.FORMAT_WOFF2] and not ignore_flavor:
|
|
814
817
|
format_ = str(flavor)
|
|
815
|
-
elif version == "OTTO" and "CFF " in font:
|
|
818
|
+
elif version == "OTTO" and ("CFF " in font or "CFF2" in font):
|
|
816
819
|
format_ = self.FORMAT_OTF
|
|
817
820
|
elif version == "\0\1\0\0":
|
|
818
821
|
format_ = self.FORMAT_TTF
|
|
@@ -1032,6 +1035,61 @@ class Font:
|
|
|
1032
1035
|
or ""
|
|
1033
1036
|
)
|
|
1034
1037
|
|
|
1038
|
+
def get_svg(
|
|
1039
|
+
self,
|
|
1040
|
+
*,
|
|
1041
|
+
text: str,
|
|
1042
|
+
size: int,
|
|
1043
|
+
) -> str:
|
|
1044
|
+
"""
|
|
1045
|
+
Gets an SVG representation of the font rendering
|
|
1046
|
+
some text using the given options.
|
|
1047
|
+
|
|
1048
|
+
:param text: The text to be rendered as SVG paths.
|
|
1049
|
+
:type text: str
|
|
1050
|
+
:param size: The size of the font to be used for rendering the text, in points.
|
|
1051
|
+
:type size: int
|
|
1052
|
+
|
|
1053
|
+
:returns: An SVG string that represents the rendered text.
|
|
1054
|
+
:rtype: str
|
|
1055
|
+
"""
|
|
1056
|
+
font = self.get_ttfont()
|
|
1057
|
+
|
|
1058
|
+
# get font metrics
|
|
1059
|
+
units_per_em = font["head"].unitsPerEm
|
|
1060
|
+
scale = size / units_per_em
|
|
1061
|
+
hhea = font["hhea"]
|
|
1062
|
+
ascent = hhea.ascent * scale
|
|
1063
|
+
descent = hhea.descent * scale
|
|
1064
|
+
width = 0
|
|
1065
|
+
height = ascent - descent
|
|
1066
|
+
|
|
1067
|
+
# get glyph set and character map
|
|
1068
|
+
glyphset = font.getGlyphSet()
|
|
1069
|
+
cmap = font["cmap"].getBestCmap()
|
|
1070
|
+
|
|
1071
|
+
# generate svg path for each glyph in text
|
|
1072
|
+
glyphs: list[str] = list(filter(None, [cmap.get(ord(char)) for char in text]))
|
|
1073
|
+
paths = ""
|
|
1074
|
+
for glyph_name in glyphs:
|
|
1075
|
+
glyph = glyphset[glyph_name]
|
|
1076
|
+
pen = SVGPathPen(glyphset)
|
|
1077
|
+
glyph.draw(pen)
|
|
1078
|
+
commands = pen.getCommands()
|
|
1079
|
+
transform = f"translate({width:.2f} {ascent:.2f}) scale({scale} -{scale})"
|
|
1080
|
+
paths += f"""<path d="{commands}" transform="{transform}" />"""
|
|
1081
|
+
width += glyph.width * scale
|
|
1082
|
+
|
|
1083
|
+
# round width and height
|
|
1084
|
+
width = int(math.ceil(width))
|
|
1085
|
+
height = int(math.ceil(height))
|
|
1086
|
+
viewbox = f"0 0 {width} {height}"
|
|
1087
|
+
xmlns = "http://www.w3.org/2000/svg"
|
|
1088
|
+
|
|
1089
|
+
# generate svg string
|
|
1090
|
+
svg_str = f"""<svg width="{width}" height="{height}" viewBox="{viewbox}" xmlns="{xmlns}">{paths}</svg>"""
|
|
1091
|
+
return svg_str
|
|
1092
|
+
|
|
1035
1093
|
def get_ttfont(
|
|
1036
1094
|
self,
|
|
1037
1095
|
) -> TTFont:
|
|
@@ -1394,18 +1452,41 @@ class Font:
|
|
|
1394
1452
|
width["value"] = width_value
|
|
1395
1453
|
return width
|
|
1396
1454
|
|
|
1455
|
+
def is_color(
|
|
1456
|
+
self,
|
|
1457
|
+
) -> bool:
|
|
1458
|
+
"""
|
|
1459
|
+
Determines if the font is a color font.
|
|
1460
|
+
|
|
1461
|
+
:returns: True if color font, False otherwise.
|
|
1462
|
+
:rtype: bool
|
|
1463
|
+
"""
|
|
1464
|
+
font = self.get_ttfont()
|
|
1465
|
+
tables = {"COLR", "CPAL", "CBDT", "CBLC"}
|
|
1466
|
+
for table in tables:
|
|
1467
|
+
if table in font:
|
|
1468
|
+
return True
|
|
1469
|
+
return False
|
|
1470
|
+
|
|
1397
1471
|
def is_monospace(
|
|
1398
1472
|
self,
|
|
1473
|
+
threshold: float = 0.85,
|
|
1399
1474
|
) -> bool:
|
|
1400
1475
|
"""
|
|
1401
1476
|
Determines if the font is a monospace font.
|
|
1402
1477
|
|
|
1478
|
+
:param threshold: The threshold (0.0 <= n <= 1.0) of glyphs with the same width to consider the font as monospace.
|
|
1479
|
+
:type threshold: float
|
|
1480
|
+
|
|
1403
1481
|
:returns: True if monospace font, False otherwise.
|
|
1404
1482
|
:rtype: bool
|
|
1405
1483
|
"""
|
|
1406
1484
|
font = self.get_ttfont()
|
|
1407
|
-
widths =
|
|
1408
|
-
|
|
1485
|
+
widths = [metrics[0] for metrics in font["hmtx"].metrics.values()]
|
|
1486
|
+
widths_counter = Counter(widths)
|
|
1487
|
+
same_width_count = widths_counter.most_common(1)[0][1]
|
|
1488
|
+
same_width_amount = same_width_count / self.get_glyphs_count()
|
|
1489
|
+
return same_width_amount >= threshold
|
|
1409
1490
|
|
|
1410
1491
|
def is_static(
|
|
1411
1492
|
self,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: python-fontbro
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.24.0
|
|
4
4
|
Summary: friendly font operations on top of fontTools.
|
|
5
5
|
Author-email: Fabio Caccamo <fabio.caccamo@gmail.com>
|
|
6
6
|
Maintainer-email: Fabio Caccamo <fabio.caccamo@gmail.com>
|
|
@@ -118,6 +118,7 @@ with open("fonts/MyFont.ttf") as fh:
|
|
|
118
118
|
- [`get_style_flag`](#get_style_flag)
|
|
119
119
|
- [`get_style_flags`](#get_style_flags)
|
|
120
120
|
- [`get_style_name`](#get_style_name)
|
|
121
|
+
- [`get_svg`](#get_svg)
|
|
121
122
|
- [`get_ttfont`](#get_ttfont)
|
|
122
123
|
- [`get_unicode_block_by_name`](#get_unicode_block_by_name)
|
|
123
124
|
- [`get_unicode_blocks`](#get_unicode_blocks)
|
|
@@ -133,6 +134,7 @@ with open("fonts/MyFont.ttf") as fh:
|
|
|
133
134
|
- [`get_vertical_metrics`](#get_vertical_metrics)
|
|
134
135
|
- [`get_weight`](#get_weight)
|
|
135
136
|
- [`get_width`](#get_width)
|
|
137
|
+
- [`is_color`](#is_color)
|
|
136
138
|
- [`is_monospace`](#is_monospace)
|
|
137
139
|
- [`is_static`](#is_static)
|
|
138
140
|
- [`is_variable`](#is_variable)
|
|
@@ -449,6 +451,23 @@ Gets the style name reading the name records with priority order (17, 22, 2).
|
|
|
449
451
|
style_name = font.get_style_name()
|
|
450
452
|
```
|
|
451
453
|
|
|
454
|
+
#### `get_svg`
|
|
455
|
+
```python
|
|
456
|
+
"""
|
|
457
|
+
Gets an SVG representation of the font rendering
|
|
458
|
+
some text using the given options.
|
|
459
|
+
|
|
460
|
+
:param text: The text to be rendered as SVG paths.
|
|
461
|
+
:type text: str
|
|
462
|
+
:param size: The size of the font to be used for rendering the text, in points.
|
|
463
|
+
:type size: int
|
|
464
|
+
|
|
465
|
+
:returns: An SVG string that represents the rendered text.
|
|
466
|
+
:rtype: str
|
|
467
|
+
"""
|
|
468
|
+
svg_str = font.get_svg(text="Hello!", size=48)
|
|
469
|
+
```
|
|
470
|
+
|
|
452
471
|
#### `get_ttfont`
|
|
453
472
|
```python
|
|
454
473
|
"""
|
|
@@ -642,11 +661,25 @@ Gets the font width value and name.
|
|
|
642
661
|
width = font.get_width()
|
|
643
662
|
```
|
|
644
663
|
|
|
664
|
+
#### `is_color`
|
|
665
|
+
```python
|
|
666
|
+
"""
|
|
667
|
+
Determines if the font is a color font.
|
|
668
|
+
|
|
669
|
+
:returns: True if color font, False otherwise.
|
|
670
|
+
:rtype: bool
|
|
671
|
+
"""
|
|
672
|
+
color = font.is_color()
|
|
673
|
+
```
|
|
674
|
+
|
|
645
675
|
#### `is_monospace`
|
|
646
676
|
```python
|
|
647
677
|
"""
|
|
648
678
|
Determines if the font is a monospace font.
|
|
649
679
|
|
|
680
|
+
:param threshold: The threshold (0.0 <= n <= 1.0) of glyphs with the same width to consider the font as monospace.
|
|
681
|
+
:type threshold: float
|
|
682
|
+
|
|
650
683
|
:returns: True if monospace font, False otherwise.
|
|
651
684
|
:rtype: bool
|
|
652
685
|
"""
|
|
@@ -25,6 +25,7 @@ tests/test_characters.py
|
|
|
25
25
|
tests/test_clone.py
|
|
26
26
|
tests/test_close.py
|
|
27
27
|
tests/test_collection.py
|
|
28
|
+
tests/test_color.py
|
|
28
29
|
tests/test_context_manager.py
|
|
29
30
|
tests/test_family_classification.py
|
|
30
31
|
tests/test_family_name.py
|
|
@@ -47,6 +48,7 @@ tests/test_str.py
|
|
|
47
48
|
tests/test_style_flags.py
|
|
48
49
|
tests/test_style_name.py
|
|
49
50
|
tests/test_subset.py
|
|
51
|
+
tests/test_svg.py
|
|
50
52
|
tests/test_unicode_blocks_and_scripts.py
|
|
51
53
|
tests/test_update_unicode_data.py
|
|
52
54
|
tests/test_variable.py
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
from tests import AbstractTestCase
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class ColorTestCase(AbstractTestCase):
|
|
5
|
+
"""
|
|
6
|
+
This class describes a color test case.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
def test_is_monospace(self):
|
|
10
|
+
with self._get_font("/Honk/static/Honk-Regular.ttf") as font:
|
|
11
|
+
self.assertTrue(font.is_color())
|
|
12
|
+
with self._get_font("/Inter/static/Inter-Regular.ttf") as font:
|
|
13
|
+
self.assertFalse(font.is_color())
|
|
14
|
+
with self._get_font("/Nabla/static/Nabla-Regular.ttf") as font:
|
|
15
|
+
self.assertTrue(font.is_color())
|
|
16
|
+
with self._get_font("/Noto_Sans_TC/NotoSansTC-Regular.otf") as font:
|
|
17
|
+
self.assertFalse(font.is_color())
|
|
18
|
+
with self._get_font("/Open_Sans/static/OpenSans-Regular.ttf") as font:
|
|
19
|
+
self.assertFalse(font.is_color())
|
|
20
|
+
with self._get_font("/Roboto_Mono/static/RobotoMono-Regular.ttf") as font:
|
|
21
|
+
self.assertFalse(font.is_color())
|
|
@@ -10,7 +10,7 @@ class MonospaceTestCase(AbstractTestCase):
|
|
|
10
10
|
with self._get_font("/Inter/static/Inter-Regular.ttf") as font:
|
|
11
11
|
self.assertFalse(font.is_monospace())
|
|
12
12
|
with self._get_font("/Noto_Sans_TC/NotoSansTC-Regular.otf") as font:
|
|
13
|
-
self.
|
|
13
|
+
self.assertTrue(font.is_monospace())
|
|
14
14
|
with self._get_font("/Open_Sans/static/OpenSans-Regular.ttf") as font:
|
|
15
15
|
self.assertFalse(font.is_monospace())
|
|
16
16
|
with self._get_font("/Roboto_Mono/static/RobotoMono-Regular.ttf") as font:
|
|
@@ -24,6 +24,7 @@ class SanitizeTestCase(AbstractTestCase):
|
|
|
24
24
|
try:
|
|
25
25
|
font = Font(font_file)
|
|
26
26
|
except Exception:
|
|
27
|
+
# there are some ttc files
|
|
27
28
|
continue
|
|
28
29
|
try:
|
|
29
30
|
font.sanitize(strict=strict)
|
|
@@ -64,7 +65,7 @@ class SanitizeTestCase(AbstractTestCase):
|
|
|
64
65
|
self._test_sanitize(
|
|
65
66
|
"fonts-ots/good",
|
|
66
67
|
strict=False,
|
|
67
|
-
expected_errors_count=
|
|
68
|
+
expected_errors_count=2, # should reduce to 0
|
|
68
69
|
)
|
|
69
70
|
|
|
70
71
|
def test_sanitize_strict_with_good_fonts(self):
|
|
@@ -72,5 +73,5 @@ class SanitizeTestCase(AbstractTestCase):
|
|
|
72
73
|
self._test_sanitize(
|
|
73
74
|
"fonts-ots/good",
|
|
74
75
|
strict=True,
|
|
75
|
-
expected_errors_count=
|
|
76
|
+
expected_errors_count=2, # should reduce to 0
|
|
76
77
|
)
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
from tests import AbstractTestCase
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class SVGTestCase(AbstractTestCase):
|
|
5
|
+
"""
|
|
6
|
+
This class describes an image test case.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
def test_generate_svg(self):
|
|
10
|
+
# font = self._get_font("/Noto_Sans_TC/NotoSansTC-Regular.otf")
|
|
11
|
+
font = self._get_font("/Inter/static/Inter-Black.ttf")
|
|
12
|
+
svg = font.get_svg(
|
|
13
|
+
text="Hello World!",
|
|
14
|
+
size=16,
|
|
15
|
+
)
|
|
16
|
+
# print(svg)
|
|
17
|
+
self.assertTrue(svg.startswith("<svg "))
|
|
18
|
+
self.assertTrue(svg.endswith("</svg>"))
|
|
19
|
+
self.assertFalse("{" in svg)
|
|
20
|
+
self.assertFalse("}" in svg)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{python_fontbro-0.23.0 → python_fontbro-0.24.0}/python_fontbro.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|