Skip to content

Commit a8dfd5a

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 647a80b commit a8dfd5a

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

pypdf/_font.py

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

33

44
@dataclass(frozen=True)
@@ -8,16 +8,16 @@ class FontDescriptor:
88
This contains both descriptive and metric information.
99
"""
1010

11-
name: str
12-
family: str
13-
weight: str
11+
name: str = "Unknown"
12+
family: str = "Unknown"
13+
weight: str = "Unknown"
1414

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]
15+
ascent: float = 800.0 # A typical ascent value for many fonts
16+
descent: float = -200.0 # A typical descent value, negative
17+
cap_height: float = 700.0 # A common cap height, often around 70% of the ascent
18+
x_height: float = 500.0 # A common x-height, often around 50% of the ascent
19+
italic_angle: float = 0.0 # Most fonts are not italic
20+
flags: int = 4 # The "FixedPitch" bit is often set for default fonts
21+
bbox: tuple[float, float, float, float] = field(default_factory=lambda: (0.0, -200.0, 1000.0, 800.0))
2222

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

0 commit comments

Comments
 (0)