Skip to content

Commit 8cb825d

Browse files
committed
ENH: build_font_width_map: Add widths for core 14 fonts
This patch reads the character widths for the core 14 Type 1 PDF fonts from the _codecs/core_fontmetrics.py file.
1 parent bb7e2d9 commit 8cb825d

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

pypdf/_cmap.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from typing import Any, Dict, List, Tuple, Union, cast
66

77
from ._codecs import adobe_glyphs, charset_encoding
8+
from ._codecs.core_fontmetrics import FONT_METRICS
89
from ._utils import logger_error, logger_warning
910
from .generic import (
1011
ArrayObject,
@@ -476,6 +477,10 @@ def build_font_width_map(
476477
# The PDF structure is invalid. The array is too small
477478
# for the specified font width.
478479
pass
480+
else:
481+
font_name = str(ft["/BaseFont"])[1:]
482+
if font_name in FONT_METRICS:
483+
font_width_map = cast(Dict[str, float], FONT_METRICS[font_name][1])
479484
if is_null_or_none(font_width_map.get("default")):
480485
font_width_map["default"] = default_font_width if default_font_width else 0.0
481486
return font_width_map

0 commit comments

Comments
 (0)