Skip to content

Commit 1b9ea3e

Browse files
committed
ENH: tests: Add a little test for the FontDescriptor dataclass
This patch adds a little test for the FontDescriptor dataclass to make codecov happy.
1 parent 83c78fd commit 1b9ea3e

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

tests/test_font.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
"""Test font-related functionality."""
2+
3+
from pypdf._font import FontDescriptor
4+
from pypdf.generic import DictionaryObject, NameObject
5+
6+
7+
def test_font_descriptor():
8+
font_res = DictionaryObject({NameObject("/BaseFont"): NameObject("/Helvetica")})
9+
my_font = FontDescriptor.from_font_resource(font_res)
10+
assert my_font.family == "Helvetica"
11+
assert my_font.weight == "Medium"
12+
assert my_font.ascent == 718
13+
assert my_font.descent == -207
14+
15+
test_string = "This is a long sentence. !@%%^€€€. çûįö¶´"
16+
charwidth = sum(my_font.character_widths[char] for char in test_string)
17+
assert charwidth == 19251
18+
19+
font_res = DictionaryObject({NameObject("/BaseFont"): NameObject("/Palatino")})
20+
my_font = FontDescriptor.from_font_resource(font_res)
21+
assert my_font.weight == "Unknown"
22+
23+
font_res = DictionaryObject({NameObject("/BaseFont"): NameObject("/Courier-Bold")})
24+
my_font = FontDescriptor.from_font_resource(font_res)
25+
assert my_font.italic_angle == 0
26+
assert my_font.flags == 33
27+
assert my_font.bbox == (-113.0, -250.0, 749.0, 801.0)

0 commit comments

Comments
 (0)