From 55345e3c04d6e189fc850c3f8798421cce831275 Mon Sep 17 00:00:00 2001 From: David Huggins-Daines Date: Thu, 19 Sep 2024 07:59:09 -0400 Subject: [PATCH] fix: make sure it is really bytes in font.decode --- pdfminer/pdfdevice.py | 8 ++++++++ pdfminer/pdffont.py | 8 ++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/pdfminer/pdfdevice.py b/pdfminer/pdfdevice.py index 2374601c..6e0c58b9 100644 --- a/pdfminer/pdfdevice.py +++ b/pdfminer/pdfdevice.py @@ -168,6 +168,10 @@ def render_string_horizontal( x -= obj * dxscale needcharspace = True else: + if isinstance(obj, str): + obj = utils.make_compat_bytes(obj) + if not isinstance(obj, bytes): + continue for cid in font.decode(obj): if needcharspace: x += charspace @@ -208,6 +212,10 @@ def render_string_vertical( y -= obj * dxscale needcharspace = True else: + if isinstance(obj, str): + obj = utils.make_compat_bytes(obj) + if not isinstance(obj, bytes): + continue for cid in font.decode(obj): if needcharspace: y += charspace diff --git a/pdfminer/pdffont.py b/pdfminer/pdffont.py index e3c51d73..5b0402fd 100644 --- a/pdfminer/pdffont.py +++ b/pdfminer/pdffont.py @@ -899,8 +899,8 @@ def is_vertical(self) -> bool: def is_multibyte(self) -> bool: return False - def decode(self, bytes: bytes) -> Iterable[int]: - return bytearray(bytes) # map(ord, bytes) + def decode(self, data: bytes) -> Iterable[int]: + return data def get_ascent(self) -> float: """Ascent above the baseline, in text space units""" @@ -1173,8 +1173,8 @@ def is_vertical(self) -> bool: def is_multibyte(self) -> bool: return True - def decode(self, bytes: bytes) -> Iterable[int]: - return self.cmap.decode(bytes) + def decode(self, data: bytes) -> Iterable[int]: + return self.cmap.decode(data) def char_disp(self, cid: int) -> Union[float, Tuple[Optional[float], float]]: """Returns an integer for horizontal fonts, a tuple for vertical fonts."""