Skip to content

Commit 82c4f76

Browse files
committed
ENH: _font: Set some defaults for the FontDescriptor class
This patch introduces some defaults for the FontDescriptor. This might be useful if we would like to migrate existing code for collecting font widths to the class, while not having all code in place to also collect all associated other information about the font. The defaults I took from Google Gemini...
1 parent 830464a commit 82c4f76

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

pypdf/_font.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,26 @@
1-
from dataclasses import dataclass
1+
from dataclasses import dataclass, field
22

33

44
@dataclass(frozen=True)
55
class FontDescriptor:
66
"""
77
Represents the FontDescriptor dictionary as defined in the PDF specification.
88
This contains both descriptive and metric information.
9+
10+
The defaults are derived from the mean values of the 14 core fonts, rounded
11+
to 100.
912
"""
1013

11-
name: str
12-
family: str
13-
weight: str
14+
name: str = "Unknown"
15+
family: str = "Unknown"
16+
weight: str = "Unknown"
1417

15-
ascent: float
16-
descent: float
17-
cap_height: float
18-
x_height: float
19-
italic_angle: float
20-
flags: int
21-
bbox: tuple[float, float, float, float]
18+
ascent: float = 700.0
19+
descent: float = -200.0
20+
cap_height: float = 600.0
21+
x_height: float = 500.0
22+
italic_angle: float = 0.0 # Non-italic
23+
flags: int = 32 # Non-serif, non-symbolic, not fixed width
24+
bbox: tuple[float, float, float, float] = field(default_factory=lambda: (-100.0, -200.0, 1000.0, 900.0))
2225

23-
character_widths: dict[str, int]
26+
character_widths: dict[str, int] = field(default_factory=dict)

0 commit comments

Comments
 (0)