Skip to content

Commit

Permalink
get_text_range(): adapt allocation to pdfium version
Browse files Browse the repository at this point in the history
backported from devel_new branch
  • Loading branch information
mara004 committed May 7, 2024
1 parent 7ce4d31 commit eded6c2
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/pypdfium2/_helpers/textpage.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import pypdfium2.raw as pdfium_c
import pypdfium2.internal as pdfium_i
from pypdfium2._helpers.misc import PdfiumError
from pypdfium2.version import PDFIUM_INFO

c_double = ctypes.c_double

Expand Down Expand Up @@ -94,7 +95,14 @@ def get_text_range(self, index=0, count=-1, errors="ignore", force_this=False):
t_start, t_end, l_passive, r_passive = active_range
index += l_passive
count -= l_passive + r_passive
in_count = (t_end+1 - t_start)*2 + 1
in_count = t_end+1 - t_start

# pdfium fea01fa9e2 (>6167) to d6a4b27d80 (<6415) requires assuming 4 bytes per character
# https://github.com/pypdfium2-team/pypdfium2/issues/298
# https://crbug.com/pdfium/2133
if 6167 < PDFIUM_INFO.build < 6415:
in_count *= 2
in_count += 1 # null terminator

buffer = ctypes.create_string_buffer(in_count * 2)
buffer_ptr = ctypes.cast(buffer, ctypes.POINTER(ctypes.c_ushort))
Expand Down

0 comments on commit eded6c2

Please sign in to comment.