Skip to content

Commit

Permalink
fix: make sure it is really bytes in font.decode
Browse files Browse the repository at this point in the history
  • Loading branch information
dhdaines committed Sep 19, 2024
1 parent 9199809 commit 55345e3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
8 changes: 8 additions & 0 deletions pdfminer/pdfdevice.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions pdfminer/pdffont.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down Expand Up @@ -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."""
Expand Down

0 comments on commit 55345e3

Please sign in to comment.