[Poppler-bugs] [Bug 77790] get_text_layout introspection mismatch
bugzilla-daemon at freedesktop.org
bugzilla-daemon at freedesktop.org
Wed Jun 11 01:24:32 PDT 2014
https://bugs.freedesktop.org/show_bug.cgi?id=77790
--- Comment #1 from Anselm Kruis <a.kruis at science-computing.de> ---
I have exactly the same issue with python. I was able to work around problem
using the ctypes foreign function interface of Python.
The code is for Python 2.7. It should be possible create a gi.overrides.Poppler
module based on this code. This would fix the issue for Python.
from gi.repository import Poppler, GLib
import ctypes
lib_poppler = ctypes.cdll.LoadLibrary("libpoppler-glib-8")
ctypes.pythonapi.PyCapsule_GetPointer.restype = ctypes.c_void_p
ctypes.pythonapi.PyCapsule_GetPointer.argtypes = [ctypes.py_object,
ctypes.c_char_p]
PyCapsule_GetPointer = ctypes.pythonapi.PyCapsule_GetPointer
class Poppler_Rectangle(ctypes.Structure):
_fields_ = [ ("x1", ctypes.c_double), ("y1", ctypes.c_double), ("x2",
ctypes.c_double), ("y2", ctypes.c_double) ]
LP_Poppler_Rectangle = ctypes.POINTER(Poppler_Rectangle)
poppler_page_get_text_layout = ctypes.CFUNCTYPE(ctypes.c_int,
ctypes.c_void_p,
ctypes.POINTER(LP_Poppler_Rectangle),
ctypes.POINTER(ctypes.c_uint)
)(lib_poppler.poppler_page_get_text_layout)
def get_page_layout(page):
assert isinstance(page, Poppler.Page)
capsule = page.__gpointer__
page_addr = PyCapsule_GetPointer(capsule, None)
rectangles = LP_Poppler_Rectangle()
n_rectangles = ctypes.c_uint(0)
has_text = poppler_page_get_text_layout(page_addr,
ctypes.byref(rectangles), ctypes.byref(n_rectangles))
try:
result = []
if has_text:
assert n_rectangles.value > 0, "n_rectangles.value > 0:
{}".format(n_rectangles.value)
assert rectangles, "rectangles: {}".format(rectangles)
for i in range(n_rectangles.value):
r = rectangles[i]
result.append((r.x1, r.y1, r.x2, r.y2))
return result
finally:
if rectangles:
GLib.free(ctypes.addressof(rectangles.contents))
--
You are receiving this mail because:
You are the assignee for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/poppler-bugs/attachments/20140611/cb9a41dd/attachment.html>
More information about the Poppler-bugs
mailing list