From 9a2d983760f016c340c6813fd53685875bb2ccf9 Mon Sep 17 00:00:00 2001 From: Martin Thoma Date: Tue, 14 Nov 2023 08:28:59 +0100 Subject: [PATCH] ROB: MissingWidth is IndirectObject (#2288) Fixes #2286 Co-authored-by: pubpub-zz <4083478+pubpub-zz@users.noreply.github.com> --- pypdf/_cmap.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/pypdf/_cmap.py b/pypdf/_cmap.py index 6392805be..2706007c2 100644 --- a/pypdf/_cmap.py +++ b/pypdf/_cmap.py @@ -6,7 +6,7 @@ from ._codecs import adobe_glyphs, charset_encoding from ._utils import b_, logger_warning from .errors import PdfReadWarning -from .generic import DecodedStreamObject, DictionaryObject, StreamObject +from .generic import DecodedStreamObject, DictionaryObject, IndirectObject, NullObject, StreamObject # code freely inspired from @twiggy ; see #711 @@ -457,6 +457,17 @@ def compute_space_width( m += x cpt += 1 sp_width = m / max(1, cpt) / 2 + + if isinstance(sp_width, IndirectObject): + # According to + # 'Table 122 - Entries common to all font descriptors (continued)' + # the MissingWidth should be a number, but according to #2286 it can + # be an indirect object + obj = sp_width.get_object() + if obj is None or isinstance(obj, NullObject): + return 0.0 + return obj # type: ignore + return sp_width