<html>
<head>
<base href="https://bugs.freedesktop.org/" />
</head>
<body>
<p>
<div>
<b><a class="bz_bug_link
bz_status_NEW "
title="NEW --- - get_text_layout introspection mismatch"
href="https://bugs.freedesktop.org/show_bug.cgi?id=77790#c1">Comment # 1</a>
on <a class="bz_bug_link
bz_status_NEW "
title="NEW --- - get_text_layout introspection mismatch"
href="https://bugs.freedesktop.org/show_bug.cgi?id=77790">bug 77790</a>
from <span class="vcard"><a class="email" href="mailto:a.kruis@science-computing.de" title="Anselm Kruis <a.kruis@science-computing.de>"> <span class="fn">Anselm Kruis</span></a>
</span></b>
<pre>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))</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are the assignee for the bug.</li>
</ul>
</body>
</html>