From 7393e1fe4bee27eee49cd95240f519dc6b643c31 Mon Sep 17 00:00:00 2001 From: Martin Thoma Date: Thu, 9 Nov 2023 12:27:00 +0100 Subject: [PATCH 1/3] ROB: MissingWidth is IndirectObject --- pypdf/_cmap.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/pypdf/_cmap.py b/pypdf/_cmap.py index 6392805be..8c75baa79 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, 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: + return 0.0 + return obj # type: ignore + return sp_width From 91c85a91293f851e77a14836b585d617dbfdf532 Mon Sep 17 00:00:00 2001 From: Martin Thoma Date: Tue, 14 Nov 2023 07:39:45 +0100 Subject: [PATCH 2/3] Update pypdf/_cmap.py Co-authored-by: pubpub-zz <4083478+pubpub-zz@users.noreply.github.com> --- pypdf/_cmap.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pypdf/_cmap.py b/pypdf/_cmap.py index 8c75baa79..95857af3f 100644 --- a/pypdf/_cmap.py +++ b/pypdf/_cmap.py @@ -464,7 +464,7 @@ def compute_space_width( # 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: + if obj is None or isinstance(obj, NullObject): return 0.0 return obj # type: ignore From c84f8411108eef59d3fb6ccb8a0996251332ecaf Mon Sep 17 00:00:00 2001 From: Martin Thoma Date: Tue, 14 Nov 2023 07:39:51 +0100 Subject: [PATCH 3/3] Update pypdf/_cmap.py Co-authored-by: pubpub-zz <4083478+pubpub-zz@users.noreply.github.com> --- pypdf/_cmap.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pypdf/_cmap.py b/pypdf/_cmap.py index 95857af3f..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, IndirectObject, StreamObject +from .generic import DecodedStreamObject, DictionaryObject, IndirectObject, NullObject, StreamObject # code freely inspired from @twiggy ; see #711