Skip to content

Commit 9a2d983

Browse files
ROB: MissingWidth is IndirectObject (#2288)
Fixes #2286 Co-authored-by: pubpub-zz <4083478+pubpub-zz@users.noreply.github.com>
1 parent 03bce94 commit 9a2d983

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

pypdf/_cmap.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from ._codecs import adobe_glyphs, charset_encoding
77
from ._utils import b_, logger_warning
88
from .errors import PdfReadWarning
9-
from .generic import DecodedStreamObject, DictionaryObject, StreamObject
9+
from .generic import DecodedStreamObject, DictionaryObject, IndirectObject, NullObject, StreamObject
1010

1111

1212
# code freely inspired from @twiggy ; see #711
@@ -457,6 +457,17 @@ def compute_space_width(
457457
m += x
458458
cpt += 1
459459
sp_width = m / max(1, cpt) / 2
460+
461+
if isinstance(sp_width, IndirectObject):
462+
# According to
463+
# 'Table 122 - Entries common to all font descriptors (continued)'
464+
# the MissingWidth should be a number, but according to #2286 it can
465+
# be an indirect object
466+
obj = sp_width.get_object()
467+
if obj is None or isinstance(obj, NullObject):
468+
return 0.0
469+
return obj # type: ignore
470+
460471
return sp_width
461472

462473

0 commit comments

Comments
 (0)